-
Notifications
You must be signed in to change notification settings - Fork 1
/
4-c-like-languages.el
105 lines (83 loc) · 3.05 KB
/
4-c-like-languages.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
98
99
100
101
102
103
104
105
;; Some customisations for C-like languages
;; Brackets and whitespace how I like them
(setq-default c-default-style "k&r"
c-basic-offset 2
indent-tabs-mode nil
tab-width 4)
(defun cleanup-c-buffer ()
"Correctly indent, remove tabs and extra whitespace in C source code"
(interactive)
(c-indent-region (point-min) (point-max))
(untabify (point-min) (point-max))
(whitespace-cleanup-region (point-min) (point-max)))
;; Use pretty colours when we're compiling
(use-package ansi-color
:init
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; Colour in shell?
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Compile customisation
(use-package cl
;; cl is a built-in package, so don't try and install it!
:ensure nil
:bind
(("<f5>" . recompile))
:init
(setq
compilation-scroll-output 'first-error ;; scroll until first error
compilation-skip-threshold 2 ;; skip warnings
compilation-read-command t ;; confirm compile command
compilation-window-height 12 ;; keep it readable
compilation-auto-jump-to-first-error nil ;; jump to first error auto
compilation-auto-jump-to-next-error nil ;; jump to next error
)
;; If there were no compilation errors, delete the compilation window
(setq compilation-exit-message-function
(lambda (status code msg)
;; If M-x compile exits with a 0
(when (and (eq status 'exit) (zerop code))
;; then bury the *compilation* buffer, so that C-x b doesn't go there
(bury-buffer "*compilation*")
;; and return to whatever were looking at before
(replace-buffer-in-windows "*compilation*"))
;; Always return the anticipated result of compilation-exit-message-function
(cons msg code))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Company mode for code completion
(use-package company
:config
(global-company-mode)
:diminish company-mode)
(use-package irony
:config
(use-package company-irony
:ensure t
:config
(push 'company-irony company-backends)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; rtags - C++ aware tagging
;; http://www.rtags.net
(use-package rtags
:init
(setq rtags-path "~/Tools/rtags/install/bin")
;; Start rtags automatically for C/C++
(add-hook 'c-mode-common-hook #'rtags-start-process-unless-running)
:config
(rtags-enable-standard-keybindings)
;; Get completions working with company mode
(setq rtags-autostart-diagnostics t)
(rtags-diagnostics)
(setq rtags-completions-enabled t)
(push 'company-rtags company-backends)
;; Need to have helm installed as well
(use-package helm-rtags
:init
(setq rtags-use-helm t)
:config
(setq rtags-display-result-backend 'helm))
(use-package flycheck-rtags))