Backport bits of CLI rewrite

The rewrite for Doom's CLI is taking a while, so I've backported a few
important changes in order to ease the transition and fix a couple bugs
sooner.

Fixes #2802, #2737, #2386

The big highlights are:

- Fix #2802: We now update recipe repos *before* updating/installing any
  new packages. No more "Could not find package X in recipe repositories".

- Fix #2737: An edge case where straight couldn't reach a pinned
  commit (particularly with agda).

- Doom is now smarter about what option it recommends when straight
  prompts you to make a choice.

- Introduces a new init path for Doom. The old way:
  - Launch in "minimal" CLI mode in non-interactive sessions
  - Launch a "full" interactive mode otherwise.
  The new way
  - Launch in "minimal" CLI mode *only* for bin/doom
  - Launch is a simple mode for non-interactive sessions that still need
    access to your interactive config (like async org export/babel).
  - Launch a "full" interactive mode otherwise.

  This should fix compatibility issues with plugins that use the
  async.el library or spawn child Emacs processes to fake
  parallelization (like org's async export and babel functionality).

- Your private init.el is now loaded more reliably when running any
  bin/doom command. This gives you an opportunity to configure its
  settings.

- Added doom-first-{input,buffer,file}-hook hooks, which we use to queue
  deferred activation of a number of packages. Users can remove these
  modes from these hooks; altogether preventing them from loading,
  rather than waiting for them to load to then disable them,
  e.g. (after! smartparens (smartparens-global-mode -1)) -> (remove-hook
  'doom-first-buffer #'smartparens-global-mode)

  Hooks added to doom-first-*-hook variables will be removed once they
  run.

  This should also indirectly fix #2386, by preventing interactive modes
  from running in non-interactive session.

- Added `doom/bump-*` commands to make bumping modules and packages
  easier, and `doom/bumpify-*` commands for converting package!
  statements into user/repo@sha1hash format for bump commits.

- straight.el is now commit-pinned, like all other packages. We also
  more reliably install straight.el by cloning it ourselves, rather than
  relying on its bootstrap.el.

  This should prevent infinite "straight has diverged from master"
  prompts whenever we change branches (though, you might have to put up
  with it one more after this update -- see #2937 for workaround).

All the other minor changes:

- Moved core/autoload/cli.el to core/autoload/process.el
- The package manager will log attempts to check out pinned commits
- If package state is incomplete while rebuilding packages, emit a
  simpler error message instead of an obscure one!
- Added -u switch to 'doom sync' to make it run 'doom update' afterwards
- Added -p switch to 'doom sync' to make it run 'doom purge' afterwards
- Replace doom-modules function with doom-modules-list
- The `with-plist!` macro was removed, since `cl-destructuring-bind`
  already serves that purpose well enough.
- core/autoload/packages.el was moved into core-packages.el
- bin/doom will no longer die if DOOMDIR or DOOMLOCALDIR don't have a
  trailing slash
- Introduces doom-debug-variables; a list of variables to toggle on
  doom/toggle-debug-mode.
- The sandbox has been updated to reflect the above changes, also:
  1. Child instances will no longer inherit the process environment of
     the host instance,
  2. It will no longer produce an auto-save-list directory in ~/.emacs.d
This commit is contained in:
Henrik Lissner 2020-05-14 15:00:23 -04:00
parent 043a561565
commit 0e851ace9b
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
31 changed files with 1316 additions and 1149 deletions

View file

@ -5,25 +5,25 @@
:; case "$VERSION" in *\ 2[0-5].[0-9]) echo "Detected Emacs $VERSION"; echo "Doom only supports Emacs 26.1 and newer"; echo; exit 2 ;; esac :; case "$VERSION" in *\ 2[0-5].[0-9]) echo "Detected Emacs $VERSION"; echo "Doom only supports Emacs 26.1 and newer"; echo; exit 2 ;; esac
:; DOOMBASE="$(dirname "$0")/.." :; DOOMBASE="$(dirname "$0")/.."
:; [ "$1" = -d ] || [ "$1" = --debug ] && { shift; export DEBUG=1; } :; [ "$1" = -d ] || [ "$1" = --debug ] && { shift; export DEBUG=1; }
:; [ "$1" = run ] && { cd "$DOOMBASE"; shift; exec $EMACS -q --no-splash -l bin/doom "$@"; exit 0; } :; [ "$1" = run ] && { cd "$DOOMBASE"; shift; exec $EMACS -q --no-splash -l init.el "$@"; exit 0; }
:; exec $EMACS --no-site-file --script "$0" -- "$@" :; exec $EMACS --no-site-file --script "$0" -- "$@"
:; exit 0 :; exit 0
(let* ((load-prefer-newer t) (let* ((loaddir (file-name-directory (file-truename load-file-name)))
(loaddir (file-name-directory (file-truename load-file-name)))
(emacsdir (getenv "EMACSDIR")) (emacsdir (getenv "EMACSDIR"))
(user-emacs-directory (user-emacs-directory
(abbreviate-file-name (or emacsdir (expand-file-name "../" loaddir))))) (abbreviate-file-name (or emacsdir (expand-file-name "../" loaddir)))))
;;
(load (expand-file-name "core/core.el" user-emacs-directory) nil t)
;; HACK Load `cl' and site files manually so we can stop them from polluting ;; HACK Load `cl' and site files manually so we can stop them from polluting
;; CLI logs with deprecation and file load messages. ;; CLI logs with deprecation and file load messages.
(let ((inhibit-message t)) (quiet! (when (> emacs-major-version 26)
(when (> emacs-major-version 26)
(require 'cl)) (require 'cl))
(load "site-start" t t)) (load "site-start" t t))
(push (expand-file-name "core" user-emacs-directory) load-path) (doom-log "Initializing Doom CLI")
(require 'core)
(require 'core-cli) (require 'core-cli)
(defcli! :main (defcli! :main
@ -45,10 +45,10 @@ with a different private module."
(setq user-emacs-directory (file-name-as-directory emacsdir)) (setq user-emacs-directory (file-name-as-directory emacsdir))
(print! (info "EMACSDIR=%s") localdir)) (print! (info "EMACSDIR=%s") localdir))
(when doomdir (when doomdir
(setenv "DOOMDIR" doomdir) (setenv "DOOMDIR" (file-name-as-directory doomdir))
(print! (info "DOOMDIR=%s") localdir)) (print! (info "DOOMDIR=%s") localdir))
(when localdir (when localdir
(setenv "DOOMLOCALDIR" localdir) (setenv "DOOMLOCALDIR" (file-name-as-directory localdir))
(print! (info "DOOMLOCALDIR=%s") localdir)) (print! (info "DOOMLOCALDIR=%s") localdir))
(when debug-p (when debug-p
(setenv "DEBUG" "1") (setenv "DEBUG" "1")
@ -75,21 +75,16 @@ with a different private module."
(when (or emacsdir doomdir localdir) (when (or emacsdir doomdir localdir)
(load! "core/core.el" user-emacs-directory)) (load! "core/core.el" user-emacs-directory))
(cond ((not noninteractive) (let (print-level print-gensym print-length)
(print! "Doom launched out of %s (test mode)" (path user-emacs-directory)) (condition-case e
(load! "init.el" user-emacs-directory) (if (null command)
(doom-run-all-startup-hooks-h)) (doom-cli-execute "help")
((null command)
(doom-cli-execute "help"))
((condition-case e
(let ((start-time (current-time))) (let ((start-time (current-time)))
(and (doom-cli-execute command args) (and (doom-cli-execute command args)
(print! (success "Finished! (%.4fs)") (print! (success "Finished! (%.4fs)")
(float-time (float-time
(time-subtract (current-time) (time-subtract (current-time)
start-time))))) start-time))))))
(user-error (user-error
(print! (error "%s\n") (error-message-string e)) (print! (error "%s\n") (error-message-string e))
(print! (yellow "See 'doom help %s' for documentation on this command.") (car args)) (print! (yellow "See 'doom help %s' for documentation on this command.") (car args))
@ -107,11 +102,11 @@ with a different private module."
(dolist (item (cdr e)) (dolist (item (cdr e))
(print! "%S" item)) (print! "%S" item))
(print! "n/a"))) (print! "n/a")))
(when (featurep 'straight) (when (and (bound-and-true-p straight-process-buffer)
(when (string-match-p (regexp-quote straight-process-buffer) (string-match-p (regexp-quote straight-process-buffer)
(error-message-string e)) (error-message-string e)))
(print! (bold "Straight output:")) (print! (bold "Straight output:"))
(print-group! (print! "%s" (straight--process-get-output)))))) (print-group! (print! "%s" (straight--process-get-output)))))
(unless debug-on-error (unless debug-on-error
(terpri) (terpri)
(print! (print!
@ -122,7 +117,8 @@ with a different private module."
(string-join (append (list (file-name-nondirectory load-file-name) "-d" command) (string-join (append (list (file-name-nondirectory load-file-name) "-d" command)
args) args)
" ")) " "))
(error ""))))))) ; Ensure non-zero exit code ;; Ensure non-zero exit code
(error ""))))))
(doom-cli-execute :main (cdr (member "--" argv))) (doom-cli-execute :main (cdr (member "--" argv)))
(setq argv nil)) (setq argv nil))

View file

@ -55,14 +55,19 @@ And jumps to your `doom!' block."
(defmacro doom--if-compile (command on-success &optional on-failure) (defmacro doom--if-compile (command on-success &optional on-failure)
(declare (indent 2)) (declare (indent 2))
`(with-current-buffer (compile ,command) (let ((windowsym (make-symbol "doom-sync-window")))
`(with-current-buffer (compile ,command t)
(let ((,windowsym (get-buffer-window (current-buffer))))
(select-window ,windowsym)
(add-hook (add-hook
'compilation-finish-functions 'compilation-finish-functions
(lambda (_buf status) (lambda (_buf status)
(if (equal status "finished\n") (if (equal status "finished\n")
,on-success (progn
(delete-window ,windowsym)
,on-success)
,on-failure)) ,on-failure))
nil 'local))) nil 'local)))))
;;;###autoload ;;;###autoload
(defun doom/reload () (defun doom/reload ()
@ -89,7 +94,7 @@ Runs `doom-reload-hook' afterwards."
(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-run-hook) (run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook)
(print! (success "Config successfully reloaded!"))) (message "Config successfully reloaded!"))
(user-error "Failed to reload your config"))) (user-error "Failed to reload your config")))
;;;###autoload ;;;###autoload

View file

