It's common for me to run a throwaway piece of code I'm not particularly interested in saving on my disk, so I'm often working inside emacs in a buffer not attached to any file in my system.
When working with interpreted (I'm a little reluctant to use this term) languages like Python, Scheme or Lua, each respective major mode (the common ones) offer ways of running the REPL/interpreter inside the editor and executing the content of a buffer directly. (Generally with a function called send-buffer
or something like that).
However when working with C, I cannot find a similar functionality. I find myself forced to save the file to disk, in order to give gcc
a filename as argument.
Is there a way to send the content of an emacs buffer to gcc without writing the file to disk?
Best Answer
Use
C-x h
(mark-whole-buffer
), then'M-|
(shell-command-on-region
), then use @Kotte's suggestion above to rungcc -x c -o tmp_prog - && tmp_prog
Or here's an elisp function that does it: