Using the Emacs mode for Cargo, I'm able to build and run Rust code inside Emacs. However, the terminal that opens when executing cargo-process-run does not accept user input.

For example, when running

use std::io;
fn main() {
  let mut input = String::new();

      .read_line(&mut input)
      .expect("Failed to read line.");

the terminal will hang without being capable of receiving keyboard input.

I've read that a similar problem can occur when executing compile, but this could somehow be resolved by starting in comint-mode. Unfortunately, I have not found a way to translate that solution to this scenario.

How can I resolve this?

2 Answers 2


After some research, I was able to solve it by adding this to my init.el:

(with-eval-after-load 'rust-mode
  (define-key rust-mode-map (kbd "C-r") 'my-cargo-run))
(defun my-cargo-run ()
  "Build and run Rust code."
  (let (
      (orig-win (selected-window))
      (run-win (display-buffer (get-buffer "*Cargo Run*") nil 'visible))
    (select-window run-win)
    (read-only-mode 0)
    (select-window orig-win)

The function my-cargo-run calls cargo-process-run, enables comint-mode and disables the read-only mode of the terminal. The first two lines bind the function to C-r.

I've asked the author of cargo.el to include this in the package.

  • Thanks, very helpful. For rustic-mode changing (cargo-process-run) to (rustic-cargo-run) is enough. Commented Jun 29, 2020 at 7:54
  • @Safron, is there some entry in an issue tracker for that? It's been a couple years and I don't see it in cargo.el yet.
    – daveloyall
    Commented Jul 22, 2022 at 22:20
  • @daveloyall It is tracked by github.com/kwrooijen/cargo.el/issues/29. No progress yet though...
    – Safron
    Commented Jul 23, 2022 at 9:56

Another possibility:

(defun rust-compile-send-input ()
  "Read string from minibuffer and send it to the rust process of the current
  (let ((input (read-from-minibuffer "Send input to rust process: "))
        (proc (get-buffer-process (current-buffer)))
        (inhibit-read-only t))
    (process-send-string proc (concat input "\n"))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.