@@ -170,10 +170,14 @@ Currently only working with lsp-mode."
170170Tests that are executed by `rustic-cargo-current-test' will also be
171171stored in this variable." )
172172
173+ (defvar rustic-test-history nil
174+ " Holds previous arguments for 'cargo test', similar to `compile-arguments`." )
175+
173176(defvar rustic-cargo-test-mode-map
174177 (let ((map (make-sparse-keymap )))
175178 (set-keymap-parent map rustic-compilation-mode-map)
176179 (define-key map [remap recompile] 'rustic-cargo-test-rerun )
180+ (define-key map (kbd " C-c C-t" ) 'rustic-cargo-test-rerun-current )
177181 map)
178182 " Local keymap for `rustic-cargo-test-mode' buffers." )
179183
@@ -237,7 +241,8 @@ If ARG is not nil, use value as argument and store it in
237241 (list (rustic-cargo-package-argument)
238242 rustic-test-arguments
239243 rustic-cargo-build-arguments
240- rustic-default-test-arguments)))))
244+ rustic-default-test-arguments))
245+ nil nil 'rustic-test-history )))
241246 (rustic-cargo-use-last-stored-arguments
242247 (if (> (length rustic-test-arguments) 0 )
243248 rustic-test-arguments
@@ -246,20 +251,47 @@ If ARG is not nil, use value as argument and store it in
246251 rustic-default-test-arguments))))
247252
248253;;;### autoload
249- (defun rustic-cargo-test-rerun ()
254+ (defun rustic-cargo-test-rerun (arg )
250255 " Run 'cargo test' with `rustic-test-arguments' ."
251- (interactive )
256+ (interactive " P " )
252257 (let ((default-directory (or rustic-compilation-directory default-directory)))
258+ (setq rustic-test-arguments
259+ (if arg
260+ (read-from-minibuffer " Cargo test arguments: " rustic-test-arguments nil nil 'rustic-test-history )
261+ rustic-test-arguments))
262+ (rustic-cargo-test-run rustic-test-arguments)))
263+
264+ (defun rustic-cargo-test-rerun-current (arg )
265+ " Rerun the test at point from `rustic-cargo-test-mode' ."
266+ (interactive " P" )
267+ (let* ((default-directory (or rustic-compilation-directory default-directory))
268+ (test (rustic-cargo--get-test-at-point))
269+ (command (if test
270+ (concat " -- --exact " test)
271+ (error " No test found at point " ))))
272+ (setq rustic-test-arguments
273+ (if arg
274+ (read-from-minibuffer " Cargo test arguments: " command nil nil 'rustic-test-history )
275+ command))
253276 (rustic-cargo-test-run rustic-test-arguments)))
254277
278+ (defun rustic-cargo--get-test-at-point ()
279+ (save-excursion
280+ (beginning-of-line )
281+ (when (re-search-forward " ^test \\ ([^ ]+\\ ) ..." (line-end-position ) t )
282+ (buffer-substring-no-properties (match-beginning 1 ) (match-end 1 )))))
283+
255284;;;### autoload
256285(defun rustic-cargo-current-test ()
257286 " Run 'cargo test' for the test near point."
258287 (interactive )
259288 (rustic-compilation-process-live)
260289 (-if-let (test-to-run (setq rustic-test-arguments
261290 (rustic-cargo--get-test-target)))
262- (rustic-cargo-run-test test-to-run)
291+ (progn
292+ (unless (equal (car rustic-test-history) test-to-run)
293+ (push test-to-run rustic-test-history))
294+ (rustic-cargo-run-test test-to-run))
263295 (message " Could not find test at point. " )))
264296
265297(defun rustic-cargo-run-test (test )
@@ -645,6 +677,9 @@ If BIN is not nil, create a binary application, otherwise a library."
645677(defvar rustic-run-arguments " "
646678 " Holds arguments for 'cargo run', similar to `compilation-arguments`." )
647679
680+ (defvar rustic-run-history nil
681+ " Holds previous arguments for 'cargo run', similar to `compile-history`." )
682+
648683(defvar rustic-cargo-run-mode-map
649684 (let ((map (make-sparse-keymap )))
650685 (define-key map [remap recompile] 'rustic-cargo-run-rerun )
@@ -676,17 +711,24 @@ When calling this function from `rustic-popup-mode', always use the value of
676711 (interactive " P" )
677712 (rustic-cargo-run-command
678713 (cond (arg
679- (setq rustic-run-arguments (read-from-minibuffer " Cargo run arguments: " rustic-run-arguments)))
714+ (setq rustic-run-arguments
715+ (read-from-minibuffer " Cargo run arguments: "
716+ rustic-run-arguments nil nil 'rustic-run-history )))
680717 (rustic-cargo-use-last-stored-arguments
681718 rustic-run-arguments)
682719 ((rustic--get-run-arguments))
683720 (t rustic-run-arguments))))
684721
685722;;;### autoload
686- (defun rustic-cargo-run-rerun ()
723+ (defun rustic-cargo-run-rerun (arg )
687724 " Run 'cargo run' with `rustic-run-arguments' ."
688- (interactive )
725+ (interactive " P " )
689726 (let ((default-directory (or rustic-compilation-directory default-directory)))
727+ (setq rustic-run-arguments
728+ (if arg
729+ (read-from-minibuffer " cargo run arguments: "
730+ rustic-run-arguments nil nil 'rustic-run-history )
731+ rustic-run-arguments))
690732 (rustic-cargo-run-command rustic-run-arguments)))
691733
692734(defun rustic--get-run-arguments ()
0 commit comments