2019-10-14 17:38:14 +02:00
|
|
|
;;; c++.el --- C++ settings. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-01-04 10:24:43 +01:00
|
|
|
;; Time-stamp: <2020-01-04T10:24:10+0100>
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'basics/global-variables)
|
|
|
|
(require 'programming/common)
|
|
|
|
|
|
|
|
(unless slow-computer
|
|
|
|
(use-package flycheck-clang-tidy
|
|
|
|
:pin melpa
|
|
|
|
:after (flycheck projectile lsp-ui)
|
|
|
|
:if (executable-find "clang-tidy")
|
|
|
|
:config
|
|
|
|
(defun my/clang-tidy-off ()
|
|
|
|
"Disable c/c++-clang-tidy."
|
|
|
|
(when (or (eq major-mode 'c++-mode) (eq major-mode 'c-mode))
|
|
|
|
(add-to-list 'flycheck-disabled-checkers 'c/c++-clang-tidy))
|
|
|
|
)
|
|
|
|
(defun my/clang-tidy-on ()
|
|
|
|
"Enable c/c++-clang-tidy."
|
|
|
|
(when (or (eq major-mode 'c++-mode) (eq major-mode 'c-mode))
|
|
|
|
(setq-local flycheck-disabled-checkers
|
|
|
|
(remove 'c/c++-clang-tidy flycheck-disabled-checkers)))
|
|
|
|
)
|
|
|
|
|
|
|
|
(defun my/flycheck-clang-tidy-setup ()
|
|
|
|
(flycheck-clang-tidy-setup)
|
|
|
|
;; Run clang-tidy after the lsp-ui checker.
|
|
|
|
(when lsp-mode
|
|
|
|
(unless (equal (flycheck-get-next-checker-for-buffer 'lsp-ui)
|
|
|
|
'c/c++-clang-tidy)
|
|
|
|
(flycheck-add-next-checker 'lsp-ui '(warning . c/c++-clang-tidy)))))
|
|
|
|
:hook
|
|
|
|
(flycheck-mode . my/flycheck-clang-tidy-setup)
|
|
|
|
(first-change . my/clang-tidy-off) ; Disable when file is modified.
|
|
|
|
(before-save . my/clang-tidy-on) ; Enable if file is saved.
|
|
|
|
)
|
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Highlight Doxygen comments.
|
|
|
|
(use-package highlight-doxygen
|
|
|
|
:custom-face
|
|
|
|
(highlight-doxygen-comment ((t (:inherit font-lock-comment-face
|
|
|
|
:foreground "#667788"))))
|
|
|
|
(highlight-doxygen-code-block ((t (:inherit highlight-doxygen-comment-face))))
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(prog-mode . highlight-doxygen-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Set coding style.
|
|
|
|
(use-package cc-mode
|
|
|
|
:ensure nil ; Builtin.
|
|
|
|
|
|
|
|
:config
|
|
|
|
(c-add-style ; Construct own coding style definition.
|
|
|
|
"tastytea"
|
|
|
|
'("bsd"
|
|
|
|
(c-basic-offset . 4) ; Indent with 4 spaces.
|
|
|
|
(c-offsets-alist . ((innamespace . [0]))))) ; Don't indent in namespaces.
|
|
|
|
(c-add-style
|
|
|
|
"tastytea-legacy" ; For old code.
|
|
|
|
'("bsd"
|
|
|
|
(c-basic-offset . 4)))
|
|
|
|
|
|
|
|
(defun my/get-builddir ()
|
|
|
|
(if (member 'projectile-mode minor-mode-list)
|
|
|
|
(concat (projectile-project-root) "build")
|
|
|
|
nil))
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(c-default-style "tastytea")
|
|
|
|
)
|
|
|
|
|
|
|
|
(unless slow-computer
|
|
|
|
;; Client for Language Server Protocol servers.
|
|
|
|
(use-package lsp-mode
|
|
|
|
:if (executable-find "clangd")
|
2019-10-27 21:08:30 +01:00
|
|
|
:after (whitespace)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:custom
|
|
|
|
(lsp-prefer-flymake nil) ; Disable flymake.
|
|
|
|
(lsp-auto-guess-root t) ; Don't ask for project root.
|
|
|
|
(lsp-clients-clangd-args '("-compile-commands-dir=build"))
|
|
|
|
(lsp-eldoc-render-all t) ; Display all eldoc information.
|
|
|
|
|
2019-10-27 21:08:30 +01:00
|
|
|
:config
|
|
|
|
(defun my/lsp-ws-toggle ()
|
|
|
|
(if lsp-ui-peek-mode
|
|
|
|
(my/whitespace-mode-off)
|
|
|
|
(my/whitespace-mode-on)))
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:hook
|
|
|
|
(c++-mode . lsp)
|
|
|
|
(c-mode . lsp)
|
2019-10-27 21:08:30 +01:00
|
|
|
(lsp-ui-peek-mode . my/lsp-ws-toggle) ; Dots in wrong color.
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
;; Eye-candy and flycheck support for lsp-mode.
|
|
|
|
(use-package lsp-ui
|
|
|
|
:after (lsp-mode flycheck)
|
|
|
|
|
|
|
|
:custom
|
|
|
|
(lsp-ui-sideline-enable nil) ; Do not insert doc into buffer.
|
|
|
|
(lsp-ui-doc-include-signature t) ; Include signature in doc popup.
|
|
|
|
(lsp-ui-doc-enable nil) ; Disable doc popup.
|
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map lsp-ui-mode-map
|
2019-12-19 19:21:39 +01:00
|
|
|
("M-." . lsp-ui-peek-find-definitions)
|
|
|
|
("C-M-." . lsp-ui-peek-find-references)
|
|
|
|
)
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
:hook
|
|
|
|
(lsp-mode . lsp-ui-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Completions with lsp-mode.
|
|
|
|
(use-package company-lsp
|
|
|
|
:after (lsp-mode company)
|
|
|
|
|
|
|
|
:config
|
|
|
|
(push 'company-lsp company-backends)
|
|
|
|
)
|
|
|
|
|
2019-11-04 11:11:53 +01:00
|
|
|
;; ivy interface to lsp-mode.
|
2019-10-14 17:38:14 +02:00
|
|
|
(use-package lsp-ivy
|
|
|
|
:after (lsp-mode ivy)
|
|
|
|
)
|
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Highlighting and indentation for CMake.
|
|
|
|
(use-package cmake-mode
|
|
|
|
;; The CMake ebuild installs and activates the mode.
|
|
|
|
:unless (string-match-p "gentoo" operating-system-release)
|
|
|
|
|
|
|
|
:mode
|
2019-12-26 08:44:45 +01:00
|
|
|
("CMakeLists\\.txt$" . cmake-mode)
|
|
|
|
("\\.cmake$" . cmake-mode)
|
2019-10-14 17:38:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
;; CMake reference.
|
|
|
|
(use-package eldoc-cmake
|
|
|
|
:after cmake-mode
|
|
|
|
|
|
|
|
:hook
|
|
|
|
(cmake-mode . eldoc-cmake-enable)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; GUI for gdb and other debuggers.
|
|
|
|
(use-package realgud
|
|
|
|
:after (cc-mode)
|
|
|
|
:functions (realgud:gdb)
|
|
|
|
|
|
|
|
:config
|
|
|
|
(defun my/launch-gdb ()
|
|
|
|
"Load realgud and launch gdb."
|
|
|
|
(interactive)
|
|
|
|
(load-library "realgud")
|
|
|
|
(realgud:gdb))
|
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map c-mode-base-map
|
|
|
|
("C-c g" . my/launch-gdb)
|
|
|
|
("M-<down>" . nil) ; Disabled, because I use them for scrolling.
|
|
|
|
("M-<up>" . nil)) ; ^ FIXME: Does not work. ^
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Extra highlighting.
|
|
|
|
(use-package modern-cpp-font-lock
|
|
|
|
:hook
|
|
|
|
(c++-mode . modern-c++-font-lock-mode)
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Add #include directives for missing symbols.
|
|
|
|
(use-package clang-include-fixer
|
|
|
|
:ensure nil ; Installed by clang.
|
|
|
|
:if (executable-find "clang-include-fixer")
|
|
|
|
:functions (clang-include-fixer--start clang-include-fixer--add-header)
|
|
|
|
|
|
|
|
:init
|
|
|
|
(defvar my/llvm-path
|
|
|
|
(concat (file-name-directory (executable-find "clang-include-fixer")) ".."))
|
|
|
|
(add-to-list 'load-path (concat my/llvm-path "/share/clang"))
|
|
|
|
|
|
|
|
:config
|
|
|
|
(defun my/clang-find-all-symbols ()
|
|
|
|
"Invokes run-find-all-symbols.py."
|
|
|
|
(interactive)
|
|
|
|
(shell-command (concat "cd " (my/get-builddir) " && "
|
|
|
|
my/llvm-path "/share/clang/run-find-all-symbols.py"
|
|
|
|
" -b " my/llvm-path "/bin/find-all-symbols")))
|
|
|
|
|
|
|
|
(defun my/clang-include-fixer ()
|
|
|
|
"Invoke clang-include-fixer with -p=build."
|
|
|
|
(interactive)
|
|
|
|
(message (concat "Calling the include fixer. "
|
|
|
|
"This might take some seconds. Please wait."))
|
|
|
|
(clang-include-fixer--start #'clang-include-fixer--add-header
|
|
|
|
"-output-headers"
|
|
|
|
(concat "-p=" (my/get-builddir))))
|
|
|
|
|
|
|
|
:bind
|
|
|
|
("C-x M-i" . my/clang-include-fixer)
|
|
|
|
)
|
|
|
|
|
2020-01-04 10:24:43 +01:00
|
|
|
(use-package find-file
|
|
|
|
:custom
|
|
|
|
(cc-search-directories '("." ; Set directories for ff-find-other-file.
|
|
|
|
"/usr/include"
|
|
|
|
"/usr/local/include/*"
|
|
|
|
"../src"
|
|
|
|
"../include"))
|
|
|
|
)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(provide 'programming/c++)
|
|
|
|
;;; c++.el ends here
|