aboutsummaryrefslogtreecommitdiff
path: root/dot.emacs.d/elisp/doc-mode.el
blob: db7be1e353a75b4c36bdf3a456d47cf49575765a (plain) (blame)
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
;;; doc-mode.el --- a major-mode for highlighting a hierarchy structured text.

;; @Author: SUN, Tong <suntong001@users.sf.net>, (c)2001-6, all right reserved
;; @Version: $Date: 2006/01/19 03:13:41 $ $Revision: 1.14 $
;; @Keywords: text, processes, tools
;; @Home URL: http://xpt.sourceforge.net/
;; 
;; Distribute freely, but please include the author's info & copyright,
;; the file's version & url with the distribution.
;; 
;; Support free software movement! Please send you comments, suggestions, bug
;; reports, patches to the author from the xpt project home URL. They are
;; warmly welcome. Thank you for using the tools from the xpt project.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;{{{ Commentary: 

;;
;; To enter doc-mode automatically, add (autoload 'doc-mode "doc-mode")
;; to your .emacs file and change the first line of your doc file to:
;; # -*- Doc -*-
;; if it doesn't have a .doc extension.
;; 
;; To handle .doc files, e.g., 'filename.doc', add something like
;; (add-to-list 'auto-mode-alist '("\\.doc$" . doc-mode))
;; to your .emacs file

;;
;; The documentation for the "Structure Of The Hierarchy Text" can be found in
;; the docstring for the doc-mode function.
;;

;;}}}

;;{{{ Variables: 

(defgroup doc-faces nil
  "AsciiDoc highlighting"
  :group 'docs)

;; == Colors
; color n is more prominent than color n+1

(defface doc-title-1-face
  `((((class color)
      (background dark))
     (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
    (((class color)
      (background light))
     (:foreground "brown3" :bold t :height 1.2 :inherit variable-pitch))
    (t (:weight bold :inherit variable-pitch)))
  "Face for AsciiDoc titles at level 1."
  :group 'doc-faces)

(defface doc-title-2-face
  `((((class color)
      (background dark))
     (:foreground "DeepPink2" :bold t :height 1.1 :inherit variable-pitch))
    (((class color)
      (background light))
     (:foreground "DeepPink2" :bold t :height 1.1 :inherit variable-pitch))
    (t (:weight bold :inherit variable-pitch)))
  "Face for AsciiDoc titles at level 2."
  :group 'doc-faces)

(defface doc-title-3-face
  `((((class color)
      (background dark))
     (:foreground "sienna3" :bold t))
    (((class color)
      (background light))
     (:foreground "sienna3" :bold t))
    (t (:weight bold)))
  "Face for AsciiDoc titles at level 3."
  :group 'doc-faces)

(defface doc-title-4-face
  `((((class color)
      (background dark))
     (:foreground "burlywood3"))
    (((class color)
      (background light))
     (:foreground "burlywood3"))
    (t ()))
  "Face for AsciiDoc titles at level 4."
  :group 'doc-faces)

(defface info-node
  '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
    (((class color) (background dark)) (:foreground "white" :bold t :italic t))
    (t (:bold t :italic t)))
  "Face for Info node names."
  :group 'doc-faces)

(defvar doc-title-1 'doc-title-1-face)
(defvar doc-title-2 'doc-title-2-face)
(defvar doc-title-3 'doc-title-3-face)
(defvar doc-title-4 'doc-title-4-face)

(defvar general-font-lock-red1 font-lock-warning-face)
(defvar general-font-lock-red2 font-lock-comment-face)
(defvar general-font-lock-red3 font-lock-string-face)

(defvar general-font-lock-green1 font-lock-type-face)
(defvar general-font-lock-green2 font-lock-constant-face)

(defvar general-font-lock-blue1 font-lock-keyword-face)
(defvar general-font-lock-blue2 font-lock-function-name-face)
(defvar general-font-lock-blue3 font-lock-builtin-face)

(defvar general-font-lock-yellow1 font-lock-variable-name-face)
(defvar general-font-lock-yellow2 font-lock-comment-face)

;; == doc-mode settings

(defvar doc-mode-hook nil
  "Normal hook run when entering Doc Text mode.")

(defvar doc-mode-abbrev-table nil
  "Abbrev table in use in Doc-mode buffers.")
(define-abbrev-table 'doc-mode-abbrev-table ())

(defconst doc-font-lock-keywords
  (eval-when-compile
    (list

     ;; Section titles
     (cons "^==? +.*"		'doc-title-1)
     (cons "^=== +.*"		'doc-title-2)
     (cons "^==== +.*"		'doc-title-3)
     (cons "^===== +.*"		'doc-title-4)

     ;; Delimited blocks
     (cons "^[-=+*_]\\{6,\\} *\$" 'general-font-lock-yellow1)
     (cons "^\\.\\{6,\\} *\$"	'general-font-lock-yellow2)
     (cons "^\\.[A-Z].*\$"	'general-font-lock-yellow2)

     ;; Misc specials
     (cons "^.*\\?\\? *\$"	'doc-title-4)
     (cons "^.*[:;][:;-] *\$"	'general-font-lock-blue2)

     ;; Comment Lines
     (cons "^//.*"		'general-font-lock-blue3)

     ;; Auxiliary directives
     (cons "^>>[{}=]+ .*"	'general-font-lock-green1)
     (cons "^<< +.*"		'general-font-lock-blue3)

     ;; Annotation
     (cons "\\*[A-Z]+\\*:"	'general-font-lock-red1)

     ))
 "Default expressions to highlight in AsciiDoc mode.")

;;}}} 

;;{{{ Doc & Autoload: 

;;###autoload
(define-derived-mode doc-mode text-mode "DOC"
  "Major mode for editing AsciiDoc text files.
Turning on Doc mode runs the normal hook `doc-mode-hook'.

Document Structure

Titles consist of a line starting with one or more equals characters (the
number of equals corresponds the section level) followed by a space followed
by the title text. E.g.:

  = Document Title (level 0)
  == Section title (level 1)
  === Section title (level 2)
  ==== Section title (level 3)
  ===== Section title (level 4)

Auxiliary directives.

<< Last update time

>>{{{ folding start tag
>>}}} folding end tag
Group frames into folders.

Example:

== A Certain Unix Tool

=== Basic Info

==== Usage

// This is a hidden comment.

ListingBlocks are rendered verbatim in a monospaced font, they retain
line and whitespace formatting and 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 code and file listings.

--------------------------------------
#include <stdio.h>

int main() {
        printf(\"Hello World!\\n\");
        exit(0);
}
--------------------------------------

===== Description

===== Features

=== Version 

==== Dependencies

==== Installation

===== Steps

===== Help

<< 14:16:27
"
  (interactive)
  (modify-syntax-entry ?\'  ".")
  ;(flyspell-mode nil)

  (make-local-variable 'paragraph-start)
  (setq paragraph-start (concat "$\\|>" page-delimiter))
  (make-local-variable 'paragraph-separate)
  (setq paragraph-separate paragraph-start)
  (make-local-variable 'paragraph-ignore-fill-prefix)
  (setq paragraph-ignore-fill-prefix t)

  (make-local-variable 'require-final-newline)
  (setq require-final-newline t)

  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults 
	'(doc-font-lock-keywords 
	  nil				; KEYWORDS-ONLY: no
	  nil				; CASE-FOLD: no
	  ((?_ . "w"))			; SYNTAX-ALIST
	  ))
  (run-hooks 'doc-mode-hook))

(provide 'doc-mode)

;;}}}

;;; doc-mode.el ends here