branch: main
commit f4e5ef2af43cea032f3726551f86a183ccb4b71f
Author: Paul Nelson <ultr...@gmail.com>
Commit: Arash Esbati <ar...@gnu.org>

    Fix folding of verbatim macros
    
    * tex-fold.el (TeX-fold-macro-nth-arg): Use
    `LaTeX-verbatim-macro-boundaries' to find end of argument when
    argument is verbatim.  (bug#73302)
    
    * NEWS.org (Fixed): Announce the change.
---
 NEWS.org    |  4 ++++
 tex-fold.el | 20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 2f258249..03660d09 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -41,6 +41,10 @@
   various tabular environments to =latex.el= from the respective style
   files.
 
+** Fixed
+
+- Fold argument of verbatim macros more accurately.
+
 ** Removed
 
 - Remove the possibility to disable the side-wide installation with:
diff --git a/tex-fold.el b/tex-fold.el
index d13c892f..a4ebe43a 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -52,6 +52,8 @@
 (autoload 'Texinfo-find-env-start "tex-info")
 (autoload 'Texinfo-find-env-end "tex-info")
 
+(declare-function LaTeX-verbatim-macro-boundaries "latex")
+
 (defgroup TeX-fold nil
   "Fold TeX macros."
   :group 'AUCTeX)
@@ -656,11 +658,19 @@ backward compatibility and always nil."
                                          (concat open-string " \t"))
                                         (point)))
                   (goto-char
-                   (if delims
-                       (with-syntax-table
-                           (TeX-search-syntax-table open-char close-char)
-                         (scan-lists (point) 1 1))
-                     (TeX-find-closing-brace)))
+                   (if (TeX-verbatim-p)
+                       (cond ((derived-mode-p 'LaTeX-mode)
+                              (cdr (LaTeX-verbatim-macro-boundaries)))
+                             ;; FIXME: When other modes implement a
+                             ;; nontrivial `TeX-verbatim-p-function', we
+                             ;; should return the appropriate endpoint
+                             ;; here.
+                             )
+                     (if delims
+                         (with-syntax-table
+                             (TeX-search-syntax-table open-char close-char)
+                           (scan-lists (point) 1 1))
+                       (TeX-find-closing-brace))))
                   (setq content-end (save-excursion
                                       (backward-char)
                                       (skip-chars-backward " \t")

Reply via email to