4

It has been difficult to see immediately the types of variables in C++ codes because they are defined using 'auto', 'template' and 'decltype'.
If you use IDE, you can detect the type after the compilation by being a cursor on the variable.
My question is, does an emacs package exist to achieve such a function?

  • I think your best bet will be irony-mode as suggested by @GuillaumePapin. With Function-Args disabled I still get mini-buffer descriptions of auto type variables - which were of type auto before compilation. So no, you cannot get this behaviour alone with Function-Args - my apologies. Will my check .emacs.d and get back to you. – nyameko Feb 28 '17 at 9:17
  • Thank you for sincere coping. I decided to use irony-mode as suggested by @GuillaumePapin. However, as he said, irony-mode is not enough to display the types of any variables in C++ codes. I think the demand of more powerful packages will be increasing. – rosetta-jpn Feb 28 '17 at 10:59
5

With irony-mode, you can use M-x irony-get-type RET. This probably won't work for everything but it worked for the following snippet:

int main()
{
   auto var = 1.0;
   return var;
}

Having the cursor on any of the two var, and calling M-x irony-get-type RET, returns: double in the minibuffer.

  • Helpful answer. Just to make this complete, I would add a key binding in my .emacs to get the type result without a need to type in the command each time. For example: (global-set-key [C-f1] 'irony-get-type) – ElazarR Mar 1 '17 at 7:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.