Refactor feature deferral for (common|emacs)-lisp
'lisp-mode is now deferred, to make it easier to lazy-configure it
This commit is contained in:
parent
f003d2b4fe
commit
7b761a9b42
3 changed files with 38 additions and 25 deletions
|
@ -141,6 +141,26 @@ serve as a predicated alternative to `after!'."
|
|||
(put ',fun 'permanent-local-hook t)
|
||||
(add-hook 'after-load-functions #',fun)))))
|
||||
|
||||
(defmacro defer-feature! (feature &optional mode)
|
||||
"TODO"
|
||||
(let ((advice-fn (intern (format "doom|defer-feature-%s" feature)))
|
||||
(mode (or mode feature)))
|
||||
`(progn
|
||||
(delq ',feature features)
|
||||
(advice-add #',mode :before #',advice-fn)
|
||||
(defun ,advice-fn (&rest _)
|
||||
;; Some plugins (like yasnippet) run `lisp-mode' early, to parse some
|
||||
;; elisp. This would prematurely trigger this function. In these cases,
|
||||
;; `lisp-mode-hook' is let-bound to nil or its hooks are delayed, so if
|
||||
;; we see either, keep pretending elisp-mode isn't loaded.
|
||||
(when (and ,(intern (format "%s-hook" mode))
|
||||
(not delay-mode-hooks))
|
||||
;; Otherwise, announce to the world elisp-mode has been loaded, so
|
||||
;; `after!' handlers can respond and configure elisp-mode as
|
||||
;; expected.
|
||||
(provide ',feature)
|
||||
(advice-remove #',mode #',advice-fn))))))
|
||||
|
||||
(defmacro after! (targets &rest body)
|
||||
"A smart wrapper around `with-eval-after-load'. Supresses warnings during
|
||||
compilation. This will no-op on features that have been disabled by the user."
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
;;; lang/common-lisp/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; `lisp-mode' is loaded at startup. In order to lazy load its config we need to
|
||||
;; pretend it isn't loaded
|
||||
(defer-feature! lisp-mode)
|
||||
|
||||
|
||||
;;
|
||||
;; packages
|
||||
|
||||
(defvar inferior-lisp-program "sbcl")
|
||||
(add-hook 'lisp-mode-hook #'rainbow-delimiters-mode)
|
||||
|
||||
(after! lisp-mode
|
||||
(set-repl-handler! 'lisp-mode #'sly-mrepl)
|
||||
(set-eval-handler! 'lisp-mode #'sly-eval-region)
|
||||
(set-lookup-handlers! 'lisp-mode
|
||||
:definition #'sly-edit-definition
|
||||
:documentation #'sly-describe-symbol)
|
||||
|
||||
(add-hook 'lisp-mode-hook #'rainbow-delimiters-mode))
|
||||
|
||||
|
||||
(after! sly
|
||||
|
@ -20,12 +36,6 @@
|
|||
;; These buffers are meant to be displayed with sufficient vertical space.
|
||||
(set-popup-rule! "^\\*sly-\\(db\\|inspector\\)" :ignore t)
|
||||
|
||||
(set-repl-handler! 'lisp-mode #'sly-mrepl)
|
||||
(set-eval-handler! 'lisp-mode #'sly-eval-region)
|
||||
(set-lookup-handlers! 'lisp-mode
|
||||
:definition #'sly-edit-definition
|
||||
:documentation #'sly-describe-symbol)
|
||||
|
||||
(sp-with-modes '(sly-mrepl-mode)
|
||||
(sp-local-pair "'" "'" :actions nil)
|
||||
(sp-local-pair "`" "`" :actions nil))
|
||||
|
|
|
@ -3,26 +3,9 @@
|
|||
(defvar +emacs-lisp-enable-extra-fontification t
|
||||
"If non-nil, highlight special forms, and defined functions and variables.")
|
||||
|
||||
|
||||
;;
|
||||
;; elisp-mode deferral hack
|
||||
|
||||
;; `elisp-mode' is loaded at startup. In order to lazy load its config we need
|
||||
;; to pretend it isn't loaded
|
||||
(delq 'elisp-mode features)
|
||||
;; ...until the first time `emacs-lisp-mode' runs
|
||||
(advice-add #'emacs-lisp-mode :before #'+emacs-lisp|init)
|
||||
|
||||
(defun +emacs-lisp|init (&rest _)
|
||||
;; Some plugins (like yasnippet) run `emacs-lisp-mode' early, to parse some
|
||||
;; elisp. This would prematurely trigger this function. In these cases,
|
||||
;; `emacs-lisp-mode-hook' is let-bound to nil or its hooks are delayed, so if
|
||||
;; we see either, keep pretending elisp-mode isn't loaded.
|
||||
(when (and emacs-lisp-mode-hook (not delay-mode-hooks))
|
||||
;; Otherwise, announce to the world elisp-mode has been loaded, so `after!'
|
||||
;; handlers can respond and configure elisp-mode as expected.
|
||||
(provide 'elisp-mode)
|
||||
(advice-remove #'emacs-lisp-mode #'+emacs-lisp|init)))
|
||||
(defer-feature! elisp-mode emacs-lisp-mode)
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue