Function: smie-config-set-indent

smie-config-set-indent is an interactive and byte-compiled function defined in smie.el.gz.

Signature

(smie-config-set-indent)

Documentation

Add a rule to adjust the indentation of current line.

Probably introduced at or before Emacs version 24.4.

Key Bindings

Aliases

sh-learn-line-indent (obsolete since 28.1) sh-set-indent (obsolete since 28.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-config-set-indent ()
  "Add a rule to adjust the indentation of current line."
  (interactive)
  (let* ((trace (cdr (smie-config--get-trace)))
         (_ (unless trace (error "No SMIE rules involved")))
         (sig (if (null (cdr trace))
                  (pcase-let* ((elem (car trace))
                               (`(,_pos ,kind ,token ,res ,rewrite) elem))
                    (list kind token (or (nth 3 rewrite) res)))
                (let* ((choicestr
                        (completing-read
                         "Adjust rule: "
                         (mapcar (lambda (elem)
                                   (format "%s %S"
                                           (substring (symbol-name (cadr elem))
                                                      1)
                                           (nth 2 elem)))
                                 trace)
                         nil t nil nil
                         nil)) ;FIXME: Provide good default!
                       (choicelst (car (read-from-string
                                        (concat "(:" choicestr ")")))))
                  (catch 'found
                    (pcase-dolist (`(,_pos ,kind ,token ,res ,rewrite) trace)
                      (when (and (eq kind (car choicelst))
                                 (equal token (nth 1 choicelst)))
                        (throw 'found (list kind token
                                            (or (nth 3 rewrite) res)))))))))
         (default-new (smie-config--guess-value sig))
         (newstr (read-string (format-prompt
                               "Adjust rule (%S %S -> %S) to" default-new
                               (nth 0 sig) (nth 1 sig) (nth 2 sig))
                              nil nil (format "%S" default-new)))
         (new (car (read-from-string newstr))))
    (let ((old (rassoc sig smie-config--buffer-local)))
      (when old
        (setq smie-config--buffer-local
              (remove old smie-config--buffer-local))))
    (push (cons new sig) smie-config--buffer-local)
    (message "Added rule %S %S -> %S (via %S)"
             (nth 0 sig) (nth 1 sig) new (nth 2 sig))
    (add-function :around (local 'smie-rules-function) #'smie-config--advice)))