lang/cc: refactor
This commit is contained in:
parent
c60970ff2d
commit
5f141a82ab
1 changed files with 32 additions and 35 deletions
|
@ -6,8 +6,7 @@
|
||||||
:init
|
:init
|
||||||
(setq-default c-basic-offset tab-width)
|
(setq-default c-basic-offset tab-width)
|
||||||
|
|
||||||
;; Auto-detect C++ header files
|
(defun +cc--c++-header-file-p ()
|
||||||
(push (cons (lambda ()
|
|
||||||
(and buffer-file-name
|
(and buffer-file-name
|
||||||
(equal (file-name-extension buffer-file-name) "h")
|
(equal (file-name-extension buffer-file-name) "h")
|
||||||
(or (file-exists-p (expand-file-name
|
(or (file-exists-p (expand-file-name
|
||||||
|
@ -17,27 +16,20 @@
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
(projectile-current-project-files))))
|
(projectile-current-project-files))))
|
||||||
(equal (file-name-extension file) "cpp")))))
|
(equal (file-name-extension file) "cpp")))))
|
||||||
'c++-mode)
|
|
||||||
magic-mode-alist)
|
|
||||||
|
|
||||||
;; Auto-detect Obj-C header files
|
(defun +cc--objc-header-file-p ()
|
||||||
(push (cons (lambda ()
|
|
||||||
(and buffer-file-name
|
(and buffer-file-name
|
||||||
(equal (file-name-extension buffer-file-name) "h")
|
(equal (file-name-extension buffer-file-name) "h")
|
||||||
(re-search-forward "@\\<interface\\>" magic-mode-regexp-match-limit t)))
|
(re-search-forward "@\\<interface\\>" magic-mode-regexp-match-limit t)))
|
||||||
'objc-mode)
|
|
||||||
magic-mode-alist)
|
;; Auto-detect C++/Obj-C header files
|
||||||
|
(push (cons #'+cc--c++-header-file-p 'c++-mode) magic-mode-alist)
|
||||||
|
(push (cons #'+cc--objc-header-file-p 'objc-mode) magic-mode-alist)
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(setq c-tab-always-indent nil
|
(setq c-tab-always-indent nil
|
||||||
c-electric-flag nil)
|
c-electric-flag nil)
|
||||||
|
|
||||||
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
|
||||||
;; extra highlights for numbers in C (`modern-cpp-font-lock' offers something better for C++)
|
|
||||||
(add-hook 'c-mode-hook #'highlight-numbers-mode)
|
|
||||||
;; Fontification of C++11 string literals
|
|
||||||
(add-hook 'c++-mode-hook #'+cc|extra-fontify-c++)
|
|
||||||
|
|
||||||
(set! :electric '(c-mode c++-mode objc-mode java-mode)
|
(set! :electric '(c-mode c++-mode objc-mode java-mode)
|
||||||
:chars '(?\n ?\}))
|
:chars '(?\n ?\}))
|
||||||
|
|
||||||
|
@ -45,6 +37,10 @@
|
||||||
'(c-mode c++-mode objc-mode)
|
'(c-mode c++-mode objc-mode)
|
||||||
'(company-irony-c-headers company-irony))
|
'(company-irony-c-headers company-irony))
|
||||||
|
|
||||||
|
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
||||||
|
(add-hook 'c-mode-hook #'highlight-numbers-mode) ; fontify numbers in C
|
||||||
|
(add-hook 'c++-mode-hook #'+cc|extra-fontify-c++) ; fontify C++11 string literals
|
||||||
|
|
||||||
(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 "<" ">" :when '(+cc-sp-point-is-template-p +cc-sp-point-after-include-p))
|
(sp-local-pair "<" ">" :when '(+cc-sp-point-is-template-p +cc-sp-point-after-include-p))
|
||||||
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
|
(sp-local-pair "/*" "*/" :post-handlers '(("||\n[i]" "RET") ("| " "SPC")))
|
||||||
|
@ -98,10 +94,9 @@
|
||||||
:map c++-mode-map
|
:map c++-mode-map
|
||||||
"}" nil
|
"}" nil
|
||||||
|
|
||||||
;; Smartparens and cc-mode both try to autoclose
|
;; Smartparens and cc-mode both try to autoclose angle-brackets
|
||||||
;; angle-brackets intelligently. The result isn't very
|
;; intelligently. The result isn't very intelligent (causes redundant
|
||||||
;; intelligent (causes redundant characters), so we just do it
|
;; characters), so just do it ourselves.
|
||||||
;; ourselves.
|
|
||||||
"<" nil
|
"<" nil
|
||||||
:map (c-mode-base-map c++-mode-map)
|
:map (c-mode-base-map c++-mode-map)
|
||||||
:i ">" #'+cc/autoclose->-maybe))
|
:i ">" #'+cc/autoclose->-maybe))
|
||||||
|
@ -119,15 +114,17 @@
|
||||||
(setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
|
(setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
|
||||||
:init
|
:init
|
||||||
(defun +cc|init-irony-mode ()
|
(defun +cc|init-irony-mode ()
|
||||||
(when (memq major-mode '(c-mode c++-mode objc-mode))
|
(when (and (memq major-mode '(c-mode c++-mode objc-mode))
|
||||||
(when (file-directory-p irony-server-install-prefix)
|
(file-directory-p irony-server-install-prefix))
|
||||||
(irony-mode +1))))
|
(irony-mode +1)))
|
||||||
(add-hook 'c-mode-common-hook #'+cc|init-irony-mode)
|
(add-hook 'c-mode-common-hook #'+cc|init-irony-mode)
|
||||||
:config
|
:config
|
||||||
(add-hook! 'irony-mode-hook #'(irony-eldoc flycheck-mode))
|
(add-hook! 'irony-mode-hook #'(irony-eldoc flycheck-mode))
|
||||||
(add-hook! 'c++-mode-hook
|
|
||||||
|
(defun +cc|init-c++11-clang-options ()
|
||||||
(make-local-variable 'irony-additional-clang-options)
|
(make-local-variable 'irony-additional-clang-options)
|
||||||
(push "-std=c++11" irony-additional-clang-options))
|
(cl-pushnew "-std=c++11" irony-additional-clang-options :test 'equal))
|
||||||
|
(add-hook 'c++-mode-hook #'+cc|init-c++11-clang-options)
|
||||||
|
|
||||||
(map! :map irony-mode-map
|
(map! :map irony-mode-map
|
||||||
[remap completion-at-point] #'counsel-irony
|
[remap completion-at-point] #'counsel-irony
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue