Function: smie-setup
smie-setup is a byte-compiled function defined in smie.el.gz.
Signature
(smie-setup GRAMMAR RULES-FUNCTION &rest KEYWORDS)
Documentation
Setup SMIE navigation and indentation.
GRAMMAR is a grammar table generated by smie-prec2->grammar.
RULES-FUNCTION is a set of indentation rules for use on smie-rules-function.
KEYWORDS are additional arguments, which can use the following keywords:
- :forward-token FUN
- :backward-token FUN
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-setup (grammar rules-function &rest keywords)
"Setup SMIE navigation and indentation.
GRAMMAR is a grammar table generated by `smie-prec2->grammar'.
RULES-FUNCTION is a set of indentation rules for use on `smie-rules-function'.
KEYWORDS are additional arguments, which can use the following keywords:
- :forward-token FUN
- :backward-token FUN"
(setq-local smie-rules-function rules-function)
(setq-local smie-grammar grammar)
(setq-local indent-line-function #'smie-indent-line)
(add-function :around (local 'normal-auto-fill-function) #'smie-auto-fill)
(setq-local forward-sexp-function #'smie-forward-sexp-command)
(while keywords
(let ((k (pop keywords))
(v (pop keywords)))
(pcase k
(:forward-token
(setq-local smie-forward-token-function v))
(:backward-token
(setq-local smie-backward-token-function v))
(_ (message "smie-setup: ignoring unknown keyword %s" k)))))
(let ((ca (cdr (assq :smie-closer-alist grammar))))
(when ca
(setq-local smie-closer-alist ca)
;; Only needed for interactive calls to blink-matching-open.
(setq-local blink-matching-check-function #'smie-blink-matching-check)
(add-hook 'post-self-insert-hook
#'smie-blink-matching-open 'append 'local)
(add-function :around (local 'show-paren-data-function)
#'smie--matching-block-data)
;; Setup smie-blink-matching-triggers. Rather than wait for SPC to
;; blink, try to blink as soon as we type the last char of a block ender.
(let ((closers (sort (mapcar #'cdr smie-closer-alist) #'string-lessp))
(triggers ())
closer)
(while (setq closer (pop closers))
(unless
;; FIXME: this eliminates prefixes of other closers, but we
;; should probably eliminate prefixes of other keywords as well.
(and closers (string-prefix-p closer (car closers)))
(push (aref closer (1- (length closer))) triggers)))
(setq-local smie-blink-matching-triggers
(append smie-blink-matching-triggers
(delete-dups triggers)))))))