GNU bug report logs - #48937
13.0.12; Paragraph filling with line that ends in % followed by comment

Previous Next

Package: auctex;

Reported by: Gustavo Barros <gusbrs.2016 <at> gmail.com>

Date: Wed, 9 Jun 2021 14:59:02 UTC

Severity: normal

Found in version 13.0.12

Done: Tassilo Horn <tsdh <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 48937 in the body.
You can then email your comments to 48937 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Wed, 09 Jun 2021 14:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gustavo Barros <gusbrs.2016 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Wed, 09 Jun 2021 14:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gustavo Barros <gusbrs.2016 <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: 13.0.12; Paragraph filling with line that ends in % followed by
 comment 
Date: Wed, 09 Jun 2021 11:58:46 -0300
Hi All,

When a paragraph containing a line whose text ends with a "legit" `\%' 
and is followed by a comment, paragraph filling joins the following 
paragraph content into the comment, when it shouldn't.

An ECM to reproduce the issue is: start `emacs -Q'.

Do an initial setup:
#+begin_src emacs-lisp
(add-to-list 'load-path "~/.emacs.d/elpa/auctex-13.0.12")
(load "auctex.el" nil t t)
(setq TeX-parse-self t)
(setq TeX-auto-save t)
#+end_src

Visit a `.tex' file with contents ("|" represents point position):

#+begin_src latex
\documentclass{article}

\begin{document}

|Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  Ut purus 
elit,
vestibulum ut, placerat ac, adipiscing vitae, felis.  Curabitur dictum 
gravida
mauris.  Nam arcu libero, nonummy eget, consectetuer id, vulputate a, 
magna.
Donec vehicula augue eu neque.  Pellentesque habitant morbi tristique 
senectus
et netus et malesuada fames ac turpis egestas. 35\% % FIXME check this 
number
Mauris ut leo.  Cras viverra metus rhoncus sem.  Nulla et lectus 
vestibulum
urna fringilla ultrices.

\end{document}
#+end_src

and call `M-q'. The result is:

#+begin_src latex
\documentclass{article}

\begin{document}

|Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis.  Curabitur
dictum gravida mauris.  Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna.  Donec vehicula augue eu neque.  Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas.
35\% % FIXME check this number Mauris ut leo.  Cras viverra metus 
rhoncus sem.  Nulla et lectus vestibulum urna fringilla ultrices.

\end{document}
#+end_src

Resulting in the undesired effect of the rest of the paragraph being 
joined into the comment, of which it was not part before the filling.

(Note that this message may get filled (format-flowed) by the MUA, so 
that the examples might not be immediately displayed as expected. Please 
take that into consideration. I do hope it is still 
understandable/reproducible.)

Best regards,
Gustavo.




Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Wed, 09 Jun 2021 19:36:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Gustavo Barros <gusbrs.2016 <at> gmail.com>
Cc: bug-auctex <at> gnu.org, 48937 <at> debbugs.gnu.org
Subject: Re: bug#48937: 13.0.12; Paragraph filling with line that ends in %
 followed by comment
Date: Wed, 09 Jun 2021 21:05:43 +0200
Gustavo Barros <gusbrs.2016 <at> gmail.com> writes:

Hi Gustavo,

> When a paragraph containing a line whose text ends with a "legit" `\%'
> and is followed by a comment, paragraph filling joins the following
> paragraph content into the comment, when it shouldn't.

Indeed, that's a corner case nobody has bothered to handle yet.  I've
pushed a fix to master.  Please give it a try.

If you don't have a git checkout handy, you can also `eval-defun' the
function below containing the fix.

Bye,
Tassilo

--8<---------------cut here---------------start------------->8---
(defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag)
  "Fill region as one paragraph.
Break lines to fit `fill-column', but leave all lines ending with
\\\\ \(plus its optional argument) alone.  Lines with code
comments and lines ending with `\\par' are included in filling but
act as boundaries.  Prefix arg means justify too.  From program,
pass args FROM, TO and JUSTIFY-FLAG.

You can disable filling inside a specific environment by adding
it to `LaTeX-indent-environment-list', only indentation is
performed in that case."
  (interactive "*r\nP")
  (let ((end-marker (save-excursion (goto-char to) (point-marker))))
    (if (or (assoc (LaTeX-current-environment) LaTeX-indent-environment-list)
            (member (TeX-current-macro) LaTeX-fill-excluded-macros)
            ;; This could be generalized, if there are more cases where
            ;; a special string at the start of a region to fill should
            ;; inhibit filling.
            (progn (save-excursion (goto-char from)
                                   (looking-at (concat TeX-comment-start-regexp
                                                       "+[ \t]*"
                                                       "Local Variables:")))))
        ;; Filling disabled, only do indentation.
        (indent-region from to nil)
      (save-restriction
        (goto-char from)
        (while (< (point) end-marker)
          (if (re-search-forward
               (concat "\\("
                       ;; Code comments.
                       "\\([^ \r\n%\\]\\|\\\\%\\)\\([ \t]\\|\\\\\\\\\\)*"
                       "[^\r\n\\]" TeX-comment-start-regexp
                       "\\|"
                       ;; Lines ending with `\par'.
                       "\\(\\=\\|[^" TeX-esc "\n]\\)\\("
                       (regexp-quote (concat TeX-esc TeX-esc))
                       "\\)*"
                       (regexp-quote TeX-esc) "par[ \t]*"
                       "\\({[ \t]*}\\)?[ \t]*$"
                       "\\)\\|\\("
                       ;; Lines ending with `\\'.
                       (regexp-quote TeX-esc)
                       (regexp-quote TeX-esc)
                       "\\(\\s-*\\*\\)?"
                       "\\(\\s-*\\[[^]]*\\]\\)?"
                       "\\s-*$\\)")
               end-marker t)
              (progn
                (goto-char (line-end-position))
                (delete-horizontal-space)
                ;; I doubt very much if we want justify -
                ;; this is a line with \\
                ;; if you think otherwise - uncomment the next line
                ;; (and justify-flag (justify-current-line))
                (forward-char)
                ;; keep our position in a buffer
                (save-excursion
                  ;; Code comments and lines ending with `\par' are
                  ;; included in filling.  Lines ending with `\\' are
                  ;; skipped.
                  (if (match-string 1)
                      (LaTeX-fill-region-as-para-do from (point) justify-flag)
                    (LaTeX-fill-region-as-para-do
                     from (line-beginning-position 0) justify-flag)
                    ;; At least indent the line ending with `\\'.
                    (indent-according-to-mode)))
                (setq from (point)))
            ;; ELSE part follows - loop termination relies on a fact
            ;; that (LaTeX-fill-region-as-para-do) moves point past
            ;; the filled region
            (LaTeX-fill-region-as-para-do from end-marker justify-flag)))))))
