forked from tkg/xslide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xslide3.el
executable file
·342 lines (331 loc) · 10.9 KB
/
xslide3.el
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
;;;; xslide3.el --- XSL Integrated Development Environment
;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2011, 2013, 2024 Tony Graham
;; Author: Tony Graham <[email protected]>
;; Contributors: Simon Brooke, Girard Milmeister, Norman Walsh,
;; Moritz Maass, Lassi Tuura, Simon Wright, KURODA Akira,
;; Ville Skyttä, Glen Peterson, Samuel Bronson
;; Created: 29 July 2011
;; Keywords: languages, xsl, xml
;;; This file is not part of GNU Emacs.
;; This program 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 2
;; of the License, or (at your option) any later version.
;;
;; This program 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 this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; imenu stuff
(defun xsl-sort-alist (alist)
"Sort an alist."
(sort
alist
(lambda (a b) (string< (car a) (car b)))))
(defun xsl-imenu-create-index-function ()
"Create an alist of elements, etc. suitable for use with `imenu'."
(interactive)
(let ((template-alist '())
(mode-alist '())
(key-alist '())
(attribute-set-alist '())
(name-alist '())
(function-alist '())
(accumulator-alist '())
(xsl-mode-alist '()))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*<xsl:template\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 1))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
;; Don't move point because the 'mode' attribute may be before
;; the 'match' attribute.
(if (save-excursion
(re-search-forward
"match\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>" nil t)))
t))
(let* ((pattern (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3))))
(pattern-position (or
(match-beginning 2)
(match-beginning 3))))
;; Test to see if there is a 'mode' attribute.
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"mode\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>" nil t)))
t))
(let* ((mode-name (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3))))
(mode-name-alist (assoc mode-name mode-alist)))
(if mode-name-alist
(setcdr mode-name-alist
(list (car (cdr mode-name-alist))
(cons pattern pattern-position)))
(setq mode-alist
(cons
(list mode-name (cons pattern pattern-position))
mode-alist))))
(setq template-alist
(cons (cons pattern pattern-position)
template-alist)))))
;; When there's no "match" attribute, can still have "name"
;; attribute
(if (save-excursion
(re-search-forward
"\\s-+name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>" nil t)))
t))
(setq name-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
name-alist))))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*<xsl:attribute-set\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 1))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>$" nil t)))
t))
(setq attribute-set-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
attribute-set-alist))))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*<xsl:key\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 1))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>$" nil t)))
t))
(setq key-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
key-alist))))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*<xsl:function\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 1))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>$" nil t)))
t))
(setq function-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
function-alist))))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*<xsl:accumulator\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 1))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>$" nil t)))
t))
(setq accumulator-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
accumulator-alist))))
(goto-char (point-min))
(while
(re-search-forward
"^\\s-*\\(<xsl:mode\\)\\(\\s-+\\)" nil t)
;; Go to the beginning of the whitespace after the element name
(goto-char (match-beginning 2))
;; Match on either single-quoted or double-quoted attribute value.
;; The expression that doesn't match will have return nil for
;; `match-beginning' and `match-end'.
(if (save-excursion
(re-search-forward
"name\\s-*=\\s-*\\(\"\\([^\"]*\\)\"\\|'\\([^']*\\)'\\)"
(save-excursion
(save-match-data
(re-search-forward "<\\|>$" nil t)))
t))
(setq xsl-mode-alist
(cons
(cons (buffer-substring-no-properties
;; Rely on the pattern that didn't match
;; returning nil and on `or' evaluating the
;; second form when the first returns nil.
(or
(match-beginning 2)
(match-beginning 3))
(or
(match-end 2)
(match-end 3)))
(or
(match-beginning 2)
(match-beginning 3)))
xsl-mode-alist))
(setq xsl-mode-alist
(cons
(cons "#unnamed" (point))
xsl-mode-alist))))
(append
(if key-alist
(list (cons "xsl:key" (xsl-sort-alist key-alist))))
(if function-alist
(list (cons "xsl:function" (xsl-sort-alist function-alist))))
(if accumulator-alist
(list (cons "xsl:accumulator" (xsl-sort-alist accumulator-alist))))
(if attribute-set-alist
(list (cons "xsl:attribute-set"
(xsl-sort-alist attribute-set-alist))))
(if xsl-mode-alist
(list (cons "xsl:mode"
(xsl-sort-alist xsl-mode-alist))))
(if name-alist
(list (cons "name=" (xsl-sort-alist name-alist))))
(if mode-alist
;; Sort the mode-alist members, format the mode names nicely,
;; and sort the templates within each mode.
(append
(mapcar (lambda (x)
(cons (format "mode=\"%s\"" (car x))
(xsl-sort-alist (cdr x))))
(xsl-sort-alist mode-alist))))
(xsl-sort-alist template-alist))))
(define-derived-mode xsl-mode nxml-mode "xslide"
"Major mode for editing XSLT."
(setq rng-schema-locating-files
(add-to-list 'rng-schema-locating-files
(locate-file "xslt-schemas.xml" load-path)))
(rng-auto-set-schema)
(setq imenu-create-index-function 'xsl-imenu-create-index-function)
(setq imenu-extract-index-name-function 'xsl-imenu-create-index-function)
(imenu-add-to-menubar "Templates")
(make-local-variable 'tab-width)
(setq tab-width 8)
(setq indent-tabs-mode nil)
(modify-syntax-entry ?' "."))
;;; xslide3.el ends here