mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 03:50:24 +10:00
Moving to Doom Emacs!
This commit is contained in:
174
.emacs.d/modules/lang/cc/README.org
Normal file
174
.emacs.d/modules/lang/cc/README.org
Normal file
@@ -0,0 +1,174 @@
|
||||
#+TITLE: lang/cc
|
||||
#+DATE: January 16, 2017
|
||||
#+SINCE: v2.0
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#irony-server][irony-server]]
|
||||
- [[#macos][MacOS]]
|
||||
- [[#arch-linux][Arch Linux]]
|
||||
- [[#opensuse][openSUSE]]
|
||||
- [[#rtags][rtags]]
|
||||
- [[#configure][Configure]]
|
||||
- [[#project-compile-settings][Project compile settings]]
|
||||
- [[#known-issues-with-bear-on-macos][Known issues with bear on macOS]]
|
||||
|
||||
* Description
|
||||
This module adds support for the C-family of languages: C, C++, and Objective-C.
|
||||
|
||||
+ Code completion (~company-irony~)
|
||||
+ eldoc support (~irony-eldoc~)
|
||||
+ Syntax-checking (~flycheck-irony~)
|
||||
+ Code navigation (~rtags~)
|
||||
+ File Templates ([[../../editor/file-templates/templates/c-mode][c-mode]], [[../../editor/file-templates/templates/c++-mode][c++-mode]])
|
||||
+ Snippets ([[https://github.com/hlissner/doom-snippets/tree/master/cc-mode][cc-mode]], [[https://github.com/hlissner/doom-snippets/tree/master/c-mode][c-mode]], [[https://github.com/hlissner/doom-snippets/tree/master/c++-mode][c++-mode]])
|
||||
+ Several improvements to C++11 indentation and syntax highlighting.
|
||||
|
||||
** Module Flags
|
||||
+ ~+lsp~ Disables irony+rtags and replaces them with LSP (ccls by default). This
|
||||
requires the =:tools lsp= module.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/Kitware/CMake][cmake-mode]]
|
||||
+ [[https://github.com/chachi/cuda-mode][cuda-mode]]
|
||||
+ [[https://github.com/liblit/demangle-mode][demangle-mode]]
|
||||
+ [[https://github.com/jart/disaster][disaster]]
|
||||
+ [[https://github.com/ludwigpacifici/modern-cpp-font-lock][modern-cpp-font-lock]]
|
||||
+ [[https://github.com/salmanebah/opencl-mode][opencl-mode]]
|
||||
+ [[https://github.com/jimhourihan/glsl-mode][glsl-mode]]*
|
||||
+ [[https://github.com/guidoschmidt/company-glsl][company-glsl]]*
|
||||
+ =+lsp=
|
||||
+ [[https://github.com/MaskRay/emacs-ccls][ccls]]
|
||||
+ =-lsp=
|
||||
+ [[https://github.com/Sarcasm/irony-mode][irony]]
|
||||
+ [[https://github.com/ikirill/irony-eldoc][irony-eldoc]]
|
||||
+ [[https://github.com/Sarcasm/flycheck-irony][flycheck-irony]]
|
||||
+ [[https://github.com/Sarcasm/company-irony][company-irony]]
|
||||
+ [[https://github.com/hotpxl/company-irony-c-headers][company-irony-c-headers]]
|
||||
+ [[https://github.com/Andersbakken/rtags][rtags]]
|
||||
+ [[https://github.com/Andersbakken/rtags][ivy-rtags]]
|
||||
+ [[https://github.com/Andersbakken/rtags][helm-rtags]]
|
||||
|
||||
* Prerequisites
|
||||
This module requires
|
||||
|
||||
+ irony-server
|
||||
+ rtags
|
||||
|
||||
** irony-server
|
||||
Irony powers the code completion, eldoc and syntax checking systems.
|
||||
|
||||
After installing its dependencies, run ~M-x irony-install-server~ in Emacs.
|
||||
|
||||
*** MacOS
|
||||
Due to linking issues, MacOS users must compile irony-server manually:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
brew install cmake
|
||||
brew install llvm # 1gb+ installation! May take a while!
|
||||
|
||||
git clone https://github.com/Sarcasm/irony-mode irony-mode
|
||||
mkdir irony-mode/server/build
|
||||
pushd irony-mode/server/build
|
||||
|
||||
DEST="$HOME/.emacs.d/.local/etc/irony-server/"
|
||||
cmake -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
|
||||
-DCMAKE_INSTALL_PREFIX="$DEST" ../
|
||||
cmake --build . --use-stderr --config Release --target install
|
||||
|
||||
install_name_tool -change @rpath/libclang.dylib \
|
||||
/usr/local/opt/llvm/lib/libclang.dylib \
|
||||
"$DEST/bin/irony-server"
|
||||
|
||||
# cleanup
|
||||
popd
|
||||
rm -rf irony-mode
|
||||
#+END_SRC
|
||||
|
||||
*** Arch Linux
|
||||
#+BEGIN_SRC sh
|
||||
pacman -S clang cmake
|
||||
#+END_SRC
|
||||
|
||||
*** openSUSE
|
||||
#+BEGIN_SRC sh :dir /sudo::
|
||||
sudo zypper install clang cmake
|
||||
#+END_SRC
|
||||
|
||||
** rtags
|
||||
Code navigation requires an [[https://github.com/Andersbakken/rtags][rtags]] server (~rdm~) installed. This should be
|
||||
available through your OS's package manager.
|
||||
|
||||
This module will auto-start ~rdm~ when you open C/C++ buffers (so long as one
|
||||
isn't already running). If you prefer to run it yourself:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
rdm &
|
||||
rc -J $PROJECT_ROOT # loads PROJECT_ROOT's compile_commands.json
|
||||
#+END_SRC
|
||||
|
||||
* Configure
|
||||
** Project compile settings
|
||||
By default, a set of default compile settings are defined in
|
||||
~+cc-default-compiler-options~ for C, C++ and Objective C. Irony, rtags and
|
||||
flycheck will fall back to these.
|
||||
|
||||
To make these tools aware of project specific build settings, you need a JSON
|
||||
[[https://sarcasm.github.io/notes/dev/compilation-database.html#ninja][compilation database]] present (i.e. a ~compile_commands.json~ file).
|
||||
|
||||
There are [[https://sarcasm.github.io/notes/dev/compilation-database.html][many ways to generate one]]. I use [[http://www.cmake.org/][CMake]] or [[https://github.com/rizsotto/Bear][bear]]:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
# For CMake projects
|
||||
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
|
||||
|
||||
# For non-CMake projects
|
||||
make clean
|
||||
bear make
|
||||
#+END_SRC
|
||||
|
||||
Use ~M-x +cc/reload-compile-db~ to reload your compile db in an already-open
|
||||
C/C++/ObjC buffer.
|
||||
|
||||
*** Known issues with bear on macOS
|
||||
MacOS' [[https://support.apple.com/en-us/HT204899][System Integrity Protection (SIP)]] might interfere with bear if ~make~ is
|
||||
under ~/usr/bin/~ which results in an empty compilation database.
|
||||
|
||||
From the bear [[https://github.com/rizsotto/Bear#empty-compilation-database-on-os-x-captain-or-fedora][readme]]:
|
||||
|
||||
#+begin_quote
|
||||
Security extension/modes on different operating systems might disable library
|
||||
preloads. This case Bear behaves normally, but the result compilation database
|
||||
will be empty. (Please make sure it's not the case when reporting bugs.) Notable
|
||||
examples for enabled security modes are: OS X 10.11 (check with csrutil status |
|
||||
grep 'System Integrity Protection'), and Fedora, CentOS, RHEL (check with
|
||||
sestatus | grep 'SELinux status').
|
||||
|
||||
Workaround could be to disable the security feature while running Bear. (This
|
||||
might involve reboot of your computer, so might be heavy workaround.) Another
|
||||
option if the build tool is not installed under certain directories. Or use
|
||||
tools which are using compiler wrappers. (It injects a fake compiler which does
|
||||
record the compiler invocation and calls the real compiler too.) An example for
|
||||
such tool might be scan-build. The build system shall respect CC and CXX
|
||||
environment variables.
|
||||
#+end_quote
|
||||
|
||||
A workaround might be to install ~make~ via Homebrew which puts ~gmake~
|
||||
under ~/usr/local/~.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
brew install make
|
||||
#+END_SRC
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
make clean
|
||||
bear gmake
|
||||
#+END_SRC
|
||||
|
||||
Additional info:
|
||||
+ [[https://github.com/rizsotto/Bear/issues/158][Empty compilation database with compiler in /usr/local]]
|
||||
+ [[https://github.com/rizsotto/Bear/issues/152][Workaround for 'Empty compilation database on OS X Captain]]
|
||||
188
.emacs.d/modules/lang/cc/autoload.el
Normal file
188
.emacs.d/modules/lang/cc/autoload.el
Normal file
@@ -0,0 +1,188 @@
|
||||
;;; lang/cc/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.cl\\'" . opencl-mode))
|
||||
|
||||
|
||||
;;
|
||||
;; Library
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc-c++-lineup-inclass (langelem)
|
||||
"Indent inclass lines one level further than access modifier keywords."
|
||||
(and (eq major-mode 'c++-mode)
|
||||
(or (assoc 'access-label c-syntactic-context)
|
||||
(save-excursion
|
||||
(save-match-data
|
||||
(re-search-backward
|
||||
"\\(?:p\\(?:ublic\\|r\\(?:otected\\|ivate\\)\\)\\)"
|
||||
(c-langelem-pos langelem) t))))
|
||||
'++))
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc-lineup-arglist-close (langlem)
|
||||
"Line up the closing brace in an arglist with the opening brace IF cursor is
|
||||
preceded by the opening brace or a comma (disregarding whitespace in between)."
|
||||
(when (save-excursion
|
||||
(save-match-data
|
||||
(skip-chars-backward " \t\n" (c-langelem-pos langelem))
|
||||
(memq (char-before) (list ?, ?\( ?\;))))
|
||||
(c-lineup-arglist langlem)))
|
||||
|
||||
(defun +cc--re-search-for (regexp)
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(save-match-data
|
||||
(widen)
|
||||
(goto-char (point-min))
|
||||
(re-search-forward regexp magic-mode-regexp-match-limit t)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc-c-c++-objc-mode ()
|
||||
"Uses heuristics to detect `c-mode', `objc-mode' or `c++-mode'.
|
||||
|
||||
1. Checks if there are nearby cpp/cc/m/mm files with the same name.
|
||||
2. Checks for ObjC and C++-specific keywords and libraries.
|
||||
3. Falls back to `+cc-default-header-file-mode', if set.
|
||||
4. Otherwise, activates `c-mode'.
|
||||
|
||||
This is meant to replace `c-or-c++-mode' (introduced in Emacs 26.1), which
|
||||
doesn't support specification of the fallback mode and whose heuristics are
|
||||
simpler."
|
||||
(let ((base (file-name-sans-extension (buffer-file-name (buffer-base-buffer)))))
|
||||
(cond ((file-exists-p! (or (concat base ".cpp")
|
||||
(concat base ".cc")))
|
||||
(c++-mode))
|
||||
((or (file-exists-p! (or (concat base ".m")
|
||||
(concat base ".mm")))
|
||||
(+cc--re-search-for
|
||||
(concat "^[ \t\r]*\\(?:"
|
||||
"@\\(?:class\\|interface\\|property\\|end\\)\\_>"
|
||||
"\\|#import +<Foundation/Foundation.h>"
|
||||
"\\|[-+] ([a-zA-Z0-9_]+)"
|
||||
"\\)")))
|
||||
(objc-mode))
|
||||
((+cc--re-search-for
|
||||
(let ((id "[a-zA-Z0-9_]+") (ws "[ \t\r]+") (ws-maybe "[ \t\r]*"))
|
||||
(concat "^" ws-maybe "\\(?:"
|
||||
"using" ws "\\(?:namespace" ws "std;\\|std::\\)"
|
||||
"\\|" "namespace" "\\(?:" ws id "\\)?" ws-maybe "{"
|
||||
"\\|" "class" ws id ws-maybe "[:{\n]"
|
||||
"\\|" "template" ws-maybe "<.*>"
|
||||
"\\|" "#include" ws-maybe "<\\(?:string\\|iostream\\|map\\)>"
|
||||
"\\)")))
|
||||
(c++-mode))
|
||||
((functionp +cc-default-header-file-mode)
|
||||
(funcall +cc-default-header-file-mode))
|
||||
((c-mode)))))
|
||||
|
||||
(defun +cc-resolve-include-paths ()
|
||||
(cl-loop with path = (or buffer-file-name default-directory)
|
||||
for dir in +cc-default-include-paths
|
||||
if (file-name-absolute-p dir)
|
||||
collect dir
|
||||
else if (projectile-locate-dominating-file path dir)
|
||||
collect (expand-file-name dir it)))
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc/reload-compile-db ()
|
||||
"Reload the current project's JSON compilation database."
|
||||
(interactive)
|
||||
(unless (memq major-mode '(c-mode c++-mode objc-mode))
|
||||
(user-error "Not a C/C++/ObjC buffer"))
|
||||
;; first rtag
|
||||
(when (and (featurep 'rtags)
|
||||
rtags-enabled
|
||||
(executable-find rtags-rc-binary-name))
|
||||
(with-temp-buffer
|
||||
(message "Reloaded compile commands for rtags daemon")
|
||||
(rtags-call-rc :silent t "-J" (or (doom-project-root) default-directory))))
|
||||
;; then irony
|
||||
(when (and (featurep 'irony) irony-mode)
|
||||
(+cc-init-irony-compile-options-h)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc/imenu ()
|
||||
"Invoke `rtags-imenu' if a running rdm process is available, otherwise invoke
|
||||
`imenu'."
|
||||
(interactive)
|
||||
(call-interactively
|
||||
(if (and (processp rtags-rdm-process)
|
||||
(not (eq (process-status rtags-rdm-process) 'exit))
|
||||
(not (eq (process-status rtags-rdm-process) 'signal)))
|
||||
#'rtags-imenu
|
||||
#'imenu)))
|
||||
|
||||
|
||||
;;
|
||||
;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc-fontify-constants-h ()
|
||||
"Better fontification for preprocessor constants"
|
||||
(when (memq major-mode '(c-mode c++-mode))
|
||||
(font-lock-add-keywords
|
||||
nil '(("\\<[A-Z]*_[0-9A-Z_]+\\>" . font-lock-constant-face)
|
||||
("\\<[A-Z]\\{3,\\}\\>" . font-lock-constant-face))
|
||||
t)))
|
||||
|
||||
(defvar +cc--project-includes-alist nil)
|
||||
;;;###autoload
|
||||
(defun +cc-init-irony-compile-options-h ()
|
||||
"Initialize compiler options for irony-mode. It searches for the nearest
|
||||
compilation database and initailizes it, otherwise falling back on
|
||||
`+cc-default-compiler-options' and `+cc-default-include-paths'.
|
||||
|
||||
See https://github.com/Sarcasm/irony-mode#compilation-database for details on
|
||||
compilation dbs."
|
||||
(when (memq major-mode '(c-mode c++-mode objc-mode))
|
||||
(require 'irony-cdb)
|
||||
(unless (irony-cdb-autosetup-compile-options)
|
||||
(let ((project-root (doom-project-root))
|
||||
(include-paths (+cc-resolve-include-paths)))
|
||||
(setf (alist-get project-root +cc--project-includes-alist)
|
||||
include-paths)
|
||||
(irony-cdb--update-compile-options
|
||||
(append (delq nil (cdr-safe (assq major-mode +cc-default-compiler-options)))
|
||||
(cl-loop for path in include-paths
|
||||
collect (format "-I%s" path)))
|
||||
project-root)))))
|
||||
|
||||
;; ;;;###autoload
|
||||
;; (defun +cc|init-ccls-compile-options ()
|
||||
;; "TODO"
|
||||
;; (when (memq major-mode '(c-mode c++-mode objc-mode))
|
||||
;; (when-let (include-paths (+cc-resolve-include-paths))
|
||||
;; (let ((args (delq nil (cdr-safe (assq major-mode +cc-default-compiler-options)))))
|
||||
;; (setf (alist-get (or (lsp-workspace-root)
|
||||
;; (lsp--suggest-project-root)
|
||||
;; (doom-project-root))
|
||||
;; +cc--project-includes-alist)
|
||||
;; include-paths)
|
||||
;; (setq ccls-initialization-options
|
||||
;; `(:clang (:extraArgs
|
||||
;; [,@(cl-loop for path in include-paths
|
||||
;; collect (format "-I%s" path))])))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +cc-init-ffap-integration-h ()
|
||||
"Takes the local project include paths and registers them with ffap.
|
||||
This way, `find-file-at-point' (and `+lookup/file') will know where to find most
|
||||
header files."
|
||||
(when-let (project-root (or (bound-and-true-p irony--working-directory)
|
||||
(and (featurep 'lsp)
|
||||
(or (lsp-workspace-root)
|
||||
(doom-project-root)))))
|
||||
(require 'ffap)
|
||||
(make-local-variable 'ffap-c-path)
|
||||
(make-local-variable 'ffap-c++-path)
|
||||
(cl-loop for dir in (or (cdr (assoc project-root +cc--project-includes-alist))
|
||||
(+cc-resolve-include-paths))
|
||||
do (add-to-list (pcase major-mode
|
||||
(`c-mode 'ffap-c-path)
|
||||
(`c++-mode 'ffap-c++-path))
|
||||
(expand-file-name dir project-root)))))
|
||||
263
.emacs.d/modules/lang/cc/config.el
Normal file
263
.emacs.d/modules/lang/cc/config.el
Normal file
@@ -0,0 +1,263 @@
|
||||
;;; lang/cc/config.el --- c, c++, and obj-c -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +cc-default-include-paths
|
||||
(list "include"
|
||||
"includes")
|
||||
"A list of default relative paths which will be searched for up from the
|
||||
current file, to be passed to irony as extra header search paths. Paths can be
|
||||
absolute. This is ignored if your project has a compilation database.
|
||||
|
||||
This is ignored by ccls.")
|
||||
|
||||
(defvar +cc-default-header-file-mode 'c-mode
|
||||
"Fallback major mode for .h files if all other heuristics fail (in
|
||||
`+cc-c-c++-objc-mode').")
|
||||
|
||||
(defvar +cc-default-compiler-options
|
||||
`((c-mode . nil)
|
||||
(c++-mode
|
||||
. ,(list "-std=c++1z" ; use C++17 draft by default
|
||||
(when IS-MAC
|
||||
;; NOTE beware: you'll get abi-inconsistencies when passing
|
||||
;; std-objects to libraries linked with libstdc++ (e.g. if you
|
||||
;; use boost which wasn't compiled with libc++)
|
||||
"-stdlib=libc++")))
|
||||
(objc-mode . nil))
|
||||
"A list of default compiler options for the C family. These are ignored if a
|
||||
compilation database is present in the project.
|
||||
|
||||
This is ignored by ccls.")
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! cc-mode
|
||||
:commands (c-mode c++-mode objc-mode java-mode)
|
||||
:mode ("\\.mm\\'" . objc-mode)
|
||||
:init
|
||||
;; The plusses in c++-mode can be annoying to search for ivy/helm (which reads
|
||||
;; queries as regexps), so we add these for convenience.
|
||||
(defalias 'cpp-mode 'c++-mode)
|
||||
(defvaralias 'cpp-mode-map 'c++-mode-map)
|
||||
|
||||
;; Activate `c-mode', `c++-mode' or `objc-mode' depending on heuristics
|
||||
(add-to-list 'auto-mode-alist '("\\.h\\'" . +cc-c-c++-objc-mode))
|
||||
|
||||
;; Ensure find-file-at-point works in C modes, must be added before irony
|
||||
;; and/or lsp hooks are run.
|
||||
(add-hook! '(c-mode-local-vars-hook
|
||||
c++-mode-local-vars-hook
|
||||
objc-mode-local-vars-hook)
|
||||
#'+cc-init-ffap-integration-h)
|
||||
|
||||
:config
|
||||
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\} ?\{))
|
||||
(set-docsets! 'c-mode "C")
|
||||
(set-docsets! 'c++-mode "C++" "Boost")
|
||||
|
||||
(set-rotate-patterns! 'c++-mode
|
||||
:symbols '(("public" "protected" "private")
|
||||
("class" "struct")))
|
||||
|
||||
(set-pretty-symbols! '(c-mode c++-mode)
|
||||
;; Functional
|
||||
;; :def "void "
|
||||
;; Types
|
||||
:null "nullptr"
|
||||
:true "true" :false "false"
|
||||
:int "int" :float "float"
|
||||
:str "std::string"
|
||||
:bool "bool"
|
||||
;; Flow
|
||||
:not "!"
|
||||
:and "&&" :or "||"
|
||||
:for "for"
|
||||
:return "return"
|
||||
:yield "#require")
|
||||
|
||||
;;; Better fontification (also see `modern-cpp-font-lock')
|
||||
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
||||
(add-hook! '(c-mode-hook c++-mode-hook) #'+cc-fontify-constants-h)
|
||||
|
||||
;; Custom style, based off of linux
|
||||
(setq c-basic-offset tab-width
|
||||
c-backspace-function #'delete-backward-char)
|
||||
|
||||
(c-add-style
|
||||
"doom" '((c-comment-only-line-offset . 0)
|
||||
(c-hanging-braces-alist (brace-list-open)
|
||||
(brace-entry-open)
|
||||
(substatement-open after)
|
||||
(block-close . c-snug-do-while)
|
||||
(arglist-cont-nonempty))
|
||||
(c-cleanup-list brace-else-brace)
|
||||
(c-offsets-alist
|
||||
(knr-argdecl-intro . 0)
|
||||
(substatement-open . 0)
|
||||
(substatement-label . 0)
|
||||
(statement-cont . +)
|
||||
(case-label . +)
|
||||
;; align args with open brace OR don't indent at all (if open
|
||||
;; brace is at eolp and close brace is after arg with no trailing
|
||||
;; comma)
|
||||
(brace-list-intro . 0)
|
||||
(brace-list-close . -)
|
||||
(arglist-intro . +)
|
||||
(arglist-close +cc-lineup-arglist-close 0)
|
||||
;; don't over-indent lambda blocks
|
||||
(inline-open . 0)
|
||||
(inlambda . 0)
|
||||
;; indent access keywords +1 level, and properties beneath them
|
||||
;; another level
|
||||
(access-label . -)
|
||||
(inclass +cc-c++-lineup-inclass +)
|
||||
(label . 0))))
|
||||
|
||||
(when (listp c-default-style)
|
||||
(setf (alist-get 'other c-default-style) "doom")))
|
||||
|
||||
|
||||
(use-package! modern-cpp-font-lock
|
||||
:hook (c++-mode . modern-c++-font-lock-mode))
|
||||
|
||||
|
||||
(use-package! irony
|
||||
:unless (featurep! +lsp)
|
||||
:commands (irony-install-server irony-mode)
|
||||
:preface
|
||||
(setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
|
||||
:init
|
||||
(add-hook! '(c-mode-local-vars-hook
|
||||
c++-mode-local-vars-hook
|
||||
objc-mode-local-vars-hook)
|
||||
(defun +cc-init-irony-mode-h ()
|
||||
(if (file-directory-p irony-server-install-prefix)
|
||||
(irony-mode +1)
|
||||
(message "Irony server isn't installed"))))
|
||||
:config
|
||||
(setq irony-cdb-search-directory-list '("." "build" "build-conda"))
|
||||
|
||||
;; Initialize compilation database, if present. Otherwise, fall back on
|
||||
;; `+cc-default-compiler-options'.
|
||||
(add-hook 'irony-mode-hook #'+cc-init-irony-compile-options-h)
|
||||
|
||||
(use-package! irony-eldoc
|
||||
:hook (irony-mode . irony-eldoc))
|
||||
|
||||
(use-package! flycheck-irony
|
||||
:when (featurep! :tools flycheck)
|
||||
:config (flycheck-irony-setup))
|
||||
|
||||
(use-package! company-irony
|
||||
:when (featurep! :completion company)
|
||||
:init
|
||||
(set-company-backend! 'irony-mode
|
||||
'(:separate company-irony-c-headers company-irony))
|
||||
:config
|
||||
(require 'company-irony-c-headers)))
|
||||
|
||||
|
||||
;;
|
||||
;; Major modes
|
||||
|
||||
(use-package! cmake-mode
|
||||
:defer t
|
||||
:config (set-docsets! 'cmake-mode "CMake"))
|
||||
|
||||
(use-package! company-cmake ; for `cmake-mode'
|
||||
:when (featurep! :completion company)
|
||||
:after cmake-mode
|
||||
:config (set-company-backend! 'cmake-mode 'company-cmake))
|
||||
|
||||
|
||||
(use-package! demangle-mode
|
||||
:hook llvm-mode)
|
||||
|
||||
|
||||
(use-package! company-glsl ; for `glsl-mode'
|
||||
:when (featurep! :completion company)
|
||||
:after glsl-mode
|
||||
:config (set-company-backend! 'glsl-mode 'company-glsl))
|
||||
|
||||
|
||||
;;
|
||||
;; Rtags Support
|
||||
|
||||
(use-package! rtags
|
||||
:unless (featurep! +lsp)
|
||||
:commands rtags-executable-find
|
||||
:preface
|
||||
(setq rtags-install-path (concat doom-etc-dir "rtags/"))
|
||||
:init
|
||||
(add-hook! '(c-mode-local-vars-hook
|
||||
c++-mode-local-vars-hook
|
||||
objc-mode-local-vars-hook)
|
||||
(defun +cc-init-rtags-h ()
|
||||
"Start an rtags server in c-mode and c++-mode buffers."
|
||||
(when (and (require 'rtags nil t)
|
||||
(rtags-executable-find rtags-rdm-binary-name))
|
||||
(rtags-start-process-unless-running))))
|
||||
:config
|
||||
(setq rtags-autostart-diagnostics t
|
||||
rtags-use-bookmarks nil
|
||||
rtags-completions-enabled nil
|
||||
rtags-display-result-backend
|
||||
(cond ((featurep! :completion ivy) 'ivy)
|
||||
((featurep! :completion helm) 'helm)
|
||||
('default))
|
||||
;; These executables are named rtags-* on debian
|
||||
rtags-rc-binary-name
|
||||
(or (cl-find-if #'executable-find (list rtags-rc-binary-name "rtags-rc"))
|
||||
rtags-rc-binary-name)
|
||||
rtags-rdm-binary-name
|
||||
(or (cl-find-if #'executable-find (list rtags-rdm-binary-name "rtags-rdm"))
|
||||
rtags-rdm-binary-name)
|
||||
;; If not using ivy or helm to view results, use a pop-up window rather
|
||||
;; than displaying it in the current window...
|
||||
rtags-results-buffer-other-window t
|
||||
;; ...and don't auto-jump to first match before making a selection.
|
||||
rtags-jump-to-first-match nil)
|
||||
|
||||
(set-lookup-handlers! '(c-mode c++-mode)
|
||||
:definition #'rtags-find-symbol-at-point
|
||||
:references #'rtags-find-references-at-point)
|
||||
|
||||
(add-hook! 'kill-emacs-hook (ignore-errors (rtags-cancel-process)))
|
||||
|
||||
;; Use rtags-imenu instead of imenu/counsel-imenu
|
||||
(define-key! (c-mode-map c++-mode-map) [remap imenu] #'+cc/imenu)
|
||||
|
||||
(add-hook 'rtags-jump-hook #'better-jumper-set-jump)
|
||||
(add-hook 'rtags-after-find-file-hook #'recenter))
|
||||
|
||||
|
||||
;;
|
||||
;; LSP
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(add-hook! '(c-mode-local-vars-hook
|
||||
c++-mode-local-vars-hook
|
||||
objc-mode-local-vars-hook)
|
||||
(defun +cc-init-lsp-h ()
|
||||
(setq-local company-transformers nil)
|
||||
(setq-local company-lsp-async t)
|
||||
(setq-local company-lsp-cache-candidates nil)
|
||||
(lsp!))))
|
||||
|
||||
|
||||
(use-package! ccls
|
||||
:when (featurep! +lsp)
|
||||
:after lsp
|
||||
:init
|
||||
(after! projectile
|
||||
(add-to-list 'projectile-globally-ignored-directories ".ccls-cache")
|
||||
(add-to-list 'projectile-project-root-files-bottom-up ".ccls-root")
|
||||
(add-to-list 'projectile-project-root-files-top-down-recurring "compile_commands.json"))
|
||||
:config
|
||||
(when IS-MAC
|
||||
(setq ccls-initialization-options
|
||||
`(:clang ,(list :extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1"
|
||||
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
|
||||
"-isystem/usr/local/include"]
|
||||
:resourceDir (string-trim (shell-command-to-string "clang -print-resource-dir")))))))
|
||||
24
.emacs.d/modules/lang/cc/doctor.el
Normal file
24
.emacs.d/modules/lang/cc/doctor.el
Normal file
@@ -0,0 +1,24 @@
|
||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
;;; lang/cc/doctor.el
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(when (require 'rtags nil t)
|
||||
;; rtags
|
||||
(when-let (bins (cl-remove-if #'rtags-executable-find
|
||||
(list rtags-rdm-binary-name
|
||||
rtags-rc-binary-name)))
|
||||
(warn! "Couldn't find the rtag client and/or server programs %s. Disabling rtags support"
|
||||
bins)))
|
||||
|
||||
;; irony server
|
||||
(when (require 'irony nil t)
|
||||
(unless (file-directory-p irony-server-install-prefix)
|
||||
(warn! "Irony server isn't installed. Run M-x irony-install-server")))
|
||||
|
||||
(when (featurep! :completion company)
|
||||
;; glslangValidator
|
||||
(unless (executable-find "glslangValidator")
|
||||
(warn! "Couldn't find glslangValidator. GLSL code completion is disabled")))
|
||||
28
.emacs.d/modules/lang/cc/packages.el
Normal file
28
.emacs.d/modules/lang/cc/packages.el
Normal file
@@ -0,0 +1,28 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/cc/packages.el
|
||||
|
||||
(package! cmake-mode :recipe (:host github :repo "emacsmirror/cmake-mode" :files (:defaults "*")))
|
||||
(package! cuda-mode)
|
||||
(package! demangle-mode)
|
||||
(package! disaster)
|
||||
(package! modern-cpp-font-lock)
|
||||
(package! opencl-mode)
|
||||
|
||||
(when (package! glsl-mode)
|
||||
(when (featurep! :completion company)
|
||||
(package! company-glsl :recipe (:host github :repo "Kaali/company-glsl"))))
|
||||
|
||||
(if (featurep! +lsp)
|
||||
(package! ccls)
|
||||
(when (package! irony)
|
||||
(package! irony-eldoc)
|
||||
(when (featurep! :tools flycheck)
|
||||
(package! flycheck-irony))
|
||||
(when (featurep! :completion company)
|
||||
(package! company-irony)
|
||||
(package! company-irony-c-headers)))
|
||||
(when (package! rtags)
|
||||
(when (featurep! :completion ivy)
|
||||
(package! ivy-rtags))
|
||||
(when (featurep! :completion helm)
|
||||
(package! helm-rtags))))
|
||||
Reference in New Issue
Block a user