summaryrefslogtreecommitdiff
path: root/rust-cargo.el
diff options
context:
space:
mode:
authorSvilen Ivanov <isvilen@applicata.bg>2024-05-13 13:03:40 +0300
committerSvilen Ivanov <isvilen@applicata.bg>2024-05-14 14:54:25 +0300
commit947ebf993818f7135e12d4b0da6f5b05ba790c14 (patch)
treeb0f81270f68977ac27a2deb07413be7adc071df2 /rust-cargo.el
parente54bbae8c4c2af580b5721ad5ac151f2ad19293e (diff)
downloadrust-mode-947ebf993818f7135e12d4b0da6f5b05ba790c14.tar.gz
Support running interactive programs
Diffstat (limited to 'rust-cargo.el')
-rw-r--r--rust-cargo.el40
1 files changed, 24 insertions, 16 deletions
diff --git a/rust-cargo.el b/rust-cargo.el
index bda23d8..cd2214a 100644
--- a/rust-cargo.el
+++ b/rust-cargo.el
@@ -67,46 +67,54 @@
;;; Internal
-(defun rust--compile (format-string &rest args)
+(defun rust--compile (comint 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))))
+ default-directory))
+ ;; make sure comint is a boolean value
+ (comint (not (not comint))))
+ (compile (apply #'format format-string args) comint)))
;;; Commands
(defun rust-check ()
"Compile using `cargo check`"
(interactive)
- (rust--compile "%s check %s" rust-cargo-bin rust-cargo-default-arguments))
+ (rust--compile nil "%s check %s" rust-cargo-bin rust-cargo-default-arguments))
(defun rust-compile ()
"Compile using `cargo build`"
(interactive)
- (rust--compile "%s build %s" rust-cargo-bin rust-cargo-default-arguments))
+ (rust--compile nil "%s build %s" rust-cargo-bin rust-cargo-default-arguments))
(defun rust-compile-release ()
"Compile using `cargo build --release`"
(interactive)
- (rust--compile "%s build --release" rust-cargo-bin))
+ (rust--compile nil "%s build --release" rust-cargo-bin))
-(defun rust-run ()
- "Run using `cargo run`"
- (interactive)
- (rust--compile "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
+(defun rust-run (&optional comint)
+ "Run using `cargo run`
-(defun rust-run-release ()
- "Run using `cargo run --release`"
- (interactive)
- (rust--compile "%s run --release" rust-cargo-bin))
+If optional arg COMINT is t or invoked with universal prefix arg,
+output buffer will be in comint mode, i.e. interactive."
+ (interactive "P")
+ (rust--compile comint "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
+
+(defun rust-run-release (&optional comint)
+ "Run using `cargo run --release`
+
+If optional arg COMINT is t or invoked with universal prefix arg,
+output buffer will be in comint mode, i.e. interactive."
+ (interactive "P")
+ (rust--compile comint "%s run --release" rust-cargo-bin))
(defun rust-test ()
"Test using `cargo test`"
(interactive)
- (rust--compile "%s test %s" rust-cargo-bin rust-cargo-default-arguments))
+ (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments))
(defun rust-run-clippy ()
"Run `cargo clippy'."
@@ -118,7 +126,7 @@
;; set `compile-command' temporarily so `compile' doesn't
;; clobber the existing value
(compile-command (mapconcat #'shell-quote-argument args " ")))
- (rust--compile compile-command)))
+ (rust--compile nil compile-command)))
;;; _
(provide 'rust-cargo)