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