diff options
| author | brotzeit <brotzeitmacher@gmail.com> | 2022-06-23 23:23:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-23 23:23:15 +0200 |
| commit | af4aa18a9ba7ef9e7dbc1bcae0f4f58fc21f5a4f (patch) | |
| tree | b51f38975619d40fe7c9bf9fc97f09743ecc0b2d | |
| parent | 5f654a5867ef3847a844d944ff5425ec3acdecc8 (diff) | |
| parent | 332a23285a910a413cd58aea63c9ed581dcf9100 (diff) | |
| download | rust-mode-af4aa18a9ba7ef9e7dbc1bcae0f4f58fc21f5a4f.tar.gz | |
Merge pull request #447 from glasserc/support-envrc
Support envrc
| -rw-r--r-- | rust-cargo.el | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/rust-cargo.el b/rust-cargo.el index 58f0151..9f6e611 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -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))) |
