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
|
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)
|
|
|
|
|
2023-03-11 19:50:28 -05:00
|
|
|
;; HACK: Normally, envrc updates on `after-change-major-mode-hook' (runs after
|
|
|
|
;; a major mode's body and hooks). IMHO, this is too late; a mode's hooks
|
|
|
|
;; might depend on environmental state that direnv sets up (e.g. starting an
|
|
|
|
;; LSP server that expects project-specific envvars), so I move it to
|
|
|
|
;; `change-major-mode-after-body-hook' instead, which runs before said
|
|
|
|
;; hooks, but not the body.
|
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
|
|
|
(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
|
|
|
|
2023-03-11 19:50:28 -05:00
|
|
|
;; ...However, the above hack causes envrc to trigger in its own, internal
|
|
|
|
;; buffers, causing extra direnv errors.
|
|
|
|
(defadvice! +direnv--debounce-update-a (&rest _)
|
|
|
|
"Prevent direnv from running multiple times, consecutively in a buffer."
|
|
|
|
:before-while #'envrc--update
|
|
|
|
(not (string-prefix-p "*envrc" (buffer-name))))
|
|
|
|
|
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."
|
2023-02-17 12:08:32 -05:00
|
|
|
:before-while #'envrc-global-mode
|
|
|
|
(or (executable-find envrc-direnv-executable)
|
|
|
|
(ignore (doom-log "Failed to locate direnv executable; aborting envrc-global-mode"))))
|
2020-08-23 21:37:02 -04:00
|
|
|
|
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))
|