【问题标题】:Align symbols in plist对齐 plist 中的符号
【发布时间】:2018-03-11 16:42:51
【问题描述】:

如何对齐 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)

顺便说一句,lisp 是否有类似的功能,例如c-show-syntactic-information,这对于这类事情非常有用。我找不到 apropos 的任何内容。

【问题讨论】:

标签: emacs indentation


【解决方案1】:

您希望 Emacs 缩进 defhydra,就像缩进 Common Lisp defun,所以你放

(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 文件。

【讨论】:

    【解决方案2】:

    在上一个答案的基础上,common-lisp-indent-function 将根据需要缩进 plist。但是,我不想全局更改缩进功能,所以这只是一个包装器,用common-lisp-indent-function 缩进一个区域并使用前缀打开/关闭它。

    (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)))
    

    【讨论】:

      猜你喜欢
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2022-11-30
      • 1970-01-01
      • 2011-06-15
      • 2014-12-18
      相关资源
      最近更新 更多