Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
elisp function for generating header guards for C/C++ headers.
(defun c-include-guard ()
"Insert C header include guards."
(let (original-point macro-name)
(set 'original-point (point))
(set 'macro-name
(goto-char (point-min))
(concat "#ifndef " macro-name "\n#define " macro-name "\n\n"))
(set 'original-point (- (+ (point) original-point) 1))
(goto-char (point-max))
(insert "\n#endif\n")
(goto-char original-point)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.