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:
Henrik Lissner 2018-12-05 19:01:17 -05:00
parent f003d2b4fe
commit 7b761a9b42
3 changed files with 38 additions and 25 deletions

View file

@ -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))

View file

@ -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)
;;