Skip to content

Commit af4aa18

Browse files
authored
Merge pull request #447 from glasserc/support-envrc
Support envrc
2 parents 5f654a5 + 332a232 commit af4aa18

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

rust-cargo.el

+18-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,24 @@
3030

3131
(defun rust-buffer-project ()
3232
"Get project root if possible."
33-
(with-temp-buffer
34-
(let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
35-
(when (/= ret 0)
36-
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
37-
(goto-char 0)
38-
(let ((output (json-read)))
39-
(cdr (assoc-string "root" output))))))
33+
;; Copy environment variables into the new buffer, since
34+
;; with-temp-buffer will re-use the variables' defaults, even if
35+
;; they have been changed in this variable using e.g. envrc-mode.
36+
;; See https://github.com/purcell/envrc/issues/12.
37+
(let ((env process-environment)
38+
(path exec-path))
39+
(with-temp-buffer
40+
;; Copy the entire environment just in case there's something we
41+
;; don't know we need.
42+
(setq-local process-environment env)
43+
;; Set PATH so we can find cargo.
44+
(setq-local exec-path path)
45+
(let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
46+
(when (/= ret 0)
47+
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
48+
(goto-char 0)
49+
(let ((output (json-read)))
50+
(cdr (assoc-string "root" output)))))))
4051

4152
(defun rust-update-buffer-project ()
4253
(setq-local rust-buffer-project (rust-buffer-project)))

0 commit comments

Comments
 (0)