Remove :when support from after!; add defer-until!
New macro does what the :when keyword did for after!.
This commit is contained in:
parent
e9ccc09fe4
commit
5a7c8803d9
3 changed files with 21 additions and 18 deletions
|
@ -222,6 +222,23 @@ MATCH is a string regexp. Only entries that match it will be included."
|
||||||
|
|
||||||
(defalias 'lambda! 'λ!)
|
(defalias 'lambda! 'λ!)
|
||||||
|
|
||||||
|
(defmacro defer-until! (condition &rest body)
|
||||||
|
"Run BODY when CONDITION is true (checks on `after-load-functions'). Meant to
|
||||||
|
serve as a predicated alternative to `after!'."
|
||||||
|
(declare (indent defun) (debug t))
|
||||||
|
`(if ,(cadr targets)
|
||||||
|
(progn ,@body)
|
||||||
|
,(let ((fun (gensym "doom|delay-form-")))
|
||||||
|
`(progn
|
||||||
|
(fset ',fun (lambda (&rest args)
|
||||||
|
(when ,(or (car (cdr-safe targets)) t)
|
||||||
|
(remove-hook 'after-load-functions #',fun)
|
||||||
|
(unintern ',fun nil)
|
||||||
|
(ignore args)
|
||||||
|
,@body)))
|
||||||
|
(put ',fun 'permanent-local-hook t)
|
||||||
|
(add-hook 'after-load-functions #',fun)))))
|
||||||
|
|
||||||
(defmacro after! (targets &rest body)
|
(defmacro after! (targets &rest body)
|
||||||
"A smart wrapper around `with-eval-after-load'. Supresses warnings during
|
"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."
|
compilation. This will no-op on features that have been disabled by the user."
|
||||||
|
@ -229,7 +246,6 @@ compilation. This will no-op on features that have been disabled by the user."
|
||||||
(unless (and (symbolp targets)
|
(unless (and (symbolp targets)
|
||||||
(memq targets (bound-and-true-p doom-disabled-packages)))
|
(memq targets (bound-and-true-p doom-disabled-packages)))
|
||||||
(list (if (or (not (bound-and-true-p byte-compile-current-file))
|
(list (if (or (not (bound-and-true-p byte-compile-current-file))
|
||||||
(eq (car-safe targets) :when)
|
|
||||||
(dolist (next (doom-enlist targets))
|
(dolist (next (doom-enlist targets))
|
||||||
(unless (keywordp next)
|
(unless (keywordp next)
|
||||||
(if (symbolp next)
|
(if (symbolp next)
|
||||||
|
@ -237,20 +253,7 @@ compilation. This will no-op on features that have been disabled by the user."
|
||||||
(load next :no-message :no-error)))))
|
(load next :no-message :no-error)))))
|
||||||
#'progn
|
#'progn
|
||||||
#'with-no-warnings)
|
#'with-no-warnings)
|
||||||
(cond ((eq (car-safe targets) :when)
|
(cond ((symbolp targets)
|
||||||
`(if ,(cadr targets)
|
|
||||||
(progn ,@body)
|
|
||||||
,(let ((fun (gensym "doom|delay-form-")))
|
|
||||||
`(progn
|
|
||||||
(fset ',fun (lambda (&rest args)
|
|
||||||
(when ,(or (car (cdr-safe targets)) t)
|
|
||||||
(remove-hook 'after-load-functions #',fun)
|
|
||||||
(unintern ',fun nil)
|
|
||||||
(ignore args)
|
|
||||||
,@body)))
|
|
||||||
(put ',fun 'permanent-local-hook t)
|
|
||||||
(add-hook 'after-load-functions #',fun)))))
|
|
||||||
((symbolp targets)
|
|
||||||
`(with-eval-after-load ',targets
|
`(with-eval-after-load ',targets
|
||||||
,@body))
|
,@body))
|
||||||
((and (consp targets)
|
((and (consp targets)
|
||||||
|
|
|
@ -30,13 +30,13 @@ these properties:
|
||||||
If non-nil, don't expand any template for this file and don't test any other
|
If non-nil, don't expand any template for this file and don't test any other
|
||||||
file template rule against this buffer."
|
file template rule against this buffer."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(after! (:when (boundp '+file-templates-alist))
|
(defer-until! (boundp '+file-templates-alist)
|
||||||
(+file-templates--set pred plist)))
|
(+file-templates--set pred plist)))
|
||||||
|
|
||||||
;;;###autodef
|
;;;###autodef
|
||||||
(defun set-file-templates! (&rest templates)
|
(defun set-file-templates! (&rest templates)
|
||||||
"Like `set-file-templates!', but register many file templates at once."
|
"Like `set-file-templates!', but register many file templates at once."
|
||||||
(after! (:when (boundp '+file-templates-alist))
|
(defer-until! (boundp '+file-templates-alist)
|
||||||
(dolist (template templates)
|
(dolist (template templates)
|
||||||
(+file-templates--set (car template) (cdr template)))))
|
(+file-templates--set (car template) (cdr template)))))
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
DOCSET (a string).
|
DOCSET (a string).
|
||||||
|
|
||||||
See `devdocs-alist' for the defaults. "
|
See `devdocs-alist' for the defaults. "
|
||||||
(after! (:when (boundp 'devdocs-alist))
|
(defer-until! (boundp 'devdocs-alist)
|
||||||
(dolist (mode (doom-enlist modes))
|
(dolist (mode (doom-enlist modes))
|
||||||
(setf (alist-get mode devdocs-alist) docset))))
|
(setf (alist-get mode devdocs-alist) docset))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue