Ramblings of a code junkie

November 1, 2006

Working with C++

Written by

Lets start the revamp with a somewhat usefull post, for the Emacs inclined…

As most of the Emacs users I write Emacs Lisp to make my life easier at times. Since I have been writing a lot of C++ lately for the fun of it I run into some small annoyances at times, like creating header guards; the #ifndef, #define, #endif sequence you write to prevent including a header file more then once. So I cooked up a small lisp function to insert them for me:

(defun cxx-create-gaurds ()
    (goto-char (point-min))
    (setq guard (concat (upcase
                          (file-name-nondirectory buffer-file-name)))
    (insert "#ifndef " guard  "\n")
    (insert "#define " guard  "\n")
    (goto-char (point-max))
    (insert "\n#endif // " guard "\n")))

Just bind it to an available keybinding and thats one less annoyance in this world :)

Zarro Taags!

Leave a Comment