Emacs lisp: is it possible (using lisp) to run command in an eshell working in other buffer? Emacs lisp: is it possible (using lisp) to run command in an eshell working in other buffer? shell shell

Emacs lisp: is it possible (using lisp) to run command in an eshell working in other buffer?


Normally, if you want to run something after the compilation has finished, you add it to the compilation command. For example, instead of

M-x compile RET make RET

You might type

M-x compile RET make && ./test RET

or you might add the program to some appropriate target in your makefile, so you can do

M-x compile RET make test RET

Maybe if you can explain why you want to run the compiled program in eshell, I could offer you better advice.


However, if you insist on using eshell, you might be able to use compilation-finish-functions:

Functions to call when a compilation process finishes. Each function is called with two arguments: the compilation buffer, and a string describing how the process finished.

This isn't all that well documented, but the string is "finished\n" if the process finished successfully. So you might do something like this:

(defun run-compilation-output-in-eshell (buf msg)  "If compilation finished successfully, switch to eshell and execute a command."  (when (string= msg "finished\n")    (eshell)    (goto-char (point-max))    (eshell-kill-input)    (insert "echo command goes here")    (eshell-send-input)))(add-hook 'compilation-finish-functions #'run-compilation-output-in-eshell)

This seems rather rude, though: if you happen to be typing into the eshell buffer when the compilation finishes, then this deletes your input. As I said above, a bit more context might be helpful.


Since it's Emacs, it's possible, but would require some Elisp hacking.

In the meantime, I'd suggest going the easy route by binding to F5 a macro that will do the following; assuming you hit F5 in c++ buffer:

  1. switch to eshell buffer
  2. run the compilation command for your program
  3. switch back to c++ buffer