--8<---------------cut here---------------end--------------->8---





Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Wed, 09 Jun 2021 19:36:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 01:12:01 GMT) Full text and rfc822 format available.

Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gustavo Barros <gusbrs.2016 <at> gmail.com>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: bug-auctex <at> gnu.org, 48937 <at> debbugs.gnu.org
Subject: Re: bug#48937: 13.0.12; Paragraph filling with line that ends in %
 followed by comment
Date: Wed, 09 Jun 2021 22:11:40 -0300
Hi Tassilo,

On Wed, 09 Jun 2021 at 16:05, Tassilo Horn <tsdh <at> gnu.org> wrote:

> Indeed, that's a corner case nobody has bothered to handle yet.  I've
> pushed a fix to master.  Please give it a try.
>
> If you don't have a git checkout handy, you can also `eval-defun' the
> function below containing the fix.

Thank you very much for the quick answer and fix.

I did try it out, and I admit that that regexp is a little daunting to 
me.  But I was particularly not understanding why the "[^\r\n\\]" before 
`TeX-comment-start-regexp' in the patch. I still don't get its intent 
well, but I could get it to fail again by a small adjustment of the ECM, 
namely by removing the space between the `\%' and the comment character, 
so that we have `\%%'. This case fails to match because "[^\r\n\\]" must 
include one character before `TeX-comment-start-regexp'.

#+begin_src latex
\documentclass{article}

\begin{document}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis.  Curabitur
dictum gravida mauris.  Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna.  Donec vehicula augue eu neque.  Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas. 35\%% FIXME check this number
Mauris ut leo.  Cras viverra metus rhoncus sem.  Nulla et lectus
vestibulum urna fringilla ultrices.

\end{document}
#+end_src

Bye,
Gustavo.




Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 01:12:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 05:23:02 GMT) Full text and rfc822 format available.

Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Gustavo Barros <gusbrs.2016 <at> gmail.com>
Cc: bug-auctex <at> gnu.org, 48937 <at> debbugs.gnu.org
Subject: Re: bug#48937: 13.0.12; Paragraph filling with line that ends in %
 followed by comment
Date: Thu, 10 Jun 2021 07:20:16 +0200
Gustavo Barros <gusbrs.2016 <at> gmail.com> writes:

Hi Gustavo,

>> Indeed, that's a corner case nobody has bothered to handle yet.  I've
>> pushed a fix to master.  Please give it a try.
>>
>> If you don't have a git checkout handy, you can also `eval-defun' the
>> function below containing the fix.
>
> Thank you very much for the quick answer and fix.
>
> I did try it out, and I admit that that regexp is a little daunting to
> me.  But I was particularly not understanding why the "[^\r\n\\]"
> before `TeX-comment-start-regexp' in the patch.

Indeed, that was a leftover from playing with the regexp which isn't
needed and produces the problem you describe below.

> I still don't get its intent well, but I could get it to fail again by
> a small adjustment of the ECM, namely by removing the space between
> the `\%' and the comment character, so that we have `\%%'.

Right.  Should be fixed in git master or with the new definition below.

--8<---------------cut here---------------start------------->8---
(defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag)
  "Fill region as one paragraph.
