GNU bug report logs - #56160
13.1.3; fill breaks verbatim macros not followed with spaces

Previous Next

Package: auctex;

Reported by: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>

Date: Thu, 23 Jun 2022 10:24:01 UTC

Severity: normal

Found in version 13.1.3

Done: Ikumi Keita <ikumi <at> ikumi.que.jp>

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 56160 in the body.
You can then email your comments to 56160 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#56160; Package auctex. (Thu, 23 Jun 2022 10:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Thibaut Benjamin <thibaut.benjamin <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Thu, 23 Jun 2022 10:24:02 GMT) Full text and rfc822 format available.

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

From: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: 13.1.3; fill breaks verbatim macros not followed with spaces
Date: Thu, 23 Jun 2022 11:00:42 +0200
[Message part 1 (text/plain, inline)]
The behavior of LaTeX-fill-* seems to break when used with a verbatim
macro which is not followed by a space.

A minimal example is a TeX file containing only the following line

> Lorem ipsum dolor sit amet, consectetur adipiscing elit, \verb|sed
> do|eiusmod tempor
>
Running the LaTeX-fill-buffer command yields the following, which does not
compile since a line break is inserted inside a verbatim macro.

> Lorem ipsum dolor sit amet, consectetur adipiscing elit, \verb|sed
> do|eiusmod tempor


Adding a space after the macro solves the issue and the following file is
filled properly.

> Lorem ipsum dolor sit amet, consectetur adipiscing elit, \verb|sed do|
> eiusmod tempor
>

My original use-case was with a piece of code of the following form, where
adding the space is not really an option.

> \lstinline|a <=|~$b$
>
A possible workaround is to replace the space inside the verb macro with a
no-break space (U+00A0)

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

Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Wed, 29 Jun 2022 06:29:02 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>
Cc: 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3;
 fill breaks verbatim macros not followed with spaces
Date: Wed, 29 Jun 2022 15:28:08 +0900
[Message part 1 (text/plain, inline)]
Hi Thibaut,

>>>>> Thibaut Benjamin <thibaut.benjamin <at> gmail.com> writes:
> The behavior of LaTeX-fill-* seems to break when used with a verbatim
> macro which is not followed by a space.

> A minimal example is a TeX file containing only the following line

>> Lorem ipsum dolor sit amet, consectetur adipiscing elit, \verb|sed do|eiusmod tempor
>> 
> Running the LaTeX-fill-buffer command yields the following, which does not
> compile since a line break is inserted inside a verbatim macro.

>> Lorem ipsum dolor sit amet, consectetur adipiscing elit, \verb|sed
>> do|eiusmod tempor