@ -1,5 +1,36 @@
;;; core/autoload/debug.el -*- lexical-binding: t; -*- ;;; core/autoload/debug.el -*- lexical-binding: t; -*-
;;
;;; Doom's debug mode
;;;###autoload
(defvar doom-debug-variables
'(doom-debug-mode
init-file-debug
debug-on-error
garbage-collection-messages
use-package-verbose
jka-compr-verbose
lsp-log-io
gcmh-verbose
magit-refresh-verbose
url-debug)
"A list of variable to toggle on `doom/toggle-debug-mode'.")
;;;###autoload
(defun doom/toggle-debug-mode (&optional arg)
"Toggle `debug-on-error' and `doom-debug-mode' for verbose logging."
(interactive (list (or current-prefix-arg 'toggle)))
(let ((value
(cond ((eq arg 'toggle) (not doom-debug-mode))
((> (prefix-numeric-value arg) 0)))))
(mapc (doom-rpartial #'set value) doom-debug-variables)
(message "Debug mode %s" (if value "on" "off"))))
;;
;;; Hooks
;;;###autoload ;;;###autoload
(defun doom-run-all-startup-hooks-h () (defun doom-run-all-startup-hooks-h ()
"Run all startup Emacs hooks. Meant to be executed after starting Emacs with "Run all startup Emacs hooks. Meant to be executed after starting Emacs with
@ -17,18 +48,12 @@
;; ;;
;;; Helpers ;;; Helpers
(defun doom-template-insert (template)
"TODO"
(let ((file (expand-file-name (format "templates/%s" template) doom-core-dir)))
(when (file-exists-p file)
(insert-file-contents file))))
(defsubst doom--collect-forms-in (file form) (defsubst doom--collect-forms-in (file form)
(when (file-readable-p file) (when (file-readable-p file)
(let (forms) (let (forms)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(delay-mode-hooks (emacs-lisp-mode)) (let (emacs-lisp-mode) (emacs-lisp-mode))
(while (re-search-forward (format "(%s " (regexp-quote form)) nil t) (while (re-search-forward (format "(%s " (regexp-quote form)) nil t)
(let ((ppss (syntax-ppss))) (let ((ppss (syntax-ppss)))
(unless (or (nth 4 ppss) (unless (or (nth 4 ppss)
@ -45,7 +70,7 @@ ready to be pasted in a bug report on github."
(require 'vc-git) (require 'vc-git)
(require 'core-packages) (require 'core-packages)
(let ((default-directory doom-emacs-dir) (let ((default-directory doom-emacs-dir)
(doom-modules (doom-modules))) (doom-modules (doom-module-list)))
(letf! (defun sh (&rest args) (cdr (apply #'doom-call-process args))) (letf! (defun sh (&rest args) (cdr (apply #'doom-call-process args)))
`((emacs `((emacs
(version . ,emacs-version) (version . ,emacs-version)
@ -243,10 +268,10 @@ Some items are not supported by the `nsm.el' module."
(file (make-temp-file "doom-sandbox-"))) (file (make-temp-file "doom-sandbox-")))
(require 'package) (require 'package)
(with-temp-file file (with-temp-file file
(insert (prin1 `(progn
(prin1-to-string (setq noninteractive nil
(macroexp-progn process-environment ',doom--initial-process-environment
(append `((setq noninteractive nil exec-path ',doom--initial-exec-path
init-file-debug t init-file-debug t
load-path ',load-path load-path ',load-path
package--init-file-ensured t package--init-file-ensured t
@ -255,15 +280,25 @@ Some items are not supported by the `nsm.el' module."
user-emacs-directory ,doom-emacs-dir) user-emacs-directory ,doom-emacs-dir)
(with-eval-after-load 'undo-tree (with-eval-after-load 'undo-tree
;; undo-tree throws errors because `buffer-undo-tree' isn't ;; undo-tree throws errors because `buffer-undo-tree' isn't
;; corrrectly initialized ;; correctly initialized
(setq-default buffer-undo-tree (make-undo-tree)))) (setq-default buffer-undo-tree (make-undo-tree)))
(pcase mode (ignore-errors
(delete-directory ,(expand-file-name "auto-save-list" doom-emacs-dir) 'parents)))
(current-buffer))
(prin1 `(unwind-protect
(defun --run-- () ,(read (concat "(progn\n" contents "\n)")))
(delete-file ,file))
(current-buffer))
(prin1 (pcase mode
(`vanilla-doom+ ; Doom core + modules - private config (`vanilla-doom+ ; Doom core + modules - private config
`((load-file ,(expand-file-name "core.el" doom-core-dir)) `(progn
(load-file ,(expand-file-name "core.el" doom-core-dir))
(setq doom-modules-dirs (list doom-modules-dir))
(let ((doom-init-modules-p t))
(doom-initialize) (doom-initialize)
(doom-initialize-core) (doom-initialize-core-modules))
(add-hook 'window-setup-hook #'doom-display-benchmark-h)
(setq doom-modules ',doom-modules) (setq doom-modules ',doom-modules)
(--run--)
(maphash (lambda (key plist) (maphash (lambda (key plist)
(let ((doom--current-module key) (let ((doom--current-module key)
(doom--current-flags (plist-get plist :flags))) (doom--current-flags (plist-get plist :flags)))
@ -277,14 +312,18 @@ Some items are not supported by the `nsm.el' module."
(run-hook-wrapped 'doom-init-modules-hook #'doom-try-run-hook) (run-hook-wrapped 'doom-init-modules-hook #'doom-try-run-hook)
(doom-run-all-startup-hooks-h))) (doom-run-all-startup-hooks-h)))
(`vanilla-doom ; only Doom core (`vanilla-doom ; only Doom core
`((load-file ,(expand-file-name "core.el" doom-core-dir)) `(progn
(load-file ,(expand-file-name "core.el" doom-core-dir))
(let ((doom-init-modules-p t))
(doom-initialize) (doom-initialize)
(doom-initialize-core) (doom-initialize-core-modules))
(--run--)
(doom-run-all-startup-hooks-h))) (doom-run-all-startup-hooks-h)))
(`vanilla ; nothing loaded (`vanilla ; nothing loaded
`((package-initialize))))))) `(progn
"\n(unwind-protect (progn\n" contents "\n)\n" (package-initialize)
(format "(delete-file %S))" file))) (--run--))))
(current-buffer)))
(let ((args (if (eq mode 'doom) (let ((args (if (eq mode 'doom)
(list "-l" file) (list "-l" file)
(list "-Q" "-l" file)))) (list "-Q" "-l" file))))
@ -343,7 +382,7 @@ to reproduce bugs and determine if Doom is to blame."
(doom-sandbox-emacs-lisp-mode) (doom-sandbox-emacs-lisp-mode)
(setq-local default-directory doom-emacs-dir) (setq-local default-directory doom-emacs-dir)
(unless (buffer-live-p exists) (unless (buffer-live-p exists)
(doom-template-insert "VANILLA_SANDBOX") (insert-file-contents (doom-glob doom-core-dir "templates/VANILLA_SANDBOX"))
(let ((contents (substitute-command-keys (buffer-string)))) (let ((contents (substitute-command-keys (buffer-string))))
(erase-buffer) (erase-buffer)
(insert contents "\n"))) (insert contents "\n")))
@ -378,20 +417,3 @@ will be automatically appended to the result."
(profiler-report) (profiler-report)
(profiler-stop)) (profiler-stop))
(setq doom--profiler (not doom--profiler))) (setq doom--profiler (not doom--profiler)))
;;;###autoload
(defun doom/toggle-debug-mode (&optional arg)
"Toggle `debug-on-error' and `doom-debug-mode' for verbose logging."
(interactive (list (or current-prefix-arg 'toggle)))
(let ((value
(cond ((eq arg 'toggle) (not doom-debug-mode))
((> (prefix-numeric-value arg) 0)))))
(setq doom-debug-mode value
debug-on-error value
garbage-collection-messages value
use-package-verbose value
jka-compr-verbose value
lsp-log-io value
gcmh-verbose value
magit-refresh-verbose value)
(message "Debug mode %s" (if value "on" "off"))))

View file

@ -427,8 +427,8 @@ If prefix arg is present, refresh the cache."
(let ((guess (or (function-called-at-point) (let ((guess (or (function-called-at-point)
(symbol-at-point)))) (symbol-at-point))))
(require 'finder-inf nil t) (require 'finder-inf nil t)
(require 'core-packages) (require 'package)
(doom-initialize-packages) (require 'straight)
(let ((packages (delete-dups (let ((packages (delete-dups
(append (mapcar #'car package-alist) (append (mapcar #'car package-alist)
(mapcar #'car package--builtins) (mapcar #'car package--builtins)
@ -503,7 +503,7 @@ If prefix arg is present, refresh the cache."
(modules (modules
(if (gethash (symbol-name package) straight--build-cache) (if (gethash (symbol-name package) straight--build-cache)
(doom-package-get package :modules) (doom-package-get package :modules)
(plist-get (cdr (assq package (doom-packages-list 'all))) (plist-get (cdr (assq package (doom-package-list 'all)))
:modules))) :modules)))
(package--print-help-section "Modules") (package--print-help-section "Modules")
(insert "Declared by the following Doom modules:\n") (insert "Declared by the following Doom modules:\n")

View file

@ -1,276 +1,5 @@
;;; core/autoload/packages.el -*- lexical-binding: t; -*- ;;; core/autoload/packages.el -*- lexical-binding: t; -*-
;;
;;; Package metadata
;;;###autoload
(defun doom-package-get (package &optional prop nil-value)
"Returns PACKAGE's `package!' recipe from `doom-packages'."
(let ((plist (cdr (assq package doom-packages))))
(if prop
(if (plist-member plist prop)
(plist-get plist prop)
nil-value)
plist)))
;;;###autoload
(defun doom-package-set (package prop value)
"Set PROPERTY in PACKAGE's recipe to VALUE."
(setf (alist-get package doom-packages)
(plist-put (alist-get package doom-packages)
prop value)))
;;;###autoload
(defun doom-package-recipe (package &optional prop nil-value)
"Returns the `straight' recipe PACKAGE was registered with."
(let ((plist (gethash (symbol-name package) straight--recipe-cache)))
(if prop
(if (plist-member plist prop)
(plist-get plist prop)
nil-value)
plist)))
;;;###autoload
(defun doom-package-recipe-repo (package)
"Resolve and return PACKAGE's (symbol) local-repo property."
(if-let* ((recipe (cdr (straight-recipes-retrieve package)))
(repo (straight-vc-local-repo-name recipe)))
repo
(symbol-name package)))
;;;###autoload
(defun doom-package-build-recipe (package &optional prop nil-value)
"Returns the `straight' recipe PACKAGE was installed with."
(let ((plist (nth 2 (gethash (symbol-name package) straight--build-cache))))
(if prop
(if (plist-member plist prop)
(plist-get plist prop)
nil-value)
plist)))
;;;###autoload
(defun doom-package-build-time (package)
"TODO"
(car (gethash (symbol-name package) straight--build-cache)))
;;;###autoload
(defun doom-package-dependencies (package &optional recursive _noerror)
"Return a list of dependencies for a package."
(let ((deps (nth 1 (gethash (symbol-name package) straight--build-cache))))
(if recursive
(nconc deps (mapcan (lambda (dep) (doom-package-dependencies dep t t))
deps))
deps)))
;;;###autoload
(defun doom-package-depending-on (package &optional noerror)
"Return a list of packages that depend on the package named NAME."
(cl-check-type name symbol)
;; can't get dependencies for built-in packages
(unless (or (doom-package-build-recipe name)
noerror)
(error "Couldn't find %s, is it installed?" name))
(cl-loop for pkg in (hash-table-keys straight--build-cache)
for deps = (doom-package-dependencies pkg)
if (memq package deps)
collect pkg
and append (doom-package-depending-on pkg t)))
;;
;;; Predicate functions
;;;###autoload
(defun doom-package-built-in-p (package)
"Return non-nil if PACKAGE (a symbol) is built-in."
(eq (doom-package-build-recipe package :type)
'built-in))
;;;###autoload
(defun doom-package-installed-p (package)
"Return non-nil if PACKAGE (a symbol) is installed."
(file-directory-p (straight--build-dir (symbol-name package))))
;;;###autoload
(defun doom-package-registered-p (package)
"Return non-nil if PACKAGE (a symbol) has been registered with `package!'.
Excludes packages that have a non-nil :built-in property."
(when-let (plist (doom-package-get package))
(not (plist-get plist :ignore))))
;;;###autoload
(defun doom-package-private-p (package)
"Return non-nil if PACKAGE was installed by the user's private config."
(assq :private (doom-package-get package :modules)))
;;;###autoload
(defun doom-package-protected-p (package)
"Return non-nil if PACKAGE is protected.
A protected package cannot be deleted and will be auto-installed if missing."
(memq package doom-core-packages))
;;;###autoload
(defun doom-package-core-p (package)
"Return non-nil if PACKAGE is a core Doom package."
(or (doom-package-protected-p package)
(assq :core (doom-package-get package :modules))))
;;;###autoload
(defun doom-package-backend (package)
"Return 'straight, 'builtin, 'elpa or 'other, depending on how PACKAGE is
installed."
(cond ((gethash (symbol-name package) straight--build-cache)
'straight)
((or (doom-package-built-in-p package)
(assq package package--builtins))
'builtin)
((assq package package-alist)
'elpa)
((locate-library (symbol-name package))
'other)))
;;;###autoload
(defun doom-package-different-recipe-p (name)
"Return t if a package named NAME (a symbol) has a different recipe than it
was installed with."
(cl-check-type name symbol)
;; TODO
;; (when (doom-package-installed-p name)
;; (when-let* ((doom-recipe (assq name doom-packages))
;; (install-recipe (doom-package-recipe)))
;; (not (equal (cdr quelpa-recipe)
;; (cdr (plist-get (cdr doom-recipe) :recipe))))))
)
;;
;;; Package list getters
(defun doom--read-module-packages-file (file &optional noeval noerror)
(with-temp-buffer ; prevent buffer-local settings from propagating
(condition-case e
(if (not noeval)
(load file noerror t t)
(when (file-readable-p file)
(insert-file-contents file)
(delay-mode-hooks (emacs-lisp-mode))
(while (search-forward "(package! " nil t)
(save-excursion
(goto-char (match-beginning 0))
(unless (let ((ppss (syntax-ppss)))
(or (nth 3 ppss)
(nth 4 ppss)))
(cl-destructuring-bind (name . plist)
(cdr (sexp-at-point))
(push (cons
name (plist-put
plist :modules
(list (doom-module-from-path file))))
doom-packages)))))))
((debug error)
(signal 'doom-package-error
(list (doom-module-from-path file)
file
e))))))
;;;###autoload
(defun doom-package-list (&optional all-p)
"Retrieve a list of explicitly declared packages from enabled modules.
This excludes core packages listed in `doom-core-packages'.
If ALL-P, gather packages unconditionally across all modules, including disabled
ones."
(let ((doom-interactive-mode t)
(doom-modules (doom-modules))
doom-packages)
(doom--read-module-packages-file
(doom-path doom-core-dir "packages.el") all-p t)
(let ((private-packages (doom-path doom-private-dir "packages.el")))
(unless all-p
;; We load the private packages file twice to ensure disabled packages
;; are seen ASAP, and a second time to ensure privately overridden
;; packages are properly overwritten.
(doom--read-module-packages-file private-packages nil t))
(if all-p
(mapc #'doom--read-module-packages-file
(doom-files-in doom-modules-dir
:depth 2
:match "/packages\\.el$"))
(cl-loop for key being the hash-keys of doom-modules
for path = (doom-module-path (car key) (cdr key) "packages.el")
for doom--current-module = key
do (doom--read-module-packages-file path nil t)))
(doom--read-module-packages-file private-packages all-p t))
(nreverse doom-packages)))
;;;###autoload
(defun doom-package-pinned-list ()
"Return an alist mapping package names (strings) to pinned commits (strings)."
(let (alist)
(dolist (package doom-packages alist)
(cl-destructuring-bind (name &key disable ignore pin unpin &allow-other-keys)
package
(when (and (not ignore)
(not disable)
(or pin unpin))
(setf (alist-get (doom-package-recipe-repo name) alist
nil 'remove #'equal)
(unless unpin pin)))))))
;;;###autoload
(defun doom-package-unpinned-list ()
"Return an alist mapping package names (strings) to pinned commits (strings)."
(let (alist)
(dolist (package doom-packages alist)
(cl-destructuring-bind
(_ &key recipe disable ignore pin unpin &allow-other-keys)
package
(when (and (not ignore)
(not disable)
(or unpin
(and (plist-member recipe :pin)
(null pin))))
(cl-pushnew (doom-package-recipe-repo (car package)) alist
:test #'equal))))))
;;;###autoload
(defun doom-package-recipe-list ()
"Return straight recipes for non-builtin packages with a local-repo."
(let (recipes)
(dolist (recipe (hash-table-values straight--recipe-cache))
(cl-destructuring-bind (&key local-repo type no-build &allow-other-keys)
recipe
(unless (or (null local-repo)
(eq type 'built-in)
no-build)
(push recipe recipes))))
(nreverse recipes)))
;;;###autoload
(defmacro doom-with-package-recipes (recipes binds &rest body)
"TODO"
(declare (indent 2))
(let ((recipe-var (make-symbol "recipe"))
(recipes-var (make-symbol "recipes")))
`(let* ((,recipes-var ,recipes)
(built ())
(straight-use-package-pre-build-functions
(cons (lambda (pkg) (cl-pushnew pkg built :test #'equal))
straight-use-package-pre-build-functions)))
(dolist (,recipe-var ,recipes-var)
(cl-block nil
(straight--with-plist (append (list :recipe ,recipe-var) ,recipe-var)
,(doom-enlist binds)
,@body)))
(nreverse built))))
;;
;;; Main functions
;;;###autoload ;;;###autoload
(defun doom/reload-packages () (defun doom/reload-packages ()
"Reload `doom-packages', `package' and `quelpa'." "Reload `doom-packages', `package' and `quelpa'."
@ -280,47 +9,185 @@ ones."
(doom-initialize-packages t) (doom-initialize-packages t)
(message "Reloading packages...DONE")) (message "Reloading packages...DONE"))
;;;###autoload
(defun doom/update-pinned-package-form (&optional select)
"Inserts or updates a `:pin' for the `package!' statement at point.
;;
;;; Bump commands
(defun doom--package-full-recipe (package plist)
(doom-plist-merge
(plist-get plist :recipe)
(or (cdr (straight-recipes-retrieve package))
(plist-get (cdr (assq package doom-packages))
:recipe))))
(defun doom--package-to-bump-string (package plist)
"Return a PACKAGE and its PLIST in 'username/repo@commit' format."
(format "%s@%s"
(plist-get (doom--package-full-recipe package plist) :repo)
(substring-no-properties (plist-get plist :pin) 0 7)))
(defun doom--package-at-point (&optional point)
"Return the package and plist from the (package! PACKAGE PLIST...) at point."
(save-match-data
(save-excursion
(and point (goto-char point))
(if (eq (sexp-at-point) 'package!)
(progn
(backward-sexp)
(backward-char)
t)
(while (and (search-backward "(package!" nil t)
(doom-point-in-string-or-comment-p))))
(unless (or (doom-point-in-string-or-comment-p)
(not (eq (car-safe (sexp-at-point)) 'package!)))
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'sexp)
(let ((package (let (doom-packages)
(eval (sexp-at-point) t))))
(list :beg beg
:end end
:package (car package)
:plist (cdr package))))))))
;;;###autoload
(defun doom/bumpify-package-at-point ()
"Convert `package!' call at point to a bump string."
(interactive)
(cl-destructuring-bind (&key package plist beg end)
(doom--package-at-point)
(when-let (str (doom--package-to-bump-string package plist))
(goto-char beg)
(delete-region beg end)
(insert str))))
;;;###autoload
(defun doom/bumpify-packages-in-buffer ()
"Convert all `package!' calls in buffer into bump strings."
(interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward "(package!" nil t)
(unless (doom-point-in-string-or-comment-p)
(doom/bumpify-package-at-point)))))
;;;###autoload
(defun doom/bump-package-at-point (&optional select)
"Inserts or updates a `:pin' for the `package!' statement at point.
Grabs the latest commit id of the package using 'git'." Grabs the latest commit id of the package using 'git'."
(interactive "P") (interactive "P")
;; REVIEW Better error handling (doom-initialize-packages)
;; TODO Insert a new `package!' if no `package!' at poin (cl-destructuring-bind (&key package plist beg end)
(require 'straight) (or (doom--package-at-point)
(ignore-errors (user-error "Not on a `package!' call"))
(while (and (atom (sexp-at-point)) (let* ((recipe (doom--package-full-recipe package plist))
(not (bolp))) (branch (or (plist-get recipe :branch)
(forward-sexp -1))) straight-vc-git-default-branch))
(save-excursion (oldid (or (plist-get plist :pin)
(if (not (eq (sexp-at-point) 'package!)) (doom-package-get package :pin)))
(user-error "Not on a `package!' call") id url)
(backward-char) (when (or (eq (plist-get plist :built-in) t)
(let* ((recipe (cdr (sexp-at-point))) (and (eq (plist-get plist :built-in) 'prefer)
(package (car recipe)) (locate-library (symbol-name package))))
(oldid (doom-package-get package :pin)) (user-error "%s: skipping built-in package" package))
(id (setq url (straight-vc-git--destructure recipe (upstream-repo upstream-host)
(straight-vc-git--encode-url upstream-repo upstream-host))
id (when url
(cdr (doom-call-process (cdr (doom-call-process
"git" "ls-remote" "git" "ls-remote" url
(straight-vc-git--destructure (unless select
(doom-plist-merge (or branch straight-vc-git-default-branch))))))
(plist-get (cdr recipe) :recipe)
(or (cdr (straight-recipes-retrieve package))
(plist-get (cdr (assq package doom-packages)) :recipe)))
(upstream-repo upstream-host)
(straight-vc-git--encode-url upstream-repo upstream-host))))))
(unless id (unless id
(user-error "No id for %S package" package)) (user-error "%s: no id from %s" package url))
(let* ((id (if select (let* ((id (car (split-string
(car (split-string (completing-read "Commit: " (split-string id "\n" t)))) (if select
(car (split-string id)))) (completing-read "Commit: " (split-string id "\n" t))
(id (substring id 0 10))) id)))))
(if (and oldid (string-match-p (concat "^" oldid) id)) (when (and oldid (equal oldid id))
(user-error "No update necessary") (user-error "%s: no update necessary" package))
(if (re-search-forward ":pin +\"\\([^\"]+\\)\"" (cdr (bounds-of-thing-at-point 'sexp)) t) (save-excursion
(if (re-search-forward ":pin +\"\\([^\"]+\\)\"" end t)
(replace-match id t t nil 1) (replace-match id t t nil 1)
(thing-at-point--end-of-sexp) (thing-at-point--end-of-sexp)
(backward-char) (backward-char)
(insert " :pin " (prin1-to-string id))) (insert " :pin " (prin1-to-string id))))
(message "Updated %S: %s -> %s" package oldid id))))))) (message "Updated %S: %s -> %s"
package
(substring oldid 0 10)
(substring id 0 10))))))
;;;###autoload
(defun doom/bump-packages-in-buffer (&optional select)
"Inserts or updates a `:pin' for the `package!' statement at point.
Grabs the latest commit id of the package using 'git'."
(interactive "P")
(save-excursion
(goto-char (point-min))
(doom-initialize-packages)
(let (packages)
(while (search-forward "(package! " nil t)
(unless (let ((ppss (syntax-ppss)))
(or (nth 4 ppss)
(nth 3 ppss)
(save-excursion
(and (goto-char (match-beginning 0))
(not (plist-member (sexp-at-point) :pin))))))
(condition-case e
(push (doom/bump-package-at-point) packages)
(user-error (message "%s" (error-message-string e))))))
(if packages
(message "Updated %d packages\n- %s" (length packages) (string-join packages "\n- "))
(message "No packages to update")))))
;;;###autoload
(defun doom/bump-module (category &optional module select)
"Bump packages in CATEGORY MODULE.
If SELECT (prefix arg) is non-nil, prompt you to choose a specific commit for
each package."
(interactive
(append
(mapcar #'intern
(split-string
(completing-read
"Bump module: "
(let ((modules (doom-module-list 'all)))
(mapcar (lambda (m)
(if (listp m)
(format "%s %s" (car m) (cdr m))
(format "%s" m)))
(append (list ":private")
(delete-dups (mapcar #'car modules))
modules)))
nil t nil nil)
" " t))
(list current-prefix-arg)))
(if-let (packages-file (if (eq category :private)
(doom-glob doom-private-dir "packages.el")
(doom-module-locate-path category module "packages.el")))
(with-current-buffer
(or (get-file-buffer packages-file)
(find-file-noselect packages-file))
(doom/bump-packages-in-buffer select))
(user-error "Module %s %s has no packages.el file")))
;;;###autoload
(defun doom/bump-package (package)
"Bump PACKAGE in all modules that install it."
(interactive
(list (completing-read "Bump package: "
(mapcar #'car (doom-package-list 'all)))))
(let* ((packages (doom-package-list 'all))
(modules (plist-get (alist-get package packages) :modules)))
(unless modules
(user-error "This package isn't installed by any Doom module"))
(dolist (module modules)
(when-let (packages-file (doom-module-locate-path (car module) (cdr module)))
(doom/bump-module (car module) (cdr module))))))
;;
;;; Bump commits
;;;###autoload
(defun doom/commit-bumps ()
(interactive))

View file

@ -35,24 +35,6 @@ list, the pair is destructured into (CAR . CDR)."
"Delete PROP from PLIST in-place." "Delete PROP from PLIST in-place."
`(setq ,plist (doom-plist-delete ,plist ,prop))) `(setq ,plist (doom-plist-delete ,plist ,prop)))
;;;###autoload
(defmacro with-plist! (plist props &rest body)
"With props bound from PLIST to PROPS, evaluate BODY.
PROPS is a list of symbols. Each one is converted to a keyword and then its
value is looked up in the PLIST and bound to the symbol for the duration of
BODY."
(declare (indent 2))
(let ((plist-sym (make-symbol "plist")))
`(let* ((,plist-sym ,plist)
,@(cl-loop for prop in props
collect
`(,prop
(plist-get
,plist-sym
,(doom-keyword-intern (symbol-name prop))))))
,@body)))
;; ;;
;;; Library ;;; Library

View file

@ -1,7 +1,4 @@
;;; core/autoload/cli.el -*- lexical-binding: t; -*- ;;; core/autoload/process.el -*- lexical-binding: t; -*-
;;
;;; Library
;;;###autoload ;;;###autoload
(defun doom-call-process (command &rest args) (defun doom-call-process (command &rest args)
@ -10,7 +7,7 @@
Returns (STATUS . OUTPUT) when it is done, where STATUS is the returned error Returns (STATUS . OUTPUT) when it is done, where STATUS is the returned error
code of the process and OUTPUT is its stdout output." code of the process and OUTPUT is its stdout output."
(with-temp-buffer (with-temp-buffer
(cons (or (apply #'call-process command nil t nil args) (cons (or (apply #'call-process command nil t nil (remq nil args))
-1) -1)
(string-trim (buffer-string))))) (string-trim (buffer-string)))))
@ -28,7 +25,7 @@ Warning: freezes indefinitely on any stdin prompt."
(cons (let ((process (cons (let ((process
(make-process :name "doom-sh" (make-process :name "doom-sh"
:buffer (current-buffer) :buffer (current-buffer)
:command (cons command args) :command (cons command (remq nil args))
:connection-type 'pipe)) :connection-type 'pipe))
done-p) done-p)
(set-process-filter (set-process-filter

View file

@ -71,6 +71,9 @@
"TODO" "TODO"
(add-hook 'window-setup-hook #'doom-load-session 'append)) (add-hook 'window-setup-hook #'doom-load-session 'append))
;;;###autoload
(add-to-list 'command-switch-alist (cons "--restore" #'doom-restore-session-handler))
;; ;;
;;; Commands ;;; Commands

View file

@ -2,7 +2,9 @@
(defcli! (compile c) (defcli! (compile c)
((recompile-p ["-r" "--recompile"]) ((recompile-p ["-r" "--recompile"])
&rest targets) (core-p ["-c" "--core"])
(private-p ["-p" "--private"])
(verbose-p ["-v" "--verbose"]))
"Byte-compiles your config or selected modules. "Byte-compiles your config or selected modules.
compile [TARGETS...] compile [TARGETS...]
@ -11,8 +13,23 @@
Accepts :core and :private as special arguments, which target Doom's core files Accepts :core and :private as special arguments, which target Doom's core files
and your private config files, respectively. To recompile your packages, use and your private config files, respectively. To recompile your packages, use
'doom rebuild' instead." 'doom build' instead."
(doom-cli-byte-compile targets recompile-p)) (doom-cli-byte-compile
(if (or core-p private-p)
(append (when core-p
(list (doom-glob doom-emacs-dir "init.el")
doom-core-dir))
(when private-p
(list doom-private-dir)))
(append (list (doom-glob doom-emacs-dir "init.el")
doom-core-dir)
(cl-remove-if-not
;; Only compile Doom's modules
(lambda (path) (file-in-directory-p path doom-emacs-dir))
;; Omit `doom-private-dir', which is always first
(cdr (doom-module-load-path)))))
recompile-p
verbose-p))
(defcli! clean () (defcli! clean ()
"Delete all *.elc files." "Delete all *.elc files."
@ -25,17 +42,20 @@ and your private config files, respectively. To recompile your packages, use
(defun doom--byte-compile-ignore-file-p (path) (defun doom--byte-compile-ignore-file-p (path)
(let ((filename (file-name-nondirectory path))) (let ((filename (file-name-nondirectory path)))
(or (string-prefix-p "." filename) (or (not (equal (file-name-extension path) "el"))
(member filename (list "packages.el" "doctor.el"))
(string-prefix-p "." filename)
(string-prefix-p "test-" filename) (string-prefix-p "test-" filename)
(string-suffix-p ".example.el" filename) (string-prefix-p "flycheck_" filename)
(not (equal (file-name-extension path) "el")) (string-suffix-p ".example.el" filename))))
(member filename (list "packages.el" "doctor.el")))))
(cl-defun doom-cli-byte-compile (&optional modules recompile-p) (cl-defun doom-cli-byte-compile (&optional targets recompile-p verbose-p)
"Byte compiles your emacs configuration. "Byte compiles your emacs configuration.
init.el is always byte-compiled by this. init.el is always byte-compiled by this.
If TARGETS is specified, as a list of direcotries
If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are
byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom
core. It always ignores unit tests and files with `no-byte-compile' enabled. core. It always ignores unit tests and files with `no-byte-compile' enabled.
@ -48,94 +68,64 @@ Use `doom-clean-byte-compiled-files' or `make clean' to reverse
byte-compilation. byte-compilation.
If RECOMPILE-P is non-nil, only recompile out-of-date files." If RECOMPILE-P is non-nil, only recompile out-of-date files."
(let ((default-directory doom-emacs-dir) (let* ((default-directory doom-emacs-dir)
(doom-modules (doom-modules)) (targets (nreverse (delete-dups targets)))
(byte-compile-verbose doom-debug-mode)
(byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
;; In case it is changed during compile-time ;; In case it is changed during compile-time
(auto-mode-alist auto-mode-alist) (auto-mode-alist auto-mode-alist)
(noninteractive t) kill-emacs-hook kill-buffer-query-functions)
targets)
(let (target-dirs)
(dolist (module (delete-dups modules))
(pcase module
(":core"
(push (doom-glob doom-emacs-dir "init.el") targets)
(push doom-core-dir target-dirs))
(":private"
(push doom-private-dir target-dirs))
((pred file-directory-p)
(push module target-dirs))
((pred (string-match "^\\([^/]+\\)/\\([^/]+\\)$"))
(push (doom-module-locate-path
(doom-keyword-intern (match-string 1 module))
(intern (match-string 2 module)))
target-dirs))
(_ (user-error "%S is not a valid target" module))))
(and (or (null modules) (member ":private" modules))
(not recompile-p)
(not (or doom-auto-accept
(y-or-n-p
(concat "Warning: byte compiling is for advanced users. It will interfere with your\n"
"efforts to debug issues. It is not recommended you do it if you frequently\n"
"tinker with your Emacs config.\n\n"
"Alternatively, use `bin/doom compile :core` instead to byte-compile only the\n"
"Doom core files, as these don't change often.\n\n"
"If you have issues, please make sure byte-compilation isn't the cause by using\n"
"`bin/doom clean` to clear out your *.elc files.\n\n"
"Byte-compile anyway?"))))
(user-error "Aborting"))
(let ((after-load-functions
(if (null targets)
after-load-functions
;; Assemble el files we want to compile, and preserve in the order
;; they are loaded in, so we don't run into any scary catch-22s
;; while byte-compiling, like missing macros.
(cons (let ((target-dirs (cl-remove-if-not #'file-directory-p targets)))
(lambda (path)
(and (not (doom--byte-compile-ignore-file-p path))
(cl-find-if (doom-partial #'file-in-directory-p path)
target-dirs)
(cl-pushnew path targets))))
after-load-functions))))
(doom-log "Reloading Doom in preparation for byte-compilation")
;; But first we must be sure that Doom and your private config have been ;; But first we must be sure that Doom and your private config have been
;; fully loaded. Which usually aren't so in an noninteractive session. ;; fully loaded. Which usually aren't so in an noninteractive session.
(let ((doom-interactive-mode 'byte-compile)) (let ((load-prefer-newer t)
(doom-initialize) (noninteractive t)
(doom-initialize-packages) doom-interactive-mode)
(doom-initialize-core)) (doom-initialize 'force)
(quiet! (doom-initialize-packages))))
;; (if (null targets)
(unless target-dirs (print! (info "No targets to %scompile" (if recompile-p "re" "")))
(push (doom-glob doom-emacs-dir "init.el") targets) (print! (start "%scompiling your config...")
;; If no targets were supplied, then we use your module list. (if recompile-p "Re" "Byte-"))
(appendq! target-dirs
(list doom-core-dir)
(nreverse
(cl-remove-if-not
(lambda (path) (file-in-directory-p path doom-emacs-dir))
;; Omit `doom-private-dir', which is always first
(cdr (doom-module-load-path))))))
;; Assemble el files we want to compile; taking into account that MODULES (dolist (dir
;; may be a list of MODULE/SUBMODULE strings from the command line. (cl-remove-if-not #'file-directory-p targets)
(appendq! targets (setq targets (cl-remove-if #'file-directory-p targets)))
(doom-files-in target-dirs (prependq! targets
:match "\\.el$" (doom-files-in
:filter #'doom--byte-compile-ignore-file-p))) dir :match "\\.el" :filter #'doom--byte-compile-ignore-file-p)))
(unless targets
(print!
(if targets
(warn "Couldn't find any valid targets")
(info "No targets to %scompile" (if recompile-p "re" ""))))
(cl-return nil))
(print!
(start (if recompile-p
"Recompiling stale elc files..."
"Byte-compiling your config (may take a while)...")))
(print-group! (print-group!
(require 'use-package) (require 'use-package)
(condition-case e (condition-case-unless-debug e
(let ((total-ok 0) (let* ((total-ok 0)
(total-fail 0) (total-fail 0)
(total-noop 0) (total-noop 0)
(byte-compile-verbose nil)
(byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
(byte-compile-dynamic-docstrings t)
(use-package-compute-statistics nil)
(use-package-defaults use-package-defaults) (use-package-defaults use-package-defaults)
(use-package-expand-minimally t) (use-package-expand-minimally t)
kill-emacs-hook kill-buffer-query-functions) (targets (delete-dups targets))
(modules (seq-group-by (lambda (t) (doom-module-from-path t)) targets))
(total-files (length targets))
(total-modules (length modules))
(i 0)
last-module)
;; Prevent packages from being loaded at compile time if they ;; Prevent packages from being loaded at compile time if they
;; don't meet their own predicates. ;; don't meet their own predicates.
(push (list :no-require t (push (list :no-require t
@ -146,40 +136,41 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
(when-let (pred (plist-get args :unless)) (when-let (pred (plist-get args :unless))
(eval pred t))))) (eval pred t)))))
use-package-defaults) use-package-defaults)
(dolist (module-files modules)
(unless recompile-p (cl-incf i)
(doom-clean-byte-compiled-files)) (dolist (target (cdr module-files))
(dolist (target (delete-dups (delq nil targets)))
(cl-incf
(if (not (or (not recompile-p)
(let ((elc-file (byte-compile-dest-file target))) (let ((elc-file (byte-compile-dest-file target)))
(and (file-exists-p elc-file) (cl-incf
(file-newer-than-file-p target elc-file))))) (if (and recompile-p (not (file-newer-than-file-p target elc-file)))
total-noop total-noop
(pcase (if (doom-file-cookie-p target "if" t) (pcase (if (not (doom-file-cookie-p target "if" t))
'no-byte-compile
(unless (equal last-module (car module-files))
(print! (success "(% 3d/%d) Compiling %s %s module...")
i total-modules (caar module-files) (cdar module-files))
(setq last-module (car module-files)))
(if verbose-p
(byte-compile-file target) (byte-compile-file target)
'no-byte-compile) (quiet! (byte-compile-file target))))
(`no-byte-compile (`no-byte-compile
(print! (info "Ignored %s") (relpath target)) (print! (debug "(% 3d/%d) Ignored %s")
i total-modules (relpath target))
total-noop) total-noop)
(`nil (`nil
(print! (error "Failed to compile %s") (relpath target)) (print! (error "(% 3d/%d) Failed to compile %s")
i total-modules (relpath target))
total-fail) total-fail)
(_ (_ total-ok)))))))
(print! (success "Compiled %s") (relpath target)) (print! (class (if (= total-fail 0) 'success 'warn)
(load target t t)
total-ok)))))
(print! (class (if (= total-fail 0) 'success 'error)
"%s %d/%d file(s) (%d ignored)") "%s %d/%d file(s) (%d ignored)")
(if recompile-p "Recompiled" "Compiled") (if recompile-p "Recompiled" "Byte-compiled")
total-ok (- (length targets) total-noop) total-ok total-files
total-noop) total-noop)
t) (= total-fail 0))
((debug error) ((debug error)
(print! (error "\nThere were breaking errors.\n\n%s") (print! (error "There were breaking errors.\n\n%s")
"Reverting changes...") "Reverting changes...")
(signal 'doom-error (list 'byte-compile e))))))) (signal 'doom-error (list 'byte-compile e))))))))
(defun doom-clean-byte-compiled-files () (defun doom-clean-byte-compiled-files ()
"Delete all the compiled elc files in your Emacs configuration and private "Delete all the compiled elc files in your Emacs configuration and private
@ -188,7 +179,8 @@ module. This does not include your byte-compiled, third party packages.'"
(print! (start "Cleaning .elc files")) (print! (start "Cleaning .elc files"))
(print-group! (print-group!
(cl-loop with default-directory = doom-emacs-dir (cl-loop with default-directory = doom-emacs-dir
with success = nil with success = 0
with esc = (if doom-debug-mode "" "\033[1A")
for path for path
in (append (doom-glob doom-emacs-dir "*.elc") in (append (doom-glob doom-emacs-dir "*.elc")
(doom-files-in doom-private-dir :match "\\.elc$" :depth 1) (doom-files-in doom-private-dir :match "\\.elc$" :depth 1)
@ -196,10 +188,10 @@ module. This does not include your byte-compiled, third party packages.'"
(doom-files-in doom-modules-dirs :match "\\.elc$" :depth 4)) (doom-files-in doom-modules-dirs :match "\\.elc$" :depth 4))
if (file-exists-p path) if (file-exists-p path)
do (delete-file path) do (delete-file path)
and do (print! (success "Deleted %s") (relpath path)) and do (print! (success "\033[KDeleted %s%s") (relpath path) esc)
and do (setq success t) and do (cl-incf success)
finally do finally do
(print! (if success (print! (if (> success 0)
(success "All elc files deleted") (success "\033[K%d elc files deleted" success)
(info "No elc files to clean")))) (info "\033[KNo elc files to clean"))))
t)) t))

View file

@ -1,5 +1,7 @@
;;; core/cli/debug.el -*- lexical-binding: t; -*- ;;; core/cli/debug.el -*- lexical-binding: t; -*-
(load! "autoload/debug" doom-core-dir)
;; ;;
;;; Commands ;;; Commands
@ -24,6 +26,5 @@
(defcli! (version v) () (defcli! (version v) ()
"Show version information for Doom & Emacs." "Show version information for Doom & Emacs."
:bare t
(doom/version) (doom/version)
nil) nil)

View file

@ -81,7 +81,6 @@ in."
(print-group! (print-group!
(let ((doom-interactive-mode 'doctor)) (let ((doom-interactive-mode 'doctor))
(doom-initialize 'force) (doom-initialize 'force)
(doom-initialize-core)
(doom-initialize-modules)) (doom-initialize-modules))
(print! (success "Initialized Doom Emacs %s") doom-version) (print! (success "Initialized Doom Emacs %s") doom-version)

View file

@ -1,7 +1,8 @@
;;; core/cli/env.el -*- lexical-binding: t; -*- ;;; core/cli/env.el -*- lexical-binding: t; -*-
(defcli! env (defcli! env
((clear-p ["-c" "--clear"] "Clear and delete your envvar file") ((allow ["-a" "--allow"] "An envvar whitelist regexp")
(clear-p ["-c" "--clear"] "Clear and delete your envvar file")
(outputfile ["-o" PATH] (outputfile ["-o" PATH]
"Generate the envvar file at PATH. Envvar files that aren't in "Generate the envvar file at PATH. Envvar files that aren't in
`doom-env-file' won't be loaded automatically at startup. You will need to load `doom-env-file' won't be loaded automatically at startup. You will need to load
@ -58,35 +59,25 @@ Why this over exec-path-from-shell?
(defvar doom-env-ignored-vars (defvar doom-env-ignored-vars
'("^DBUS_SESSION_BUS_ADDRESS$" '("^DBUS_SESSION_BUS_ADDRESS$"
"^GPG_AGENT_INFO$" "^GPG_AGENT_INFO$" "^\\(SSH\\|GPG\\)_TTY$"
"^\\(SSH\\|GPG\\)_TTY$" "^SSH_\\(AUTH_SOCK\\|AGENT_PID\\)$"
"^HOME$" "^HOME$" "^PWD$" "^PS1$" "^R?PROMPT$" "^TERM$"
"^PS1$"
"^PWD$"
"^R?PROMPT$"
"^SSH_AGENT_PID$"
"^SSH_AUTH_SOCK$"
"^TERM$"
;; Doom envvars ;; Doom envvars
"^DEBUG$" "^DEBUG$" "^INSECURE$" "^YES$" "^__")
"^INSECURE$"
"^YES$"
"^__")
"Environment variables to not save in `doom-env-file'. "Environment variables to not save in `doom-env-file'.
Each string is a regexp, matched against variable names to omit from Each string is a regexp, matched against variable names to omit from
`doom-env-file'.") `doom-env-file'.")
(defun doom-cli-reload-env-file (&optional force-p env-file) (defun doom-cli-reload-env-file (&optional force-p env-file whitelist)
"Generates `doom-env-file', if it doesn't exist (or if FORCE-P). "Generates `doom-env-file', if it doesn't exist (or if FORCE-P).
This scrapes the variables from your shell environment by running This scrapes the variables from your shell environment by running
`doom-env-executable' through `shell-file-name' with `doom-env-switches'. By `doom-env-executable' through `shell-file-name' with `doom-env-switches'. By
default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in
`doom-env-ignored-vars' are removed." `doom-env-ignored-vars' are removed."
(let ((env-file (if env-file (let ((env-file (if env-file (expand-file-name env-file) doom-env-file))
(expand-file-name env-file) (process-environment doom--initial-process-environment))
doom-env-file)))
(when (or force-p (not (file-exists-p env-file))) (when (or force-p (not (file-exists-p env-file)))
(with-temp-file env-file (with-temp-file env-file
(setq-local coding-system-for-write 'utf-8) (setq-local coding-system-for-write 'utf-8)
@ -95,8 +86,6 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in
"Regenerating" "Regenerating"
"Generating") "Generating")
(path env-file)) (path env-file))
(let ((process-environment doom--initial-process-environment))
(print! (info "Scraping shell environment"))
(print-group! (print-group!
(when doom-interactive-mode (when doom-interactive-mode
(user-error "'doom env' must be run on the command line, not an interactive session")) (user-error "'doom env' must be run on the command line, not an interactive session"))
@ -123,10 +112,12 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in
;; user's interactive shell, therefore we just dump ;; user's interactive shell, therefore we just dump
;; `process-environment' to a file. ;; `process-environment' to a file.
(dolist (env process-environment) (dolist (env process-environment)
(if (cl-find-if (doom-rpartial #'string-match-p (car (split-string env "="))) (if (and (cl-find-if (doom-rpartial #'string-match-p (car (split-string env "=")))
doom-env-ignored-vars) doom-env-ignored-vars)
(not (cl-find-if (doom-rpartial #'string-match-p (car (split-string env "=")))
whitelist)))
(print! (info "Ignoring %s") env) (print! (info "Ignoring %s") env)
(insert env "\0\n"))) (insert env "\0\n")))
(print! (success "Successfully generated %S") (print! (success "Successfully generated %S")
(path env-file)) (path env-file))
t)))))) t)))))

View file

@ -24,7 +24,6 @@ DOOMDIR environment variable. e.g.
doom -p ~/.config/doom install doom -p ~/.config/doom install
DOOMDIR=~/.config/doom doom install" DOOMDIR=~/.config/doom doom install"
:bare t
(print! (green "Installing Doom Emacs!\n")) (print! (green "Installing Doom Emacs!\n"))
(let ((default-directory (doom-path "~"))) (let ((default-directory (doom-path "~")))
;; Create `doom-private-dir' ;; Create `doom-private-dir'
@ -59,8 +58,7 @@ DOOMDIR environment variable. e.g.
;; In case no init.el was present the first time `doom-initialize-modules' was ;; In case no init.el was present the first time `doom-initialize-modules' was
;; called in core.el (e.g. on first install) ;; called in core.el (e.g. on first install)
(doom-initialize 'force 'noerror) (doom-initialize-modules 'force)
(doom-initialize-modules)
;; Ask if user would like an envvar file generated ;; Ask if user would like an envvar file generated
(if noenv-p (if noenv-p
@ -102,5 +100,5 @@ DOOMDIR environment variable. e.g.
(print! (success "\nFinished! Doom is ready to go!\n")) (print! (success "\nFinished! Doom is ready to go!\n"))
(with-temp-buffer (with-temp-buffer
(doom-template-insert "QUICKSTART_INTRO") (insert (doom-glob doom-core-dir "templates/QUICKSTART_INTRO"))
(print! (buffer-string))))) (print! "%s" (buffer-string)))))

View file

@ -74,23 +74,77 @@ list remains lean."
"-n" "25" end-ref (concat "^" (regexp-quote start-ref))) "-n" "25" end-ref (concat "^" (regexp-quote start-ref)))
(straight--process-get-output))) (straight--process-get-output)))
(defun doom--barf-if-incomplete-packages ()
(let ((straight-safe-mode t))
(condition-case _ (straight-check-all)
(error (user-error "Package state is incomplete. Run 'doom sync' first")))))
(defmacro doom--with-package-recipes (recipes binds &rest body)
(declare (indent 2))
(let ((recipe-var (make-symbol "recipe"))
(recipes-var (make-symbol "recipes")))
`(let* ((,recipes-var ,recipes)
(built ())
(straight-use-package-pre-build-functions
(cons (lambda (pkg &rest _) (cl-pushnew pkg built :test #'equal))
straight-use-package-pre-build-functions)))
(dolist (,recipe-var ,recipes-var (nreverse built))
(cl-block nil
(straight--with-plist (append (list :recipe ,recipe-var) ,recipe-var)
,(doom-enlist binds)
,@body))))))
(defvar doom--cli-updated-recipes nil)
(defun doom--cli-recipes-update ()
"Updates straight and recipe repos."
(unless doom--cli-updated-recipes
(straight--make-build-cache-available)
(print! (start "Updating recipe repos..."))
(print-group!
(doom--with-package-recipes
(delq
nil (mapcar (doom-rpartial #'gethash straight--repo-cache)
(mapcar #'symbol-name straight-recipe-repositories)))
(recipe package type local-repo)
(let ((esc (unless doom-debug-mode "\033[1A"))
(ref (straight-vc-get-commit type local-repo))
newref)
(print! (start "\033[KUpdating recipes for %s...%s") package esc)
(when (straight-vc-fetch-from-remote recipe)
(setq output (straight--process-get-output))
(straight-merge-package package)
(or (equal ref (setq newref (straight-vc-get-commit type local-repo)))
(print! (success "\033[K%s updated (%s -> %s)")
package
(doom--abbrev-commit ref)
(doom--abbrev-commit newref)))))))
(setq straight--recipe-lookup-cache (make-hash-table :test #'eq)
doom--cli-updated-recipes t)))
(defun doom-cli-packages-install () (defun doom-cli-packages-install ()
"Installs missing packages. "Installs missing packages.
This function will install any primary package (i.e. a package with a `package!' This function will install any primary package (i.e. a package with a `package!'
declaration) or dependency thereof that hasn't already been." declaration) or dependency thereof that hasn't already been."
(straight--transaction-finalize) (doom-initialize-packages)
(print! (start "Installing packages...")) (print! (start "Installing packages..."))
(let ((pinned (doom-package-pinned-list))) (let ((pinned (doom-package-pinned-list)))
(print-group! (print-group!
(if-let (built (if-let (built
(doom-with-package-recipes (doom-package-recipe-list) (doom--with-package-recipes (doom-package-recipe-list)
(recipe package type local-repo) (recipe package type local-repo)
(unless (file-directory-p (straight--repos-dir local-repo))
(doom--cli-recipes-update))
(condition-case-unless-debug e (condition-case-unless-debug e
(straight-use-package (intern package)) (let ((straight-use-package-pre-build-functions
(cons (lambda (pkg &rest _)
(when-let (commit (cdr (assoc pkg pinned)))
(print! (info "Checked out %s") commit)))
straight-use-package-pre-build-functions)))
(straight-use-package (intern package)))
(error (error
(signal 'doom-package-error (signal 'doom-package-error (list package e))))))
(list package e (straight--process-get-output)))))))
(print! (success "Installed %d packages") (print! (success "Installed %d packages")
(length built)) (length built))
(print! (info "No packages need to be installed")) (print! (info "No packages need to be installed"))
@ -99,7 +153,7 @@ declaration) or dependency thereof that hasn't already been."
(defun doom-cli-packages-build (&optional force-p) (defun doom-cli-packages-build (&optional force-p)
"(Re)build all packages." "(Re)build all packages."
(straight--transaction-finalize) (doom-initialize-packages)
(print! (start "(Re)building %spackages...") (if force-p "all " "")) (print! (start "(Re)building %spackages...") (if force-p "all " ""))
(print-group! (print-group!
(let ((straight-check-for-modifications (let ((straight-check-for-modifications
@ -118,7 +172,7 @@ declaration) or dependency thereof that hasn't already been."
(unless force-p (unless force-p
(straight--make-build-cache-available)) (straight--make-build-cache-available))
(if-let (built (if-let (built
(doom-with-package-recipes recipes (package local-repo) (doom--with-package-recipes recipes (package local-repo)
(unless force-p (unless force-p
;; Ensure packages with outdated files/bytecode are rebuilt ;; Ensure packages with outdated files/bytecode are rebuilt
(let ((build-dir (straight--build-dir package)) (let ((build-dir (straight--build-dir package))
@ -143,18 +197,21 @@ declaration) or dependency thereof that hasn't already been."
(defun doom-cli-packages-update () (defun doom-cli-packages-update ()
"Updates packages." "Updates packages."
(straight--transaction-finalize) (doom-initialize-packages)
(print! (start "Updating packages (this may take a while)...")) (doom--barf-if-incomplete-packages)
(let* ((repo-dir (straight--repos-dir)) (let* ((repo-dir (straight--repos-dir))
(pinned (doom-package-pinned-list)) (pinned (doom-package-pinned-list))
(recipes (doom-package-recipe-list))
(packages-to-rebuild (make-hash-table :test 'equal)) (packages-to-rebuild (make-hash-table :test 'equal))
(repos-to-rebuild (make-hash-table :test 'equal)) (repos-to-rebuild (make-hash-table :test 'equal))
(recipes (doom-package-recipe-list))
(total (length recipes)) (total (length recipes))
(esc (unless doom-debug-mode "\033[1A")) (esc (unless doom-debug-mode "\033[1A"))
(i 0) (i 0)
errors) errors)
(doom-with-package-recipes recipes (recipe package type local-repo) (when recipes
(doom--cli-recipes-update))
(print! (start "Updating packages (this may take a while)..."))
(doom--with-package-recipes recipes (recipe package type local-repo)
(cl-incf i) (cl-incf i)
(print-group! (print-group!
(unless (straight--repository-is-available-p recipe) (unless (straight--repository-is-available-p recipe)
@ -173,7 +230,9 @@ declaration) or dependency thereof that hasn't already been."
(error "%S is not a valid repository" package))) (error "%S is not a valid repository" package)))
(condition-case-unless-debug e (condition-case-unless-debug e
(let ((ref (straight-vc-get-commit type local-repo)) (let ((ref (straight-vc-get-commit type local-repo))
(target-ref (cdr (assoc local-repo pinned))) (target-ref
(cdr (or (assoc local-repo pinned)
(assoc package pinned))))
output) output)
(or (cond (or (cond
((not (stringp target-ref)) ((not (stringp target-ref))
@ -201,9 +260,9 @@ declaration) or dependency thereof that hasn't already been."
(doom--same-commit-p target-ref (straight-vc-get-commit type local-repo))) (doom--same-commit-p target-ref (straight-vc-get-commit type local-repo)))
((print! (start "\033[K(%d/%d) Re-cloning %s...") i total local-repo esc) ((print! (start "\033[K(%d/%d) Re-cloning %s...") i total local-repo esc)
(let ((repo (straight--repos-dir local-repo))) (let ((repo (straight--repos-dir local-repo))
(ignore-errors (straight-vc-git-default-clone-depth 'full))
(delete-directory repo 'recursive)) (delete-directory repo 'recursive)
(print-group! (print-group!
(straight-use-package (intern package) nil 'no-build)) (straight-use-package (intern package) nil 'no-build))
(prog1 (file-directory-p repo) (prog1 (file-directory-p repo)
@ -219,7 +278,7 @@ declaration) or dependency thereof that hasn't already been."
(puthash package t packages-to-rebuild) (puthash package t packages-to-rebuild)
(unless (string-empty-p output) (unless (string-empty-p output)
(print! (start "\033[K(%d/%d) Updating %s...") i total local-repo) (print! (start "\033[K(%d/%d) Updating %s...") i total local-repo)
(print-group! (print! (indent 2 output)))) (print-group! (print! "%s" (indent 2 output))))
(print! (success "\033[K(%d/%d) %s updated (%s -> %s)") (print! (success "\033[K(%d/%d) %s updated (%s -> %s)")
i total local-repo i total local-repo
(doom--abbrev-commit ref) (doom--abbrev-commit ref)
@ -227,24 +286,19 @@ declaration) or dependency thereof that hasn't already been."
(user-error (user-error
(signal 'user-error (error-message-string e))) (signal 'user-error (error-message-string e)))
(error (error
(print! (warn "\033[K(%d/%d) Encountered error with %s" i total package)) (signal 'doom-package-error (list package e)))))))
(print-group! (print-group!
(print! (error "%s") e)
(print-group! (print! (info "%s" (straight--process-get-output)))))
(push package errors))))))
(princ "\033[K") (princ "\033[K")
(when errors
(print! (error "Encountered %d error(s), the offending packages: %s")
(length errors) (string-join errors ", ")))
(if (hash-table-empty-p packages-to-rebuild) (if (hash-table-empty-p packages-to-rebuild)
(ignore (print! (success "All %d packages are up-to-date") total)) (ignore (print! (success "All %d packages are up-to-date") total))
(straight--transaction-finalize)
(let ((default-directory (straight--build-dir))) (let ((default-directory (straight--build-dir)))
(mapc (doom-rpartial #'delete-directory 'recursive) (mapc (doom-rpartial #'delete-directory 'recursive)
(hash-table-keys packages-to-rebuild))) (hash-table-keys packages-to-rebuild)))
(print! (success "Updated %d package(s)") (print! (success "Updated %d package(s)")
(hash-table-count packages-to-rebuild)) (hash-table-count packages-to-rebuild))
(doom-cli-packages-build) (doom-cli-packages-build)
t))) t))))
;;; PURGE (for the emperor) ;;; PURGE (for the emperor)
@ -258,8 +312,8 @@ declaration) or dependency thereof that hasn't already been."
(defun doom--cli-packages-purge-builds (builds) (defun doom--cli-packages-purge-builds (builds)
(if (not builds) (if (not builds)
(progn (print! (info "No builds to purge")) (prog1 0
0) (print! (info "No builds to purge")))
(print! (start "Purging straight builds..." (length builds))) (print! (start "Purging straight builds..." (length builds)))
(print-group! (print-group!
(length (length
@ -287,8 +341,8 @@ declaration) or dependency thereof that hasn't already been."
(defun doom--cli-packages-regraft-repos (repos) (defun doom--cli-packages-regraft-repos (repos)
(if (not repos) (if (not repos)
(progn (print! (info "No repos to regraft")) (prog1 0
0) (print! (info "No repos to regraft")))
(print! (start "Regrafting %d repos..." (length repos))) (print! (start "Regrafting %d repos..." (length repos)))
(let ((before-size (doom-directory-size (straight--repos-dir)))) (let ((before-size (doom-directory-size (straight--repos-dir))))
(print-group! (print-group!
@ -302,8 +356,7 @@ declaration) or dependency thereof that hasn't already been."
(defun doom--cli-packages-purge-repo (repo) (defun doom--cli-packages-purge-repo (repo)
(let ((repo-dir (straight--repos-dir repo))) (let ((repo-dir (straight--repos-dir repo)))
(delete-directory repo-dir 'recursive) (delete-directory repo-dir 'recursive)
(ignore-errors (delete-file (straight--modified-file repo))
(delete-file (straight--modified-file repo)))
(if (file-directory-p repo-dir) (if (file-directory-p repo-dir)
(ignore (print! (error "Failed to purge repos/%s" repo))) (ignore (print! (error "Failed to purge repos/%s" repo)))
(print! (success "Purged repos/%s" repo)) (print! (success "Purged repos/%s" repo))
@ -311,8 +364,8 @@ declaration) or dependency thereof that hasn't already been."
(defun doom--cli-packages-purge-repos (repos) (defun doom--cli-packages-purge-repos (repos)
(if (not repos) (if (not repos)
(progn (print! (info "No repos to purge")) (prog1 0
0) (print! (info "No repos to purge")))
(print! (start "Purging straight repositories...")) (print! (start "Purging straight repositories..."))
(print-group! (print-group!
(length (length
@ -322,8 +375,8 @@ declaration) or dependency thereof that hasn't already been."
(require 'core-packages) (require 'core-packages)
(let ((dirs (doom-files-in package-user-dir :type t :depth 0))) (let ((dirs (doom-files-in package-user-dir :type t :depth 0)))
(if (not dirs) (if (not dirs)
(progn (print! (info "No ELPA packages to purge")) (prog1 0
0) (print! (info "No ELPA packages to purge")))
(print! (start "Purging ELPA packages...")) (print! (start "Purging ELPA packages..."))
(dolist (path dirs (length dirs)) (dolist (path dirs (length dirs))
(condition-case e (condition-case e
@ -346,15 +399,17 @@ a `package!' declaration) or isn't depended on by another primary package.
If BUILDS-P, include straight package builds. If BUILDS-P, include straight package builds.
If REPOS-P, include straight repos. If REPOS-P, include straight repos.
If ELPA-P, include packages installed with package.el (M-x package-install)." If ELPA-P, include packages installed with package.el (M-x package-install)."
(doom-initialize-packages)
(doom--barf-if-incomplete-packages)
(print! (start "Purging orphaned packages (for the emperor)...")) (print! (start "Purging orphaned packages (for the emperor)..."))
(cl-destructuring-bind (&optional builds-to-purge repos-to-purge repos-to-regraft) (cl-destructuring-bind (&optional builds-to-purge repos-to-purge repos-to-regraft)
(let ((rdirs (straight--directory-files (straight--repos-dir) nil nil 'sort)) (let ((rdirs (straight--directory-files (straight--repos-dir) nil nil 'sort))
(bdirs (straight--directory-files (straight--build-dir) nil nil 'sort))) (bdirs (straight--directory-files (straight--build-dir) nil nil 'sort)))
(list (cl-remove-if (doom-rpartial #'gethash straight--profile-cache) (list (seq-remove (doom-rpartial #'gethash straight--profile-cache)
bdirs) bdirs)
(cl-remove-if (doom-rpartial #'straight--checkhash straight--repo-cache) (seq-remove (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs) rdirs)
(cl-remove-if-not (doom-rpartial #'straight--checkhash straight--repo-cache) (seq-filter (doom-rpartial #'straight--checkhash straight--repo-cache)
rdirs))) rdirs)))
(let (success) (let (success)
(print-group! (print-group!

View file

@ -19,7 +19,7 @@ following shell commands:
nil (list nil (list
(unless packages-only-p (unless packages-only-p
(doom-cli-upgrade doom-auto-accept doom-auto-discard)) (doom-cli-upgrade doom-auto-accept doom-auto-discard))
(doom-cli-execute "refresh") (doom-cli-execute "sync")
(when (doom-cli-packages-update) (when (doom-cli-packages-update)
(doom-cli-reload-package-autoloads) (doom-cli-reload-package-autoloads)
t))) t)))
@ -110,6 +110,23 @@ following shell commands:
(equal (vc-git--rev-parse "HEAD") new-rev)) (equal (vc-git--rev-parse "HEAD") new-rev))
(print! (info "%s") (cdr result)) (print! (info "%s") (cdr result))
(error "Failed to check out %s" (substring new-rev 0 10))) (error "Failed to check out %s" (substring new-rev 0 10)))
;; Reload Doom's CLI & libraries, in case there were any
;; upstream changes. Major changes will still break, however
(condition-case e
(progn
(mapc (doom-rpartial #'unload-feature t)
'(core core-lib
core-cli
core-modules
core-packages))
(require 'core)
(setq doom-init-p nil
doom-init-modules-p nil)
(doom-initialize))
(error
(signal 'doom-error (list "Could not upgrade Doom without issues"))))
(print! (success "Finished upgrading Doom Emacs"))) (print! (success "Finished upgrading Doom Emacs")))
t))))) t)))))
(ignore-errors (ignore-errors

View file

@ -1,5 +1,24 @@
;;; -*- lexical-binding: t; no-byte-compile: t; -*- ;;; -*- lexical-binding: t; no-byte-compile: t; -*-
(require 'seq)
(load! "autoload/process")
(load! "autoload/plist")
(load! "autoload/files")
(load! "autoload/format")
;; Create all our core directories to quell file errors
(mapc (doom-rpartial #'make-directory 'parents)
(list doom-local-dir
doom-etc-dir
doom-cache-dir))
;; Ensure straight and the bare minimum is ready to go
(require 'core-modules)
(require 'core-packages)
(doom-initialize-core-packages)
;; ;;
;;; Variables ;;; Variables
@ -11,7 +30,6 @@ commands like `doom-cli-packages-install', `doom-cli-packages-update' and
(defvar doom-auto-discard (getenv "FORCE") (defvar doom-auto-discard (getenv "FORCE")
"If non-nil, discard all local changes while updating.") "If non-nil, discard all local changes while updating.")
(defvar doom--cli-p nil)
(defvar doom--cli-commands (make-hash-table :test 'equal)) (defvar doom--cli-commands (make-hash-table :test 'equal))
(defvar doom--cli-groups (make-hash-table :test 'equal)) (defvar doom--cli-groups (make-hash-table :test 'equal))
(defvar doom--cli-group nil) (defvar doom--cli-group nil)
@ -54,7 +72,8 @@ commands like `doom-cli-packages-install', `doom-cli-packages-update' and
(defun doom--cli-process (cli args) (defun doom--cli-process (cli args)
(let* ((args (copy-sequence args)) (let* ((args (copy-sequence args))
(arglist (copy-sequence (doom-cli-arglist cli))) (arglist (copy-sequence (doom-cli-arglist cli)))
(expected (or (cl-position-if (doom-rpartial #'memq cl--lambda-list-keywords) (expected
(or (cl-position-if (doom-rpartial #'memq cl--lambda-list-keywords)
arglist) arglist)
(length arglist))) (length arglist)))
(got 0) (got 0)
@ -137,7 +156,7 @@ Executes a cli defined with `defcli!' with the name or alias specified by
COMMAND, and passes ARGS to it." COMMAND, and passes ARGS to it."
(if-let (cli (doom-cli-get command)) (if-let (cli (doom-cli-get command))
(funcall (doom-cli-fn cli) (funcall (doom-cli-fn cli)
(doom--cli-process cli args)) (doom--cli-process cli (remq nil args)))
(user-error "Couldn't find any %S command" command))) (user-error "Couldn't find any %S command" command)))
(defmacro defcli! (name speclist &optional docstring &rest body) (defmacro defcli! (name speclist &optional docstring &rest body)
@ -186,10 +205,6 @@ BODY will be run when this dispatcher is called."
for optsym = (if (listp opt) (car opt) opt) for optsym = (if (listp opt) (car opt) opt)
unless (memq optsym cl--lambda-list-keywords) unless (memq optsym cl--lambda-list-keywords)
collect (list optsym `(cdr (assq ',optsym --alist--)))) collect (list optsym `(cdr (assq ',optsym --alist--))))
,@(unless (plist-get plist :bare)
'((unless doom-init-p
(doom-initialize 'force 'noerror)
(doom-initialize-modules))))
,@body))) ,@body)))
doom--cli-commands) doom--cli-commands)
(when aliases (when aliases
@ -208,10 +223,25 @@ BODY will be run when this dispatcher is called."
;;; Straight hacks ;;; Straight hacks
(defvar doom--cli-straight-discard-options (defvar doom--cli-straight-discard-options
'("^Delete remote \"[^\"]+\", re-create it with correct " '((" has diverged from branch "
"^Reset branch " . "^Reset [^ ]+ to branch")
"^Abort merge$" (" but recipe specifies a URL of "
"^Discard changes$")) . "^Delete remote \"[^\"]+\", re-create it with correct ")
(" has a merge conflict:"
. "^Abort merge$")
(" has a dirty worktree:"
. "^Discard changes$")
("^In repository "
. "^Reset branch "))
"A list of regexps, mapped to regexps.
Their CAR is tested against the prompt, and CDR is tested against the presented
option, and is used by `straight-vc-git--popup-raw' to select which option to
recommend.
It may not be obvious to users what they should do for some straight prompts,
so Doom will recommend the one that reverts a package back to its (or target)
original state.")
;; HACK Remove dired & magit options from prompt, since they're inaccessible in ;; HACK Remove dired & magit options from prompt, since they're inaccessible in
;; noninteractive sessions. ;; noninteractive sessions.
@ -222,15 +252,21 @@ BODY will be run when this dispatcher is called."
(defadvice! doom--straight-fallback-to-y-or-n-prompt-a (orig-fn &optional prompt) (defadvice! doom--straight-fallback-to-y-or-n-prompt-a (orig-fn &optional prompt)
:around #'straight-are-you-sure :around #'straight-are-you-sure
(or doom-auto-accept (or doom-auto-accept
(if noninteractive (if doom-interactive-mode
(y-or-n-p (format! "%s" (or prompt ""))) (funcall orig-fn prompt)
(funcall orig-fn prompt)))) (y-or-n-p (format! "%s" (or prompt ""))))))
(defun doom--straight-recommended-option-p (prompt option)
(cl-loop for (prompt-re . opt-re) in doom--cli-straight-discard-options
if (string-match-p prompt-re prompt)
return (string-match-p opt-re option)))
(defadvice! doom--straight-fallback-to-tty-prompt-a (orig-fn prompt actions) (defadvice! doom--straight-fallback-to-tty-prompt-a (orig-fn prompt actions)
"Modifies straight to prompt on the terminal when in noninteractive sessions." "Modifies straight to prompt on the terminal when in noninteractive sessions."
:around #'straight--popup-raw :around #'straight--popup-raw
(if (not noninteractive) (if doom-interactive-mode
(funcall orig-fn prompt actions) (funcall orig-fn prompt actions)
(let ((doom--cli-straight-discard-options doom--cli-straight-discard-options))
;; We can't intercept C-g, so no point displaying any options for this key ;; We can't intercept C-g, so no point displaying any options for this key
;; when C-c is the proper way to abort batch Emacs. ;; when C-c is the proper way to abort batch Emacs.
(delq! "C-g" actions 'assoc) (delq! "C-g" actions 'assoc)
@ -242,8 +278,7 @@ BODY will be run when this dispatcher is called."
(cl-loop with doom-auto-accept = t (cl-loop with doom-auto-accept = t
for (_key desc func) in actions for (_key desc func) in actions
when desc when desc
when (cl-find-if (doom-rpartial #'string-match-p desc) when (doom--straight-recommended-option-p prompt desc)
doom--cli-straight-discard-options)
return (funcall func)) return (funcall func))
(print! (start "%s") (red prompt)) (print! (start "%s") (red prompt))
(print-group! (print-group!
@ -256,9 +291,10 @@ BODY will be run when this dispatcher is called."
do (push func options) do (push func options)
and do and do
(print! "%2s) %s" (1+ (length options)) (print! "%2s) %s" (1+ (length options))
(if (cl-find-if (doom-rpartial #'string-match-p desc) (if (doom--straight-recommended-option-p prompt desc)
doom--cli-straight-discard-options) (progn
(green (concat desc " (Recommended)")) (setq doom--cli-straight-discard-options nil)
(green (concat desc " (Recommended)")))
desc)))) desc))))
(terpri) (terpri)
(let* ((options (let* ((options
@ -278,7 +314,7 @@ BODY will be run when this dispatcher is called."
options)) options))
(print! (warn "%s is not a valid answer, try again.") (print! (warn "%s is not a valid answer, try again.")
answer)) answer))
(funcall (nth answer options)))))))) (funcall (nth answer options)))))))))
(defadvice! doom--straight-respect-print-indent-a (args) (defadvice! doom--straight-respect-print-indent-a (args)
"Indent straight progress messages to respect `doom-format-indent', so we "Indent straight progress messages to respect `doom-format-indent', so we
@ -297,32 +333,16 @@ everywhere we use it (and internally)."
interactive))) interactive)))
;;
;;; Dependencies
(require 'seq)
;; Eagerly load these libraries because we may be in a session that hasn't been
;; fully initialized (e.g. where autoloads files haven't been generated or
;; `load-path' populated).
(load! "autoload/cli")
(load! "autoload/debug")
(load! "autoload/files")
(load! "autoload/format")
(load! "autoload/plist")
;; ;;
;;; CLI Commands ;;; CLI Commands
(load! "cli/help") (load! "cli/help")
(load! "cli/install") (load! "cli/install")
(defcligroup! "Maintenance"
"For managing your config and packages"
(defcli! (sync s refresh re) (defcli! (sync s refresh re)
((if-necessary-p ["-n" "--if-necessary"] "Only regenerate autoloads files if necessary") ((inhibit-envvar-p ["-e"] "Don't regenerate the envvar file")
(inhibit-envvar-p ["-e"] "Don't regenerate the envvar file") (inhibit-elc-p ["-c"] "Don't recompile config")
(update-p ["-u"] "...")
(prune-p ["-p" "--prune"] "Purge orphaned packages & regraft repos")) (prune-p ["-p" "--prune"] "Purge orphaned packages & regraft repos"))
"Synchronize your config with Doom Emacs. "Synchronize your config with Doom Emacs.
@ -337,48 +357,44 @@ recompile. Run this whenever you:
It will ensure that unneeded packages are removed, all needed packages are It will ensure that unneeded packages are removed, all needed packages are
installed, autoloads files are up-to-date and no byte-compiled files have gone installed, autoloads files are up-to-date and no byte-compiled files have gone
stale." stale."
:bare t
(let (success)
;; Ensures that no pre-existing state pollutes the generation of the new
;; autoloads files.
(dolist (file (list doom-autoload-file doom-package-autoload-file))
(delete-file file)
(delete-file (byte-compile-dest-file file)))
(doom-initialize 'force 'noerror)
(doom-initialize-modules)
(print! (start "Synchronizing your config with Doom Emacs...")) (print! (start "Synchronizing your config with Doom Emacs..."))
(print-group! (print-group!
(when (and (not inhibit-envvar-p) (and (not inhibit-envvar-p)
(file-exists-p doom-env-file)) (file-exists-p doom-env-file)
(doom-cli-reload-env-file 'force)) (doom-cli-reload-env-file 'force))
(doom-cli-reload-core-autoloads) (doom-cli-reload-core-autoloads)
(doom-cli-packages-install) (doom-cli-packages-install)
(doom-cli-packages-build) (doom-cli-packages-build)
(when update-p
(doom-cli-packages-update))
(doom-cli-packages-purge prune-p 'builds-p prune-p prune-p) (doom-cli-packages-purge prune-p 'builds-p prune-p prune-p)
(doom-cli-reload-package-autoloads) (doom-cli-reload-package-autoloads)
t))) t))
(load! "cli/env") (load! "cli/env")
(load! "cli/upgrade") (load! "cli/upgrade")
(load! "cli/packages") (load! "cli/packages")
(load! "cli/autoloads")) (load! "cli/autoloads")
(defcligroup! "Diagnostics" (defcligroup! "Diagnostics"
"For troubleshooting and diagnostics" "For troubleshooting and diagnostics"
(load! "cli/doctor") (load! "cli/doctor")
(load! "cli/debug") (load! "cli/debug")
(load! "cli/test"))
;; Our tests are broken at the moment. Working on fixing them, but for now we
;; disable them:
;; (load! "cli/test")
)
(defcligroup! "Compilation" (defcligroup! "Compilation"
"For compiling Doom and your config" "For compiling Doom and your config"
(load! "cli/byte-compile")) (load! "cli/byte-compile"))
(defcligroup! "Utilities" (defcligroup! "Utilities"
"Conveniences for interacting with Doom externally" "Conveniences for interacting with Doom externally"
(defcli! run () (defcli! run (&rest args)
"Run Doom Emacs from bin/doom's parent directory. "Run Doom Emacs from bin/doom's parent directory.
All arguments are passed on to Emacs. All arguments are passed on to Emacs.
@ -388,11 +404,16 @@ All arguments are passed on to Emacs.
WARNING: this command exists for convenience and testing. Doom will suffer WARNING: this command exists for convenience and testing. Doom will suffer
additional overhead by being started this way. For the best performance, it is additional overhead by being started this way. For the best performance, it is
best to run Doom out of ~/.emacs.d and ~/.doom.d.") best to run Doom out of ~/.emacs.d and ~/.doom.d."))
;; (load! "cli/batch")
;; (load! "cli/org") ;;
) ;;; Load user config
(condition-case-unless-debug e
(load! "init" doom-private-dir t)
(error
(signal 'doom-private-error (list "init.el" e))))
(provide 'core-cli) (provide 'core-cli)
;;; core-cli.el ends here ;;; core-cli.el ends here

View file

@ -79,8 +79,8 @@ possible."
t)))))) t))))))
;; Don't autosave files or create lock/history/backup files. We don't want ;; Don't autosave files or create lock/history/backup files. We don't want
;; copies of potentially sensitive material floating around, and we'll rely on ;; copies of potentially sensitive material floating around or polluting our
;; git and our own good fortune instead. Fingers crossed! ;; filesystem. We rely on git and our own good fortune instead. Fingers crossed!
(setq auto-save-default nil (setq auto-save-default nil
create-lockfiles nil create-lockfiles nil
make-backup-files nil make-backup-files nil
@ -216,7 +216,7 @@ possible."
(use-package! recentf (use-package! recentf
;; Keep track of recently opened files ;; Keep track of recently opened files
:defer-incrementally easymenu tree-widget timer :defer-incrementally easymenu tree-widget timer
:after-call after-find-file :hook (doom-first-file . recentf-mode)
:commands recentf-open-files :commands recentf-open-files
:config :config
(defun doom--recent-file-truename (file) (defun doom--recent-file-truename (file)
@ -246,22 +246,20 @@ possible."
"Add dired directory to recentf file list." "Add dired directory to recentf file list."
(recentf-add-file default-directory))) (recentf-add-file default-directory)))
(when doom-interactive-mode
(add-hook 'kill-emacs-hook #'recentf-cleanup) (add-hook 'kill-emacs-hook #'recentf-cleanup)
(quiet! (recentf-mode +1)))) (advice-add #'recentf-load-list :around #'doom-shut-up-a))
(use-package! savehist (use-package! savehist
;; persist variables across sessions ;; persist variables across sessions
:defer-incrementally custom :defer-incrementally custom
:after-call post-command-hook :hook (doom-first-input . savehist-mode)
:init
(setq savehist-file (concat doom-cache-dir "savehist"))
:config :config
(setq savehist-file (concat doom-cache-dir "savehist") (setq savehist-save-minibuffer-history t
savehist-save-minibuffer-history t
savehist-autosave-interval nil ; save on kill only savehist-autosave-interval nil ; save on kill only
savehist-additional-variables '(kill-ring search-ring regexp-search-ring)) savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
(savehist-mode +1)
(add-hook! 'kill-emacs-hook (add-hook! 'kill-emacs-hook
(defun doom-unpropertize-kill-ring-h () (defun doom-unpropertize-kill-ring-h ()
"Remove text properties from `kill-ring' for a smaller savehist file." "Remove text properties from `kill-ring' for a smaller savehist file."
@ -273,11 +271,11 @@ possible."
(use-package! saveplace (use-package! saveplace
;; persistent point location in buffers ;; persistent point location in buffers
:after-call after-find-file dired-initial-position-hook :hook (doom-first-file . save-place-mode)
:config :init
(setq save-place-file (concat doom-cache-dir "saveplace") (setq save-place-file (concat doom-cache-dir "saveplace")
save-place-limit 100) save-place-limit 100)
:config
(defadvice! doom--recenter-on-load-saveplace-a (&rest _) (defadvice! doom--recenter-on-load-saveplace-a (&rest _)
"Recenter on cursor when loading a saved place." "Recenter on cursor when loading a saved place."
:after-while #'save-place-find-file-hook :after-while #'save-place-find-file-hook
@ -293,9 +291,7 @@ possible."
`pp' can be expensive for longer lists, and there's no reason to prettify cache `pp' can be expensive for longer lists, and there's no reason to prettify cache
files, so we replace calls to `pp' with the much faster `prin1'." files, so we replace calls to `pp' with the much faster `prin1'."
:around #'save-place-alist-to-file :around #'save-place-alist-to-file
(letf! ((#'pp #'prin1)) (funcall orig-fn))) (letf! ((#'pp #'prin1)) (funcall orig-fn))))
(save-place-mode +1))
(use-package! server (use-package! server
@ -314,7 +310,8 @@ files, so we replace calls to `pp' with the much faster `prin1'."
;;; Packages ;;; Packages
(use-package! better-jumper (use-package! better-jumper
:after-call pre-command-hook :hook (doom-first-input . better-jumper-mode)
:hook (better-jumper-post-jump . recenter)
:preface :preface
;; REVIEW Suppress byte-compiler warning spawning a *Compile-Log* buffer at ;; REVIEW Suppress byte-compiler warning spawning a *Compile-Log* buffer at
;; startup. This can be removed once gilbertw1/better-jumper#2 is merged. ;; startup. This can be removed once gilbertw1/better-jumper#2 is merged.
@ -324,17 +321,16 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(global-set-key [remap evil-jump-backward] #'better-jumper-jump-backward) (global-set-key [remap evil-jump-backward] #'better-jumper-jump-backward)
(global-set-key [remap xref-pop-marker-stack] #'better-jumper-jump-backward) (global-set-key [remap xref-pop-marker-stack] #'better-jumper-jump-backward)
:config :config
(better-jumper-mode +1) (advice-add #'dired-find-file :before #'doom-set-jump-maybe-a)
(add-hook 'better-jumper-post-jump-hook #'recenter)
(defadvice! doom-set-jump-a (orig-fn &rest args) (defun doom-set-jump-a (orig-fn &rest args)
"Set a jump point and ensure ORIG-FN doesn't set any new jump points." "Set a jump point and ensure ORIG-FN doesn't set any new jump points."
(better-jumper-set-jump (if (markerp (car args)) (car args))) (better-jumper-set-jump (if (markerp (car args)) (car args)))
(let ((evil--jumps-jumping t) (let ((evil--jumps-jumping t)
(better-jumper--jumping t)) (better-jumper--jumping t))
(apply orig-fn args))) (apply orig-fn args)))
(defadvice! doom-set-jump-maybe-a (orig-fn &rest args) (defun doom-set-jump-maybe-a (orig-fn &rest args)
"Set a jump point if ORIG-FN returns non-nil." "Set a jump point if ORIG-FN returns non-nil."
(let ((origin (point-marker)) (let ((origin (point-marker))
(result (result
@ -441,7 +437,7 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(use-package! smartparens (use-package! smartparens
;; Auto-close delimiters and blocks as you type. It's more powerful than that, ;; Auto-close delimiters and blocks as you type. It's more powerful than that,
;; but that is all Doom uses it for. ;; but that is all Doom uses it for.
:after-call doom-switch-buffer-hook after-find-file :hook (doom-first-buffer . smartparens-global-mode)
:commands sp-pair sp-local-pair sp-with-modes sp-point-in-comment sp-point-in-string :commands sp-pair sp-local-pair sp-with-modes sp-point-in-comment sp-point-in-string
:config :config
;; smartparens recognizes `slime-mrepl-mode', but not `sly-mrepl-mode', so... ;; smartparens recognizes `slime-mrepl-mode', but not `sly-mrepl-mode', so...
@ -501,16 +497,12 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(defun doom-disable-smartparens-mode-maybe-h () (defun doom-disable-smartparens-mode-maybe-h ()
(when smartparens-mode (when smartparens-mode
(setq-local doom-buffer-smartparens-mode t) (setq-local doom-buffer-smartparens-mode t)
(turn-off-smartparens-mode)))) (turn-off-smartparens-mode)))))
(smartparens-global-mode +1))
(use-package! so-long (use-package! so-long
:after-call after-find-file :hook (doom-first-file . global-so-long-mode)
:config :config
(when doom-interactive-mode
(global-so-long-mode +1))
(setq so-long-threshold 400) ; reduce false positives w/ larger threshold (setq so-long-threshold 400) ; reduce false positives w/ larger threshold
;; Don't disable syntax highlighting and line numbers, or make the buffer ;; Don't disable syntax highlighting and line numbers, or make the buffer
;; read-only, in `so-long-minor-mode', so we can have a basic editing ;; read-only, in `so-long-minor-mode', so we can have a basic editing
@ -530,6 +522,7 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(appendq! so-long-minor-modes (appendq! so-long-minor-modes
'(flycheck-mode '(flycheck-mode
flyspell-mode flyspell-mode
spell-fu-mode
eldoc-mode eldoc-mode
smartparens-mode smartparens-mode
highlight-numbers-mode highlight-numbers-mode
@ -560,8 +553,7 @@ files, so we replace calls to `pp' with the much faster `prin1'."
(use-package! ws-butler (use-package! ws-butler
;; a less intrusive `delete-trailing-whitespaces' on save ;; a less intrusive `delete-trailing-whitespaces' on save
:after-call after-find-file :hook (doom-first-buffer . ws-butler-global-mode))
:config (ws-butler-global-mode +1))
(provide 'core-editor) (provide 'core-editor)
;;; core-editor.el ends here ;;; core-editor.el ends here

View file

@ -179,8 +179,7 @@ localleader prefix."
;;; Packages ;;; Packages
(use-package! which-key (use-package! which-key
:defer 1 :hook (doom-first-input . which-key-mode)
:after-call pre-command-hook
:init :init
(setq which-key-sort-order #'which-key-prefix-then-key-order (setq which-key-sort-order #'which-key-prefix-then-key-order
which-key-sort-uppercase-first nil which-key-sort-uppercase-first nil
@ -195,9 +194,7 @@ localleader prefix."
(setq-hook! 'which-key-init-buffer-hook line-spacing 3) (setq-hook! 'which-key-init-buffer-hook line-spacing 3)
(which-key-add-key-based-replacements doom-leader-key "<leader>") (which-key-add-key-based-replacements doom-leader-key "<leader>")
(which-key-add-key-based-replacements doom-localleader-key "<localleader>") (which-key-add-key-based-replacements doom-localleader-key "<localleader>"))
(which-key-mode +1))
;; ;;

View file

@ -467,11 +467,19 @@ advised)."
(put ',fn 'permanent-local-hook t) (put ',fn 'permanent-local-hook t)
(add-hook sym #',fn ,append)))))) (add-hook sym #',fn ,append))))))
(defmacro add-hook-trigger! (hook-var &rest targets)
"TODO"
`(let ((fn (intern (format "%s-h" ,hook-var))))
(fset fn (lambda (&rest _) (run-hooks ,hook-var) (set ,hook-var nil)))
(put ,hook-var 'permanent-local t)
(dolist (on (list ,@targets))
(if (functionp on)
(advice-add on :before fn)
(add-hook on fn)))))
(defmacro add-hook! (hooks &rest rest) (defmacro add-hook! (hooks &rest rest)
"A convenience macro for adding N functions to M hooks. "A convenience macro for adding N functions to M hooks.
If N and M = 1, there's no benefit to using this macro over `add-hook'.
This macro accepts, in order: This macro accepts, in order:
1. The mode(s) or hook(s) to add to. This is either an unquoted mode, an 1. The mode(s) or hook(s) to add to. This is either an unquoted mode, an

View file

@ -71,6 +71,13 @@ before the user's private module.")
;; ;;
;;; Bootstrap API ;;; Bootstrap API
(defun doom-initialize-core-modules ()
"Load Doom's core files for an interactive session."
(require 'core-keybinds)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor))
(defun doom-initialize-modules (&optional force-p) (defun doom-initialize-modules (&optional force-p)
"Loads the init.el in `doom-private-dir' and sets up hooks for a healthy "Loads the init.el in `doom-private-dir' and sets up hooks for a healthy
session of Dooming. Will noop if used more than once, unless FORCE-P is session of Dooming. Will noop if used more than once, unless FORCE-P is
@ -78,8 +85,11 @@ non-nil."
(when (or force-p (not doom-init-modules-p)) (when (or force-p (not doom-init-modules-p))
(setq doom-init-modules-p t (setq doom-init-modules-p t
doom-modules nil) doom-modules nil)
(load custom-file 'noerror 'nomessage) (with-temp-buffer
(when (load! "init" doom-private-dir t) (doom-log "Initializing core modules")
(doom-initialize-core-modules)
(when-let (init-p (load! "init" doom-private-dir t))
(doom-log "Initializing user config")
(when doom-modules (when doom-modules
(maphash (lambda (key plist) (maphash (lambda (key plist)
(let ((doom--current-module key) (let ((doom--current-module key)
@ -87,7 +97,6 @@ non-nil."
(load! "init" (plist-get plist :path) t))) (load! "init" (plist-get plist :path) t)))
doom-modules)) doom-modules))
(run-hook-wrapped 'doom-before-init-modules-hook #'doom-try-run-hook) (run-hook-wrapped 'doom-before-init-modules-hook #'doom-try-run-hook)
(when doom-interactive-mode
(when doom-modules (when doom-modules
(maphash (lambda (key plist) (maphash (lambda (key plist)
(let ((doom--current-module key) (let ((doom--current-module key)
@ -95,7 +104,8 @@ non-nil."
(load! "config" (plist-get plist :path) t))) (load! "config" (plist-get plist :path) t)))
doom-modules)) doom-modules))
(run-hook-wrapped 'doom-init-modules-hook #'doom-try-run-hook) (run-hook-wrapped 'doom-init-modules-hook #'doom-try-run-hook)
(load! "config" doom-private-dir t))))) (load! "config" doom-private-dir t)
(load custom-file 'noerror (not doom-debug-mode))))))
;; ;;
@ -122,15 +132,17 @@ non-nil."
of PROPERTY and VALUEs. of PROPERTY and VALUEs.
\(fn CATEGORY MODULE PROPERTY VALUE &rest [PROPERTY VALUE [...]])" \(fn CATEGORY MODULE PROPERTY VALUE &rest [PROPERTY VALUE [...]])"
(puthash (cons category module)
(if-let (old-plist (doom-module-get category module)) (if-let (old-plist (doom-module-get category module))
(progn (if (null plist)
(when plist old-plist
(when (cl-oddp (length plist)) (when (cl-oddp (length plist))
(signal 'wrong-number-of-arguments (list (length plist)))) (signal 'wrong-number-of-arguments (list (length plist))))
(while plist (while plist
(plist-put old-plist (pop plist) (pop plist)))) (plist-put old-plist (pop plist) (pop plist)))
(puthash (cons category module) old-plist doom-modules)) old-plist)
(puthash (cons category module) plist doom-modules))) plist)
doom-modules))
(defun doom-module-set (category module &rest plist) (defun doom-module-set (category module &rest plist)
"Enables a module by adding it to `doom-modules'. "Enables a module by adding it to `doom-modules'.
@ -223,10 +235,13 @@ those directories. The first returned path is always `doom-private-dir'."
collect (plist-get plist :path))) collect (plist-get plist :path)))
nil)) nil))
(defun doom-modules (&optional refresh-p) (defun doom-module-list (&optional all-p)
"Minimally initialize `doom-modules' (a hash table) and return it. "Minimally initialize `doom-modules' (a hash table) and return it.
This value is cached. If REFRESH-P, then don't use the cached value." This value is cached. If REFRESH-P, then don't use the cached value."
(or (unless refresh-p doom-modules) (if all-p
(cl-loop for path in (cdr (doom-module-load-path 'all))
collect (doom-module-from-path path))
(or doom-modules
(let (doom-interactive-mode (let (doom-interactive-mode
doom-modules doom-modules
doom-init-modules-p) doom-init-modules-p)
@ -234,7 +249,7 @@ This value is cached. If REFRESH-P, then don't use the cached value."
(or doom-modules (or doom-modules
(make-hash-table :test 'equal (make-hash-table :test 'equal
:size 20 :size 20
:rehash-threshold 1.0))))) :rehash-threshold 1.0))))))
;; ;;

View file

@ -30,43 +30,20 @@
;; `doom-core-dir'. These contain `package!' declarations that tell DOOM what ;; `doom-core-dir'. These contain `package!' declarations that tell DOOM what
;; plugins to install and where from. ;; plugins to install and where from.
;; ;;
;; All that said, you can still use package.el's commands, but 'bin/doom ;; All that said, you can still use package.el's commands, but 'bin/doom sync'
;; refresh' will purge ELPA packages. ;; will purge ELPA packages.
(defvar doom-init-packages-p nil
"If non-nil, Doom's package management system has been initialized.")
(defvar doom-packages () (defvar doom-packages ()
"A list of enabled packages. Each element is a sublist, whose CAR is the "A list of enabled packages. Each element is a sublist, whose CAR is the
package's name as a symbol, and whose CDR is the plist supplied to its package's name as a symbol, and whose CDR is the plist supplied to its
`package!' declaration. Set by `doom-initialize-packages'.") `package!' declaration. Set by `doom-initialize-packages'.")
(defvar doom-core-packages '(straight use-package)
"A list of packages that must be installed (and will be auto-installed if
missing) and shouldn't be deleted.")
(defvar doom-core-package-sources
'((org-elpa :local-repo nil)
(melpa
:type git :host github
:repo "melpa/melpa"
:no-build t)
(gnu-elpa-mirror
:type git :host github
:repo "emacs-straight/gnu-elpa-mirror"
:no-build t)
(emacsmirror-mirror
:type git :host github
:repo "emacs-straight/emacsmirror-mirror"
:no-build t))
"A list of recipes for straight's recipe repos.")
(defvar doom-disabled-packages () (defvar doom-disabled-packages ()
"A list of packages that should be ignored by `use-package!' and `after!'.") "A list of packages that should be ignored by `use-package!' and `after!'.")
;; ;;
;;; Package managers ;;; package.el
;; Ensure that, if we do need package.el, it is configured correctly. You really ;; Ensure that, if we do need package.el, it is configured correctly. You really
;; shouldn't be using it, but it may be convenient for quick package testing. ;; shouldn't be using it, but it may be convenient for quick package testing.
@ -94,7 +71,7 @@ missing) and shouldn't be deleted.")
;;; Straight ;;; Straight
(setq straight-base-dir doom-local-dir (setq straight-base-dir doom-local-dir
straight-repository-branch "master" straight-repository-branch "develop"
straight-cache-autoloads nil ; we already do this, and better. straight-cache-autoloads nil ; we already do this, and better.
;; Doom doesn't encourage you to modify packages in place. Disabling this ;; Doom doesn't encourage you to modify packages in place. Disabling this
;; makes 'doom sync' instant (once everything set up), which is much nicer ;; makes 'doom sync' instant (once everything set up), which is much nicer
@ -123,81 +100,305 @@ missing) and shouldn't be deleted.")
;; ;;
;;; Bootstrapper ;;; Bootstrappers
(defun doom-initialize-core-packages (&optional force-p)
"Ensure `straight' is installed and was compiled with this version of Emacs."
(when (or force-p (null (bound-and-true-p straight-recipe-repositories)))
(doom-log "Initializing straight")
(cl-destructuring-bind (&key pin recipe &allow-other-keys)
(let ((doom-packages (doom-package-list nil 'core-only)))
(doom-package-get 'straight))
(let ((repo-dir (doom-path straight-base-dir "straight/repos/straight.el"))
(repo-url (concat "http" (if gnutls-verify-error "s")
"://github.com/"
(or (plist-get recipe :repo) "raxod502/straight.el")))
(branch (or (plist-get recipe :branch) straight-repository-branch))
(call (if doom-debug-mode #'doom-exec-process #'doom-call-process)))
(if (not (file-directory-p repo-dir))
(message "Installing straight...")
;; TODO Rethink this clumsy workaround
(let ((default-directory repo-dir))
(unless (equal (cdr (doom-call-process "git" "rev-parse" "HEAD")) pin)
(delete-directory repo-dir 'recursive)
(message "Updating straight..."))))
(unless (file-directory-p repo-dir)
(cond
((eq straight-vc-git-default-clone-depth 'full)
(funcall call "git" "clone" "--origin" "origin" repo-url repo-dir))
((null pin)
(funcall call "git" "clone" "--origin" "origin" repo-url repo-dir
"--depth" (number-to-string straight-vc-git-default-clone-depth)
"--branch" straight-repository-branch))
((integerp straight-vc-git-default-clone-depth)
(make-directory repo-dir t)
(let ((default-directory repo-dir))
(funcall call "git" "init")
(funcall call "git" "checkout" "-b" straight-repository-branch)
(funcall call "git" "remote" "add" "origin" repo-url)
(funcall call "git" "fetch" "origin" pin
"--depth" (number-to-string straight-vc-git-default-clone-depth))
(funcall call "git" "checkout" "--detach" pin)))))
(require 'straight (concat repo-dir "/straight.el"))
(doom-log "Initializing recipes")
(with-temp-buffer
(insert-file-contents (doom-path repo-dir "bootstrap.el"))
;; Don't install straight for us -- we've already done that -- only set
;; up its recipe repos for us.
(eval-region (search-forward "(require 'straight)")
(point-max)))))))
(defun doom-initialize-packages (&optional force-p) (defun doom-initialize-packages (&optional force-p)
"Ensures that Doom's package system and straight.el are initialized. "Process all packages, essential and otherwise, if they haven't already been.
If FORCE-P is non-nil, do it anyway. If FORCE-P is non-nil, do it anyway.
This ensure `doom-packages' is populated, if isn't aren't already. Use this This ensures `doom-packages' is populated and `straight' recipes are properly
before any of straight's or Doom's package management's API to ensure all the processed."
necessary package metadata is initialized and available for them." (doom-initialize-core-packages force-p)
(unless doom-init-packages-p
(setq force-p t))
(when (or force-p (not (bound-and-true-p package--initialized))) (when (or force-p (not (bound-and-true-p package--initialized)))
(doom-log "Initializing package.el") (doom-log "Initializing package.el")
(require 'package) (require 'package)
(package-initialize)) (package-initialize)
(when (or force-p (not doom-packages)) (unless package--initialized
(doom-log "Initializing straight") (error "Failed to initialize package.el")))
(setq doom-init-packages-p t) (when (or force-p (null doom-packages))
(doom-ensure-straight) (doom-log "Initializing straight.el")
(mapc #'straight-use-package doom-core-packages) (or (setq doom-disabled-packages nil
(doom-log "Initializing doom-packages")
(setq doom-disabled-packages nil
doom-pinned-packages nil
doom-packages (doom-package-list)) doom-packages (doom-package-list))
(error "Failed to read any packages"))
(dolist (package doom-packages) (dolist (package doom-packages)
(let ((name (car package))) (cl-destructuring-bind
(with-plist! (cdr package) (recipe modules disable ignore pin) (name &key recipe disable ignore &allow-other-keys) package
(if ignore (unless ignore
(doom-log "Ignoring package %S" name) (if disable
(if (not disable) (cl-pushnew name doom-disabled-packages)
(with-demoted-errors "Package error: %s"
(when recipe (when recipe
(straight-override-recipe (cons name recipe))) (straight-override-recipe (cons name recipe)))
(straight-register-package name)) (straight-register-package name)))))))
(doom-log "Disabling package %S" name)
(cl-pushnew name doom-disabled-packages)
;; Warn about disabled core packages
(when (cl-find :core modules :key #'car)
(print! (warn "%s\n%s")
(format "You've disabled %S" name)
(indent 2 (concat "This is a core package. Disabling it will cause errors, as Doom assumes\n"
"core packages are always available. Disable their minor-modes or hooks instead.")))))))))))
(defun doom-ensure-straight ()
"Ensure `straight' is installed and was compiled with this version of Emacs." ;;
(unless (fboundp 'straight--reset-caches) ;;; Package management API
(defvar bootstrap-version)
(let* (;; Force straight to install into ~/.emacs.d/.local/straight instead of (defun doom-package-get (package &optional prop nil-value)
;; ~/.emacs.d/straight by pretending `doom-local-dir' is our .emacs.d. "Returns PACKAGE's `package!' recipe from `doom-packages'."
(user-emacs-directory straight-base-dir) (let ((plist (cdr (assq package doom-packages))))
(bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el")) (if prop
(bootstrap-version 5)) (if (plist-member plist prop)
(make-directory (doom-path straight-base-dir "straight/build") 'parents) (plist-get plist prop)
(or (require 'straight nil t) nil-value)
(file-readable-p bootstrap-file) plist)))
(with-current-buffer
(url-retrieve-synchronously (defun doom-package-set (package prop value)
(format "https://raw.githubusercontent.com/raxod502/straight.el/%s/install.el" "Set PROPERTY in PACKAGE's recipe to VALUE."
straight-repository-branch) (setf (alist-get package doom-packages)
'silent 'inhibit-cookies) (plist-put (alist-get package doom-packages)
(goto-char (point-max)) prop value)))
(eval-print-last-sexp)))
(load bootstrap-file nil t)) (defun doom-package-recipe (package &optional prop nil-value)
(require 'straight)) "Returns the `straight' recipe PACKAGE was registered with."
(straight--reset-caches) (let ((plist (gethash (symbol-name package) straight--recipe-cache)))
(setq straight-recipe-repositories nil (if prop
straight-recipe-overrides nil) (if (plist-member plist prop)
(mapc #'straight-use-recipes doom-core-package-sources) (plist-get plist prop)
(straight-register-package nil-value)
`(straight :type git :host github plist)))
:repo ,(format "%s/straight.el" straight-repository-user)
:files ("straight*.el") (defun doom-package-recipe-repo (package)
:branch ,straight-repository-branch "Resolve and return PACKAGE's (symbol) local-repo property."
:no-byte-compile t))) (if-let* ((recipe (cdr (straight-recipes-retrieve package)))
(repo (straight-vc-local-repo-name recipe)))
repo
(symbol-name package)))
(defun doom-package-build-recipe (package &optional prop nil-value)
"Returns the `straight' recipe PACKAGE was installed with."
(let ((plist (nth 2 (gethash (symbol-name package) straight--build-cache))))
(if prop
(if (plist-member plist prop)
(plist-get plist prop)
nil-value)
plist)))
(defun doom-package-build-time (package)
"TODO"
(car (gethash (symbol-name package) straight--build-cache)))
(defun doom-package-dependencies (package &optional recursive _noerror)
"Return a list of dependencies for a package."
(let ((deps (nth 1 (gethash (symbol-name package) straight--build-cache))))
(if recursive
(append deps (mapcan (lambda (dep) (doom-package-dependencies dep t t))
(copy-sequence deps)))
(copy-sequence deps))))
(defun doom-package-depending-on (package &optional noerror)
"Return a list of packages that depend on the package named NAME."
(cl-check-type name symbol)
;; can't get dependencies for built-in packages
(unless (or (doom-package-build-recipe name)
noerror)
(error "Couldn't find %s, is it installed?" name))
(cl-loop for pkg in (hash-table-keys straight--build-cache)
for deps = (doom-package-dependencies pkg)
if (memq package deps)
collect pkg
and append (doom-package-depending-on pkg t)))
;;; Predicate functions
(defun doom-package-built-in-p (package)
"Return non-nil if PACKAGE (a symbol) is built-in."
(eq (doom-package-build-recipe package :type)
'built-in))
(defun doom-package-installed-p (package)
"Return non-nil if PACKAGE (a symbol) is installed."
(file-directory-p (straight--build-dir (symbol-name package))))
(defun doom-package-is-type-p (package type)
"TODO"
(memq type (doom-enlist (doom-package-get package :type))))
(defun doom-package-in-module-p (package category &optional module)
"Return non-nil if PACKAGE was installed by the user's private config."
(when-let (modules (doom-package-get package :modules))
(or (and (not module) (assq :private modules))
(member (cons category module) modules))))
(defun doom-package-backend (package)
"Return 'straight, 'builtin, 'elpa or 'other, depending on how PACKAGE is
installed."
(cond ((gethash (symbol-name package) straight--build-cache)
'straight)
((or (doom-package-built-in-p package)
(assq package package--builtins))
'builtin)
((assq package package-alist)
'elpa)
((locate-library (symbol-name package))
'other)))
(defun doom-package-changed-recipe-p (name)
"Return t if a package named NAME (a symbol) has a different recipe than it
was installed with."
(cl-check-type name symbol)
;; TODO
;; (when (doom-package-installed-p name)
;; (when-let* ((doom-recipe (assq name doom-packages))
;; (install-recipe (doom-package-recipe)))
;; (not (equal (cdr quelpa-recipe)
;; (cdr (plist-get (cdr doom-recipe) :recipe))))))
)
;;; Package getters
(defun doom--read-packages (file &optional noeval noerror)
(condition-case-unless-debug e
(with-temp-buffer ; prevent buffer-local state from propagating
(if (not noeval)
(load file noerror 'nomessage 'nosuffix)
(when (file-exists-p file)
(insert-file-contents file)
(let (emacs-lisp-mode) (emacs-lisp-mode))
;; Scrape `package!' blocks from FILE for a comprehensive listing of
;; packages used by this module.
(while (search-forward "(package! " nil t)
(goto-char (match-beginning 0))
(let ((ppss (save-excursion (syntax-ppss))))
;; Don't collect packages in comments or strings
(or (nth 3 ppss)
(nth 4 ppss)
(cl-destructuring-bind (_ name . plist)
(read (current-buffer))
(push (cons
name (plist-put
plist :modules
(list (doom-module-from-path file))))
doom-packages))))))))
(error
(signal 'doom-package-error
(list (doom-module-from-path file)
file e)))))
(defun doom-package-list (&optional all-p core-only-p)
"Retrieve a list of explicitly declared packages from enabled modules.
If ALL-P, gather packages unconditionally across all modules, including disabled
ones."
(let ((doom-interactive-mode t)
doom-packages)
(doom--read-packages
(doom-path doom-core-dir "packages.el") all-p 'noerror)
(unless core-only-p
(let ((private-packages (doom-path doom-private-dir "packages.el"))
(doom-modules (doom-module-list)))
(if all-p
(mapc #'doom--read-packages
(doom-files-in doom-modules-dir
:depth 2
:match "/packages\\.el$"))
;; We load the private packages file twice to ensure disabled packages
;; are seen ASAP, and a second time to ensure privately overridden
;; packages are properly overwritten.
(doom--read-packages private-packages nil 'noerror)
(cl-loop for key being the hash-keys of doom-modules
for path = (doom-module-path (car key) (cdr key) "packages.el")
for doom--current-module = key
do (doom--read-packages path nil 'noerror)))
(doom--read-packages private-packages all-p 'noerror)))
(reverse doom-packages)))
(defun doom-package-pinned-list ()
"Return an alist mapping package names (strings) to pinned commits (strings)."
(let (alist)
(dolist (package doom-packages alist)
(cl-destructuring-bind (name &key disable ignore pin unpin &allow-other-keys)
package
(when (and (not ignore)
(not disable)
(or pin unpin))
(setf (alist-get (doom-package-recipe-repo name) alist
nil 'remove #'equal)
(unless unpin pin)))))))
(defun doom-package-unpinned-list ()
"Return an alist mapping package names (strings) to pinned commits (strings)."
(let (alist)
(dolist (package doom-packages alist)
(cl-destructuring-bind
(_ &key recipe disable ignore pin unpin &allow-other-keys)
package
(when (and (not ignore)
(not disable)
(or unpin
(and (plist-member recipe :pin)
(null pin))))
(cl-pushnew (doom-package-recipe-repo (car package)) alist
:test #'equal))))))
(defun doom-package-recipe-list ()
"Return straight recipes for non-builtin packages with a local-repo."
(let (recipes)
(dolist (recipe (hash-table-values straight--recipe-cache))
(cl-destructuring-bind (&key local-repo type no-build &allow-other-keys)
recipe
(unless (or (null local-repo)
(eq type 'built-in)
no-build)
(push recipe recipes))))
(nreverse recipes)))
(defun doom-package-state-list ()
"TODO"
(let (alist)
(dolist (recipe (hash-table-values straight--repo-cache) alist)
(cl-destructuring-bind (&key local-repo type &allow-other-keys)
recipe
(when (and local-repo (not (eq type 'built-in)))
(setf (alist-get local-repo alist nil nil #'equal)
(straight-vc-get-commit type local-repo)))))))
;; ;;
@ -254,6 +455,8 @@ elsewhere."
(plist-put! plist :modules (plist-put! plist :modules
(append module-list (append module-list
(list module) (list module)
(when (file-in-directory-p ,(dir!) doom-private-dir)
'((:private . modules)))
nil)))) nil))))
;; Merge given plist with pre-existing one ;; Merge given plist with pre-existing one
(doplist! ((prop val) (list ,@plist) plist) (doplist! ((prop val) (list ,@plist) plist)
@ -282,8 +485,9 @@ elsewhere."
(error-message-string e))))) (error-message-string e)))))
;; This is the only side-effect of this macro! ;; This is the only side-effect of this macro!
(setf (alist-get name doom-packages) plist) (setf (alist-get name doom-packages) plist)
(unless (plist-get plist :disable)
(with-no-warnings (with-no-warnings
(not (plist-get plist :disable))))) (cons name plist)))))
(defmacro disable-packages! (&rest packages) (defmacro disable-packages! (&rest packages)
"A convenience macro for disabling packages in bulk. "A convenience macro for disabling packages in bulk.
@ -311,24 +515,26 @@ should use it!"
(if (memq t targets) (if (memq t targets)
`(mapc (doom-rpartial #'doom-package-set :unpin t) `(mapc (doom-rpartial #'doom-package-set :unpin t)
(mapcar #'car doom-packages)) (mapcar #'car doom-packages))
(let (forms) (macroexp-progn
(dolist (target targets) (mapcar
(cl-check-type target (or symbol keyword list)) (lambda (target)
(cond (when target
((symbolp target) `(doom-package-set ',target :unpin t)))
(push `(doom-package-set ',target :unpin t) forms)) (cl-loop for target in targets
((or (keywordp target) if (or (keywordp target) (listp target))
(listp target)) append
(cl-destructuring-bind (category . modules) (doom-enlist target) (cl-loop with (category . modules) = (doom-enlist target)
(dolist (pkg doom-packages) for (name . plist) in doom-packages
(let ((pkg-modules (plist-get (cdr pkg) :modules))) for pkg-modules = (plist-get plist :modules)
(and (assq category pkg-modules) if (and (assq category pkg-modules)
(or (null modules) (or (null modules)
(cl-loop for module in modules (cl-loop for module in modules
if (member (cons category module) pkg-modules) if (member (cons category module) pkg-modules)
return t)) return t))
(push `(doom-package-set ',(car pkg) :unpin t) forms)))))))) name)
(macroexp-progn forms)))) collect it)
else if (symbolp target)
collect target)))))
(provide 'core-packages) (provide 'core-packages)
;;; core-packages.el ends here ;;; core-packages.el ends here

View file

@ -20,7 +20,6 @@ Emacs.")
;;; Packages ;;; Packages
(use-package! projectile (use-package! projectile
:after-call after-find-file dired-before-readin-hook minibuffer-setup-hook
:commands (projectile-project-root :commands (projectile-project-root
projectile-project-name projectile-project-name
projectile-project-p projectile-project-p

View file

@ -443,9 +443,10 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(use-package! winner (use-package! winner
;; undo/redo changes to Emacs' window layout ;; undo/redo changes to Emacs' window layout
:after-call after-find-file doom-switch-window-hook :hook (window-configuration-change . winner-mode)
:preface (defvar winner-dont-bind-my-keys t) ; I'll bind keys myself :preface (defvar winner-dont-bind-my-keys t) ; I'll bind keys myself
:config (winner-mode +1) :config
(remove-hook 'window-configuration-change #'winner-mode)
(appendq! winner-boring-buffers (appendq! winner-boring-buffers
'("*Compile-Log*" "*inferior-lisp*" "*Fuzzy Completions*" '("*Compile-Log*" "*inferior-lisp*" "*Fuzzy Completions*"
"*Apropos*" "*Help*" "*cvs*" "*Buffer List*" "*Ibuffer*" "*Apropos*" "*Help*" "*cvs*" "*Buffer List*" "*Ibuffer*"
@ -454,13 +455,12 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(use-package! paren (use-package! paren
;; highlight matching delimiters ;; highlight matching delimiters
:after-call after-find-file doom-switch-buffer-hook :hook (doom-first-buffer . show-paren-mode)
:config :config
(setq show-paren-delay 0.1 (setq show-paren-delay 0.1
show-paren-highlight-openparen t show-paren-highlight-openparen t
show-paren-when-point-inside-paren t show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t) show-paren-when-point-in-periphery t))
(show-paren-mode +1))
;;;###package whitespace ;;;###package whitespace

View file

@ -1,8 +1,9 @@
;;; core.el --- the heart of the beast -*- lexical-binding: t; -*- ;;; core.el --- the heart of the beast -*- lexical-binding: t; -*-
(when (version< emacs-version "26.1") (eval-when-compile
(error "Detected Emacs %s. Doom only supports Emacs 26.1 and higher" (when (< emacs-major-version 26)
emacs-version)) (error "Detected Emacs v%s. Doom only supports Emacs 26 and newer"
emacs-version)))
(defconst doom-version "2.0.9" (defconst doom-version "2.0.9"
"Current version of Doom Emacs.") "Current version of Doom Emacs.")
@ -195,7 +196,7 @@ users).")
;; Emacs "updates" its ui more often than it needs to, so we slow it down ;; Emacs "updates" its ui more often than it needs to, so we slow it down
;; slightly from 0.5s: ;; slightly from 0.5s:
(setq idle-update-delay 1) (setq idle-update-delay 1.0)
;; Emacs is essentially one huge security vulnerability, what with all the ;; Emacs is essentially one huge security vulnerability, what with all the
;; dependencies it pulls in from all corners of the globe. Let's try to be at ;; dependencies it pulls in from all corners of the globe. Let's try to be at
@ -306,15 +307,13 @@ users).")
;; Adopt a sneaky garbage collection strategy of waiting until idle time to ;; Adopt a sneaky garbage collection strategy of waiting until idle time to
;; collect; staving off the collector while the user is working. ;; collect; staving off the collector while the user is working.
(when doom-interactive-mode
(setq gcmh-idle-delay 5 (setq gcmh-idle-delay 5
gcmh-high-cons-threshold 16777216 ; 16mb gcmh-high-cons-threshold 16777216 ; 16mb
gcmh-verbose doom-debug-mode gcmh-verbose doom-debug-mode
gc-cons-percentage 0.6) gc-cons-percentage 0.6)
(add-transient-hook! 'pre-command-hook (gcmh-mode +1))
(with-eval-after-load 'gcmh (with-eval-after-load 'gcmh
(setq gc-cons-percentage 0.1) ;; But restore this later, otherwise we risk freezing and stuttering!
(add-hook 'focus-out-hook #'gcmh-idle-garbage-collect))) (setq gc-cons-percentage 0.1))
;; HACK `tty-run-terminal-initialization' is *tremendously* slow for some ;; HACK `tty-run-terminal-initialization' is *tremendously* slow for some
;; reason. Disabling it completely could have many side-effects, so we ;; reason. Disabling it completely could have many side-effects, so we
@ -337,18 +336,14 @@ users).")
"Run MODE-local-vars-hook after local variables are initialized." "Run MODE-local-vars-hook after local variables are initialized."
(run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode)) (run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode))
#'doom-try-run-hook)) #'doom-try-run-hook))
(add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h)
;; If the user has disabled `enable-local-variables', then ;; If the user has disabled `enable-local-variables', then
;; `hack-local-variables-hook' is never triggered, so we trigger it at the end ;; `hack-local-variables-hook' is never triggered, so we trigger it at the end
;; of `after-change-major-mode-hook': ;; of `after-change-major-mode-hook':
(defun doom-run-local-var-hooks-if-necessary-h () (defun doom-run-local-var-hooks-maybe-h ()
"Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled." "Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled."
(unless enable-local-variables (unless enable-local-variables
(doom-run-local-var-hooks-h))) (doom-run-local-var-hooks-h)))
(add-hook 'after-change-major-mode-hook
#'doom-run-local-var-hooks-if-necessary-h
'append)
;; ;;
@ -427,7 +422,18 @@ If this is a daemon session, load them all immediately instead."
nil #'doom-load-packages-incrementally nil #'doom-load-packages-incrementally
(cdr doom-incremental-packages) t)))) (cdr doom-incremental-packages) t))))
(add-hook 'emacs-startup-hook #'doom-load-packages-incrementally-h)
;;
;;; Custom hooks
(defvar doom-first-input-hook nil
"Transient hooks run before the first user input.")
(defvar doom-first-file-hook nil
"Transient hooks run before the first interactively opened file.")
(defvar doom-first-buffer-hook nil
"Transient hooks run before the first interactively opened buffer.")
;; ;;
@ -445,7 +451,7 @@ If RETURN-P, return the message as a string instead of displaying it."
(setq doom-init-time (setq doom-init-time
(float-time (time-subtract (current-time) before-init-time)))))) (float-time (time-subtract (current-time) before-init-time))))))
(defun doom-initialize (&optional force-p noerror) (defun doom-initialize (&optional force-p)
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil). "Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil).
The bootstrap process ensures that the essential directories exist, all core The bootstrap process ensures that the essential directories exist, all core
@ -473,6 +479,7 @@ for a list of all recognized module trees. Order defines precedence (from most
to least)." to least)."
(when (or force-p (not doom-init-p)) (when (or force-p (not doom-init-p))
(setq doom-init-p t) (setq doom-init-p t)
(doom-log "Initializing Doom")
;; Reset as much state as possible, so `doom-initialize' can be treated like ;; Reset as much state as possible, so `doom-initialize' can be treated like
;; a reset function. e.g. when reloading the config. ;; a reset function. e.g. when reloading the config.
@ -480,70 +487,51 @@ to least)."
load-path doom--initial-load-path load-path doom--initial-load-path
process-environment doom--initial-process-environment) process-environment doom--initial-process-environment)
;; Load shell environment, optionally generated from 'doom env'. No need to (or (and
;; do so if we're in terminal Emacs, because Emacs will correctly inherit ;; `doom-autoload-file' tells Emacs where to load all its functions
;; from. This includes everything in core/autoload/*.el and
;; autoload files in enabled modules.
(or (doom-load-autoloads-file doom-autoload-file)
(ignore (warn "Doom's core autoloads file is missing")))
;; Loads `doom-package-autoload-file', which loads a concatenated
;; package autoloads file which caches `load-path',
;; `auto-mode-alist', `Info-directory-list', and
;; `doom-disabled-packages'. A big reduction in startup time.
(or (doom-load-autoloads-file doom-package-autoload-file)
(ignore (warn "Doom's package autoloads file is missing"))))
(signal 'doom-error
(list "Doom is in an incomplete state"
"run 'bin/doom sync' on the command line to repair it")))
;; Load shell environment, optionally generated from 'doom env'. No need
;; to do so if we're in terminal Emacs, where Emacs correctly inherits
;; your shell environment there. ;; your shell environment there.
(when (and (or (display-graphic-p) (and (or (display-graphic-p)
(daemonp)) (daemonp))
(file-exists-p doom-env-file)) (doom-load-envvars-file doom-env-file 'noerror))
(doom-load-envvars-file doom-env-file))
(require 'core-modules) (require 'core-modules)
(let (;; `doom-autoload-file' tells Emacs where to load all its functions (autoload 'doom-initialize-packages "core-packages")
;; from. This includes everything in core/autoload/*.el and autoload (autoload 'doom-initialize-core-packages "core-packages")
;; files in enabled modules.
(core-autoloads-p (doom-load-autoloads-file doom-autoload-file noerror))
;; Loads `doom-package-autoload-file', which loads a concatenated
;; package autoloads file which caches `load-path', `auto-mode-alist',
;; `Info-directory-list', and `doom-disabled-packages'. A big
;; reduction in startup time.
(pkg-autoloads-p (doom-load-autoloads-file doom-package-autoload-file noerror)))
(if (and core-autoloads-p pkg-autoloads-p (not force-p))
;; In case we want to use package.el or straight via M-x ;; In case we want to use package.el or straight via M-x
(progn (with-eval-after-load 'package (require 'core-packages))
(with-eval-after-load 'package (with-eval-after-load 'straight (doom-initialize-packages))
(require 'core-packages))
(with-eval-after-load 'straight
(require 'core-packages)
(doom-initialize-packages)))
;; Eagerly load these libraries because we may be in a session that hasn't been ;; Bootstrap interactive session
;; fully initialized (e.g. where autoloads files haven't been generated or (add-hook! 'window-setup-hook
;; `load-path' populated). (add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h)
(mapc (doom-rpartial #'load nil (not doom-debug-mode) 'nosuffix) (add-hook 'after-change-major-mode-hook #'doom-run-local-var-hooks-maybe-h 'append)
(file-expand-wildcards (concat doom-core-dir "autoload/*.el"))) (add-hook 'doom-first-input-hook #'gcmh-mode)
(add-hook-trigger! 'doom-first-input-hook 'pre-command-hook)
;; Create all our core directories to quell file errors (add-hook-trigger! 'doom-first-file-hook 'after-find-hook 'dired-initial-position-hook)
(mapc (doom-rpartial #'make-directory 'parents) (add-hook-trigger! 'doom-first-buffer-hook 'after-find-hook 'doom-switch-buffer-hook))
(list doom-local-dir (add-hook 'emacs-startup-hook #'doom-load-packages-incrementally-h)
doom-etc-dir
doom-cache-dir))
;; Ensure the package management system (and straight) are ready for
;; action (and all core packages/repos are installed)
(require 'core-packages)
(doom-initialize-packages force-p))
(unless (or (and core-autoloads-p pkg-autoloads-p)
noerror)
(unless core-autoloads-p
(warn "Your Doom core autoloads file is missing"))
(unless pkg-autoloads-p
(warn "Your package autoloads file is missing"))
(signal 'doom-autoload-error (list "Run `bin/doom refresh' to generate them")))
(when doom-interactive-mode
(add-hook 'window-setup-hook #'doom-display-benchmark-h 'append) (add-hook 'window-setup-hook #'doom-display-benchmark-h 'append)
(add-to-list 'command-switch-alist (cons "--restore" #'doom-restore-session-handler))))
t))
(defun doom-initialize-core () (doom-initialize-modules force-p))
"Load Doom's core files for an interactive session."
(require 'core-keybinds) doom-init-p)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor))
(provide 'core) (provide 'core)
;;; core.el ends here ;;; core.el ends here

View file

@ -5,6 +5,22 @@
(package! auto-minor-mode :pin "17cfa1b54800fdef2975c0c0531dad34846a5065") (package! auto-minor-mode :pin "17cfa1b54800fdef2975c0c0531dad34846a5065")
(package! gcmh :pin "b1bde5089169a74f62033d027e06e98cbeedd43f") (package! gcmh :pin "b1bde5089169a74f62033d027e06e98cbeedd43f")
;; core-packages.el
(package! straight
;; :type 'core
:recipe `(:host github
:repo "raxod502/straight.el"
:branch ,straight-repository-branch
:local-repo "straight.el"
:files ("straight*.el")
:no-build t)
:pin "f606bfaf9330cfb1ef6971bb1f6ac4e2c39a39c2")
;; core-modules.el
(package! use-package
;; :type 'core
:pin "c873d5529c9c80cb58222f22873a4f081c307cb2")
;; core-ui.el ;; core-ui.el
(package! all-the-icons :pin "d6cb6d4a779eaa3570d8e451fd4d38b2b4554860") (package! all-the-icons :pin "d6cb6d4a779eaa3570d8e451fd4d38b2b4554860")
(package! hide-mode-line :pin "88888825b5b27b300683e662fa3be88d954b1cea") (package! hide-mode-line :pin "88888825b5b27b300683e662fa3be88d954b1cea")

View file

@ -47,7 +47,3 @@
;; And let 'er rip! ;; And let 'er rip!
(doom-initialize) (doom-initialize)
(if noninteractive
(doom-initialize-packages)
(doom-initialize-core)
(doom-initialize-modules))

View file

@ -5,7 +5,7 @@
(use-package! flycheck (use-package! flycheck
:commands flycheck-list-errors flycheck-buffer :commands flycheck-list-errors flycheck-buffer
:after-call doom-switch-buffer-hook after-find-file :hook (doom-first-buffer . global-flycheck-mode)
:config :config
(setq flycheck-emacs-lisp-load-path 'inherit) (setq flycheck-emacs-lisp-load-path 'inherit)
@ -39,9 +39,7 @@
:n "j" #'flycheck-error-list-next-error :n "j" #'flycheck-error-list-next-error
:n "k" #'flycheck-error-list-previous-error :n "k" #'flycheck-error-list-previous-error
:n "RET" #'flycheck-error-list-goto-error :n "RET" #'flycheck-error-list-goto-error
:n [return] #'flycheck-error-list-goto-error) :n [return] #'flycheck-error-list-goto-error))
(global-flycheck-mode +1))
(use-package! flycheck-popup-tip (use-package! flycheck-popup-tip

View file

@ -23,8 +23,7 @@ be negative.")
;;; Packages ;;; Packages
(use-package! helm-mode (use-package! helm-mode
:defer t :hook (doom-first-input . helm-mode)
:after-call pre-command-hook
:init :init
(map! [remap apropos] #'helm-apropos (map! [remap apropos] #'helm-apropos
[remap find-library] #'helm-locate-library [remap find-library] #'helm-locate-library
@ -43,7 +42,6 @@ be negative.")
[remap recentf-open-files] #'helm-recentf [remap recentf-open-files] #'helm-recentf
[remap yank-pop] #'helm-show-kill-ring) [remap yank-pop] #'helm-show-kill-ring)
:config :config
(helm-mode +1)
;; helm is too heavy for `find-file-at-point' ;; helm is too heavy for `find-file-at-point'
(add-to-list 'helm-completing-read-handlers-alist (cons #'find-file-at-point nil))) (add-to-list 'helm-completing-read-handlers-alist (cons #'find-file-at-point nil)))

View file

@ -8,12 +8,12 @@
;;; Packages ;;; Packages
(use-package! ido (use-package! ido
:after-call pre-command-hook :hook (doom-first-input . ido-mode)
:hook (ido-mode . ido-everywhere) :hook (ido-mode . ido-everywhere)
:hook (ido-mode . ido-ubiquitous-mode) :hook (ido-mode . ido-ubiquitous-mode)
:preface :preface
;; HACK `ido' is a really old package. It defines `ido-mode' manually and ;; HACK `ido' is a really old package. It defines `ido-mode' manually and
;; doesn't define a hook, so we define one for it.") ;; doesn't define a hook, so we define one for it, so we can use it!
(defadvice! +ido-run-hooks-a (&rest _) (defadvice! +ido-run-hooks-a (&rest _)
:after #'ido-mode :after #'ido-mode
(run-hooks 'ido-mode-hook)) (run-hooks 'ido-mode-hook))
@ -42,9 +42,7 @@
;; Go to $HOME with ~ ;; Go to $HOME with ~
"~" (λ! (if (looking-back "/" (point-min)) "~" (λ! (if (looking-back "/" (point-min))
(insert "~/") (insert "~/")
(call-interactively #'self-insert-command)))) (call-interactively #'self-insert-command)))))
(ido-mode +1))
(use-package! ido-vertical-mode (use-package! ido-vertical-mode

View file

@ -19,7 +19,7 @@ results buffer.")
;;; Packages ;;; Packages
(use-package! ivy (use-package! ivy
:after-call pre-command-hook :hook (doom-first-input . ivy-mode)
:init :init
(let ((standard-search-fn (let ((standard-search-fn
(if (featurep! +prescient) (if (featurep! +prescient)
@ -98,12 +98,10 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
(apply orig-fn args))) (apply orig-fn args)))
(define-key! ivy-minibuffer-map (define-key! ivy-minibuffer-map
"C-c C-e" #'+ivy/woccur
[remap doom/delete-backward-word] #'ivy-backward-kill-word [remap doom/delete-backward-word] #'ivy-backward-kill-word
"C-c C-e" #'+ivy/woccur
"C-o" #'ivy-dispatching-done "C-o" #'ivy-dispatching-done
"M-o" #'hydra-ivy/body) "M-o" #'hydra-ivy/body))
(ivy-mode +1))
(use-package! ivy-rich (use-package! ivy-rich

View file

@ -432,7 +432,19 @@ relative to `org-directory', unless it is an absolute path."
(setq org-pandoc-options (setq org-pandoc-options
'((standalone . t) '((standalone . t)
(mathjax . t) (mathjax . t)
(variable . "revealjs-url=https://revealjs.com"))))) (variable . "revealjs-url=https://revealjs.com"))))
(defadvice! +org--fix-async-export-a (orig-fn &rest args)
:around #'org-export-to-file
(if (not org-export-in-background)
(apply orig-fn args)
(setq org-export-async-init-file (make-temp-file "doom-org-async-export"))
(with-temp-file org-export-async-init-file
(prin1 `(progn (setq org-export-async-debug ,debug-on-error
load-path ',load-path)
(load ,user-init-file nil t))
(current-buffer)))
(apply orig-fn args))))
(defun +org-init-habit-h () (defun +org-init-habit-h ()