-
Notifications
You must be signed in to change notification settings - Fork 60
/
.doconce-mode.el
190 lines (163 loc) · 6.45 KB
/
.doconce-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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
;; How to use this file: in .emacs just write
;; (load-file "~/.doconce-mode.el")
;; if this file is in the home directory
;;http://stackoverflow.com/questions/1063115/a-hello-world-example-for-a-major-mode-in-emacs
;;http://ergoemacs.org/emacs/elisp_syntax_coloring.html
;; Key bindings, see http://ergoemacs.org/emacs/keyboard_shortcuts.html
(add-hook 'DocOnce-hook
(lambda ()
(local-set-key (kbd "\C-chelp") "
|--------------------------------------------------------|
| Emacs key | Action |
|----l-------------------------l-------------------------|
| Ctrl+c f | figure |
| Ctrl+c v | movie/video |
| Ctrl+c h1 | heading level 1 (section/h1) |
| Ctrl+c h2 | heading level 2 (subsection/h2) |
| Ctrl+c h3 | heading level 2 (subsection/h3) |
| Ctrl+c hp | heading for paragraph |
| Ctrl+c me | math environment: `!bt` equation `!et`|
| Ctrl+c ma | math environment: `!bt` align `!et` |
| Ctrl+c ce | code environment: `!bc` code `!ec` |
| Ctrl+c cf | code from file: `@@@CODE` |
| Ctrl+c table2 | table with 2 columns |
| Ctrl+c table3 | table with 3 columns |
| Ctrl+c table4 | table with 4 columns |
| Ctrl+c exer | exercise outline |
| Ctrl+c slide | slide outline |
| Ctrl+c help | print this table |
|--------------------------------------------------------|
")
(local-set-key (kbd "\C-cf") "FIGURE: [path, width=400 frac=1.0] caption on one line. label{}")
(local-set-key "\C-ch1" "======= Section heading (h1) =======")
(local-set-key "\C-ch2" "===== Subsection heading (h2) =====")
(local-set-key "\C-ch3" "=== Subsubsection heading (h3) ===")
(local-set-key "\C-chp" "__Paragraph heading.__ ")
(local-set-key "\C-cv" "MOVIE: [path] caption on one line.")
(local-set-key (kbd "\C-cslide") "
!split
===== Slide heading =====
!bslidecell 00
!bpop
* bullet 1
* bullet 2
!epop
!eslidecell
!bslidecell 01
FIGURE: [path, width=400]
!eslidecell
")
(local-set-key (kbd "\C-ctable2") "
|------------------------|
| heading1 | heading2 |
|----l-----------r-------|
| 1.0 | 2.0 |
|------------------------|
")
(local-set-key (kbd "\C-ctable3") "
|-----------------------------------|
| heading1 | heading2 | heading3 |
|----l-----------r------------c-----|
| 1.0 | 2.0 | |
| | | |
|-----------------------------------|
")
(local-set-key (kbd "\C-ctable4") "
|----------------------------------------------|
| heading1 | heading2 | heading3 | heading4 |
|----l-----------r------------c-----------r----|
| 1.0 | 2.0 | | |
| | | | |
|----------------------------------------------|
")
(local-set-key (kbd "\C-cme") "!bt
\\begin{equation}
...
label{}
\\end{equation}
!et")
(local-set-key (kbd "\C-cma") "!bt
\\begin{align}
... &=
label{} \\\\
... &=
label{}
\\end{align}
!et")
(local-set-key (kbd "\C-cce") "!bc
!ec")
(local-set-key (kbd "\C-ccf") "@@@CODE path fromto: start_regex@to_regex")
(local-set-key (kbd "\C-cexer") "===== Exercise: ... =====
label{}
file=solution.pdf
text...
# !bsol
# !esol
# !bsubex
# subexercise...
# !bsol
# !esol
# !esubex
")
)
)
; Syntax highlighting
(make-face 'do-code-face)
(set-face-attribute 'do-code-face nil :family "courier")
(set-face-attribute 'do-code-face nil :slant 'normal)
;(set-face-attribute 'do-code-face nil :background "red")
(make-face 'do-math-face)
(set-face-attribute 'do-math-face nil :family "courier")
(set-face-attribute 'do-math-face nil :slant 'normal)
;(set-face-attribute 'do-math-face nil :height '150)
;(set-face-attribute 'do-math-face nil :height '100)
(set-face-attribute 'do-math-face nil :foreground "lightgray")
(make-face 'do-figmov-face)
;(set-face-attribute 'do-figmov-face nil :background "gray")
;(set-face-attribute 'do-figmov-face nil :slant 'italic)
(set-face-attribute 'do-figmov-face nil :underline t)
(make-face 'do-heading-face)
;(set-face-attribute 'do-heading-face nil :background "yellow")
;(set-face-attribute 'do-heading-face nil :foreground "yellow")
; other colors: lightblue, lightgray, purple
(set-face-attribute 'do-heading-face nil :foreground "red")
(set-face-attribute 'do-heading-face nil :slant 'normal)
;(set-face-attribute 'do-heading-face nil :height '170)
(make-face 'do-emph-face)
(set-face-attribute 'do-emph-face nil :slant 'italic)
(make-face 'do-bold-face)
;(set-face-attribute 'do-bold-face nil :weight 'bold)
(set-face-attribute 'do-bold-face nil :slant 'italic)
(set-face-attribute 'do-bold-face nil :foreground "lightblue")
(make-face 'do-filecode-face)
(set-face-attribute 'do-filecode-face nil :slant 'italic)
(make-face 'do-comment-face)
(set-face-attribute 'do-comment-face nil :slant 'italic)
(set-face-attribute 'do-comment-face nil :foreground "blue")
(make-face 'do-split-face)
(set-face-attribute 'do-split-face nil :background "red")
;;###autoload
(define-generic-mode DocOnce
'(("%<doc>" . "%</doc>")) ; (mako) comment characters
'("bwarning" "ewarning" "bquote" "equote" "bnotice" "enotice" "bsummary" "esummary" "bquestion" "equestion" "bblock" "eblock" "bbox" "ebox" "bsubex" "esubex" "bhint" "ehint" "bsol" "esol" "bans" "eans" "bremarks" "eremarks" "bpop" "epop" "bslidecell" "eslidecell" "idx") ; keywords (!bt used below does not work well)
'(("\\(^!bc[^§]+?!ec\\)" (1 'do-code-face))
("\\(^\\(FIGURE\\|MOVIE\\|AUTHOR\\|TITLE\\):.+$\\)" (1 'do-figmov-face))
("\\(^!bt[^§]+?!et\\)" (1 'do-code-face))
("\\(`.+?`\\)" (1 'do-code-face))
("\\(\\*.+?\\*\\)" (1 'do-emph-face))
("\\(\s+_.+?_\s+\\)" (1 'do-bold-face))
("\\(==+ *.+ *==+\\)" (1 'do-heading-face))
("\\(^__.+?[.:?]__\\)" (1 'do-heading-face))
("\\(^@@@CODE .+\\)" (1 'do-filecode-face))
("\\(^#.+$\\)" (1 'do-comment-face))
("\\(!split\s+\\)" (1 'do-bold-face))
("\\(label\{.+?\}\\)" (1 'do-bold-face))
("\\(ref\{.+?\}\\)" (1 'do-bold-face))
) ; font lock
'("\\.do\\.txt$") ; auto-mode-alist
'(doconce-special-setup) ; function-list
"An example major mode.
We have comments, keywords, a special face for dates, and recognize .hello files.")
(defun doconce-special-setup ()
"Some custom setup stuff done here by mode writer."
(message "You've just enabled the DocOnce mode."))