Working with C++
In Code, Emacs | no comments yet | permalink
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 ()
(interactive)
(save-excursion
(goto-char (point-min))
(setq guard (concat (upcase
(file-name-sans-extension
(file-name-nondirectory buffer-file-name)))
"_H"))
(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
email this | tag this | digg this | trackback | comment RSS feed
Leave a Comment