Fix lazy loading of elisp-mode config
elisp-mode is loaded at startup, so the usual methods won't work. Instead, we tie a transient advice to the emacs-lisp-mode function, *however*, this function is commonly called by various packages to parse elisp code! So we have to make sure the emacs lisp module only initializes the first time it is used interactively.
This commit is contained in:
parent
ca5ff92192
commit
d55c7896f1
1 changed files with 62 additions and 56 deletions
|
@ -2,7 +2,21 @@
|
|||
|
||||
(add-to-list 'auto-mode-alist '("\\.Cask\\'" . emacs-lisp-mode))
|
||||
|
||||
(defun +emacs-lisp|init ()
|
||||
(add-hook! 'emacs-lisp-mode-hook
|
||||
#'(;; 3rd-party functionality
|
||||
auto-compile-on-save-mode doom|enable-delete-trailing-whitespace
|
||||
;; fontification
|
||||
rainbow-delimiters-mode highlight-quoted-mode highlight-numbers-mode +emacs-lisp|extra-fontification
|
||||
;; initialization
|
||||
+emacs-lisp|init-imenu +emacs-lisp|disable-flycheck-maybe))
|
||||
|
||||
(defun +emacs-lisp|init (&rest _)
|
||||
;; Some plugins will run `emacs-lisp-mode' with `emacs-lisp-mode-hook' set to
|
||||
;; nil (cough yasnippet cough) or its mode hooks delayed. This prematurely
|
||||
;; fires this function. Most of these setters affect emacs-lisp-mode-hook, so
|
||||
;; they'd be swallowed up if it's letbound to nil, causing a half-initialized
|
||||
;; elisp-mode in some sessions.
|
||||
(when (and emacs-lisp-mode-hook (not delay-mode-hooks))
|
||||
(set-repl-handler! 'emacs-lisp-mode #'+emacs-lisp/repl)
|
||||
(set-eval-handler! 'emacs-lisp-mode #'+emacs-lisp-eval)
|
||||
(set-lookup-handlers! 'emacs-lisp-mode :documentation 'info-lookup-symbol)
|
||||
|
@ -16,17 +30,11 @@
|
|||
("advice-add" "advice-remove")
|
||||
("add-hook" "remove-hook")
|
||||
("add-hook!" "remove-hook!")))
|
||||
|
||||
(add-hook! 'emacs-lisp-mode-hook
|
||||
#'(;; 3rd-party functionality
|
||||
auto-compile-on-save-mode doom|enable-delete-trailing-whitespace
|
||||
;; fontification
|
||||
rainbow-delimiters-mode highlight-quoted-mode highlight-numbers-mode +emacs-lisp|extra-fontification
|
||||
;; initialization
|
||||
+emacs-lisp|init-imenu +emacs-lisp|disable-flycheck-maybe))
|
||||
|
||||
;;
|
||||
(defun +emacs-lisp|extra-fontification ()
|
||||
(advice-remove #'emacs-lisp-mode #'+emacs-lisp|init)))
|
||||
(advice-add #'emacs-lisp-mode :before #'+emacs-lisp|init)
|
||||
|
||||
(defun +emacs-lisp|extra-fontification ()
|
||||
"Display lambda as a smybol and fontify doom module functions."
|
||||
(font-lock-add-keywords
|
||||
nil `(;; Highlight custom Doom cookies
|
||||
|
@ -34,7 +42,7 @@
|
|||
;; Highlight doom/module functions
|
||||
("\\(^\\|\\s-\\|,\\)(\\(\\(doom\\|\\+\\)[^) ]+\\|[^) ]+!\\)[) \n]" (2 font-lock-keyword-face)))))
|
||||
|
||||
(defun +emacs-lisp|init-imenu ()
|
||||
(defun +emacs-lisp|init-imenu ()
|
||||
"Improve imenu support with better expression regexps and Doom-specific forms."
|
||||
(setq imenu-generic-expression
|
||||
'(("Evil Commands" "^\\s-*(evil-define-\\(?:command\\|operator\\|motion\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
|
||||
|
@ -53,15 +61,13 @@
|
|||
("Variables" "^\\s-*(defvar\\(?:-local\\)?\\s-+\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)[[:space:]\n]+[^)]" 1)
|
||||
("Types" "^\\s-*(\\(cl-def\\(?:struct\\|type\\)\\|def\\(?:class\\|face\\|group\\|ine-\\(?:condition\\|error\\|widget\\)\\|package\\|struct\\|t\\(?:\\(?:hem\\|yp\\)e\\)\\)\\)\\s-+'?\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)" 2))))
|
||||
|
||||
(defun +emacs-lisp|disable-flycheck-maybe ()
|
||||
(defun +emacs-lisp|disable-flycheck-maybe ()
|
||||
"Disable flycheck-mode if in emacs.d."
|
||||
(when (or (not buffer-file-name)
|
||||
(cl-loop for dir in (list doom-emacs-dir doom-private-dir)
|
||||
if (file-in-directory-p buffer-file-name dir)
|
||||
return t))
|
||||
(flycheck-mode -1))))
|
||||
|
||||
(add-transient-hook! 'emacs-lisp-mode (+emacs-lisp|init))
|
||||
(flycheck-mode -1)))
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue