Add :when support to after!
This lets you delay a body of code until an arbitrary condition is met (which is checked whenever a file is loaded). Also refactors set-file-template! to wait until +file-templates-alist is defined.
This commit is contained in:
parent
d8b1e469bc
commit
2496e0348d
2 changed files with 18 additions and 3 deletions
|
@ -226,7 +226,20 @@ compilation. This will no-op on features that have been disabled by the user."
|
|||
(load next :no-message :no-error))))
|
||||
#'progn
|
||||
#'with-no-warnings)
|
||||
(cond ((symbolp targets)
|
||||
(cond ((eq (car-safe targets) :when)
|
||||
`(if ,(cadr targets)
|
||||
(progn ,@body)
|
||||
,(let* ((hook 'after-load-functions)
|
||||
(fun (intern (format "doom|delay-form-in-%s" hook))))
|
||||
`(progn
|
||||
(fset ',fun (lambda (&rest args)
|
||||
(when ,(or (car (cdr-safe targets)) t)
|
||||
(remove-hook ',hook #',fun)
|
||||
(ignore args)
|
||||
,@body)))
|
||||
(put ',fun 'permanent-local-hook t)
|
||||
(add-hook ',hook #',fun)))))
|
||||
((symbolp targets)
|
||||
`(eval-after-load ',targets '(progn ,@body)))
|
||||
((and (consp targets)
|
||||
(memq (car targets) '(:or :any)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue