Function: smie-blink-matching-open

smie-blink-matching-open is a byte-compiled function defined in smie.el.gz.

Signature

(smie-blink-matching-open)

Documentation

Blink the matching opener when applicable.

This uses SMIE's tables and is expected to be placed on post-self-insert-hook.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-blink-matching-open ()
  "Blink the matching opener when applicable.
This uses SMIE's tables and is expected to be placed on `post-self-insert-hook'."
  (let ((pos (point))                   ;Position after the close token.
        token)
    (when (and blink-matching-paren
               smie-closer-alist                     ; Optimization.
               (or (eq (char-before) last-command-event) ;; Sanity check.
                   (save-excursion
                     (or (progn (skip-chars-backward " \t")
                                (setq pos (point))
                                (eq (char-before) last-command-event))
                         (progn (skip-chars-backward " \n\t")
                                (setq pos (point))
                                (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))))))))