Thanks for your report. I can confirm it. (My `fill-column' is 75.)

To developers:
The reason for this behavior is that `LaTeX-fill-move-to-break-point'
moves the point on the space inside "\verb|sed do|". The function
tries to avoid line break inside \verb, but it doesn't work for this case:
,----
| (defun LaTeX-fill-move-to-break-point (linebeg)
|   "Move to the position where the line should be broken."
|   (fill-move-to-break-point linebeg)
| [...]
|   ;; Cater for \verb|...| (and similar) contructs which should not be
|   ;; broken. (FIXME: Make it work with shortvrb.sty (also loaded by
|   ;; doc.sty) where |...| is allowed.  Arbitrary delimiters may be
|   ;; chosen with \MakeShortVerb{<char>}.)  This could probably be
|   ;; handled with `fill-nobreak-predicate', but this is not available
|   ;; in XEmacs.
|   (let ((final-breakpoint (point))
|         (verb-macros (regexp-opt (append (LaTeX-verbatim-macros-with-delims)
|                                          (LaTeX-verbatim-macros-with-braces)))))
|     (save-excursion
|       ;; Look for the start of a verbatim macro in the current line.
|       (when (re-search-backward (concat (regexp-quote TeX-esc)
|                                         "\\(?:" verb-macros "\\)\\([^a-z@*]\\)")
|                                 (line-beginning-position) t)
|         ;; Determine start and end of verbatim macro.
|         (let ((beg (point))
|               (end (if (not (string-match "[ [{]" (match-string 1)))
|                        (cdr (LaTeX-verbatim-macro-boundaries))
|                      (TeX-find-macro-end))))
|           ;; Determine if macro end is behind fill column.
|           (when (and end
|                      (> (- end (line-beginning-position))
|                         (current-fill-column))
|                      (> end final-breakpoint))
|             ;; Search backwards for place to break before the macro.
|             (goto-char beg)
|             (skip-chars-backward "^ \n")
|             ;; Determine if point ended up at the beginning of the line.
|             (when (save-excursion (skip-chars-backward " \t%") (bolp))
|               ;; Search forward for a place to break after the macro.
|               (goto-char end)
|               (skip-chars-forward "^ \n" (point-max)))
|             (setq final-breakpoint (point))))))
|     (goto-char final-breakpoint))
`----
In this case, the end position of "\verb|sed do|" sits before fill
column, so the conditional of `when' after the comment "Determine if
macro end is behind fill column." evaluates to nil. I suppose that this
code presumes that \verb|...| always has a space after it.

I think it's a good chance to accomplish an idea suggested in the above
comment, to make use of `fill-nobreak-predicate'; we no longer have to
cater for XEmacs.

How about the attached patch? This temporally adds `LaTeX-verbatim-p' to
`fill-nobreak-predicate' to avoid space inside \verb|...| when
`fill-move-to-break-point' is called.

Note that it would fail when the user uses tex-font.el or disables
font lock, because `LaTeX-verbatim-p' depends on the facilities of
font-latex.el.

What do you think about it?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[tentative-patch (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Wed, 29 Jun 2022 07:48:01 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3; fill breaks verbatim macros not followed
 with spaces
Date: Wed, 29 Jun 2022 09:46:59 +0200
Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> In this case, the end position of "\verb|sed do|" sits before fill
> column, so the conditional of `when' after the comment "Determine if
> macro end is behind fill column." evaluates to nil. I suppose that this
> code presumes that \verb|...| always has a space after it.
>
> I think it's a good chance to accomplish an idea suggested in the above
> comment, to make use of `fill-nobreak-predicate'; we no longer have to
> cater for XEmacs.

Thanks for looking into this.  I agree, we should switch to
`fill-nobreak-predicate'.  But have a look at this example:

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\begin{document}

Move point to ! and do
C-c RET verb RET RET
write some text RET SPC

Some text -!

And it gives you:

Some text -\verb|write
more text| 

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% fill-column: 25
%%% End:
--8<---------------cut here---------------end--------------->8---

Emacs add a line-break inside \verb which is fixed when I hit 'M-q'.

Maybe we should add this

(add-to-list (make-local-variable 'fill-nobreak-predicate)
             #'LaTeX-verbatim-p t)

to `LaTeX-common-initialization'?

> How about the attached patch? This temporally adds `LaTeX-verbatim-p' to
> `fill-nobreak-predicate' to avoid space inside \verb|...| when
> `fill-move-to-break-point' is called.

See above.

> Note that it would fail when the user uses tex-font.el or disables
> font lock, because `LaTeX-verbatim-p' depends on the facilities of
> font-latex.el.

Yes, but I think we can live with that :-)

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Thu, 30 Jun 2022 05:00:02 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3;
 fill breaks verbatim macros not followed with spaces
Date: Thu, 30 Jun 2022 13:59:25 +0900
[Message part 1 (text/plain, inline)]
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:
> Maybe we should add this

> (add-to-list (make-local-variable 'fill-nobreak-predicate)
>              #'LaTeX-verbatim-p t)

> to `LaTeX-common-initialization'?

Thanks, that makes more sense. Common rule should apply for auto fill as
well.

Then the fix should look like the attached patch.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[0001-Don-t-break-line-inside-verb-like-macro-bug-56160.patch (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Thu, 30 Jun 2022 08:31:01 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3; fill breaks verbatim macros not followed
 with spaces
Date: Thu, 30 Jun 2022 10:30:24 +0200
Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

>>>>>> Arash Esbati <arash <at> gnu.org> writes:
>> Maybe we should add this
>
>> (add-to-list (make-local-variable 'fill-nobreak-predicate)
>>              #'LaTeX-verbatim-p t)
>
>> to `LaTeX-common-initialization'?
>
> Thanks, that makes more sense. Common rule should apply for auto fill as
> well.

I'm not sure I understand the last sentence.  Can you elaborate?

> Then the fix should look like the attached patch.

LGTM.  Please go ahead and install it.

> +  ;; Cater for \verb|...| (and similar) contructs which should not be
> +  ;; broken. (FIXME: Make it work with shortvrb.sty (also loaded by
> +  ;; doc.sty) where |...| is allowed.  Arbitrary delimiters may be
> +  ;; chosen with \MakeShortVerb{<char>}.)
> +  (add-to-list (make-local-variable 'fill-nobreak-predicate)
> +               #'LaTeX-verbatim-p t)

I think we can also adjust `LaTeX-verbatim-p' to handle the FIXME.
AUCTeX doesn't parse files for \MakeShortVerb, it looks at the chars
defined in `LaTeX-shortvrb-chars' for delimiters.  We could do something
like this in `LaTeX-verbatim-p' (addition starts with (when
LaTeX-shortvrb-chars ...):

--8<---------------cut here---------------start------------->8---
(defun LaTeX-verbatim-p (&optional pos)
  "Return non-nil if position POS is in a verbatim-like construct."
  (when pos (goto-char pos))
  (save-match-data
    (or (when (fboundp 'font-latex-faces-present-p)
          (font-latex-faces-present-p 'font-latex-verbatim-face))
        (member (LaTeX-current-verbatim-macro)
                (LaTeX-verbatim-macros-with-delims))
        (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
        (member (LaTeX-current-environment) (LaTeX-verbatim-environments))
        (when LaTeX-shortvrb-chars
          (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
                 (regexp (concat "\\("
                                 (mapconcat #'regexp-quote strings "\\|")
                                 "\\)")))
            (and (save-excursion
                   (re-search-backward regexp (line-beginning-position) t))
                 (save-excursion
                   (re-search-forward (regexp-quote (match-string-no-properties 1))
                                      (line-end-position) t))))))))
--8<---------------cut here---------------end--------------->8---

This is also a small test file if you like to play with it:

--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{shortvrb}
\begin{document}
|foo| and "bar" 
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% LaTeX-shortvrb-chars: (?|)
%%% End:
--8<---------------cut here---------------end--------------->8---

WDYT?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Thu, 30 Jun 2022 15:42:02 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3; fill breaks verbatim macros not followed
 with spaces
Date: Thu, 30 Jun 2022 17:41:21 +0200
Arash Esbati <arash <at> gnu.org> writes:

> I think we can also adjust `LaTeX-verbatim-p' to handle the FIXME.
> AUCTeX doesn't parse files for \MakeShortVerb, it looks at the chars
> defined in `LaTeX-shortvrb-chars' for delimiters.  We could do something
> like this in `LaTeX-verbatim-p' (addition starts with (when
> LaTeX-shortvrb-chars ...):

Sorry, there was a thinko in my last message, next try:

--8<---------------cut here---------------start------------->8---
(defun LaTeX-verbatim-p (&optional pos)
  "Return non-nil if position POS is in a verbatim-like construct."
  (when pos (goto-char pos))
  (save-match-data
    (or (when (fboundp 'font-latex-faces-present-p)
          (font-latex-faces-present-p 'font-latex-verbatim-face))
        (member (LaTeX-current-verbatim-macro)
                (LaTeX-verbatim-macros-with-delims))
        (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
        (member (LaTeX-current-environment) (LaTeX-verbatim-environments))
        (when LaTeX-shortvrb-chars
          (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
                 (regexp (mapconcat #'regexp-quote strings "\\|"))
                 (p (point))
                 (match (save-excursion
                          (re-search-forward regexp (line-end-position) t))))
            (and match
                 (save-excursion
                   (cl-oddp (how-many regexp (line-beginning-position) p)))
                 (save-excursion
                   (cl-evenp (how-many regexp (line-beginning-position) match)))))))))
--8<---------------cut here---------------end--------------->8---

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Fri, 01 Jul 2022 04:40:01 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3;
 fill breaks verbatim macros not followed with spaces
Date: Fri, 01 Jul 2022 13:39:42 +0900
>>>>> Arash Esbati <arash <at> gnu.org> writes:
> LGTM.  Please go ahead and install it.

Done. :-)

>> Thanks, that makes more sense. Common rule should apply for auto fill as
>> well.

> I'm not sure I understand the last sentence.  Can you elaborate?

AUCTeX doesn't have its own auto fill function. If auto fill is enabled,
`do-auto-fill' does its job. Since it doesn't call
`LaTeX-fill-move-to-break-point', it pays no attention to \verb before
the latest commit.
Now that `fill-nobreak-predicate' contains `LaTeX-verbatim-p' in latex
mode buffer, `do-auto-fill', which call `fill-move-to-break-point',
obeys the same rule with respect to \verb as `LaTeX-fill-*' functions.

> I think we can also adjust `LaTeX-verbatim-p' to handle the FIXME.
> AUCTeX doesn't parse files for \MakeShortVerb, it looks at the chars
> defined in `LaTeX-shortvrb-chars' for delimiters.  We could do something
> like this in `LaTeX-verbatim-p' (addition starts with (when
> LaTeX-shortvrb-chars ...):

> Sorry, there was a thinko in my last message, next try:

This looks good to me. Some minor comments follow.

> (defun LaTeX-verbatim-p (&optional pos)
...
>         (when LaTeX-shortvrb-chars
>           (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
>                  (regexp (mapconcat #'regexp-quote strings "\\|"))

In most cases,
          (let ((regexp (concat "[" LaTeX-shortvrb-chars "]"))
would be enough. Is it necessary to take corner cases, in which
`LaTeX-shortvrb-chars' contains ?- or ?], into accounts?

>                  (p (point))
>                  (match (save-excursion
>                           (re-search-forward regexp (line-end-position) t))))
>             (and match
>                  (save-excursion
>                    (cl-oddp (how-many regexp (line-beginning-position) p)))
>                  (save-excursion
>                    (cl-evenp (how-many regexp (line-beginning-position) match)))))))))

This `cl-evenp' always evaluates to non-nil because the first
`re-search-forward' succeeded, doesn't it?

Best,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Fri, 01 Jul 2022 09:03:02 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3; fill breaks verbatim macros not followed
 with spaces
Date: Fri, 01 Jul 2022 11:01:27 +0200
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

>>>>>> Arash Esbati <arash <at> gnu.org> writes:
>
> Done. :-)

Thanks 🙏🏿

>> I'm not sure I understand the last sentence.  Can you elaborate?
>
> AUCTeX doesn't have its own auto fill function. If auto fill is enabled,
> `do-auto-fill' does its job. 

Thanks, now I understand what you meant.

>> (defun LaTeX-verbatim-p (&optional pos)
> ...
>>         (when LaTeX-shortvrb-chars
>>           (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
>>                  (regexp (mapconcat #'regexp-quote strings "\\|"))
>
> In most cases,
>           (let ((regexp (concat "[" LaTeX-shortvrb-chars "]"))
> would be enough. Is it necessary to take corner cases, in which
> `LaTeX-shortvrb-chars' contains ?- or ?], into accounts?

That was also my first approach, but then I thought I make it more
robust since we really don't know what people will choose as delimiters.
Actually, I think we have change that to:

    (regexp (concat "[^\\]" (mapconcat #'regexp-quote strings "\\|")))

to exclude things like \|, \- and \" etc.

>>                  (p (point))
>>                  (match (save-excursion
>>                           (re-search-forward regexp (line-end-position) t))))
>>             (and match
>>                  (save-excursion
>>                    (cl-oddp (how-many regexp (line-beginning-position) p)))
>>                  (save-excursion
>>                    (cl-evenp (how-many regexp (line-beginning-position) match)))))))))
>
> This `cl-evenp' always evaluates to non-nil because the first
> `re-search-forward' succeeded, doesn't it?

True, that was again only precaution.  But I think we're not done yet.
Please consider this example, and hit 'M-q' in the paragraphs once with
`font-lock-mode' enabled and once disabled:

--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{shortvrb}
\begin{document}

Lorem ipsum |dolor| sit "amet", consectetur |adipiscing elit, sed do eiusmod|
tempor incididunt ut labore et dolore magna aliqua.

Lorem ipsum |dolor| sit "amet", consectetur \verb|adipiscing elit, sed do eiusmod|
tempor incididunt ut labore et dolore magna aliqua.

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% LaTeX-shortvrb-chars: (?| ?\")
%%% End:
--8<---------------cut here---------------end--------------->8---

with this definition:

--8<---------------cut here---------------start------------->8---
(defun LaTeX-verbatim-p (&optional pos)
  "Return non-nil if position POS is in a verbatim-like construct."
  (when pos (goto-char pos))
  (save-match-data
    (or (when (fboundp 'font-latex-faces-present-p)
          (font-latex-faces-present-p 'font-latex-verbatim-face))
        (member (LaTeX-current-verbatim-macro)
                (LaTeX-verbatim-macros-with-delims))
        (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
        (member (LaTeX-current-environment) (LaTeX-verbatim-environments))
        (when LaTeX-shortvrb-chars
          (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
                 (regexp (concat "[^\\]"
                                 (mapconcat #'regexp-quote strings "\\|")))
                 (p (point))
                 (match (save-excursion
                          (re-search-forward regexp (line-end-position) t))))
            (and match
                 (save-excursion
                   (cl-oddp (how-many regexp (line-beginning-position) p)))
                 (save-excursion
                   (cl-evenp (how-many regexp (line-beginning-position) match)))))))))
--8<---------------cut here---------------end--------------->8---

With `font-lock-mode' enabled, you get this:

--8<---------------cut here---------------start------------->8---
Lorem ipsum |dolor| sit "amet",
consectetur |adipiscing elit, sed do eiusmod| tempor incididunt ut
labore et dolore magna aliqua.

Lorem ipsum |dolor| sit "amet", consectetur
\verb|adipiscing elit, sed do eiusmod| tempor incididunt ut labore et
dolore magna aliqua.
--8<---------------cut here---------------end--------------->8---

and without, you get:

--8<---------------cut here---------------start------------->8---
Lorem ipsum |dolor| sit "amet", consectetur
|adipiscing elit, sed do eiusmod| tempor incididunt ut labore et
dolore magna aliqua.

Lorem ipsum |dolor| sit "amet", consectetur
\verb|adipiscing elit, sed do eiusmod| tempor incididunt ut labore et
dolore magna aliqua.
--8<---------------cut here---------------end--------------->8---

I think the issue is that '|' has also `font-latex-verbatim-face' which
makes Emacs travel to far back when searching for the next break point.
I'm not sure what's the best approach to fix this, what do you think?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Fri, 01 Jul 2022 16:34:02 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3; fill breaks verbatim macros not followed
 with spaces
Date: Fri, 01 Jul 2022 18:33:30 +0200
Arash Esbati <arash <at> gnu.org> writes:

> I think the issue is that '|' has also `font-latex-verbatim-face' which
> makes Emacs travel to far back when searching for the next break point.
> I'm not sure what's the best approach to fix this, what do you think?

Following up myself, I think I have an idea which excludes the boundries
while looking for `font-latex-verbatim-face':

--8<---------------cut here---------------start------------->8---
(defun LaTeX-verbatim-p (&optional pos)
  "Return non-nil if position POS is in a verbatim-like construct."
  (when pos (goto-char pos))
  (save-match-data
    (or (when (and (fboundp 'font-latex-faces-present-p)
                   (bound-and-true-p font-lock-mode))
          (if (and LaTeX-shortvrb-chars
                   (member (following-char) LaTeX-shortvrb-chars))
              (let ((regexp (concat "[^" TeX-esc "]"
                                    (regexp-quote (string (following-char))))))
                (if (cl-oddp (how-many regexp (line-beginning-position) (1+ (point))))
                    (font-latex-faces-present-p 'font-latex-verbatim-face (1- (point)))
                  (font-latex-faces-present-p 'font-latex-verbatim-face (1+ (point)))))
            (font-latex-faces-present-p 'font-latex-verbatim-face)))
        (member (LaTeX-current-verbatim-macro)
                (LaTeX-verbatim-macros-with-delims))
        (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
        (member (LaTeX-current-environment) (LaTeX-verbatim-environments))
        (when LaTeX-shortvrb-chars
          (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
                 (regexp (concat "[^\\]"
                                 (mapconcat #'regexp-quote strings "\\|")))
                 (p (point))
                 (match (save-excursion
                          (re-search-forward regexp (line-end-position) t))))
            (and match
                 (save-excursion
                   (cl-oddp (how-many regexp (line-beginning-position) p)))
                 (save-excursion
                   (cl-evenp (how-many regexp (line-beginning-position) match)))))))))
--8<---------------cut here---------------end--------------->8---

Any comments welcome.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Sat, 02 Jul 2022 08:53:01 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>, 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3;
 fill breaks verbatim macros not followed with spaces
Date: Sat, 02 Jul 2022 17:52:39 +0900
>>>>> Arash Esbati <arash <at> gnu.org> writes:
> That was also my first approach, but then I thought I make it more
> robust since we really don't know what people will choose as delimiters.

OK.

> Actually, I think we have change that to:

>     (regexp (concat "[^\\]" (mapconcat #'regexp-quote strings "\\|")))

> to exclude things like \|, \- and \" etc.

(1) Alternatives concatenated by mapconcat must be enclosed with \(?:...\),
    otherwise "[^\\]" affects only the first component.
(2) This regexp doesn't match a shortvrb delimiter at the BOL
    because the regexp search is limited at (line-beginning-position).

Considering the above two points, the regexp should be built as
    (regexp (concat "\\(?:[^\\]\\|^\\)\\(?:"
               (mapconcat #'regexp-quote strings "\\|") "\\)"))

> Please consider this example, and hit 'M-q' in the paragraphs once with
> `font-lock-mode' enabled and once disabled:

> I think the issue is that '|' has also `font-latex-verbatim-face' which
> makes Emacs travel to far back when searching for the next break point.

Agreed.

> I'm not sure what's the best approach to fix this, what do you think?

> Following up myself, I think I have an idea which excludes the boundries
> while looking for `font-latex-verbatim-face':
----------------------------------------------------------------------
(defun LaTeX-verbatim-p (&optional pos)
[...]
          (if (and LaTeX-shortvrb-chars
                   (member (following-char) LaTeX-shortvrb-chars))
              (let ((regexp (concat "[^" TeX-esc "]"
                                    (regexp-quote (string (following-char))))))
                (if (cl-oddp (how-many regexp (line-beginning-position) (1+ (point))))
                    (font-latex-faces-present-p 'font-latex-verbatim-face (1- (point)))
                  (font-latex-faces-present-p 'font-latex-verbatim-face (1+ (point)))))
            (font-latex-faces-present-p 'font-latex-verbatim-face)))
[...]
----------------------------------------------------------------------
Hmm, rather complex. In addition, this code returns nil just before the
closing shortvrb delimiter. How about this?
-------------------------------------------------------------------------------
          (if (and LaTeX-shortvrb-chars
                   (memq (following-char) LaTeX-shortvrb-chars))
	      (and (font-latex-faces-present-p 'font-latex-verbatim-face)
		   (font-latex-faces-present-p 'font-latex-verbatim-face
					       (1- (point))))
            (font-latex-faces-present-p 'font-latex-verbatim-face)))
----------------------------------------------------------------------

Best,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#56160; Package auctex. (Mon, 04 Jul 2022 10:19:02 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Thibaut Benjamin <thibaut.benjamin <at> gmail.com>
Cc: 56160 <at> debbugs.gnu.org
Subject: Re: bug#56160: 13.1.3;
 fill breaks verbatim macros not followed with spaces
Date: Mon, 04 Jul 2022 19:18:19 +0900
Hi Thibaut,

>>>>> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
>>>>> Arash Esbati <arash <at> gnu.org> writes:
>> LGTM.  Please go ahead and install it.

> Done. :-)

I think that your original problem was fixed in the git repository. I'll
close this bug.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




bug closed, send any further explanations to 56160 <at> debbugs.gnu.org and Thibaut Benjamin <thibaut.benjamin <at> gmail.com> Request was from Ikumi Keita <ikumi <at> ikumi.que.jp> to control <at> debbugs.gnu.org. (Mon, 04 Jul 2022 10:20: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. (Mon, 01 Aug 2022 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 262 days ago.

Previous Next


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