diff --git a/core/cli/autoloads.el b/core/cli/autoloads.el index 8bdce2d18..c766f4f66 100644 --- a/core/cli/autoloads.el +++ b/core/cli/autoloads.el @@ -1,12 +1,13 @@ ;;; 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. It scans and reads autoload cookies (;;;###autoload) in core/autoload/*.el, -modules/*/*/autoload.el and modules/*/*/autoload/*.el, and generates -`doom-autoload-file', then compiles `doom-package-autoload-file' from the -concatenated autoloads files of all installed packages. +modules/*/*/autoload.el and modules/*/*/autoload/*.el, and generates and +byte-compiles `doom-autoload-file', as well as `doom-package-autoload-file' +(created from the concatenated autoloads files of all installed packages). It also caches `load-path', `Info-directory-list', `doom-disabled-packages', `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.") (defun doom-delete-autoloads-file (file) - "Delete FILE (an autoloads file), and delete the accompanying *.elc file, if -it exists." + "Delete FILE (an autoloads file) and accompanying *.elc file, if any." (cl-check-type file string) (when (file-exists-p 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/reload")) -(defun doom--do-load (&rest files) - (if (and noninteractive (not (daemonp))) - (add-hook 'kill-emacs-hook #'doom--warn-refresh-session) - (dolist (file files) - (load-file (byte-compile-dest-file file))))) +(defun doom--reload-files (&rest files) + (if (not noninteractive) + (dolist (file files) + (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) (let ((short-name (file-name-nondirectory file)) @@ -222,7 +235,7 @@ even if it doesn't need reloading!" (member-p (push sexp forms))))) (if forms - (concat (mapconcat #'prin1-to-string (reverse forms) "\n") + (concat (mapconcat #'prin1-to-string (nreverse forms) "\n") "\n") "")))))) @@ -293,7 +306,7 @@ Run this whenever your `doom!' block, or a module autoload file, is modified." (print! (green "✓ Clean up autoloads"))) ;; Byte compile it to give the file a chance to reveal errors. (doom--byte-compile-file doom-autoload-file) - (doom--do-load doom-autoload-file) + (doom--reload-files doom-autoload-file) t))) @@ -377,5 +390,5 @@ This should be run whenever your `doom!' block or update your packages." (doom--cleanup-package-autoloads) (print! (green "✓ Removed load-path/auto-mode-alist entries")))) (doom--byte-compile-file doom-package-autoload-file) - (doom--do-load doom-package-autoload-file) + (doom--reload-files doom-package-autoload-file) t)) diff --git a/core/cli/packages.el b/core/cli/packages.el index c82b32945..02ca80ac8 100644 --- a/core/cli/packages.el +++ b/core/cli/packages.el @@ -1,18 +1,8 @@ ;; -*- no-byte-compile: t; -*- ;;; 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) `(condition-case-unless-debug e @@ -20,24 +10,49 @@ ('user-error (print! (bold (red " NOTICE: %s")) e)) ('file-error - (print! (bold (red " FILE ERROR: %s")) (error-message-string e)) - (print! " Trying again...") + (print! " %s\n %s" + (bold (red "FILE ERROR: %s" (error-message-string e))) + "Trying again...") (quiet! (doom-refresh-packages-maybe t)) ,@body) ('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) (when (funcall fn doom-auto-accept) (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) - "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...") (let ((packages (doom-get-missing-packages))) (cond ((not packages) @@ -96,7 +111,10 @@ success))))) (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...") (let ((packages (cl-sort (cl-copy-list (doom-get-outdated-packages)) #'string-lessp :key #'car))) @@ -140,7 +158,13 @@ success))))) (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...") (let ((packages (doom-get-orphaned-packages))) (cond ((not packages) diff --git a/core/core-editor.el b/core/core-editor.el index d9dea6e5e..4c3b249d8 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -173,9 +173,10 @@ savehist file." (def-package! server :when (display-graphic-p) :after-call (pre-command-hook after-find-file) - :config + :init (when-let* ((name (getenv "EMACS_SERVER_NAME"))) (setq server-name name)) + :config (unless (server-running-p) (server-start))) diff --git a/core/core-lib.el b/core/core-lib.el index 8aa861cc7..0bdc5ea58 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -1,5 +1,20 @@ ;;; 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 @@ -108,7 +123,7 @@ Accepts the same arguments as `message'." (let ((inhibit-message (active-minibuffer-window))) (message ,(concat (propertize "DOOM " 'face 'font-lock-comment-face) - (when doom--current-module + (when (bound-and-true-p doom--current-module) (propertize (format "[%s/%s] " (doom-keyword-name (car doom--current-module)) diff --git a/core/core.el b/core/core.el index b59b40ec6..d233cc748 100644 --- a/core/core.el +++ b/core/core.el @@ -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' for a list of all recognized module trees. Order defines precedence (from most to least)." + (add-to-list 'load-path doom-core-dir) + (require 'core-lib) + (when (or force-p (not doom-init-p)) (setq doom-init-p t) ; Prevent infinite recursion @@ -516,7 +519,6 @@ to least)." shell-file-name (or (getenv "SHELL") shell-file-name)))) - (require 'core-lib) (require 'core-modules) (require 'core-os) (if noninteractive @@ -531,20 +533,6 @@ to least)." ;; ;;; 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) (unless noninteractive (doom-initialize-modules))