diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index f2163b243e..c68e55e0b4 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el @@ -997,46 +997,48 @@ smie-blink-matching-open (eq (char-before) last-command-event))))) (memq last-command-event smie-blink-matching-triggers) (not (nth 8 (syntax-ppss)))) - (save-excursion - (setq token (funcall smie-backward-token-function)) - (when (and (eq (point) (1- pos)) - (= 1 (length token)) - (not (rassoc token smie-closer-alist))) - ;; The trigger char is itself a token but is not one of the - ;; closers (e.g. ?\; in Octave mode), so go back to the - ;; previous token. - (setq pos (point)) - (setq token (funcall smie-backward-token-function))) - (when (rassoc token smie-closer-alist) - ;; We're after a close token. Let's still make sure we - ;; didn't skip a comment to find that token. - (funcall smie-forward-token-function) - (when (and (save-excursion - ;; Skip the trigger char, if applicable. - (if (eq (char-after) last-command-event) - (forward-char 1)) - (if (eq ?\n last-command-event) - ;; Skip any auto-indentation, if applicable. - (skip-chars-forward " \t")) - (>= (point) pos)) - ;; If token ends with a trigger char, don't blink for - ;; anything else than this trigger char, lest we'd blink - ;; both when inserting the trigger char and when - ;; inserting a subsequent trigger char like SPC. - (or (eq (char-before) last-command-event) - (not (memq (char-before) - smie-blink-matching-triggers))) - ;; FIXME: For octave's "switch ... case ... case" we flash - ;; `switch' at the end of the first `case' and we burp - ;; "mismatch" at the end of the second `case'. - (or smie-blink-matching-inners - (not (numberp (nth 2 (assoc token smie-grammar)))))) - ;; The major mode might set blink-matching-check-function - ;; buffer-locally so that interactive calls to - ;; blink-matching-open work right, but let's not presume - ;; that's the case. - (let ((blink-matching-check-function #'smie-blink-matching-check)) - (blink-matching-open)))))))) + (when + (save-excursion + (setq token (funcall smie-backward-token-function)) + (when (and (eq (point) (1- pos)) + (= 1 (length token)) + (not (rassoc token smie-closer-alist))) + ;; The trigger char is itself a token but is not one of the + ;; closers (e.g. ?\; in Octave mode), so go back to the + ;; previous token. + (setq pos (point)) + (setq token (funcall smie-backward-token-function))) + (and (rassoc token smie-closer-alist) + (progn + ;; We're after a close token. Let's still make sure we + ;; didn't skip a comment to find that token. + (funcall smie-forward-token-function) + (and (save-excursion + ;; Skip the trigger char, if applicable. + (if (eq (char-after) last-command-event) + (forward-char 1)) + (if (eq ?\n last-command-event) + ;; Skip any auto-indentation, if applicable. + (skip-chars-forward " \t")) + (>= (point) pos)) + ;; If token ends with a trigger char, don't blink for + ;; anything else than this trigger char, lest we'd blink + ;; both when inserting the trigger char and when + ;; inserting a subsequent trigger char like SPC. + (or (eq (char-before) last-command-event) + (not (memq (char-before) + smie-blink-matching-triggers))) + ;; FIXME: For octave's "switch ... case ... case" we flash + ;; `switch' at the end of the first `case' and we burp + ;; "mismatch" at the end of the second `case'. + (or smie-blink-matching-inners + (not (numberp (nth 2 (assoc token smie-grammar))))))))) + ;; The major mode might set blink-matching-check-function + ;; buffer-locally so that interactive calls to + ;; blink-matching-open work right, but let's not presume + ;; that's the case. + (let ((blink-matching-check-function #'smie-blink-matching-check)) + (blink-matching-open)))))) (defvar-local smie--matching-block-data-cache nil) diff --git a/lisp/simple.el b/lisp/simple.el index 4454791ad2..6a077cc55a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7648,6 +7648,7 @@ blink-matching-open (condition-case () (progn (syntax-propertize (point)) + (forward-comment -1) (forward-sexp -1) ;; backward-sexp skips backward over prefix chars, ;; so move back to the matching paren.