2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- C/C++ Layer packages File for Spacemacs
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 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
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq c-c++-packages
|
2014-12-14 04:08:55 +00:00
|
|
|
'(
|
|
|
|
cc-mode
|
|
|
|
cmake-mode
|
2015-03-22 06:23:12 +00:00
|
|
|
company
|
|
|
|
company-c-headers
|
2015-04-28 01:26:51 +00:00
|
|
|
company-ycmd
|
2014-12-23 03:51:44 +00:00
|
|
|
flycheck
|
2015-04-15 05:36:37 +00:00
|
|
|
helm-gtags
|
2015-04-23 14:35:04 +00:00
|
|
|
semantic
|
|
|
|
srefactor
|
2015-03-12 09:16:14 +00:00
|
|
|
stickyfunc-enhance
|
2015-04-28 01:26:51 +00:00
|
|
|
ycmd
|
2015-04-19 03:40:24 +00:00
|
|
|
))
|
2014-12-14 04:08:55 +00:00
|
|
|
|
2015-03-09 13:26:13 +00:00
|
|
|
(unless (version< emacs-version "24.4")
|
|
|
|
(add-to-list 'c-c++-packages 'srefactor))
|
|
|
|
|
2014-12-14 04:08:55 +00:00
|
|
|
(defun c-c++/init-cc-mode ()
|
|
|
|
(use-package cc-mode
|
|
|
|
:defer t
|
|
|
|
:config
|
|
|
|
(progn
|
2015-04-14 05:49:28 +00:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.cxx$" . c++-mode))
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.hpp$" . c++-mode))
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode))
|
2015-02-23 14:59:01 +00:00
|
|
|
(require 'compile)
|
2015-03-11 00:26:16 +00:00
|
|
|
(c-toggle-auto-newline 1)
|
2015-03-18 17:58:29 +00:00
|
|
|
(evil-leader/set-key-for-mode 'c-mode
|
|
|
|
"mga" 'projectile-find-other-file
|
|
|
|
"mgA" 'projectile-find-other-file-other-window)
|
|
|
|
(evil-leader/set-key-for-mode 'c++-mode
|
|
|
|
"mga" 'projectile-find-other-file
|
|
|
|
"mgA" 'projectile-find-other-file-other-window))))
|
2015-02-23 14:59:01 +00:00
|
|
|
|
2014-12-14 04:08:55 +00:00
|
|
|
(defun c-c++/init-cmake-mode ()
|
2015-02-23 14:59:01 +00:00
|
|
|
(use-package cmake-mode
|
2015-03-22 06:23:12 +00:00
|
|
|
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))
|
2015-04-09 03:57:22 +00:00
|
|
|
:init (push 'company-cmake company-backends-cmake-mode)))
|
2014-12-23 03:51:44 +00:00
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun c-c++/post-init-flycheck ()
|
2015-03-22 06:23:12 +00:00
|
|
|
(add-to-hooks 'flycheck-mode '(c-mode-hook c++-mode-hook)))
|
2015-03-16 01:44:10 +00:00
|
|
|
|
2015-04-15 05:36:37 +00:00
|
|
|
(defun c-c++/post-init-helm-gtags ()
|
2015-04-22 04:53:57 +00:00
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'c-mode)
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'c++-mode))
|
2015-04-15 05:36:37 +00:00
|
|
|
|
2015-04-23 14:35:04 +00:00
|
|
|
(defun c-c++/post-init-semantic ()
|
2015-04-16 10:43:10 +00:00
|
|
|
(semantic/enable-semantic-mode 'c-mode)
|
2015-04-23 14:35:04 +00:00
|
|
|
(semantic/enable-semantic-mode 'c++-mode))
|
|
|
|
|
|
|
|
(defun c-c++/post-init-srefactor ()
|
2015-04-16 10:43:10 +00:00
|
|
|
(evil-leader/set-key-for-mode 'c-mode "mr" 'srefactor-refactor-at-point)
|
2015-04-23 14:35:04 +00:00
|
|
|
(evil-leader/set-key-for-mode 'c++-mode "mr" 'srefactor-refactor-at-point)
|
|
|
|
(add-to-hooks 'spacemacs/lazy-load-srefactor '(c-mode-hook c++-mode-hook)))
|
2015-03-16 01:44:10 +00:00
|
|
|
|
2015-04-16 10:43:10 +00:00
|
|
|
(defun c-c++/post-init-stickyfunc-enhance ()
|
|
|
|
(add-to-hooks 'spacemacs/lazy-load-stickyfunc-enhance '(c-mode-hook c++-mode-hook)))
|
2015-04-03 21:12:56 +00:00
|
|
|
|
2015-04-03 23:13:52 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'auto-completion)
|
2015-04-03 21:12:56 +00:00
|
|
|
(defun c-c++/post-init-company ()
|
|
|
|
;; push this backend by default
|
2015-04-09 03:57:22 +00:00
|
|
|
(push '(company-clang :with company-yasnippet)
|
|
|
|
company-backends-c-mode-common)
|
|
|
|
(spacemacs|add-company-hook c-mode-common)
|
|
|
|
(spacemacs|add-company-hook cmake-mode)
|
2015-04-03 21:12:56 +00:00
|
|
|
|
|
|
|
;; .clang_complete file loading
|
|
|
|
;; Sets the arguments for company-clang based on a project-specific text file.
|
|
|
|
|
|
|
|
;; START Based on the Sarcasm/irony-mode compilation database code.
|
|
|
|
(defun company-mode/find-clang-complete-file ()
|
|
|
|
(when buffer-file-name
|
|
|
|
(let ((dir (locate-dominating-file buffer-file-name ".clang_complete")))
|
|
|
|
(when dir
|
|
|
|
(concat (file-name-as-directory dir) ".clang_complete")))))
|
|
|
|
|
|
|
|
(defun company-mode/load-clang-complete-file (cc-file)
|
|
|
|
"Load the flags from CC-FILE, one flag per line."
|
|
|
|
(let ((invocation-dir (expand-file-name (file-name-directory cc-file)))
|
|
|
|
(case-fold-search nil)
|
|
|
|
compile-flags)
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents cc-file)
|
|
|
|
;; Replace relative paths with absolute paths (by @trishume)
|
|
|
|
;; (goto-char (point-min))
|
|
|
|
(while (re-search-forward "\\(-I\\|-isystem\n\\)\\(\\S-\\)" nil t)
|
|
|
|
(replace-match (format "%s%s" (match-string 1)
|
|
|
|
(expand-file-name (match-string 2) invocation-dir))))
|
|
|
|
;; Turn lines into a list
|
|
|
|
(setq compile-flags
|
|
|
|
;; remove whitespaces at the end of each line, if any
|
|
|
|
(mapcar #'(lambda (line)
|
|
|
|
(if (string-match "[ \t]+$" line)
|
|
|
|
(replace-match "" t t line)
|
|
|
|
line))
|
|
|
|
(split-string (buffer-string) "\n" t))))
|
|
|
|
compile-flags))
|
|
|
|
;; END Back to things written by @trishume
|
|
|
|
|
|
|
|
(defun company-mode/more-than-prefix-guesser ()
|
|
|
|
(unless company-clang-arguments
|
|
|
|
(let* ((cc-file (company-mode/find-clang-complete-file))
|
|
|
|
(flags (if cc-file (company-mode/load-clang-complete-file cc-file) '())))
|
|
|
|
(setq-local company-clang-arguments flags)
|
|
|
|
(setq flycheck-clang-args flags)))
|
|
|
|
(company-clang-guess-prefix))
|
|
|
|
|
|
|
|
(setq company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser))
|
|
|
|
|
|
|
|
(defun c-c++/init-company-c-headers ()
|
|
|
|
(use-package company-c-headers
|
2015-04-03 23:13:52 +00:00
|
|
|
:if (configuration-layer/package-usedp 'company)
|
2015-04-03 21:12:56 +00:00
|
|
|
:defer t
|
2015-04-09 05:27:53 +00:00
|
|
|
:init (push 'company-c-headers company-backends-c-mode-common))))
|
2015-04-28 01:26:51 +00:00
|
|
|
|
|
|
|
|
2015-04-28 02:27:11 +00:00
|
|
|
(defun c-c++/post-init-ycmd ()
|
|
|
|
(add-hook 'c++-mode-hook 'ycmd-mode)
|
|
|
|
(evil-leader/set-key-for-mode 'c++-mode
|
|
|
|
"mgg" 'ycmd-goto
|
|
|
|
"mgG" 'ycmd-goto-imprecise))
|
|
|
|
|
|
|
|
(defun c-c++/post-init-company-ycmd ()
|
|
|
|
(push '(company-ycmd :with company-yasnippet)
|
|
|
|
company-backends-c-mode-common))
|