23.7.1.8 Sample Indentation Rules

Here is an example of an indentation function:

     (eval-when-compile (require 'cl))       ;For the `case' macro.
     (defun sample-smie-rules (kind token)
       (case kind
         (:elem (case token
                  (basic sample-indent-basic)))
         (:after
          (cond
           ((equal token ",") (smie-rule-separator kind))
           ((equal token ":=") sample-indent-basic)))
         (:before
          (cond
           ((equal token ",") (smie-rule-separator kind))
           ((member token '("begin" "(" "{"))
            (if (smie-rule-hanging-p) (smie-rule-parent)))
           ((equal token "if")
            (and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
                 (smie-rule-parent)))))))

A few things to note:

blog comments powered by Disqus