我正在使用带有cc模式的emacs24,我想知道如何使我的emacs更“聪明”。输入}后,它将自动插入一个新行并缩进为例外。我想知道如何将点切换到上一行。 例如,当我定义一个函数时,现在我的emacs行为是:
void f()
{
}
//point
“// point”是输入}后光标的位置。 但我想要的是:
void f()
{
//point
}
我希望光标的位置可以切换到上一行并自动缩进。 我知道emacs可以做到这一点,但我不知道怎么做,谁能帮帮我?
答案 0 :(得分:1)
我认为你是在追踪这些...... C-M-u
,C-M-d
,C-M-f
和C-M-b
练习一点......他们是一种全球性的,他们几乎在所有模式中都表现出上下文。
更新:
哦..似乎你想自动放置光标..实际上,更常见的Emacs将帮助你根本不输入}
。我的意思是emacs可以自动插入关闭paran。
有一个内置的 电对模式
第三方 autopair.el答案 1 :(得分:0)
我不相信任何电动,所以我写了这个功能。
(defconst insert-logical-brackets-logical-bracket-begin "{")
(defconst insert-logical-brackets-logical-bracket-end "}")
(defconst insert-logical-brackets-default-style 0)
(make-variable-buffer-local 'logical-bracket-begin)
(make-variable-buffer-local 'logical-bracket-end)
(make-variable-buffer-local 'insert-logical-brackets-default-style)
(defun insert-logical-brackets(&optional style)
"If STYLE = 0(default, according to `insert-logical-brackets-default-style' value), make a newline before opening bracket, if line is not empty. Make a newline after closing bracket, if there is something after this bracket. Make two newlines in the middle.
If STYLE = 1, don't make newlines before opening a bracket(one of c styles).
If STYLE = 2, don't make newlines before opening and after closing bracket.
If STYLE = 3, allways make all newlines.
If STYLE is not nil, don't make newlines between brackets(still makes before/after lines)."
(interactive "P")
(when (eq style nil)
(setq style insert-logical-brackets-default-style))
(funcall indent-line-function)
(unless (or (eq 1 style) (eq 2 style))
(when (or (/= (point) (save-excursion (back-to-indentation) (point))) (eq 3 style))
(newline)
(funcall indent-line-function)))
(unless (and (integerp style) (= 2 style))
(when (or (not (looking-at "\n")) (eq 3 style))
(newline)
(funcall indent-line-function)
(forward-line -1)
(goto-char (point-at-eol))))
(insert logical-bracket-begin)
(funcall indent-line-function)
(let ((return-point (point)))
(when (or (not style) (or (eq 0 style) (eq 1 style) (eq 2 style) (eq 3 style)))
(newline)
(funcall indent-line-function)
(setq return-point (point))
(newline))
(insert logical-bracket-end)
(funcall indent-line-function)
(goto-char return-point)))
答案 2 :(得分:0)
查看模板系统,例如yasnippet:http://www.emacswiki.org/emacs/CategoryTemplates
答案 3 :(得分:0)
auto-indent-mode也许你想要的!