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")
|
2021-07-06 02:19:05 -04:00
|
|
|
:hook (doom-first-file . envrc-global-mode)
|
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
|
2021-07-06 02:19:05 -04:00
|
|
|
(or (get 'envrc-mode 'direnv-executable)
|
|
|
|
(put 'envrc-mode 'direnv-executable (executable-find "direnv" t))
|
2020-08-23 21:37:02 -04:00
|
|
|
(ignore (doom-log "Couldn't find direnv executable"))))
|
|
|
|
|
2021-07-06 02:19:05 -04:00
|
|
|
;; Ensure babel's execution environment matches the host buffer's.
|
|
|
|
(advice-add #'org-babel-execute-src-block :around #'envrc-propagate-environment)
|
|
|
|
|
|
|
|
;; Make sure any envrc changes are propagated after a `doom/reload'
|
|
|
|
(add-hook 'doom-after-reload-hook #'envrc-reload-all))
|