对齐 plist 中的符号

Align symbols in plist

如何对齐 plist 中的符号?下面以默认'emacs-lisp-mode缩进

为例
'(:a 1
     :b 2
     :c 3)

(defhydra h (:color amaranth
                    :pre some-pre
                    :post some-post)
  nil)

如何实现如下缩进?

(defhydra h (:color amaranth
             :pre some-pre
             :post some-post)
  nil)

附带说明一下,是否有类似 c-show-syntactic-information 的 lisp 函数,它对这类事情非常有用。我找不到 apropos.

的任何内容

您希望 Emacs 以缩进 Common 的方式缩进 defhydra Lispdefun,所以你把

(autoload 'common-lisp-indent-function "cl-indent" "Common Lisp indent.")
(custom-set-variables
 '(lisp-indent-function 'common-lisp-indent-function))
(put 'defhydra 'common-lisp-indent-function 'defun)

进入您的 .emacs 并在 lisp-mode 中编辑您的 hydra 文件。

基于之前的答案,common-lisp-indent-function 将根据需要缩进 plists。但是,我不想全局更改 indent-function,所以这只是一个包装器,用于缩进带有 common-lisp-indent-function 的区域并使用前缀 on/off 切换它。

(defun my-cl-indent (&optional start end switch)
  "Indent region with `common-lisp-indent-function'. With prefix
toggle buffer-local value to be `common-lisp-indent-function'."
  (interactive "r\nP")
  (when switch
    (setq-local lisp-indent-function
                (if (eq lisp-indent-function 'lisp-indent-function)
                    'common-lisp-indent-function
                  'lisp-indent-function)))
  (let ((lisp-indent-function 'common-lisp-indent-function))
    (put 'cl-flet 'common-lisp-indent-function
         (get 'flet 'common-lisp-indent-function))
    (indent-region start end)))