1

我正在使用带有 cc 模式的 emacs24,我想知道如何让我的 emacs 更“聪明”。在我输入 } 后,它会自动插入一个新行并缩进为例外。我想知道如何将点切换到上一行。例如,当我定义一个函数时,现在我的 emacs 行为是:

void f()
{
}
//point

“//point”是输入}后光标的位置。但我想要的是这个:

void f()
{
    //point
}

我希望光标的位置可以自动切换到上一行并缩进。我知道emacs可以做到这一点,但我不知道该怎么做,谁能帮助我?

4

4 回答 4

1

我想你是在追求这些.. C-M-u, C-M-d, C-M-fandC-M-b

练习一下......它们是一种全球性的,它们在几乎所有模式下都会根据上下文表现......

更新:

哦.. 似乎您想自动放置光标.. 实际上,更一般地说,Emacs 会帮助您根本不打字}。我的意思是emacs可以自动插入关闭参数。

内置一对电模式

第三方 autopair.el

于 2012-07-01T08:23:51.323 回答
0

看看像 yasnippet 这样的模板系统:http ://www.emacswiki.org/emacs/CategoryTemplates

于 2012-07-04T11:02:59.087 回答
0

自动缩进模式也许是你想要的!

于 2012-07-09T01:03:24.577 回答
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)))
于 2012-07-04T08:55:06.027 回答