2019-04-05 03:16:37 -04:00
|
|
|
;;; tools/direnv/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2020-08-21 02:34:07 -04:00
|
|
|
(use-package! envrc
|
|
|
|
:when (executable-find "direnv")
|
2020-08-23 15:17:37 -04:00
|
|
|
:after-call doom-first-file-hook
|
2019-04-05 03:16:37 -04:00
|
|
|
:config
|
2020-08-21 02:34:07 -04:00
|
|
|
(add-to-list 'doom-debug-variables 'envrc-debug)
|
2019-07-10 02:29:13 +02:00
|
|
|
|
2021-05-12 16:28:52 -04:00
|
|
|
(set-popup-rule! "^\\*envrc\\*" :quit t :ttl 0)
|
|
|
|
|
Drop Emacs 26.x support
Emacs 27.x has been the stable version of Emacs for nearly a year, and
introduces a litany of bugfixes, performance, and quality-of-life
improvements that significantly reduce Doom's maintenance burden (like
XDG support, early-init.el, image manipulation without imagemagick, a
native JSON library, harfbuzz support, pdumper, and others).
With so many big changes on Doom's horizon, I like having one less (big)
thing to worry about.
Also reverts bb677cf7a (#5232) as it is no longer needed.
2021-07-06 01:54:32 -04:00
|
|
|
;; A globalized minor mode triggers on `after-change-major-mode-hook'
|
|
|
|
;; normally, which runs after a major mode's body and hooks. If those hooks do
|
|
|
|
;; any initialization work that's sensitive to environmental state set up by
|
|
|
|
;; direnv, then you're gonna have a bad time, so I move the trigger to
|
|
|
|
;; `change-major-mode-after-body-hook' instead. This runs before said hooks
|
|
|
|
;; (but not the body; fingers crossed that no major mode does important env
|
|
|
|
;; initialization there).
|
|
|
|
(add-hook! 'envrc-global-mode-hook
|
|
|
|
(defun +direnv-init-global-mode-earlier-h ()
|
|
|
|
(let ((fn #'envrc-global-mode-enable-in-buffers))
|
|
|
|
(if (not envrc-global-mode)
|
|
|
|
(remove-hook 'change-major-mode-after-body-hook fn)
|
|
|
|
(remove-hook 'after-change-major-mode-hook fn)
|
|
|
|
(add-hook 'change-major-mode-after-body-hook fn 100)))))
|
2020-11-10 16:29:13 -05:00
|
|
|
|
2020-02-02 03:18:49 -05:00
|
|
|
(defadvice! +direnv--fail-gracefully-a (&rest _)
|
|
|
|
"Don't try to use direnv if the executable isn't present."
|
2020-08-21 02:34:07 -04:00
|
|
|
:before-while #'envrc-mode
|
2020-02-02 03:18:49 -05:00
|
|
|
(or (executable-find "direnv")
|
2020-08-23 21:37:02 -04:00
|
|
|
(ignore (doom-log "Couldn't find direnv executable"))))
|
|
|
|
|
|
|
|
;; HACK envrc-mode only affects the current buffer's environment, which is
|
|
|
|
;; generally what we want, except when we're running babel blocks in
|
|
|
|
;; org-mode, because there may be state or envvars those blocks need to
|
|
|
|
;; read. In order to perpetuate the org buffer's environment into the
|
|
|
|
;; execution of the babel block we need to temporarily change the global
|
|
|
|
;; environment. Let's hope it runs quickly enough that its effects aren't
|
|
|
|
;; felt in other buffers in the meantime!
|
|
|
|
(defvar +direnv--old-environment nil)
|
|
|
|
(defadvice! +direnv-persist-environment-a (orig-fn &rest args)
|
|
|
|
:around #'org-babel-execute-src-block
|
|
|
|
(if +direnv--old-environment
|
|
|
|
(apply orig-fn args)
|
|
|
|
(setq-default +direnv--old-environment
|
|
|
|
(cons (default-value 'process-environment)
|
|
|
|
(default-value 'exec-path))
|
|
|
|
exec-path exec-path
|
|
|
|
process-environment process-environment)
|
|
|
|
(unwind-protect (apply orig-fn args)
|
|
|
|
(setq-default process-environment (car +direnv--old-environment)
|
|
|
|
exec-path (cdr +direnv--old-environment)
|
|
|
|
+direnv--old-environment nil)))))
|