Hi
I see this bug isn't fixed in Emacs 30. Is it possible to fix? The right solution is to update nxml-compute-indent-in-delimited-token to contain "(while (looking-at "^[[:blank:]]*$") (forward-line -1))" to obtain the correct indentation level for text in xml
comments when there's blank lines.
(cond ((let ((end (+ pos (length close-delim))))
(and (<= end (point-max))
(string= (buffer-substring-no-properties pos end)
close-delim)))
(goto-char xmltok-start))
((progn
(goto-char pos)
(forward-line -1)
+ (while (looking-at "^[[:blank:]]*$")
+ (forward-line -1))
(<= (point) xmltok-start))
(goto-char (+ xmltok-start (length open-delim)))
(when (and (string= open-delim "<!--")
(looking-at " "))
(goto-char (1+ (point)))))
(t (back-to-indentation)))
(current-column))
For test cases, create foo.xml containing:
<foo>
<!--
bar
foo
-->
</foo>
An indent (TAB key) on the "foo" line should align it with the bar.
For test cases, create two versions of foo.xml, the first where there is a completely empty line between the bar and foo lines. The other version of foo.xml should have the line between bar and foo containing a few spaces.
Thanks
John
From: John Ciolfi <ciolfi@mathworks.com>
Sent: Wednesday, October 2, 2024 7:59 AM
To: Stefan Kangas <stefankangas@gmail.com>; Eli Zaretskii <eliz@gnu.org>
Cc: rpluim@gmail.com <rpluim@gmail.com>; 73206@debbugs.gnu.org <73206@debbugs.gnu.org>
Subject: Re: bug#73206: 28.2; xml comment with blank lines to do not indent correctly, nxml-mode.el
Hi
Using "^$" or "^[[:blank:]]*$" is fine. The difference is very minor. Consider foo.xml where the visibly "empty" line contains a single space and foo starts on the 1st column:
<foo>
<!--
bar
foo
-->
</foo>
When using "^$" and you type tab on the foo line, you'll get the following where foo starts on the 2nd column:
<foo>
<!--
bar
foo
-->
</foo>
If you use "^[[:blank:]]*$, you'll get what I expected:
<foo>
<!--
bar
foo
-->
</foo>
However, if you select all and indent-region, C-M-\ on the original you'll get the expected result with either "^$" or "^[[:blank:]]*$ because nxml-mode will pad out the space line. If the "empty" line truly blank (no spaces or tabs), then the two regex's behave
identical.
I suggest for test cases, two versions of foo.xml where one version of it has the empty line truly blank (no spaces or tabs) and the other version contains a space in the "empty" line.
You can use the attached nxml-mode-indent-fix.el which overrides the broken function to try things out on a stock Emacs, emacs -Q.
Thanks
John
From: Stefan Kangas <stefankangas@gmail.com>
Sent: Sunday, September 29, 2024 4:47 PM
To: Eli Zaretskii <eliz@gnu.org>; John Ciolfi <ciolfi@mathworks.com>
Cc: rpluim@gmail.com <rpluim@gmail.com>; 73206@debbugs.gnu.org <73206@debbugs.gnu.org>
Subject: Re: bug#73206: 28.2; xml comment with blank lines to do not indent correctly, nxml-mode.el
Eli Zaretskii <eliz@gnu.org> writes:
> Stefan, does the patch with the regexp fix look correct to you?
If we want to "keep going back until we see a non-blank line", surely
the fragment should read:
(while (looking-at "^$")
(forward-line -1))
Since
(looking-at "^[[:blank:]]*$")
will match both blank lines, and lines containing only blank space.
Which of the two do we want here?
I think it would also be good to add one or more tests here.