【发布时间】:2014-05-24 06:19:48
【问题描述】:
我正在为类似 Lisp 的语言编写一个简单的模式,但在设置缩进时遇到了问题。我一直在关注emacswiki mode tutorial。
但是,我不知道如何根据我的需要调整他们的示例缩进,因为他们不进行任何形式的计数。
基本上,每次看到{ 或( 时,我只需要在缩进计数中添加 2 个空格,即使在同一行上有多个空格,当我看到上面的闭包时减去 2 个空格.我是 elisp 的新手;如何调整他们的示例来计算大括号和括号?
为方便起见,这里是他们使用的代码(对于非括号语言):
(defun wpdl-indent-line ()
"Indent current line as WPDL code"
(interactive)
(beginning-of-line)
(if (bobp) ; Check for rule 1
(indent-line-to 0)
(let ((not-indented t) cur-indent)
(if (looking-at "^[ \t]*END_") ; Check for rule 2
(progn
(save-excursion
(forward-line -1)
(setq cur-indent (- (current-indentation) default-tab-width)))
(if (< cur-indent 0)
(setq cur-indent 0)))
(save-excursion
(while not-indented
(forward-line -1)
(if (looking-at "^[ \t]*END_") ; Check for rule 3
(progn
(setq cur-indent (current-indentation))
(setq not-indented nil))
; Check for rule 4
(if (looking-at "^[ \t]*\\(PARTICIPANT\\|MODEL\\|APPLICATION\\|WORKFLOW\\|ACTIVITY\\|DATA\\|TOOL_LIST\\|TRANSITION\\)")
(progn
(setq cur-indent (+ (current-indentation) default-tab-width))
(setq not-indented nil))
(if (bobp) ; Check for rule 5
(setq not-indented nil)))))))
(if cur-indent
(indent-line-to cur-indent)
(indent-line-to 0))))) ; If we didn't see an indentation hint, then allow no indentation
我怎样才能实现类似 lisp 的缩进(也可以使用花括号)?
【问题讨论】:
-
为什么不直接看
lisp-indent-function的出处? -
abo-abo,我找不到该函数的未编译定义。
-
从源代码安装 emacs,然后您可以使用
describe-function轻松找到定义。 -
据我所知,
lisp-indent-function是lisp-mode.el中一系列复杂缩进函数的一部分,我不知道如何处理它们...... -
你不必完全理解它就可以使用它。实际上,您可能无需修改即可使用它。
标签: emacs programming-languages lisp indentation mode