el.srt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. ;;; el.srt --- SRecode templates for Emacs Lisp mode
  2. ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric Ludlam <zappo@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. set escape_start "$"
  16. set escape_end "$"
  17. set mode "emacs-lisp-mode"
  18. set comment_start ";;;"
  19. set comment_prefix ";;"
  20. set comment_end ""
  21. set DOLLAR "$"
  22. context file
  23. template section-comment :blank
  24. "Insert a comment that separates sections of an Emacs Lisp file."
  25. ----
  26. ;;; $^$
  27. ;;
  28. ----
  29. bind "s"
  30. template empty :user :time :file
  31. "Insert a skeleton for an Emacs Lisp file."
  32. ----
  33. $>:filecomment$
  34. ;;; Commentary:
  35. ;;
  36. ;; $^$
  37. ;;; Code:
  38. (provide '$FILE$)
  39. ;;; $FILENAME$ ends here
  40. ----
  41. prompt MODESYM "Major Mode Symbol (sans -mode): "
  42. prompt MODENAME "Nice Name of mode: " defaultmacro "MODESYM"
  43. prompt MODEEXTENSION "File name extension for mode: "
  44. template major-mode :file :blank :indent
  45. "Insert the framework needed for a major mode."
  46. sectiondictionary "FONTLOCK"
  47. set NAME macro "MODESYM" "-mode-font-lock-keywords"
  48. set DOC "Keywords for use with srecode macros and font-lock."
  49. sectiondictionary "MODEHOOK"
  50. set NAME macro "MODESYM" "-mode-hook"
  51. set DOC "Hook run when " macro "MODESYM" " starts."
  52. set GROUP macro "MODESYM" "-mode"
  53. set CUSTOMTYPE "'hook"
  54. sectiondictionary "MODEFCN"
  55. set NAME macro "MODESYM" "-mode"
  56. set DOC "Major-mode for " macro "MODESYM" "-mode buffers."
  57. set INTERACTIVE ""
  58. ----
  59. $>:declaration:defgroup$
  60. $>:syntax-table$
  61. $<FONTLOCK:declaration:variable$
  62. '(
  63. )
  64. $/FONTLOCK$
  65. $>:declaration:keymap$
  66. $<MODEHOOK:declaration:variable-option$nil$/MODEHOOK$
  67. ;;;###autoload
  68. $<MODEFCN:declaration:function$
  69. (interactive)
  70. (kill-all-local-variables)
  71. (setq major-mode '$MODESYM$-mode
  72. mode-name "$?MODENAME$"
  73. comment-start ";;"
  74. comment-end "")
  75. (set (make-local-variable 'comment-start-skip)
  76. "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
  77. (set-syntax-table $MODESYM$-mode-syntax-table)
  78. (use-local-map $MODESYM$-mode-map)
  79. (set (make-local-variable 'font-lock-defaults)
  80. '($MODESYM$-mode-font-lock-keywords
  81. nil ;; perform string/comment fontification
  82. nil ;; keywords are case sensitive.
  83. ;; This puts _ & - as a word constituent,
  84. ;; simplifying our keywords significantly
  85. ((?_ . "w") (?- . "w"))))
  86. (run-hooks '$MODESYM$-mode-hook)
  87. $/MODEFCN$
  88. ;;;###autoload
  89. (add-to-list 'auto-mode-alist '("\\.$?MODEEXTENSION$$DOLLAR$" . $MODESYM$-mode))
  90. $<A:section-comment$Commands for $MODESYM$$/A$
  91. $<B:section-comment$Utils for $MODESYM$$/B$
  92. ----
  93. template syntax-table
  94. "Create a syntax table."
  95. sectiondictionary "A"
  96. set NAME macro "?MODESYM" "-mode-syntax-table"
  97. set DOC "Syntax table used in " macro "?MODESYM" " buffers."
  98. ----
  99. $<A:declaration:variable$
  100. (let ((table (make-syntax-table (standard-syntax-table))))
  101. (modify-syntax-entry ?\; ". 12" table) ;; SEMI, Comment start ;;
  102. (modify-syntax-entry ?\n ">" table) ;; Comment end
  103. (modify-syntax-entry ?\" "\"" table) ;; String
  104. (modify-syntax-entry ?\- "_" table) ;; Symbol
  105. (modify-syntax-entry ?\\ "\\" table) ;; Quote
  106. (modify-syntax-entry ?\` "'" table) ;; Prefix ` (backquote)
  107. (modify-syntax-entry ?\' "'" table) ;; Prefix ' (quote)
  108. (modify-syntax-entry ?\, "'" table) ;; Prefix , (comma)
  109. table)
  110. $/A$
  111. ----
  112. context declaration
  113. template include :blank
  114. "Insert a require statement."
  115. ----
  116. (require '$?NAME$)
  117. ----
  118. bind "i"
  119. template include-protected :blank
  120. "Insert a require statement."
  121. ----
  122. (condition-case nil
  123. (require '$?NAME$)
  124. (error nil))
  125. ----
  126. prompt INTERACTIVE "Is this an interactive function? " default " (interactive)\n " read y-or-n-p
  127. prompt NAME "Name: " defaultmacro "PRENAME"
  128. template function :el :indent :blank
  129. "Insert a defun outline."
  130. ----
  131. (defun $?NAME$ ($#ARGS$$NAME$$#NOTLAST$ $/NOTLAST$$/ARGS$)
  132. "$DOC$"
  133. $?INTERACTIVE$$^$
  134. )
  135. ----
  136. bind "f"
  137. template variable :el :indent :blank
  138. "Inert a variable.
  139. DOC is optional."
  140. ----
  141. (defvar $?NAME$ $^$
  142. "$DOC$")
  143. ----
  144. bind "v"
  145. template variable-const :el :indent :blank
  146. "Inert a variable."
  147. ----
  148. (defconst $?NAME$ $^$
  149. "$DOC$")
  150. ----
  151. template variable-option :el :el-custom :indent :blank
  152. "Inert a variable created using defcustom."
  153. ----
  154. (defcustom $?NAME$ $^$
  155. "*$DOC$"
  156. :group $GROUP$
  157. :type $?CUSTOMTYPE$)
  158. ----
  159. bind "o"
  160. template class :el :indent :blank
  161. "Insert a new class."
  162. ----
  163. (defclass $?NAME$ ()
  164. (($?ARG1$ :initarg :$ARG1$
  165. :documentation
  166. "$^$")
  167. )
  168. "Class $NAME$ ")
  169. ----
  170. bind "c"
  171. template class-tag :el :indent :blank
  172. "Insert a new class."
  173. ----
  174. (defclass $?NAME$ ($#PARENTS$$NAME$ $/PARENTS$)
  175. ($^$
  176. )
  177. "Class $NAME$ ")
  178. ----
  179. template method :el :ctxt :indent :blank
  180. "Insert a new method."
  181. ----
  182. (defmethod $?NAME$ ((this $?PARENT$))
  183. "$DOC$"
  184. $^$
  185. )
  186. ----
  187. bind "m"
  188. template method-tag :el :ctxt :indent :blank
  189. "Insert a new method for tag inserter."
  190. ----
  191. (defmethod $NAME$ ($#ARGS$$#FIRST$($NAME$ $PARENT$)$/FIRST$$#NOTFIRST$ $NAME$$/NOTFIRST$$/ARGS$)
  192. "$DOC$"
  193. $^$
  194. )
  195. ----
  196. prompt NAME "Method to Override: " defaultmacro "PRENAME" read mode-local-read-function
  197. prompt PARENT "Major Mode for binding: " defaultmacro "MODESYM"
  198. ;; Note: PARENT is used for override methods and for classes. Handy!
  199. template modelocal :el :ctxt :indent :blank
  200. "Insert a new mode-local function."
  201. ----
  202. (define-mode-local-override $?NAME$ $?PARENT$ ()
  203. "$DOC$"
  204. $^$)
  205. ----
  206. bind "l"
  207. template defgroup :indent :blank
  208. "Create a custom group."
  209. ----
  210. (defgroup $?MODESYM$-mode nil
  211. "$MODESYM$ group."
  212. :group 'languages)
  213. ----
  214. bind "g"
  215. template keymap :indent :blank
  216. "Insert a keymap of some sort"
  217. ----
  218. (defvar $?MODESYM$-mode-map
  219. (let ((km (make-sparse-keymap)))
  220. (define-key km "\C-c\C-c" '$MODESYM$-mode$^$)
  221. km)
  222. "Keymap used in `$MODESYM$-mode'.")
  223. ----
  224. bind "k"
  225. context classdecl
  226. prompt NAME "Slot Name: "
  227. template variable-tag :indent :indent :blank
  228. "A field in a class."
  229. ----
  230. ($?NAME$ :initarg :$NAME$
  231. $#DEFAULTVALUE$:initform $VALUE$$/DEFAULTVALUE$
  232. :documentation
  233. "$DOC$")
  234. ----
  235. template variable :indent :indent :blank
  236. "A field in a class."
  237. ----
  238. ($?NAME$ :initarg :$NAME$
  239. :initform nil
  240. :type list
  241. :documentation
  242. "$DOC$")
  243. ----
  244. bind "s"
  245. ;; end