Updating Doom Emacs.

This commit is contained in:
Derek Taylor
2020-06-19 22:43:40 -05:00
parent 0f664d532a
commit a5c86c514a
453 changed files with 13527 additions and 12455 deletions

View File

@@ -16,6 +16,8 @@
- [[#configure][Configure]]
- [[#project-compile-settings][Project compile settings]]
- [[#known-issues-with-bear-on-macos][Known issues with bear on macOS]]
- [[#appendix][Appendix]]
- [[#eglot-specific-bindings][Eglot specific bindings]]
* Description
This module adds support for the C-family of languages: C, C++, and Objective-C.
@@ -42,7 +44,7 @@ This module adds support for the C-family of languages: C, C++, and Objective-C.
+ [[https://github.com/jimhourihan/glsl-mode][glsl-mode]]*
+ [[https://github.com/guidoschmidt/company-glsl][company-glsl]]*
+ =+lsp=
+ [[https://github.com/MaskRay/emacs-ccls][ccls]]
+ [[https://github.com/MaskRay/emacs-ccls][ccls]] if =:tools lsp= has *no* =+eglot= flag
+ =-lsp=
+ [[https://github.com/Sarcasm/irony-mode][irony]]
+ [[https://github.com/ikirill/irony-eldoc][irony-eldoc]]
@@ -76,7 +78,8 @@ 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 \
cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
-DCMAKE_INSTALL_PREFIX="$DEST" ../
cmake --build . --use-stderr --config Release --target install
@@ -172,3 +175,12 @@ bear gmake
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]]
* Appendix
** Eglot specific bindings
When using =+lsp= and =:tools (lsp +eglot)=, lsp-mode is replaced with eglot,
and an additional function to get inheritance type hierarchy is added
| Binding | Description |
|------------------------------+--------------------------------------------------|
| ~<localleader> c t~ | ~Display inheritance type hierarchy (upwards)~ |
| ~<prefix> <localleader> c t~ | ~Display inheritance type hierarchy (downwards)~ |

View File

@@ -3,6 +3,11 @@
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.cl\\'" . opencl-mode))
;; The plusses in c++-mode can be annoying to search for ivy/helm (which reads
;; queries as regexps), so we add these for convenience.
;;;###autoload (defalias 'cpp-mode 'c++-mode)
;;;###autoload (defvaralias 'cpp-mode-map 'c++-mode-map)
;;
;; Library
@@ -117,6 +122,34 @@ simpler."
#'rtags-imenu
#'imenu)))
;; Eglot specific helper, courtesy of MaskRay
;;;###autoload
(defun +cc/eglot-ccls-inheritance-hierarchy (&optional derived)
"Show inheritance hierarchy for the thing at point.
If DERIVED is non-nil (interactively, with prefix argument), show
the children of class at point."
(interactive "P")
(if-let* ((res (jsonrpc-request
(eglot--current-server-or-lose)
:$ccls/inheritance
(append (eglot--TextDocumentPositionParams)
`(:derived ,(if derived t :json-false))
'(:levels 100) '(:hierarchy t))))
(tree (list (cons 0 res))))
(with-help-window "*ccls inheritance*"
(with-current-buffer standard-output
(while tree
(pcase-let ((`(,depth . ,node) (pop tree)))
(cl-destructuring-bind (&key uri range) (plist-get node :location)
(insert (make-string depth ?\ ) (plist-get node :name) "\n")
(make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0)
'action (lambda (_arg)
(interactive)
(find-file (eglot--uri-to-path uri))
(goto-char (car (eglot--range-region range)))))
(cl-loop for child across (plist-get node :children)
do (push (cons (1+ depth) child) tree)))))))
(eglot--error "Hierarchy unavailable")))
;;
;; Hooks

View File

@@ -33,33 +33,24 @@ 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)
;; Use `c-mode'/`c++-mode'/`objc-mode' depending on heuristics
:mode ("\\.h\\'" . +cc-c-c++-objc-mode)
;; Ensure find-file-at-point recognize system libraries in C modes. It must be
;; set up before the likes of irony/lsp are initialized. Also, we use
;; local-vars hooks to ensure these only run in their respective major modes,
;; and not their derived modes.
:hook ((c-mode-local-vars c++-mode-local-vars objc-mode-local-vars) . +cc-init-ffap-integration-h)
;;; Improve fontification in C/C++ (also see `modern-cpp-font-lock')
:hook (c-mode-common . rainbow-delimiters-mode)
:hook ((c-mode c++-mode) . +cc-fontify-constants-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-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\} ?\{))
(set-rotate-patterns! 'c++-mode
:symbols '(("public" "protected" "private")
("class" "struct")))
(set-pretty-symbols! '(c-mode c++-mode)
;; Functional
;; :def "void "
@@ -76,9 +67,12 @@ This is ignored by ccls.")
: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)
;; HACK Suppress 'Args out of range' error in when multiple modifications are
;; performed at once in a `c++-mode' buffer, e.g. with `iedit' or
;; multiple cursors.
(undefadvice! +cc--suppress-silly-errors-a (orig-fn &rest args)
:around #'c-after-change-mark-abnormal-strings
(ignore-errors (apply orig-fn args)))
;; Custom style, based off of linux
(setq c-basic-offset tab-width
@@ -115,7 +109,10 @@ This is ignored by ccls.")
(label . 0))))
(when (listp c-default-style)
(setf (alist-get 'other c-default-style) "doom")))
(setf (alist-get 'other c-default-style) "doom"))
(after! ffap
(add-to-list 'ffap-alist '(c-mode . ffap-c-mode))))
(use-package! modern-cpp-font-lock
@@ -124,46 +121,40 @@ This is ignored by ccls.")
(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"))
:commands irony-install-server
;; Initialize compilation database, if present. Otherwise, fall back on
;; `+cc-default-compiler-options'.
(add-hook 'irony-mode-hook #'+cc-init-irony-compile-options-h)
:hook (irony-mode . +cc-init-irony-compile-options-h)
;; Only initialize `irony-mode' if the server is available. Otherwise fail
;; quietly and gracefully.
:hook ((c-mode-local-vars c++-mode-local-vars objc-mode-local-vars) . +cc-init-irony-mode-maybe-h)
:preface (setq irony-server-install-prefix (concat doom-etc-dir "irony-server/"))
:config
(defun +cc-init-irony-mode-maybe-h ()
(if (file-directory-p irony-server-install-prefix)
(irony-mode +1)
(message "Irony server isn't installed")))
(setq irony-cdb-search-directory-list '("." "build" "build-conda"))
(use-package! irony-eldoc
:hook (irony-mode . irony-eldoc))
(use-package! flycheck-irony
:when (featurep! :tools flycheck)
:when (featurep! :checkers syntax)
: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)))
: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"))
(after! cmake-mode
(set-docsets! 'cmake-mode "CMake"))
(use-package! company-cmake ; for `cmake-mode'
:when (featurep! :completion company)
@@ -186,19 +177,17 @@ This is ignored by ccls.")
(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))))
;; Only initialize rtags-mode if rtags and rdm are available.
:hook ((c-mode-local-vars c++-mode-local-vars objc-mode-local-vars) . +cc-init-rtags-maybe-h)
:preface (setq rtags-install-path (concat doom-etc-dir "rtags/"))
:config
(defun +cc-init-rtags-maybe-h ()
"Start an rtags server in c-mode and c++-mode buffers.
If rtags or rdm aren't available, fail silently instead of throwing a breaking error."
(and (require 'rtags nil t)
(rtags-executable-find rtags-rdm-binary-name)
(rtags-start-process-unless-running)))
(setq rtags-autostart-diagnostics t
rtags-use-bookmarks nil
rtags-completions-enabled nil
@@ -223,11 +212,13 @@ This is ignored by ccls.")
: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)
;; Ensure rtags cleans up after itself properly when exiting Emacs, rather
;; than display a jarring confirmation prompt for killing it.
(add-hook! 'kill-emacs-hook (ignore-errors (rtags-cancel-process)))
(add-hook 'rtags-jump-hook #'better-jumper-set-jump)
(add-hook 'rtags-after-find-file-hook #'recenter))
@@ -245,9 +236,25 @@ This is ignored by ccls.")
(setq-local company-lsp-cache-candidates nil)
(lsp!))))
(when (and (featurep! +lsp) (featurep! :tools lsp +eglot))
;; Map eglot specific helper
(map! :localleader
:after cc-mode
:map c++-mode-map
:n :desc "Show type inheritance hierarchy" "ct" #'+cc/eglot-ccls-inheritance-hierarchy)
;; NOTE : This setting is untested yet
(after! eglot
;; IS-MAC custom configuration
(when IS-MAC
(add-to-list 'eglot-workspace-configuration
`((:ccls . ((: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")))))))))))
(use-package! ccls
:when (featurep! +lsp)
:when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
:after lsp
:init
(after! projectile

View File

@@ -1,27 +1,33 @@
;; -*- 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)
(package! cmake-mode
:recipe (:host github :repo "emacsmirror/cmake-mode" :files (:defaults "*"))
:pin "bfe85bc009")
(package! cuda-mode :pin "9ae9eacfdb")
(package! demangle-mode :pin "06903d731d")
(package! disaster :pin "10a785facc")
(package! modern-cpp-font-lock :pin "02f104701b")
(package! opencl-mode :pin "55cb49c824")
(when (package! glsl-mode)
(when (package! glsl-mode :pin "43d906688a")
(when (featurep! :completion company)
(package! company-glsl :recipe (:host github :repo "Kaali/company-glsl"))))
(package! company-glsl
:recipe (:host github :repo "Kaali/company-glsl")
:pin "404cd0694a")))
(if (featurep! +lsp)
(package! ccls)
(when (package! irony)
(package! irony-eldoc)
(when (featurep! :tools flycheck)
(package! flycheck-irony))
(unless (featurep! :tools lsp +eglot)
;; ccls package is necessary only for lsp-mode.
(package! ccls :pin "17ec7bb4cf"))
(when (package! irony :pin "5f75fc0c92")
(package! irony-eldoc :pin "0df5831eaa")
(when (featurep! :checkers syntax)
(package! flycheck-irony :pin "42dbecd4a8"))
(when (featurep! :completion company)
(package! company-irony)
(package! company-irony-c-headers)))
(when (package! rtags)
(package! company-irony :pin "b44711dfce")
(package! company-irony-c-headers :pin "72c386aeb0")))
(when (package! rtags :pin "d370c09007")
(when (featurep! :completion ivy)
(package! ivy-rtags))
(when (featurep! :completion helm)