1 ;;; sisu-mode.el --- Major mode for SiSU markup text
3 ;; Copyright (C) 2011, 2016 Free Software Foundation, Inc.
5 ;; Author: Ralph Amissah & Ambrose Kofi Laing
6 ;; Maintainer: Ralph Amissah <ralph.amissah@gmail.com>
7 ;; Keywords: text, syntax, processes, tools
9 ;; URL: http://www.sisudoc.org/
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 ;; with contributions from Kevin Ryde and Stefan Monnier
16 ;; This program is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 3, or (at your option)
21 ;; This program is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
29 ;; Viva Software Libre!
30 ;; Support the free software movement!
31 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;; SiSU (http://www.sisudoc.org/) is a document structuring and
36 ;; publishing framework. This package provides an Emacs major mode
39 ;; When this package is installed, files ending in ".sisu" are
40 ;; automatically associated with sisu-mode. If a file doesn't have a
41 ;; .sisu extension, add a first line:
44 ;; The documentation for the "Structure Of The Hierarchy Text" can be
45 ;; found in the sisustring for the sisu-mode function.
51 (defgroup sisu-faces nil
52 "AsciiSisu highlighting"
56 ; color n is more prominent than color n+1
58 (defface sisu-title-1-face
61 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
64 (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
65 (t (:weight bold :inherit variable-pitch)))
66 "Face for AsciiSisu titles at level 1."
69 (defface sisu-title-2-face
72 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
75 (:foreground "yellow4" :bold t :height 1.1 :inherit variable-pitch))
76 (t (:weight bold :inherit variable-pitch)))
77 "Face for AsciiSisu titles at level 2."
80 (defface sisu-title-3-face
83 (:foreground "sienna3" :bold t))
86 (:foreground "sienna3" :bold t))
88 "Face for AsciiSisu titles at level 3."
91 (defface sisu-title-4-face
94 (:foreground "burlywood3"))
97 (:foreground "burlywood3"))
99 "Face for AsciiSisu titles at level 4."
103 '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
104 (((class color) (background dark)) (:foreground "white" :bold t :italic t))
105 (t (:bold t :italic t)))
106 "Face for Info node names."
109 (defvar sisu-title-1 'sisu-title-1-face)
110 (defvar sisu-title-2 'sisu-title-2-face)
111 (defvar sisu-title-3 'sisu-title-3-face)
112 (defvar sisu-title-4 'sisu-title-4-face)
114 (defvar sisu-general-font-lock-red1 font-lock-warning-face)
115 (defvar sisu-general-font-lock-red2 font-lock-comment-face)
116 (defvar sisu-general-font-lock-red3 font-lock-string-face)
118 (defvar sisu-general-font-lock-green1 font-lock-type-face)
119 (defvar sisu-general-font-lock-green2 font-lock-constant-face)
121 (defvar sisu-general-font-lock-blue1 font-lock-keyword-face)
122 (defvar sisu-general-font-lock-blue2 font-lock-function-name-face)
123 (defvar sisu-general-font-lock-blue3 font-lock-builtin-face)
125 (defvar sisu-general-font-lock-yellow1 font-lock-variable-name-face)
126 (defvar sisu-general-font-lock-yellow2 font-lock-comment-face)
128 ;; == sisu-mode settings
130 (defvar sisu-mode-hook nil
131 "Normal hook run when entering Sisu Text mode.")
133 (defvar sisu-mode-abbrev-table nil
134 "Abbrev table in use in Sisu-mode buffers.")
135 (define-abbrev-table 'sisu-mode-abbrev-table ())
137 (defconst sisu-font-lock-keywords
140 ;;grouped text ---------
141 ;(cons "^```[ ]code\\(.\\|\n\\)+?\n```\n" 'sisu-general-font-lock-red2)
142 (cons "^```[ ]+code.*?$\\|^```$" 'sisu-general-font-lock-red2)
143 (cons "^```[ ]+table.*?$\\|^```$" 'sisu-general-font-lock-red2)
144 (cons "^```[ ]+group$\\|^```$" 'sisu-general-font-lock-red2)
145 (cons "^```[ ]+block$\\|^```$" 'sisu-general-font-lock-red2)
146 (cons "^```[ ]+poem$\\|^```$" 'sisu-general-font-lock-red2)
147 (cons "^```[ ]+alt$\\|^```$" 'sisu-general-font-lock-red2)
148 ;;grouped text ---------
149 (cons "^group{\\|^}group" 'sisu-general-font-lock-red2)
150 (cons "^block{\\|^}block" 'sisu-general-font-lock-red2)
151 (cons "^code{\\|^}code" 'sisu-general-font-lock-red2)
152 (cons "^poem{\\|^}poem" 'sisu-general-font-lock-red2)
153 (cons "^alt{\\|^}alt" 'sisu-general-font-lock-red2)
154 (cons "^table{.+\\|^}table" 'sisu-general-font-lock-red2)
155 (cons "^{table[^}]+}" 'sisu-general-font-lock-red2)
159 "^\`\\{3\\}[ ]+code.*?$"
163 '(1 sisu-general-font-lock-red2 t)
165 '(3 sisu-general-font-lock-red2 t)
169 "^\`\\{3\\}[ ]+table.*?$"
173 '(1 sisu-general-font-lock-red2 t)
175 '(3 sisu-general-font-lock-red2 t)
179 "^\`\\{3\\}[ ]+\\(group\\|block\\|alt\\|poem\\)$"
183 '(1 sisu-general-font-lock-red2 t)
185 '(3 sisu-general-font-lock-red2 t)
188 ;; footnote/endnote ----
189 ;(cons "\~{.+?}\~" 'sisu-general-font-lock-green1)
190 (cons "\~{\\*\\*\\|\~{\\*\\|\~{\\|}\~" 'sisu-general-font-lock-red2)
191 (cons "\~\\[\\+\\|\~\\[\\*\\|\~\\[\\|\\]\~" 'sisu-general-font-lock-red2)
192 (cons "\~\\^ \\|^\\^\~ " 'sisu-general-font-lock-red2)
198 '(1 sisu-general-font-lock-red1 t)
199 '(2 sisu-general-font-lock-blue2 t)
202 ;; emphasis (can be program configured to be bold italics or underscore)
209 '(1 sisu-general-font-lock-red1 t)
210 '(2 sisu-general-font-lock-red1 t)
211 '(3 sisu-general-font-lock-red1 t)
214 ;; bold ----------------
221 '(1 sisu-general-font-lock-red1 t)
222 '(2 sisu-general-font-lock-red1 t)
223 '(3 sisu-general-font-lock-red1 t)
225 (cons "\\*[^ ]+\\*" 'sisu-general-font-lock-red1)
226 (cons "^!_ .+" 'sisu-general-font-lock-red1)
228 ;; italics -------------
235 '(1 sisu-general-font-lock-red1 t)
236 '(2 sisu-general-font-lock-blue1 t)
237 '(3 sisu-general-font-lock-red1 t)
240 ;; underscore ----------
247 '(1 sisu-general-font-lock-red1 t)
248 '(2 sisu-general-font-lock-red1 t)
249 '(3 sisu-general-font-lock-red1 t)
252 ;; monospace -----------
259 '(1 sisu-general-font-lock-red1 t)
260 '(2 sisu-general-font-lock-red1 t)
261 '(3 sisu-general-font-lock-red1 t)
264 ;; citation ------------
271 '(1 sisu-general-font-lock-red1 t)
272 '(2 sisu-general-font-lock-red1 t)
273 '(3 sisu-general-font-lock-red1 t)
276 ;; inserted text -------
283 '(1 sisu-general-font-lock-red1 t)
284 '(2 sisu-general-font-lock-red1 t)
285 '(3 sisu-general-font-lock-red1 t)
288 ;; strike through ------
295 '(1 sisu-general-font-lock-red1 t)
296 '(2 sisu-general-font-lock-red1 t)
297 '(3 sisu-general-font-lock-red1 t)
300 ;; superscript ---------
307 '(1 sisu-general-font-lock-red1 t)
308 '(2 sisu-general-font-lock-red1 t)
309 '(3 sisu-general-font-lock-red1 t)
312 ;; subscript -----------
319 '(1 sisu-general-font-lock-red1 t)
320 '(2 sisu-general-font-lock-red1 t)
321 '(3 sisu-general-font-lock-red1 t)
325 (cons "^# \\|^_# " 'sisu-general-font-lock-red1)
328 (cons "^_\\*[1-9] \\|^_\\* " 'sisu-general-font-lock-red1)
331 (cons "^_[1-9] " 'sisu-general-font-lock-red1)
332 (cons "^_[1-9]! " 'sisu-general-font-lock-red1)
334 ;; hanging indented text [proposed enable when implemented]
335 (cons "^__[1-9] " 'sisu-general-font-lock-red1)
336 (cons "^_[0-9]_[0-9] " 'sisu-general-font-lock-red1)
337 (cons "^__[1-9]! " 'sisu-general-font-lock-red1)
338 (cons "^_[0-9]_[0-9]! " 'sisu-general-font-lock-red1)
341 (cons "\\(^\\|[ ]\\)http:[/][/][^ \t\n\r<]+" 'sisu-general-font-lock-blue2)
344 (cons "^% .*" 'sisu-general-font-lock-blue1)
347 (cons "^\\(-\\\\\\\\-\\|=\\\\\\\\=\\|-\\.\\.-\\)" 'sisu-general-font-lock-red2)
350 (cons " \\\\\\\\ " 'sisu-general-font-lock-red1)
352 ;; line break (depreciated)
353 (cons "<br>" 'sisu-general-font-lock-red1)
356 (list "^\\(\\([1-4]\\|:?[A-D]\\)\\~\\)\\(.*\\)"
366 "\\(}http:[/][/][^ \r\n\t<]+\\)"
368 '(1 sisu-general-font-lock-blue2 t)
369 '(2 sisu-general-font-lock-red1 t)
370 '(3 sisu-general-font-lock-blue2 t)
380 '(1 sisu-general-font-lock-green1 t)
382 '(3 sisu-general-font-lock-green1 t)
385 ;(cons "^\={.+}" 'sisu-general-font-lock-green1)
388 (cons "\\<[.0-9]+\\>" 'sisu-general-font-lock-green2)
390 ;; bullets sisu_normal (nearly copied regexp)
391 (cons "^_\\([1-9*]\\|[1-9]\\*\\) " 'sisu-general-font-lock-blue2)
400 '(1 sisu-general-font-lock-blue2 t)
401 '(2 sisu-general-font-lock-red1 t)
402 '(3 sisu-general-font-lock-blue2 t)
409 "\\([^ \r\t\n]+\\.ss\\)"
412 '(1 sisu-general-font-lock-blue2 t)
413 '(2 sisu-general-font-lock-blue2 t)
414 '(3 sisu-general-font-lock-blue2 t)
434 '(1 sisu-title-2 keep)
435 '(3 sisu-title-3 keep)
439 "Default expressions to highlight in AsciiSisu mode."
442 ;; outline mode evil "folding" if available
443 ;; (define-key evil-normal-state-map ",0" 'show-all)
444 ;; (define-key evil-normal-state-map ",-" 'hide-body)
445 ;; (define-key evil-normal-state-map ",+" 'show-subtree)
446 ;; (define-key evil-normal-state-map ",=" 'show-subtree)
450 ;;{{{ Sisu & Autoload:
453 (define-derived-mode sisu-mode text-mode "SiSU"
454 "Major mode for editing SiSU files.
455 SiSU document structuring, publishing in multiple formats and search.
456 URL `http://www.sisudoc.org/'"
457 (modify-syntax-entry ?\' ".")
458 ;;(flyspell-mode nil)
460 (make-local-variable 'paragraph-start)
461 (setq paragraph-start (concat "$\\|>" page-delimiter))
462 (make-local-variable 'paragraph-separate)
463 (setq paragraph-separate paragraph-start)
464 (make-local-variable 'paragraph-ignore-fill-prefix)
465 (setq paragraph-ignore-fill-prefix t)
467 (set (make-local-variable 'outline-regexp)
468 "^\\(\\([1-4]\\|:?[A-D]\\)\\~\\|\\@[a-z]+:\\( \\|$\\)\\)")
470 (make-local-variable 'require-final-newline)
471 (setq require-final-newline t)
473 (make-local-variable 'font-lock-defaults)
474 (setq font-lock-defaults
475 '(sisu-font-lock-keywords
476 nil ; KEYWORDS-ONLY: no
478 ((?_ . "w")) ; SYNTAX-ALIST
481 ;; TODO with outlining make sure linum (line numbering) is off,
482 ;; else performance penalty, sucks bigtime
483 (outline-minor-mode 1))
485 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ss[imt]\\'" . sisu-mode))
491 ;;; sisu-mode.el ends here