Refactor Doom core & reload autoloads remotely

- Move subr-x/cl-lib loading to core-lib
- Revise docstrings for and rename various CLI functions to be more
  descriptive and up-to-date
- After regenerating autoloads file, bin/doom will try to reload
  autoloads files remotely, through the server/daemon, if possible. This
  is highly experimental and could break
This commit is contained in:
Henrik Lissner 2019-06-16 23:01:17 +02:00
parent 72fd61e07b
commit 6be401f1a7
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 91 additions and 50 deletions

View file

@ -1,12 +1,13 @@
;;; core/cli/autoloads.el -*- lexical-binding: t; -*- ;;; core/cli/autoloads.el -*- lexical-binding: t; -*-
(dispatcher! (autoloads a) (doom-reload-autoloads nil 'force) (dispatcher! (autoloads a)
(doom-reload-autoloads nil 'force)
"Regenerates Doom's autoloads files. "Regenerates Doom's autoloads files.
It scans and reads autoload cookies (;;;###autoload) in core/autoload/*.el, It scans and reads autoload cookies (;;;###autoload) in core/autoload/*.el,
modules/*/*/autoload.el and modules/*/*/autoload/*.el, and generates modules/*/*/autoload.el and modules/*/*/autoload/*.el, and generates and
`doom-autoload-file', then compiles `doom-package-autoload-file' from the byte-compiles `doom-autoload-file', as well as `doom-package-autoload-file'
concatenated autoloads files of all installed packages. (created from the concatenated autoloads files of all installed packages).
It also caches `load-path', `Info-directory-list', `doom-disabled-packages', It also caches `load-path', `Info-directory-list', `doom-disabled-packages',
`package-activated-list' and `auto-mode-alist'.") `package-activated-list' and `auto-mode-alist'.")
@ -26,8 +27,7 @@ everyone in the universe and their dog, causing errors that make babies cry. No
one wants that.") one wants that.")
(defun doom-delete-autoloads-file (file) (defun doom-delete-autoloads-file (file)
"Delete FILE (an autoloads file), and delete the accompanying *.elc file, if "Delete FILE (an autoloads file) and accompanying *.elc file, if any."
it exists."
(cl-check-type file string) (cl-check-type file string)
(when (file-exists-p file) (when (file-exists-p file)
(when-let* ((buf (find-buffer-visiting doom-autoload-file))) (when-let* ((buf (find-buffer-visiting doom-autoload-file)))
@ -46,11 +46,24 @@ it exists."
(message " M-x doom/restart") (message " M-x doom/restart")
(message " M-x doom/reload")) (message " M-x doom/reload"))
(defun doom--do-load (&rest files) (defun doom--reload-files (&rest files)
(if (and noninteractive (not (daemonp))) (if (not noninteractive)
(add-hook 'kill-emacs-hook #'doom--warn-refresh-session) (dolist (file files)
(dolist (file files) (load-file (byte-compile-dest-file file)))
(load-file (byte-compile-dest-file file))))) (condition-case e
(progn
(require 'server)
(server-eval-at
server-name
`(progn
(dolist (file (list ,@files))
(load-file (byte-compile-dest-file file)))
(message "Successfully reloaded session!")))
(print! "%s\n\n%s"
(bold (green "All done!"))
(green "Successfully reloaded your remote Emacs session")))
('error
(add-hook 'kill-emacs-hook #'doom--warn-refresh-session)))))
(defun doom--byte-compile-file (file) (defun doom--byte-compile-file (file)
(let ((short-name (file-name-nondirectory file)) (let ((short-name (file-name-nondirectory file))
@ -222,7 +235,7 @@ even if it doesn't need reloading!"
(member-p (member-p
(push sexp forms))))) (push sexp forms)))))
(if forms (if forms
(concat (mapconcat #'prin1-to-string (reverse forms) "\n") (concat (mapconcat #'prin1-to-string (nreverse forms) "\n")
"\n") "\n")
"")))))) ""))))))
@ -293,7 +306,7 @@ Run this whenever your `doom!' block, or a module autoload file, is modified."
(print! (green "✓ Clean up autoloads"))) (print! (green "✓ Clean up autoloads")))
;; Byte compile it to give the file a chance to reveal errors. ;; Byte compile it to give the file a chance to reveal errors.
(doom--byte-compile-file doom-autoload-file) (doom--byte-compile-file doom-autoload-file)
(doom--do-load doom-autoload-file) (doom--reload-files doom-autoload-file)
t))) t)))
@ -377,5 +390,5 @@ This should be run whenever your `doom!' block or update your packages."
(doom--cleanup-package-autoloads) (doom--cleanup-package-autoloads)
(print! (green "✓ Removed load-path/auto-mode-alist entries")))) (print! (green "✓ Removed load-path/auto-mode-alist entries"))))
(doom--byte-compile-file doom-package-autoload-file) (doom--byte-compile-file doom-package-autoload-file)
(doom--do-load doom-package-autoload-file) (doom--reload-files doom-package-autoload-file)
t)) t))

View file

@ -1,18 +1,8 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; core/cli/packages.el ;;; core/cli/packages.el
(dispatcher! (install i) (doom--do #'doom-packages-install)
"Installs requested packages that aren't installed.")
(dispatcher! (update u) (doom--do #'doom-packages-update)
"Updates packages.")
(dispatcher! (autoremove r) (doom--do #'doom-packages-autoremove)
"Removes packages that are no longer needed.")
;; ;;
;; Helpers ;;; Helpers
(defmacro doom--condition-case! (&rest body) (defmacro doom--condition-case! (&rest body)
`(condition-case-unless-debug e `(condition-case-unless-debug e
@ -20,24 +10,49 @@
('user-error ('user-error
(print! (bold (red " NOTICE: %s")) e)) (print! (bold (red " NOTICE: %s")) e))
('file-error ('file-error
(print! (bold (red " FILE ERROR: %s")) (error-message-string e)) (print! " %s\n %s"
(print! " Trying again...") (bold (red "FILE ERROR: %s" (error-message-string e)))
"Trying again...")
(quiet! (doom-refresh-packages-maybe t)) (quiet! (doom-refresh-packages-maybe t))
,@body) ,@body)
('error ('error
(print! (bold (red " FATAL ERROR: %s\n Run again with the -d flag for details")) e)))) (print! (bold (red " %s %s\n %s"))
"FATAL ERROR: " e
"Run again with the -d flag for details"))))
(defsubst doom--do (fn) (defsubst doom--ensure-autoloads-while (fn)
(doom-reload-doom-autoloads) (doom-reload-doom-autoloads)
(when (funcall fn doom-auto-accept) (when (funcall fn doom-auto-accept)
(doom-reload-package-autoloads))) (doom-reload-package-autoloads)))
;; ;;
;; Library ;;; Dispatchers
(dispatcher! (install i)
(doom--ensure-autoloads-while #'doom-packages-install)
"Installs packages that aren't installed.")
(dispatcher! (update u)
(doom--ensure-autoloads-while #'doom-packages-update)
"Updates packages.")
(dispatcher! (autoremove r)
(doom--ensure-autoloads-while #'doom-packages-autoremove)
"Removes packages that are no longer needed.")
;;
;;; Library
(defun doom-packages-install (&optional auto-accept-p) (defun doom-packages-install (&optional auto-accept-p)
"Interactive command for installing missing packages." "Installs missing packages.
This function will install any primary package (i.e. a package with a `package!'
declaration) or dependency thereof that hasn't already been.
Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with
a list of packages that will be installed."
(print! "Looking for packages to install...") (print! "Looking for packages to install...")
(let ((packages (doom-get-missing-packages))) (let ((packages (doom-get-missing-packages)))
(cond ((not packages) (cond ((not packages)
@ -96,7 +111,10 @@
success))))) success)))))
(defun doom-packages-update (&optional auto-accept-p) (defun doom-packages-update (&optional auto-accept-p)
"Interactive command for updating packages." "Updates packages.
Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with
a list of packages that will be updated."
(print! "Looking for outdated packages...") (print! "Looking for outdated packages...")
(let ((packages (cl-sort (cl-copy-list (doom-get-outdated-packages)) #'string-lessp (let ((packages (cl-sort (cl-copy-list (doom-get-outdated-packages)) #'string-lessp
:key #'car))) :key #'car)))
@ -140,7 +158,13 @@
success))))) success)))))
(defun doom-packages-autoremove (&optional auto-accept-p) (defun doom-packages-autoremove (&optional auto-accept-p)
"Interactive command for auto-removing orphaned packages." "Auto-removes orphaned packages.
An orphaned package is a package that isn't a primary package (i.e. doesn't have
a `package!' declaration) or isn't depended on by another primary package.
Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with
a list of packages that will be removed."
(print! "Looking for orphaned packages...") (print! "Looking for orphaned packages...")
(let ((packages (doom-get-orphaned-packages))) (let ((packages (doom-get-orphaned-packages)))
(cond ((not packages) (cond ((not packages)

View file

@ -173,9 +173,10 @@ savehist file."
(def-package! server (def-package! server
:when (display-graphic-p) :when (display-graphic-p)
:after-call (pre-command-hook after-find-file) :after-call (pre-command-hook after-find-file)
:config :init
(when-let* ((name (getenv "EMACS_SERVER_NAME"))) (when-let* ((name (getenv "EMACS_SERVER_NAME")))
(setq server-name name)) (setq server-name name))
:config
(unless (server-running-p) (unless (server-running-p)
(server-start))) (server-start)))

View file

@ -1,5 +1,20 @@
;;; core-lib.el -*- lexical-binding: t; -*- ;;; core-lib.el -*- lexical-binding: t; -*-
(let ((load-path doom-site-load-path))
(require 'subr-x)
(require 'cl-lib))
;; Polyfills
(unless EMACS26+
(with-no-warnings
;; `kill-current-buffer' was introduced in Emacs 26
(defalias 'kill-current-buffer #'kill-this-buffer)
;; if-let and when-let were moved to (if|when)-let* in Emacs 26+ so we alias
;; them for 25 users.
(defalias 'if-let* #'if-let)
(defalias 'when-let* #'when-let)))
;; ;;
;;; Helpers ;;; Helpers
@ -108,7 +123,7 @@ Accepts the same arguments as `message'."
(let ((inhibit-message (active-minibuffer-window))) (let ((inhibit-message (active-minibuffer-window)))
(message (message
,(concat (propertize "DOOM " 'face 'font-lock-comment-face) ,(concat (propertize "DOOM " 'face 'font-lock-comment-face)
(when doom--current-module (when (bound-and-true-p doom--current-module)
(propertize (propertize
(format "[%s/%s] " (format "[%s/%s] "
(doom-keyword-name (car doom--current-module)) (doom-keyword-name (car doom--current-module))

View file

@ -473,6 +473,9 @@ The overall load order of Doom is as follows:
Module load order is determined by your `doom!' block. See `doom-modules-dirs' Module load order is determined by your `doom!' block. See `doom-modules-dirs'
for a list of all recognized module trees. Order defines precedence (from most for a list of all recognized module trees. Order defines precedence (from most
to least)." to least)."
(add-to-list 'load-path doom-core-dir)
(require 'core-lib)
(when (or force-p (not doom-init-p)) (when (or force-p (not doom-init-p))
(setq doom-init-p t) ; Prevent infinite recursion (setq doom-init-p t) ; Prevent infinite recursion
@ -516,7 +519,6 @@ to least)."
shell-file-name (or (getenv "SHELL") shell-file-name (or (getenv "SHELL")
shell-file-name)))) shell-file-name))))
(require 'core-lib)
(require 'core-modules) (require 'core-modules)
(require 'core-os) (require 'core-os)
(if noninteractive (if noninteractive
@ -531,20 +533,6 @@ to least)."
;; ;;
;;; Bootstrap Doom ;;; Bootstrap Doom
(eval-and-compile
(require 'subr-x)
(require 'cl-lib)
(unless EMACS26+
(with-no-warnings
;; `kill-current-buffer' was introduced in Emacs 26
(defalias 'kill-current-buffer #'kill-this-buffer)
;; if-let and when-let were moved to (if|when)-let* in Emacs 26+ so we
;; alias them for 25 users.
(defalias 'if-let* #'if-let)
(defalias 'when-let* #'when-let))))
(add-to-list 'load-path doom-core-dir)
(doom-initialize noninteractive) (doom-initialize noninteractive)
(unless noninteractive (unless noninteractive
(doom-initialize-modules)) (doom-initialize-modules))