Emacs 23.2包含js模式,它是一個改名和改良的Espresso。我只是做你的redunkulous代碼「縮進區域」,並得到這個:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash(o
, { start: 0
, limit: 50
}
)
我想這不完全是你想要的。逗號的偏移量可能與您可能喜歡的不同。
(天哪這是醜陋的。)
編輯
好吧,我看着JS-模式和縮進似乎是由js--proper-indentation
完成。它會查看當前行,然後嘗試做出關於如何縮進的決定。
對於各種語法模式,它有很多測試條件。我只是把支票開始用逗號線,並得到了這些結果:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash(o
, { start: 0
, limit: 50
}
)
我認爲這是你想要的,但它仍然看起來完全打破了我。無論如何,這是我做到的。
噴射該COND到列表的頂部js--proper-indentation
:
(defun js--proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
(cond
((looking-at ",")
(let ((spos
(save-excursion
(while (looking-back "}[\t\n ]*")
(backward-sexp)
(if (looking-back ",[\t\n ]*")
(re-search-backward ",[\t\n ]*")))
(cond
((looking-back "\\(,\\|(\\)[ \t]*\\<\\([^:=\n\t ]+\\)[ \t\n]*")
(re-search-backward "\\(,\\|(\\)[ \t]*\\<\\([^:=\n\t ]+\\)[ \t\n]*" (point-min) t)
(+ (current-column) 2))
((re-search-backward "\\<\\([^:=\n\t ]+\\)[ \t]*\\(:\\|=\\)" (point-min) t)
(current-column))
(t
nil)))))
(if spos
(- spos 2)
(+ js-indent-level js-expr-indent-offset))))
....
一定要保留其餘的條件在defun定義 - 我不知道他們做了什麼,但the're來說可能更重要。
不知道如果這是健壯的,我還沒有測試過它,除了你的一個測試用例。但是這應該讓你開始。
是的,人們常常通過包括從咖啡(JS-模式)壓痕增強JS2模式。但Espresso正好解決了我正在努力解決的問題。 – 2011-05-27 04:31:48
回覆:編輯謝謝,這是非常有幫助的。我將不得不做一些測試並回到這個。 – 2011-05-27 17:27:06