c/c++: replace clang with irony-mode + add cuda-mode

This commit is contained in:
Henrik Lissner 2016-04-08 14:02:55 -04:00
parent 6866fb9c5a
commit c11d28ad2e
2 changed files with 60 additions and 57 deletions

7
Cask
View file

@ -129,7 +129,12 @@
;; C/C++ -- modules/module-cc.el
(depends-on "cmake-mode")
(depends-on "glsl-mode")
(depends-on "company-c-headers")
(depends-on "cuda-mode")
;; (depends-on "company-c-headers")
(depends-on "irony")
(depends-on "irony-eldoc")
(depends-on "flycheck-irony")
(depends-on "company-irony")
;; Crystal -- modules/module-crystal.el
(depends-on "crystal-mode" :git "https://github.com/jpellerin/emacs-crystal-mode")

View file

@ -6,8 +6,9 @@
(require 'company-cmake)
(define-company-backend! cmake-mode (cmake yasnippet)))
(use-package glsl-mode
:mode ("\\.glsl\\'" "\\.vert\\'" "\\.frag\\'" "\\.geom\\'"))
(use-package glsl-mode :mode ("\\.glsl\\'" "\\.vert\\'" "\\.frag\\'" "\\.geom\\'"))
(use-package cuda-mode :mode "\\.cuh?$")
(use-package cc-mode
:defines (c-syntactic-context)
@ -20,50 +21,27 @@
:commands (c-mode c++-mode objc-mode java-mode)
:init
(associate! objc-mode :match "\\.mm$")
(add-hook! (c-mode c++-mode) '(flycheck-mode narf|init-c/c++-settings))
(add-hook! (c-mode c++-mode) '(narf|init-c/c++-settings))
:config
(setq c-basic-offset 4
c-tab-always-indent nil
(setq c-tab-always-indent nil
c-electric-flag nil)
;; TODO Clang is *really* slow in larger projects, maybe replace it with
;; irony-mode or ycmd?
(define-company-backend! c-mode-common (c-headers clang xcode))
(map! (:map c-mode-base-map
(:localleader
:nv ";" 'narf/append-semicolon)))
(defun narf/sp-point-is-template-p (id action context)
(and (sp-in-code-p id action context)
(sp-point-after-word-p id action context)))
(sp-local-pair 'c++-mode "<" ">" :when '(narf/sp-point-is-template-p))
(sp-with-modes '(c-mode c++-mode objc-mode java-mode)
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
;; Doxygen blocks
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))
(sp-local-pair "/*!" "*/" :post-handlers '(("||\n[i]" "RET") ("[d-1]< | " "SPC"))))
;; C/C++ Settings
(progn ;; C/C++
(add-hook 'c++-mode-hook 'narf|init-c++-C11-highlights)
(add-hook! (c-mode c++-mode)
(electric-indent-local-mode +1)
(setq electric-indent-chars '(?\n ?})))
(add-hook! c++-mode 'narf|init-c++-C11-highlights)
(when IS-MAC
(setq-default company-c-headers-path-system
(append '("/usr/include/" "/usr/local/include")
(f-directories "/usr/include/c++/")
(ignore-errors (f-directories "/usr/local/include/c++/"))))
(after! flycheck
(setq-default flycheck-clang-include-path '("/usr/local/include")
flycheck-gcc-include-path '("/usr/local/include"))))
(after! flycheck
(add-hook! c++-mode (setq flycheck-clang-language-standard "c++11"
flycheck-clang-standard-library "libc++")))
;; Fix enum and C++11 lambda indentation
(defadvice c-lineup-arglist (around c-lineup-arglist-indent-fix activate)
@ -77,16 +55,36 @@
;; and with unclosed brace.
(looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
0 ; no additional indent
ad-do-it)))
ad-do-it))))
;; Obj-C
(progn ;; Obj-C
(add-to-list 'magic-mode-alist
`(,(lambda ()
(and (string= (file-name-extension buffer-file-name) "h")
(re-search-forward "@\\<interface\\>"
magic-mode-regexp-match-limit t)))
. objc-mode))
(after! flycheck (add-hook! objc-mode (require 'flycheck-objc))))
. objc-mode)))
(use-package irony
:config
(setq irony-server-install-prefix (concat narf-temp-dir "/irony/"))
(push "-std=c++11" irony-additional-clang-options)
(require 'irony-eldoc)
(require 'flycheck-irony)
(flycheck-irony-setup)
(require 'company-irony)
(define-company-backend! c-mode (irony))
(define-company-backend! c++-mode (irony))
(define-company-backend! objc-mode (irony))
(add-hook! (c-mode c++-mode objc-mode)
(flycheck-mode +1)
(irony-mode +1)
(eldoc-mode +1)
(irony-eldoc +1))))
(provide 'module-cc)
;;; module-cc.el ends here