Rewrite interactive CLI commands

- Replace doom//upgrade with doom/upgrade
- Replace doom//autoloads with doom/reload-autoloads
- Replace doom//refresh with doom/reload
- Remove doom//install; there should be no workflow for this command
- Remove doom//autoremove; autoremove was replaced with purge. Maybe
  I'll write a doom//purge analogue. Not sure yet.
- Use compile instead of hacky wrapper around core-cli API

Rewrite interactive CLI commands

- Rewrite doom//upgrade & doom//autoloads
- Remove doom//install; there really should be no use-case for it
- Remove doom//autoremove; autoremove was replaced with purge. I'll get
  around to writing a doom//purge eventually.

fixup! Rewrite interactive CLI commands
This commit is contained in:
Henrik Lissner 2019-12-13 15:23:23 -05:00
parent 0f9e60d62c
commit 1e6ef4d6e4
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 57 additions and 111 deletions

View file

@ -1,5 +1,8 @@
;;; core/autoload/config.el -*- lexical-binding: t; -*-
(defvar doom-bin-dir (concat doom-emacs-dir "bin/"))
(defvar doom-bin (concat doom-bin-dir "doom"))
;;;###autoload
(defvar doom-reload-hook nil
"A list of hooks to run when `doom/reload' is called.")
@ -45,6 +48,21 @@
(interactive)
(find-file (expand-file-name "packages.el" doom-private-dir)))
;;
;;; Managements
(cl-defmacro doom--compile (command &key on-success on-failure)
(declare (indent defun))
`(with-current-buffer (compile ,command)
(add-hook
'compilation-finish-functions
(lambda (_buf status)
(if (equal status "finished\n")
,on-success
,on-failure))
nil 'local)))
;;;###autoload
(defun doom/reload ()
"Reloads your private config.
@ -55,25 +73,20 @@ reloads your package list, and lastly, reloads your private config.el.
Runs `doom-reload-hook' afterwards."
(interactive)
(or (y-or-n-p
(concat "You are about to reload your Doom config from within Emacs. This "
"is highly experimental and may cause issues. It is recommended you "
"use 'bin/doom refresh' on the command line instead.\n\n"
"Reload anyway?"))
(user-error "Aborted"))
(require 'core-cli)
(let ((doom-reloading-p t))
(compile (format "%s/bin/doom refresh" doom-emacs-dir))
(while compilation-in-progress
(sit-for 1))
(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))
(message "Finished!"))
(doom--compile (format "%s refresh" 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
(user-error "Failed to reload your config")))
;;;###autoload
(defun doom/reload-autoloads ()
@ -92,14 +105,28 @@ line."
(doom-cli-reload-autoloads nil 'force))
;;;###autoload
(defun doom/reload-env ()
"Regenerates and reloads your shell environment.
(defun doom/reload-env (&optional arg)
"Regenerates and/or reloads your envvar file.
Uses the same mechanism as 'bin/doom env reload'."
If passed the prefix ARG, clear the envvar file. Uses the same mechanism as
'bin/doom env'.
An envvar file contains a snapshot of your shell environment, which can be
imported into Emacs."
(interactive "P")
(doom--compile (format "%s env%s" 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)
(compile (format "%s env" (expand-file-name "bin/doom" doom-emacs-dir)))
(while compilation-in-progress
(sit-for 1))
(unless (file-readable-p doom-env-file)
(error "Failed to generate env file"))
(doom-load-envvars-file doom-env-file))
(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))))