>From 9ba1612c357591aea7f479cc976c525dbca77c46 Mon Sep 17 00:00:00 2001 From: Ikumi Keita Date: Wed, 30 Aug 2023 15:56:53 +0900 Subject: [PATCH] Allow programmatical folding * tex-fold.el (TeX-fold-hide-item): Abort folding if computed result is symbol `abort'. (TeX-fold-macro-spec-list): Mention the new feature. * doc/auctex.texi (Folding): Mention the new feature. --- doc/auctex.texi | 2 ++ tex-fold.el | 61 +++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/doc/auctex.texi b/doc/auctex.texi index 61f12577..087d1405 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -2747,6 +2747,8 @@ placeholder. If the first element is a function symbol, the function will be called with all mandatory arguments of the macro and the result of the function call will be used as a replacement for the macro. +Such functions typically return a string, but may also return the +symbol @code{abort} to indicate that the macro should not be folded. The placeholder is made by copying the text from the buffer together with its properties, i.e.@: its face as well. If fontification has not diff --git a/tex-fold.el b/tex-fold.el index 78b58d4d..50e9e41b 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -111,6 +111,8 @@ the respective macro argument. If the first element is a function symbol, the function will be called with all mandatory arguments of the macro and the result of the function call will be used as a replacement for the macro. +Such functions typically return a string, but may also return the +symbol `abort' to indicate that the macro should not be folded. Setting this variable does not take effect immediately. Use Customize or reset the mode." @@ -796,31 +798,40 @@ That means, put respective properties onto overlay OV." (display-string (if (listp computed) (car computed) computed)) ;; (face (when (listp computed) (cadr computed))) ) - ;; Do nothing if the overlay is empty. - (when (and ov-start ov-end) - ;; Cater for zero-length display strings. - (when (string= display-string "") (setq display-string TeX-fold-ellipsis)) - ;; Add a linebreak to the display string and adjust the overlay end - ;; in case of an overfull line. - (when (TeX-fold-overfull-p ov-start ov-end display-string) - (setq display-string (concat display-string "\n")) - (move-overlay ov ov-start (save-excursion - (goto-char ov-end) - (skip-chars-forward " \t") - (point)))) - (overlay-put ov 'mouse-face 'highlight) - (when font-lock-mode - ;; Add raise adjustment for superscript and subscript. - ;; (bug#42209) - (setq display-string - (propertize display-string - 'display (get-text-property ov-start 'display)))) - (overlay-put ov 'display display-string) - (when font-lock-mode - (overlay-put ov 'face TeX-fold-folded-face)) - (unless (zerop TeX-fold-help-echo-max-length) - (overlay-put ov 'help-echo (TeX-fold-make-help-echo - (overlay-start ov) (overlay-end ov))))))) + + (if (eq computed 'abort) + ;; Do nothing if computed result is symbol `abort' to allow + ;; programmatical customization. + ;; Suggested by Paul Nelson . + ;; + (progn (delete-overlay ov) + t ; so that `TeX-fold-dwim' "gives up" + ) + ;; Do nothing if the overlay is empty. + (when (and ov-start ov-end) + ;; Cater for zero-length display strings. + (when (string= display-string "") (setq display-string TeX-fold-ellipsis)) + ;; Add a linebreak to the display string and adjust the overlay end + ;; in case of an overfull line. + (when (TeX-fold-overfull-p ov-start ov-end display-string) + (setq display-string (concat display-string "\n")) + (move-overlay ov ov-start (save-excursion + (goto-char ov-end) + (skip-chars-forward " \t") + (point)))) + (overlay-put ov 'mouse-face 'highlight) + (when font-lock-mode + ;; Add raise adjustment for superscript and subscript. + ;; (bug#42209) + (setq display-string + (propertize display-string + 'display (get-text-property ov-start 'display)))) + (overlay-put ov 'display display-string) + (when font-lock-mode + (overlay-put ov 'face TeX-fold-folded-face)) + (unless (zerop TeX-fold-help-echo-max-length) + (overlay-put ov 'help-echo (TeX-fold-make-help-echo + (overlay-start ov) (overlay-end ov)))))))) (defun TeX-fold-show-item (ov) "Show a single LaTeX macro or environment. -- 2.41.0