Skip to content

Commit 6b62ad0

Browse files
committed
Support running interactive programs
1 parent e54bbae commit 6b62ad0

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ By default these are bound to:
173173
- <kbd>C-c C-c C-t</kbd> `rust-test`
174174
- <kbd>C-c C-c C-r</kbd> `rust-run`
175175

176+
To run programs requiring user input use universal argument when invoking
177+
`run-run` (<kbd>C-u C-c C-c C-r</kbd>).
178+
176179
### Clippy
177180

178181
`rust-run-clippy` runs

Diff for: rust-cargo.el

+24-16
Original file line numberDiff line numberDiff line change
@@ -67,46 +67,54 @@
6767

6868
;;; Internal
6969

70-
(defun rust--compile (format-string &rest args)
70+
(defun rust--compile (comint format-string &rest args)
7171
(when (null rust-buffer-project)
7272
(rust-update-buffer-project))
7373
(let ((default-directory
7474
(or (and rust-buffer-project
7575
(file-name-directory rust-buffer-project))
76-
default-directory)))
77-
(compile (apply #'format format-string args))))
76+
default-directory))
77+
;; make sure comint is a boolean value
78+
(comint (not (not comint))))
79+
(compile (apply #'format format-string args) comint)))
7880

7981
;;; Commands
8082

8183
(defun rust-check ()
8284
"Compile using `cargo check`"
8385
(interactive)
84-
(rust--compile "%s check %s" rust-cargo-bin rust-cargo-default-arguments))
86+
(rust--compile nil "%s check %s" rust-cargo-bin rust-cargo-default-arguments))
8587

8688
(defun rust-compile ()
8789
"Compile using `cargo build`"
8890
(interactive)
89-
(rust--compile "%s build %s" rust-cargo-bin rust-cargo-default-arguments))
91+
(rust--compile nil "%s build %s" rust-cargo-bin rust-cargo-default-arguments))
9092

9193
(defun rust-compile-release ()
9294
"Compile using `cargo build --release`"
9395
(interactive)
94-
(rust--compile "%s build --release" rust-cargo-bin))
96+
(rust--compile nil "%s build --release" rust-cargo-bin))
9597

96-
(defun rust-run ()
97-
"Run using `cargo run`"
98-
(interactive)
99-
(rust--compile "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
98+
(defun rust-run (&optional comint)
99+
"Run using `cargo run`
100100
101-
(defun rust-run-release ()
102-
"Run using `cargo run --release`"
103-
(interactive)
104-
(rust--compile "%s run --release" rust-cargo-bin))
101+
If optional arg COMINT is t or invoked with universal prefix arg,
102+
output buffer will be in comint mode, i.e. interactive."
103+
(interactive "P")
104+
(rust--compile comint "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
105+
106+
(defun rust-run-release (&optional comint)
107+
"Run using `cargo run --release`
108+
109+
If optional arg COMINT is t or invoked with universal prefix arg,
110+
output buffer will be in comint mode, i.e. interactive."
111+
(interactive "P")
112+
(rust--compile comint "%s run --release" rust-cargo-bin))
105113

106114
(defun rust-test ()
107115
"Test using `cargo test`"
108116
(interactive)
109-
(rust--compile "%s test %s" rust-cargo-bin rust-cargo-default-arguments))
117+
(rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments))
110118

111119
(defun rust-run-clippy ()
112120
"Run `cargo clippy'."
@@ -118,7 +126,7 @@
118126
;; set `compile-command' temporarily so `compile' doesn't
119127
;; clobber the existing value
120128
(compile-command (mapconcat #'shell-quote-argument args " ")))
121-
(rust--compile compile-command)))
129+
(rust--compile nil compile-command)))
122130

123131
;;; _
124132
(provide 'rust-cargo)

0 commit comments

Comments
 (0)