2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- C/C++ Layer packages File for Spacemacs
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq c-c++-packages
|
2018-11-20 19:55:37 +00:00
|
|
|
'(
|
|
|
|
cc-mode
|
|
|
|
clang-format
|
|
|
|
company
|
|
|
|
(company-c-headers :requires company)
|
|
|
|
(company-rtags :requires company rtags)
|
|
|
|
company-ycmd
|
|
|
|
counsel-gtags
|
2019-05-10 17:40:06 +00:00
|
|
|
(cpp-auto-include
|
|
|
|
:location (recipe :fetcher github
|
|
|
|
:repo "syohex/emacs-cpp-auto-include"))
|
2018-11-20 19:55:37 +00:00
|
|
|
disaster
|
|
|
|
flycheck
|
|
|
|
(flycheck-rtags :requires flycheck rtags)
|
|
|
|
gdb-mi
|
|
|
|
ggtags
|
|
|
|
google-c-style
|
|
|
|
helm-cscope
|
|
|
|
helm-gtags
|
|
|
|
(helm-rtags :requires helm rtags)
|
|
|
|
(ivy-rtags :requires ivy rtags)
|
|
|
|
org
|
|
|
|
realgud
|
|
|
|
rtags
|
|
|
|
semantic
|
|
|
|
srefactor
|
|
|
|
stickyfunc-enhance
|
|
|
|
xcscope
|
|
|
|
ycmd
|
|
|
|
;;lsp-backend
|
|
|
|
(cquery :requires lsp-mode)
|
|
|
|
(ccls :requires lsp-mode)
|
|
|
|
projectile
|
|
|
|
))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
2014-12-14 04:08:55 +00:00
|
|
|
|
|
|
|
(defun c-c++/init-cc-mode ()
|
|
|
|
(use-package cc-mode
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2015-05-02 13:52:15 +00:00
|
|
|
:init
|
2016-08-13 13:43:37 +00:00
|
|
|
(progn
|
2019-08-15 23:21:00 +00:00
|
|
|
(when c-c++-default-mode-for-headers
|
|
|
|
(add-to-list 'auto-mode-alist
|
|
|
|
`("\\.h\\'" . ,c-c++-default-mode-for-headers)))
|
2018-05-15 20:54:03 +00:00
|
|
|
(when c-c++-enable-auto-newline
|
|
|
|
(add-hook 'c-mode-common-hook 'spacemacs//c-toggle-auto-newline)))
|
2014-12-14 04:08:55 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2015-02-23 14:59:01 +00:00
|
|
|
(require 'compile)
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
2017-08-14 07:54:15 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode mode "mc" "compile")
|
2017-07-30 21:05:50 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode mode "mg" "goto")
|
2017-08-23 09:09:38 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode mode "mp" "project")
|
2017-07-30 21:05:50 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"ga" 'projectile-find-other-file
|
|
|
|
"gA" 'projectile-find-other-file-other-window)))))
|
2015-02-23 14:59:01 +00:00
|
|
|
|
2015-05-13 07:35:46 +00:00
|
|
|
(defun c-c++/init-clang-format ()
|
|
|
|
(use-package clang-format
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (or c-c++-enable-clang-support (spacemacs//c-c++-lsp-enabled))
|
2017-04-07 09:21:05 +00:00
|
|
|
:init
|
2017-08-01 15:36:18 +00:00
|
|
|
(progn
|
2018-03-06 08:26:09 +00:00
|
|
|
(when c-c++-enable-clang-format-on-save
|
|
|
|
(spacemacs/add-to-hooks 'spacemacs/clang-format-on-save c-c++-mode-hooks))
|
2017-08-01 15:36:18 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/declare-prefix-for-mode mode "m=" "format")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"==" 'spacemacs/clang-format-region-or-buffer
|
|
|
|
"=f" 'spacemacs/clang-format-function)))))
|
2015-05-13 07:35:46 +00:00
|
|
|
|
2015-05-14 02:32:39 +00:00
|
|
|
(defun c-c++/post-init-company ()
|
2017-07-02 13:48:06 +00:00
|
|
|
(when (configuration-layer/package-used-p 'cmake-mode)
|
2017-01-02 05:39:04 +00:00
|
|
|
(spacemacs|add-company-backends :backends company-cmake :modes cmake-mode))
|
2016-02-04 13:08:55 +00:00
|
|
|
(when c-c++-enable-clang-support
|
2018-08-30 20:03:11 +00:00
|
|
|
(if (spacemacs//c-c++-lsp-enabled)
|
|
|
|
(display-warning :error "`c-c++-enable-clang-support' ignored when using lsp backend")
|
|
|
|
(progn
|
|
|
|
(spacemacs|add-company-backends :backends company-clang :modes c-mode-common)
|
|
|
|
(setq company-clang-prefix-guesser 'spacemacs/company-more-than-prefix-guesser)
|
|
|
|
(spacemacs/add-to-hooks 'spacemacs/c-c++-load-clang-args c-c++-mode-hooks)
|
|
|
|
()))))
|
2015-05-14 02:32:39 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun c-c++/init-company-c-headers ()
|
|
|
|
(use-package company-c-headers
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2017-01-02 05:39:04 +00:00
|
|
|
:init (spacemacs|add-company-backends
|
|
|
|
:backends company-c-headers
|
|
|
|
:modes c-mode-common)))
|
2015-05-14 02:32:39 +00:00
|
|
|
|
2018-01-06 07:44:33 +00:00
|
|
|
(defun c-c++/init-company-rtags ()
|
|
|
|
(use-package company-rtags
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (and (eq c-c++-backend 'rtags) c-c++-enable-rtags-completion)
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2018-01-06 07:44:33 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq rtags-completions-enabled t)
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
:backends company-rtags
|
|
|
|
:modes c-mode-common))))
|
|
|
|
|
2018-05-13 03:59:50 +00:00
|
|
|
(defun c-c++/post-init-company-ycmd ()
|
|
|
|
(spacemacs|add-company-backends :backends company-ycmd :modes c-mode-common))
|
|
|
|
|
|
|
|
(defun c-c++/post-init-counsel-gtags ()
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/counsel-gtags-define-keys-for-mode mode)))
|
|
|
|
|
2019-05-10 17:40:06 +00:00
|
|
|
(defun c-c++/init-cpp-auto-include ()
|
|
|
|
(use-package cpp-auto-include
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(when c++-enable-organize-includes-on-save
|
|
|
|
(add-hook 'c++-mode-hook #'spacemacs/c++-organize-includes-on-save))
|
|
|
|
|
|
|
|
(spacemacs/declare-prefix-for-mode 'c++-mode
|
|
|
|
"mr" "refactor")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'c++-mode
|
|
|
|
"ri" #'spacemacs/c++-organize-includes))))
|
|
|
|
|
2018-05-13 03:59:50 +00:00
|
|
|
(defun c-c++/init-disaster ()
|
|
|
|
(use-package disaster
|
|
|
|
:defer t
|
|
|
|
:commands (disaster)
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"D" 'disaster)))))
|
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun c-c++/post-init-flycheck ()
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
2017-02-14 03:27:29 +00:00
|
|
|
(spacemacs/enable-flycheck mode))
|
2015-11-15 12:21:53 +00:00
|
|
|
(when c-c++-enable-clang-support
|
2018-03-08 08:51:12 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs/c-c++-load-clang-args c-c++-mode-hooks)))
|
2015-03-16 01:44:10 +00:00
|
|
|
|
2018-01-06 07:44:33 +00:00
|
|
|
;; TODO lazy load this package
|
|
|
|
(defun c-c++/init-flycheck-rtags ()
|
|
|
|
(use-package flycheck-rtags
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (eq c-c++-backend 'rtags)))
|
2018-01-06 07:44:33 +00:00
|
|
|
|
2016-04-05 04:08:34 +00:00
|
|
|
(defun c-c++/post-init-ggtags ()
|
2016-08-15 19:24:44 +00:00
|
|
|
(add-hook 'c-mode-local-vars-hook #'spacemacs/ggtags-mode-enable)
|
|
|
|
(add-hook 'c++-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
2015-05-29 03:42:01 +00:00
|
|
|
(defun c-c++/init-gdb-mi ()
|
|
|
|
(use-package gdb-mi
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2015-05-29 03:42:01 +00:00
|
|
|
:init
|
|
|
|
(setq
|
|
|
|
;; use gdb-many-windows by default when `M-x gdb'
|
|
|
|
gdb-many-windows t
|
|
|
|
;; Non-nil means display source file containing the main routine at startup
|
|
|
|
gdb-show-main t)))
|
|
|
|
|
2018-05-13 03:59:50 +00:00
|
|
|
(defun c-c++/init-google-c-style ()
|
|
|
|
(use-package google-c-style
|
|
|
|
:if (or 'c-c++-enable-google-style 'c-c++-enable-google-newline)
|
|
|
|
:config (progn
|
|
|
|
(when c-c++-enable-google-style (add-hook 'c-mode-common-hook 'google-set-c-style))
|
|
|
|
(when c-c++-enable-google-newline (add-hook 'c-mode-common-hook 'google-make-newline-indent)))))
|
|
|
|
|
|
|
|
(defun c-c++/pre-init-helm-cscope ()
|
|
|
|
(spacemacs|use-package-add-hook xcscope
|
|
|
|
:post-init
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/setup-helm-cscope mode))))
|
2017-08-26 21:18:09 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun c-c++/post-init-helm-gtags ()
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode mode)))
|
2015-04-15 05:36:37 +00:00
|
|
|
|
2018-01-06 07:44:33 +00:00
|
|
|
;; TODO lazy load this package
|
|
|
|
(defun c-c++/init-helm-rtags ()
|
|
|
|
(use-package helm-rtags
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (eq c-c++-backend 'rtags)
|
2018-01-06 07:44:33 +00:00
|
|
|
:init (setq rtags-display-result-backend 'helm)))
|
|
|
|
|
|
|
|
;; TODO lazy load this package
|
|
|
|
(defun c-c++/init-ivy-rtags ()
|
|
|
|
(use-package ivy-rtags
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (eq c-c++-backend 'rtags)
|
2018-01-06 07:44:33 +00:00
|
|
|
:init (setq rtags-display-result-backend 'ivy)))
|
|
|
|
|
|
|
|
;; TODO lazy load this package
|
|
|
|
(defun c-c++/init-rtags ()
|
|
|
|
(use-package rtags
|
2018-08-30 20:03:11 +00:00
|
|
|
:if (eq c-c++-backend 'rtags)
|
2018-01-06 07:44:33 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq rtags-autostart-diagnostics t)
|
|
|
|
(add-hook 'rtags-jump-hook 'evil-set-jump)
|
|
|
|
(rtags-diagnostics)
|
|
|
|
;; key bindings
|
2018-01-11 03:18:29 +00:00
|
|
|
(evil-define-key 'normal rtags-mode-map
|
|
|
|
(kbd "RET") 'rtags-select-other-window
|
|
|
|
(kbd "M-RET") 'rtags-select
|
|
|
|
(kbd "q") 'rtags-bury-or-delete)
|
2018-01-06 07:44:33 +00:00
|
|
|
;; TODO check for consistency with gtags key bindings
|
|
|
|
;; see https://github.com/syl20bnr/spacemacs/blob/develop/layers/+tags/gtags/funcs.el#L70
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"g." 'spacemacs/c-c++-tags-find-symbol-at-point
|
|
|
|
"g," 'spacemacs/c-c++-tags-find-references-at-point
|
|
|
|
"g;" 'spacemacs/c-c++-tags-find-file
|
|
|
|
"g/" 'rtags-find-all-references-at-point
|
|
|
|
"g[" 'rtags-location-stack-back
|
|
|
|
"g]" 'rtags-location-stack-forward
|
|
|
|
"g>" 'spacemacs/c-c++-tags-find-symbol
|
|
|
|
"g<" 'spacemacs/c-c++-tags-find-references
|
|
|
|
"gB" 'rtags-show-rtags-buffer
|
|
|
|
"gd" 'rtags-print-dependencies
|
|
|
|
"gD" 'rtags-diagnostics
|
|
|
|
"ge" 'rtags-reparse-file
|
|
|
|
"gE" 'rtags-preprocess-file
|
|
|
|
"gF" 'rtags-fixit
|
|
|
|
"gG" 'rtags-guess-function-at-point
|
|
|
|
"gh" 'rtags-print-class-hierarchy
|
|
|
|
"gI" 'spacemacs/c-c++-tags-imenu
|
|
|
|
"gL" 'rtags-copy-and-print-current-location
|
|
|
|
"gM" 'rtags-symbol-info
|
|
|
|
"gO" 'rtags-goto-offset
|
|
|
|
"gp" 'rtags-set-current-project
|
|
|
|
"gR" 'rtags-rename-symbol
|
|
|
|
"gs" 'rtags-print-source-arguments
|
|
|
|
"gS" 'rtags-display-summary
|
|
|
|
"gT" 'rtags-taglist
|
|
|
|
"gv" 'rtags-find-virtuals-at-point
|
|
|
|
"gV" 'rtags-print-enum-value-at-point
|
|
|
|
"gX" 'rtags-fix-fixit-at-point
|
2018-07-12 20:25:55 +00:00
|
|
|
"gY" 'rtags-cycle-through-diagnostics)))))
|
2018-01-06 07:44:33 +00:00
|
|
|
|
2017-07-18 21:54:00 +00:00
|
|
|
(defun c-c++/post-init-realgud()
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
(spacemacs/add-realgud-debugger mode "gdb")))
|
2017-05-14 17:20:10 +00:00
|
|
|
|
2015-04-23 14:35:04 +00:00
|
|
|
(defun c-c++/post-init-semantic ()
|
2018-11-04 14:12:00 +00:00
|
|
|
(spacemacs/add-to-hooks 'semantic-mode c-c++-mode-hooks)
|
2019-01-08 15:43:26 +00:00
|
|
|
(when (or (configuration-layer/layer-used-p 'gtags)
|
|
|
|
(configuration-layer/layer-used-p 'lsp))
|
2018-11-04 14:12:00 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs//disable-semantic-idle-summary-mode c-c++-mode-hooks t)))
|
2015-04-23 14:35:04 +00:00
|
|
|
|
|
|
|
(defun c-c++/post-init-srefactor ()
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
2018-08-30 20:03:11 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode "r." 'srefactor-refactor-at-point))
|
2018-01-18 04:03:00 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs/load-srefactor c-c++-mode-hooks))
|
2015-03-16 01:44:10 +00:00
|
|
|
|
2015-04-16 10:43:10 +00:00
|
|
|
(defun c-c++/post-init-stickyfunc-enhance ()
|
2018-01-18 04:03:00 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs/load-stickyfunc-enhance c-c++-mode-hooks))
|
2015-04-03 21:12:56 +00:00
|
|
|
|
2015-04-28 02:27:11 +00:00
|
|
|
(defun c-c++/post-init-ycmd ()
|
2017-07-30 21:05:50 +00:00
|
|
|
(spacemacs/add-to-hooks 'ycmd-mode c-c++-mode-hooks)
|
2016-09-04 16:24:43 +00:00
|
|
|
(add-to-list 'spacemacs-jump-handlers-c++-mode '(ycmd-goto :async t))
|
|
|
|
(add-to-list 'spacemacs-jump-handlers-c-mode '(ycmd-goto :async t))
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"gG" 'ycmd-goto-imprecise)))
|
2015-04-28 02:27:11 +00:00
|
|
|
|
2018-05-30 13:07:21 +00:00
|
|
|
(defun c-c++/pre-init-org ()
|
|
|
|
(spacemacs|use-package-add-hook org
|
|
|
|
:post-config (add-to-list 'org-babel-load-languages '(C . t))))
|
|
|
|
|
2015-07-24 02:20:25 +00:00
|
|
|
(defun c-c++/pre-init-xcscope ()
|
|
|
|
(spacemacs|use-package-add-hook xcscope
|
|
|
|
:post-init
|
2017-07-30 21:05:50 +00:00
|
|
|
(dolist (mode c-c++-modes)
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode "gi" 'cscope-index-files))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
;; BEGIN LSP BACKEND PACKAGES
|
|
|
|
;; See also https://github.com/cquery-project/cquery/wiki/Emacs
|
|
|
|
(defun c-c++/init-cquery ()
|
|
|
|
(use-package cquery
|
|
|
|
:if (eq c-c++-backend 'lsp-cquery)
|
|
|
|
:config
|
2018-12-11 21:59:25 +00:00
|
|
|
(spacemacs//c-c++-lsp-config)
|
|
|
|
:hook ((c-mode c++-mode) .
|
|
|
|
(lambda () (cl-pushnew #'company-lsp company-backends) (require 'cquery) (remhash 'clangd lsp-clients) (lsp)))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
;; See also https://github.com/MaskRay/ccls/wiki/Emacs
|
|
|
|
(defun c-c++/init-ccls ()
|
|
|
|
(use-package ccls
|
|
|
|
:if (eq c-c++-backend 'lsp-ccls)
|
|
|
|
:config
|
2018-12-11 21:59:25 +00:00
|
|
|
(spacemacs//c-c++-lsp-config)
|
|
|
|
:hook ((c-mode c++-mode) .
|
|
|
|
(lambda () (cl-pushnew #'company-lsp company-backends) (require 'ccls) (remhash 'clangd lsp-clients) (lsp)))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
;;Intentionally adding both cquery and ccls cache dirs to ignore list, to facilitate switching between
|
|
|
|
;;two without multiple caches polluting projectile find file results
|
|
|
|
(defun c-c++/pre-init-projectile ()
|
|
|
|
(spacemacs|use-package-add-hook projectile
|
|
|
|
:post-config
|
|
|
|
(progn
|
|
|
|
(add-to-list 'projectile-globally-ignored-directories ".cquery_cached_index")
|
|
|
|
(add-to-list 'projectile-globally-ignored-directories ".ccls-cache")
|
|
|
|
(when c-c++-lsp-cache-dir
|
|
|
|
(add-to-list 'projectile-globally-ignored-directories c-c++-lsp-cache-dir))
|
|
|
|
(when c-c++-adopt-subprojects
|
|
|
|
(setq projectile-project-root-files-top-down-recurring
|
|
|
|
(append '("compile_commands.json"
|
2019-06-05 02:22:53 +00:00
|
|
|
".cquery"
|
|
|
|
".ccls")
|
2018-08-30 20:03:11 +00:00
|
|
|
projectile-project-root-files-top-down-recurring))))))
|
|
|
|
|
|
|
|
;; END LSP BACKEND PACKAGES
|