[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex afd25ba576 06/25: Throw out fold spec after a si
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex afd25ba576 06/25: Throw out fold spec after a single failure |
Date: |
Mon, 8 Jan 2024 07:59:10 -0500 (EST) |
branch: externals/auctex
commit afd25ba576e36e0013d79d1b0f7943424c065761
Author: Tony Zorman <soliditsallgood@mailbox.org>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Throw out fold spec after a single failure
So far, TeX-fold-expand-spec did not abort its expansion of the
current spec if *any* of the expansions succeeded. This can lead to
some unexpected behaviour. For example, given
(setopt TeX-fold-math-spec-list
'(("[1] of {1}||{1}" ("cite"))))
expanding `\cite{this}' would result in the overlay displaying
`… of this' instead of just `this', because one of the arguments
(the mandatory one) succeeded. This is probably not what the user
intended. Instead, in order for the spec to be chosen, *all
arguments should succeed.
* tex-fold.el (TeX-fold-expand-spec): Return non-nil value only when
all expansions suceeded.
---
tex-fold.el | 56 +++++++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 31 deletions(-)
diff --git a/tex-fold.el b/tex-fold.el
index c6e9f1cae6..d4dacc1684 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -741,37 +741,31 @@ Return non-nil if a removal happened, nil otherwise."
"Expand instances of {<num>}, [<num>], <<num>>, and (<num>).
Replace them with the respective macro argument."
(let ((spec-list (split-string spec "||"))
- (delims '((?\{ . ?\}) (?\[ . ?\]) (?< . ?>) (?\( . ?\))))
- index success)
- (catch 'success
- ;; Iterate over alternatives.
- (dolist (elt spec-list)
- (setq spec elt
- index nil)
- ;; Find and expand every placeholder.
- (while (and (string-match "\\([[{<(]\\)\\([1-9]\\)\\([]}>)]\\)"
- elt index)
- ;; Does the closing delim match the opening one?
- (string-equal
- (match-string 3 elt)
- (char-to-string
- (cdr (assq (string-to-char (match-string 1 elt))
- delims)))))
- (setq index (match-end 0))
- (let ((arg (car (save-match-data
- ;; Get the argument.
- (TeX-fold-macro-nth-arg
- (string-to-number (match-string 2 elt))
- ov-start ov-end
- (assoc (string-to-char (match-string 1 elt))
- delims))))))
- (when arg (setq success t))
- ;; Replace the placeholder in the string.
- (setq elt (replace-match (or arg TeX-fold-ellipsis) nil t elt)
- index (+ index (- (length elt) (length spec)))
- spec elt)))
- (when success (throw 'success nil))))
- spec))
+ (delims '((?\{ . ?\}) (?\[ . ?\]) (?< . ?>) (?\( . ?\)))))
+ (cl-labels
+ ((expand (spec &optional index)
+ ;; If there is something to replace and the closing delimiter
+ ;; matches the opening one…
+ (if-let (((string-match "\\([[{<(]\\)\\([1-9]\\)\\([]}>)]\\)"
+ elt index))
+ (open (string-to-char (match-string 1 spec)))
+ (num (string-to-number (match-string 2 spec)))
+ (close (string-to-char (match-string 3 spec)))
+ ((equal close (cdr (assoc open delims)))))
+ ;; … then replace it and move on. Otherwise, it must have been
+ ;; a spurious spec, so abort.
+ (when-let ((arg (car (save-match-data
+ (TeX-fold-macro-nth-arg
+ num ov-start ov-end (assoc open
delims)))))
+ (spec* (replace-match arg nil t spec)))
+ (expand spec*
+ (+ (match-end 0) (- (length spec*) (length spec)))))
+ ;; Nothing to replace: return the (completed) spec.
+ spec)))
+ (or (cl-loop for elt in spec-list
+ do (when-let (expanded (expand elt))
+ (cl-return expanded)))
+ TeX-fold-ellipsis))))
(defun TeX-fold-hide-item (ov)
"Hide a single macro or environment.
- [elpa] externals/auctex 9c230e4525 08/25: * doc/changes.texi: Edit changes since last release., (continued)
- [elpa] externals/auctex 9c230e4525 08/25: * doc/changes.texi: Edit changes since last release., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 971dea5a15 19/25: ; * tex-style.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 4b3a2b90fb 18/25: ; * tex-jp.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex d7033c804b 10/25: Wrap nil inside @code, Tassilo Horn, 2024/01/08
- [elpa] externals/auctex f16350a1b4 25/25: Merge remote-tracking branch 'origin/master' into externals/auctex, Tassilo Horn, 2024/01/08
- [elpa] externals/auctex ab3f1770f3 04/25: Add "includegraphics" to `paragraph-start', Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 05a3dc0ddf 03/25: Update the caption bundle styles, Tassilo Horn, 2024/01/08
- [elpa] externals/auctex fd940f22e2 14/25: ; * latex.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 11cd76e4f9 22/25: Update style/simpleicons.el to package v10.4.0, Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 9d4eac805a 09/25: ; * doc/changes.texi: Don't use @math., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex afd25ba576 06/25: Throw out fold spec after a single failure,
Tassilo Horn <=
- [elpa] externals/auctex 524e493ba9 16/25: ; * style/tcolorbox.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex c57465b7e1 15/25: ; * style/imakeidx.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex d16ce05d1e 12/25: ; * context.el: Use `defvar-local'., Tassilo Horn, 2024/01/08
- [elpa] externals/auctex 96ab750660 02/25: ; * style/ocgx.el ("ocgx"): Adjust query prompt., Tassilo Horn, 2024/01/08