Loading ...
Sorry, an error occurred while loading the content.
 

Re: [emacs-nxml-mode] Attribute wrapping indent

Expand Messages
  • Norman Walsh
    attribute name. I would prefer to have a variable to control this ... Hmm, I ve noticed the same thing, although I d actually prefer:
    Message 1 of 6 , Jan 1, 2004
      / Sidnei da Silva <sidnei@...> was heard to say:
      | attribute name. I would prefer to have a variable to control this
      | setting, say, 'nxml-indent-attribute-value', which when set to
      | non-nil, would generate the following indentation:
      |
      | <div tal:define="tabindex tabindex/next;
      | error_workflow_action errors/workflow_action|nothing;
      | objs request/ids|nothing;
      | review_state_label string:No change;
      | target python:test(objs, objs, here);"
      | tal:attributes="class
      | python:test(error_workflow_action, 'field error', 'field')"
      | tal:condition="not:anonymous">
      |
      | Does that sound reasonable, or should I just get used to it?

      Hmm, I've noticed the same thing, although I'd actually prefer:

      <div tal:define="tabindex tabindex/next;
      error_workflow_action errors/workflow_action|nothing;
      objs request/ids|nothing;
      review_state_label string:No change;
      target python:test(objs, objs, here);"
      tal:attributes="class
      python:test(error_workflow_action, 'field error', 'field')"
      tal:condition="not:anonymous">

      What I have noticed, as a workaround, is that if you ident the second line
      of the attribute value by hand, nxml-mode indents all the rest of the lines
      "correctly".

      Be seeing you,
      norm

      --
      Norman Walsh <normyahoo@...> | Simplicity is always a
      http://nwalsh.com/ | virtue.--Edward Abbey
    • Eric Mc Sween
      ... Here s a patch against nxml-mode-20031031 that does this. I also changed the behavior of indentation for end tags so that only end tags that lie on the
      Message 2 of 6 , Jan 10, 2004
        Norman Walsh <normyahoo@...> writes:

        > Hmm, I've noticed the same thing, although I'd actually prefer:
        >
        > <div tal:define="tabindex tabindex/next;
        > error_workflow_action errors/workflow_action|nothing;
        > objs request/ids|nothing;
        > review_state_label string:No change;
        > target python:test(objs, objs, here);"
        > tal:attributes="class
        > python:test(error_workflow_action, 'field error', 'field')"
        > tal:condition="not:anonymous">

        Here's a patch against nxml-mode-20031031 that does this.

        I also changed the behavior of indentation for end tags so that only
        end tags that lie on the beginning of a line dedent. Thus, instead of
        this kind of indentation:

        <h1 tal:define="some_variable some_expression;
        some_other_variable some_other_expression;"
        tal:content="here/title_or_id">Title</h1>

        I now get this:

        <h1 tal:define="some_variable some_expression;
        some_other_variable some_other_expression;"
        tal:content="here/title_or_id">Title</h1>

        Cheers,

        Eric


        --- /tmp/nxml-mode.el.orig31139iId 2004-01-10 12:20:17.422328536 -0500
        +++ /tmp/nxml-mode.el31139vSj 2004-01-10 12:20:17.424328232 -0500
        @@ -1503,7 +1503,7 @@
        Return nil if the indent of the current line should not be changed."
        (nxml-ensure-scan-up-to-date)
        (let ((indent 0)
        - token-end target-line-start absolute)
        + token-start token-end token-type target-line-start absolute)
        (save-excursion
        (cond (;; First line: indent 0
        (save-excursion
        @@ -1511,18 +1511,18 @@
        (eq (point) (point-min)))
        (setq indent 0)
        (setq absolute t))
        - (;; End-tag at the end of a line
        + (;; End-tag at the beginning of a line
        ;; If corresponding start-tag not too far away,
        ;; and at the start of its line, then use indentation
        ;; of start-tag.
        (progn
        (back-to-indentation)
        - (setq target-line-start (point))
        - (let ((inhibit-field-text-motion t))
        - (end-of-line))
        - (skip-chars-backward " \t")
        - (and (eq (nxml-token-before) (point))
        - (memq xmltok-type '(end-tag partial-end-tag))
        + (setq target-line-start (point)
        + token-end (nxml-token-after)
        + token-start xmltok-start
        + token-type xmltok-type)
        + (goto-char token-end)
        + (and (memq token-type '(end-tag partial-end-tag))
        (nxml-scan-element-backward
        (point)
        nil
        @@ -1538,9 +1538,8 @@
        ;; Use nxml-child-indent less than normal
        ((progn
        (goto-char target-line-start)
        - (setq token-end (nxml-token-after))
        - (and (eq xmltok-start (point))
        - (memq xmltok-type '(end-tag partial-end-tag))
        + (and (eq token-start (point))
        + (memq token-type '(end-tag partial-end-tag))
        (save-excursion
        (goto-char token-end)
        (nxml-indent-at-end-of-line-p))))
        @@ -1548,11 +1547,47 @@
        (setq indent (- nxml-child-indent)))
        ;; Comment close on its own line
        ;; Indent relative to comment open
        - ((and (eq xmltok-type 'comment)
        + ((and (eq token-type 'comment)
        (eq token-end (+ target-line-start 3)))
        - (goto-char xmltok-start)
        + (goto-char token-start)
        (setq indent (current-column))
        - (setq absolute t)))
        + (setq absolute t))
        + ;; Inside a multi-line tag
        + ((progn
        + (goto-char target-line-start)
        + (skip-chars-backward " \t\n\r")
        + (setq token-end (nxml-token-before))
        + (or (and (memq xmltok-type '(start-tag empty-element))
        + (>= token-end target-line-start))
        + (memq xmltok-type '(partial-empty-element partial-start-tag))))
        + (let ((att (nxml-find-preceding-attribute))
        + name-start value-start value-end)
        + (if att
        + (progn
        + (setq name-start (xmltok-attribute-name-start att))
        + (setq value-start (xmltok-attribute-value-start att))
        + (setq value-end (xmltok-attribute-value-end att))))
        + (cond (;; Inside a partial attribute value.
        + (not value-end)
        + (save-excursion
        + (search-backward "\"" name-start nil)
        + (setq indent (1+ (current-column)))))
        + ;; Inside a complete attribute value
        + ((<= target-line-start value-end)
        + (save-excursion
        + (goto-char value-start)
        + (setq indent (current-column))))
        + ;; Not in an attribute value.
        + (t
        + (setq indent
        + (or (save-excursion
        + (goto-char xmltok-start)
        + (skip-chars-forward "^ \t\r\n")
        + (skip-chars-forward " \t")
        + (if (looking-at ".")
        + (current-column)))
        + (+ (current-column) nxml-attribute-indent))))))
        + (setq absolute t)))
        (if absolute
        indent
        (skip-chars-backward " \r\n\t")
        @@ -1578,31 +1613,6 @@
        (if (eq xmltok-type 'start-tag)
        nxml-child-indent
        0)))
        - ;; the second non-blank line of a multi-line tag
        - ((and (memq xmltok-type '(start-tag
        - empty-element
        - partial-empty-element
        - partial-start-tag))
        - (save-excursion
        - (goto-char xmltok-start)
        - (back-to-indentation)
        - (eq (point) xmltok-start))
        - (save-excursion
        - (goto-char target-line-start)
        - (skip-chars-backward " \t\r\n")
        - (back-to-indentation)
        - (eq (point) xmltok-start))
        - (<= target-line-start
        - (save-excursion
        - (goto-char token-end)
        - (skip-chars-forward " \t\r\n")
        - (point))))
        - (goto-char xmltok-start)
        - (or (save-excursion
        - (skip-chars-forward "^ \t\r\n")
        - (skip-chars-forward " \t")
        - (and (looking-at ".") (current-column)))
        - (+ (current-column) nxml-attribute-indent)))
        (;; second non-blank line of a multi-line comment
        (and (eq xmltok-type 'comment)
        (< target-line-start token-end)
      • Sidnei da Silva
        ... Sweet! It worked like a charm for me. I applied the patch to the debian package and recompiled and now I m happy again :) Can we get this patch included in
        Message 3 of 6 , Jan 13, 2004
          On Sat, Jan 10, 2004 at 09:01:45PM -0500, Eric Mc Sween wrote:
          | Here's a patch against nxml-mode-20031031 that does this.
          |
          | I also changed the behavior of indentation for end tags so that only
          | end tags that lie on the beginning of a line dedent. Thus, instead of
          | this kind of indentation:
          |
          | <h1 tal:define="some_variable some_expression;
          | some_other_variable some_other_expression;"
          | tal:content="here/title_or_id">Title</h1>
          |
          | I now get this:
          |
          | <h1 tal:define="some_variable some_expression;
          | some_other_variable some_other_expression;"
          | tal:content="here/title_or_id">Title</h1>

          Sweet! It worked like a charm for me. I applied the patch to the
          debian package and recompiled and now I'm happy again :) Can we get
          this patch included in the next release?

          --
          Sidnei da Silva <sidnei@...>
          http://awkly.org - dreamcatching :: making your dreams come true
          http://plone.org/about/team#dreamcatcher

          Linux is addictive, I'm hooked!
          -- MaDsen Wikholm's .sig
        • Sidnei da Silva
          ... Ugh. Not so fast :( It seems to have broken identation of stuff like:
          Message 4 of 6 , Jan 15, 2004
            | Sweet! It worked like a charm for me. I applied the patch to the
            | debian package and recompiled and now I'm happy again :) Can we get
            | this patch included in the next release?

            Ugh. Not so fast :(

            It seems to have broken identation of stuff like:

            <configure
            xmlns="http://namespaces.zope.org/zope">

            <permission
            id="sqlobjectsupport.AddContent"
            title="[add-sample-permission] sqlobjectsupport - Add Content"
            />

            <grant
            permission="sqlobjectsupport.AddContent"
            role="zope.Manager" />

            </configure>

            Gets idented as:

            <configure
            xmlns="http://namespaces.zope.org/zope">

            <permission
            id="sqlobjectsupport.AddContent"
            title=\
            "[add-sample-permission] sqlobjectsupport - Add Content"
            \
            />

            <grant
            \
            permission="sqlobjectsupp\
            ort.AddContent"
            \
            \
            role="zope.Manager" />

            </configure>


            (I hope you can get the idea)

            Also, if I press 'TAB' on the second line (xmlns:...) I get:

            Search failed: "\""

            on the minibuffer.

            Hope that helps.

            --
            Sidnei da Silva <sidnei@...>
            http://awkly.org - dreamcatching :: making your dreams come true
            http://plone.org/about/team#dreamcatcher

            If at first you don't succeed, you must be a programmer.
          • Eric Mc Sween
            ... [ snip example of bad indentation ] Right. Here s a fix. This is still a patch against nxml-mode-20031031. There is another problem I discovered: This:
            Message 5 of 6 , Jan 15, 2004
              Sidnei da Silva <sidnei@...> writes:

              > It seems to have broken identation of stuff like:
              >
              > <configure
              > xmlns="http://namespaces.zope.org/zope">
              >
              > <permission
              > id="sqlobjectsupport.AddContent"
              > title="[add-sample-permission] sqlobjectsupport - Add Content"
              > />
              >
              > <grant
              > permission="sqlobjectsupport.AddContent"
              > role="zope.Manager" />
              >
              > </configure>
              >
              > Gets idented as:
              >

              [ snip example of bad indentation ]

              Right. Here's a fix. This is still a patch against
              nxml-mode-20031031.

              There is another problem I discovered:

              This:

              Some text
              <a href="..."><img src="..." alt="..."
              tal:condition="..." /></a>
              Some other text
              And yet another line

              gets indented like this:

              Some text
              <a href="..."><img src="..." alt="..."
              tal:condition="..." /></a>
              Some other text
              And yet another line

              I'll probably fix this later as well as I have grown very fond of nxml
              after a couple of weeks of usage.

              So here's the updated patch:

              --- /tmp/nxml-mode.el.orig31837RDQ 2004-01-15 14:09:35.005799152 -0500
              +++ /tmp/nxml-mode.el31837eNW 2004-01-15 14:09:35.017797328 -0500
              @@ -1503,7 +1503,7 @@
              Return nil if the indent of the current line should not be changed."
              (nxml-ensure-scan-up-to-date)
              (let ((indent 0)
              - token-end target-line-start absolute)
              + token-start token-end token-type target-line-start absolute)
              (save-excursion
              (cond (;; First line: indent 0
              (save-excursion
              @@ -1511,18 +1511,18 @@
              (eq (point) (point-min)))
              (setq indent 0)
              (setq absolute t))
              - (;; End-tag at the end of a line
              + (;; End-tag at the beginning of a line
              ;; If corresponding start-tag not too far away,
              ;; and at the start of its line, then use indentation
              ;; of start-tag.
              (progn
              (back-to-indentation)
              - (setq target-line-start (point))
              - (let ((inhibit-field-text-motion t))
              - (end-of-line))
              - (skip-chars-backward " \t")
              - (and (eq (nxml-token-before) (point))
              - (memq xmltok-type '(end-tag partial-end-tag))
              + (setq target-line-start (point)
              + token-end (nxml-token-after)
              + token-start xmltok-start
              + token-type xmltok-type)
              + (goto-char token-end)
              + (and (memq token-type '(end-tag partial-end-tag))
              (nxml-scan-element-backward
              (point)
              nil
              @@ -1538,9 +1538,8 @@
              ;; Use nxml-child-indent less than normal
              ((progn
              (goto-char target-line-start)
              - (setq token-end (nxml-token-after))
              - (and (eq xmltok-start (point))
              - (memq xmltok-type '(end-tag partial-end-tag))
              + (and (eq token-start (point))
              + (memq token-type '(end-tag partial-end-tag))
              (save-excursion
              (goto-char token-end)
              (nxml-indent-at-end-of-line-p))))
              @@ -1548,11 +1547,46 @@
              (setq indent (- nxml-child-indent)))
              ;; Comment close on its own line
              ;; Indent relative to comment open
              - ((and (eq xmltok-type 'comment)
              + ((and (eq token-type 'comment)
              (eq token-end (+ target-line-start 3)))
              - (goto-char xmltok-start)
              + (goto-char token-start)
              (setq indent (current-column))
              - (setq absolute t)))
              + (setq absolute t))
              + ;; Inside a multi-line tag
              + ((progn
              + (goto-char target-line-start)
              + (skip-chars-backward " \t\n\r")
              + (setq token-end (nxml-token-before))
              + (or (and (memq xmltok-type '(start-tag empty-element))
              + (>= token-end target-line-start))
              + (memq xmltok-type '(partial-empty-element partial-start-tag))))
              + (let ((att (nxml-find-preceding-attribute))
              + name-start value-start value-end)
              + (when att
              + (setq name-start (xmltok-attribute-name-start att))
              + (setq value-start (xmltok-attribute-value-start att))
              + (setq value-end (xmltok-attribute-value-end att)))
              + (cond (;; Inside a partial attribute value.
              + (and value-start (not value-end))
              + (save-excursion
              + (search-backward "\"" name-start nil)
              + (setq indent (1+ (current-column)))))
              + ;; Inside a complete attribute value
              + ((and value-start (<= target-line-start value-end))
              + (save-excursion
              + (goto-char value-start)
              + (setq indent (current-column))))
              + ;; Not in an attribute value.
              + (t
              + (goto-char xmltok-start)
              + (setq indent
              + (or (save-excursion
              + (skip-chars-forward "^ \t\r\n")
              + (skip-chars-forward " \t")
              + (if (looking-at ".")
              + (current-column)))
              + (+ (current-column) nxml-attribute-indent))))))
              + (setq absolute t)))
              (if absolute
              indent
              (skip-chars-backward " \r\n\t")
              @@ -1578,31 +1612,6 @@
              (if (eq xmltok-type 'start-tag)
              nxml-child-indent
              0)))
              - ;; the second non-blank line of a multi-line tag
              - ((and (memq xmltok-type '(start-tag
              - empty-element
              - partial-empty-element
              - partial-start-tag))
              - (save-excursion
              - (goto-char xmltok-start)
              - (back-to-indentation)
              - (eq (point) xmltok-start))
              - (save-excursion
              - (goto-char target-line-start)
              - (skip-chars-backward " \t\r\n")
              - (back-to-indentation)
              - (eq (point) xmltok-start))
              - (<= target-line-start
              - (save-excursion
              - (goto-char token-end)
              - (skip-chars-forward " \t\r\n")
              - (point))))
              - (goto-char xmltok-start)
              - (or (save-excursion
              - (skip-chars-forward "^ \t\r\n")
              - (skip-chars-forward " \t")
              - (and (looking-at ".") (current-column)))
              - (+ (current-column) nxml-attribute-indent)))
              (;; second non-blank line of a multi-line comment
              (and (eq xmltok-type 'comment)
              (< target-line-start token-end)
            Your message has been successfully submitted and would be delivered to recipients shortly.