2019-10-14 17:38:14 +02:00
|
|
|
;;; c++.el --- C++ settings. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-05-06 00:11:25 +02:00
|
|
|
;; Time-stamp: <2020-05-05T21:04:11+0200>
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-03-18 15:00:17 +01:00
|
|
|
(require 'basics/package-management)
|
2019-10-14 17:38:14 +02:00
|
|
|
(require 'basics/global-variables)
|
|
|
|
(require 'programming/common)
|
|
|
|
|
|
|
|
(unless slow-computer
|
2020-03-27 13:52:56 +01:00
|
|
|
(when (and (executable-find "clang-tidy")
|
|
|
|
;; clang-tidy is built into clangd >= 9.
|
|
|
|
(< (my/clangd-version) 9.0))
|
|
|
|
(use-package flycheck-clang-tidy
|
|
|
|
:after (flycheck projectile lsp-ui)
|
|
|
|
:defines (lsp-mode)
|
|
|
|
:config (progn
|
|
|
|
(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.
|
2019-10-14 17:38:14 +02:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
;; Highlight Doxygen comments.
|
|
|
|
(use-package highlight-doxygen
|
|
|
|
:custom-face
|
|
|
|
(highlight-doxygen-comment ((t (:inherit font-lock-comment-face
|
|
|
|
:foreground "#667788"))))
|
2020-03-27 16:44:58 +01:00
|
|
|
(highlight-doxygen-code-block ((t (nil)))) ; Disable background-color.
|
|
|
|
:hook (prog-mode . highlight-doxygen-mode))
|
2019-10-14 17:38:14 +02:00
|
|
|
|
|
|
|
;; Set coding style.
|
|
|
|
(use-package cc-mode
|
2020-02-18 17:10:02 +01:00
|
|
|
:commands (cc-mode)
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
:config
|
|
|
|
(c-add-style ; Construct own coding style definition.
|
|
|
|
"tastytea"
|
|
|
|
'("bsd"
|
|
|
|
(c-basic-offset . 4) ; Indent with 4 spaces.
|
2020-05-06 00:11:25 +02:00
|
|
|
(c-offsets-alist . ((innamespace . [0]) ; Don't indent in namespaces.
|
|
|
|
(statement-cont . (c-lineup-assignments
|
|
|
|
c-lineup-string-cont
|
|
|
|
c-lineup-cascaded-calls
|
|
|
|
c-lineup-class-decl-init-after-brace
|
|
|
|
+))) )))
|
2019-10-14 17:38:14 +02:00
|
|
|
(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")
|
|
|
|
)
|
|
|
|
|
2020-03-27 13:46:31 +01:00
|
|
|
;; Highlighting, indentation and documentation for CMake.
|
|
|
|
;; The CMake ebuild installs and activates the mode.
|
|
|
|
(unless (string-match-p "gentoo" operating-system-release)
|
|
|
|
(use-package cmake-mode
|
|
|
|
:mode (("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
|
2020-03-27 20:30:05 +01:00
|
|
|
("C-c C-g" . my/launch-gdb)
|
2019-10-14 17:38:14 +02:00
|
|
|
("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
|
2020-02-11 17:59:12 +01:00
|
|
|
:diminish modern-c++-font-lock-mode
|
2019-10-14 17:38:14 +02:00
|
|
|
:hook
|
|
|
|
(c++-mode . modern-c++-font-lock-mode)
|
|
|
|
)
|
|
|
|
|
2020-01-04 10:24:43 +01:00
|
|
|
(use-package find-file
|
|
|
|
:custom
|
|
|
|
(cc-search-directories '("." ; Set directories for ff-find-other-file.
|
|
|
|
"../src"
|
2020-01-27 06:31:11 +01:00
|
|
|
"../include"
|
|
|
|
"../../src"
|
|
|
|
"../../include"
|
|
|
|
"../src/*"
|
|
|
|
"../include/*"
|
|
|
|
"../../src/*"
|
|
|
|
"../../include/*"
|
|
|
|
"/usr/include"
|
|
|
|
"/usr/local/include/*"))
|
2020-01-04 10:24:43 +01:00
|
|
|
)
|
|
|
|
|
2020-04-27 04:03:48 +02:00
|
|
|
(when (executable-find "clang-format")
|
|
|
|
(use-package clang-format
|
|
|
|
:ensure nil)) ; Installed by clang.
|
|
|
|
|
2019-10-14 17:38:14 +02:00
|
|
|
(provide 'programming/c++)
|
|
|
|
;;; c++.el ends here
|