forked from jmakovicka/adoc-mode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
adoc-mode.el
2998 lines (2682 loc) · 123 KB
/
adoc-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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; adoc-mode.el --- a major-mode for editing AsciiDoc files in Emacs
;;
;; Copyright 2010-2013 Florian Kaufmann <[email protected]>
;;
;; Author: Florian Kaufmann <[email protected]>
;; URL: https://github.com/sensorflo/adoc-mode/wiki
;; Created: 2009
;; Version: 0.6.6
;; Package-Requires: ((markup-faces "1.0.0"))
;; Keywords: wp AsciiDoc
;;
;; This file is not part of GNU Emacs.
;;
;; 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 2, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;
;; The syntax of the following commentary section is Markdown, so the same text
;; can be used for the wiki page on GitHub. Also, each paragraph, including list
;; items, are separated by blank lines, so it also looks good on Marmalade.
;;; Commentary:
;;
;; # Introduction
;;
;; [AsciiDoc](http://www.methods.co.nz/asciidoc/) is a text document format for
;; writing short documents, articles, books and UNIX man pages. AsciiDoc files
;; can be translated to HTML and DocBook markups.
;;
;; adoc-mode is an Emacs major mode for editing AsciiDoc files. It emphasizes on
;; the idea that the document is highlighted so it pretty much looks like the
;; final output. What must be bold is bold, what must be italic is italic etc.
;; Meta characters are naturally still visible, but in a faint way, so they can
;; be easily ignored.
;;
;;
;; # Download
;;
;; The raw file (adoc-mode.el) can be found
;; [here](https://raw.github.com/sensorflo/adoc-mode/master/adoc-mode.el).
;; Optionally you can get the sources from the [git
;; repository](https://github.com/sensorflo/adoc-mode).
;;
;; You will also need to download the library
;; [markup-faces](https://github.com/sensorflo/markup-faces). If you install
;; adoc-mode via Emacs Lisp Packages, see below, markup-faces is installed
;; automatically if you don't have it yet.
;;
;;
;; # Installation
;;
;; Installation is as usual, so if you are proficient with Emacs you don't need
;; to read this.
;;
;; ## Install the traditional way
;;
;; 1. Copy the file adoc-mode.el to a directory in your load-path, e.g.
;; \~/.emacs.d. To add a specific directory to the load path, add this to our
;; initialization file (probably ~/.emacs): `(add-to-list 'load-path
;; "mypath")`
;;
;; 2. Add either of the two following lines to your initialization file. The
;; first only loads adoc mode when necessary, the 2nd always during startup
;; of Emacs.
;;
;; * `(autoload 'adoc-mode "adoc-mode" nil t)`
;;
;; * `(require 'adoc-mode)`
;;
;; 3. Optionally byte compile adoc-mode.el for faster startup: `M-x
;; byte-compile`
;;
;; 4. To use adoc mode, call adoc-mode after you opened an AsciiDoc file: `M-x
;; adoc-mode`
;;
;;
;; ## Install via Emacs Lisp Packages (on Marmalade)
;;
;; For this way you either need packages.el from
;; [here](https://github.com/technomancy/package.el) and or Emacs 24, where the
;; packages library is already included. adoc-mode is on the
;; [Marmalade](http://marmalade-repo.org/) package archive.
;;
;; * Type `M-x package-install RET adoc-mode RET`.
;;
;;
;; ## Possible steps after installation
;;
;; Each of the following is optional
;;
;; * According to AsciiDoc manual, .txt is the standard file extension of
;; AsciiDoc files. Add the following to your initialization file to open all
;; .txt files with adoc-mode as major mode automatically: `(add-to-list
;; 'auto-mode-alist (cons "\\.txt\\'" 'adoc-mode))`
;;
;; * If your default face is a fixed pitch (monospace) face, but in AsciiDoc
;; files you liked to have normal text with a variable pitch face,
;; buffer-face-mode is for you: `(add-hook 'adoc-mode-hook (lambda()
;; (buffer-face-mode t)))`
;;
;;
;; # Features
;;
;; - sophisticated highlighting
;;
;; - promote / demote title
;;
;; - toggle title type between one line title and two line title
;;
;; - adjust underline length of a two line title to match title text's length
;;
;; - goto anchor defining a given id, default reading from xref at point
;;
;; - support for outline (however only with the one-line title style)
;;
;;
;; ## Coming features
;;
;; The next features I plan to implement
;;
;; - Demote / promote for list items
;; - Outline support also for two line titles
;; - Correctly highlighting backslash escapes
;;
;;
;; # Screenshot
;;
;; The highlighting emphasizes on how the output will look like. _All_
;; characters are visible, however meta characters are displayed in a faint way.
;;
;; ![screenshot](http://dl.dropbox.com/u/75789984/adoc-mode.png)
;;
;;
;;; Todo:
;; - Fontlock
;; - make font-lock regexps based upon AsciiDoc configuration file, or make
;; them configurable in a way similar to that configuration file
;; - respect font-lock-maximum-decoration
;; - delimited blocks are supported, but not well at all
;; - Most regexps for highlighting can spawn at most over two lines.
;; - font-lock's multi line capabilities are not used well enough. At least 2
;; line spawns should be covered - replace all .*? by .*?\\(?:\n.*?\\)??
;; - backslash escapes are seldom highlighted correctly
;; - Other common Emacs functionality/features
;; - demote/promote/create/delete titles/list-items. Also put emphasis on a
;; convenient simple user interface.
;; - hideshow
;; - outline mode shall support two line titles
;; - tags tables for anchors, indixes, bibliography items, titles, ...
;; - spell check shall ignore meta characters
;; - supply a regexp for magic-mode-alist
;; - Is there something that would remove hard newlines within a paragraph,
;; but just for display, so the paragraph uses the whole buffer length.
;; - are there generic base packages to handle lists / tables?
;; - a read only view mode where commands for navigation are on short key
;; bindings like alphanum letters
;; - study what other markup modes like rst offer
;; - AsciiDoc related features
;; - Two (or gradually fading) display modes: one emphasises to see the
;; AsciiDoc source text, the other emphasises to see how the output will
;; look like. Or even hide meta characters all together
;;; Variables:
(require 'markup-faces) ; https://github.com/sensorflo/markup-faces
(require 'cl-lib)
(require 'tempo)
(defconst adoc-mode-version "0.6.6"
"adoc mode version number.
Based upon AsciiDoc version 8.5.2. I.e. regexeps and rules are
taken from that version's asciidoc.conf / manual.")
;;;; customization
(defgroup adoc nil
"Major-mode for editing AsciiDoc files in Emacs.
Most faces adoc-mode uses belong to the markup-faces
customization group, see link below, and have to be customized
there. adoc-mode has only a few faces of its own, which can be
customized on this page."
:group 'wp
:link '(custom-group-link markup-faces))
(defcustom adoc-script-raise '(-0.3 0.3)
"How much to lower and raise subscript and superscript content.
This is a list of two floats. The first is negative and specifies
how much subscript is lowered, the second is positive and
specifies how much superscript is raised. Heights are measured
relative to that of the normal text. The faces used are
markup-superscript-face and markup-subscript-face respectively.
You need to call `adoc-calc' after a change."
:type '(list (float :tag "Subscript")
(float :tag "Superscript"))
:group 'adoc)
;; Interacts very badly with minor-modes using overlays because
;; adoc-unfontify-region-function removes ALL overlays, not only those which
;; where insered by adoc-mode.
(defcustom adoc-insert-replacement nil
"When non-nil the character/string a replacment/entity stands for is displayed.
E.g. after '&' an '&' is displayed, after '(C)' the copy right
sign is displayed. It's only about display, neither the file nor
the buffer content is affected.
Setting it to non-nil interacts very badly with minor-modes using
overlays."
:type 'boolean
:group 'adoc)
(defcustom adoc-two-line-title-del '("==" "--" "~~" "^^" "++")
"Delimiter used for the underline of two line titles.
Each string must be exactly 2 characters long. Corresponds to the
underlines element in the titles section of the asciidoc
configuration file."
:type '(list
(string :tag "level 0")
(string :tag "level 1")
(string :tag "level 2")
(string :tag "level 3")
(string :tag "level 4") )
:group 'adoc)
(defcustom adoc-delimited-block-del
'("^/\\{4,\\}" ; 0 comment
"^\\+\\{4,\\}" ; 1 pass
"^-\\{4,\\}" ; 2 listing
"^\\.\\{4,\\}" ; 3 literal
"^_\\{4,\\}" ; 4 quote
"^=\\{4,\\}" ; 5 example
"^\\*\\{4,\\}" ; 6 sidebar
"^--") ; 7 open block
"Regexp used for delimited blocks.
WARNING: They should not contain a $. It is implied that they
match up to end of the line;
They correspond to delimiter variable blockdef-xxx sections in
the AsciiDoc configuration file.
However contrary to the AsciiDoc configuration file a separate
regexp can be given for the start line and for the end line. You
may want to do that because adoc-mode often can't properly
distinguish between a) a two line tile b) start of a delimited
block and c) end of a delimited block. If you start a listing
delimited block with '>----' and end it with '<----', then all
three cases can easily be distinguished. The regexp in your
AsciiDoc config file would the probably be '^[<>]-{4,}$'"
:type '(list
(choice :tag "comment"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "pass"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "listing"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "literal"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "quote"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "example"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "sidebar"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))
(choice :tag "open"
(regexp :tag "start/end regexp")
(list :tag "separate regexp"
(regexp :tag "start regexp")
(regexp :tag "end regexp")))))
;; todo: limit value range to 1 or 2
(defcustom adoc-default-title-type 1
"Default title type, see `adoc-title-descriptor'."
:type 'integer
:group 'adoc)
;; todo: limit value range to 1 or 2
(defcustom adoc-default-title-sub-type 1
"Default title sub type, see `adoc-title-descriptor'."
:type 'integer
:group 'adoc )
(defcustom adoc-enable-two-line-title t
"Whether or not two line titles shall be fontified.
nil means never fontify. t means always fontify. A number means
only fontify if the line below has NOT the lenght of the given
number. You could use a number for example when all your
delimited block lines have a certain length.
This is usefull because adoc-mode has troubles to properly
distinguish between two line titles and a line of text before a
delimited block. Note however that adoc-mode knows the AsciiDoc
rule that the length of a two line title underline can differ at
most 3 chars from the length of the title text."
:type '(choice (const nil)
(const t)
number)
:group 'adoc)
(defcustom adoc-title-style 'adoc-title-style-one-line
"Title style used for title tempo templates.
See for example `tempo-template-adoc-title-1'."
:type '(choice (const :tag "== one line" adoc-title-style-one-line)
(const :tag "== one line enclosed ==" adoc-title-style-one-line-enclosed)
(const :tag "two line\\n--------" adoc-title-style-two-line))
:group 'adoc)
(defcustom adoc-tempo-frwk 'tempo-vanilla
"Tempo framework to be used by adoc's templates. "
:type '(choice (const :tag "tempo" tempo-vanilla)
(const :tag "tempo-snippets" tempo-snippets))
:group 'adoc)
;;;; faces / font lock
(define-obsolete-face-alias 'adoc-orig-default 'adoc-align "23.3")
(defface adoc-align
'((t (:inherit (markup-meta-face))))
"Face used so the text looks left aligned.
Is applied to whitespaces at the beginning of a line. You want to
set it to a fixed width face. This is useful if your default face
is a variable with face. Because for e.g. in a variable with
face, '- ' and ' ' (two spaces) don't have equal with, with
`adoc-align' in the following example the item's text looks
aligned.
- lorem ipsum
dolor ..."
:group 'adoc)
(define-obsolete-face-alias 'adoc-generic 'markup-gen-face "23.3")
(define-obsolete-face-alias 'adoc-monospace 'markup-typewriter-face "23.3")
(define-obsolete-face-alias 'adoc-strong 'markup-strong-face "23.3")
(define-obsolete-face-alias 'adoc-emphasis 'markup-emphasis-face "23.3")
(define-obsolete-face-alias 'adoc-superscript 'markup-superscript-face "23.3")
(define-obsolete-face-alias 'adoc-subscript 'markup-subscript-face "23.3")
(define-obsolete-face-alias 'adoc-secondary-text 'markup-secondary-text-face "23.3")
(define-obsolete-face-alias 'adoc-replacement 'markup-replacement-face "23.3")
(define-obsolete-face-alias 'adoc-complex-replacement 'markup-complex-replacement-face "23.3")
(define-obsolete-face-alias 'adoc-list-item 'markup-list-face "23.3")
(define-obsolete-face-alias 'adoc-table-del 'markup-table-face "23.3")
(define-obsolete-face-alias 'adoc-reference 'markup-reference-face "23.3")
(define-obsolete-face-alias 'adoc-delimiter 'markup-meta-face "23.3")
(define-obsolete-face-alias 'adoc-hide-delimiter 'markup-hide-delimiter-face "23.3")
(define-obsolete-face-alias 'adoc-anchor 'markup-anchor-face "23.3")
(define-obsolete-face-alias 'adoc-comment 'markup-comment-face "23.3")
(define-obsolete-face-alias 'adoc-warning 'markup-error-face "23.3")
(define-obsolete-face-alias 'adoc-preprocessor 'markup-preprocessor-face "23.3")
;; Despite the comment in font-lock.el near 'defvar font-lock-comment-face', it
;; seems I still need variables to refer to faces in adoc-font-lock-keywords.
;; Not having variables and only referring to face names in
;; adoc-font-lock-keywords does not work.
(defvar adoc-align 'adoc-align)
(defvar adoc-generic 'markup-gen-face)
(defvar adoc-monospace 'markup-typewriter-face)
(defvar adoc-replacement 'markup-replacement-face)
(defvar adoc-complex-replacement 'markup-complex-replacement-face)
(defvar adoc-table-del 'markup-table-face)
(defvar adoc-reference 'markup-reference-face)
(defvar adoc-secondary-text 'markup-secondary-text-face)
(defvar adoc-delimiter 'markup-meta-face)
(defvar adoc-hide-delimiter 'markup-meta-hide-face)
(defvar adoc-anchor 'markup-anchor-face)
(defvar adoc-comment 'markup-comment-face)
(defvar adoc-warning 'markup-error-face)
(defvar adoc-preprocessor 'markup-preprocessor-face)
;;;; misc
(defconst adoc-title-max-level 4
"Max title level, counting starts at 0.")
(defconst adoc-uolist-max-level 5
"Max unordered (bulleted) list item nesting level, counting starts at 0.")
;; I think it's actually not worth the fuzz to try to sumarize regexps until
;; profiling profes otherwise. Nevertheless I can't stop doing it.
(defconst adoc-summarize-re-uolisti t
"When non-nil, sumarize regexps for unordered list items into one regexp.
To become a customizable variable when regexps for list items
become customizable.")
(defconst adoc-summarize-re-olisti t
"As `adoc-summarize-re-uolisti', but for ordered list items.")
(defconst adoc-summarize-re-llisti t
"As `adoc-summarize-re-uolisti', but for labeled list items.")
(defvar adoc-unichar-alist nil
"An alist, key=unicode character name as string, value=codepoint.")
;; altough currently always the same face is used, I prefer an alist over a
;; list. It is faster to find out wheter any attribute id is in the alist or
;; not. And maybe markup-faces splits up markup-secondary-text-face into more
;; specific faces.
(defvar adoc-attribute-face-alist
'(("id" . markup-anchor-face)
("caption" . markup-secondary-text-face)
("xreflabel" . markup-secondary-text-face)
("alt" . markup-secondary-text-face)
("title" . markup-secondary-text-face)
("attribution" . markup-secondary-text-face)
("citetitle" . markup-secondary-text-face)
("text" . markup-secondary-text-face))
"An alist, key=attribute id, value=face.")
(defvar adoc-mode-abbrev-table nil
"Abbrev table in use in adoc-mode buffers.")
(defvar adoc-font-lock-keywords nil
"Font lock keywords in adoc-mode buffers.")
(defvar adoc-replacement-failed nil )
(define-abbrev-table 'adoc-mode-abbrev-table ())
(defvar adoc-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-d" 'adoc-demote)
(define-key map "\C-c\C-p" 'adoc-promote)
(define-key map "\C-c\C-t" 'adoc-toggle-title-type)
(define-key map "\C-c\C-g" 'adoc-goto-ref-label)
map)
"Keymap used in adoc mode.")
;;;; help text copied from asciidoc manual
(defconst adoc-help-constrained-quotes
"Constrained quotes must be bounded by white space or commonly
adjoining punctuation characters. These are the most commonly
used type of quote.")
(defconst adoc-help-emphasis
"Usually rendered italic")
(defconst adoc-help-strong
"Usually rendered bold")
(defconst adoc-help-monospace
"Aka typewritter. This does _not_ mean verbatim / literal")
(defconst adoc-help-single-quote
"Single quotation marks around enclosed text.")
(defconst adoc-help-double-quote
"Quotation marks around enclosed text.")
(defconst adoc-help-attributed
"A mechanism to allow inline attributes to be applied to
otherwise unformatted text.")
(defconst adoc-help-unconstrained-quotes
"Unconstrained quotes have no boundary constraints and can be
placed anywhere within inline text.")
(defconst adoc-help-line-break
"A plus character preceded by at least one space character at
the end of a non-blank line forces a line break. It generates a
line break (`br`) tag for HTML outputs and a custom XML
`asciidoc-br` processing instruction for DocBook outputs")
(defconst adoc-help-page-break
"A line of three or more less-than (`<<<`) characters will
generate a hard page break in DocBook and printed HTML
outputs.")
(defconst adoc-help-ruler-line
"A line of three or more apostrophe characters will generate a
ruler line. It generates a ruler (`hr`) tag for HTML outputs
and a custom XML `asciidoc-hr` processing instruction for
DocBook outputs.")
(defconst adoc-help-entity-reference
"You can also include arbitrary character entity references in
the AsciiDoc source. Example both `&` and `&` are
replace by an & (ampersand).")
(defconst adoc-help-literal-paragraph
"Verbatim in a monospaced font. Applyied to paragraphs where
the first line is indented by one or more space or tab
characters")
(defconst adoc-help-delimited-block
"Delimited blocks are blocks of text enveloped by leading and
trailing delimiter lines (normally a series of four or more
repeated characters).")
(defconst adoc-help-delimited-block-comment
"The contents of 'CommentBlocks' are not processed; they are
useful for annotations and for excluding new or outdated
content that you don't want displayed. CommentBlocks are never
written to output files.")
(defconst adoc-help-delimited-block-passthrouh
"By default the block contents is subject only to 'attributes'
and 'macros' substitutions (use an explicit 'subs' attribute to
apply different substitutions). PassthroughBlock content will
often be backend specific. The following styles can be applied
to passthrough blocks: pass:: No substitutions are performed.
This is equivalent to `subs=\"none\"`. asciimath, latexmath::
By default no substitutions are performed, the contents are
rendered as mathematical formulas.")
(defconst adoc-help-delimited-block-listing
"'ListingBlocks' are rendered verbatim in a monospaced font,
they retain line and whitespace formatting and are often
distinguished by a background or border. There is no text
formatting or substitutions within Listing blocks apart from
Special Characters and Callouts. Listing blocks are often used
for computer output and file listings.")
(defconst adoc-help-delimited-block-literal
"'LiteralBlocks' are rendered just like literal paragraphs.")
(defconst adoc-help-delimited-block-quote
"'QuoteBlocks' are used for quoted passages of text. There are
two styles: 'quote' and 'verse'. The style behavior is
identical to quote and verse paragraphs except that blocks can
contain multiple paragraphs and, in the case of the 'quote'
style, other section elements. The first positional attribute
sets the style, if no attributes are specified the 'quote'
style is used. The optional 'attribution' and 'citetitle'
attributes (positional attributes 2 and3) specify the quote's
author and source.")
(defconst adoc-help-delimited-block-example
"'ExampleBlocks' encapsulate the DocBook Example element and
are used for, well, examples. Example blocks can be titled by
preceding them with a 'BlockTitle'. DocBook toolchains will
normally automatically number examples and generate a 'List of
Examples' backmatter section.
Example blocks are delimited by lines of equals characters and
can contain any block elements apart from Titles, BlockTitles
and Sidebars) inside an example block.")
(defconst adoc-help-delimited-block-sidebar
"A sidebar is a short piece of text presented outside the
narrative flow of the main text. The sidebar is normally
presented inside a bordered box to set it apart from the main
text.The sidebar body is treated like a normal section body.")
(defconst adoc-help-delimited-block-open-block
"An 'OpenBlock' groups a set of block elements.")
(defconst adoc-help-list
"Indentation is optional and does _not_ determine nesting.")
(defconst adoc-help-bulleted-list
"Aka itimized or unordered.")
(defconst adoc-help-list-item-continuation
"Another list or a literal paragraph immediately following a
list item is implicitly appended to the list item; to append
other block elements to a list item you need to explicitly join
them to the list item with a 'list continuation' (a separator
line containing a single plus character). Multiple block
elements can be appended to a list item using list
continuations (provided they are legal list item children in
the backend markup).")
(defconst adoc-help-table
"The AsciiDoc table syntax looks and behaves like other
delimited block types and supports standard block configuration
entries.")
(defconst adoc-help-macros
"Inline Macros occur in an inline element context. A Block
macro reference must be contained in a single line separated
either side by a blank line or a block delimiter. Block macros
behave just like Inline macros, with the following differences:
1) They occur in a block context. 2) The default syntax is
<name>::<target>[<attrlist>] (two colons, not one). 3) Markup
template section names end in -blockmacro instead of
-inlinemacro.")
(defconst adoc-help-url
"If you don’t need a custom link caption you can enter the
http, https, ftp, file URLs and email addresses without any
special macro syntax.")
(defconst adoc-help-anchor
"Used to specify hypertext link targets. The `<id>` is a unique
string that conforms to the output markup's anchor syntax. The
optional `<xreflabel>` is the text to be displayed by
captionless 'xref' macros that refer to this anchor.")
(defconst adoc-help-xref
"Creates a hypertext link to a document anchor. The `<id>`
refers to an anchor ID. The optional `<caption>` is the link's
displayed text.")
(defconst adoc-help-local-doc-link
"Hypertext links to files on the local file system are
specified using the link inline macro.")
(defconst adoc-help-local-doc-link
"Hypertext links to files on the local file system are
specified using the link inline macro.")
(defconst adoc-help-comment
"Single lines starting with two forward slashes hard up against
the left margin are treated as comments. Comment lines do not
appear in the output unless the showcomments attribute is
defined. Comment lines have been implemented as both block and
inline macros so a comment line can appear as a stand-alone
block or within block elements that support inline macro
expansion.")
(defconst adoc-help-passthrough-macros
"Passthrough macros are analogous to passthrough blocks and are
used to pass text directly to the output. The substitution
performed on the text is determined by the macro definition but
can be overridden by the <subslist>. Passthroughs, by
definition, take precedence over all other text
substitutions.")
(defconst adoc-help-pass
"Inline and block. Passes text unmodified (apart from
explicitly specified substitutions).")
(defconst adoc-help-asciimath
"Inline and block. Passes text unmodified. A (backend
dependent) mechanism for rendering mathematical formulas given
using the ASCIIMath syntax.")
(defconst adoc-help-latexmath
"Inline and block. Passes text unmodified. A (backend
dependent) mechanism for rendering mathematical formulas given
using the LaTeX math syntax.")
(defconst adoc-help-pass-+++
"Inline and block. The triple-plus passthrough is functionally
identical to the pass macro but you don’t have to escape ]
characters and you can prefix with quoted attributes in the
inline version.")
(defconst adoc-help-pass-$$
"Inline and block. The double-dollar passthrough is
functionally identical to the triple-plus passthrough with one
exception: special characters are escaped.")
(defconst adoc-help-monospace-literal
"Text quoted with single backtick characters constitutes an
inline literal passthrough. The enclosed text is rendered in a
monospaced font and is only subject to special character
substitution. This makes sense since monospace text is usually
intended to be rendered literally and often contains characters
that would otherwise have to be escaped. If you need monospaced
text containing inline substitutions use a plus character
instead of a backtick.")
;;; Code:
;;;; regexps
;; from AsciiDoc manual: The attribute name/value syntax is a single line ...
;; from asciidoc.conf:
;; ^:(?P<attrname>\w[^.]*?)(\.(?P<attrname2>.*?))?:(\s+(?P<attrvalue>.*))?$
;; asciidoc src code: AttributeEntry.isnext shows that above regexp is matched
;; against single line.
(defun adoc-re-attribute-entry ()
(concat "^\\(:[a-zA-Z0-9_][^.\n]*?\\(?:\\..*?\\)?:[ \t]*\\)\\(.*?\\)$"))
;; from asciidoc.conf: ^= +(?P<title>[\S].*?)( +=)?$
;; asciidoc src code: Title.isnext reads two lines, which are then parsed by
;; Title.parse. The second line is only for the underline of two line titles.
(defun adoc-re-one-line-title (level)
"Returns a regex matching a one line title of the given LEVEL.
When LEVEL is nil, a one line title of any level is matched.
match-data has these sub groups:
1 leading delimiter inclusive whites between delimiter and title text
2 title's text exclusive leading/trailing whites
3 trailing delimiter with all whites
4 trailing delimiter only inclusive whites between title text and delimiter
0 only chars that belong to the title block element
== my title == n
---12------23------
4--4"
(let* ((del (if level
(make-string (+ level 1) ?=)
(concat "=\\{1," (+ adoc-title-max-level 1) "\\}"))))
(concat
"^\\(" del "[ \t]+\\)" ; 1
"\\([^ \t\n].*?\\)" ; 2
;; using \n instad $ is important so group 3 is guaranteed to be at least 1
;; char long (except when at the end of the buffer()). That is important to
;; to have a place to put the text property adoc-reserved on.
"\\(\\([ \t]+" del "\\)?[ \t]*\\(?:\n\\|\\'\\)\\)" ))) ; 3 & 4
(defun adoc-make-one-line-title (sub-type level text)
"Returns a one line title of LEVEL and SUB-TYPE containing the given text."
(let ((del (make-string (+ level 1) ?=)))
(concat del " " text (when (eq sub-type 2) (concat " " del)))))
;; AsciiDoc handles that by source code, there is no regexp in AsciiDoc. See
;; also adoc-re-one-line-title.
(defun adoc-re-two-line-title-undlerline (&optional del)
"Returns a regexp matching the underline of a two line title.
DEL is an element of `adoc-two-line-title-del' or nil. If nil,
any del is matched.
Note that even if this regexp matches it still doesn't mean it is
a two line title underline, see also `adoc-re-two-line-title'."
(concat
"\\("
(mapconcat
(lambda(x)
(concat
"\\(?:"
"\\(?:" (regexp-quote x) "\\)+"
(regexp-quote (substring x 0 1)) "?"
"\\)"))
(if del (list del) adoc-two-line-title-del) "\\|")
;; adoc-re-two-line-title shall have same behaviour als one line, thus
;; also here use \n instead $
"\\)[ \t]*\\(?:\n\\|\\'\\)"))
;; asciidoc.conf: regexp for _first_ line
;; ^(?P<title>.*?)$ additionally, must contain (?u)\w, see Title.parse
(defun adoc-re-two-line-title (del)
"Returns a regexps that matches a two line title.
Note that even if this regexp matches it still doesn't mean it is
a two line title. You additionaly have to test if the underline
has the correct length.
DEL is described in `adoc-re-two-line-title-undlerline'.
match-data has these sub groups:
1 dummy, so that group 2 is the title's text as in
adoc-re-one-line-title
2 title's text
3 delimiter
0 only chars that belong to the title block element"
(when (not (eq (length del) 2))
(error "two line title delimiters must be 2 chars long"))
(concat
;; 1st line: title text must contain at least one \w character, see
;; asciidoc src, Title.parse,
"\\(\\)\\(^.*?[a-zA-Z0-9_].*?\\)[ \t]*\n"
;; 2nd line: underline
(adoc-re-two-line-title-undlerline del)))
(defun adoc-make-two-line-title (level text)
"Returns a two line title of given LEVEL containing given TEXT.
LEVEL starts at 1."
(concat text "\n" (adoc-make-two-line-title-underline level (length text))))
(defun adoc-make-two-line-title-underline (level &optional length)
"Returns a two line title underline.
LEVEL is the level of the title, starting at 1. LENGTH is the
line of the title's text. When nil it defaults to 4."
(unless length
(setq length 4))
(let* ((repetition-cnt (if (>= length 2) (/ length 2) 1))
(del (nth level adoc-two-line-title-del))
(result ""))
(while (> repetition-cnt 0)
(setq result (concat result del))
(setq repetition-cnt (- repetition-cnt 1)))
(when (eq (% length 2) 1)
(setq result (concat result (substring del 0 1))))
result))
(defun adoc-re-oulisti (type &optional level sub-type)
"Returns a regexp matching an (un)ordered list item.
match-data his this sub groups:
1 leading whites
2 delimiter
3 trailing whites between delimiter and item's text
0 only chars belonging to delimiter/whites. I.e. none of text.
WARNING: See warning about list item nesting level in `adoc-list-descriptor'."
(cond
;; ^\s*- +(?P<text>.+)$ normal 0
;; ^\s*\* +(?P<text>.+)$ normal 1
;; ... ...
;; ^\s*\*{5} +(?P<text>.+)$ normal 5
;; ^\+ +(?P<text>.+)$ bibliograpy(DEPRECATED)
((eq type 'adoc-unordered)
(cond
((or (eq sub-type 'adoc-normal) (null sub-type))
(let ((r (cond ((numberp level) (if (eq level 0) "-" (make-string level ?\*)))
((or (null level) (eq level 'adoc-all-levels)) "-\\|\\*\\{1,5\\}")
(t (error "adoc-unordered/adoc-normal: invalid level")))))
(concat "^\\([ \t]*\\)\\(" r "\\)\\([ \t]+\\)")))
((and (eq sub-type 'adoc-bibliography) (null level))
"^\\(\\)\\(\\+\\)\\([ \t]+\\)")
(t (error "adoc-unordered: invalid sub-type/level combination"))))
;; ^\s*(?P<index>\d+\.) +(?P<text>.+)$ decimal = 0
;; ^\s*(?P<index>[a-z]\.) +(?P<text>.+)$ lower alpha = 1
;; ^\s*(?P<index>[A-Z]\.) +(?P<text>.+)$ upper alpha = 2
;; ^\s*(?P<index>[ivx]+\)) +(?P<text>.+)$ lower roman = 3
;; ^\s*(?P<index>[IVX]+\)) +(?P<text>.+)$ upper roman = 4
((eq type 'adoc-explicitly-numbered)
(when level (error "adoc-explicitly-numbered: invalid level"))
(let* ((l '("[0-9]+\\." "[a-z]\\." "[A-Z]\\." "[ivx]+)" "[IVX]+)"))
(r (cond ((numberp sub-type) (nth sub-type l))
((or (null sub-type) (eq sub-type 'adoc-all-subtypes)) (mapconcat 'identity l "\\|"))
(t (error "adoc-explicitly-numbered: invalid subtype")))))
(concat "^\\([ \t]*\\)\\(" r "\\)\\([ \t]+\\)")))
;; ^\s*\. +(?P<text>.+)$ normal 0
;; ^\s*\.{2} +(?P<text>.+)$ normal 1
;; ... etc until 5 ...
((eq type 'adoc-implicitly-numbered)
(let ((r (cond ((numberp level) (number-to-string (+ level 1)))
((or (null level) (eq level 'adoc-all-levels)) "1,5")
(t (error "adoc-implicitly-numbered: invalid level")))))
(concat "^\\([ \t]*\\)\\(\\.\\{" r "\\}\\)\\([ \t]+\\)")))
;; ^<?(?P<index>\d*>) +(?P<text>.+)$ callout
((eq type 'adoc-callout)
(when (or level sub-type) (error "adoc-callout invalid level/sub-type"))
"^\\(\\)\\(<?[0-9]*>\\)\\([ \t]+\\)")
;; invalid
(t (error "invalid (un)ordered list type"))))
(defun adoc-make-uolisti (level is-1st-line)
"Returns a regexp matching a unordered list item."
(let* ((del (if (eq level 0) "-" (make-string level ?\*)))
(white-1st (if indent-tabs-mode
(make-string (/ (* level standard-indent) tab-width) ?\t)
(make-string (* level standard-indent) ?\ )))
(white-rest (make-string (+ (length del) 1) ?\ )))
(if is-1st-line
(concat white-1st del " ")
white-rest)))
(defun adoc-re-llisti (type level)
"Returns a regexp matching a labeled list item.
Subgroups:
1 leading blanks
2 label text, incl whites before delimiter
3 delimiter incl trailing whites
4 delimiter only
foo :: bar
-12--23-3
44"
(cond
;; ^\s*(?P<label>.*[^:])::(\s+(?P<text>.+))?$ normal 0
;; ^\s*(?P<label>.*[^;]);;(\s+(?P<text>.+))?$ normal 1
;; ^\s*(?P<label>.*[^:]):{3}(\s+(?P<text>.+))?$ normal 2
;; ^\s*(?P<label>.*[^:]):{4}(\s+(?P<text>.+))?$ normal 3
((eq type 'adoc-labeled-normal)
(let* ((deluq (nth level '("::" ";;" ":::" "::::"))) ; unqutoed
(del (regexp-quote deluq))
(del1st (substring deluq 0 1)))
(concat
"^\\([ \t]*\\)" ; 1
"\\(.*[^" del1st "\n]\\)" ; 2
"\\(\\(" del "\\)\\(?:[ \t]+\\|$\\)\\)"))) ; 3 & 4
;; glossary (DEPRECATED)
;; ^(?P<label>.*\S):-$
((eq type 'adoc-labeled-qanda)
(concat
"^\\([ \t]*\\)" ; 1
"\\(.*[^ \t\n]\\)" ; 2
"\\(\\(\\?\\?\\)\\)$")) ; 3 & 4
;; qanda (DEPRECATED)
;; ^\s*(?P<label>.*\S)\?\?$
((eq type 'adoc-labeled-glossary)
(concat
"^\\(\\)" ; 1
"\\(.*[^ \t\n]\\)" ; 2
"\\(\\(:-\\)\\)$")) ; 3 & 4
(t (error "Unknown type/level"))))
(defun adoc-re-delimited-block-line ()
(concat
"\\(?:"
(mapconcat
(lambda (x)
(concat "\\(?:" x "\\)[ \t]*$"))
adoc-delimited-block-del "\\|")
"\\)"))
;; KLUDGE: Contrary to what the AsciiDoc manual specifies, adoc-mode does not
;; allow that either the first or the last line within a delmited block is
;; blank. That shall help to prevent the case that adoc-mode wrongly
;; interprets the end of a delimited block as the beginning, and the beginning
;; of a following delimited block as the ending, thus wrongly interpreting the
;; text between two adjacent delimited blocks as delimited block. It is
;; expected that it is unlikely that one wants to begin or end a delimited
;; block with a blank line, and it is expected that it is likely that
;; delimited blocks are surrounded by blank lines.
(defun adoc-re-delimited-block (del)
(let* ((tmp (nth del adoc-delimited-block-del))
(start (if (consp tmp) (car tmp) tmp))
(end (if (consp tmp) (cdr tmp) tmp)))
(concat
"\\(" start "\\)[ \t]*\n"
"\\("
;; a single leading non-blank line
"[ \t]*[^ \t\n].*\n"
;; optionally followed by
"\\(?:"
;; any number of arbitrary lines followed by
"\\(?:.*\n\\)*?"
;; a trailing non blank line
"[ \t]*[^ \t\n].*\n"
"\\)??"
"\\)??"
"\\(" end "\\)[ \t]*$")))
;; TODO: since its multiline, it doesn't yet work properly.
(defun adoc-re-verbatim-paragraph-sequence ()
(concat
"\\("
;; 1. paragraph in sequence delimited by blank line or list continuation
"^\\+?[ \t]*\n"
;; sequence of verbatim paragraphs
"\\(?:"
;; 1st line starts with blanks, but has also non blanks, i.e. is not empty
"[ \t]+[^ \t\n].*"
;; 2nd+ line is neither a blank line nor a list continuation line
"\\(?:\n\\(?:[^+ \t\n]\\|[ \t]+[^ \t\n]\\|\\+[ \t]*[^ \t\n]\\).*?\\)*?"
;; paragraph delimited by blank line or list continuation or end of buffer
;; NOTE: now list continuation belongs the the verbatim paragraph sequence,
;; but actually we want to highlight it differently. Thus the font lock
;; keywoard handling list continuation must come after verbatim paraphraph
;; sequence.
"\\(?:\n[ \t]*\\(?:\n\\|\\'\\)\\|\n\\+[ \t]*\n\\|\\'\\)"
"\\)+"
"\\)" ))
;; ^\.(?P<title>([^.\s].*)|(\.[^.\s].*))$
;; Isn't that asciidoc.conf regexp the same as: ^\.(?P<title>(.?[^.\s].*))$
;; insertion: so that this whole regex doesn't mistake a line starting with a
;; cell specifier like .2+| as a block title
(defun adoc-re-block-title ()
"Returns a regexp matching an block title
Subgroups:
1 delimiter
2 title's text incl trailing whites
3 newline or end-of-buffer anchor
.foo n
12--23"
(concat
"^\\(\\.\\)"
"\\(\\.?\\(?:"
"[0-9]+[^+*]" ; inserted part, see above
"\\|[^. \t\n]\\).*\\)"
"\\(\n\\|\\'\\)"))
;; (?u)^(?P<name>image|unfloat|toc)::(?P<target>\S*?)(\[(?P<attrlist>.*?)\])$
;; note that altough it hasn't got the s Python regular expression flag, it
;; still can spawn multiple lines. Probably asciidoc removes newlines before
;; it applies the regexp above
(defun adoc-re-block-macro (&optional cmd-name)
"Returns a regexp matching an attribute list elment.
Subgroups:
1 cmd name
2 target
3 attribute list, exclusive brackets []"
(concat
"^\\(" (or cmd-name "[a-zA-Z0-9_]+") "\\)::"
"\\([^ \t\n]*?\\)"
"\\["
"\\(" (adoc-re-content) "\\)"
"\\][ \t]*$"))
;; ?P<id>[\w\-_]+
(defun adoc-re-id ()
"Returns a regexp matching an id used by anchors/xrefs"
"\\(?:[-a-zA-Z0-9_]+\\)")
(defun adoc-re-anchor (&optional type id)
"Returns a regexp matching an anchor.
If TYPE is non-nil, only that type is matched. If TYPE is nil,
all types are matched.
If ID is non-nil, the regexp matches an anchor defining exactly
this id. If ID is nil, the regexp matches any anchor."
(cond
((eq type 'block-id)
;; ^\[\[(?P<id>[\w\-_]+)(,(?P<reftext>.*?))?\]\]$
(concat "^\\[\\["
"\\(" (if id (regexp-quote id) (adoc-re-id)) "\\)"
"\\(?:,\\(.*?\\)\\)?"
"\\]\\][ \t]*$"))