code_junkie

Starting any Emacs buffer with a .c extension with a template

Nov 13th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void){
  5.  
  6. }
  7.  
  8. (define-skeleton c-throwaway
  9. "Throwaway C skeleton"
  10. "#include <stdio.h>n"
  11. "#include <stdlib.h>n"
  12. "n"
  13. "int main(void){n"
  14. "n"
  15. "}n")
  16.  
  17. (define-auto-insert "\.\([Cc]\|cc\|cpp\)\'" 'c-throwaway)
  18.  
  19. (defun defaultCtemplate(cfilename)
  20. (interactive "sFilename: ")
  21. (switch-to-buffer (generate-new-buffer cfilename))
  22. (insert-file-contents "~/Desktop/test.c")
  23. (c-mode)
  24. )
  25.  
  26. (require 'tempo)
  27.  
  28. (setq c-new-buffer-template
  29. '(
  30. "#include <stdio.h>n"
  31. "#include <stdlib.h>n"
  32. "n"
  33. "int main(void){n"
  34. "n"
  35. "}n"
  36. ))
  37.  
  38. (defun my-c-style ()
  39. "My editing style for .c files."
  40. (c-mode)
  41. (if (zerop (buffer-size))
  42. (tempo-template-c-skeleton)))
  43.  
  44. (setq auto-mode-alist
  45. (cons '("\.c\'" . my-c-style) auto-mode-alist))
  46.  
  47. (tempo-define-template "c-skeleton" c-new-buffer-template
  48. nil
  49. "Insert a skeleton for a .c document")
Add Comment
Please, Sign In to add comment