forked from sensorflo/adoc-mode
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
adoc-mode.el
3489 lines (3111 loc) · 146 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 -*- lexical-binding: t; -*-
;;
;; Copyright 2009-2016 Florian Kaufmann <sensorflo@gmail.com>
;; Copyright 2022-2023 Bozhidar Batsov <bozhidar@batsov.dev> and adoc-mode contributors
;;
;; Author: Florian Kaufmann <sensorflo@gmail.com>
;; URL: https://github.com/bbatsov/adoc-mode
;; Maintainer: Bozhidar Batsov <bozhidar@batsov.dev>
;; Created: 2009
;; Version: 0.8.0-snapshot
;; Package-Requires: ((emacs "26"))
;; Keywords: docs, wp
;;
;; 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.
;;; Commentary:
;; 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.
;;; Code:
(require 'cl-lib)
(require 'tempo)
(defconst adoc-mode-version "0.8.0-snapshot"
"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 "Support for editing AsciiDoc files in GNU Emacs."
:group 'text
:prefix "adoc-"
:version "0.8.0"
:link '(url-link "https://github.com/bbatsov/adoc-mode"))
(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
`adoc-superscript-face' and `adoc-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 replacement/entity stands for is displayed.
E.g. after \\='&\\=' an \\='&\\=' is displayed, after \\='(C)\\=' the copy right
sign is displayed. It is only about display, neither the file nor
the buffer content is affected.
You need to call `adoc-calc' after you change
`adoc-insert-replacement'. For named character entities (e.g.
\\='&\\=', in contrast to \\='\\=' or \\='(C)\\=' ) to be displayed you
need to set `adoc-unichar-name-resolver'.
Setting it to non-nil interacts very badly with minor-modes using
overlays."
:type 'boolean
:group 'adoc)
(defcustom adoc-unichar-name-resolver nil
"Function taking a unicode char name and returning it's codepoint.
E.g. when given \"amp\" (as in the character entity reference
\"&\"), it shall return 38 (#x26). Is used to insert the
character a character entity reference is referring to after the
entity. When adoc-unichar-name-resolver is nil, or when its
function returns nil, nothing is done with named character
entities. Note that if `adoc-insert-replacement' is nil,
adoc-unichar-name-resolver is not used.
You can set it to `adoc-unichar-by-name'; however it requires
unichars.el (http://nwalsh.com/emacs/xmlchars/unichars.el). When
you set adoc-unichar-name-resolver to adoc-unichar-by-name, you
need to call `adoc-calc' for the change to take effect."
:type '(choice (const nil)
(const adoc-unichar-by-name)
function)
: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")
(string :tag "level 5"))
: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 length of the given
number. You could use a number for example when all your
delimited block lines have a certain length.
This is useful 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)
(defcustom adoc-fontify-code-blocks-natively 5000
"When non-nil, fontify code in code blocks using the native major mode.
This only works for code blocks where the language is
specified where we can automatically determine the appropriate
mode to use. The language to mode mapping may be customized by
setting the variable `adoc-code-lang-modes'.
The value can be a number that determines the size
up to which code blocks are fontified natively.
If the value is another non-nil value then code blocks
are fontified natively regardless of their size."
:group 'adoc
:type '(choice :tag "Fontify code blocks " :format "\n%{%t%}: %[Size%] %v"
(integer :tag "limited to")
(boolean :tag "unlimited"))
:safe #'(lambda (x) (or (booleanp x) (numberp x)))
:package-version '(adoc-mode . "0.8.0"))
;; This is based on `org-src-lang-modes' from org-src.el
(defcustom adoc-code-lang-modes
'(
("asymptote" . asy-mode)
("bash" . sh-mode)
("C" . c-mode)
("cpp" . c++-mode)
("C++" . c++-mode)
("calc" . fundamental-mode)
("ditaa" . artist-mode)
("dot" . fundamental-mode)
("elisp" . emacs-lisp-mode)
("ocaml" . tuareg-mode)
("screen" . shell-script-mode)
("shell" . sh-mode)
("sqlite" . sql-mode)
)
"Alist mapping languages to their major mode.
The key is the language name, the value is the major mode. For
many languages this is simple, but for language where this is not
the case, this variable provides a way to simplify things on the
user side. For example, there is no ocaml-mode in Emacs, but the
mode to use is `tuareg-mode'."
:group 'adoc
:type '(repeat
(cons
(string "Language name")
(symbol "Major mode")))
:package-version '(adoc-mode . "0.8.0"))
(defcustom adoc-fontify-code-block-default-mode 'prog-mode
"Default mode to use to fontify code blocks.
This mode is used when automatic detection fails, such as for
code blocks with no language specified."
:group 'adoc
:type '(choice function (const :tag "None" nil))
:package-version '(adoc-mode . "0.8.0"))
(defcustom adoc-font-lock-extend-after-change-max 5000
"Number of chars scanned backwards for re-fontification of code block headers.
Also used to delimit the scan for the end delimiter."
:type 'integer
:group 'adoc
:package-version '(adoc-mode . "0.8.0"))
;;;; faces / font lock
(define-obsolete-face-alias 'adoc-orig-default 'adoc-align-face "23.3")
(defface adoc-align-face
'((t (:inherit (adoc-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-face' in the following example the item's text looks
aligned.
- lorem ipsum
dolor ..."
:group 'adoc-faces)
(defvar adoc-align-face 'adoc-align-face)
;; 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-delimiter 'adoc-meta-face)
(defvar adoc-hide-delimiter 'adoc-meta-hide-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.")
;; although currently always the same face is used, I prefer an alist over a
;; list. It is faster to find out whether any attribute id is in the alist or
;; not. And maybe adoc-faces splits up adoc-secondary-text-face into more
;; specific faces.
(defvar adoc-attribute-face-alist
'(("id" . adoc-anchor-face)
("caption" . adoc-secondary-text-face)
("xreflabel" . adoc-secondary-text-face)
("alt" . adoc-secondary-text-face)
("title" . adoc-secondary-text-face)
("attribution" . adoc-secondary-text-face)
("citetitle" . adoc-secondary-text-face)
("text" . adoc-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 ())
;;;; 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-bold
"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-underline
"Applies an underline decoration to the span of text.")
(defconst adoc-help-overline
"Applies an overline decoration to the span of text.")
(defconst adoc-help-line-through
"Applies a line-through (aka strikethrough) decoration to the span of text.")
(defconst adoc-help-nobreak
"Disables words within the span of text from being broken.")
(defconst adoc-help-nowrap
"Prevents the span of text from wrapping at all.")
(defconst adoc-help-pre-wrap
"Prevents sequences of space and space-like characters from being collapsed (i.e., all spaces are preserved).")
(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. Applied 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-bold "Bold.")
(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.")
;;; adoc Hiding ===============================================================
(defconst adoc-markup-properties
'(face adoc-markup-face invisible adoc-markup)
"List of properties and values to apply to markup.")
(defconst adoc-language-keyword-properties
'(face adoc-language-keyword-face invisible adoc-markup)
"List of properties and values to apply to code block language names.")
(defconst adoc-language-info-properties
'(face adoc-language-info-face invisible adoc-markup)
"List of properties and values to apply to code block language info strings.")
(defconst adoc-include-title-properties
'(face adoc-link-title-face invisible adoc-markup)
"List of properties and values to apply to included code titles.")
;;; Font Lock =================================================================
(require 'font-lock)
(defgroup adoc-faces nil
"Faces used in Adoc Mode."
:group 'adoc
:group 'faces)
(defface adoc-gen-face
'((((background light))
(:foreground "medium blue"))
(((background dark))
(:foreground "skyblue")))
"Generic/base face for text with special formatting.
Typically `adoc-title-0-face', `adoc-bold-face' etc.
inherit from it. Also used for generic text thas hasn't got its
own dedicated face, e.g. if a markup command imposes arbitrary
colors/sizes/fonts upon it."
:group 'adoc-faces)
(defvar adoc-gen-face 'adoc-gen-face)
(defface adoc-meta-face
'((default (
:family "Monospace" ; emacs's faces.el also directly uses "Monospace", so I assume it is safe to do so
:stipple nil
:inverse-video nil
:box nil
:strike-through nil
:overline nil
:underline nil
:slant normal
:weight normal
:width normal
:foundry "unknown"))
(((background light)) (:foreground "gray65"))
(((background dark)) (:foreground "gray30")))
"Face for general meta characters and base for special meta characters.
The default sets all face properties to a value because then it's
easier for major mode to write font lock regular expressions."
;; For example in '<b>...<foo>...</b>', if <foo> is fontified before <b>, <b>
;; might then make <foo> bold, which is not the intend.
:group 'adoc-faces)
(defvar adoc-meta-face 'adoc-meta-face)
(defface adoc-value-face
'((t :inherit adoc-meta-face))
"For attribute values."
:group 'adoc-faces)
(defvar adoc-value-face 'adoc-value-face)
(defface adoc-bold-face
'((t (:inherit (adoc-gen-face bold))))
"Face for bold text."
:group 'adoc-faces)
(defvar adoc-bold-face 'adoc-bold-face)
(defface adoc-emphasis-face
'((t :inherit (adoc-gen-face italic)))
"For emphasized text."
:group 'adoc-faces)
(defvar adoc-emphasis-face 'adoc-emphasis-face)
(defface adoc-markup-face
'((t (:inherit shadow :slant normal :weight normal)))
"Face for markup elements."
:group 'adoc-faces)
(defvar adoc-markup-face 'adoc-markup-face)
(defface adoc-meta-hide-face
'((default (:inherit adoc-meta-face))
(((background light)) :foreground "gray75")
(((background dark)) :foreground "gray25"))
"For meta characters which can be \\='hidden\\='.
Hidden in the sense of *almost* not visible. They does not need to
be properly seen because one knows what these characters must be;
deduced from the highlighting of the near context. E.g in
AsciiDocs \\='_important_\\=', the underlines would be highlighted with
adoc-hide-delimiter-face, and the text \\='important\\=' would be
highlighted with adoc-emphasis-face. Because \\='important\\=' is
highlighted, one knows that it must be surrounded with the meta
characters \\='_\\=', and thus the meta characters do not need to be
properly seen.
For example:
AsciiDoc: *bold emphasis text* or _emphasis text_
^ ^ ^ ^"
:group 'adoc-faces)
(defvar adoc-meta-hide-face 'adoc-meta-hide-face)
(defface adoc-attribute-face
'((t :inherit adoc-meta-face :slant italic))
"For attribute names."
:group 'adoc-faces)
(defvar adoc-attribute-face 'adoc-attribute-face)
(defface adoc-anchor-face
'((t :inherit adoc-meta-face :overline t))
"For the name/id of an anchor."
:group 'adoc-faces)
(defvar adoc-anchor-face 'adoc-anchor-face)
(defface adoc-list-face
'((t (:inherit adoc-markup-face)))
"Face for list item markers."
:group 'adoc-faces)
(defvar adoc-list-face 'adoc-list-face)
(defface adoc-code-face
'((t (:inherit fixed-pitch)))
"Face for inline code and fenced code blocks.
This may be used, for example, to add a contrasting background to
inline code fragments and code blocks."
:group 'adoc-faces)
(defvar adoc-code-face 'adoc-code-face)
(defface adoc-command-face
'((default (:inherit (adoc-meta-face bold)
:box(
:line-width 2
:style released-button)))
(((background light))(:background "#f5f5f5" :foreground "black" :box (:color "#dcdcdc")))
(((background dark))(:background "#272822" :foreground "#e6db74" :box (:color "#e6db74"))))
"Face for command names."
:group 'adoc-faces)
(defvar adoc-command-face 'adoc-command-face)
(defface adoc-complex-replacement-face
'((default (:inherit adoc-meta-face
:box (:line-width 2 :style released-button)))
(((background light)) (:background "plum1" :foreground "purple3" :box (:color "plum1")))
(((background dark)) (:background "purple3" :foreground "plum1" :box (:color "purple3"))))
"Markup that is replaced by something complex.
For example an image, or a table of contents.
AsciiDoc: image:...[...]"
:group 'adoc-faces)
(defvar adoc-complex-replacement-face 'adoc-complex-replacement-face)
(defface adoc-passthrough-face
'((t :inherit (fixed-pitch adoc-gen-face)))
"For text that is passed through yet another marser/renderer.
Since this text is passed to an arbitrary renderer, it is unknown
wich of its chars are meta characters and which are literal characters."
:group 'adoc-faces)
(defvar adoc-passthrough-face 'adoc-passthrough-face)
(defface adoc-preprocessor-face
'((t :inherit (font-lock-preprocessor-face adoc-meta-face)))
"For preprocessor constructs"
:group 'adoc-faces)
(defvar adoc-preprocessor-face 'adoc-preprocessor-face)
(defface adoc-verbatim-face
'((((background light))
(:background "cornsilk"))
(((background dark))
(:background "saddlebrown")))
"For verbatim text.
Verbatim in a sense that all its characters are to be taken
literally. Note that does not necessarily mean that that it is in
a typewritter font.
For example \\='foo\\=' in the following examples. In parantheses is a
summary what the command is for according to the given markup
language.
\\=`foo\\=` (verbatim and typewriter font)
+++foo+++ (only verbatim)"
:group 'adoc-faces)
(defvar adoc-verbatim-face 'adoc-verbatim-face)
(defface adoc-warning-face
'((t :inherit (font-lock-warning-face)))
"For things that should stand out"
:group 'adoc-faces)
(defvar adoc-warning-face 'adoc-warning-face)
(defface adoc-table-face
'((t (:inherit (adoc-code-face))))
"Face for tables."
:group 'adoc-faces)
(defvar adoc-table-face 'adoc-table-face)
(defface adoc-language-keyword-face
'((t (:inherit font-lock-type-face)))
"Face for programming language identifiers."
:group 'adoc-faces)
(defvar adoc-language-keyword-face 'adoc-language-keyword-face)
(defface adoc-replacement-face
'((default (:family "Monospace"))
(((background light)) (:foreground "purple3"))
(((background dark)) (:foreground "plum1")))
"Meta characters that are replaced by text in the output.
See also `adoc-complex-replacement-face'.
For example
AsciiDoc: \\='->\\=' is replaced by an Unicode arrow
It is difficult to say whether adoc-replacement-face is part of
the group adoc-faces-meta or part of the group
adoc-faces-text. Technically they are clearly meta characters.
However they are just another representation of normal text and I
want to fontify them as such. E.g. in HTML \\='<b>foo & bar</b>\\=',
the output \\='foo & bar\\=' is fontified bold, thus I also want \\='foo
& bar\\=' in the Emacs buffer be fontified with
adoc-bold-face. Thus adoc-replacement-face needs to be
something that is orthogonal to the adoc-bold-face etc faces."
:group 'adoc-faces)
(defvar adoc-replacement-face 'adoc-replacement-face)
(defface adoc-language-info-face
'((t (:inherit font-lock-string-face)))
"Face for programming language info strings."
:group 'adoc-faces)
(defvar adoc-language-info-face 'adoc-language-info-face)
(defface adoc-reference-face
'((t (:inherit adoc-markup-face)))
"Face for link references."
:group 'adoc-faces)
(defvar adoc-reference-face 'adoc-reference-face)
(defface adoc-link-title-face
'((t (:inherit font-lock-comment-face)))
"Face for reference link titles."
:group 'adoc-faces)
(defvar adoc-link-title-face 'adoc-link-title-face)
(defface adoc-comment-face
'((t (:inherit font-lock-comment-face)))
"Face for HTML comments."
:group 'adoc-faces)
(defvar adoc-comment-face 'adoc-comment-face)
(defface adoc-superscript-face
'((t :inherit adoc-gen-face :height 0.8))
"For superscript text.
For example \\='foo\\=' in the ^foo^
Note that typically the major mode doing the font lock
additionaly raises the text; face customization does not provide
this feature."
:group 'adoc-faces)
(defvar adoc-superscript-face 'adoc-superscript-face)
(defface adoc-subscript-face
'((t :inherit adoc-gen-face :height 0.8))
"For subscript text.
For example \\='foo\\=' in the ~foo~
Note that typically the major mode doing the font lock
additionally lowers the text; face customization does not provide
this feature."
:group 'adoc-faces)
(defvar adoc-subscript-face 'adoc-subscript-face)
(defface adoc-title-face
'((t (:inherit adoc-gen-face :weight bold)))
"Base face for titles."
:group 'adoc-faces)
(defvar adoc-title-face 'adoc-title-face)
(defface adoc-title-0-face
'((t (:inherit adoc-title-face :height 2.0)))
"Face for document's title."
:group 'adoc-faces)
(defvar adoc-title-0-face 'adoc-title-0-face)
(defface adoc-title-1-face
'((t (:inherit adoc-title-face :height 1.8)))
"Face for level 1 titles."
:group 'adoc-faces)
(defvar adoc-title-1-face 'adoc-title-1-face)
(defface adoc-title-2-face
'((t (:inherit adoc-title-face :height 1.6)))
"Face for level 2 titles."
:group 'adoc-faces)
(defvar adoc-title-2-face 'adoc-title-2-face)
(defface adoc-title-3-face
'((t (:inherit adoc-title-face :height 1.4)))
"Face for level 3 titles."
:group 'adoc-faces)
(defvar adoc-title-3-face 'adoc-title-3-face)
(defface adoc-title-4-face
'((t (:inherit adoc-title-face :height 1.2)))
"Face for level 4 titles."
:group 'adoc-faces)
(defvar adoc-title-4-face 'adoc-title-4-face)
(defface adoc-title-5-face
'((t (:inherit adoc-title-face :height 1.0)))
"Face for level 5 titles."
:group 'adoc-faces)
(defvar adoc-title-5-face 'adoc-title-5-face)
(defface adoc-typewriter-face
'((t :inherit (fixed-pitch adoc-gen-face)))
"For text in typewriter/monospaced font.
For example \\='foo\\=' in the following examples:
+foo+ (only typewriter font)
\\=`foo\\=` (verbatim and typewriter font)"
:group 'adoc-faces)
(defvar adoc-typewriter-face 'adoc-typewriter-face)
(defface adoc-internal-reference-face
'((t :inherit adoc-meta-face :underline t))
"For an internal reference."
:group 'adoc-faces)
(defvar adoc-internal-reference-face 'adoc-internal-reference-face)
(defface adoc-secondary-text-face
'((t :inherit adoc-gen-face :foreground "firebrick" :height 0.9))
"For text that is not part of the running text.
For example for captions of tables or images,
or for footnotes, or for floating text."
:group 'adoc-faces)
(defvar adoc-secondary-text-face 'adoc-secondary-text-face)
(defface adoc-native-code-face
'((t (:inherit fixed-pitch)))
"For code blocks that are highlighted natively.
Use it to change the background of the code blocks."
:group 'adoc-faces)
(defvar adoc-native-code-face 'adoc-native-code-face)
;;;; 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 instead $ 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 also 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 additionally have to test if the underline
has the correct length.
DEL is described in `adoc-re-two-line-title-undlerline'.