]> code.delx.au - gnu-emacs-elpa/blob - packages/sisu-mode/sisu-mode.el
Merge commit 'd827bb511203a64da3ae5cc6910b87b7c99d233b'
[gnu-emacs-elpa] / packages / sisu-mode / sisu-mode.el
1 ;;; sisu-mode.el --- Major mode for SiSU markup text
2
3 ;; Copyright (C) 2011 Free Software Foundation, Inc.
4
5 ;; Author: Ambrose Kofi Laing (& Ralph Amissah)
6 ;; Keywords: text, processes, tools
7 ;; Version: 3.0.3
8 ;; License: GPLv3
9 ;; Home URL: SiSU: http://www.jus.uio.no/sisu
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
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
140 ;;grouped text
141 (cons "^group\{\\|^\}group" 'general-font-lock-red2)
142 (cons "^block\{\\|^\}block" 'general-font-lock-red2)
143 (cons "^code\{\\|^\}code" 'general-font-lock-red2)
144 (cons "^poem\{\\|^\}poem" 'general-font-lock-red2)
145 (cons "^alt\{\\|^\}alt" 'general-font-lock-red2)
146 (cons "^table\{.+\\|^\}table" 'general-font-lock-red2)
147 (cons "^\{table[^}]+\}" 'general-font-lock-red2)
148
149 ;; footnote/endnote
150 ;(cons "\~\{.+?\}\~" 'general-font-lock-green1)
151 (cons "\~\{\\*\\*\\|\~\{\\*\\|\~\{\\|\}\~" 'general-font-lock-red2)
152 (cons "\~\\[\\+\\|\~\\[\\*\\|\~\\[\\|\\]\~" 'general-font-lock-red2)
153
154 (cons "\~\\^ \\|^\\^\~ " 'general-font-lock-red2)
155
156 (list (concat
157 "\\(\*\~\\)"
158 "\\([^ \r\t\n]+\\)")
159 '(1 general-font-lock-red1 t)
160 '(2 general-font-lock-blue2 t))
161
162 ;; emphasis (can be program configured to be bold italics or underscore)
163 (list (concat
164 "\\([*]\{\\)"
165 "\\([^\}]+\\)"
166 "\\(\}[*]\\)")
167 '(1 general-font-lock-red1 t)
168 '(2 general-font-lock-red1 t)
169 '(3 general-font-lock-red1 t))
170
171 ;; bold
172 (list (concat
173 "\\([!]\{\\)"
174 "\\([^\}]+\\)"
175 "\\(\}[!]\\)")
176 '(1 general-font-lock-red1 t)
177 '(2 general-font-lock-red1 t)
178 '(3 general-font-lock-red1 t))
179 (cons "\\*[^ ]+\\*" 'general-font-lock-red1)
180 (cons "^!_ .+" 'general-font-lock-red1)
181
182 ;;; italics
183 (list (concat
184 "\\([/]\{\\)"
185 "\\([^\}]+\\)"
186 "\\(\}[/]\\)")
187 '(1 general-font-lock-red1 t)
188 '(2 general-font-lock-blue1 t)
189 '(3 general-font-lock-red1 t))
190
191 ;; underscore
192 (list (concat
193 "\\([_]\{\\)"
194 "\\([^\}]+\\)"
195 "\\(\}[_]\\)")
196 '(1 general-font-lock-red1 t)
197 '(2 general-font-lock-red1 t)
198 '(3 general-font-lock-red1 t))
199
200 ;; monospace
201 (list (concat
202 "\\([#]\{\\)"
203 "\\([^\}]+\\)"
204 "\\(\}[#]\\)")
205 '(1 general-font-lock-red1 t)
206 '(2 general-font-lock-red1 t)
207 '(3 general-font-lock-red1 t))
208
209 ;; citation
210 (list (concat
211 "\\([\"]\{\\)"
212 "\\([^\}]+\\)"
213 "\\(\}[\"]\\)")
214 '(1 general-font-lock-red1 t)
215 '(2 general-font-lock-red1 t)
216 '(3 general-font-lock-red1 t))
217
218 ;; inserted text
219 (list (concat
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 ;; strike through
228 (list (concat
229 "\\(\\-\{\\)"
230 "\\([^\}]+\\)"
231 "\\(\}\\-\\)")
232 '(1 general-font-lock-red1 t)
233 '(2 general-font-lock-red1 t)
234 '(3 general-font-lock-red1 t))
235
236 ;; superscript
237 (list (concat
238 "\\(\\^\{\\)"
239 "\\([^\}]+\\)"
240 "\\(\}\\^\\)")
241 '(1 general-font-lock-red1 t)
242 '(2 general-font-lock-red1 t)
243 '(3 general-font-lock-red1 t))
244
245 ;; subscript
246 (list (concat
247 "\\([,]\{\\)"
248 "\\([^\}]+\\)"
249 "\\(\}[,]\\)")
250 '(1 general-font-lock-red1 t)
251 '(2 general-font-lock-red1 t)
252 '(3 general-font-lock-red1 t))
253
254 ;;numbered list
255 (cons "^# \\|^_# " 'general-font-lock-red1)
256
257 ;;bullet text
258 (cons "^_\\*[1-9] \\|^_\\* " 'general-font-lock-red1)
259
260 ;;indented text
261 (cons "^_[1-9] " 'general-font-lock-red1)
262
263 ;;url
264 (cons "\\(^\\|[ ]\\)http:[/][/][^ \t\n\r<]+" 'general-font-lock-blue2)
265
266 ;; \\|\$
267
268 ;; Comment Lines
269 (cons "^% .*" 'general-font-lock-blue1)
270 ;; line break
271 (cons "<br>" 'general-font-lock-red1)
272
273 ;; Section titles
274 (list "^\\(\\([1-8]\\|:?[A-C]\\)\\~\\)\\(.*\\)"
275 '(1 sisu-title-1 t)
276 '(3 sisu-title-2 t))
277
278 ;; hyper-links
279 (list (concat
280 "\\(\{~^\\|\{\\)"
281 "\\([^\}\{]+\\)"
282 "\\(\}http:[/][/][^ \r\n\t<]+\\)")
283 '(1 general-font-lock-blue2 t)
284 '(2 general-font-lock-red1 t)
285 '(3 general-font-lock-blue2 t))
286
287 ;; book index
288 (cons "^\=\{.+\}" 'general-font-lock-green1)
289
290 ;; numbers
291 (cons "\\<[.0-9]+\\>" 'general-font-lock-green2)
292
293 ;; bullets sisu_normal (nearly copied regexp)
294 (cons "^_\\([1-9*]\\|[1-9]\\*\\) " 'general-font-lock-blue2)
295
296 ;; image links
297 (list (concat
298 "\\(\{\\)"
299 "\\([^\}\{]+\\)"
300 "\\(\}image\\)")
301 '(1 general-font-lock-blue2 t)
302 '(2 general-font-lock-red1 t)
303 '(3 general-font-lock-blue2 t))
304
305 ;; insert file links
306 (list (concat
307 "\\(<< \\)"
308 "\\([^ \r\t\n]+\\.ss\\)"
309 "\\(i\\|t\\)")
310 '(1 general-font-lock-blue2 t)
311 '(2 general-font-lock-blue2 t)
312 '(3 general-font-lock-blue2 t))
313
314 ;; raw keywords
315 (list (concat
316 "^\\(\\@\\("
317 "title\\|"
318 "creator\\|"
319 "date\\|"
320 "publisher\\|"
321 "rights\\|"
322 "classify\\|"
323 "original\\|"
324 "notes\\|"
325 "links\\|"
326 "make\\|"
327 "\\):\\)\\(.*\\)")
328 '(1 sisu-title-2 keep)
329 '(3 sisu-title-3 keep))
330
331 ))
332 "Default expressions to highlight in AsciiSisu mode.")
333
334 ;;}}}
335
336 ;;{{{ Sisu & Autoload:
337
338 ;;;###autoload
339 (define-derived-mode sisu-mode text-mode "SiSU"
340 "Major mode for editing SiSU files.
341 SiSU (http://www.sisudoc.org/) is a document structuring and
342 publishing framework. This major mode handles SiSU markup."
343 (modify-syntax-entry ?\' ".")
344 ;(flyspell-mode nil)
345
346 (make-local-variable 'paragraph-start)
347 (setq paragraph-start (concat "$\\|>" page-delimiter))
348 (make-local-variable 'paragraph-separate)
349 (setq paragraph-separate paragraph-start)
350 (make-local-variable 'paragraph-ignore-fill-prefix)
351 (setq paragraph-ignore-fill-prefix t)
352
353 (make-local-variable 'require-final-newline)
354 (setq require-final-newline t)
355
356 (make-local-variable 'font-lock-defaults)
357 (setq font-lock-defaults
358 '(sisu-font-lock-keywords
359 nil ; KEYWORDS-ONLY: no
360 nil ; CASE-FOLD: no
361 ((?_ . "w")) ; SYNTAX-ALIST
362 ))
363 (run-hooks 'sisu-mode-hook))
364
365 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.sisu\\'" . sisu-mode))
366
367 (provide 'sisu-mode)
368
369 ;;}}}
370
371 ;;; sisu-mode.el ends here