-
Notifications
You must be signed in to change notification settings - Fork 5
/
scribble-mode.el
126 lines (102 loc) · 4.1 KB
/
scribble-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
;;; scribble-mode.el --- Major mode for editing Scribble documents -*- lexical-binding: t; -*-
;; Copyright (c) 2014 Mario Rodas <[email protected]>
;; Author: Mario Rodas <[email protected]>
;; URL: https://github.com/emacs-pe/scribble-mode
;; Keywords: convenience
;; Version: 0.1
;; Package-Requires: ((emacs "24"))
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A major mode for editing Scribble documents.
;;
;; You can install [geiser][] to `scribble-mode-hook' to eldoc and auto
;; completion support:
;;
;; (add-hook 'scribble-mode-hook #'geiser-mode)
;;
;; [geiser]: http://www.nongnu.org/geiser/
;;; Code:
(defgroup scribble-mode nil
"Major mode for editing Scribble documents."
:prefix "scribble-mode-"
:group 'languages)
(defcustom scribble-mode-executable "scribble"
"Path to scribble executable."
:type 'string
:group 'scribble-mode)
(defvar scribble-mode-imenu-generic-expression
`(("Title"
,(rx "@title" (? (: "[" (* (not (any "]")))) "]") "{" (group (+ (not (any "}")))) "}")
1)
("Section"
,(rx "@" (* "sub") "section" (? (: "[" (* (not (any "]")))) "]") "{" (group (+ (not (any "}")))) "}")
1)))
(defvar scribble-mode-syntax-table
(let ((table (make-syntax-table)))
;; Whitespace
(modify-syntax-entry ?\t " " table)
(modify-syntax-entry ?\n "> " table)
(modify-syntax-entry ?\f " " table)
(modify-syntax-entry ?\r " " table)
(modify-syntax-entry ?\s " " table)
(modify-syntax-entry ?\" "\" " table)
(modify-syntax-entry ?\\ "\\ " table)
;; Special characters
(modify-syntax-entry ?' "' " table)
(modify-syntax-entry ?` "' " table)
(modify-syntax-entry ?, "' " table)
(modify-syntax-entry ?@ "' " table)
;; Comments
(modify-syntax-entry ?\@ "' 1" table)
(modify-syntax-entry ?\; "' 2" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?# "w 14" table)
;; Brackets and braces balance for editing convenience.
(modify-syntax-entry ?\[ "(] " table)
(modify-syntax-entry ?\] ")[ " table)
(modify-syntax-entry ?{ "(} " table)
(modify-syntax-entry ?} "){ " table)
(modify-syntax-entry ?\( "() " table)
(modify-syntax-entry ?\) ")( " table)
table)
"Syntax table for `scribble-mode'.")
(defvar scribble-mode-font-lock-keywords
`((,(rx bol (group "#lang") (+ space) (group (1+ not-newline)))
(1 font-lock-keyword-face)
(2 font-lock-variable-name-face))
;; keyword arguments
(,(rx (group "#:" (+ (not (any space ")")))))
(1 font-lock-keyword-face))
;; #t #f
(,(regexp-opt '("#t" "#true" "#f" "#false") 'symbols)
(1 font-lock-constant-face))
(,(rx (group "@" (+ (not (any space "[" "{" "("))))) ; FIXME
(1 font-lock-function-name-face)))
"Font lock for `scribble-mode'.")
;;;###autoload
(define-derived-mode scribble-mode prog-mode "Scribble"
"Major mode for editing scribble files.
\\{scribble-mode-map}"
(set (make-local-variable 'comment-start) "@;")
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'comment-multi-line) nil)
(set (make-local-variable 'font-lock-defaults)
'(scribble-mode-font-lock-keywords))
(set (make-local-variable 'imenu-generic-expression)
scribble-mode-imenu-generic-expression)
(imenu-add-to-menubar "Contents"))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.scrbl\\'" . scribble-mode))
(provide 'scribble-mode)
;;; scribble-mode.el ends here