branch: main
commit b404938737d444245a99a6db3abbba3ebba14b8c
Author: Paul Nelson <[email protected]>
Commit: Arash Esbati <[email protected]>
Improve delimiter and macro handling
* tex-fold.el (TeX-fold--verb-data): Add check to ensure
`backward-sexp' doesn't jump before macro boundaries when matching
braces.
(TeX-fold-verbs): Require word boundary after macro name in
regexp to prevent folding partial macro matches (e.g., \pyv in
\pyvm). (bug#78585)
---
tex-fold.el | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/tex-fold.el b/tex-fold.el
index 2c10cc27..766270ef 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -1362,13 +1362,17 @@ only in LaTeX modes."
?\{
end-delim-char))
(start-delim (char-to-string start-delim-char))
- (verb-arg-start
- (1+ (progn
- (goto-char bound-end)
- (if (string= start-delim TeX-grop)
- (progn (backward-sexp) (point))
- (forward-char -1)
- (search-backward start-delim bound-start t)))))
+ (start-delim-pos
+ (save-excursion
+ (goto-char bound-end)
+ (if (string= start-delim TeX-grop) ; "{"
+ (when-let* ((matching-brace (save-excursion
(backward-sexp)
+ (point))))
+ (and (>= matching-brace bound-start) matching-brace))
+ ;; delimiter is, e.g., "|"
+ (goto-char (1- bound-end))
+ (search-backward start-delim bound-start t))))
+ (verb-arg-start (1+ start-delim-pos))
(verb-arg-end (1- bound-end)))
(list bound-start
bound-end
@@ -1384,7 +1388,8 @@ Replaces the verbatim content with its own text."
(regexp-opt
(append
(LaTeX-verbatim-macros-with-braces)
- (LaTeX-verbatim-macros-with-delims))))))
+ (LaTeX-verbatim-macros-with-delims)))
+ "\\_>")))
(while (let ((case-fold-search nil))
(re-search-forward re end t))
(when-let* ((data (TeX-fold--verb-data))