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