按';键时,Emacs返回缩进代码行;返回';钥匙

按';键时,Emacs返回缩进代码行;返回';钥匙,emacs,Emacs,我使用的是emacs 22.2.1和Ubuntu 9.04 我已经在.emacs文件中这样做了。每次我按“;”时缩进并创建新行或{} if(success == 0) { printf("Success\n"); <---- if I press return key here it will go <-- to here, and I have to tab to go to the code line. 映射返回到换行+缩进。或者,如果您愿意,您可以养成键入C-

我使用的是emacs 22.2.1和Ubuntu 9.04

我已经在.emacs文件中这样做了。每次我按“;”时缩进并创建新行或{}

if(success == 0)
{
    printf("Success\n");
    <---- if I press return key here it will go
<-- to here, and I have to tab to go to the code line.

映射返回到换行+缩进。或者,如果您愿意,您可以养成键入C-j而不是return的习惯,因为C-j已经映射到此函数。

找到它的方法是

  • 知道C-j做你想做的事
  • 使用C-h k C-j找出C-j映射到
    换行和缩进
  • 在EMACS信息中查找重新映射键

你真的想要“;”要创建新行吗?这对循环有什么影响?如果你这样做了,那么我建议创建一个新函数,该函数可以自我插入;然后进行换行和缩进。更好的是,将此添加到
prog mode hook
“发现的方法是[…]知道[某件事]。”如果ad homeem是老狗反驳的方式,我希望我永远是一只小狗。
(require 'cc-mode)

;; Auto indent on insertion of a curly brace
(add-hook 'c-mode-hook '(lambda()
 (c-toggle-auto-state t)))

;; Set coding style to indent 4 spaces
(setq c-default-style "bsd"
  c-basic-offset 4)
(add-hook 'c-mode-hook
          '(lambda ()
             (define-key c-mode-map "\C-m" 'newline-and-indent)))