Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,28 @@ sent to the program in one of two ways:
input can be typed directly into the output buffer of 'cargo run'
and sent off with `RET`, just like in `comint-mode`. You need
[polymode](https://polymode.github.io) installed for this to work.

#### Run Arguments

The run arguments of the `cargo run` command is determined by the
`rustic-run-arguments` variable.

By default, any of the run commands will ask the user what the run arguments
should be in the minibuffer and stored in the `rustic-run-arguments` variable.
However if the `rustic-cargo-use-last-stored-arguments` variable is set to a non
`nil` value, the previously stored value of `rustic-run-arguments` would be used.

An alternative way of specify the run arguments would be using the function
arguments. If it is set to a non `nil` value the argument would be used and
stored in `rustic-run-arguments` instead.

For example:

``` elisp
(rustic-cargo-run "-r")
```

The `cargo run` would be run with the argument "-r".

### Outdated

Expand Down
26 changes: 20 additions & 6 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@ If BIN is not nil, create a binary application, otherwise a library."
(define-derived-mode rustic-cargo-run-mode rustic-compilation-mode "cargo-run"
:group 'rustic)

(defun rustic-ask-run-args ()
"Asks the cargo run arguments for cargo run from the minibuffer.

The run arguments is stored in rustic-run-arguments."
(interactive)
(setq rustic-run-arguments (read-from-minibuffer
"Cargo run arguments: " rustic-run-arguments)))

;;;###autoload
(defun rustic-cargo-run-command (&optional run-args)
"Start compilation process for 'cargo run' with optional RUN-ARGS."
Expand All @@ -601,17 +609,23 @@ If BIN is not nil, create a binary application, otherwise a library."
(defun rustic-cargo-run (&optional arg)
"Run 'cargo run'.

TODO: Auto specify example/bin based on file.

If ARG is not nil, use value as argument and store it in `rustic-run-arguments'.
When calling this function from `rustic-popup-mode', always use the value of
`rustic-run-arguments'."

When calling this function from `rustic-popup-mode' or
`rustic-cargo-use-last-stored-arguments' is not nil, always use the value of
`rustic-run-arguments'.

Otherwise the arguments are taken from the minibuffer."
(interactive "P")
(rustic-cargo-run-command
(cond (arg
(setq rustic-run-arguments (read-from-minibuffer "Cargo run arguments: " rustic-run-arguments)))
(cond (arg (setq rustic-run-arguments arg))
;; Using stored arguments
(rustic-cargo-use-last-stored-arguments
rustic-run-arguments)
((rustic--get-run-arguments))
(t rustic-run-arguments))))
;; Asking from minibuffer
(t (rustic-ask-run-args)))))

;;;###autoload
(defun rustic-cargo-run-rerun ()
Expand Down
62 changes: 38 additions & 24 deletions rustic-comint.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ hit RET to send it to the program."
(defun rustic-cargo-comint-run (&optional arg)
"Run 'cargo run' but for interactive programs.


TODO: Auto specify example/bin based on file.

If ARG is not nil, use value as argument and store it in `rustic-run-arguments'.
When calling this function from `rustic-popup-mode', always use the value of
`rustic-run-arguments'."

When calling this function from `rustic-popup-mode' or
`rustic-cargo-use-last-stored-arguments' is not nil, always use the value of
`rustic-run-arguments'.

Otherwise the arguments are taken from the minibuffer."
(interactive "P")
(rustic--inheritenv
(let ((run-args (rustic--get-run-arguments)))
Expand All @@ -61,12 +68,12 @@ When calling this function from `rustic-popup-mode', always use the value of
(unless (comint-check-proc (current-buffer))
(rustic--cargo-repl-in-buffer
(current-buffer)
(concat "run" (cond
(arg
(setq rustic-run-comint-arguments
(read-from-minibuffer "Cargo run arguments: " rustic-run-comint-arguments)))
(run-args)
(t ""))))
(concat "run " (cond (arg (setq rustic-run-arguments arg))
;; Using stored arguments
(rustic-cargo-use-last-stored-arguments
rustic-run-arguments)
;; Asking from minibuffer
(t (rustic-ask-run-args)))))
(rustic-cargo-run-comint-mode)))))

;;;###autoload
Expand All @@ -78,18 +85,18 @@ When calling this function from `rustic-popup-mode', always use the value of
(get-buffer-create rustic-run-comint-buffer-name))
(rustic--cargo-repl-in-buffer
(current-buffer)
(concat "run" rustic-run-comint-arguments))))
(concat "run" rustic-run-arguments))))

(defun rustic--cargo-repl-in-buffer (buffer run-args)
"Make Cargo comint Repl in BUFFER.
Optionally accepts RUN-ARGS which will be passed to the
executable."
(make-comint-in-buffer
(apply 'make-comint-in-buffer
rustic-run-comint-buffer-name
buffer
(rustic-cargo-bin)
'()
run-args))
(split-string run-args)))

;;; Cargo run with plain comint and optional polymode

Expand All @@ -108,20 +115,27 @@ executable."
;;;###autoload
(defun rustic-cargo-plain-run (&optional arg)
"Run `cargo run' for the current project.
Read the full command from the minibuffer when ARG is non-nil or
when called with a prefix command \\[universal-argument]."

TODO: Auto specify example/bin based on file.

If ARG is not nil, use value as argument and store it in `rustic-run-arguments'.

When calling this function from `rustic-popup-mode' or
`rustic-cargo-use-last-stored-arguments' is not nil, always use the value of
`rustic-run-arguments'.

Otherwise the arguments are taken from the minibuffer."
(interactive "P")
(let* ((command (if arg
(read-from-minibuffer "Cargo run command: " "cargo run -- ")
(concat (rustic-cargo-bin) " run "
(setq rustic-run-arguments
(read-from-minibuffer
"Run arguments: "
(if (rustic-cargo-run-get-relative-example-name)
(concat "--example "
(rustic-cargo-run-get-relative-example-name))
(car compile-history))
nil nil 'compile-history)) ))))
;; (if (rustic-cargo-run-get-relative-example-name)
;; (concat "--example " (rustic-cargo-run-get-relative-example-name))
;; (car compile-history))
(let* ((command (concat (rustic-cargo-bin) " run "
(cond (arg (setq rustic-run-arguments arg))
;; Using stored arguments
(rustic-cargo-use-last-stored-arguments
rustic-run-arguments)
;; Asking from minibuffer
(t (rustic-ask-run-args))))))
(rustic-run-cargo-command command (list :mode 'rustic-cargo-plainrun-mode))))

(define-derived-mode rustic-cargo-plain-run-mode rustic-compilation-mode "Cargo run"
Expand Down