From b78c862e9829aee4681e39f613f69f95e27d1169 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 14 Apr 2020 19:49:20 -0400 Subject: [PATCH] Refactor compile macro in doom/reload-* commands --- core/autoload/config.el | 55 +++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/core/autoload/config.el b/core/autoload/config.el index c8f7cb5b5..770a704fc 100644 --- a/core/autoload/config.el +++ b/core/autoload/config.el @@ -53,8 +53,8 @@ And jumps to your `doom!' block." ;; ;;; Managements -(cl-defmacro doom--compile (command &key on-success on-failure) - (declare (indent defun)) +(defmacro doom--if-compile (command on-success &optional on-failure) + (declare (indent 2)) `(with-current-buffer (compile ,command) (add-hook 'compilation-finish-functions @@ -80,18 +80,16 @@ Runs `doom-reload-hook' afterwards." ;; In case doom/reload is run before incrementally loaded packages are loaded, ;; which could cause odd load order issues. (mapc #'require (cdr doom-incremental-packages)) - (doom--compile (format "%s sync -e" doom-bin) - :on-success - (let ((doom-reloading-p t)) - (doom-initialize 'force) - (with-demoted-errors "PRIVATE CONFIG ERROR: %s" - (general-auto-unbind-keys) - (unwind-protect - (doom-initialize-modules 'force) - (general-auto-unbind-keys t))) - (run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook) - (print! (success "Config successfully reloaded!"))) - :on-failure + (doom--if-compile (format "%s sync -e" doom-bin) + (let ((doom-reloading-p t)) + (doom-initialize 'force) + (with-demoted-errors "PRIVATE CONFIG ERROR: %s" + (general-auto-unbind-keys) + (unwind-protect + (doom-initialize-modules 'force) + (general-auto-unbind-keys t))) + (run-hook-wrapped 'doom-reload-hook #'doom-try-hook) + (print! (success "Config successfully reloaded!"))) (user-error "Failed to reload your config"))) ;;;###autoload @@ -122,25 +120,22 @@ imported into Emacs." (interactive "P") (when IS-WINDOWS (user-error "Cannot reload envvar file from within Emacs on Windows, run it from cmd.exe")) - (doom--compile - (format "%s -ic '%s env%s'" - (string-trim - (shell-command-to-string - (format "getent passwd %S | cut -d: -f7" - (user-login-name)))) - doom-bin (if arg " -c" "")) - :on-success - (let ((doom-reloading-p t)) - (unless arg - (doom-load-envvars-file doom-env-file))) - :on-failure + (doom--if-compile + (format "%s -ic '%s env%s'" + (string-trim + (shell-command-to-string + (format "getent passwd %S | cut -d: -f7" + (user-login-name)))) + doom-bin (if arg " -c" "")) + (let ((doom-reloading-p t)) + (unless arg + (doom-load-envvars-file doom-env-file))) (error "Failed to generate env file"))) ;;;###autoload (defun doom/upgrade () "Run 'doom upgrade' then prompt to restart Emacs." (interactive) - (doom--compile (format "%s upgrade" doom-bin) - :on-success - (when (y-or-n-p "You must restart Emacs for the upgrade to take effect.\n\nRestart Emacs?") - (doom/restart-and-restore)))) + (doom--if-compile (format "%s upgrade" doom-bin) + (when (y-or-n-p "You must restart Emacs for the upgrade to take effect.\n\nRestart Emacs?") + (doom/restart-and-restore))))