Ikumi Keita <[email protected]> writes:

>>>>>> Arash Esbati <[email protected]> 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



_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex

Reply via email to