dargscisyhp · 2022-03-25 22:35
Hello,
I'm learning how to code in C, and was wondering what workflow you guys use for the edit->compile->run->edit cycle. Currently I have a second window with vterm popped up where I issue my gcc/run commands, however I was wondering if other's use different methods.
Thanks.
super-linux-nerd · 2022-03-25 23:11
`M-x compile`
ieure · 2022-03-26 00:34
Yep, this, or `projectile-compile-project` / `projectile-test-project`, which end up calling `compile`.
arthurno1 · 2022-03-26 02:17
> Currently I have a second window with vterm popped up where I issue my gcc/run commands
No, that asks you to constantly switch between windows/frames. And you don't really benefit from Emacs built in integration with the gcc compiler. As suggested, check compile command.
I suggest also to start using makefiles; there are a lots of pre-written, generic makefiles for all kind of projects, if you are not used to write your own, which you can just drop-in into your projects. Here you can find some tips on how to automatically get Emacs to find a "closest" makefile and compile/recompile your project with a key shortcuts (via compile command):
https://www.emacswiki.org/emacs/CompileCommand
fragbot2 · 2022-03-26 06:48
My personal favorite:
(global-set-key (kbd "<f12>") 'compile)
AsterOps · 2022-03-26 07:00
for learning purpose point number 5) from this link is quite useful: [https://linuxhint.com/c\_emacs\_configuration/](https://linuxhint.com/c_emacs_configuration/)
it's similar behavior like from Visual Studio
oantolin · 2022-03-26 16:52
Running programs in terminals typically produces dead text: text you can only read but not meaningfully interact with. Running those same commands with a nice Emacs wrapper produces text you can really use, so I highly recommend using Emacs wrappers around tools whenever possible. For compilation this means using `M-x compile` as others have already mentioned: you get a nice buffer with compilation errors that work as hyperlinks to the location of the error. You can click on one with the mouse¹ or move point to it and press `RET`. But you don't even have to go the compilation output buffer: the commands `next-error` and `previous-error` bound by default to `M-g n` and `M-g p` (among other bindings) will move you between error locations too.
The same goes for running `grep` in a terminal: you get dead text, but `M-x grep` provides you navigation functionality similar to `M-x compile`. Say no to dead text.
----
¹ I assume, I actually don't use the mouse much, but Emacs usually let's you use either keyboard or mouse for link-like things.
DrownNotably · 2022-03-27 11:12
I do something similar, but I set it to recompile instead, so I don't get the minibuffer prompt.