Skip to content

Commit

Permalink
revert(core)!: remove exec-path-from-shell
Browse files Browse the repository at this point in the history
The startup may become too slow when using shell configuration
frameworks like `Oh-my-zsh`

This reverts commit fc202b6.
  • Loading branch information
abougouffa committed Jul 15, 2023
1 parent 52262dd commit 8dfb0d9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
11 changes: 0 additions & 11 deletions core/me-bootstrap.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@
(defun +use-package--remove-check-if-disabled-advice-h ()
(advice-remove 'use-package '+use-package--check-if-disabled-a)))

;; The current `exec-path-from-shell' don't support Windows. Generally there is
;; no need for this hack on Windows.
(when os/win (push 'exec-path-from-shell minemacs-disabled-packages))

;; Read some environment variables from shell (like $PATH)
(use-package exec-path-from-shell
:straight t
:custom
(exec-path-from-shell-variables '("PATH" "MANPATH" "CMAKE_PREFIX_PATH" "PKG_CONFIG_PATH"))
:hook (minemacs-after-startup . exec-path-from-shell-initialize))


(provide 'me-bootstrap)

Expand Down
6 changes: 6 additions & 0 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ Unbind setq hooks on HOOKS for VARS.
Queue FNS to be byte/natively-compiled after a brief delay.
(fn &rest FNS)")
(autoload '+env-save "../elisp/+minemacs" "\
Load environment variables of the current session to the file
\".emacs.d/local/system-env.el\"." t)
(autoload '+env-load "../elisp/+minemacs" "\
Load environment variables from the file saved in
\".emacs.d/local/system-env.el\" if available." t)
(autoload '+ignore-root "../elisp/+minemacs" "\
Add ROOTS to ignored projects, recentf, etc.
Expand Down
8 changes: 8 additions & 0 deletions core/me-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ MinEmacs hooks will be run in this order:
:variable-pitch-font-size 13)
"Default fonts of MinEmacs."))

(defcustom +env-save-vars
'("PATH" "MANPATH" "CMAKE_PREFIX_PATH" "PKG_CONFIG_PATH" "LSP_USE_PLISTS")
"List of the environment variables to saved by `+env-save'.
You need to run Emacs from terminal to get the environment variables.
MinEmacs then save them when calling `+env-save' to be used in GUI sessions as well."
:group 'minemacs-core
:type '(repeat string))


(provide 'me-vars)

Expand Down
37 changes: 37 additions & 0 deletions elisp/+minemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,43 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
(let (byte-compile-warnings)
(+shutup! (byte-compile fn)))))))

;;;###autoload
(defun +env-save ()
"Load environment variables of the current session to the file
\".emacs.d/local/system-env.el\"."
(interactive)
(with-temp-buffer
(insert ";; -*- mode: emacs-lisp; no-byte-compile: t; no-native-compile: t; -*-\n\n")
(dolist (env-var +env-save-vars)
(when-let ((var-val (getenv env-var)))
(when (equal "PATH" env-var)
(insert
(format
"\n;; Helper function\n%s\n"
'(defun +add-to-path (path)
(unless (member path exec-path)
(add-to-list 'exec-path path)))))
(insert "\n;; Adding PATH content to `exec-path'\n")
(dolist (path (parse-colon-path var-val))
(when path
(insert
(format
"(+add-to-path \"%s\")\n"
path path))))
(insert "\n"))
(insert
(format "(setenv \"%s\" \"%s\")\n" env-var var-val))))
(write-file (concat minemacs-local-dir "system-env.el"))))

;;;###autoload
(defun +env-load ()
"Load environment variables from the file saved in
\".emacs.d/local/system-env.el\" if available."
(interactive)
(let ((env-file (concat minemacs-local-dir "system-env.el")))
(when (file-exists-p env-file)
(+load env-file))))

;;;###autoload
(defun +ignore-root (&rest roots)
"Add ROOTS to ignored projects, recentf, etc."
Expand Down
13 changes: 13 additions & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
(when (file-exists-p user-init-tweaks)
(+load user-init-tweaks))))

;; HACK: When Emacs is launched from the terminal (in GNU/Linux), it inherits
;; the terminal's environment variables, which can be useful specially for
;; running commands under a custom "$PATH" directory. But when Emacs is launched
;; from the desktop manager (KDE, Gnome, etc.), it can omit the terminal's
;; environment variables. The way I solve this is by launching Emacs from
;; terminal, which gives Emacs the full environment variables of the invoking
;; terminal. Then I call the `+env-save' command, which reads the environment
;; variables defined in `+env-save-vars' and stores them in
;; "~/.emacs.d/local/system-env.el". This file is then loaded in the future
;; Emacs sessions (launched either from terminal or from GUI) by calling the
;; `+env-load' command.
(+env-load) ; Load environment variables when available.

;; NOTE: This is MinEmacs' synchronization point. To get a fast Emacs startup,
;; MinEmacs tries to defer loading most of its packages until this hook is
;; executed. This is managed by the `minemacs-loaded' and `minemacs-lazy'
Expand Down

0 comments on commit 8dfb0d9

Please sign in to comment.