对mods的注意事项:请注意,这个问题并不是一个品味问题。我要求提供有关我在Spacemacs'中遇到的缩进约定的具体信息。 elisp的默认缩进规则。
为什么这段代码会被格式化程序缩进:
(defun lispy--maybe-safe-delete-region (beg end)
"Delete the region from BEG to END.
If `lispy-safe-delete' is non-nil, exclude unmatched delimiters."
(if lispy-safe-delete
(let ((safe-regions (lispy--find-safe-regions beg end)))
(dolist (safe-region safe-regions)
(delete-region (car safe-region) (cdr safe-region)))
(test))
(delete-region beg end)
(test)))
而不是这样:
(defun lispy--maybe-safe-delete-region (beg end)
"Delete the region from BEG to END.
If `lispy-safe-delete' is non-nil, exclude unmatched delimiters."
(if lispy-safe-delete
(let ((safe-regions (lispy--find-safe-regions beg end)))
(dolist (safe-region safe-regions)
(delete-region (car safe-region) (cdr safe-region)))
(test))
(delete-region beg end)
(test)))
如您所见,默认格式没有在同一级别缩进if
sexp的子级。我不了解它运作的规则,因为let
sexp的孩子在同一级别缩进。
答案 0 :(得分:3)
因为Emacs Lisp的IF
运算符允许一个 然后表单和多个 else 表单。为了便于阅读, else 表单与然后表单的缩进方式不同。
ELISP> (if (> 10 20)
(print 'foo)
(princ 'bar)
(princ 'baz)
nil)
barbaz
nil