forked from redguardtoo/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-cc-mode.el
97 lines (79 loc) · 3.37 KB
/
init-cc-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(defun c-wx-lineup-topmost-intro-cont (langelem)
(save-excursion
(beginning-of-line)
(if (re-search-forward "EVT_" (line-end-position) t)
'c-basic-offset
(c-lineup-topmost-intro-cont langelem))))
;C/C++ SECTION
(defun my-c-mode-hook ()
;; @see http://stackoverflow.com/questions/3509919/ \
;; emacs-c-opening-corresponding-header-file
(local-set-key (kbd "C-x C-o") 'ff-find-other-file)
(local-set-key "\M-f" 'c-forward-into-nomenclature)
(local-set-key "\M-b" 'c-backward-into-nomenclature)
(setq cc-search-directories '("." "/usr/include" "/usr/local/include/*" "../*/include" "$WXWIN/include"))
(setq c-basic-offset 4)
(setq c-style-variables-are-local-p nil)
;give me NO newline automatically after electric expressions are entered
(setq c-auto-newline nil)
; @see http://xugx2007.blogspot.com.au/2007/06/benjamin-rutts-emacs-c-development-tips.html
(setq compilation-window-height 8)
(setq compilation-finish-function
(lambda (buf str)
(if (string-match "exited abnormally" str)
;;there were errors
(message "compilation errors, press C-x ` to visit")
;;no errors, make the compilation window go away in 0.5 seconds
(when (string-match "*compilation*" (buffer-name buf))
;; @see http://emacswiki.org/emacs/ModeCompile#toc2
(bury-buffer "*compilation*")
(winner-undo)
(message "NO COMPILATION ERRORS!")
))))
;if (0) becomes if (0)
; { {
; ; ;
; } }
(c-set-offset 'substatement-open 0)
;first arg of arglist to functions: tabbed in once
;(default was c-lineup-arglist-intro-after-paren)
(c-set-offset 'arglist-intro '+)
;second line of arglist to functions: tabbed in once
;(default was c-lineup-arglist)
(c-set-offset 'arglist-cont-nonempty '+)
;switch/case: make each case line indent from switch
(c-set-offset 'case-label '+)
;make the ENTER key indent next line properly
(local-set-key "\C-m" 'newline-and-indent)
;syntax-highlight aggressively
;(setq font-lock-support-mode 'lazy-lock-mode)
(setq lazy-lock-defer-contextually t)
(setq lazy-lock-defer-time 0)
;make DEL take all previous whitespace with it
(c-toggle-hungry-state 1)
;make open-braces after a case: statement indent to 0 (default was '+)
(c-set-offset 'statement-case-open 0)
;make a #define be left-aligned
(setq c-electric-pound-behavior (quote (alignleft)))
;wxwdigets stuff
(c-set-offset 'topmost-intro-cont 'c-wx-lineup-topmost-intro-cont)
;do not impose restriction that all lines not top-level be indented at least
;1 (was imposed by gnu style by default)
(setq c-label-minimum-indentation 0)
(require 'fic-mode)
(add-hook 'c++-mode-hook 'turn-on-fic-mode)
; @see https://github.com/seanfisk/cmake-flymake
; make sure you project use cmake
(flymake-mode 1)
(cppcm-reload-all)
)
;; donot use c-mode-common-hook or cc-mode-hook because many major-modes use this hook
(add-hook 'c-mode-common-hook
(lambda ()
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
(setq gtags-suggested-key-mapping t)
(ggtags-mode 1))
(when (derived-mode-p 'c-mode 'c++-mode)
(my-c-mode-hook))
))
(provide 'init-cc-mode)