diff --git a/tex-fold.el b/tex-fold.el index af1191f..e473aee 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -563,8 +563,12 @@ TYPE can be either 'env for environments, 'macro for macros or (LaTeX-find-matching-end) (point)) (t - (goto-char start) - (TeX-find-macro-end))))) + ;; Most of the math macros to be folded don't take an optional + ;; argument, and in math mode square brackets are generally used as + ;; they are. + (let ((TeX-find-macro-end-ignore-brackets (eq type 'math))) + (goto-char start) + (TeX-find-macro-end)))))) (defun TeX-fold-overfull-p (ov-start ov-end display-string) "Return t if an overfull line will result after adding an overlay. diff --git a/tex.el b/tex.el index 5c81994..7d66f1c 100644 --- a/tex.el +++ b/tex.el @@ -5259,11 +5259,16 @@ considered part of the macro." (cons start-point (point)) nil)))))) -(defun TeX-find-macro-end-helper (start) +(defvar TeX-find-macro-end-ignore-brackets nil + "Whether `TeX-find-macro-end' should ignore square brackets.") + +(defun TeX-find-macro-end-helper (start &optional ignore-brackets) "Find the end of a macro given its START. -START is the position just before the starting token of the macro. -If the macro is followed by square brackets or curly braces, -those will be considered part of it." +START is the position just before the starting token of the +macro. If the macro is followed by square brackets or curly +braces, those will be considered part of it, unless +`TeX-find-macro-end-ignore-brackets' is non-nil, in which case +square brackets will be ignored as part of the macro." (save-excursion (save-match-data (catch 'found @@ -5274,12 +5279,13 @@ those will be considered part of it." (while (not (eobp)) (cond ;; Skip over pairs of square brackets - ((or (looking-at "[ \t]*\n?\\(\\[\\)") ; Be conservative: Consider - ; only consecutive lines. - (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) - (save-excursion - (forward-line 1) - (looking-at "[ \t]*\\(\\[\\)")))) + ((and (null TeX-find-macro-end-ignore-brackets) + ;; Be conservative: Consider only consecutive lines. + (or (looking-at "[ \t]*\n?\\(\\[\\)") + (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp)) + (save-excursion + (forward-line 1) + (looking-at "[ \t]*\\(\\[\\)"))))) (goto-char (match-beginning 1)) (condition-case nil (forward-sexp) @@ -5305,7 +5311,9 @@ those will be considered part of it." "Return the start of a macro. If LIMIT is given, do not search backward further than this point in buffer. Arguments enclosed in brackets or braces are -considered part of the macro." +considered part of the macro. If +`TeX-find-macro-end-ignore-brackets' is non-nil, square brackets +will be ignored as part of the macro." (car (TeX-find-macro-boundaries limit))) (defun TeX-find-macro-end ()