|
30 | 30 |
|
31 | 31 | (defun rust-buffer-project ()
|
32 | 32 | "Get project root if possible."
|
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))))))) |
| 33 | + (if (file-remote-p default-directory) |
| 34 | + (rust-buffer-crate) |
| 35 | + ;; Copy environment variables into the new buffer, since |
| 36 | + ;; with-temp-buffer will re-use the variables' defaults, even if |
| 37 | + ;; they have been changed in this variable using e.g. envrc-mode. |
| 38 | + ;; See https://github.com/purcell/envrc/issues/12. |
| 39 | + (let ((env process-environment) |
| 40 | + (path exec-path)) |
| 41 | + (with-temp-buffer |
| 42 | + ;; Copy the entire environment just in case there's something we |
| 43 | + ;; don't know we need. |
| 44 | + (setq-local process-environment env) |
| 45 | + ;; Set PATH so we can find cargo. |
| 46 | + (setq-local exec-path path) |
| 47 | + (let ((ret (call-process rust-cargo-bin nil t nil "locate-project"))) |
| 48 | + (when (/= ret 0) |
| 49 | + (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) |
| 50 | + (goto-char 0) |
| 51 | + (let ((output (json-read))) |
| 52 | + (cdr (assoc-string "root" output)))))))) |
| 53 | + |
| 54 | +(defun rust-buffer-crate () |
| 55 | + "Try to locate Cargo.toml using `locate-dominating-file'." |
| 56 | + (let ((dir (locate-dominating-file default-directory "Cargo.toml"))) |
| 57 | + (if dir dir default-directory))) |
51 | 58 |
|
52 | 59 | (defun rust-update-buffer-project ()
|
53 | 60 | (setq-local rust-buffer-project (rust-buffer-project)))
|
|
0 commit comments