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