2022-07-30 21:49:00 +02:00
|
|
|
;;; lisp/lib/config.el -*- lexical-binding: t; -*-
|
2019-03-02 01:12:48 -05:00
|
|
|
|
2022-07-28 22:25:19 +02:00
|
|
|
(defvar doom-bin-dir (expand-file-name "bin/" doom-emacs-dir))
|
|
|
|
(defvar doom-bin (expand-file-name "doom" doom-bin-dir))
|
2019-12-13 15:23:23 -05:00
|
|
|
|
2022-09-06 19:59:20 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defvar doom-after-reload-hook nil
|
|
|
|
"A list of hooks to run after `doom/reload' has reloaded Doom.")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defvar doom-before-reload-hook nil
|
|
|
|
"A list of hooks to run before `doom/reload' has reloaded Doom.")
|
|
|
|
|
2019-03-02 01:12:48 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom/open-private-config ()
|
2022-08-13 21:27:11 +02:00
|
|
|
"Browse your `doom-user-dir'."
|
2019-03-02 01:12:48 -05:00
|
|
|
(interactive)
|
2022-08-13 21:27:11 +02:00
|
|
|
(unless (file-directory-p doom-user-dir)
|
|
|
|
(make-directory doom-user-dir t))
|
|
|
|
(doom-project-browse doom-user-dir))
|
2019-03-02 01:12:48 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/find-file-in-private-config ()
|
2022-08-13 21:27:11 +02:00
|
|
|
"Search for a file in `doom-user-dir'."
|
2019-03-02 01:12:48 -05:00
|
|
|
(interactive)
|
2022-08-13 21:27:11 +02:00
|
|
|
(doom-project-find-file doom-user-dir))
|
2019-03-02 01:12:48 -05:00
|
|
|
|
2019-10-25 18:19:33 -04:00
|
|
|
;;;###autoload
|
2019-12-29 18:22:44 -05:00
|
|
|
(defun doom/goto-private-init-file ()
|
|
|
|
"Open your private init.el file.
|
|
|
|
And jumps to your `doom!' block."
|
2019-10-25 18:19:33 -04:00
|
|
|
(interactive)
|
2022-09-24 10:45:50 +02:00
|
|
|
(find-file (expand-file-name doom-module-init-file doom-user-dir))
|
2019-10-25 18:19:33 -04:00
|
|
|
(goto-char
|
|
|
|
(or (save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "(doom!" nil t))
|
|
|
|
(point))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2019-12-29 18:22:44 -05:00
|
|
|
(defun doom/goto-private-config-file ()
|
2019-10-25 18:19:33 -04:00
|
|
|
"Open your private config.el file."
|
|
|
|
(interactive)
|
2022-09-24 10:45:50 +02:00
|
|
|
(find-file (expand-file-name doom-module-config-file doom-user-dir)))
|
2019-10-25 18:19:33 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-12-29 18:22:44 -05:00
|
|
|
(defun doom/goto-private-packages-file ()
|
2019-10-25 18:19:33 -04:00
|
|
|
"Open your private packages.el file."
|
|
|
|
(interactive)
|
2022-09-24 10:45:50 +02:00
|
|
|
(find-file (expand-file-name doom-module-packages-file doom-user-dir)))
|
2019-10-25 18:19:33 -04:00
|
|
|
|
2019-12-13 15:23:23 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Managements
|
|
|
|
|
2020-04-14 19:49:20 -04:00
|
|
|
(defmacro doom--if-compile (command on-success &optional on-failure)
|
|
|
|
(declare (indent 2))
|
2024-08-24 16:36:01 -04:00
|
|
|
`(let ((default-directory doom-emacs-dir)
|
|
|
|
(exec-path (cons doom-bin-dir exec-path)))
|
2021-08-14 02:28:14 -04:00
|
|
|
(with-current-buffer (compile ,command t)
|
|
|
|
(let ((w (get-buffer-window (current-buffer))))
|
|
|
|
(select-window w)
|
|
|
|
(add-hook
|
|
|
|
'compilation-finish-functions
|
|
|
|
(lambda (_buf status)
|
|
|
|
(if (equal status "finished\n")
|
|
|
|
(progn
|
|
|
|
(delete-window w)
|
|
|
|
,on-success)
|
|
|
|
,on-failure))
|
|
|
|
nil 'local)))))
|
2019-12-13 15:23:23 -05:00
|
|
|
|
2024-08-24 16:36:01 -04:00
|
|
|
(defvar doom-reload-command "doom sync -B -e"
|
|
|
|
"Command that `doom/reload' runs.")
|
2019-03-02 01:12:48 -05:00
|
|
|
;;;###autoload
|
2019-07-28 14:16:33 +02:00
|
|
|
(defun doom/reload ()
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
"Reloads your private config.
|
2019-03-02 01:12:48 -05:00
|
|
|
|
2024-07-18 22:34:25 -04:00
|
|
|
WARNING: This command is experimental! If you haven't configured your config to
|
|
|
|
be idempotent, then this could cause compounding slowness or errors.
|
|
|
|
|
2020-02-19 23:34:16 -05:00
|
|
|
This is experimental! It will try to do as `bin/doom sync' does, but from within
|
|
|
|
this Emacs session. i.e. it reload autoloads files (if necessary), reloads your
|
|
|
|
package list, and lastly, reloads your private config.el.
|
2019-03-02 01:12:48 -05:00
|
|
|
|
2020-10-16 22:28:08 -04:00
|
|
|
Runs `doom-after-reload-hook' afterwards."
|
2019-07-28 14:16:33 +02:00
|
|
|
(interactive)
|
2020-04-14 01:47:20 -04:00
|
|
|
(mapc #'require (cdr doom-incremental-packages))
|
2024-08-24 16:36:01 -04:00
|
|
|
(doom--if-compile doom-reload-command
|
2022-09-26 12:06:42 +02:00
|
|
|
(doom-context-with '(reload modules)
|
2021-05-05 16:12:35 -04:00
|
|
|
(doom-run-hooks 'doom-before-reload-hook)
|
2022-09-18 12:05:11 +02:00
|
|
|
(doom-load (file-name-concat doom-user-dir doom-module-init-file) t)
|
2020-04-14 19:49:20 -04:00
|
|
|
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
|
|
|
|
(general-auto-unbind-keys)
|
|
|
|
(unwind-protect
|
2022-09-18 12:05:11 +02:00
|
|
|
(startup--load-user-init-file nil)
|
2020-04-14 19:49:20 -04:00
|
|
|
(general-auto-unbind-keys t)))
|
2021-05-05 16:12:35 -04:00
|
|
|
(doom-run-hooks 'doom-after-reload-hook)
|
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
2020-05-14 15:00:23 -04:00
|
|
|
(message "Config successfully reloaded!"))
|
2019-12-13 15:23:23 -05:00
|
|
|
(user-error "Failed to reload your config")))
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
|
2019-07-07 13:12:35 +02:00
|
|
|
;;;###autoload
|
2019-07-27 17:03:44 +02:00
|
|
|
(defun doom/reload-autoloads ()
|
2022-09-16 03:11:40 +02:00
|
|
|
"Reload only the autoloads of the current profile.
|
2019-07-07 13:12:35 +02:00
|
|
|
|
|
|
|
This is much faster and safer than `doom/reload', but not as comprehensive. This
|
2019-10-25 18:22:19 -04:00
|
|
|
reloads your package and module visibility, but does not install new packages or
|
|
|
|
remove orphaned ones. It also doesn't reload your private config.
|
2019-07-07 13:12:35 +02:00
|
|
|
|
2020-02-19 23:34:16 -05:00
|
|
|
It is useful to only pull in changes performed by 'doom sync' on the command
|
2019-07-07 13:12:35 +02:00
|
|
|
line."
|
2019-07-27 17:03:44 +02:00
|
|
|
(interactive)
|
2022-09-16 03:11:40 +02:00
|
|
|
(require 'doom-profiles)
|
|
|
|
;; TODO: Make this more robust
|
2022-09-26 12:06:42 +02:00
|
|
|
(doom-context-with 'reload
|
refactor: introduce doom-context
Introduces a system to announce what execution contexts are active, so I
can react appropriately, emit more helpful logs/warnings in the case of
issues, and throw more meaningful errors.
* bin/doom: load module CLIs in the 'modules' context.
* lisp/cli/doctor.el: load package files in 'packages' context.
* lisp/doom-cli.el:
- (doom-before-init-hook, doom-after-init-hook): trigger hooks at the
correct time. This may increase startup load time, as the benchmark
now times more of the startup process.
- (doom-cli-execute, doom-cli-context-execute,
doom-cli-context-restore, doom-cli-context-parse,
doom-cli--output-benchmark-h, doom-cli-call, doom-cli--restart,
doom-cli-load, run!): remove redundant context prefix in debug logs,
it's now redundant with doom-context, which doom-log now prefixes
them with.
* lisp/doom-lib.el (doom-log): prefix doom-context to doom-log output,
unless it starts with :.
* lisp/doom-packages.el (package!, doom-packages--read): throw error if
not used in a packages.el file or in the context of our package
manager.
* lisp/doom-profiles.el (doom-profile--generate-init-vars,
doom-profile--generate-load-modules): use modules doom-context instead
of doom-init-time to detect startup.
* lisp/doom-start.el (doom-load-packages-incrementally-h): move function
closer to end of doom-after-init-hook.
* lisp/doom.el:
- (doom-before-init-hook, doom--set-initial-values-h,
doom--begin-init-h): rename doom--set-initial-values-h to
doom--begin-init-h and ensure it runs as late in
doom-before-init-hook as possible, as that is the point where Doom's
"initialization" formally begins.
- (doom-after-init-hook): don't trigger at the end of command-line-1
in non-interactive sessions. This will be triggered manually in
doom-cli.el's run!.
* lisp/lib/config.el (doom/reload, doom/reload-autoloads,
doom/reload-env): use 'reload' context for reload commands.
* modules/lang/emacs-lisp/autoload.el (+emacs-lisp-eval): use 'eval'
context.
* modules/lang/org/config.el: remove doom-reloading-p; check for
'reload' doom context instead.
2022-09-24 12:38:25 +02:00
|
|
|
(dolist (file (mapcar #'car doom-profile-generators))
|
|
|
|
(when (string-match-p "/[0-9]+-loaddefs[.-]" file)
|
|
|
|
(load (doom-path doom-profile-dir doom-profile-init-dir-name file)
|
|
|
|
'noerror)))))
|
2019-07-07 13:12:35 +02:00
|
|
|
|
2021-08-11 01:43:22 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom/reload-env ()
|
|
|
|
"Reloads your envvar file.
|
|
|
|
|
|
|
|
DOES NOT REGENERATE IT. You must run 'doom env' in your shell OUTSIDE of Emacs.
|
|
|
|
Doing so from within Emacs will taint your shell environment.
|
|
|
|
|
|
|
|
An envvar file contains a snapshot of your shell environment, which can be
|
|
|
|
imported into Emacs."
|
2021-08-12 23:26:56 +07:00
|
|
|
(interactive)
|
2022-09-26 12:06:42 +02:00
|
|
|
(doom-context-with 'reload
|
refactor: introduce doom-context
Introduces a system to announce what execution contexts are active, so I
can react appropriately, emit more helpful logs/warnings in the case of
issues, and throw more meaningful errors.
* bin/doom: load module CLIs in the 'modules' context.
* lisp/cli/doctor.el: load package files in 'packages' context.
* lisp/doom-cli.el:
- (doom-before-init-hook, doom-after-init-hook): trigger hooks at the
correct time. This may increase startup load time, as the benchmark
now times more of the startup process.
- (doom-cli-execute, doom-cli-context-execute,
doom-cli-context-restore, doom-cli-context-parse,
doom-cli--output-benchmark-h, doom-cli-call, doom-cli--restart,
doom-cli-load, run!): remove redundant context prefix in debug logs,
it's now redundant with doom-context, which doom-log now prefixes
them with.
* lisp/doom-lib.el (doom-log): prefix doom-context to doom-log output,
unless it starts with :.
* lisp/doom-packages.el (package!, doom-packages--read): throw error if
not used in a packages.el file or in the context of our package
manager.
* lisp/doom-profiles.el (doom-profile--generate-init-vars,
doom-profile--generate-load-modules): use modules doom-context instead
of doom-init-time to detect startup.
* lisp/doom-start.el (doom-load-packages-incrementally-h): move function
closer to end of doom-after-init-hook.
* lisp/doom.el:
- (doom-before-init-hook, doom--set-initial-values-h,
doom--begin-init-h): rename doom--set-initial-values-h to
doom--begin-init-h and ensure it runs as late in
doom-before-init-hook as possible, as that is the point where Doom's
"initialization" formally begins.
- (doom-after-init-hook): don't trigger at the end of command-line-1
in non-interactive sessions. This will be triggered manually in
doom-cli.el's run!.
* lisp/lib/config.el (doom/reload, doom/reload-autoloads,
doom/reload-env): use 'reload' context for reload commands.
* modules/lang/emacs-lisp/autoload.el (+emacs-lisp-eval): use 'eval'
context.
* modules/lang/org/config.el: remove doom-reloading-p; check for
'reload' doom context instead.
2022-09-24 12:38:25 +02:00
|
|
|
(let ((default-directory doom-emacs-dir))
|
|
|
|
(with-temp-buffer
|
|
|
|
(doom-load-envvars-file doom-env-file)
|
|
|
|
(message "Reloaded %S" (abbreviate-file-name doom-env-file))))))
|
2021-08-11 01:43:22 -04:00
|
|
|
|
2024-08-24 16:36:01 -04:00
|
|
|
(defvar doom-upgrade-command "doom upgrade -B --force"
|
|
|
|
"Command that `doom/upgrade' runs.")
|
2019-12-13 15:23:23 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom/upgrade ()
|
|
|
|
"Run 'doom upgrade' then prompt to restart Emacs."
|
:boom: Replace exec-path-from-shell w/ 'bin/doom env'
IMPORTANT: This is a breaking update for Mac users, as your shell
environment will no longer be inherited correctly (with the removal of
exec-path-from-shell). The quick fix is: 'bin/doom env refresh'. Also,
the set-env! autodef now does nothing (and is deprecated), be sure to
remove calls to it in your config.
Smaller changes:
+ This update also adds --no-* switches to doom quickstart
+ Includes general improvements to the documentation of several bin/doom
commands.
+ Moves doom/reload* commands to core/autoload/config.el
+ doom/reload-project has been removed (it didn't actually do anything)
The breaking change:
This update adds an "envvar file" to Doom Emacs. This file is generated
by `doom env refresh`, populated with variables scraped from your shell
environment (from both non-interactive and interactive sessions). This
file is then (inexpensively) loaded at startup, if it exists.
+ The file is manually generated with `doom env refresh`.
+ It can be regenerated automatically whenever `doom refresh` is run by
running `doom env enable` (`doom env clear` will reverse this and
delete the env file).
+ `doom quickstart` will ask if you want to auto-generate this envvar
file. You won't need it if you're confident Emacs will always be
started from the correct environment, however.
+ Your env file can be reloaded from a running Emacs session with `M-x
doom/reload-env`. Note: this won't work if the Emacs session you're
running it in doesn't have a correct SHELL set. i.e. don't use this to
create your first env file!
The idea isn't mine -- it's borrowed from Spacemacs -- and was
introduced to me in #1053 by @yurimx. I was impressed with it. Prior to
this, I was unhappy with exec-path-from-shell (no hate to the dev, I
understand its necessity), and 'doom patch-macos' wasn't ideal for mac
users (needed to be reapplied every time you update Emacs). What's more,
many users (even Linux users) had to install exec-path-from-shell
anyway.
This solution suffers from none of their shortcomings. More reliable
than patch-macos, more performant and complete than
exec-path-from-shell, and easily handled by bin/doom.
2019-03-28 00:06:10 -04:00
|
|
|
(interactive)
|
2024-08-24 16:36:01 -04:00
|
|
|
(doom--if-compile doom-upgrade-command
|
2020-04-14 19:49:20 -04:00
|
|
|
(when (y-or-n-p "You must restart Emacs for the upgrade to take effect.\n\nRestart Emacs?")
|
|
|
|
(doom/restart-and-restore))))
|