summaryrefslogtreecommitdiff
path: root/etc/srecode/el.srt
blob: 7d5c64c86c0192856ab891a9a3df7f7213696983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
;;; el.srt --- SRecode templates for Emacs Lisp mode

;; Copyright (C) 2007-2020 Free Software Foundation, Inc.

;; Author: Eric M. Ludlam <zappo@gnu.org>

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

set escape_start "$"
set escape_end "$"

set mode "emacs-lisp-mode"

set comment_start  ";;;"
set comment_prefix  ";;"
set comment_end  ""

set DOLLAR "$"

context file

template section-comment :blank
"Insert a comment that separates sections of an Emacs Lisp file."
----

;;; $^$
;;

----
bind "s"


template empty :user :time :file
"Insert a skeleton for an Emacs Lisp file."
----
$>:filecomment$

;;; Commentary:
;;
;; $^$

;;; Code:


(provide '$FILE$)

;;; $FILENAME$ ends here

----

prompt MODESYM "Major Mode Symbol (sans -mode): "
prompt MODENAME "Nice Name of mode: " defaultmacro "MODESYM"
prompt MODEEXTENSION "File name extension for mode: "

template major-mode :file :blank :indent
"Insert the framework needed for a major mode."
sectiondictionary "FONTLOCK"
set NAME macro "MODESYM" "-mode-font-lock-keywords"
set DOC "Keywords for use with srecode macros and font-lock."
sectiondictionary "MODEHOOK"
set NAME macro "MODESYM" "-mode-hook"
set DOC "Hook run when " macro "MODESYM" " starts."
set GROUP macro "MODESYM" "-mode"
set CUSTOMTYPE "'hook"
sectiondictionary "MODEFCN"
set NAME macro "MODESYM" "-mode"
set DOC "Major-mode for " macro "MODESYM" "-mode buffers."
set INTERACTIVE ""
----
$>:declaration:defgroup$

$>:syntax-table$

$<FONTLOCK:declaration:variable$
   '(
     )
$/FONTLOCK$

$>:declaration:keymap$

$<MODEHOOK:declaration:variable-option$nil$/MODEHOOK$

