emacselispindentationproperty-list

Customize Elisp plist indentation


I don't like how plists are indented in Elisp.

;; current   desired   Python (for comparison)
;; '(a 1     '(a 1     {'a': 1,
;;     b 2     b 2      'b': 2,
;;     c 3)    c 3)     'c': 3}

Tried on M-x emacs-version 24.3.1, ran emacs -Q, typed the plist and pressed C-x h C-M-\.

This indentation makes sense when it isn't a list:

(mapcar (lambda (x) (x + 1))
        '(1 2 3 4))

How do I change formatting settings so that only plists (or, if that's impossible, all quoted lists) have the desired rectangular indentation, but indentation of everything else stays the same? I need this stored locally in an .el file, so that when I edit this file, it is indented as desired, but this behavior doesn't end up anywhere else.


Solution

  • Found it:

    (setq lisp-indent-function 'common-lisp-indent-function)
    

    Here's a sample file:

    (setq x  '(a 1
               b 2
               c 3))
    
    ;;; Local Variables:
    ;;; lisp-indent-function: common-lisp-indent-function
    ;;; End:
    

    I'll just dump my whole indentation config here:

    (setq lisp-indent-function 'common-lisp-indent-function)
    (put 'cl-flet 'common-lisp-indent-function
         (get 'flet 'common-lisp-indent-function))
    (put 'cl-labels 'common-lisp-indent-function
         (get 'labels 'common-lisp-indent-function))
    (put 'if 'common-lisp-indent-function 2)
    (put 'dotimes-protect 'common-lisp-indent-function
         (get 'when 'common-lisp-indent-function))