brotzeit / rustic

Rust development environment for Emacs
Apache License 2.0
728 stars 102 forks source link

Is it normal that the *rustic-compilation* buffer is read only? #173

Closed parvizfarnia closed 3 years ago

parvizfarnia commented 4 years ago

I'm completely a beginner in using rustic and I wasn't sure to write this topic here as an "Issue" or rather post it on a forum because I don't really know whether it is actually a bug. Here is my problem: When I press C-c C-c C-r the program is run via cargo run and there is a new buffer in Emacs labled: * rustic-compilation * where you can view the output of cargo run. However it seems to me that unlike a classic terminal you don't have the possibility to provide any input value to the program. Consider the following example (from The Book on Rust web site)

use std::io;

fn main() {
    println!("Guess the number!");

    println!("Please input your guess.");

    let mut guess = String::new();

    io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");

    println!("You guessed: {}", guess);
}

Here the program, waits for the user to enter a value, yet there is no possibility to enter a value in the * rustic-compilation * buffer and it seems to me that this buffer is somewhat locked/read-only. Am I missing something here or this is indeed how the buffer has been implemented, that is without any user interaction?

Thanks in advance,

parvizfarnia commented 4 years ago

I slightly modified a solution that I found in this thread: Cargo-process does not accept user input

The following (added to my init.el) solved the problem:

(defun my-cargo-run ()
  "Build and run Rust code."
  (interactive)
  (rustic-cargo-run)
  (let (
      (orig-win (selected-window))
      (run-win (display-buffer (get-buffer "*rustic-compilation*") nil 'visible))
    )
    (select-window run-win)
    (comint-mode)
    (read-only-mode 0)
  )
)
(define-key rustic-mode-map (kbd "C-*") 'my-cargo-run)
brotzeit commented 4 years ago

Yeah I just realized that regular compilation-mode also behaves this way. I will change it.

dcguim commented 2 years ago

I am still experiencing the same problem in package 20220625.2008. When I execute rustic-cargo-run in my rustic session, rustic compiles and run my code, and attempts to write in the cargo-run emacs buffer. If I provide integers and press enter, I get:

user-error: No (^error[^:]*:[^
]*
 *--> \([^
]+\):\([0-9]+\):\([0-9]+\) 1 2 3) here

The rust program I am executing is exactly the same as above.

brotzeit commented 2 years ago

You can try rustic-cargo-comint-run instead.

dcguim commented 2 years ago

I tried M-x rustic-cargo-comint-run, please follow the backtrace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  expand-file-name(nil)
  file-relative-name(nil "/Users/dguim/work/rust/hello_cargo/")
  rustic-cargo-run-get-relative-example-name()
  rustic--get-run-arguments()
  rustic-cargo-comint-run(nil)
  funcall-interactively(rustic-cargo-comint-run nil)
  call-interactively(rustic-cargo-comint-run record nil)
  command-execute(rustic-cargo-comint-run record)
  execute-extended-command(nil "rustic-cargo-comint-run" "rustic-cargo-comint-ru")
  funcall-interactively(execute-extended-command nil "rustic-cargo-comint-run" "rustic-cargo-comint-ru")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

It seems rustic-cargo-run-comint-run is failing to fetch the cargo run -- arg from (rustic--get-run-arguments).

brotzeit commented 2 years ago

I didn't add this feature, because I don't use cargo run. Can you please open a new issue. It would also be a good opportunity to fix a few lines of elisp for anybody who is interested ;)