-
Notifications
You must be signed in to change notification settings - Fork 1
/
lang-cpp.el
176 lines (134 loc) · 6.18 KB
/
lang-cpp.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
;;; lang-cpp.el --- C++ and C language dialects integration
;;; Commentary:
;; SEE ALSO: lang-apple.el
;;; Code:
(require 'cc-vars)
(setq c-default-style '((java-mode . "java")
(awk-mode . "awk")
(other . "linux"))) ;; default value of "gnu"
(setq-default c-basic-offset 4)
;; (setq c-basic-offset 4)
;;; https://github.com/Lindydancer/cmake-font-lock
(use-package cmake-font-lock)
;;; https://github.com/jimhourihan/glsl-mode
(use-package glsl-mode)
;; TODO: add flycheck support for glsl
;;; https://github.com/chachi/cuda-mode
(use-package cuda-mode)
;; (setq cuda-mode-hook nil)
;; add path manually;
(add-hook 'cuda-mode-hook
(lambda ()
( setq c-basic-offset 4
flycheck-cuda-include-path (list "."))
))
;;; https://github.com/Sarcasm/irony-mode
;;
;; Prerequisites:
;;
;; irony-server provides the libclang interface to irony-mode. It uses a simple
;; protocol based on S-expression. This server, written in C++ and requires the
;; following packages to be installed on your system:
;;
;; - CMake >= 2.8.3
;; - libclang # provided by llvm via Xcode on macOS, need to install libclang
;; headers (see below)
(use-package irony)
;; ubuntu: sudo apt install cmake libclang1 libclang-dev
;; macos: brew install cmake
;;
;; Note: since relies on Homebrew, assumes macOS user already owns /usr/local
;;
;; cp -p "`xcode-select --print-path`"/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /usr/local/lib
;; cd /tmp
;; svn export http://llvm.org/svn/llvm-project/cfe/trunk/include/clang-c/
;; cp -RP clang-c /usr/local/include
;;
;; M-x irony-install-server
;; Enable irony for all c++ files
(add-hook 'c++-mode-hook (lambda ()
(irony-mode)
(irony-eldoc)
(setq flycheck-gcc-language-standard "c++11")
(setq flycheck-clang-language-standard "c++17")))
;;(setq c++-mode-hook nil)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(push 'cuda-mode irony-supported-major-modes)
\
;; (add-hook 'irony-mode-hook
;; (lambda ()
;; (define-key irony-mode-map [remap completion-at-point]
;; 'irony-completion-at-point-async)
;; (define-key irony-mode-map [remap complete-symbol]
;; 'irony-completion-at-point-async)
;; (irony-cdb-autosetup-compile-options)
;; ))
(defun dpc-irony-mode-hook ()
"Change the \\<C-M-i> binding to counsel-irony."
(define-key irony-mode-map
[remap completion-at-point] 'counsel-irony)
(define-key irony-mode-map
[remap complete-symbol] 'counsel-irony))
; Use irony's completion functions.
(add-hook 'irony-mode-hook 'dpc-irony-mode-hook)
;; use compile_commands.json obtained from CMake -D CMAKE_EXPORT_COMPILE_COMMANDS=O
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
;; https://github.com/Sarcasm/flycheck-irony
(use-package flycheck-irony)
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
;; https://github.com/ikirill/irony-eldoc
(use-package irony-eldoc)
(add-hook 'irony-mode-hook #'irony-eldoc)
;; ubuntu: sudo apt install clang
;; https://github.com/Sarcasm/company-irony
(use-package company-irony)
;;; load grouped with company-irony-c-headers below
;; (eval-after-load 'company
;; '(add-to-list 'company-backends 'company-irony))
;; https://github.com/hotpxl/company-irony-c-headers
(use-package company-irony-c-headers)
;; Load with `irony-mode` as a grouped backend
(eval-after-load 'company
'(add-to-list
'company-backends '(company-irony-c-headers company-irony)))
;; Sometimes when the compiler options change, you need to manually reload
;; header completion cache by invoking
;; company-irony-c-headers-reload-compiler-output.
;; https://github.com/stardiviner/arduino-mode
;; (use-package arduino-mode)
;; company-ardunio configuration for irony.el
;; Add arduino's include options to irony-mode's variable.
;; (add-hook 'irony-mode-hook 'company-arduino-turn-on)
;; Activate irony-mode on arduino-mode
;; (add-hook 'arduino-mode-hook 'irony-mode)
;; https://github.com/yuutayamada/company-arduino
;; (use-package company-arduino) ;; requires: irony-mode, company-irony and company-c-headers
;; Note
;; This package's default configuration is set for Linux environment, which I'm currently using, so if you are using different environment (Mac or Windows), please change the Arduino's directory paths accordingly. Related variables: company-arduino-sketch-directory-regex, company-arduino-home, company-arduino-header, company-arduino-includes-dirs and irony-arduino-includes-options.
;; https://github.com/randomphrase/company-c-headers
;; (use-package company-c-headers)
;; ;; Configuration for company-c-headers.el
;; ;; The `company-arduino-append-include-dirs' function appends
;; ;; Arduino's include directories to the default directories
;; ;; if `default-directory' is inside `company-arduino-home'. Otherwise
;; ;; just returns the default directories.
;; ;; Please change the default include directories accordingly.
;; ;; macOS: gcc -x c++ -v -E /dev/null
;; ;; /usr/local/include
;; ;; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
;; ;; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
;; ;; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
;; ;; /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
;; (defun my-company-c-headers-get-system-path ()
;; "Return the system include path for the current buffer."
;; (let ((default '("/usr/include/" "/usr/local/include/")))
;; (company-arduino-append-include-dirs default t)))
;; (setq company-c-headers-path-system 'my-company-c-headers-get-system-path)
;; (eval-after-load 'company
;; (add-to-list 'company-backends 'company-c-headers))
;; https://github.com/ZachMassia/platformio-mode
;; (use-package platformio-mode)
(provide 'lang-cpp)
;;; lang-cpp.el ends here