8f0e9456f8f92f73a28fee884ee4189b16ddd8be
[dotfiles.git] / emacs.d / config / init-c-cpp.el
1
2
3 ;---------------------------------------------------------------------------------------
4 ;; irony-mode
5 ;;
6 ; set LD_LIBRARY_PATH 
7 (setenv "LD_LIBRARY_PATH" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/")
8 ; load irony-mode
9 ;( add-to-list 'load-path (expand-file-name "~/.emacs.d/irony-mode/elisp/"))
10 (require 'irony)
11 (add-hook 'c++-mode-hook 'irony-mode)
12 (add-hook 'c-mode-hook 'irony-mode)
13 (add-hook 'objc-mode-hook 'irony-mode)
14
15 ;; replace the `completion-at-point' and `complete-symbol' bindings in
16 ;; irony-mode's buffers by irony-mode's function
17 (defun my-irony-mode-hook ()
18   (define-key irony-mode-map [remap completion-at-point]
19     'irony-completion-at-point-async)
20   (define-key irony-mode-map [remap complete-symbol]
21     'irony-completion-at-point-async))
22 (add-hook 'irony-mode-hook 'my-irony-mode-hook)
23 (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
24
25
26 ;---------------------------------------------------------------------------------------
27 ;; auto-complete, yasnippt, auto-complete-c-headers, iedit
28 ;;
29 ;; c/c++ auto-complete, yasnippet, auto-complet-c-headers
30 ;;https://www.youtube.com/watch?v=HTUE03LnaXA&list=PL-mFLc7R_MJet8ItKipCtYc7PWoS5KTfM
31 ;; input TAB to 
32 (require 'yasnippet)
33 (yas-global-mode 1)
34
35 ;; auto-complete-c-headers
36 (defun my:ac-c-header-init ()
37   (require 'auto-complete-c-headers)
38   (add-to-list 'ac-sources 'ac-source-c-headers)
39   (add-to-list 'achead:include-directories "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include")
40 )
41 (add-hook 'c++-mode-hook 'my:ac-c-header-init)
42 (add-hook 'c-mode-hook 'my:ac-c-header-init)
43
44 ;;; iedit, fix iedit bug in Mac, C-c ; to trigger multiple cursor edit
45 (define-key global-map (kbd "C-c ;") 'iedit-mode)
46
47
48 ;; flymake-google-cpplint-load
49 ;; define a function for flymake initialization
50 ;(defun my:flymake-google-init ()
51 ;  (require 'flymake-google-cpplint)
52 ;  (custom-set-variables
53 ;   '(flymake-google-cpplint-command "/usr/local/bin/cpplint"))
54 ;  (flymake-google-cpplint-load)
55 ;  )
56 ;(add-hook 'c-mode-hook 'my:flymake-google-init)
57 ;(add-hook 'c++-mode-hook 'my:flymake-google-init)
58
59 ;; start google-c-style with emacs
60 ;(require 'google-c-style)
61 ;(add-hook 'c-mode-hook 'google-set-c-style)
62 ;(add-hook 'c++-mode-hook 'google-make-newline-indent)
63
64
65
66 ;---------------------------------------------------------------------------------------
67 ;; cedet
68 ;;
69 (semantic-mode 1)
70 ;; let's define a function which adds semantic as a suggestion backend to auto complete
71 (defun my:add-semantic-to-autocomplete()
72   (add-to-list 'ac-sources 'ac-source-semantic)
73   )
74 (add-hook 'c-mode-common-hook 'my:add-semantic-to-autocomplete)
75 ;; turn on ede mode
76 (global-ede-mode 1)
77
78 ;(ede-cpp-root-project "my project" :file "~/demos/my_program/src/main.cpp"
79 ;                     :include-path '("/../my_inc"))
80 ;; you can use system-include-path for setting up the system header file locations.
81
82 ;; turn on automatic reparsing of open buffers in semantic
83 (global-semantic-idle-scheduler-mode 1)
84 (global-semantic-stickyfunc-mode 1)
85
86
87 (provide 'init-c-cpp)