Set .h group in C ++ - mode in emacs

I'm not quite sure if this question is related to stackoverflow or superuser (is there any emacs file exchange?). Based on the meta.stackoverflow post, I assume that it does.

My emacs by default uses header files (from the .h version) in c mode. I can easily enter Mx C ++ mode and return the selection back, but because I program more often in C ++ than c. I was wondering what I need to change to add .h to the C ++ group.

+4
source share
2 answers

Here is what I have in the .emacs file:

; Make .h files be C++ mode (setq auto-mode-alist(cons '("\\.h$" . c++-mode) auto-mode-alist)) 

There may be an easier way, but it works.

+7
source

Well, here's what many do:

  // -*-c++-*- 

This line at the top of the header tells emacs its C ++.

I like this better than just calling all .h C ++ files, because some of them are not. Although I must admit, although it annoys me because of its ugliness, I took to call my header files .hpp .: - /

+3
source

All Articles