-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextile-mode.el
402 lines (316 loc) · 11.8 KB
/
textile-mode.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
;;; textile-mode.el --- Textile markup editing major mode
;; Copyright (C) 2006 Free Software Foundation, Inc.
;; Author: Julien Barnier <[email protected]>
;; $Id: textile-mode.el 6 2006-03-30 22:37:08Z juba $
;; This file 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, or (at your option)
;; any later version.
;; This file 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; Known bugs or limitations:
;; - if several {style}, [lang] or (class) attributes are given for
;; the same block, only the first one of each type will be
;; highlighted.
;;
;; - some complex imbrications of inline markup and attributes are
;; not well-rendered (for example, *strong *{something}notstrong*)
;;
;;; Code:
(defvar textile-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [foo] 'textile-do-foo)
map)
"Keymap for `textile-mode'.")
(defun textile-re-concat (l)
"Concatenate the elements of a list with a \\| separator and
non-matching parentheses"
(concat
"\\(?:"
(mapconcat 'identity l "\\|")
"\\)"))
(setq textile-attributes
'("{[^}]*}" "([^)]*)" "\\[[^]]*\\]"))
(setq textile-blocks
'("^h1" "^h2" "^h3" "^h4" "^h5" "^h6" "^p" "^bq" "^fn[0-9]+" "^#+ " "^\\*+ " "^table"))
(setq textile-inline-markup
'("\\*" "\\*\\*" "_" "__" "\\?\\?" "@" "-" "\\+" "^" "~" "%"))
(setq textile-alignments
'( "<>" "<" ">" "=" "(+" ")+"))
(setq textile-table-alignments
'( "<>" "<" ">" "=" "_" "\\^" "~" "\\\\[0-9]+" "/[0-9]+"))
; from gnus-button-url-regexp
(setq textile-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)")
(defun textile-block-matcher (bloc)
"Return the matcher regexp for a block element"
(concat
"^"
bloc
(textile-re-concat textile-alignments) "?"
(textile-re-concat textile-attributes) "*"
"\\. "
"\\(\\(?:.\\|\n\\)*?\\)\n\n"))
(defun textile-attribute-matcher (attr-start attr-end)
"Return the matcher regexp for an attribute"
(concat
(textile-re-concat (append textile-blocks textile-inline-markup))
(textile-re-concat textile-alignments) "*"
(textile-re-concat textile-attributes) "*"
"\\(" attr-start "[^"
(if (string-equal attr-end "\\]") "]" attr-end)
"]*" attr-end "\\)"))
(defun textile-inline-markup-matcher (markup)
"Return the matcher regexp for an inline markup"
(concat
"\\W\\("
markup
"\\(?:\\w\\|\\w.*?\\w\\|[[{(].*?\\w\\)"
markup
"\\)\\W"))
(defun textile-list-bullet-matcher (bullet)
"Return the matcher regexp for a list bullet"
(concat
"^\\(" bullet "\\)"
(textile-re-concat textile-alignments) "*"
(textile-re-concat textile-attributes) "*"))
(defun textile-alignments-matcher ()
"Return the matcher regexp for an alignments or indentation"
(concat
"\\(?:" (textile-re-concat textile-blocks) "\\|" "!" "\\)"
"\\(" (textile-re-concat textile-alignments) "+" "\\)"))
(defun textile-table-matcher ()
"Return the matcher regexp for a table row or header"
(concat
"\\(?:"
"^table" (textile-re-concat textile-table-alignments) "*" (textile-re-concat textile-attributes) "*" "\\. *$"
"\\|"
"^" (textile-re-concat textile-table-alignments) "*" (textile-re-concat textile-attributes) "*" "\\(?:\\. *|\\)"
"\\|"
"|" (textile-re-concat textile-table-alignments) "*" (textile-re-concat textile-attributes) "*" "\\(?:\\. \\)?"
"\\|"
"| *$"
"\\)"))
(defun textile-link-matcher ()
"Return the matcher regexp for a link"
(concat
"\\(?:"
"\\(?:" "\".*?\"" "\\|" "\\[.*?\\]" "\\)?"
textile-url-regexp
"\\|"
"\".*?\":[^ \n\t]+"
"\\)"))
(defun textile-image-matcher ()
"Return the matcher regexp for an image link"
(concat
"!"
(textile-re-concat textile-alignments) "*"
"/?\\w[^ \n\t]*?\\(?: *(.*?)\\|\\w\\)"
"!:?"))
(defun textile-acronym-matcher ()
"Return the matcher regexp for an acronym"
(concat
"\\w+" "(.*?)"))
(defvar textile-font-lock-keywords
(list
;; headers
`(,(textile-block-matcher "h1") 1 'textile-h1-face t t)
`(,(textile-block-matcher "h2") 1 'textile-h2-face t t)
`(,(textile-block-matcher "h3") 1 'textile-h3-face t t)
`(,(textile-block-matcher "h4") 1 'textile-h4-face t t)
`(,(textile-block-matcher "h5") 1 'textile-h5-face t t)
`(,(textile-block-matcher "h6") 1 'textile-h6-face t t)
;; blockquotes
`(,(textile-block-matcher "bq") 1 'textile-blockquote-face t t)
;; footnotes
`(,(textile-block-matcher "fn[0-9]+") 1 'textile-footnote-face t t)
;; footnote marks
'("\\w\\([[0-9]+]\\)" 1 'textile-footnotemark-face prepend t)
;; acronyms
`(,(textile-acronym-matcher) 0 'textile-acronym-face t t)
;; emphasis
`(,(textile-inline-markup-matcher "__") 1 'textile-emph-face prepend t)
`(,(textile-inline-markup-matcher "_") 1 'textile-emph-face prepend t)
'("<em>\\(.\\|\n\\)*?</em>" 0 'textile-emph-face prepend t)
;; strength
`(,(textile-inline-markup-matcher "\\*\\*") 1 'textile-strong-face prepend t)
`(,(textile-inline-markup-matcher "\\*") 1 'textile-strong-face prepend t)
'("<strong>\\(.\\|\n\\)*?</strong>" 0 'textile-strong-face prepend t)
;; citation
`(,(textile-inline-markup-matcher "\\?\\?") 1 'textile-citation-face prepend t)
;; code
`(,(textile-inline-markup-matcher "@") 1 'textile-code-face prepend t)
;; deletion
`(,(textile-inline-markup-matcher "-") 1 'textile-deleted-face prepend t)
;; insertion
`(,(textile-inline-markup-matcher "\\+") 1 'textile-inserted-face prepend t)
;; superscript
`(,(textile-inline-markup-matcher "\\^") 1 'textile-superscript-face prepend t)
;; subscript
`(,(textile-inline-markup-matcher "~") 1 'textile-subscript-face prepend t)
;; span
`(,(textile-inline-markup-matcher "%") 1 'textile-span-face prepend t)
;; image link
`(,(textile-image-matcher) 0 'textile-image-face t t)
;; ordered list bullet
`(,(textile-list-bullet-matcher "#+") 1 'textile-ol-bullet-face)
;; unordered list bullet
`(,(textile-list-bullet-matcher "\\*+") 1 'textile-ul-bullet-face)
;; style
`(,(textile-attribute-matcher "{" "}") 1 'textile-style-face t t)
;; class
`(,(textile-attribute-matcher "(" ")") 1 'textile-class-face t t)
;; lang
`(,(textile-attribute-matcher "\\[" "\\]") 1 'textile-lang-face t t)
;; alignments and indentation
`(,(textile-alignments-matcher) 1 'textile-alignments-face t t)
;; tables
`(,(textile-table-matcher) 0 'textile-table-face t t)
;; links
`(,(textile-link-matcher) 0 'textile-link-face t t)
;; <pre> blocks
'("<pre>\\(.\\|\n\\)*?</pre>" 0 'textile-pre-face t t)
;; <code> blocks
'("<code>\\(.\\|\n\\)*?</code>" 0 'textile-code-face t t))
"Keywords/Regexp for fontlocking of textile-mode")
;; (defvar textile-imenu-generic-expression
;; ...)
;; (defvar textile-outline-regexp
;; ...)
(define-derived-mode textile-mode text-mode "Textile"
"A major mode for editing textile files."
(set (make-local-variable 'font-lock-defaults) '(textile-font-lock-keywords t))
(set (make-local-variable 'font-lock-multiline) 'undecided))
;; FACES
(defgroup textile-faces nil
"Faces used by textile-mode for syntax highlighting"
:group 'faces)
(defface textile-h1-face
'((t (:height 2.0 :weight bold)))
"Face used to highlight h1 headers."
:group 'textile-faces)
(defface textile-h2-face
'((t (:height 1.75 :weight bold)))
"Face used to highlight h2 headers."
:group 'textile-faces)
(defface textile-h3-face
'((t (:height 1.6 :weight bold)))
"Face used to highlight h3 headers."
:group 'textile-faces)
(defface textile-h4-face
'((t (:height 1.35 :weight bold)))
"Face used to highlight h4 headers."
:group 'textile-faces)
(defface textile-h5-face
'((t (:height 1.2 :weight bold)))
"Face used to highlight h5 headers."
:group 'textile-faces)
(defface textile-h6-face
'((t (:height 1.0 :weight bold)))
"Face used to highlight h6 headers."
:group 'textile-faces)
(defface textile-blockquote-face
'((t (:foreground "ivory4")))
"Face used to highlight bq blocks."
:group 'textile-faces)
(defface textile-footnote-face
'((t (:foreground "orange red")))
"Face used to highlight footnote blocks."
:group 'textile-faces)
(defface textile-footnotemark-face
'((t (:foreground "orange red")))
"Face used to highlight footnote marks."
:group 'textile-faces)
(defface textile-style-face
'((t (:foreground "sandy brown")))
"Face used to highlight style parameters."
:group 'textile-faces)
(defface textile-class-face
'((t (:foreground "yellow green")))
"Face used to highlight class and id parameters."
:group 'textile-faces)
(defface textile-lang-face
'((t (:foreground "sky blue")))
"Face used to highlight lang parameters."
:group 'textile-faces)
(defface textile-emph-face
'((t (:slant italic)))
"Face used to highlight emphasized words."
:group 'textile-faces)
(defface textile-strong-face
'((t (:weight bold)))
"Face used to highlight strong words."
:group 'textile-faces)
(defface textile-code-face
'((t (:foreground "ivory3")))
"Face used to highlight inline code."
:group 'textile-faces)
(defface textile-citation-face
'((t (:slant italic)))
"Face used to highlight citations."
:group 'textile-faces)
(defface textile-deleted-face
'((t (:strike-through t)))
"Face used to highlight deleted words."
:group 'textile-faces)
(defface textile-inserted-face
'((t (:underline t)))
"Face used to highlight inserted words."
:group 'textile-faces)
(defface textile-superscript-face
'((t (:height 1.1)))
"Face used to highlight superscript words."
:group 'textile-faces)
(defface textile-subscript-face
'((t (:height 0.8)))
"Face used to highlight subscript words."
:group 'textile-faces)
(defface textile-span-face
'((t (:foreground "pink")))
"Face used to highlight span words."
:group 'textile-faces)
(defface textile-alignments-face
'((t (:foreground "cyan")))
"Face used to highlight alignments."
:group 'textile-faces)
(defface textile-ol-bullet-face
'((t (:foreground "red")))
"Face used to highlight ordered lists bullets."
:group 'textile-faces)
(defface textile-ul-bullet-face
'((t (:foreground "blue")))
"Face used to highlight unordered list bullets."
:group 'textile-faces)
(defface textile-pre-face
'((t (:foreground "green")))
"Face used to highlight <pre> blocks."
:group 'textile-faces)
(defface textile-code-face
'((t (:foreground "yellow")))
"Face used to highlight <code> blocks."
:group 'textile-faces)
(defface textile-table-face
'((t (:foreground "red")))
"Face used to highlight tables."
:group 'textile-faces)
(defface textile-link-face
'((t (:foreground "blue")))
"Face used to highlight links."
:group 'textile-faces)
(defface textile-image-face
'((t (:foreground "pink")))
"Face used to highlight image links."
:group 'textile-faces)
(defface textile-acronym-face
'((t (:foreground "cyan")))
"Face used to highlight acronyms links."
:group 'textile-faces)
(provide 'textile-mode)
;;; textile-mode.el ends here