Skip to content

Commit

Permalink
Allow rustic-compile to accept a command argument
Browse files Browse the repository at this point in the history
Previous it required binding compilation-arguments to pass an arg to it.
  • Loading branch information
CeleritasCelery committed Oct 12, 2024
1 parent fb41de5 commit 9237c94
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
28 changes: 13 additions & 15 deletions rustic-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,19 @@ buffer."
;;; Interactive

;;;###autoload
(defun rustic-compile (&optional arg)
"Compile rust project.
If the variable `compilation-read-command' is non-nil or if
`rustic-compile` is called with prefix argument ARG then read the
command in the minibuffer. Otherwise use
`rustic-compile-command'.
In either store the used command in `compilation-arguments'."
(interactive "P")
(rustic-set-compilation-arguments
(if (or compilation-read-command arg)
(compilation-read-command (or (car compilation-arguments)
(rustic-compile-command)))
(rustic-compile-command)))
(defun rustic-compile (command)
"Run COMMAND in the current Rust workspace root.
Interactively, prompts for the command if the variable
`compilation-read-command' is non-nil; otherwise uses
`rustic-compile-command'."
(interactive
(list
(if compilation-read-command
(compilation-read-command (or (car compilation-arguments)
(rustic-compile-command)))
(rustic-compile-command))))
(rustic-set-compilation-arguments command)
(setq compilation-directory (funcall rustic-compile-directory-method))
(rustic-compilation-process-live)
(rustic-compilation-start (split-string (car compilation-arguments))
Expand Down
6 changes: 2 additions & 4 deletions test/rustic-clippy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
(let* ((buffer1 (get-buffer-create "b1"))
(string "fn main() { String::from(' ').extend(String::from(' ').chars()); } ")
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
(dir (rustic-babel-generate-project t))
(compilation-read-command nil))
(dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(src (concat dir "/src"))
(file1 (expand-file-name "main.rs" src))
Expand Down Expand Up @@ -63,8 +62,7 @@
(let* ((buffer1 (get-buffer-create "b1"))
(string "ffn main() { String::from(' ').extend(String::from(' ').chars()); } ")
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
(dir (rustic-babel-generate-project t))
(compilation-read-command nil))
(dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(src (concat dir "/src"))
(file1 (expand-file-name "main.rs" src))
Expand Down
26 changes: 19 additions & 7 deletions test/rustic-compile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@

(ert-deftest rustic-test-compile ()
(let* ((dir (rustic-babel-generate-project t)))
(should-not compilation-directory)
(should-not compilation-arguments)
(setq compilation-arguments "cargo fmt")
(let* ((default-directory dir)
(proc (rustic-compile "cargo fmt")))
(should (process-live-p proc))
(while (eq (process-status proc) 'run)
(sit-for 0.1))
(should (string= compilation-directory dir))
(let ((proc (rustic-recompile)))
(while (eq (process-status proc) 'run)
(sit-for 0.1)))
(should (string= (car compilation-arguments) "cargo fmt"))
(should (string= compilation-directory dir))))
(setq compilation-directory nil)
(setq compilation-arguments nil))

(ert-deftest rustic-test-compile-interactive ()
(let* ((dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(compilation-read-command nil)
(proc (rustic-compile)))
(proc (call-interactively 'rustic-compile)))
(should (process-live-p proc))
(while (eq (process-status proc) 'run)
(sit-for 0.1))
Expand All @@ -107,10 +120,9 @@
(let* ((string "fn main() { let s = 1;}")
(buf (rustic-test-count-error-helper-new string))
(default-directory (file-name-directory (buffer-file-name buf)))
(rustic-format-trigger nil)
(compilation-read-command nil))
(rustic-format-trigger nil))
(with-current-buffer buf
(let* ((proc (rustic-compile))
(let* ((proc (rustic-compile "cargo build"))
(buffer (process-buffer proc)))
(while (eq (process-status proc) 'run)
(sit-for 0.01))
Expand Down
6 changes: 2 additions & 4 deletions test/rustic-window-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
(ert-deftest rustic-test-window-count ()
(should (= (length (window-list)) 1))
(let* ((dir (rustic-babel-generate-project t)))
(setq compilation-arguments "cargo fmt")
(let* ((default-directory dir)
(compilation-read-command nil))
(rustic-compile)
(let* ((default-directory dir))
(rustic-compile "cargo fmt")
(rustic-test--wait-till-finished rustic-compilation-buffer-name)
(should (= (length (window-list)) 2))
(should (get-buffer-window rustic-compilation-buffer-name)))))
Expand Down

0 comments on commit 9237c94

Please sign in to comment.