我正在爲類似Lisp的語言編寫簡單模式,並且在設置縮進時遇到了麻煩。我一直在關注emacswiki mode tutorial。創建emacs模式:定義縮進
但是,我不知道如何調整他們的示例縮進符合我的需求,因爲他們沒有做任何形式的計數。
基本上,我只需要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,我無法找到該函數的未編譯定義。 – WorldsEndless
從源代碼安裝emacs,然後您可以通過'describe-function'輕鬆找到定義。 –