]> code.delx.au - gnu-emacs-elpa/blob - packages/sisu-mode/sisu-mode.el
* sisu-mode.el (sisu-mode): Autoload.
[gnu-emacs-elpa] / packages / sisu-mode / sisu-mode.el
1 ;;; sisu-mode.el --- a major-mode for highlighting a hierarchy structured 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 2011-03-11 (2008-12-14)
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 ;;
35 ;; To enter sisu-mode automatically, add (autoload 'sisu-mode "sisu-mode")
36 ;; to your .emacs file and change the first line of your sisu file to:
37 ;; # -*- Sisu -*-
38 ;; if it doesn't have a .sisu extension.
39 ;;
40 ;; To handle .sisu files, e.g., 'filename.sisu', add something like
41 ;; (add-to-list 'auto-mode-alist '("\\.sisu$" . sisu-mode))
42 ;; to your .emacs file
43
44 ;;
45 ;; The documentation for the "Structure Of The Hierarchy Text" can be found in
46 ;; the sisustring for the sisu-mode function.
47 ;;
48
49 ;;; Code:
50
51 ;;{{{ Variables:
52
53 (defgroup sisu-faces nil
54 "AsciiSisu highlighting"
55 :group 'sisus)
56
57 ;; == Colors
58 ; color n is more prominent than color n+1
59
60 (defface sisu-title-1-face
61 `((((class color)
62 (background dark))
63 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
64 (((class color)
65 (background light))
66 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
67 (t (:weight bold :inherit variable-pitch)))
68 "Face for AsciiSisu titles at level 1."
69 :group 'sisu-faces)
70
71 (defface sisu-title-2-face
72 `((((class color)
73 (background dark))
74 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
75 (((class color)
76 (background light))
77 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
78 (t (:weight bold :inherit variable-pitch)))
79 "Face for AsciiSisu titles at level 2."
80 :group 'sisu-faces)
81
82 (defface sisu-title-3-face
83 `((((class color)
84 (background dark))
85 (:foreground "sienna3" :bold t))
86 (((class color)
87 (background light))
88 (:foreground "sienna3" :bold t))
89 (t (:weight bold)))
90 "Face for AsciiSisu titles at level 3."
91 :group 'sisu-faces)
92
93 (defface sisu-title-4-face
94 `((((class color)
95 (background dark))
96 (:foreground "burlywood3"))
97 (((class color)
98 (background light))
99 (:foreground "burlywood3"))
100 (t ()))
101 "Face for AsciiSisu titles at level 4."
102 :group 'sisu-faces)
103
104 (defface info-node
105 '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
106 (((class color) (background dark)) (:foreground "white" :bold t :italic t))
107 (t (:bold t :italic t)))
108 "Face for Info node names."
109 :group 'sisu-faces)
110
111 (defvar sisu-title-1 'sisu-title-1-face)
112 (defvar sisu-title-2 'sisu-title-2-face)
113 (defvar sisu-title-3 'sisu-title-3-face)
114 (defvar sisu-title-4 'sisu-title-4-face)
115
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
143 ;;grouped text
144 (cons "^group\{\\|^\}group" 'general-font-lock-red2)
145 (cons "^block\{\\|^\}block" 'general-font-lock-red2)
146 (cons "^code\{\\|^\}code" 'general-font-lock-red2)
147 (cons "^poem\{\\|^\}poem" 'general-font-lock-red2)
148 (cons "^alt\{\\|^\}alt" 'general-font-lock-red2)
149 (cons "^table\{.+\\|^\}table" 'general-font-lock-red2)
150 (cons "^\{table[^}]+\}" 'general-font-lock-red2)
151
152 ;; footnote/endnote
153 ;(cons "\~\{.+?\}\~" 'general-font-lock-green1)
154 (cons "\~\{\\*\\*\\|\~\{\\*\\|\~\{\\|\}\~" 'general-font-lock-red2)
155 (cons "\~\\[\\+\\|\~\\[\\*\\|\~\\[\\|\\]\~" 'general-font-lock-red2)
156
157 (cons "\~\\^ \\|^\\^\~ " 'general-font-lock-red2)
158
159 (list (concat
160 "\\(\*\~\\)"
161 "\\([^ \r\t\n]+\\)")
162 '(1 general-font-lock-red1 t)
163 '(2 general-font-lock-blue2 t))
164
165 ;; emphasis (can be program configured to be bold italics or underscore)
166 (list (concat
167 "\\([*]\{\\)"
168 "\\([^\}]+\\)"
169 "\\(\}[*]\\)")
170 '(1 general-font-lock-red1 t)
171 '(2 general-font-lock-red1 t)
172 '(3 general-font-lock-red1 t))
173
174 ;; bold
175 (list (concat
176 "\\([!]\{\\)"
177 "\\([^\}]+\\)"
178 "\\(\}[!]\\)")
179 '(1 general-font-lock-red1 t)
180 '(2 general-font-lock-red1 t)
181 '(3 general-font-lock-red1 t))
182 (cons "\\*[^ ]+\\*" 'general-font-lock-red1)
183 (cons "^!_ .+" 'general-font-lock-red1)
184
185 ;;; italics
186 (list (concat
187 "\\([/]\{\\)"
188 "\\([^\}]+\\)"
189 "\\(\}[/]\\)")
190 '(1 general-font-lock-red1 t)
191 '(2 general-font-lock-blue1 t)
192 '(3 general-font-lock-red1 t))
193
194 ;; underscore
195 (list (concat
196 "\\([_]\{\\)"
197 "\\([^\}]+\\)"
198 "\\(\}[_]\\)")
199 '(1 general-font-lock-red1 t)
200 '(2 general-font-lock-red1 t)
201 '(3 general-font-lock-red1 t))
202
203 ;; monospace
204 (list (concat
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 ;; citation
213 (list (concat
214 "\\([\"]\{\\)"
215 "\\([^\}]+\\)"
216 "\\(\}[\"]\\)")
217 '(1 general-font-lock-red1 t)
218 '(2 general-font-lock-red1 t)
219 '(3 general-font-lock-red1 t))
220
221 ;; inserted text
222 (list (concat
223 "\\([\+]\{\\)"
224 "\\([^\}]+\\)"
225 "\\(\}[\+]\\)")
226 '(1 general-font-lock-red1 t)
227 '(2 general-font-lock-red1 t)
228 '(3 general-font-lock-red1 t))
229
230 ;; strike through
231 (list (concat
232 "\\(\\-\{\\)"
233 "\\([^\}]+\\)"
234 "\\(\}\\-\\)")
235 '(1 general-font-lock-red1 t)
236 '(2 general-font-lock-red1 t)
237 '(3 general-font-lock-red1 t))
238
239 ;; superscript
240 (list (concat
241 "\\(\\^\{\\)"
242 "\\([^\}]+\\)"
243 "\\(\}\\^\\)")
244 '(1 general-font-lock-red1 t)
245 '(2 general-font-lock-red1 t)
246 '(3 general-font-lock-red1 t))
247
248 ;; subscript
249 (list (concat
250 "\\([,]\{\\)"
251 "\\([^\}]+\\)"
252 "\\(\}[,]\\)")
253 '(1 general-font-lock-red1 t)
254 '(2 general-font-lock-red1 t)
255 '(3 general-font-lock-red1 t))
256
257 ;;numbered list
258 (cons "^# \\|^_# " 'general-font-lock-red1)
259
260 ;;bullet text
261 (cons "^_\\*[1-9] \\|^_\\* " 'general-font-lock-red1)
262
263 ;;indented text
264 (cons "^_[1-9] " 'general-font-lock-red1)
265
266 ;;url
267 (cons "\\(^\\|[ ]\\)http:[/][/][^ \t\n\r<]+" 'general-font-lock-blue2)
268
269 ;; \\|\$
270
271 ;; Comment Lines
272 (cons "^% .*" 'general-font-lock-blue1)
273 ;; line break
274 (cons "<br>" 'general-font-lock-red1)
275
276 ;; Section titles
277 (list "^\\(\\([1-8]\\|:?[A-C]\\)\\~\\)\\(.*\\)"
278 '(1 sisu-title-1 t)
279 '(3 sisu-title-2 t))
280
281 ;; hyper-links
282 (list (concat
283 "\\(\{~^\\|\{\\)"
284 "\\([^\}\{]+\\)"
285 "\\(\}http:[/][/][^ \r\n\t<]+\\)")
286 '(1 general-font-lock-blue2 t)
287 '(2 general-font-lock-red1 t)
288 '(3 general-font-lock-blue2 t))
289
290 ;; book index
291 (cons "^\=\{.+\}" 'general-font-lock-green1)
292
293 ;; numbers
294 (cons "\\<[.0-9]+\\>" 'general-font-lock-green2)
295
296 ;; bullets sisu_normal (nearly copied regexp)
297 (cons "^_\\([1-9*]\\|[1-9]\\*\\) " 'general-font-lock-blue2)
298
299 ;; image links
300 (list (concat
301 "\\(\{\\)"
302 "\\([^\}\{]+\\)"
303 "\\(\}image\\)")
304 '(1 general-font-lock-blue2 t)
305 '(2 general-font-lock-red1 t)
306 '(3 general-font-lock-blue2 t))
307
308 ;; insert file links
309 (list (concat
310 "\\(<< \\)"
311 "\\([^ \r\t\n]+\\.ss\\)"
312 "\\(i\\|t\\)")
313 '(1 general-font-lock-blue2 t)
314 '(2 general-font-lock-blue2 t)
315 '(3 general-font-lock-blue2 t))
316
317 ;; raw keywords
318 (list (concat
319 "^\\(\\@\\("
320 "title\\|"
321 "creator\\|"
322 "date\\|"
323 "publisher\\|"
324 "rights\\|"
325 "classify\\|"
326 "original\\|"
327 "notes\\|"
328 "links\\|"
329 "make\\|"
330 "\\):\\)\\(.*\\)")
331 '(1 sisu-title-2 keep)
332 '(3 sisu-title-3 keep))
333
334 ))
335 "Default expressions to highlight in AsciiSisu mode.")
336
337 ;;}}}
338
339 ;;{{{ Sisu & Autoload:
340
341 ;;;###autoload
342 (define-derived-mode sisu-mode text-mode "SiSU"
343 "Major mode for editing SiSU files."
344 (modify-syntax-entry ?\' ".")
345 ;(flyspell-mode nil)
346
347 (make-local-variable 'paragraph-start)
348 (setq paragraph-start (concat "$\\|>" page-delimiter))
349 (make-local-variable 'paragraph-separate)
350 (setq paragraph-separate paragraph-start)
351 (make-local-variable 'paragraph-ignore-fill-prefix)
352 (setq paragraph-ignore-fill-prefix t)
353
354 (make-local-variable 'require-final-newline)
355 (setq require-final-newline t)
356
357 (make-local-variable 'font-lock-defaults)
358 (setq font-lock-defaults
359 '(sisu-font-lock-keywords
360 nil ; KEYWORDS-ONLY: no
361 nil ; CASE-FOLD: no
362 ((?_ . "w")) ; SYNTAX-ALIST
363 ))
364 (run-hooks 'sisu-mode-hook))
365
366 (provide 'sisu-mode)
367
368 ;;}}}
369
370 ;;; sisu-mode.el ends here