-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp-init.el
663 lines (568 loc) · 22.5 KB
/
cpp-init.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
;; Compilation
(global-set-key (kbd "<f12>")
(lambda ()
(interactive)
(setq-local compilation-read-command nil)
(call-interactively 'compile)))
;; setup GDB
;; use gdb-many-windows by default
(setq gdb-many-windows t)
;; Non-nil means display source file containing the main routine at startup
(setq gdb-show-main t)
;; activate whitespace-mode to view all whitespace characters
(global-set-key (kbd "C-c w") 'whitespace-mode)
;; this variables must be set before load helm-gtags
;; you can change to any prefix key of your choice
(setq helm-gtags-prefix-key "\C-cg")
(use-package helm-gtags
:init
(progn
(setq helm-gtags-ignore-case t
helm-gtags-auto-update t
helm-gtags-use-input-at-cursor t
helm-gtags-pulse-at-cursor t
helm-gtags-prefix-key "\C-cg"
helm-gtags-suggested-key-mapping t)
;; Enable helm-gtags-mode in Dired so you can jump to any tag
;; when navigate project tree with Dired
(add-hook 'dired-mode-hook 'helm-gtags-mode)
;; Enable helm-gtags-mode in Eshell for the same reason as above
(add-hook 'eshell-mode-hook 'helm-gtags-mode)
;; Enable helm-gtags-mode in languages that GNU Global supports
(add-hook 'c-mode-hook 'helm-gtags-mode)
(add-hook 'c++-mode-hook 'helm-gtags-mode)
(add-hook 'java-mode-hook 'helm-gtags-mode)
(add-hook 'asm-mode-hook 'helm-gtags-mode)
;; key bindings
(with-eval-after-load 'helm-gtags
(define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
(define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
(define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
(define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
(define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
(define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))))
(use-package cc-mode)
;;(use-package semantic)
;;(global-semanticdb-minor-mode 1)
;;(global-semantic-idle-scheduler-mode 1)
;;(global-semantic-stickyfunc-mode 1)
;;(semantic-mode 1)
;;(defun company-semantic-setup ()
;; "Configure company-backends for company-semantic and company-yasnippet."
;; (delete 'company-irony company-backends)
;; (push '(company-semantic :with company-yasnippet) company-backends)
;; )
(defun company-c-headers-setup ()
(delete 'company-semantic company-backends)
(add-to-list 'company-backends 'company-c-headers))
(add-hook 'c++-mode-hook 'company-c-headers-setup)
(add-hook 'c-mode-hook 'company-c-headers-setup)
(add-hook 'c++-mode-hook 'company-semantic-setup)
(add-hook 'c-mode-hook 'company-semantic-setup)
;; (defun alexott/cedet-hook ()
;; (local-set-key "\C-c\C-j" 'semantic-ia-fast-jump)
;; (local-set-key "\C-c\C-s" 'semantic-ia-show-summary))
;; (add-hook 'c-mode-common-hook 'alexott/cedet-hook)
;; (add-hook 'c-mode-hook 'alexott/cedet-hook)
;; (add-hook 'c++-mode-hook 'alexott/cedet-hook)
;; Enable EDE only in C/C++
;;(require 'ede)
;;(global-ede-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Editing -> Editing Basics
(setq global-mark-ring-max 5000 ; increase mark ring to contains 5000 entries
mark-ring-max 5000 ; increase kill ring to contains 5000 entries
tab-width 4 ; default to 4 visible spaces to display a tab
)
(add-hook 'sh-mode-hook
(lambda ()
(setq tab-width 4)))
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(delete-selection-mode)
;; GROUP: Editing -> Killing
(setq kill-ring-max 5000 ; increase kill-ring capacity
kill-whole-line t ; if NIL, kill whole line and move the next line up
)
;; show whitespace in diff-mode
(add-hook 'diff-mode-hook
(lambda ()
(setq-local whitespace-style
'(face
tabs
tab-mark
spaces
space-mark
trailing
indentation::space
indentation::tab
newline
newline-mark))
(whitespace-mode 1)))
;; Package: volatile-highlights
;; GROUP: Editing -> Volatile Highlights
(use-package volatile-highlights
:init
(volatile-highlights-mode t))
;; Package: clean-aindent-mode
(use-package clean-aindent-mode
:init
(add-hook 'prog-mode-hook 'clean-aindent-mode))
;; Package: dtrt-indent
(use-package dtrt-indent
:init
(dtrt-indent-mode 1)
(setq dtrt-indent-verbosity 0))
;; Package: ws-butler
(use-package ws-butler
:init
(add-hook 'prog-mode-hook 'ws-butler-mode)
(add-hook 'text-mode 'ws-butler-mode)
(add-hook 'fundamental-mode 'ws-butler-mode))
;; PACKAGE: comment-dwim-2
(use-package comment-dwim-2
:bind (("M-;" . comment-dwim-2))
)
;; PACKAGE: anzu
;; GROUP: Editing -> Matching -> Isearch -> Anzu
(use-package anzu
:init
(global-anzu-mode)
(global-set-key (kbd "M-%") 'anzu-query-replace)
(global-set-key (kbd "C-M-%") 'anzu-query-replace-regexp))
;; PACKAGE: iedit
(use-package iedit
:bind (("C-;" . iedit-mode))
:init
(setq iedit-toggle-key-default nil))
;; Customized functions
(defun prelude-move-beginning-of-line (arg)
"Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
(interactive "^p")
(setq arg (or arg 1))
;; Move lines first
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(back-to-indentation)
(when (= orig-point (point))
(move-beginning-of-line 1))))
(global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single
line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single
line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;; kill a line, including whitespace characters until next non-whiepsace character
;; of next line
(defadvice kill-line (before check-position activate)
(if (member major-mode
'(emacs-lisp-mode scheme-mode lisp-mode
c-mode c++-mode objc-mode
latex-mode plain-tex-mode))
(if (and (eolp) (not (bolp)))
(progn (forward-char 1)
(just-one-space 0)
(backward-char 1)))))
;; taken from prelude-editor.el
;; automatically indenting yanked text if in programming-modes
(defvar yank-indent-modes
'(LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be listed here.")
(defvar yank-indent-blacklisted-modes
'(python-mode slim-mode haml-mode)
"Modes for which auto-indenting is suppressed.")
(defvar yank-advised-indent-threshold 1000
"Threshold (# chars) over which indentation does not automatically occur.")
(defun yank-advised-indent-function (beg end)
"Do indentation, as long as the region isn't too large."
(if (<= (- end beg) yank-advised-indent-threshold)
(indent-region beg end nil)))
(defadvice yank (after yank-indent activate)
"If current mode is one of 'yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
(defadvice yank-pop (after yank-pop-indent activate)
"If current mode is one of `yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
(when (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
;; prelude-core.el
(defun indent-buffer ()
"Indent the currently visited buffer."
(interactive)
(indent-region (point-min) (point-max)))
;; prelude-editing.el
(defcustom prelude-indent-sensitive-modes
'(coffee-mode python-mode slim-mode haml-mode yaml-mode)
"Modes for which auto-indenting is suppressed."
:type 'list)
(defun indent-region-or-buffer ()
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(unless (member major-mode prelude-indent-sensitive-modes)
(save-excursion
(if (region-active-p)
(progn
(indent-region (region-beginning) (region-end))
(message "Indented selected region."))
(progn
(indent-buffer)
(message "Indented buffer.")))
(whitespace-cleanup))))
(global-set-key (kbd "C-c i") 'indent-region-or-buffer)
;; add duplicate line function from Prelude
;; taken from prelude-core.el
(defun prelude-get-positions-of-line-or-region ()
"Return positions (beg . end) of the current line
or region."
(let (beg end)
(if (and mark-active (> (point) (mark)))
(exchange-point-and-mark))
(setq beg (line-beginning-position))
(if mark-active
(exchange-point-and-mark))
(setq end (line-end-position))
(cons beg end)))
;; smart openline
(defun prelude-smart-open-line (arg)
"Insert an empty line after the current line.
Position the cursor at its beginning, according to the current mode.
With a prefix ARG open line above the current line."
(interactive "P")
(if arg
(prelude-smart-open-line-above)
(progn
(move-end-of-line nil)
(newline-and-indent))))
(defun prelude-smart-open-line-above ()
"Insert an empty line above the current line.
Position the cursor at it's beginning, according to the current mode."
(interactive)
(move-beginning-of-line nil)
(newline-and-indent)
(forward-line -1)
(indent-according-to-mode))
(global-set-key (kbd "M-o") 'prelude-smart-open-line)
(global-set-key (kbd "M-o") 'open-line)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Clang-format
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; clang-format can be triggered using C-c C-f
;; Create clang-format file using google style
;; clang-format -style=google -dump-config > .clang-format
(use-package clang-format
:ensure nil
:bind (("C-c C-f" . clang-format-region))
:config
(defun clang-format-on-save ()
(add-hook 'before-save-hook #'clang-format-buffer nil 'local))
(add-hook 'c++-mode-hook 'clang-format-on-save)
(add-hook 'c-mode-hook 'clang-format-on-save)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Modern C++ code highlighting
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package modern-cpp-font-lock
:ensure nil
:init
(eval-when-compile
;; Silence missing function warnings
(declare-function modern-c++-font-lock-global-mode
"modern-cpp-font-lock.el"))
:config
(modern-c++-font-lock-global-mode t)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C++ keys
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package cc-mode
:ensure nil
:init
(add-to-list 'auto-mode-alist '("\\.tpp\\'" . c++-mode))
:config
;; Compilation command for C/C++
(defvar my:compile-command "clang++ -Wall -Wextra -std=c++14 ")
(define-key c++-mode-map (kbd "C-c C-c") 'compile)
(define-key c++-mode-map (kbd "C-c C-k") 'kill-compilation)
(setq compile-command my:compile-command)
;; Enable hide/show of code blocks
(add-hook 'c-mode-common-hook 'hs-minor-mode)
(use-package google-c-style
:ensure nil
:config
;; This prevents the extra two spaces in a namespace that Emacs
;; otherwise wants to put... Gawd!
(add-hook 'c-mode-common-hook 'google-set-c-style)
;; Autoindent using google style guide
(add-hook 'c-mode-common-hook 'google-make-newline-indent)
)
)
;; We want to be able to see if there is a tab character vs a space.
;; global-whitespace-mode allows us to do just that.
;; Set whitespace mode to only show tabs, not newlines/spaces.
(use-package whitespace
:ensure nil
:init
(eval-when-compile
;; Silence missing function warnings
(declare-function global-whitespace-mode "whitespace.el"))
:config
(setq whitespace-style '(tabs tab-mark))
;; Turn on whitespace mode globally.
(global-whitespace-mode t)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; string-inflection
;; used for switching between different cases, eg CamelCase,
;; lowerCamelCase, snake_case, and SCREAMING_SNAKE_CASE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package string-inflection
:ensure nil
:defer t
:bind (("C-c c i" . string-inflection-cycle)
("C-c c l" . string-inflection-lower-camelcase)
("C-c c c" . string-inflection-camelcase)
("C-c c s" . string-inflection-underscore)
("C-c c u" . string-inflection-upcase)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load asm-mode when opening assembly files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package asm-mode
:mode ("\\.s\\'"))
;;; brew install llvm
;;; brew link llvm
;;;
;; ==> llvm
;; To use the bundled libc++ please add the following LDFLAGS:
;; LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
;; llvm is keg-only, which means it was not symlinked into /usr/local,
;; because macOS already provides this software and installing another version in
;; parallel can cause all kinds of trouble.
;; If you need to have llvm first in your PATH run:
;; echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
;; For compilers to find llvm you may need to set:
;; export LDFLAGS="-L/usr/local/opt/llvm/lib"
;; export CPPFLAGS="-I/usr/local/opt/llvm/include"
;;
;; In the shell
;; rdm &
;; rc -J .
(defun my-rtags-init ()
(interactive)
(use-package rtags
:config
;; ensure that we use only rtags checking
;; https://github.com/Andersbakken/rtags#optional-1
(defun company-rtags-setup ()
"Configure company-backends for company-rtags."
(interactive)
(use-package company-rtags)
(delete 'company-semantic company-backends)
(setq rtags-completions-enabled t)
(push '(company-rtags :with company-yasnippet) company-backends))
(push 'company-rtags company-backends)
(setq rtags-autostart-diagnostics t)
(rtags-diagnostics)
;; install standard rtags keybindings. Do M-. on the symbol below to
;; jump to definition and see the keybindings.
(rtags-enable-standard-keybindings)
(define-key c-mode-base-map (kbd "M-.") (function rtags-find-symbol-at-point))
(define-key c-mode-base-map (kbd "M-,") (function rtags-find-references-at-point))
(define-key c-mode-base-map (kbd "M-?") 'rtags-display-summary)
(define-key c-mode-base-map (kbd "<C-tab>") (function company-complete))
(global-company-mode)
(rtags-start-process-unless-running)
(add-hook 'c++-mode-hook 'company-rtags-setup)
(add-hook 'c-mode-hook 'company-rtags-setup)
)
(use-package helm-rtags
:config
(setq rtags-use-helm t))
(use-package flycheck-rtags
:config
(defun flycheck-rtags-setup ()
(flycheck-select-checker 'rtags)
(setq-local flycheck-highlighting-mode nil) ;; RTags creates more accurate overlays.
(setq-local flycheck-check-syntax-automatically nil))
;; c-mode-common-hook is also called by c++-mode
(add-hook 'c-mode-hook #'flycheck-rtags-setup)
(add-hook 'c-mode-hook 'flycheck-mode)
(add-hook 'c++-mode-hook #'flycheck-rtags-setup)
(add-hook 'c++-mode-hook 'flycheck-mode))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; cmake-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-cmake-init ()
(interactive)
(use-package cmake-mode
:ensure nil
:mode ("CMakeLists.txt" ".cmake")
:hook (cmake-mode . (lambda ()
(add-to-list 'company-backends 'company-cmake)))
:config
(use-package cmake-font-lock
:ensure nil
:defer t
:commands (cmake-font-lock-activate)
:hook (cmake-mode . (lambda ()
(cmake-font-lock-activate)
(font-lock-add-keywords
nil '(("\\<\\(FIXME\\|TODO\\|BUG\\|DONE\\)"
1 font-lock-warning-face t))))))
(defun company-cmake-setup ()
(add-to-list 'company-backends 'company-cmake))
(add-hook 'cmake-mode-hook 'company-cmake-setup))
(use-package cmake-ide
:config
(cmake-ide-setup))
(use-package cmake-project
:config
(defun maybe-cmake-project-hook ()
(if (file-exists-p "CMakeLists.txt") (cmake-project-mode)))
(add-hook 'c-mode-hook 'maybe-cmake-project-hook)
(add-hook 'c++-mode-hook 'maybe-cmake-project-hook))
(use-package cpputils-cmake
:config
(add-hook 'c-mode-common-hook
(lambda ()
(if (derived-mode-p 'c-mode 'c++-mode)
(cppcm-reload-all)
)))
;; OPTIONAL, somebody reported that they can use this package with Fortran
(add-hook 'c90-mode-hook (lambda () (cppcm-reload-all)))
;; OPTIONAL, avoid typing full path when starting gdb
(global-set-key (kbd "C-c C-g")
'(lambda ()(interactive) (gud-gdb (concat "gdb --fullname " (cppcm-get-exe-path-current-buffer)))))
(setq cppcm-get-executable-full-path-callback
(lambda (path type tgt-name)
;; path is the supposed-to-be target's full path
;; type is either add_executabe or add_library
;; tgt-name is the target to built. The target's file extension is stripped
(message "cppcm-get-executable-full-path-callback called => %s %s %s" path type tgt-name)
(let* ((dir (file-name-directory path))
(file (file-name-nondirectory path)))
(cond
((string= type "add_executable")
(setq path (concat dir "bin/" file)))
;; for add_library
(t (setq path (concat dir "lib/" file)))
))
;; return the new path
(message "cppcm-get-executable-full-path-callback called => path=%s" path)
path)))
)
;;;; IRONY MODE
;;;; Before using RTags you need to start rdm and index your
;;;; project. In order to index your project, RTags requires you to
;;;; export your project's compile commands with cmake.
;;;;
;;;; $ rdm &
;;;; $ cd /path/to/project/root
;;;; $ cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1
;;;; $ rc -J .
;;;;
;;;; NOTE: Like RTags, Irony requires a compilation database. To create one run the following:
;;;;
;;;; $ cd /path/to/project/root
;;;; $ cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1
;;;; The first time you run irony you must install the irony-server by runing the command: M-x irony-install-server
;;;;
;;; To have cmake-ide automatically create a compilation commands file in your project root create a .dir-locals.el containing the following:
;;;; ((nil . ((cmake-ide-build-dir . "<PATH_TO_PROJECT_BUILD_DIRECTORY>"))))
;;;; to build irony server:
;;;; $ cd ~/Dropbox/.emacs.d/elpa/irony-20190703.1732/server
;;;; $ cmake -DCMAKE_INSTALL_PREFIX\=/Users/marcelbecker/Dropbox/.emacs.d/irony/ -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm /Users/marcelbecker/Dropbox/.emacs.d/elpa/irony-20190703.1732/server
;;;; $ cmake --build . --use-stderr --config Release --target install
(defun my-irony-init ()
(interactive)
(use-package irony
:config
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(defun my-irony-mode-hook ()
(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))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(setq company-backends (delete 'company-semantic company-backends)))
(use-package company-irony
:config
(eval-after-load 'company1
'(add-to-list 'company-backends 'company-irony)))
(use-package company-irony-c-headers
:config
(eval-after-load 'company
'(add-to-list
'company-backends '(company-irony-c-headers company-irony))))
(use-package irony-eldoc
:config
(add-hook 'irony-mode-hook #'irony-eldoc))
(use-package flycheck-irony
:config
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook #'flycheck-irony-setup)))
)
(defun my-cedet-enable ()
"Start CEDET."
(interactive)
(remove-hook 'c++-mode-hook 'company-rtags-setup)
(remove-hook 'c-mode-hook 'company-rtags-setup)
(remove-hook 'c++-mode-hook 'flycheck-rtags-setup)
(remove-hook 'c-mode-hook 'flycheck-rtags-setup)
;;(semantic-enable)
(add-hook 'c++-mode-hook 'company-c-headers-setup)
(add-hook 'c-mode-hook 'company-c-headers-setup)
(add-hook 'c++-mode-hook 'company-semantic-setup)
(add-hook 'c-mode-hook 'company-semantic-setup)
)
(defun my-irony-enable ()
"Start irony mode."
(interactive)
;;(semantic-disable)
(remove-hook 'c++-mode-hook 'company-c-headers-setup)
(remove-hook 'c-mode-hook 'company-c-headers-setup)
(remove-hook 'c++-mode-hook 'company-semantic-setup)
(remove-hook 'c-mode-hook 'company-semantic-setup)
(rtags-start-process-unless-running)
(add-hook 'c++-mode-hook 'company-rtags-setup)
(add-hook 'c-mode-hook 'company-rtags-setup)
(add-hook 'c++-mode-hook 'flycheck-rtags-setup)
(add-hook 'c-mode-hook 'flycheck-rtags-setup)
)