Refactor compile macro in doom/reload-* commands
This commit is contained in:
parent
1cb753cbb1
commit
b78c862e98
1 changed files with 25 additions and 30 deletions
|
@ -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,8 +80,7 @@ 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
|
||||
(doom--if-compile (format "%s sync -e" doom-bin)
|
||||
(let ((doom-reloading-p t))
|
||||
(doom-initialize 'force)
|
||||
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
|
||||
|
@ -89,9 +88,8 @@ Runs `doom-reload-hook' afterwards."
|
|||
(unwind-protect
|
||||
(doom-initialize-modules 'force)
|
||||
(general-auto-unbind-keys t)))
|
||||
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook)
|
||||
(run-hook-wrapped 'doom-reload-hook #'doom-try-hook)
|
||||
(print! (success "Config successfully reloaded!")))
|
||||
:on-failure
|
||||
(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
|
||||
(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" ""))
|
||||
:on-success
|
||||
(let ((doom-reloading-p t))
|
||||
(unless arg
|
||||
(doom-load-envvars-file doom-env-file)))
|
||||
:on-failure
|
||||
(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
|
||||
(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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue