emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode ca7d99c 469/486: Set default directory when comp


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode ca7d99c 469/486: Set default directory when compiling.
Date: Sat, 7 Aug 2021 09:26:16 -0400 (EDT)

branch: elpa/rust-mode
commit ca7d99c6fd90fc1e636aa9d4020a2f077786a0c3
Author: Nathan Moreau <nathan.moreau@m4x.org>
Commit: Nathan Moreau <nathan.moreau@m4x.org>

    Set default directory when compiling.
---
 rust-mode.el | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/rust-mode.el b/rust-mode.el
index 2d63dc5..2c89b97 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1901,20 +1901,29 @@ Return the created process."
   (interactive)
   (setq-local rust-format-on-save nil))
 
+(defun rust--compile (format-string &rest args)
+  (when (null rust-buffer-project)
+    (rust-update-buffer-project))
+  (let ((default-directory
+          (or (and rust-buffer-project
+                   (file-name-directory rust-buffer-project))
+              default-directory)))
+    (compile (apply #'format format-string args))))
+
 (defun rust-compile ()
   "Compile using `cargo build`"
   (interactive)
-  (compile (format "%s build" rust-cargo-bin)))
+  (rust--compile "%s build" rust-cargo-bin))
 
 (defun rust-run ()
   "Run using `cargo run`"
   (interactive)
-  (compile (format "%s run" rust-cargo-bin)))
+  (rust--compile "%s run" rust-cargo-bin))
 
 (defun rust-test ()
   "Test using `cargo test`"
   (interactive)
-  (compile (format "%s test" rust-cargo-bin)))
+  (rust--compile "%s test" rust-cargo-bin))
 
 ;;; Hooks
 
@@ -2072,7 +2081,7 @@ visit the new file."
          ;; set `compile-command' temporarily so `compile' doesn't
          ;; clobber the existing value
          (compile-command (mapconcat #'shell-quote-argument args " ")))
-    (compile compile-command)))
+    (rust--compile compile-command)))
 
 ;;; Utilities
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]