💥 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.
This commit is contained in:
Henrik Lissner 2019-03-28 00:06:10 -04:00
parent ab616cfb95
commit 2dc52bc9be
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
19 changed files with 266 additions and 136 deletions

View file

@ -1,5 +1,9 @@
;;; core/autoload/config.el -*- lexical-binding: t; -*-
;;;###autoload
(defvar doom-reloading-p nil
"TODO")
;;;###autoload
(defun doom/open-private-config ()
"TODO"
@ -14,25 +18,70 @@
(interactive)
(doom-project-find-file doom-private-dir))
;;;###autoload
(defun doom/open-env ()
"TODO"
(interactive)
(when (and (not (file-exists-p doom-env-file))
(y-or-n-p "User doesn't have an envvar file, generate one?"))
(doom/reload-env))
(find-file doom-env-file))
;;;###autoload
(defun doom/reload (&optional force-p)
"Reloads your config. This is experimental!
"Reloads your private config.
If called from a noninteractive session, this will try to communicate with a
live server (if one is found) to tell it to run this function.
This is experimental! It will try to do as `bin/doom refresh' 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.
If called from an interactive session, tries to reload autoloads files (if
necessary), reinistalize doom (via `doom-initialize') and reloads your private
init.el and config.el. Then runs `doom-reload-hook'."
Runs `doom-reload-hook' afterwards."
(interactive "P")
(require 'core-cli)
(doom-reload-autoloads force-p)
(setq load-path doom-site-load-path)
(let (doom-init-p)
(doom-initialize))
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
(doom-initialize-modules 'force))
(when (bound-and-true-p doom-packages)
(doom/reload-packages))
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook)
(let ((doom-reloading-p t))
(when (getenv "DOOMENV")
(doom-reload-env-file 'force))
(doom-reload-autoloads force-p)
(setq load-path doom-site-load-path)
(let (doom-init-p)
(doom-initialize))
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
(doom-initialize-modules 'force))
(when (bound-and-true-p doom-packages)
(doom/reload-packages))
(run-hook-wrapped 'doom-reload-hook #'doom-try-run-hook))
(message "Finished!"))
;;;###autoload
(defun doom/reload-env ()
"Regenerates and reloads your shell environment.
Uses the same mechanism as 'bin/doom env reload'."
(interactive)
(compile (format "%s env refresh" (expand-file-name "bin/doom" doom-emacs-dir)))
(while compilation-in-progress
(sit-for 1))
(unless (file-readable-p doom-env-file)
(error "Failed to generate env file"))
(load-env-vars doom-env-file))
;;;###autoload
(defun doom/reload-font ()
"Reload `doom-font', `doom-variable-pitch-font', and `doom-unicode-font', if
set."
(interactive)
(when doom-font
(set-frame-font doom-font t))
(doom|init-fonts))
;;;###autoload
(defun doom/reload-theme ()
"Reset the current color theme and fonts."
(interactive)
(let ((theme (or (car-safe custom-enabled-themes) doom-theme)))
(when theme
(mapc #'disable-theme custom-enabled-themes))
(when (and doom-theme (not (memq doom-theme custom-enabled-themes)))
(let (doom--prefer-theme-elc)
(load-theme doom-theme t)))
(doom|init-fonts)))

View file

@ -21,6 +21,7 @@ ready to be pasted in a bug report on github."
"- System features: %s\n"
"- Details:\n"
" ```elisp\n"
" env bootstrapper: %s\n"
" elc count: %s\n"
" uname -a: %s\n"
" modules: %s\n"
@ -36,6 +37,8 @@ ready to be pasted in a bug report on github."
"n/a")
(display-graphic-p) (daemonp)
(bound-and-true-p system-configuration-features)
(cond ((file-exists-p doom-env-file) 'envvar-file)
((featurep 'exec-path-from-shell) 'exec-path-from-shell))
;; details
(length (doom-files-in `(,@doom-modules-dirs
,doom-core-dir

View file

@ -28,15 +28,6 @@ they are absolute."
;;
;; Commands
;;;###autoload
(defun doom/reload-project ()
"Reload the project root cache."
(interactive)
(projectile-invalidate-cache nil)
(setq-default projectile-project-root nil)
(dolist (fn projectile-project-root-files-functions)
(remhash (format "%s-%s" fn default-directory) projectile-project-root-cache)))
;;;###autoload
(defun doom/find-file-in-other-project (project-root)
"Preforms `projectile-find-file' in a known project of your choosing."

View file

@ -81,18 +81,6 @@ See `display-line-numbers' for what these values mean."
(`nil "disabled")
(_ (symbol-name next))))))
;;;###autoload
(defun doom/reload-theme ()
"Reset the current color theme and fonts."
(interactive)
(let ((theme (or (car-safe custom-enabled-themes) doom-theme)))
(when theme
(mapc #'disable-theme custom-enabled-themes))
(when (and doom-theme (not (memq doom-theme custom-enabled-themes)))
(let (doom--prefer-theme-elc)
(load-theme doom-theme t)))
(doom|init-fonts)))
;;;###autoload
(defun doom/delete-frame ()
"Delete the current frame, but ask for confirmation if it isn't empty."
@ -161,15 +149,6 @@ windows (unlike `doom/window-maximize-buffer') Activate again to undo."
(while (ignore-errors (windmove-up)) (delete-window))
(while (ignore-errors (windmove-down)) (delete-window))))
;;;###autoload
(defun doom/reload-font ()
"Reload `doom-font', `doom-variable-pitch-font', and `doom-unicode-font', if
set."
(interactive)
(when doom-font
(set-frame-font doom-font t))
(doom|init-fonts))
;;;###autoload
(defun doom/set-frame-opacity (opacity)
"Interactively change the current frame's opacity.