GNU bug report logs - #73206
28.2; xml comment with blank lines to do not indent correctly, nxml-mode.el

Previous Next

Package: emacs;

Reported by: ciolfi <at> mathworks.com

Date: Thu, 12 Sep 2024 18:04:03 UTC

Severity: normal

Found in version 28.2

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: John Ciolfi <ciolfi <at> mathworks.com>
To: Stefan Kangas <stefankangas <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: "73206 <at> debbugs.gnu.org" <73206 <at> debbugs.gnu.org>, "rpluim <at> gmail.com" <rpluim <at> gmail.com>
Subject: bug#73206: 28.2; xml comment with blank lines to do not indent correctly, nxml-mode.el
Date: Wed, 30 Apr 2025 10:55:07 +0000
[Message part 1 (text/plain, inline)]
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 <at> mathworks.com>
Sent: Wednesday, October 2, 2024 7:59 AM
To: Stefan Kangas <stefankangas <at> gmail.com>; Eli Zaretskii <eliz <at> gnu.org>
Cc: rpluim <at> gmail.com <rpluim <at> gmail.com>; 73206 <at> debbugs.gnu.org <73206 <at> 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 <at> gmail.com>
Sent: Sunday, September 29, 2024 4:47 PM
To: Eli Zaretskii <eliz <at> gnu.org>; John Ciolfi <ciolfi <at> mathworks.com>
Cc: rpluim <at> gmail.com <rpluim <at> gmail.com>; 73206 <at> debbugs.gnu.org <73206 <at> 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 <at> 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.

[Message part 2 (text/html, inline)]

This bug report was last modified 11 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.