Opening a header file in Emacs
I use the following function from the "find-file-hook" in order to choose between using objc-mode, c++-mode and c-mode when opening a ".h" file:
(defun bh-choose-header-mode () (interactive) (if (string-equal (substring (buffer-file-name) -2) ".h") (progn ;; OK, we got a .h file, if a .m file exists we'll assume it's ; an objective c file. Otherwise, we'll look for a .cpp file. (let ((dot-m-file (concat (substring (buffer-file-name) 0 -1) "m")) (dot-cpp-file (concat (substring (buffer-file-name) 0 -1) "cpp"))) (if (file-exists-p dot-m-file) (progn (objc-mode) ) (if (file-exists-p dot-cpp-file) (c++-mode) ) ) ) ) ) ) (add-hook 'find-file-hook 'bh-choose-header-mode)
