From 4b3ebd99a0f0a3ea95e2d60c63d8d6f9273922e0 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 14 Aug 2021 12:40:52 -0500 Subject: Implement `with-eval-after-loads' macro --- init.el | 26 ++++++++++++-------------- lisp/acdw.el | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/init.el b/init.el index 703dc56..4209a6b 100644 --- a/init.el +++ b/init.el @@ -1009,15 +1009,14 @@ if ripgrep is installed, otherwise `consult-grep'." (:advise completing-read-multiple :filter-args #'crm-indicator)) - (with-eval-after-load 'vertico - (with-eval-after-load 'consult - (when (boundp 'consult-crm-map) - (define-key consult-crm-map "\r" #'+vertico-crm-exit) - (define-key consult-crm-map "\t" #'vertico-exit) - (defun +vertico-crm-exit () - (interactive) - (run-at-time 0 nil #'vertico-exit) - (funcall #'vertico-exit)))))) + (with-eval-after-loads (vertico consult) + (when (boundp 'consult-crm-map) + (define-key consult-crm-map "\r" #'+vertico-crm-exit) + (define-key consult-crm-map "\t" #'vertico-exit) + (defun +vertico-crm-exit () + (interactive) + (run-at-time 0 nil #'vertico-exit) + (funcall #'vertico-exit))))) (setup (:straight crux) @@ -1089,11 +1088,10 @@ if ripgrep is installed, otherwise `consult-grep'." #'which-key--hide-popup-ignore-command) embark-become-indicator embark-action-indicator) - (with-eval-after-load 'embark - (with-eval-after-load 'consult - (setup (:straight embark-consult) - (add-hook 'embark-collect-mode-hook - #'consult-preview-at-point-mode))))) + (with-eval-after-loads (embark consult) + (setup (:straight embark-consult) + (add-hook 'embark-collect-mode-hook + #'consult-preview-at-point-mode)))) (setup (:straight epithet) (add-hook 'Info-selection-hook #'epithet-rename-buffer) diff --git a/lisp/acdw.el b/lisp/acdw.el index 4c17bcb..2aa6c1f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -108,6 +108,22 @@ is unfocused." ,@body) (message "%s... Done." ,message))) +(defmacro with-eval-after-loads (files &rest body) + "Execute BODY after FILES are loaded. +This macro simplifies `with-eval-after-load' for multiple nested +features." + (declare (indent 1) (debug (form def-body))) + (waterfall-list 'with-eval-after-load files body)) + +(defun waterfall-list (car list rest) + "Cons CAR with each element in LIST in a waterfall fashion, end with REST. +For use with the `with-eval-after-loads' function." + (cond ((atom list) `(,car ',list ,@rest)) + ((= 1 (length list)) `(,car ',(car list) ,@rest)) + (t + `(,car ',(car list) + ,(waterfall-list car (cdr list) rest))))) + ;;; Comment-or-uncomment-sexp ;; from https://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html -- cgit 1.4.1-21-gabe81