Fix #3812: direnv not in scope for babel execution
This commit is contained in:
parent
134f959838
commit
6f49f2151e
1 changed files with 23 additions and 1 deletions
|
@ -40,4 +40,26 @@
|
||||||
"Don't try to use direnv if the executable isn't present."
|
"Don't try to use direnv if the executable isn't present."
|
||||||
:before-while #'envrc-mode
|
:before-while #'envrc-mode
|
||||||
(or (executable-find "direnv")
|
(or (executable-find "direnv")
|
||||||
(ignore (doom-log "Couldn't find direnv executable")))))
|
(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)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue