Emacs 23.2 包含 js-mode,这是一个重命名和修饰的 Espresso。我刚刚在你冗长的代码上做了“缩进区域”,得到了这个:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash( o
, { start: 0
, limit: 50
}
)
我想这不是你想要的。逗号的偏移与您可能喜欢的不同。
(天哪,太丑了。)
编辑
好的,我查看了 js-mode,缩进似乎是由js--proper-indentation
. 它查看当前行,然后尝试决定如何缩进。
它有一堆测试条件,用于各种语法模式。我只是检查以逗号开头的行,并得到以下结果:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash( o
, { start: 0
, limit: 50
}
)
我认为这就是你想要的,但在我看来它仍然完全破碎。无论如何,我就是这样做的。
将此条件注入列表顶部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))))
....
Be sure to keep the rest of the conditions in that defun - I don't know what they do but the're probably important.
No idea if this is robust, I haven't tested it except for your one test case. But this oughta get you started.