spacemacs/layers/+lang/c-c++/packages.el

145 lines
4.5 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- C/C++ Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq c-c++-packages
'(
cc-mode
disaster
clang-format
cmake-mode
company
(company-c-headers :toggle (configuration-layer/package-usedp 'company))
company-ycmd
flycheck
gdb-mi
ggtags
helm-cscope
helm-gtags
semantic
2016-03-10 13:29:04 +00:00
srefactor
stickyfunc-enhance
ycmd
2015-07-28 18:09:23 +00:00
xcscope
))
(defun c-c++/init-cc-mode ()
(use-package cc-mode
:defer t
:init
2016-08-13 13:43:37 +00:00
(progn
(add-to-list 'auto-mode-alist
`("\\.h\\'" . ,c-c++-default-mode-for-headers)))
:config
(progn
(require 'compile)
(c-toggle-auto-newline 1)
(spacemacs/set-leader-keys-for-major-mode 'c-mode
"ga" 'projectile-find-other-file
"gA" 'projectile-find-other-file-other-window)
(spacemacs/set-leader-keys-for-major-mode 'c++-mode
"ga" 'projectile-find-other-file
"gA" 'projectile-find-other-file-other-window))))
(defun c-c++/init-disaster ()
(use-package disaster
:defer t
:commands (disaster)
:init
(progn
(spacemacs/set-leader-keys-for-major-mode 'c-mode
"D" 'disaster)
(spacemacs/set-leader-keys-for-major-mode 'c++-mode
"D" 'disaster))))
(defun c-c++/init-clang-format ()
(use-package clang-format
:if c-c++-enable-clang-support))
(defun c-c++/init-cmake-mode ()
(use-package cmake-mode
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))))
(defun c-c++/post-init-company ()
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(when (configuration-layer/package-usedp 'cmake-mode)
(spacemacs|add-company-backends :backends company-cmake :modes cmake-mode))
(when c-c++-enable-clang-support
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends :backends company-clang
:modes c-mode-common)
(setq company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser)
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs/add-to-hooks 'c-c++/load-clang-args
'(c-mode-hook c++-mode-hook))))
(defun c-c++/init-company-c-headers ()
(use-package company-c-headers
:defer t
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
:init (spacemacs|add-company-backends
:backends company-c-headers
:modes c-mode-common)))
(defun c-c++/post-init-flycheck ()
2016-01-27 20:08:25 +00:00
(dolist (mode '(c-mode c++-mode))
(spacemacs/add-flycheck-hook mode))
(when c-c++-enable-clang-support
(spacemacs/add-to-hooks 'c-c++/load-clang-args '(c-mode-hook c++-mode-hook))))
2015-03-16 01:44:10 +00:00
(defun c-c++/post-init-ggtags ()
(add-hook 'c-mode-local-vars-hook #'spacemacs/ggtags-mode-enable)
(add-hook 'c++-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun c-c++/init-gdb-mi ()
(use-package gdb-mi
:defer t
: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)))
(defun c-c++/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'c-mode)
(spacemacs/helm-gtags-define-keys-for-mode 'c++-mode))
(defun c-c++/post-init-semantic ()
2016-03-11 01:18:04 +00:00
(spacemacs/add-to-hooks 'semantic-mode '(c-mode-hook c++-mode-hook)))
(defun c-c++/post-init-srefactor ()
(spacemacs/set-leader-keys-for-major-mode 'c-mode "r" 'srefactor-refactor-at-point)
(spacemacs/set-leader-keys-for-major-mode 'c++-mode "r" 'srefactor-refactor-at-point)
(spacemacs/add-to-hooks 'spacemacs/lazy-load-srefactor '(c-mode-hook c++-mode-hook)))
2015-03-16 01:44:10 +00:00
(defun c-c++/post-init-stickyfunc-enhance ()
(spacemacs/add-to-hooks 'spacemacs/lazy-load-stickyfunc-enhance '(c-mode-hook c++-mode-hook)))
(defun c-c++/post-init-ycmd ()
(add-hook 'c++-mode-hook 'ycmd-mode)
(add-hook 'c-mode-hook 'ycmd-mode)
(add-to-list 'spacemacs-jump-handlers-c++-mode '(ycmd-goto :async t))
(add-to-list 'spacemacs-jump-handlers-c-mode '(ycmd-goto :async t))
2016-08-13 13:43:37 +00:00
(dolist (mode '(c++-mode c-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"gG" 'ycmd-goto-imprecise)))
(defun c-c++/post-init-company-ycmd ()
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends :backends company-ycmd :modes c-mode-common))
(defun c-c++/pre-init-xcscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
2015-07-28 18:09:23 +00:00
(dolist (mode '(c-mode c++-mode))
(spacemacs/set-leader-keys-for-major-mode mode "gi" 'cscope-index-files))))
(defun c-c++/pre-init-helm-cscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
(dolist (mode '(c-mode c++-mode))
(spacemacs/setup-helm-cscope mode))))