C and C++ both use .h extension for headers.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 21 Oct 2010 16:05:39 +0300
changeset 499 c3390bcde246
parent 497 1848e3b1fc00
child 500 1f8c3b0b0ca3
C and C++ both use .h extension for headers. By default this file opened in c-mode. Check headers for C++ keywords to enable c++-mode.
.emacs-my
--- a/.emacs-my	Tue Oct 12 15:05:33 2010 +0300
+++ b/.emacs-my	Thu Oct 21 16:05:39 2010 +0300
@@ -980,6 +980,18 @@
 
 (add-to-list 'auto-mode-alist '("\\.js$" . js-mode))
 
+(defun my-c++-header-file-p ()
+  "Return non-nil, if in a C++ header."
+  (and (string-match "\\.h$"
+                     (or (buffer-file-name)
+                         (buffer-name)))
+       (save-excursion
+         (re-search-forward "\\_<class\\_>" nil t))))
+
+(add-to-list 'magic-mode-alist
+             '(my-c++-header-file-p . c++-mode))
+
+
 (setq-default comment-style (quote indent))
 (setq-default comment-column 44)
 (setq-default comment-fill-column my-fill-column)