;;;###autoload
$<MODEFCN:declaration:function$
  (interactive)
  (kill-all-local-variables)
  (setq major-mode '$MODESYM$-mode
        mode-name "$?MODENAME$"
	comment-start ";;"
	comment-end "")
  (set (make-local-variable 'comment-start-skip)
       "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
  (set-syntax-table $MODESYM$-mode-syntax-table)
  (use-local-map $MODESYM$-mode-map)
  (set (make-local-variable 'font-lock-defaults)
       '($MODESYM$-mode-font-lock-keywords
         nil  ;; perform string/comment fontification
         nil  ;; keywords are case sensitive.
         ;; This puts _ & - as a word constituent,
         ;; simplifying our keywords significantly
         ((?_ . "w") (?- . "w"))))
  (run-hooks '$MODESYM$-mode-hook)
$/MODEFCN$

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.$?MODEEXTENSION$$DOLLAR$" . $MODESYM$-mode))

$<A:section-comment$Commands for $MODESYM$$/A$

$<B:section-comment$Utils for $MODESYM$$/B$
----

template syntax-table
"Create a syntax table."
sectiondictionary "A"
set NAME macro "?MODESYM" "-mode-syntax-table"
set DOC "Syntax table used in " macro "?MODESYM" " buffers."
----
$<A:declaration:variable$
  (let ((table (make-syntax-table (standard-syntax-table))))
    (modify-syntax-entry ?\; ". 12"  table) ;; SEMI, Comment start ;;
    (modify-syntax-entry ?\n ">"     table) ;; Comment end
    (modify-syntax-entry ?\" "\""    table) ;; String
    (modify-syntax-entry ?\- "_"     table) ;; Symbol
    (modify-syntax-entry ?\\ "\\"    table) ;; Quote
    (modify-syntax-entry ?\` "'"     table) ;; Prefix ` (backquote)
    (modify-syntax-entry ?\' "'"     table) ;; Prefix ' (quote)
    (modify-syntax-entry ?\, "'"     table) ;; Prefix , (comma)

    table)
$/A$
----


context declaration

template include :blank
"Insert a require statement."
----
(require '$?NAME$)
----
bind "i"

template include-protected :blank
"Insert a require statement."
----
(condition-case nil
     (require '$?NAME$)
   (error nil))
----

prompt INTERACTIVE "Is this an interactive function? " default "  (interactive)\n  " read y-or-n-p
prompt NAME "Name: " defaultmacro "PRENAME"

template function :el :indent :blank
"Insert a defun outline."
----
(defun $?NAME$ ($#ARGS$$NAME$$#NOTLAST$ $/NOTLAST$$/ARGS$)
  "$DOC$"
$?INTERACTIVE$$^$
  )
----
bind "f"


template variable :el :indent :blank
"Inert a variable.
DOC is optional."
----
(defvar $?NAME$ $^$
  "$DOC$")
----
bind "v"

template variable-const :el :indent :blank
"Inert a variable."
----
(defconst $?NAME$ $^$
  "$DOC$")
----

template variable-option :el :el-custom :indent :blank
"Inert a variable created using defcustom."
----
(defcustom $?NAME$ $^$
  "*$DOC$"
  :group '$GROUP$
  :type $?CUSTOMTYPE$)
----
bind "o"

template class :el :indent :blank
"Insert a new class."
----
(defclass $?NAME$ ()
   (($?ARG1$ :initarg :$ARG1$
             :documentation
	     "$^$")
   )
   "Class $NAME$ ")
----
bind "c"

template class-tag :el :indent :blank
"Insert a new class."
----
(defclass $?NAME$ ($#PARENTS$$NAME$ $/PARENTS$)
   ($^$
    )
   "Class $NAME$ ")
----

template method :el :ctxt :indent :blank
"Insert a new method."
----
(defmethod $?NAME$ ((this $?PARENT$))
  "$DOC$"
  $^$
  )
----
bind "m"

template method-tag :el :ctxt :indent :blank
"Insert a new method for tag inserter."
----
(defmethod $NAME$ ($#ARGS$$#FIRST$($NAME$ $PARENT$)$/FIRST$$#NOTFIRST$ $NAME$$/NOTFIRST$$/ARGS$)
  "$DOC$"
  $^$
  )
----

prompt NAME "Method to Override: " defaultmacro "PRENAME" read mode-local-read-function
prompt PARENT "Major Mode for binding: " defaultmacro "MODESYM"

;; Note: PARENT is used for override methods and for classes.  Handy!
template modelocal :el :ctxt :indent :blank
"Insert a new mode-local function."
----
(define-mode-local-override $?NAME$ $?PARENT$ ()
  "$DOC$"
  $^$)
----
bind "l"


template defgroup :indent :blank
"Create a custom group."
----
(defgroup $?MODESYM$-mode nil
  "$MODESYM$ group."
  :group 'languages)
----
bind "g"


template keymap :indent :blank
"Insert a keymap of some sort"
----
(defvar $?MODESYM$-mode-map
  (let ((km (make-sparse-keymap)))
    (define-key km "\C-c\C-c" '$MODESYM$-mode$^$)
    km)
  "Keymap used in `$MODESYM$-mode'.")
----
bind "k"


context classdecl

prompt NAME "Slot Name: "

template variable-tag :indent :indent :blank
"A field in a class."
----
($?NAME$ :initarg :$NAME$
	 $#DEFAULTVALUE$:initform $VALUE$$/DEFAULTVALUE$
	 :documentation
	 "$DOC$")

----

template variable :indent :indent :blank
"A field in a class."
----
($?NAME$ :initarg :$NAME$
	 :initform nil
	 :type list
	 :documentation
	 "$DOC$")

----
bind "s"



;; end