Refactor compile macro in doom/reload-* commands

This commit is contained in:
Henrik Lissner 2020-04-14 19:49:20 -04:00
parent 1cb753cbb1
commit b78c862e98
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -53,8 +53,8 @@ And jumps to your `doom!' block."
;; ;;
;;; Managements ;;; Managements
(cl-defmacro doom--compile (command &key on-success on-failure) (defmacro doom--if-compile (command on-success &optional on-failure)
(declare (indent defun)) (declare (indent 2))
`(with-current-buffer (compile ,command) `(with-current-buffer (compile ,command)
(add-hook (add-hook
'compilation-finish-functions 'compilation-finish-functions
@ -80,18 +80,16 @@ Runs `doom-reload-hook' afterwards."
;; In case doom/reload is run before incrementally loaded packages are loaded, ;; In case doom/reload is run before incrementally loaded packages are loaded,
;; which could cause odd load order issues. ;; which could cause odd load order issues.
(mapc #'require (cdr doom-incremental-packages)) (mapc #'require (cdr doom-incremental-packages))
(doom--compile (format "%s sync -e" doom-bin) (doom--if-compile (format "%s sync -e" doom-bin)
:on-success (let ((doom-reloading-p t))
(let ((doom-reloading-p t)) (doom-initialize 'force)
(doom-initialize 'force) (with-demoted-errors "PRIVATE CONFIG ERROR: %s"
(with-demoted-errors "PRIVATE CONFIG ERROR: %s" (general-auto-unbind-keys)
(general-auto-unbind-keys) (unwind-protect
(unwind-protect (doom-initialize-modules 'force)
(doom-initialize-modules 'force) (general-auto-unbind-keys t)))
(general-auto-unbind-keys t))) (run-hook-wrapped 'doom-reload-hook #'doom-try-hook)
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook) (print! (success "Config successfully reloaded!")))
(print! (success "Config successfully reloaded!")))
:on-failure
(user-error "Failed to reload your config"))) (user-error "Failed to reload your config")))
;;;###autoload ;;;###autoload
@ -122,25 +120,22 @@ imported into Emacs."
(interactive "P") (interactive "P")
(when IS-WINDOWS (when IS-WINDOWS
(user-error "Cannot reload envvar file from within Emacs on Windows, run it from cmd.exe")) (user-error "Cannot reload envvar file from within Emacs on Windows, run it from cmd.exe"))
(doom--compile (doom--if-compile
(format "%s -ic '%s env%s'" (format "%s -ic '%s env%s'"
(string-trim (string-trim
(shell-command-to-string (shell-command-to-string
(format "getent passwd %S | cut -d: -f7" (format "getent passwd %S | cut -d: -f7"
(user-login-name)))) (user-login-name))))
doom-bin (if arg " -c" "")) doom-bin (if arg " -c" ""))
:on-success (let ((doom-reloading-p t))
(let ((doom-reloading-p t)) (unless arg
(unless arg (doom-load-envvars-file doom-env-file)))
(doom-load-envvars-file doom-env-file)))
:on-failure
(error "Failed to generate env file"))) (error "Failed to generate env file")))
;;;###autoload ;;;###autoload
(defun doom/upgrade () (defun doom/upgrade ()
"Run 'doom upgrade' then prompt to restart Emacs." "Run 'doom upgrade' then prompt to restart Emacs."
(interactive) (interactive)
(doom--compile (format "%s upgrade" doom-bin) (doom--if-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?")
(when (y-or-n-p "You must restart Emacs for the upgrade to take effect.\n\nRestart Emacs?") (doom/restart-and-restore))))
(doom/restart-and-restore))))