Universal Feature
-
Comment out codes: select code in visual mode, then M-; (Alt + semicolon); this is universal for multiple languages supported by Emacs. C, Python, Clojure are verified.
-
Use C-j instead of Enter to put cursor at the proper position (indention) of the next line;
-
Modify C indent size to 4 space: add following code into ~/.emacs:
(defun my-c-mode-common-hook () (setq c-basic-offset 4) (setq c-indent-level 4) (setq tab-width 4)) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
-
Format codes with right indents on region: C-M-\;
C Support
-
List all key-bindings: F1 b;
-
Open buffer in another window: C-x 4 b;
-
Write a makefile, compile: M-x compile; run: M-! make run; After modification of source code, you just need [M-x
M-! M-p] to do compile-run procedure, because M-p is the last command in shell mode.
Here is the demo C source file:
#include <stdio.h>
int main () {
printf("hello world\n");
return 0;
}
"return 0:" is necessary, or the return value will be 12, which will be seen as a exception by the shell.