Function: smie-rule-separator

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

Signature

(smie-rule-separator METHOD)

Documentation

Indent current token as a "separator".

By "separator", we mean here a token whose sole purpose is to separate various elements within some enclosing syntactic construct, and which does not have any semantic significance in itself (i.e. it would typically no exist as a node in an abstract syntax tree). Such a token is expected to have an associative syntax and be closely tied to its syntactic parent. Typical examples are "," in lists of arguments
(enclosed inside parentheses), or ";" in sequences of instructions (enclosed
in a {..} or begin..end block). METHOD should be the method name that was passed to smie-rules-function. Only meaningful when called from within smie-rules-function.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-rule-separator (method)
  "Indent current token as a \"separator\".
By \"separator\", we mean here a token whose sole purpose is to separate
various elements within some enclosing syntactic construct, and which does
not have any semantic significance in itself (i.e. it would typically no exist
as a node in an abstract syntax tree).
Such a token is expected to have an associative syntax and be closely tied
to its syntactic parent.  Typical examples are \",\" in lists of arguments
\(enclosed inside parentheses), or \";\" in sequences of instructions (enclosed
in a {..} or begin..end block).
METHOD should be the method name that was passed to `smie-rules-function'.
Only meaningful when called from within `smie-rules-function'."
  ;; FIXME: The code below works OK for cases where the separators
  ;; are placed consistently always at beginning or always at the end,
  ;; but not if some are at the beginning and others are at the end.
  ;; I.e. it gets confused in cases such as:
  ;;     (  a
  ;;     ,  a,
  ;;        b
  ;;     ,  c,
  ;;        d
  ;;     )
  ;;
  ;; Assuming token is associative, the default rule for associative
  ;; tokens (which assumes an infix operator) works fine for many cases.
  ;; We mostly need to take care of the case where token is at beginning of
  ;; line, in which case we want to align it with its enclosing parent.
  (cond
   ((and (eq method :before) (smie-rule-bolp) (not (smie-rule-sibling-p)))
    (let ((parent-col (cdr (smie-rule-parent)))
          (parent-pos-col     ;FIXME: we knew this when computing smie--parent.
           (save-excursion
             (goto-char (cadr smie--parent))
             (smie-indent-forward-token)
             (forward-comment (point-max))
             (current-column))))
      (cons 'column
            (max parent-col
                 (min parent-pos-col
                      (- parent-pos-col (smie-indent--separator-outdent)))))))
   ((and (eq method :after) (smie-indent--bolp))
    (smie-indent--separator-outdent))))