Function: smie-indent--rule

smie-indent--rule is a byte-compiled function defined in smie.el.gz.

Signature

(smie-indent--rule METHOD TOKEN &optional AFTER PARENT BASE-POS)

Documentation

Compute indentation column according to smie-rules-function.

METHOD and TOKEN are passed to smie-rules-function. AFTER is the position after TOKEN, if known. PARENT is the parent info returned by smie-backward-sexp, if known. BASE-POS is the position relative to which offsets should be applied.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-indent--rule ( method token
                           ;; FIXME: Too many parameters.
                           &optional after parent base-pos)
  "Compute indentation column according to `smie-rules-function'.
METHOD and TOKEN are passed to `smie-rules-function'.
AFTER is the position after TOKEN, if known.
PARENT is the parent info returned by `smie-backward-sexp', if known.
BASE-POS is the position relative to which offsets should be applied."
  ;; This is currently called in 3 cases:
  ;; - :before opener, where rest=nil but base-pos could as well be parent.
  ;; - :before other, where
  ;;                  ; after=nil
  ;;                  ; parent is set
  ;;                  ; base-pos=parent
  ;; - :after tok, where
  ;;                  ; after is set; parent=nil; base-pos=point;
  (save-excursion
    (let ((offset (smie-indent--rule-1 method token after parent)))
      (cond
       ((not offset) nil)
       ((eq (car-safe offset) 'column) (cdr offset))
       ((integerp offset)
        (+ offset
           (if (null base-pos) 0
             (goto-char base-pos)
             ;; Use smie-indent-virtual when indenting relative to an opener:
             ;; this will also by default use current-column unless
             ;; that opener is hanging, but will additionally consult
             ;; rules-function, so it gives it a chance to tweak indentation
             ;; (e.g. by forcing indentation relative to its own parent, as in
             ;; fn a => fn b => fn c =>).
             ;; When parent==nil it doesn't matter because the only case
             ;; where it's really used is when the base-pos is hanging anyway.
             (if (or (and parent (null (car parent)))
                     (smie-indent--hanging-p))
                 (smie-indent-virtual) (current-column)))))
       (t (error "Unknown indentation offset %s" offset))))))