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.