From 5a7c8803d9ec1806524b1b9ac942935e41c8128b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 27 Jun 2018 21:29:28 +0200 Subject: [PATCH] Remove :when support from after!; add defer-until! New macro does what the :when keyword did for after!. --- core/core-lib.el | 33 ++++++++++++---------- modules/feature/file-templates/autoload.el | 4 +-- modules/feature/lookup/autoload/devdocs.el | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/core-lib.el b/core/core-lib.el index d7078d8ef..44d2914b1 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -222,6 +222,23 @@ MATCH is a string regexp. Only entries that match it will be included." (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) "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." @@ -229,7 +246,6 @@ compilation. This will no-op on features that have been disabled by the user." (unless (and (symbolp targets) (memq targets (bound-and-true-p doom-disabled-packages))) (list (if (or (not (bound-and-true-p byte-compile-current-file)) - (eq (car-safe targets) :when) (dolist (next (doom-enlist targets)) (unless (keywordp 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))))) #'progn #'with-no-warnings) - (cond ((eq (car-safe targets) :when) - `(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) + (cond ((symbolp targets) `(with-eval-after-load ',targets ,@body)) ((and (consp targets) diff --git a/modules/feature/file-templates/autoload.el b/modules/feature/file-templates/autoload.el index 731edb9bb..acd8b0ca2 100644 --- a/modules/feature/file-templates/autoload.el +++ b/modules/feature/file-templates/autoload.el @@ -30,13 +30,13 @@ these properties: If non-nil, don't expand any template for this file and don't test any other file template rule against this buffer." (declare (indent defun)) - (after! (:when (boundp '+file-templates-alist)) + (defer-until! (boundp '+file-templates-alist) (+file-templates--set pred plist))) ;;;###autodef (defun set-file-templates! (&rest templates) "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) (+file-templates--set (car template) (cdr template))))) diff --git a/modules/feature/lookup/autoload/devdocs.el b/modules/feature/lookup/autoload/devdocs.el index 5baf61cf4..5625c81e9 100644 --- a/modules/feature/lookup/autoload/devdocs.el +++ b/modules/feature/lookup/autoload/devdocs.el @@ -7,7 +7,7 @@ DOCSET (a string). See `devdocs-alist' for the defaults. " - (after! (:when (boundp 'devdocs-alist)) + (defer-until! (boundp 'devdocs-alist) (dolist (mode (doom-enlist modes)) (setf (alist-get mode devdocs-alist) docset))))