i wanted to bind a key to a compile and run command, then i found this post, Compile and run single file c++ programs in Emacs[SOLVED] ( last answer)
It works perfectly fine and as intended.
The only problem i am having is: is it possible to run the "compile" process in the eshell or in the shell instead of the "compile" shell? The problem with the "compile" shell is that i am unable to write anything after the program exited.
For those who dont want to click on the link,here is the elisp function, even tho i dont think it has much to do with the question:
(defun compileandrun()
(interactive)
(save-buffer)
(compile (concat "g++ " (file-name-nondirectory (buffer-file-name)) " -o " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) " && ./" (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))) t )
(other-window 1)
(end-of-buffer)
)
(add-hook 'c++-mode-hook
(lambda () (local-set-key (kbd "<f8>") #'compileandrun)))
```
eshell
, but you cannot usecompilation-mode
in aneshell
buffer. If you want the goodies ofcompilation-mode
, then you'll need to stick with using thecompile.el
library. You can continue to execute new commands withcompile
provided that you have the correct working directory, or youlet
-bind thedefault-directory
for the duration of thecompile
command. E.g,(defun make () (interactive) (compile "make"))
; or,M-x eval-expression RET (compile "make install") RET
. FYI:eshell
is able to process Lisp expressions at the command prompt. – lawlist Jul 24 '20 at 19:43compilation-minor-mode
which you can temporarily activate to have the goodies ofcompilation-mode
. I just wrote a little C++ test program and put intentionally an error in there. I rung++ test.cc -o test.exe
in an Eshell and switched onM-x compilation-minor.mode
afterwards. The errors are highlighted like incompilation-mode
and clicking on the error lines in the Eshell buffer sends me to the occurrence of the error in the C++ file. When I am done with debugging I can switchcompilation-minor-mode
off and use the Eshell buffer as usual. – Tobias Jul 25 '20 at 13:01