This repository was archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscriba.el
127 lines (100 loc) · 3.31 KB
/
scriba.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
127
;;; Variables
(defgroup scriba nil
"Scriba Mode."
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
:group 'docs)
(defcustom scriba-mode-hook nil
"List of functions to call when entering Scriba mode."
:type 'hook
:options '(flyspell-mode))
;;; Syntax highlighting
(defvar scriba-font-lock-keywords
'(("@[a-zA-Z]+" . font-lock-keyword-face)
("@begin(\\([a-zA-Z]+\\))" 1 font-lock-function-name-face)
("@end(\\([a-zA-Z]+\\))" 1 font-lock-function-name-face)))
;;; Text insertion and manipulation
(defun scriba-insert-at-sign ()
(interactive)
(insert "@"))
(defun scriba-insert-block (tag-name)
"Insert a @begin/@end block."
(interactive (list (read-string "Tag: ")))
(insert "@begin(" tag-name ")\n\n@end(" tag-name ")"))
(defun scriba-insert-section (title)
"Insert a section."
(interactive (list (read-string "Title: ")))
(insert "@begin(section)\n@title(" title ")\n\n@end(section)"))
(defun scriba-wrap-text (before-text after-text)
"Wrap the selected region in text."
(let ((begin (mark))
(end (point)))
(save-restriction
(narrow-to-region begin end)
(goto-char (point-min))
(insert before-text)
(goto-char (point-max))
(insert after-text))))
(defun scriba-apply-markup (tag)
"Wrap the selected region in markup."
(scriba-wrap-text (concat "@" tag "(")
")"))
(defun scriba-boldify ()
(interactive)
(scriba-apply-markup "b"))
(defun scriba-italicize ()
(interactive)
(scriba-apply-markup "i"))
(defun scriba-underline ()
(interactive)
(scriba-apply-markup "u"))
(defun scriba-strikethrough ()
(interactive)
(scriba-apply-markup "strike"))
(defun scriba-codify ()
(interactive)
(scriba-apply-markup "c"))
(defun scriba-superscript ()
(interactive)
(scriba-apply-markup "sup"))
(defun scriba-subscript ()
(interactive)
(scriba-apply-markup "sub"))
;;; Keybindings
(defvar scriba-mode-map
(let ((map (make-keymap)))
;; Inserting strings
(define-key map "\t" 'scriba-insert-at-sign)
(define-key map "\C-c\C-cb" 'scriba-insert-block)
(define-key map "\C-c\C-cs" 'scriba-insert-section)
;; Markup
(define-key map "\C-c\C-sb" 'scriba-boldify)
(define-key map "\C-c\C-si" 'scriba-italicize)
(define-key map "\C-c\C-su" 'scriba-underline)
(define-key map "\C-c\C-ss" 'scriba-strikethrough)
(define-key map "\C-c\C-sc" 'scriba-codify)
(define-key map "\C-c\C-s^" 'scriba-superscript)
(define-key map "\C-c\C-sv" 'scriba-subscript)
map))
;;; Menu
(easy-menu-define scriba-mode-menu
scriba-mode-map
"Menu used for `scriba-mode'."
'("Scriba"
["Insert block" scriba-insert-block t]
["Insert section" scriba-insert-section t]
"----"
["Bold" scriba-boldify t]
["Italic" scriba-italicize t]
["Underline" scriba-underline t]
["Strikethrough" scriba-strikethrough t]
["Code" scriba-codify t]
["Superscript" scriba-superscript t]
["Subscript" scriba-subscript t]))
;;; File extensions
(add-to-list 'auto-mode-alist
'("\\.scr\\'" . scriba-mode))
;;; Mode
(define-derived-mode scriba-mode text-mode "Scriba"
"Major mode for editing Scriba files."
(setq font-lock-defaults '((scriba-font-lock-keywords))))
(provide 'scriba)