7

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.

5 Answers 5

9

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

@Jéôme Radix: Someone already mentioned flymake, and as I said I'm sceptical to this since I work a lot when on battery power. I guess it's something to check out, though.
1

if you're interested in something a bit different, you could write all your little piece into snippets, using the YAsnippet package, then you could type something like #in, hit TAB, and it will expand into... whatever you want.

1 Comment

I already use YAsnippet for various things but for includes I find that it's faster just to type it out myself.
0

Sounds like flymake is exactly what your after. It runs a compiler in the background, and will hightlight errors, as you type.

2 Comments

I'm sceptical... seems like that would waste a lot of CPU time for little bemefit, and be a nuance in itself since I would have to turn it off whenever I'm on battery power.
I have not found it an issue myself, and arnt most compilers capable of reusing large ammounts of object code, resulting in only partial compiles?
0

I was going to suggest that this could be a slightly odd application for flyspell, but danlei's answer looks better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.