-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasciidoc.el
411 lines (334 loc) · 12.3 KB
/
asciidoc.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
;;; asciidoc.el --- asciidoc text file development support
;;; http://www.metaperl.com/asciidoc-el/
;; Copyright (C) 2007 Terrence Brannon <[email protected]>
;; Author: Terrence Brannon <[email protected]>
;; Created: 21 Sept 2007
;; Version: 0.1
;; Keywords: text-formatting
;; This file is not (yet) part of GNU Emacs.
;; However, it is distributed under the same license.
;; GNU Emacs 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 2, or (at your option)
;; any later version.
;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Description:
;; Suggested (but entirely optional) add-ons:
;; doc-mode: font-locking for asciidoc buffers
;; http://xpt.sourceforge.net/tools/doc-mode/
;; - connect asciidoc.el to doc-mode as follows:
;; (autoload 'doc-mode "doc-mode" nil t)
;; (add-to-list 'auto-mode-alist '("\\.adoc$" . doc-mode))
;; (add-hook 'doc-mode-hook
;; '(lambda ()
;; (turn-on-auto-fill)
;; (require 'asciidoc)))
;; Author extends thanks to:
;; Steve Youngs (JackaLX on irc://irc.freenode.net/xemacs)
;; bpalmer, twb
;; Version control:
;; This software is under Mercurial version control and maybe retrieved via:
;; hg clone http://hg.metaperl.com/asciidoc-el
;; Code:
(setq debug-on-error t)
(require 'easymenu)
(require 'cl)
(require 'apropos)
(defvar *asciidoc-indent-level* 2 "Number of spaces to indent per level")
(defvar *delimiter-length* 70
"How many characters to use when building a delimited block string. 4 min")
(defun asciidoc-header (title author revision)
"Insert asciidoc header consisting of TITLE and optional AUTHOR and REVISION"
(interactive "sHeader title: \nsHeader author (return if none): \nsHeader revision (return if none):")
(insert
(concat title "\n"
(make-string (length title) ?=) "\n"
author "\n"
revision "\n"
"\n"
)))
(defun asciidoc-get-started ()
(interactive)
(let ((date (format-time-string "%D" (current-time))))
(asciidoc-header "Document Title"
"Terrence Brannon <[email protected]>"
date)))
(defun asciidoc-emphasized (text)
"Insert text with asciidoc emphasis formatting"
(interactive "sText to be emphasized: ")
(insert
(concat "_" text "_")))
(defun asciidoc-strong (text)
"Insert text with asciidoc strong formatting"
(interactive "sText to be strong-formatted: ")
(insert
(concat "*" text "*")))
(defun asciidoc-monospace (text)
"Insert text with asciidoc monospace formatting"
(interactive "sText to be monospace formatted: ")
(insert
(concat "`" text "`")))
(defun asciidoc-quoted (text)
"Insert text with asciidoc quoted-text formatting"
(interactive "sText to be enclosed in quotation marks: ")
(insert
(concat "``" text "''")))
(defun asciidoc-unquoted (text)
"Insert text with asciidoc unquoted text formatting"
(interactive "sText to be non-quoted: ")
(insert
(concat "#" text "#")))
(defun asciidoc-passthru-triple-plus (text)
"Insert text with asciidoc triple plus passthrough formatting"
(interactive "sText to be formatted for no change: ")
(insert
(concat "+++" text "+++")))
(defun asciidoc-passthru-double-dollar (text)
"Insert text with asciidoc double-dollar formatting"
(interactive "sText to be formatted for no change except escaping special characters: ")
(insert
(concat "$$" text "$$")))
(defun asciidoc-passthru-double-dollar (text)
"Insert text with asciidoc double-dollar formatting"
(interactive "sText to be formatted for no change except escaping special characters: ")
(insert
(concat "$$" text "$$")))
(defun asciidoc-superscript (text)
"Insert text with asciidoc superscript formatting"
(interactive "sText to be formatted for superscripting: ")
(insert
(concat "^" text "^")))
(defun asciidoc-subscript (text)
"Insert text with asciidoc subscript formatting"
(interactive "sText to be formatted for subscripting: ")
(insert
(concat "~" text "~")))
(defun asciidoc-line-break ()
"Insert asciidoc forced line break"
(interactive)
(insert
(concat " +\n")))
(defun asciidoc-horizontal-rule ()
"Insert asciidoc <hr /> tag for HTML only"
(interactive)
(insert
(concat "'''\n")))
(defun asciidoc-copyright ()
"Insert asciidoc copyright replacement"
(interactive)
(insert "(C) "))
(defun asciidoc-trademark ()
"Insert asciidoc copyright replacement"
(interactive)
(insert "(TM) "))
(defun asciidoc-registered-trademark ()
"Insert asciidoc registered copyright replacement"
(interactive)
(insert "(R) "))
(defun asciidoc-section-title (section-level title)
"Insert asciidoc one-line title syntax"
(interactive "NNumber of equals signs (2-4): \nsSection title: ")
; " " equals-signs
(let ((equals-signs (make-string (1+ section-level) ?=)))
(insert
(concat
"\n"
equals-signs " " title
"\n\n"))))
(defun asciidoc-block-title (text)
"Insert text with asciidoc block title formatting"
(interactive "sText to be formatted as block title: ")
(insert
(concat "." text "\n")))
(defun asciidoc-block-id-element (text)
"Insert text with asciidoc BlockId Element formatting"
(interactive "sText to be formatted as block-id: ")
(insert
(concat "[[" text "]]" "\n")))
(defun asciidoc-block-reference (block-id descriptive-text)
"Insert asciidoc reference to a block consisting of BLOCK-ID and DESCRIPTIVE-TEXT"
(interactive "sBlockId: \nsDescriptive text: ")
(insert
(concat "<<" block-id "," descriptive-text ">>"
)))
(defun asciidoc-verse-paragraph (text)
"Insert verse paragraph formatting"
(interactive)
(insert (concat "[verse]" "\n")))
(defun asciidoc-literal-paragraph (text)
"Insert literal paragraph formatting"
(interactive)
(insert (concat " " "\n")))
(defun asciidoc-admonition-paragraph (text)
"Insert admonition paragraph formatting"
(interactive)
(insert (concat "[NOTE]" "\n")))
(defun asciidoc-delimited-block (delimiter text)
""
(let ((str (make-string *delimiter-length* delimiter)))
(insert (concat str "\n" text "\n" str "\n\n"))))
(defun asciidoc-comment-block (text)
"create an asciidoc CommentBlock"
(interactive "sText for comment block? ")
(asciidoc-delimited-block ?/ text))
(defun asciidoc-passthru-block (text)
"create an asciidoc PassthroughBlock"
(interactive "sText for passthru block? ")
(asciidoc-delimited-block ?+ text))
(defun asciidoc-listing-block (text)
"create an asciidoc ListingBlock"
(interactive "sText for listing block? ")
(asciidoc-delimited-block ?- text))
(defun asciidoc-literal-block (text)
"create an asciidoc LiteralBlock"
(interactive "sText for literal block? ")
(asciidoc-delimited-block ?. text))
(defun asciidoc-sidebar-block (text)
"create an asciidoc SidebarBlock"
(interactive "sText for sidebar block? ")
(asciidoc-delimited-block ?* text))
(defun asciidoc-example-block (text)
"create an asciidoc ExampleBlock, using TEXT and optionally modifying the default EXAMPLE-LABEL and EXAMPLE-DESCRIPTION"
(interactive "sText for example block? ")
(let ((example-label (read-string "Example label? (it needs a space at the end) " "Example: "))
(example-description (read-string "Example description? " "An example")))
(if (not (string= "" example-label))
(insert "[caption=" "\"" example-label "\"" "]" "\n"))
(if (not (string= "" example-description))
(insert "." example-description "\n"))
(asciidoc-delimited-block ?= text)))
(defun asciidoc-quotation-block (text author source)
"create an asciidoc QuoteBlock"
(interactive "sText of quotation? \nsAuthor of quotation? \nsWhere did this quotation come from? ")
(insert
(concat "["
"attribution=" "\"" author "\""
","
"citetitle=" "\"" source "\""
"]" "\n"))
(asciidoc-delimited-block ?_ text))
(defun asciidoc-compile ()
(interactive)
(setq compile-command
(concat
"asciidoc -a numbered -a toc -a toclevels=4" " "
(file-name-nondirectory (buffer-file-name))
))
(call-interactively 'compile))
(defvar *asciidoc-bullet* '("-" "*")
"strings representing each of the two bullet levels offered by Asciidoc")
(defun asciidoc-bullet-item (bullet-level text)
"At BULLET_LEVEL, insert TEXT"
(interactive "NBullet level (1 or 2): \nsText for bullet: ")
(let* ((level (if (= bullet-level 2) 1 0))
(bullet (nth level *asciidoc-bullet*))
(tab-space (make-string (* level 4) ?\s)))
(insert
(concat
tab-space bullet " " text "\n"))))
(defun asciidoc-numbered-list-item (item-level text)
"At ITEM-LEVEL, insert TEXT"
(interactive "NItem level (1 or 2): \nsText for bullet: ")
(let* ((level (if (= item-level 2) 2 1))
(bullet (make-string level ?.))
(tab-space (make-string (* (- level 1) 4) ?\s)))
(insert
(concat
tab-space bullet " " text "\n"))))
(defun asciidoc-labelled-list-item (text)
"Insert TEXT"
(interactive "sLabel for list item: ")
(insert
(concat
text "::" "\n ")))
(defun asciidoc-bibliography-item (ref-label ref-text)
"Insert bibliography item consisting of REF-LABEL and REF-TEXT"
(interactive "sLabel for bib item: \nsText of bibitem: ")
(insert
(concat
"+" " " "[[[" ref-label "]]]" " " ref-text "\n")))
(defun asciidoc-href (url link-text)
"Insert hyperlink consisting of URL and LINK-TEXT"
(interactive "sURL: \nsText describing URL: ")
(insert
(concat
url "[" link-text "]" "\n"
)))
(defun asciidoc-relative-href (url link-text)
"Insert hyperlink consisting of URL and LINK-TEXT"
(interactive "sRelative path to file (anchors allowed): \nsText describing link: ")
(insert
(concat
"link:"
url "[" link-text "]" "\n"
)))
(defun asciidoc-image-href (url link-text)
"Insert hyperlink consisting of URL and LINK-TEXT"
(interactive "sURL to image file: \nsText describing image (only displayed when image unavailable): ")
(insert
(concat
"image:"
url "[" "\"" link-text "\"" "]" "\n"
)))
(setq asciidoc-global-menuspec
(list "Doc"
(list
"Links and refs"
(vector "Href" 'asciidoc-href)
(vector "Image" 'asciidoc-image-href)
(vector "Relative url" 'asciidoc-relative-href)
(vector "Internal document references" 'asciidoc-block-reference)
)
(list
"Reference items"
(vector "Bibliography listing" 'asciidoc-bibliography-item)
(vector "BlockId element" 'asciidoc-block-id-element))
(list
"Bullets and lists"
(vector "Bulleted list" 'asciidoc-bullet-item)
(vector "Numbered list" 'asciidoc-numbered-list-item)
(vector "Labelled list" 'asciidoc-labelled-list-item)
)
(list
"Text formatting"
(vector "Emphasis" 'asciidoc-emphasized)
(vector "Strong (bold)" 'asciidoc-strong)
(vector "Monospaced" 'asciidoc-monospace)
(vector "Quotation marks around text" 'asciidoc-quoted)
(vector "Superscript" 'asciidoc-superscript)
(vector "Subscript" 'asciidoc-subscript)
)
(list
"Special symbols"
(vector "Copyright" 'asciidoc-copyright)
(vector "Trademark" 'asciidoc-trademark)
(vector "Registered trademark" 'asciidoc-registered-trademark)
)
(list
"Blocks"
(vector "Example block" 'asciidoc-example-block)
(vector "Listing block" 'asciidoc-listing-block)
(vector "Quotation block" 'asciidoc-quotation-block)
(vector "Literal block" 'asciidoc-literal-block)
(vector "Sidebar block" 'asciidoc-sidebar-block)
(vector "Comment block" 'asciidoc-comment-block)
(vector "Pass-through block" 'asciidoc-passthru-triple-plus)
)
(list
"Run Asciidoc"
(vector "Compile" 'asciidoc-compile)
(vector "Recompile" 'recompile)
)
(vector "Start document" 'asciidoc-get-started)
))
(easy-menu-define
asciidoc-global-menu global-map "" asciidoc-global-menuspec)
(provide 'asciidoc)
;;; asciidoc.el ends here