c/c++: replace clang with irony-mode + add cuda-mode
This commit is contained in:
parent
6866fb9c5a
commit
c11d28ad2e
2 changed files with 60 additions and 57 deletions
7
Cask
7
Cask
|
@ -129,7 +129,12 @@
|
||||||
;; C/C++ -- modules/module-cc.el
|
;; C/C++ -- modules/module-cc.el
|
||||||
(depends-on "cmake-mode")
|
(depends-on "cmake-mode")
|
||||||
(depends-on "glsl-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
|
;; Crystal -- modules/module-crystal.el
|
||||||
(depends-on "crystal-mode" :git "https://github.com/jpellerin/emacs-crystal-mode")
|
(depends-on "crystal-mode" :git "https://github.com/jpellerin/emacs-crystal-mode")
|
||||||
|
|
|
@ -6,87 +6,85 @@
|
||||||
(require 'company-cmake)
|
(require 'company-cmake)
|
||||||
(define-company-backend! cmake-mode (cmake yasnippet)))
|
(define-company-backend! cmake-mode (cmake yasnippet)))
|
||||||
|
|
||||||
(use-package glsl-mode
|
(use-package glsl-mode :mode ("\\.glsl\\'" "\\.vert\\'" "\\.frag\\'" "\\.geom\\'"))
|
||||||
:mode ("\\.glsl\\'" "\\.vert\\'" "\\.frag\\'" "\\.geom\\'"))
|
|
||||||
|
(use-package cuda-mode :mode "\\.cuh?$")
|
||||||
|
|
||||||
(use-package cc-mode
|
(use-package cc-mode
|
||||||
:defines (c-syntactic-context)
|
:defines (c-syntactic-context)
|
||||||
:functions (c-toggle-electric-state c-toggle-auto-newline
|
:functions (c-toggle-electric-state c-toggle-auto-newline
|
||||||
c-skip-comments-and-strings c-forward-sws c-end-of-macro
|
c-skip-comments-and-strings c-forward-sws c-end-of-macro
|
||||||
c-font-lock-invalid-string csharp-log c-font-lock-declarators
|
c-font-lock-invalid-string csharp-log c-font-lock-declarators
|
||||||
c-get-lang-constant c-forward-keyword-clause
|
c-get-lang-constant c-forward-keyword-clause
|
||||||
c-fontify-recorded-types-and-refs c-forward-type imenu--split
|
c-fontify-recorded-types-and-refs c-forward-type imenu--split
|
||||||
c-backward-sws c-determine-limit c-beginning-of-decl-1)
|
c-backward-sws c-determine-limit c-beginning-of-decl-1)
|
||||||
:commands (c-mode c++-mode objc-mode java-mode)
|
:commands (c-mode c++-mode objc-mode java-mode)
|
||||||
:init
|
:init
|
||||||
(associate! objc-mode :match "\\.mm$")
|
(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
|
:config
|
||||||
(setq c-basic-offset 4
|
(setq c-tab-always-indent nil
|
||||||
c-tab-always-indent nil
|
|
||||||
c-electric-flag 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
|
(map! (:map c-mode-base-map
|
||||||
(:localleader
|
(:localleader
|
||||||
:nv ";" 'narf/append-semicolon)))
|
: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-local-pair 'c++-mode "<" ">" :when '(narf/sp-point-is-template-p))
|
||||||
(sp-with-modes '(c-mode c++-mode objc-mode java-mode)
|
(sp-with-modes '(c-mode c++-mode objc-mode java-mode)
|
||||||
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
|
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
|
||||||
|
|
||||||
;; Doxygen blocks
|
;; Doxygen blocks
|
||||||
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))
|
(sp-local-pair "/**" "*/" :post-handlers '(("||\n[i]" "RET") ("||\n[i]" "SPC")))
|
||||||
(sp-local-pair "/*!" "*/" :post-handlers '(("||\n[i]" "RET") ("[d-1]< | " "SPC"))))
|
(sp-local-pair "/*!" "*/" :post-handlers '(("||\n[i]" "RET") ("[d-1]< | " "SPC"))))
|
||||||
|
|
||||||
;; C/C++ Settings
|
(progn ;; C/C++
|
||||||
(add-hook! (c-mode c++-mode)
|
(add-hook 'c++-mode-hook 'narf|init-c++-C11-highlights)
|
||||||
(electric-indent-local-mode +1)
|
(add-hook! (c-mode c++-mode)
|
||||||
(setq electric-indent-chars '(?\n ?})))
|
(electric-indent-local-mode +1)
|
||||||
(add-hook! c++-mode 'narf|init-c++-C11-highlights)
|
(setq electric-indent-chars '(?\n ?})))
|
||||||
|
|
||||||
(when IS-MAC
|
;; Fix enum and C++11 lambda indentation
|
||||||
(setq-default company-c-headers-path-system
|
(defadvice c-lineup-arglist (around c-lineup-arglist-indent-fix activate)
|
||||||
(append '("/usr/include/" "/usr/local/include")
|
"Improve indentation of continued C++11 lambda function opened as argument."
|
||||||
(f-directories "/usr/include/c++/")
|
(setq ad-return-value
|
||||||
(ignore-errors (f-directories "/usr/local/include/c++/"))))
|
(if (and (eq major-mode 'c++-mode)
|
||||||
(after! flycheck
|
(ignore-errors
|
||||||
(setq-default flycheck-clang-include-path '("/usr/local/include")
|
(save-excursion
|
||||||
flycheck-gcc-include-path '("/usr/local/include"))))
|
(goto-char (c-langelem-pos langelem))
|
||||||
|
;; Detect "[...](" or "[...]{". preceded by "," or "(",
|
||||||
|
;; and with unclosed brace.
|
||||||
|
(looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
|
||||||
|
0 ; no additional indent
|
||||||
|
ad-do-it))))
|
||||||
|
|
||||||
(after! flycheck
|
(progn ;; Obj-C
|
||||||
(add-hook! c++-mode (setq flycheck-clang-language-standard "c++11"
|
(add-to-list 'magic-mode-alist
|
||||||
flycheck-clang-standard-library "libc++")))
|
`(,(lambda ()
|
||||||
|
(and (string= (file-name-extension buffer-file-name) "h")
|
||||||
|
(re-search-forward "@\\<interface\\>"
|
||||||
|
magic-mode-regexp-match-limit t)))
|
||||||
|
. objc-mode)))
|
||||||
|
|
||||||
;; Fix enum and C++11 lambda indentation
|
(use-package irony
|
||||||
(defadvice c-lineup-arglist (around c-lineup-arglist-indent-fix activate)
|
:config
|
||||||
"Improve indentation of continued C++11 lambda function opened as argument."
|
(setq irony-server-install-prefix (concat narf-temp-dir "/irony/"))
|
||||||
(setq ad-return-value
|
(push "-std=c++11" irony-additional-clang-options)
|
||||||
(if (and (eq major-mode 'c++-mode)
|
|
||||||
(ignore-errors
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (c-langelem-pos langelem))
|
|
||||||
;; Detect "[...](" or "[...]{". preceded by "," or "(",
|
|
||||||
;; and with unclosed brace.
|
|
||||||
(looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
|
|
||||||
0 ; no additional indent
|
|
||||||
ad-do-it)))
|
|
||||||
|
|
||||||
;; Obj-C
|
(require 'irony-eldoc)
|
||||||
(add-to-list 'magic-mode-alist
|
|
||||||
`(,(lambda ()
|
(require 'flycheck-irony)
|
||||||
(and (string= (file-name-extension buffer-file-name) "h")
|
(flycheck-irony-setup)
|
||||||
(re-search-forward "@\\<interface\\>"
|
|
||||||
magic-mode-regexp-match-limit t)))
|
(require 'company-irony)
|
||||||
. objc-mode))
|
(define-company-backend! c-mode (irony))
|
||||||
(after! flycheck (add-hook! objc-mode (require 'flycheck-objc))))
|
(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)
|
(provide 'module-cc)
|
||||||
;;; module-cc.el ends here
|
;;; module-cc.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue