Skip to content

Instantly share code, notes, and snippets.

Embed
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."
(interactive)
(let (original-point macro-name)
(set 'original-point (point))
(set 'macro-name
(upcase
(replace-regexp-in-string
"\\."
"_"
(file-name-nondirectory
buffer-file-name))))
(goto-char (point-min))
(insert
(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.