Emacs 输入}后如何将点切换到上一行?

Emacs 输入}后如何将点切换到上一行?,emacs,elisp,cc-mode,Emacs,Elisp,Cc Mode,我正在使用带有cc模式的emacs24,我想知道如何使我的emacs更“聪明”。键入a}后,它将自动插入新行并按例外情况缩进。我想知道如何将该点切换到上一行。 例如,当我定义一个函数时,现在我的emacs行为是: void f() { } //point “//点”是输入}后光标的位置。 但我想要的是: void f() { //point } 我希望光标的位置可以切换到上一行并自动缩进。 我知道emacs可以做到这一点,但我不知道怎么做,谁能帮我?我想你在追求这些C-M-u,C-M

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

void f()
{
}
//point
“//点”是输入}后光标的位置。 但我想要的是:

void f()
{
    //point
}
我希望光标的位置可以切换到上一行并自动缩进。
我知道emacs可以做到这一点,但我不知道怎么做,谁能帮我?

我想你在追求这些<代码>C-M-u,
C-M-d
C-M-f
C-M-b

练习一下。。。它们是全球性的,几乎在所有模式下都会表现出情境性

更新:

哦。。您似乎希望自动放置光标。。实际上,在更一般的情况下,Emacs将帮助您根本不键入
}
。我的意思是emacs可以自动插入关闭参数

有一个内置的 电对模式

第三方
autopair.el

我想你在找这些<代码>C-M-u,
C-M-d
C-M-f
C-M-b

练习一下。。。它们是全球性的,几乎在所有模式下都会表现出情境性

更新:

哦。。您似乎希望自动放置光标。。实际上,在更一般的情况下,Emacs将帮助您根本不键入
}
。我的意思是emacs可以自动插入关闭参数

有一个内置的 电对模式

第三方
autopair.el

我不相信任何电子产品,所以我编写了这个函数

(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)))

我不相信任何电的东西,所以我写了这个函数

(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)))

看看像yasnippet这样的模板系统:

看看像yasnippet这样的模板系统:

也许你想要什么

也许是你想要的