Skip to content

Commit

Permalink
Merge pull request #447 from glasserc/support-envrc
Browse files Browse the repository at this point in the history
Support envrc
  • Loading branch information
brotzeit authored Jun 23, 2022
2 parents 5f654a5 + 332a232 commit af4aa18
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions rust-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@

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

(defun rust-update-buffer-project ()
(setq-local rust-buffer-project (rust-buffer-project)))
Expand Down

0 comments on commit af4aa18

Please sign in to comment.