Skip to content

Commit 34abafb

Browse files
Allow rustic-compile to accept a command argument
Previous it required binding compilation-arguments to pass an arg to it.
1 parent 0d79e4c commit 34abafb

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

rustic-compile.el

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,19 @@ buffer."
537537
;;; Interactive
538538

539539
;;;###autoload
540-
(defun rustic-compile (&optional arg)
541-
"Compile rust project.
542-
543-
If the variable `compilation-read-command' is non-nil or if
544-
`rustic-compile` is called with prefix argument ARG then read the
545-
command in the minibuffer. Otherwise use
546-
`rustic-compile-command'.
547-
548-
In either store the used command in `compilation-arguments'."
549-
(interactive "P")
550-
(rustic-set-compilation-arguments
551-
(if (or compilation-read-command arg)
552-
(compilation-read-command (or (car compilation-arguments)
553-
(rustic-compile-command)))
554-
(rustic-compile-command)))
540+
(defun rustic-compile (command)
541+
"Run COMMAND in the current Rust workspace root.
542+
543+
Interactively, prompts for the command if the variable
544+
`compilation-read-command' is non-nil; otherwise uses
545+
`rustic-compile-command'."
546+
(interactive
547+
(list
548+
(if compilation-read-command
549+
(compilation-read-command (or (car compilation-arguments)
550+
(rustic-compile-command)))
551+
(rustic-compile-command))))
552+
(rustic-set-compilation-arguments command)
555553
(setq compilation-directory (funcall rustic-compile-directory-method))
556554
(rustic-compilation-process-live)
557555
(rustic-compilation-start (split-string (car compilation-arguments))

test/rustic-clippy-test.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
(let* ((buffer1 (get-buffer-create "b1"))
1111
(string "fn main() { String::from(' ').extend(String::from(' ').chars()); } ")
1212
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
13-
(dir (rustic-babel-generate-project t))
14-
(compilation-read-command nil))
13+
(dir (rustic-babel-generate-project t)))
1514
(let* ((default-directory dir)
1615
(src (concat dir "/src"))
1716
(file1 (expand-file-name "main.rs" src))
@@ -63,8 +62,7 @@
6362
(let* ((buffer1 (get-buffer-create "b1"))
6463
(string "ffn main() { String::from(' ').extend(String::from(' ').chars()); } ")
6564
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
66-
(dir (rustic-babel-generate-project t))
67-
(compilation-read-command nil))
65+
(dir (rustic-babel-generate-project t)))
6866
(let* ((default-directory dir)
6967
(src (concat dir "/src"))
7068
(file1 (expand-file-name "main.rs" src))

test/rustic-compile-test.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,25 @@
8585

8686
(ert-deftest rustic-test-compile ()
8787
(let* ((dir (rustic-babel-generate-project t)))
88-
(should-not compilation-directory)
89-
(should-not compilation-arguments)
90-
(setq compilation-arguments "cargo fmt")
88+
(let* ((default-directory dir)
89+
(proc (rustic-compile "cargo fmt")))
90+
(should (process-live-p proc))
91+
(while (eq (process-status proc) 'run)
92+
(sit-for 0.1))
93+
(should (string= compilation-directory dir))
94+
(let ((proc (rustic-recompile)))
95+
(while (eq (process-status proc) 'run)
96+
(sit-for 0.1)))
97+
(should (string= (car compilation-arguments) "cargo fmt"))
98+
(should (string= compilation-directory dir))))
99+
(setq compilation-directory nil)
100+
(setq compilation-arguments nil))
101+
102+
(ert-deftest rustic-test-compile-interactive ()
103+
(let* ((dir (rustic-babel-generate-project t)))
91104
(let* ((default-directory dir)
92105
(compilation-read-command nil)
93-
(proc (rustic-compile)))
106+
(proc (call-interactively 'rustic-compile)))
94107
(should (process-live-p proc))
95108
(while (eq (process-status proc) 'run)
96109
(sit-for 0.1))
@@ -107,10 +120,9 @@
107120
(let* ((string "fn main() { let s = 1;}")
108121
(buf (rustic-test-count-error-helper-new string))
109122
(default-directory (file-name-directory (buffer-file-name buf)))
110-
(rustic-format-trigger nil)
111-
(compilation-read-command nil))
123+
(rustic-format-trigger nil))
112124
(with-current-buffer buf
113-
(let* ((proc (rustic-compile))
125+
(let* ((proc (rustic-compile "cargo build"))
114126
(buffer (process-buffer proc)))
115127
(while (eq (process-status proc) 'run)
116128
(sit-for 0.01))

test/rustic-window-test.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
(ert-deftest rustic-test-window-count ()
88
(should (= (length (window-list)) 1))
99
(let* ((dir (rustic-babel-generate-project t)))
10-
(setq compilation-arguments "cargo fmt")
11-
(let* ((default-directory dir)
12-
(compilation-read-command nil))
13-
(rustic-compile)
10+
(let* ((default-directory dir))
11+
(rustic-compile "cargo fmt")
1412
(rustic-test--wait-till-finished rustic-compilation-buffer-name)
1513
(should (= (length (window-list)) 2))
1614
(should (get-buffer-window rustic-compilation-buffer-name)))))

0 commit comments

Comments
 (0)