当按“返回”键时,Emacs返回到缩进的代码行(Emacs return to indented code line when press 'return' key)

我使用的是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.

但是,如果我按下返回键,它将把我带到第0列而不是我正在处理的代码缩进行,即

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

I am using emacs 22.2.1 and Ubuntu 9.04

I have done this in my .emacs file. Which indents and creates a new line each time I press ';' or '{ }'

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.

However, if I press the return key it will take me to column 0 not the indent line of code I am working on i.e.

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

贴图返回换行符+缩进。 或者,如果你喜欢,你可以形成输入Cj而不是返回的习惯,因为Cj已经映射到这个函数。

(add-hook 'c-mode-hook '(lambda () (define-key c-mode-map "\C-m" 'newline-and-indent)))

maps return to newline + indent. Or, if you like, you can form the habit of typing C-j instead of return, since C-j is already mapped to this function.

更多推荐