;; Switch from header to implementation and vice versa (defun switch-cc-to-h () (interactive) (when (string-match "^\\(.*\\)\\.\\([^.]*\\)$" buffer-file-name) (let ((name (match-string 1 buffer-file-name)) (suffix (match-string 2 buffer-file-name))) (cond ((string-match suffix "c\\|cc\\|C\\|cpp") (cond ((file-exists-p (concat name ".h")) (find-file (concat name ".h")) ) ((file-exists-p (concat name ".hh")) (find-file (concat name ".hh")) ) ((file-exists-p (concat name ".hpp")) (find-file (concat name ".hpp")) ) )) ((string-match suffix "h\\|hh\\|hpp") (cond ((file-exists-p (concat name ".cc")) (find-file (concat name ".cc")) ) ((file-exists-p (concat name ".C")) (find-file (concat name ".C")) ) ((file-exists-p (concat name ".cpp")) (find-file (concat name ".cpp")) ) ((file-exists-p (concat name ".c")) (find-file (concat name ".c")) ))))))) (add-hook 'c++-mode-hook (lambda () (define-key c++-mode-map [(control f12)] 'switch-cc-to-h) ))