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