Starter Kit C++
This is part of the Emacs Starter Kit.
Starter Kit C++
Set C++ mode for *.h
and *.ipp
files (instead of plain-old C mode)
(setq auto-mode-alist (cons '("\\.h$" . c++-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.ipp$" . c++-mode) auto-mode-alist))
Running starter-kit-coding-hook
(add-hook 'c-mode-common-hook 'run-starter-kit-coding-hook)
Un/fold function/namespace definitions
(add-hook 'c-mode-common-hook (lambda () ;; hungry delete ;;(c-toggle-hungry-state t) (whitespace-mode t)))
Compilation
Scroll down compilation messages
(setq compilation-scroll-output t)
Send notification when compilation is done
(defun compile-notify (buffer message) (sk-popup "Emacs compilation" message)) (setq compilation-finish-function 'compile-notify)
Bury compilation buffer
If compilation is successful namely neither errors nor warnings, the compilation buffer will disappear after 1 second. Stolen from stackoverflow.
(defun sk-bury-compile-buffer-if-successful (buffer string) "Bury a compilation buffer if succeeded without warnings " (if (and (string-match "compilation" (buffer-name buffer)) (string-match "finished" string) (not (with-current-buffer buffer (search-forward "warning" nil t)))) (run-with-timer 1 nil (lambda (buf) (bury-buffer buf) (switch-to-prev-buffer (get-buffer-window buf) 'kill)) buffer))) (add-hook 'compilation-finish-functions 'sk-bury-compile-buffer-if-successful)
cpputils-cmake
From https://github.com/redguardtoo/cpputils-cmake
(add-hook 'c++-mode-hook (lambda () (cppcm-reload-all))) (setq cppcm-build-dirname "__build-Linux-x86_64")
Tags
The following code makes use to etags
program to generate a list of tags and
to ease the code navigation.
Create TAGS table
(defun sk-create-tags(dirname name) "Create tags file." (interactive "DDirectory: \nsName suffix: ") (shell-command (format "find %s -type f \\( -name '*.cc' -o -name '*.h' \\) | etags - && mv %s/TAGS %s/TAGS-%s" dirname default-directory temporary-file-directory name)))
Set TAGS filename
(setq tags-file-name (concat temporary-file-directory "TAGS"))
No indentation within namespace block
(defconst my-cc-style '("cc-mode" (c-offsets-alist . ((innamespace . [0]))))) (c-add-style "my-cc-mode" my-cc-style)