| 1 | ;;; -*-emacs-lisp-*- |
| 2 | |
| 3 | (skel-include "skelrc.c") |
| 4 | |
| 5 | (defun skelrc-c-sanitize-guard (s) |
| 6 | (setq s (copy-sequence s)) |
| 7 | (let ((i 0) (l (length s))) |
| 8 | (while (< i l) |
| 9 | (let ((c (aref s i))) |
| 10 | (aset s i (if (eq (char-syntax c) ?w) (upcase c) ?_))) |
| 11 | (setq i (1+ i)))) |
| 12 | s) |
| 13 | |
| 14 | (defun skelrc-c-guard-name () |
| 15 | (if buffer-file-name |
| 16 | (skelrc-c-sanitize-guard |
| 17 | (file-name-sans-extension (file-name-nondirectory buffer-file-name))) |
| 18 | (skel-lookup 'include-guard-name))) |
| 19 | |
| 20 | (setq skel-alist |
| 21 | (append |
| 22 | '((preamble . "[[guard]][[c++-guard]][[includes]][[structures]][[functions]]") |
| 23 | (guard . "#ifndef [[guard-name]]_H\n#define [[guard-name]]_H\n\n") |
| 24 | (guard-name . (skelrc-c-guard-name)) |
| 25 | (c++-guard . "#ifdef __cplusplus\n extern \"C\" {\n#endif\n\n") |
| 26 | (includes . "[[includes-banner]]\n\n[[headers]]") |
| 27 | (includes-banner . (skelrc-banner "Header files")) |
| 28 | (headers . "") |
| 29 | (structures . "[[struct-banner]]\n\n") |
| 30 | (struct-banner . (skelrc-banner "Data structures")) |
| 31 | (functions . "[[func-banner]]\n\n") |
| 32 | (func-banner . (skelrc-banner "Functions provided")) |
| 33 | (postamble . "\n[[c++-unguard]]#endif\n") |
| 34 | (c++-unguard . "#ifdef __cplusplus\n }\n#endif\n\n")) |
| 35 | skel-alist)) |