Break lines to fit `fill-column', but leave all lines ending with
\\\\ \(plus its optional argument) alone.  Lines with code
comments and lines ending with `\\par' are included in filling but
act as boundaries.  Prefix arg means justify too.  From program,
pass args FROM, TO and JUSTIFY-FLAG.

You can disable filling inside a specific environment by adding
it to `LaTeX-indent-environment-list', only indentation is
performed in that case."
  (interactive "*r\nP")
  (let ((end-marker (save-excursion (goto-char to) (point-marker))))
    (if (or (assoc (LaTeX-current-environment) LaTeX-indent-environment-list)
            (member (TeX-current-macro) LaTeX-fill-excluded-macros)
            ;; This could be generalized, if there are more cases where
            ;; a special string at the start of a region to fill should
            ;; inhibit filling.
            (progn (save-excursion (goto-char from)
                                   (looking-at (concat TeX-comment-start-regexp
                                                       "+[ \t]*"
                                                       "Local Variables:")))))
        ;; Filling disabled, only do indentation.
        (indent-region from to nil)
      (save-restriction
        (goto-char from)
        (while (< (point) end-marker)
          (if (re-search-forward
               (concat "\\("
                       ;; Code comments.
                       "\\([^ \r\n%\\]\\|\\\\%\\)\\([ \t]\\|\\\\\\\\\\)*"
                       TeX-comment-start-regexp
                       "\\|"
                       ;; Lines ending with `\par'.
                       "\\(\\=\\|[^" TeX-esc "\n]\\)\\("
                       (regexp-quote (concat TeX-esc TeX-esc))
                       "\\)*"
                       (regexp-quote TeX-esc) "par[ \t]*"
                       "\\({[ \t]*}\\)?[ \t]*$"
                       "\\)\\|\\("
                       ;; Lines ending with `\\'.
                       (regexp-quote TeX-esc)
                       (regexp-quote TeX-esc)
                       "\\(\\s-*\\*\\)?"
                       "\\(\\s-*\\[[^]]*\\]\\)?"
                       "\\s-*$\\)")
               end-marker t)
              (progn
                (goto-char (line-end-position))
                (delete-horizontal-space)
                ;; I doubt very much if we want justify -
                ;; this is a line with \\
                ;; if you think otherwise - uncomment the next line
                ;; (and justify-flag (justify-current-line))
                (forward-char)
                ;; keep our position in a buffer
                (save-excursion
                  ;; Code comments and lines ending with `\par' are
                  ;; included in filling.  Lines ending with `\\' are
                  ;; skipped.
                  (if (match-string 1)
                      (LaTeX-fill-region-as-para-do from (point) justify-flag)
                    (LaTeX-fill-region-as-para-do
                     from (line-beginning-position 0) justify-flag)
                    ;; At least indent the line ending with `\\'.
                    (indent-according-to-mode)))
                (setq from (point)))
            ;; ELSE part follows - loop termination relies on a fact
            ;; that (LaTeX-fill-region-as-para-do) moves point past
            ;; the filled region
            (LaTeX-fill-region-as-para-do from end-marker justify-flag)))))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 05:23:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 11:02:02 GMT) Full text and rfc822 format available.

Message #26 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gustavo Barros <gusbrs.2016 <at> gmail.com>
To: Tassilo Horn <tsdh <at> gnu.org>
Cc: bug-auctex <at> gnu.org, 48937 <at> debbugs.gnu.org
Subject: Re: bug#48937: 13.0.12; Paragraph filling with line that ends in %
 followed by comment
Date: Thu, 10 Jun 2021 08:01:33 -0300
Hi Tassilo,

On Thu, 10 Jun 2021 at 02:20, Tassilo Horn <tsdh <at> gnu.org> wrote:

> Right.  Should be fixed in git master or with the new definition 
> below.

Now I do understand that part of the regexp. And it looks good to me.
Thank you very much once again.

Bye,
Gustavo.





Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 11:02:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#48937; Package auctex. (Thu, 10 Jun 2021 11:43:01 GMT) Full text and rfc822 format available.

Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Gustavo Barros <gusbrs.2016 <at> gmail.com>
Cc: bug-auctex <at> gnu.org, 48937-done <at> debbugs.gnu.org
Subject: Re: bug#48937: 13.0.12; Paragraph filling with line that ends in %
 followed by comment
Date: Thu, 10 Jun 2021 13:41:39 +0200
>> Right.  Should be fixed in git master or with the new definition below.
>
> Now I do understand that part of the regexp. And it looks good to me.
> Thank you very much once again.

You are welcome.  I'm closing this issue now.

Bye,
Tassilo





Reply sent to Tassilo Horn <tsdh <at> gnu.org>:
You have taken responsibility. (Thu, 10 Jun 2021 11:43:01 GMT) Full text and rfc822 format available.

Notification sent to Gustavo Barros <gusbrs.2016 <at> gmail.com>:
bug acknowledged by developer. (Thu, 10 Jun 2021 11:43:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 09 Jul 2021 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 42 days ago.

Previous Next


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