There's a small nuance that's been bugging me for a while, namely that I frequently type #inclued
instead of #include
. If it wasn't obvious, I program a lot of C and C++. That typo has wrecked countless builds and consumed time that would have been better spent drinking coffee or surfing stackoverflow. Surely emacs can be helpful and rectify my mistakes as I type (in cc-mode
only, of course). But how?
Googling and searching stackoverflow didn't provide any answers.
You could use this in abbrev-mode: After you entered #inclued, do C-x a i g include RET
, and from then on, every time you type #inclued, it will be changed to #include automatically. If you want that abbrev to be local to a mode, use C-x a i l
instead of C-x a i g
. Also, you can edit your abbrevs with M-x edit-abbrevs
.
A nicier and more global solution than abbrevs (because you can't predict all the typos you'll make) is to use flymake (which comes with emacs distribution).
http://flymake.sourceforge.net/
Flymake checks your source code behind the scene while you're still typing your code into the buffer. It highlights what's wrong with your code (that is : what gcc tells is wrong).
Running gcc in the background does not use more CPU than your antivirus bloatware. Moreover, if you have 2 or more cores, gcc can take advantage of parallelization. It only checks the syntax, not compiling anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With