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.

  • 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: emacs.stackexchange.com/questions/7617/… 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 at 2: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 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.