]> code.delx.au - gnu-emacs-elpa/blob - packages/sisu-mode/sisu-mode.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / sisu-mode / sisu-mode.el
1 ;;; sisu-mode.el --- Major mode for SiSU markup text
2
3 ;; Copyright (C) 2011, 2016 Free Software Foundation, Inc.
4
5 ;; Author: Ralph Amissah & Ambrose Kofi Laing
6 ;; Maintainer: Ralph Amissah <ralph.amissah@gmail.com>
7 ;; Keywords: text, syntax, processes, tools
8 ;; Version: 7.1.8
9 ;; URL: http://www.sisudoc.org/
10 ;; originally looked at (based on) doc-mode, with kind permission of the author
11 ;; Author: SUN, Tong <suntong001@users.sf.net>, (c)2001-6, all right reserved
12 ;; Version: $Date: 2006/01/19 03:13:41 $ $Revision: 1.14 $
13 ;; Home URL: http://xpt.sourceforge.net/
14 ;; with contributions from Kevin Ryde and Stefan Monnier
15
16 ;; This program is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 3, or (at your option)
19 ;; any later version.
20 ;;
21 ;; This program is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25 ;;
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
28
29 ;; Viva Software Libre!
30 ;; Support the free software movement!
31 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32
33 ;;; Commentary:
34
35 ;; SiSU (http://www.sisudoc.org/) is a document structuring and
36 ;; publishing framework. This package provides an Emacs major mode
37 ;; for SiSU markup.
38
39 ;; When this package is installed, files ending in ".sisu" are
40 ;; automatically associated with sisu-mode. If a file doesn't have a
41 ;; .sisu extension, add a first line:
42 ;; # -*- Sisu -*-
43
44 ;; The documentation for the "Structure Of The Hierarchy Text" can be
45 ;; found in the sisustring for the sisu-mode function.
46
47 ;;; Code:
48
49 ;;{{{ Variables:
50
51 (defgroup sisu-faces nil
52 "AsciiSisu highlighting"
53 :group 'sisus)
54
55 ;; == Colors
56 ; color n is more prominent than color n+1
57
58 (defface sisu-title-1-face
59 `((((class color)
60 (background dark))
61 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
62 (((class color)
63 (background light))
64 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
65 (t (:weight bold :inherit variable-pitch)))
66 "Face for AsciiSisu titles at level 1."
67 :group 'sisu-faces)
68
69 (defface sisu-title-2-face
70 `((((class color)
71 (background dark))
72 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
73 (((class color)
74 (background light))
75 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
76 (t (:weight bold :inherit variable-pitch)))
77 "Face for AsciiSisu titles at level 2."
78 :group 'sisu-faces)
79
80 (defface sisu-title-3-face
81 `((((class color)
82 (background dark))
83 (:foreground "sienna3" :bold t))
84 (((class color)
85 (background light))
86 (:foreground "sienna3" :bold t))
87 (t (:weight bold)))
88 "Face for AsciiSisu titles at level 3."
89 :group 'sisu-faces)
90
91 (defface sisu-title-4-face
92 `((((class color)
93 (background dark))
94 (:foreground "burlywood3"))
95 (((class color)
96 (background light))
97 (:foreground "burlywood3"))
98 (t ()))
99 "Face for AsciiSisu titles at level 4."
100 :group 'sisu-faces)
101
102 (defface info-node
103 '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
104 (((class color) (background dark)) (:foreground "white" :bold t :italic t))
105 (t (:bold t :italic t)))
106 "Face for Info node names."
107 :group 'sisu-faces)
108
109 (defvar sisu-title-1 'sisu-title-1-face)
110 (defvar sisu-title-2 'sisu-title-2-face)
111 (defvar sisu-title-3 'sisu-title-3-face)
112 (defvar sisu-title-4 'sisu-title-4-face)
113
114 (defvar sisu-general-font-lock-red1 font-lock-warning-face)
115 (defvar sisu-general-font-lock-red2 font-lock-comment-face)
116 (defvar sisu-general-font-lock-red3 font-lock-string-face)
117
118 (defvar sisu-general-font-lock-green1 font-lock-type-face)
119 (defvar sisu-general-font-lock-green2 font-lock-constant-face)
120
121 (defvar sisu-general-font-lock-blue1 font-lock-keyword-face)
122 (defvar sisu-general-font-lock-blue2 font-lock-function-name-face)
123 (defvar sisu-general-font-lock-blue3 font-lock-builtin-face)
124
125 (defvar sisu-general-font-lock-yellow1 font-lock-variable-name-face)
126 (defvar sisu-general-font-lock-yellow2 font-lock-comment-face)
127
128 ;; == sisu-mode settings
129
130 (defvar sisu-mode-hook nil
131 "Normal hook run when entering Sisu Text mode.")
132
133 (defvar sisu-mode-abbrev-table nil
134 "Abbrev table in use in Sisu-mode buffers.")
135 (define-abbrev-table 'sisu-mode-abbrev-table ())
136
137 (defconst sisu-font-lock-keywords
138 (eval-when-compile
139 (list
140 ;;grouped text ---------
141 ;(cons "^```[ ]code\\(.\\|\n\\)+?\n```\n" 'sisu-general-font-lock-red2)
142 (cons "^```[ ]+code.*?$\\|^```$" 'sisu-general-font-lock-red2)
143 (cons "^```[ ]+table.*?$\\|^```$" 'sisu-general-font-lock-red2)
144 (cons "^```[ ]+group$\\|^```$" 'sisu-general-font-lock-red2)
145 (cons "^```[ ]+block$\\|^```$" 'sisu-general-font-lock-red2)
146 (cons "^```[ ]+poem$\\|^```$" 'sisu-general-font-lock-red2)
147 (cons "^```[ ]+alt$\\|^```$" 'sisu-general-font-lock-red2)
148 ;;grouped text ---------
149 (cons "^group{\\|^}group" 'sisu-general-font-lock-red2)
150 (cons "^block{\\|^}block" 'sisu-general-font-lock-red2)
151 (cons "^code{\\|^}code" 'sisu-general-font-lock-red2)
152 (cons "^poem{\\|^}poem" 'sisu-general-font-lock-red2)
153 (cons "^alt{\\|^}alt" 'sisu-general-font-lock-red2)
154 (cons "^table{.+\\|^}table" 'sisu-general-font-lock-red2)
155 (cons "^{table[^}]+}" 'sisu-general-font-lock-red2)
156
157 (list
158 (concat
159 "^\`\\{3\\}[ ]+code.*?$"
160 "\\(.\\|\n\\)+?"
161 "\`\\{3\\}$"
162 )
163 '(1 sisu-general-font-lock-red2 t)
164 '(2 nil t)
165 '(3 sisu-general-font-lock-red2 t)
166 )
167 (list
168 (concat
169 "^\`\\{3\\}[ ]+table.*?$"
170 "\\(.\\|\n\\)+?"
171 "\`\\{3\\}$"
172 )
173 '(1 sisu-general-font-lock-red2 t)
174 '(2 nil t)
175 '(3 sisu-general-font-lock-red2 t)
176 )
177 (list
178 (concat
179 "^\`\\{3\\}[ ]+\\(group\\|block\\|alt\\|poem\\)$"
180 "\\(.\\|\n\\)+?"
181 "^\`\\{3\\}$"
182 )
183 '(1 sisu-general-font-lock-red2 t)
184 '(2 nil t)
185 '(3 sisu-general-font-lock-red2 t)
186 )
187
188 ;; footnote/endnote ----
189 ;(cons "\~{.+?}\~" 'sisu-general-font-lock-green1)
190 (cons "\~{\\*\\*\\|\~{\\*\\|\~{\\|}\~" 'sisu-general-font-lock-red2)
191 (cons "\~\\[\\+\\|\~\\[\\*\\|\~\\[\\|\\]\~" 'sisu-general-font-lock-red2)
192 (cons "\~\\^ \\|^\\^\~ " 'sisu-general-font-lock-red2)
193 (list
194 (concat
195 "\\(\*\~\\)"
196 "\\([^ \r\t\n]+\\)"
197 )
198 '(1 sisu-general-font-lock-red1 t)
199 '(2 sisu-general-font-lock-blue2 t)
200 )
201
202 ;; emphasis (can be program configured to be bold italics or underscore)
203 (list
204 (concat
205 "\\([*]{\\)"
206 "\\([^}]+\\)"
207 "\\(}[*]\\)"
208 )
209 '(1 sisu-general-font-lock-red1 t)
210 '(2 sisu-general-font-lock-red1 t)
211 '(3 sisu-general-font-lock-red1 t)
212 )
213
214 ;; bold ----------------
215 (list
216 (concat
217 "\\([!]{\\)"
218 "\\([^}]+\\)"
219 "\\(}[!]\\)"
220 )
221 '(1 sisu-general-font-lock-red1 t)
222 '(2 sisu-general-font-lock-red1 t)
223 '(3 sisu-general-font-lock-red1 t)
224 )
225 (cons "\\*[^ ]+\\*" 'sisu-general-font-lock-red1)
226 (cons "^!_ .+" 'sisu-general-font-lock-red1)
227
228 ;; italics -------------
229 (list
230 (concat
231 "\\([/]{\\)"
232 "\\([^}]+\\)"
233 "\\(}[/]\\)"
234 )
235 '(1 sisu-general-font-lock-red1 t)
236 '(2 sisu-general-font-lock-blue1 t)
237 '(3 sisu-general-font-lock-red1 t)
238 )
239
240 ;; underscore ----------
241 (list
242 (concat
243 "\\([_]{\\)"
244 "\\([^}]+\\)"
245 "\\(\}[_]\\)"
246 )
247 '(1 sisu-general-font-lock-red1 t)
248 '(2 sisu-general-font-lock-red1 t)
249 '(3 sisu-general-font-lock-red1 t)
250 )
251
252 ;; monospace -----------
253 (list
254 (concat
255 "\\([#]{\\)"
256 "\\([^}]+\\)"
257 "\\(}[#]\\)"
258 )
259 '(1 sisu-general-font-lock-red1 t)
260 '(2 sisu-general-font-lock-red1 t)
261 '(3 sisu-general-font-lock-red1 t)
262 )
263
264 ;; citation ------------
265 (list
266 (concat
267 "\\([\"]{\\)"
268 "\\([^}]+\\)"
269 "\\(}[\"]\\)"
270 )
271 '(1 sisu-general-font-lock-red1 t)
272 '(2 sisu-general-font-lock-red1 t)
273 '(3 sisu-general-font-lock-red1 t)
274 )
275
276 ;; inserted text -------
277 (list
278 (concat
279 "\\([\+]{\\)"
280 "\\([^}]+\\)"
281 "\\(}[\+]\\)"
282 )
283 '(1 sisu-general-font-lock-red1 t)
284 '(2 sisu-general-font-lock-red1 t)
285 '(3 sisu-general-font-lock-red1 t)
286 )
287
288 ;; strike through ------
289 (list
290 (concat
291 "\\(\\-{\\)"
292 "\\([^}]+\\)"
293 "\\(}\\-\\)"
294 )
295 '(1 sisu-general-font-lock-red1 t)
296 '(2 sisu-general-font-lock-red1 t)
297 '(3 sisu-general-font-lock-red1 t)
298 )
299
300 ;; superscript ---------
301 (list
302 (concat
303 "\\(\\^{\\)"
304 "\\([^}]+\\)"
305 "\\(}\\^\\)"
306 )
307 '(1 sisu-general-font-lock-red1 t)
308 '(2 sisu-general-font-lock-red1 t)
309 '(3 sisu-general-font-lock-red1 t)
310 )
311
312 ;; subscript -----------
313 (list
314 (concat
315 "\\([,]{\\)"
316 "\\([^}]+\\)"
317 "\\(}[,]\\)"
318 )
319 '(1 sisu-general-font-lock-red1 t)
320 '(2 sisu-general-font-lock-red1 t)
321 '(3 sisu-general-font-lock-red1 t)
322 )
323
324 ;; numbered list
325 (cons "^# \\|^_# " 'sisu-general-font-lock-red1)
326
327 ;; bullet text
328 (cons "^_\\*[1-9] \\|^_\\* " 'sisu-general-font-lock-red1)
329
330 ;; indented text
331 (cons "^_[1-9] " 'sisu-general-font-lock-red1)
332 (cons "^_[1-9]! " 'sisu-general-font-lock-red1)
333
334 ;; hanging indented text [proposed enable when implemented]
335 (cons "^__[1-9] " 'sisu-general-font-lock-red1)
336 (cons "^_[0-9]_[0-9] " 'sisu-general-font-lock-red1)
337 (cons "^__[1-9]! " 'sisu-general-font-lock-red1)
338 (cons "^_[0-9]_[0-9]! " 'sisu-general-font-lock-red1)
339
340 ;; url
341 (cons "\\(^\\|[ ]\\)http:[/][/][^ \t\n\r<]+" 'sisu-general-font-lock-blue2)
342
343 ;; Comment Lines
344 (cons "^% .*" 'sisu-general-font-lock-blue1)
345
346 ;; page break
347 (cons "^\\(-\\\\\\\\-\\|=\\\\\\\\=\\|-\\.\\.-\\)" 'sisu-general-font-lock-red2)
348
349 ;; line break
350 (cons " \\\\\\\\ " 'sisu-general-font-lock-red1)
351
352 ;; line break (depreciated)
353 (cons "<br>" 'sisu-general-font-lock-red1)
354
355 ;; Section titles
356 (list "^\\(\\([1-4]\\|:?[A-D]\\)\\~\\)\\(.*\\)"
357 '(1 sisu-title-1 t)
358 '(3 sisu-title-2 t)
359 )
360
361 ;; hyper-links
362 (list
363 (concat
364 "\\({~^\\|{\\)"
365 "\\([^}{]+\\)"
366 "\\(}http:[/][/][^ \r\n\t<]+\\)"
367 )
368 '(1 sisu-general-font-lock-blue2 t)
369 '(2 sisu-general-font-lock-red1 t)
370 '(3 sisu-general-font-lock-blue2 t)
371 )
372
373 ;; book index
374 (list
375 (concat
376 "^\\(\={\\)"
377 "\\([^}{]+\\)"
378 "\\(}\\)$"
379 )
380 '(1 sisu-general-font-lock-green1 t)
381 '(2 nil t)
382 '(3 sisu-general-font-lock-green1 t)
383 )
384
385 ;(cons "^\={.+}" 'sisu-general-font-lock-green1)
386
387 ;; numbers
388 (cons "\\<[.0-9]+\\>" 'sisu-general-font-lock-green2)
389
390 ;; bullets sisu_normal (nearly copied regexp)
391 (cons "^_\\([1-9*]\\|[1-9]\\*\\) " 'sisu-general-font-lock-blue2)
392
393 ;; image links
394 (list
395 (concat
396 "\\({\\)"
397 "\\([^}{]+\\)"
398 "\\(}image\\)"
399 )
400 '(1 sisu-general-font-lock-blue2 t)
401 '(2 sisu-general-font-lock-red1 t)
402 '(3 sisu-general-font-lock-blue2 t)
403 )
404
405 ;; insert file links
406 (list
407 (concat
408 "\\(<< \\)"
409 "\\([^ \r\t\n]+\\.ss\\)"
410 "\\(i\\|t\\)"
411 )
412 '(1 sisu-general-font-lock-blue2 t)
413 '(2 sisu-general-font-lock-blue2 t)
414 '(3 sisu-general-font-lock-blue2 t)
415 )
416
417 ;; raw keywords
418 (list
419 (concat
420 "^\\(\\@\\("
421 "creator\\|"
422 "title\\|"
423 "date\\|"
424 "rights\\|"
425 "publisher\\|"
426 "classify\\|"
427 "identifier\\|"
428 "original\\|"
429 "notes\\|"
430 "links\\|"
431 "make\\|"
432 "\\):\\)\\(.*\\)"
433 )
434 '(1 sisu-title-2 keep)
435 '(3 sisu-title-3 keep)
436 )
437 )
438 )
439 "Default expressions to highlight in AsciiSisu mode."
440 )
441
442 ;; outline mode evil "folding" if available
443 ;; (define-key evil-normal-state-map ",0" 'show-all)
444 ;; (define-key evil-normal-state-map ",-" 'hide-body)
445 ;; (define-key evil-normal-state-map ",+" 'show-subtree)
446 ;; (define-key evil-normal-state-map ",=" 'show-subtree)
447
448 ;;}}}
449
450 ;;{{{ Sisu & Autoload:
451
452 ;;;###autoload
453 (define-derived-mode sisu-mode text-mode "SiSU"
454 "Major mode for editing SiSU files.
455 SiSU document structuring, publishing in multiple formats and search.
456 URL `http://www.sisudoc.org/'"
457 (modify-syntax-entry ?\' ".")
458 ;;(flyspell-mode nil)
459
460 (make-local-variable 'paragraph-start)
461 (setq paragraph-start (concat "$\\|>" page-delimiter))
462 (make-local-variable 'paragraph-separate)
463 (setq paragraph-separate paragraph-start)
464 (make-local-variable 'paragraph-ignore-fill-prefix)
465 (setq paragraph-ignore-fill-prefix t)
466
467 (set (make-local-variable 'outline-regexp)
468 "^\\(\\([1-4]\\|:?[A-D]\\)\\~\\|\\@[a-z]+:\\( \\|$\\)\\)")
469
470 (make-local-variable 'require-final-newline)
471 (setq require-final-newline t)
472
473 (make-local-variable 'font-lock-defaults)
474 (setq font-lock-defaults
475 '(sisu-font-lock-keywords
476 nil ; KEYWORDS-ONLY: no
477 nil ; CASE-FOLD: no
478 ((?_ . "w")) ; SYNTAX-ALIST
479 ))
480 ;; Enable outlining.
481 ;; TODO with outlining make sure linum (line numbering) is off,
482 ;; else performance penalty, sucks bigtime
483 (outline-minor-mode 1))
484
485 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ss[imt]\\'" . sisu-mode))
486
487 (provide 'sisu-mode)
488
489 ;;}}}
490
491 ;;; sisu-mode.el ends here