2

I'm writing a minor mode to handle automatic spacing of operator characters, but I'm having some trouble with C/C++. The problem is that I can't figure out how to tell in general whether a * is a multiplication or a pointer type. Similarly for &, and </> in C++ .

I've currently got some basic hacks to detect the built in types (int, char, etc.) and to detect types ending in _t. I've also found the c-guess-basic-syntax function which can tell me when point is in a function header so I can handle function argument and return types. However I can't find any way to detect when point is in a normal variable declaration.

Is it possible without implementing a C compiler?

  • It should be possible for C, but not for C++ given the high complexity of the language. Probably explains why the approach of shelling out to clang is popular there. – wasamasa Jul 8 '15 at 11:37
  • 1
    If you don't mind the overhead, semantic should be able to give you all the information you need. Open up cpp file and start semantic mode and run (semantic-fetch-tags) in it, you'll see a ton of information that can be useful to you. Also with your point inside a function you can run (semantic-get-local-variables) which will give you the list of local variables and where they are declared in the current function. – Jordon Biondo Jul 8 '15 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.