home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / dmacro-2.0 / dm-c.el next >
Encoding:
Text File  |  1991-11-15  |  4.6 KB  |  188 lines

  1. ;;; Copyright (c) 1991 Wayne Mesard.  May be redistributed only under the
  2. ;;; terms of the GNU Emacs General Public License.
  3.  
  4. ;;; 
  5. ;;; DM-C  :  Dynamic Macros for C mode
  6. ;;; 
  7.  
  8. ;; This file tries to load "dmacro.elc".
  9. ;; The "load-path" variable, as set in your Emacs init file, should include
  10. ;; a directory containing the file "dmacro.elc".
  11.  
  12. ;;; HISTORY
  13. ;;    2.0 wmesard - Oct 18, 1991: Freeze.
  14.  
  15. ;;;
  16. ;;; REQUIREMENTS
  17. ;;;
  18.  
  19. (require 'dmacro)
  20.  
  21.  
  22. ;;; 
  23. ;;; KEY BINDINGS
  24. ;;; 
  25.  
  26. (if (not (and (boundp 'dont-bind-my-keys) dont-bind-my-keys))
  27.     (global-set-key "\C-ct" 
  28.             (dmacro-function "dstamp" "dtstamp" 'insert-timestamp))
  29.   )
  30.  
  31.  
  32. ;;; 
  33. ;;; USER PARAMETERS
  34. ;;; 
  35.  
  36. (setq auto-dmacro-alist (append '(("\\.c$" . masthead) ("\\.h$" . dot-h))
  37.                   auto-dmacro-alist))
  38.  
  39.  
  40. ;;;
  41. ;;; ALIASES
  42. ;;;
  43.  
  44. (def-dmacro-alias
  45.   dn ((month-num) :pad nil)
  46.   dd ((chron) 8 10 :pad nil)
  47.   dy ((chron) 22)
  48.   )
  49.   
  50. ;;; 
  51. ;;; GLOBAL DMACROS
  52. ;;; 
  53.  
  54. (add-dmacros 'global-abbrev-table '(
  55.     ("dstamp"    " -~((user-initials) :down)~dn/~dd/~dy."
  56.      nil    "user id and date")
  57.     ("dtstamp"    " -~((user-initials) :down)~dn/~dd/~dy ~((hour) :pad nil):~min~ampm."
  58.      nil     "user id, date and time")
  59.     ))
  60.  
  61.  
  62. ;;; 
  63. ;;; C-MODE DMACROS
  64. ;;; 
  65.  
  66. (add-dmacros 'c-mode-abbrev-table '(
  67.     ("i"     "#include <~@.h>\n"
  68.      nil    "simple #include directive")
  69.     ("iinclude"    "#ifndef ~((prompt file \"Header file name: \") :up)
  70. # include <~(prompt file).h>
  71. #endif /* ~((prompt file) :up) */\n"    nil
  72.     "interactive #include with #ifndef (prompts for file name)")
  73.     ("d"     "#define " nil)
  74.     ("ifd"    "#ifdef ~@
  75. ~(mark)
  76. #endif \n"    indent    "#ifdef/#endif (no prompting)")
  77.     ("ifdnever"    "#ifdef NEVER
  78. ~@
  79. #endif /* NEVER */\n"    nil
  80.     "#ifdef NEVER (ideal for use with dmacro-wrap-region)")
  81.     ("ifddebug"    "#ifdef DEBUG\nif (debuglevel >= ~(prompt debug \"Debug level: \") {
  82. (void) fprintf(stderr, \"DEBUG: ~@\\n\");
  83. (void) fflush (stderr);\n(void) getch ();\n}
  84. #endif /* DEBUG */"
  85.     indent "print debugging info to stderr")
  86.     ("iifd"    "#ifdef ~(prompt constant \"#ifdef condition: \")
  87. ~@
  88. #endif /* ~(prompt) */\n"    nil    "#ifdef/#endif (prompts for condition)")
  89.     ("iifnd"    "#ifndef ~(prompt constant \"#ifndef condition: \")
  90. ~@
  91. #endif /* ~(prompt) */\n"    nil      "#ifndef/#endif (prompts for condition)")
  92.     ("iifed"    "#ifdef ~(prompt constant \"#ifdef condition: \")
  93. ~@
  94. #else
  95.  ~(mark)
  96. #endif /* ~(prompt) */\n"    nil  "#ifdef/#else/#endif (prompts for condition)")
  97.     ("b"     "{
  98. ~@
  99. }"    indent "curly braces (ideal for dmacro-wrap-line)")
  100.     ("switch"    "switch (~@)
  101. {
  102.  
  103. }"    indent    "switch statement")
  104.     ("case"    "case ~@:
  105.  
  106. break;"    indent "case/break")
  107.     ("if"    "if (~@)
  108.  ~(mark)\n"     indent    "if statement")
  109.     ("ife"    "if (~@)
  110.  ~(mark)
  111. else
  112.  ~(mark)\n"     indent    "if/else statement")
  113.     ("for"    "for (~@; ; )
  114. {
  115.  ~mark
  116. }\n"     indent "for statment")
  117.     ("fori"    "for (i = 0; i < ~@; ++i)
  118. {
  119.  ~mark
  120. }\n"     indent "for statement (increments variable i)")
  121.     ("foriefficient"    "for (i = ~@; --i >= 0; )
  122. {
  123.  ~mark
  124. }\n"     indent "for statement (decrements i efficiently)")
  125.     ("ifor"    "for (~(prompt var \"Variable: \") = 0; ~prompt < ~@; ++~prompt)
  126. {
  127.  ~mark
  128. }\n"    indent    "interactive for statment (prompts for variable name)")
  129.     ("while"    "while (~@)
  130. {
  131.  ~mark
  132. }\n"     indent "while statement")
  133.     ("void"    "(void)"    indent)
  134.     ("p"    "(void) printf(\"~@\\n\"~mark);" indent "printf")
  135.     ("ifmal"
  136.        "if ((~@ = (~(prompt type \"Variable type: \") *) ~(dmacro malloc)(~(mark)sizeof(~(prompt)))) == NULLP(~(prompt)))\n"    
  137.        indent    "malloc with check for error (prompts for var type)")
  138.     ("mal"    "= (~(prompt type \"Variable type: \") *) ~(dmacro malloc)(~@sizeof(~(prompt)));\n"    
  139.      indent    "call to malloc (prompts for var type)")
  140.     ("fdesc"    "/**
  141. NAME:    
  142.   ~@
  143. PURPOSE:
  144.   ~mark
  145. ARGS:
  146.   > ~mark
  147. RETURNS:
  148.   < ~mark
  149. NOTES:
  150.   ~mark
  151. **/\n"    expand "Standard function comment block")
  152.     ("func"
  153.      "~(prompt type \"Function type: \") ~(prompt name \"Function name: \")(~@)
  154. {\n~mark\n} /* ~(prompt name) */\n"
  155.      indent "function definition (prompts for type and name)")
  156.     ("main"    "main(argc, argv)
  157. int argc;
  158. char **argv;
  159. {
  160. ~@
  161. }\n"     indent "an empty main() function with args")
  162.     ("masthead"
  163.     "/* Copyright (c) ~(year) by A BIG Corporation.  All Rights Reserved */
  164.  
  165. /***
  166.    NAME
  167.      ~(file-name)
  168.    PURPOSE
  169.      ~point
  170.    NOTES
  171.      ~mark
  172.    HISTORY
  173. ~(dmacro history)Created.
  174. ***/\n\n"      expand
  175.     "commment block for the top of a .c file")
  176.     ("history"    "     ~(user-id) - ~(mon) ~dd, ~(year): "    expand
  177.      "a new HISTORY entry in the masthead")
  178.     ("hifndef"    "#ifndef ~((file-name) :up)
  179. #define ~((file-name) :up)
  180.  
  181. ~@
  182.  
  183. #endif /* ~((file-name) :up) */" expand "used by dot-h macro")
  184.  
  185.     ("dot-h"    "~(dmacro masthead t)~(dmacro hifndef)"    expand
  186.      "comment block for the top of a .h file")
  187. ))
  188.