Hi Thibaut,
>>>>> Thibaut Benjamin <[email protected]> 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
diff --git a/latex.el b/latex.el
index c32c8ed5..e18b6f11 100644
--- a/latex.el
+++ b/latex.el
@@ -4752,8 +4752,15 @@ space does not end a sentence, so don't break a line there."
fill-prefix)))
(defun LaTeX-fill-move-to-break-point (linebeg)
- "Move to the position where the line should be broken."
- (fill-move-to-break-point linebeg)
+ "Move to the position where the line should be broken.
+See `fill-move-to-break-point' for the meaning of 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>}.)
+ (let ((fill-nobreak-predicate
+ (cons #'LaTeX-verbatim-p fill-nobreak-predicate)))
+ (fill-move-to-break-point linebeg))
;; Prevent line break between 2-byte char and 1-byte char.
(when (and (or (and (not (looking-at LaTeX-nospace-between-char-regexp))
(TeX-looking-at-backward
@@ -4777,40 +4784,6 @@ space does not end a sentence, so don't break a line there."
(1- (- (point) linebeg)))
(not (TeX-escaped-p (match-beginning 0))))
(goto-char (match-beginning 0)))
- ;; 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))
(when LaTeX-fill-break-at-separators
(let ((orig-breakpoint (point))
(final-breakpoint (point))
_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex