all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#7937: nxml-mode.el indenting wrong when more than one <> on a line
@ 2011-01-29 21:47 jidanni
  2019-10-14 15:41 ` Stefan Kangas
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: jidanni @ 2011-01-29 21:47 UTC (permalink / raw)
  To: 7937

The nxml-mode indenting (C-x h TAB) is wrong as can be seen by the
</Folder></Folder> lining up on top of themselves, etc.
emacs-version "24.0.50.1" http://jidanni.org/comp/configuration/

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Folder><name>噪音 Noise</name><description>http://jidanni.org/me/quiet.html</description>
    <Folder><name>慶福街 1-3 Qingfu St.</name>
    <Placemark><name>Luo Yuntian</name><LineString><coordinates>
    120.868205,24.176483 120.865225,24.181802</coordinates></LineString></Placemark>
    </Folder>
    <Folder><name>慶福街 1-6 Qingfu St.</name>
    <Placemark><name>Chen Chunlai</name><LineString><coordinates>
    120.877008,24.187393 120.866215,24.181668</coordinates></LineString></Placemark>
    </Folder>
    </Folder>
  </Document>
</kml>





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#7937: nxml-mode.el indenting wrong when more than one <> on a line
  2011-01-29 21:47 bug#7937: nxml-mode.el indenting wrong when more than one <> on a line jidanni
@ 2019-10-14 15:41 ` Stefan Kangas
  2019-10-18  8:19 ` 積丹尼 Dan Jacobson
  2023-03-28 19:05 ` bug#7937: nxml-mode indenting bug fix Stephen Meister
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2019-10-14 15:41 UTC (permalink / raw)
  To: 積丹尼 Dan Jacobson; +Cc: 7937

jidanni@jidanni.org writes:

> The nxml-mode indenting (C-x h TAB) is wrong as can be seen by the
> </Folder></Folder> lining up on top of themselves, etc.
> emacs-version "24.0.50.1" http://jidanni.org/comp/configuration/
>
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://www.opengis.net/kml/2.2">
>   <Document>
>     <Folder><name>噪音 Noise</name><description>http://jidanni.org/me/quiet.html</description>
>     <Folder><name>慶福街 1-3 Qingfu St.</name>
>     <Placemark><name>Luo Yuntian</name><LineString><coordinates>
>     120.868205,24.176483 120.865225,24.181802</coordinates></LineString></Placemark>
>     </Folder>
>     <Folder><name>慶福街 1-6 Qingfu St.</name>
>     <Placemark><name>Chen Chunlai</name><LineString><coordinates>
>     120.877008,24.187393 120.866215,24.181668</coordinates></LineString></Placemark>
>     </Folder>
>     </Folder>
>   </Document>
> </kml>

What's the expected indentation here?

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#7937: nxml-mode.el indenting wrong when more than one <> on a line
  2011-01-29 21:47 bug#7937: nxml-mode.el indenting wrong when more than one <> on a line jidanni
  2019-10-14 15:41 ` Stefan Kangas
@ 2019-10-18  8:19 ` 積丹尼 Dan Jacobson
  2020-08-07 10:32   ` Lars Ingebrigtsen
  2023-03-28 19:05 ` bug#7937: nxml-mode indenting bug fix Stephen Meister
  2 siblings, 1 reply; 6+ messages in thread
From: 積丹尼 Dan Jacobson @ 2019-10-18  8:19 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 7937

>>>>> "SK" == Stefan Kangas <stefan@marxist.se> writes:

SK> What's the expected indentation here?

Simple:
<Folder>
   <Folder>
etc.

