Created
May 17, 2014 09:51
-
-
Save ahoka/a5197774db3b1289c8e6 to your computer and use it in GitHub Desktop.
elisp function for generating header guards for C/C++ headers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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