0

So I've been mapping my M-x compile like this, according to c-mode-hook or c++-mode-hook:

(add-hook 'c++-mode-hook
          (lambda ()
            (set (make-local-variable 'compile-command)
                 (concat "g++ " buffer-file-name " && ./a.out"  ) )))

In other words, doing M-x compile on a c or c++ file will compile and run it.

This works but I want this to be a 2 part process. So, I will have a buffer that contains the errors from running M-x compile and another buffer, maybe eshell, that is ready to run the program.

The first one is easy, I can just do this:

(add-hook 'c++-mode-hook
          (lambda ()
            (set (make-local-variable 'compile-command)
                 (concat "g++ " buffer-file-name) )))

This does not run the ./a.out part. Now, for the second part, I know that I can just do M-x eshell, then type ./a.out and the program should run.

My question is: Is it possible to tell emacs to send "./a.out" in current directory to eshell/term? I would then have a third buffer opens that is eshell/term, where the program runs. And then I would like to bind a shortcut to this, say F6.

mle0312
  • 295
  • 1
  • 8
  • I wrote a proposed proof concept of how to send `*eshell*` commands under the hood a couple of years ago, but there was no apparent interest. I consider inserting text into a buffer for the purposes of sending a command to Eshell quite clunky, but that is an option: https://emacs.stackexchange.com/questions/7617/how-to-programmatically-execute-a-command-in-eshell/7625   A `*shell*` buffer has existing mechanism to send commands under the hood using `comint-send-string` and `comint-send-input`, the latter of which (I think) can be obviated if the string contains a newline `\n` at the end. – lawlist Jan 24 '20 at 02:04
  • Do you know about projectile? Provides the concept of projects to emacs and has the possibility to execute compile/test/run commands. The output of this gets displayed in a `*compilation*` buffer. – Swedgin Jan 24 '20 at 08:10

0 Answers0