We didn't close the Folder tag, so it has no "right" not to indent it!





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#7937: nxml-mode.el indenting wrong when more than one <> on a line
  2019-10-18  8:19 ` 積丹尼 Dan Jacobson
@ 2020-08-07 10:32   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-07 10:32 UTC (permalink / raw)
  To: 積丹尼 Dan Jacobson; +Cc: Stefan Kangas, 7937

積丹尼 Dan Jacobson <jidanni@jidanni.org> writes:

>>>>>> "SK" == Stefan Kangas <stefan@marxist.se> writes:
>
> SK> What's the expected indentation here?
>
> Simple:
> <Folder>
>    <Folder>
> etc.
>
> We didn't close the Folder tag, so it has no "right" not to indent it!

This bug is still present in Emacs 28.1.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#7937: nxml-mode indenting bug fix.
  2011-01-29 21:47 bug#7937: nxml-mode.el indenting wrong when more than one <> on a line jidanni
  2019-10-14 15:41 ` Stefan Kangas
  2019-10-18  8:19 ` 積丹尼 Dan Jacobson
@ 2023-03-28 19:05 ` Stephen Meister
  2023-03-30  6:56   ` Eli Zaretskii
  2 siblings, 1 reply; 6+ messages in thread
From: Stephen Meister @ 2023-03-28 19:05 UTC (permalink / raw)
  To: 7937


[-- Attachment #1.1: Type: text/plain, Size: 752 bytes --]

Hi,
  I've tried to put a fix in place for bug 7937 (and possibly 7768
unintentionally).  The repair I've made will cause changes in the way that
nxml indents lines under normal circumstances.  I'm not sure if a change
like this is acceptable given that I'm only trying to fix a bug.  The
behavior change is most visible in a situation such as:

<root>
  <a><b><c>
    inner
  </c>
</b>
  </a>
</root>

Which would now be indented as:
<root>
  <a><b><c>
        inner
      </c>
    </b>
  </a>
</root>

There are additional tests which show more of the indenting changes as well.

This is my first bug fix, please let me know if I've missed anything
(procedurally or otherwise).  I'm happy to rework/restructure this based on
any suggestions.

-steve

[-- Attachment #1.2: Type: text/html, Size: 1134 bytes --]

[-- Attachment #2: bug7937.patch --]
[-- Type: text/x-patch, Size: 8619 bytes --]

diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 3869d0327fd..74108fa9d73 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -1327,7 +1327,8 @@ nxml-compute-indent-from-matching-start-tag
 its line.  Otherwise return nil."
   (save-excursion
     (back-to-indentation)
-    (let ((bol (point)))
+    (let ((bol (point))
+          bol-token-type)
       (let ((inhibit-field-text-motion t))
 	(end-of-line))
       (skip-chars-backward " \t")
@@ -1338,6 +1339,7 @@ nxml-compute-indent-from-matching-start-tag
 	       (save-excursion
 		 (goto-char bol)
 		 (nxml-token-after)
+                 (setq bol-token-type xmltok-type)
 		 (= xmltok-start bol))
 	       (eq xmltok-type 'data))
 	   (condition-case nil
@@ -1352,15 +1354,19 @@ nxml-compute-indent-from-matching-start-tag
 	     (goto-char xmltok-start)
 	     (skip-chars-backward " \t")
 	     (bolp))
-	   (current-indentation)))))
+	   (+ (current-indentation)
+              ;; in the case of a line starting with data, keep the
+              ;; indent level above the starting tag.
+              (if (eq bol-token-type 'data)
+                  nxml-child-indent
+                0))))))
 
 (defun nxml-compute-indent-from-previous-line ()
   "Compute the indent for a line using the indentation of a previous line."
   (save-excursion
     (end-of-line)
     (let ((eol (point))
-	  bol prev-bol ref
-	  before-context after-context)
+	  bol prev-bol ref)
       (back-to-indentation)
       (setq bol (point))
       (catch 'indent
@@ -1378,60 +1384,48 @@ nxml-compute-indent-from-previous-line
 		   (not (or (= xmltok-start (point))
 			    (eq xmltok-type 'data))))))
 	(setq ref (point))
-	;; Now scan over tokens until the end of the line to be indented.
-	;; Determine the context before and after the beginning of the
-	;; line.
-	(while (< (point) eol)
-	  (nxml-tokenize-forward)
-	  (cond ((<= bol xmltok-start)
-		 (setq after-context
-		       (nxml-merge-indent-context-type after-context)))
-		((and (<= (point) bol)
-		      (not (and (eq xmltok-type 'partial-start-tag)
-				(= (point) bol))))
-		 (setq before-context
-		       (nxml-merge-indent-context-type before-context)))
-		((eq xmltok-type 'data)
-		 (setq before-context
-		       (nxml-merge-indent-context-type before-context))
-		 (setq after-context
-		       (nxml-merge-indent-context-type after-context)))
-		;; If in the middle of a token that looks inline,
-		;; then indent relative to the previous non-blank line
-		((eq (nxml-merge-indent-context-type before-context)
-		     'mixed)
-		 (goto-char prev-bol)
-		 (throw 'indent (current-column)))
-		(t
-		 (throw 'indent
-			(nxml-compute-indent-in-token bol))))
-	  (skip-chars-forward " \t\r\n"))
-	(goto-char ref)
-	(+ (current-column)
-	   (* nxml-child-indent
-	      (+ (if (eq before-context 'start-tag) 1 0)
-		 (if (eq after-context 'end-tag) -1 0))))))))
-
-(defun nxml-merge-indent-context-type (context)
-  "Merge the indent context type CONTEXT with the token in `xmltok-type'.
-Return the merged indent context type.  An indent context type is
-either nil or one of the symbols `start-tag', `end-tag', `markup',
-`comment', `mixed'."
-  (cond ((memq xmltok-type '(start-tag partial-start-tag))
-	 (if (memq context '(nil start-tag comment))
-	     'start-tag
-	   'mixed))
-	((memq xmltok-type '(end-tag partial-end-tag))
-	 (if (memq context '(nil end-tag comment))
-	     'end-tag
-	   'mixed))
-	((eq xmltok-type 'comment)
-	 (cond ((memq context '(start-tag end-tag comment))
-		context)
-	       (context 'mixed)
-	       (t 'comment)))
-	(context 'mixed)
-	(t 'markup)))
+        (let ((depth-before 0)
+              (depth-after 0)
+              start-type-before)
+          (nxml-tokenize-forward)
+          (when (> (point) bol)         ; one token spans this and the line before
+            (throw 'indent (nxml-compute-indent-in-token bol)))
+          
+          ;; Scan over the prevous line to determine the change in element depth
+          (setq start-type-before xmltok-type)
+          (while (< (point) bol)        ; examine all tags on the previous line
+            (cond ((eq xmltok-type 'partial-start-tag)
+                   (throw 'indent (nxml-compute-indent-in-token bol)))
+                  ((eq xmltok-type 'start-tag)
+                   (cl-incf depth-before))
+                  ((eq xmltok-type 'end-tag)
+                   (cl-incf depth-before -1)))
+            (skip-chars-forward " \t\r\n")
+            (nxml-tokenize-forward))
+          
+          ;; Scan over the current line to determine the change in element depth
+          (while (and (<= (point) eol)        ; examine all tags on the current line.
+                      (< (point) (point-max)))
+            (cond ((eq  xmltok-type 'start-tag)
+                   (cl-incf depth-after))
+                  ((eq xmltok-type 'end-tag)
+                   (cl-incf depth-after -1)))
+            (skip-chars-forward " \t\r\n")
+            (nxml-tokenize-forward))
+          
+          (goto-char ref)
+	  (+ (current-column)
+	     (* nxml-child-indent
+                (+ (max 0 depth-before)
+                   (min 0 depth-after)
+                   ;; if our before-line started as a data element we
+                   ;; must back out that indentation as well as long
+                   ;; as we are not beginning additional tags
+                   (if (and (memq start-type-before '(data cdata-section))
+                            (>= depth-after 0)
+                            (< depth-before 0))
+                       -1
+                     0)))))))))
 
 (defun nxml-compute-indent-in-token (pos)
   "Return the indent for a line that starts inside a token.
diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el
index 973f2ebb67e..532c39e8608 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -31,6 +31,17 @@ nxml-mode-tests-correctly-indented-string
 
 (ert-deftest nxml-indent-line-after-attribute ()
   (should (nxml-mode-tests-correctly-indented-string "
+<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"
+          xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+          xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0
+                              https://maven.apache.org/xsd/settings-1.0.0.xsd\">
+  <mirrors one=\"two\"
+           three=\"four\">
+    ...
+  </mirrors>
+</settings>
+"))
+  (should (nxml-mode-tests-correctly-indented-string "
 <settings
     xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"
     xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
@@ -155,5 +166,100 @@ nxml-mode-test-comment-bug-17264
       ;; Inside comment
       (should (eq (nth 4 (syntax-ppss)) t)))))
 
+(ert-deftest nxml-mode-test-indent-line-after-data ()
+  "Test indenting of lines after data or cdata"
+  (should (nxml-mode-tests-correctly-indented-string "
+<kml>
+  <description>
+    more</description>
+  <abc>data</abc>
+
+  <description>
+    more
+    <abc>data</abc>
+  </description>
+
+  <description>
+    more
+    <abc>
+      data
+    </abc>
+  </description>
+
+  <description>
+    <![CDATA[multi
+             line
+             data]]></description>
+  <abc>data</abc>
+
+  <description>
+    <![CDATA[multi
+             line
+             data]]>
+    <abc>data</abc>
+  </description>
+  <description>
+    <![CDATA[multi
+             line
+             data]]>
+    <abc>
+      data
+    </abc>
+  </description>
+</kml>
+")))
+
+
+(ert-deftest nxml-mode-test-multiple-start-tags-single-line ()
+  "Test for indent depth where multiple tags are on one line."
+  (should (nxml-mode-tests-correctly-indented-string "
+<kml>
+  <Document>
+    <Folder><name>abc</name>
+      <Folder><name>123</name>
+      </Folder>
+    </Folder>
+  </Document>
+</kml>"))
+  (should (nxml-mode-tests-correctly-indented-string "
+<kml>
+  <Document>
+    <Folder><name>abc</name>
+      <Folder></Folder>
+    </Folder>
+  </Document>
+</kml>"))
+  (should (nxml-mode-tests-correctly-indented-string "
+<kml>
+  <document></document>
+  <elm>
+    data
+  </elmh>
+  <a><b><c>
+        <d>data</d>
+  </c></b></a>
+  <a><b><c><inner /><d>
+          <e></e>
+  </d><inner /></c></b></a>
+  <single />
+  <one><two><three>
+        four
+      </three>
+    </two>
+  </one>
+  <one>
+    <two>
+      <three>
+        four
+  </three></two></one>
+  <one><two>
+      three<four>
+        five
+      </four>
+    </two>
+  </one>
+</kml>
+")))
+
 (provide 'nxml-mode-tests)
 ;;; nxml-mode-tests.el ends here

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#7937: nxml-mode indenting bug fix.
  2023-03-28 19:05 ` bug#7937: nxml-mode indenting bug fix Stephen Meister
@ 2023-03-30  6:56   ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2023-03-30  6:56 UTC (permalink / raw)
  To: Stephen Meister; +Cc: 7937

> From: Stephen Meister <pallagun@gmail.com>
> Date: Tue, 28 Mar 2023 15:05:05 -0400
> 
>   I've tried to put a fix in place for bug 7937 (and possibly 7768 unintentionally).  The repair I've made will
> cause changes in the way that nxml indents lines under normal circumstances.  I'm not sure if a change like
> this is acceptable given that I'm only trying to fix a bug.  The behavior change is most visible in a situation
> such as:
> 
> <root>
>   <a><b><c>
>     inner
>   </c>
> </b>
>   </a>
> </root>
> 
> Which would now be indented as:
> <root>
>   <a><b><c>
>         inner
>       </c>
>     </b>
>   </a>
> </root>

Sounds like the new behavior is better.  So I'm okay with this change
in behavior.

> This is my first bug fix, please let me know if I've missed anything (procedurally or otherwise).  I'm happy to
> rework/restructure this based on any suggestions.

Thanks, please see a few minor comments below.

> diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
> index 3869d0327fd..74108fa9d73 100644
> --- a/lisp/nxml/nxml-mode.el
> +++ b/lisp/nxml/nxml-mode.el

Please accompany the patches with a ChangeLog-style commit log
message.  The file CONTRIBUTE in the Emacs source tree describes our
conventions for writing log messages, and you can use "git log" to see
these conventions in action in our repository.

Also, please try to use "git format-patch" to format the patches, as
that makes it easier for us to install the patches.

> @@ -1352,15 +1354,19 @@ nxml-compute-indent-from-matching-start-tag
>  	     (goto-char xmltok-start)
>  	     (skip-chars-backward " \t")
>  	     (bolp))
> -	   (current-indentation)))))
> +	   (+ (current-indentation)
> +              ;; in the case of a line starting with data, keep the
> +              ;; indent level above the starting tag.

Comments should start with a capitalized letter.

> +          (nxml-tokenize-forward)
> +          (when (> (point) bol)         ; one token spans this and the line before
> +            (throw 'indent (nxml-compute-indent-in-token bol)))
> +          
> +          ;; Scan over the prevous line to determine the change in element depth
> +          (setq start-type-before xmltok-type)
> +          (while (< (point) bol)        ; examine all tags on the previous line

Comments should end with a period (i.e., should be full English
sentences), and should not overflow the 80-column line length, and
preferably not the fill-column as well.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-30  6:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-29 21:47 bug#7937: nxml-mode.el indenting wrong when more than one <> on a line jidanni
2019-10-14 15:41 ` Stefan Kangas
2019-10-18  8:19 ` 積丹尼 Dan Jacobson
2020-08-07 10:32   ` Lars Ingebrigtsen
2023-03-28 19:05 ` bug#7937: nxml-mode indenting bug fix Stephen Meister
2023-03-30  6:56   ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.