让我们看看我是否能够解释它。当我在 emacs 24 中输入这个时:
int foo() {|}
注:| = 光标
然后按回车键,我得到下一个输出:
int foo() {
|}
所以,我的问题是:我怎样才能实现下一个行为?
int foo() {
|
}
让我们看看我是否能够解释它。当我在 emacs 24 中输入这个时:
int foo() {|}
注:| = 光标
然后按回车键,我得到下一个输出:
int foo() {
|}
所以,我的问题是:我怎样才能实现下一个行为?
int foo() {
|
}
而不是global-set-key
你应该使用类似的东西(define-key 'c++-mode-map ...
,但这是基础知识。
(defun newline-and-push-brace ()
"`newline-and-indent', but bracket aware."
(interactive)
(insert "\n")
(when (looking-at "}")
(insert "\n")
(indent-according-to-mode)
(forward-line -1))
(indent-according-to-mode))
(global-set-key (kbd "RET") 'newline-and-push-brace)
您可以定义一个函数来检查您是否处于这种情况并执行您想要的操作,否则只需调用您的主要模式的换行命令,例如:
(defun brackets-newline (point)
(interactive "d")
(setq next-char (char-before point))
(if (and next-char
(char-equal next-char 123))
;; if we are sitting in front of a close bracket, do what you want
(progn
(newline)
(newline)
(previous-line)
;;call whatever "TAB" is in this mode
(funcall (key-binding (kbd "TAB"))))
;; otherwise just insert a newline
(newline)))
然后将此绑定到(kbd "RET")
可能有更好的方法来使用defadvice
或类似的方法,但这似乎对我来说效果很好。