Subject: Re: bug#61400: Different filling for verbatim macros

From: Arash Esbati <[email-masked]>
Date: Sun, 12 Feb 2023 12:18:31 +0100

Hi Keita,

Ikumi Keita <[email-masked]> writes:

> I realized that multiple players are involved in this issue.

First of all, many thanks for your (as always) precise analysis 🙏🏿

> We can fix this inconsistency by the following code:
> ----------------------------------------------------------------------
> (defun LaTeX-verbatim-macro-boundaries ()
> [...]
>       ;; Search backwards for the macro start, unless we are facing one
>       (if (looking-at (concat (regexp-quote TeX-esc) verbatim-regexp))
>           (forward-char 1)
>         (catch 'found
> [...]
> ----------------------------------------------------------------------
> With this fix, `LaTeX-current-verbatim-macro' returns sane result even
> when the point is just before "\verb". It just behave like
> `TeX-current-macro'.

I think this should be our course of action: Make
`LaTeX-current-verbatim-macro' and `TeX-current-macro' work identical.

> Yes, the behavior becomes coherent, but in the undesired direction. :-(

We should take that.

> For consistency, maybe we should modify `TeX-current-macro' and
> `LaTeX-current-verbatim-macro' so that they return nil when the point is
> just before the verbatim macro. However, I'm not yet sure whether such
> change brings about bad side effects.

I agree, we shouldn't touch `TeX-current-macro'.

> Perhaps the safe fix is to tweak `TeX-current-macro' and
> `LaTeX-current-verbatim-macro' so that they accept optional argument for
> use in `LaTeX-verbatim-p'?

Here is another idea: We don't use `LaTeX-verbatim-p' in
`fill-nobreak-predicate', but define two new functions, say
`LaTeX-verbatim-macro-arg-boundaries' and `LaTeX-verbatim-nobreak-p'.
The first one is carved out of `LaTeX-verbatim-macro-boundaries' and
returns the beginning and end positions of the argument, as the name
suggests.

And `LaTeX-verbatim-nobreak-p' does the following: Check if the possible
break point for filling is inside the range returned by
`LaTeX-verbatim-macro-arg-boundaries' and if
`LaTeX-current-verbatim-macro' on that point returns non-nil, then
inhibit break there (t value), otherwise allow brake (nil value.)

WDYT, does this make sense?

Best, Arash