1 ; Created by Brian Templeton (bpt@hcoop.net)
2 ; Extended by Adam Chlipala (adamc@hcoop.net)
4 (eval-when-compile (require 'cl
))
6 (defvar domtool-indent
2)
8 (defvar domtool-mode-syntax-table
9 (let ((table (make-syntax-table)))
10 (loop for i from ?a to ?z
11 do
(modify-syntax-entry i
"w" table
))
12 (loop for i from ?A to ?Z
13 do
(modify-syntax-entry i
"w" table
))
14 (loop for i from ?
0 to ?
9
15 do
(modify-syntax-entry i
"w" table
))
18 (loop for ch across
(if (stringp (car pair
))
21 do
(modify-syntax-entry ch
(cadr pair
) table
)))
22 '((" \t\n\14" " ") ; \14 is ^L
31 ;; We identify single-line comments using
32 ;; font-lock-syntactic-keywords, because it's easier to
33 ;; recognize documentation comments using the syntax table.
36 ("->=<,:;^!&" ".") ; -> => <- = , : ; ^ ! &
40 (defvar domtool-font-lock-keywords
43 (regexp-opt '("let" "in" "begin" "end" "with" "where" "extern" "type"
44 "val" "context" "Root"
46 "vhost" "location" "directory" "domain" "dom"
50 ("type[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face
)
51 ("val[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-variable-name-face
)))
53 (defvar domtool-font-lock-syntactic-keywords
54 '(("\\(#\\).*\\(\n\\|\\'\\)"
58 (defun domtool-font-lock-syntactic-face-function (state)
59 "Major mode for editing Domtool files."
60 (cond ((nth 3 state
) font-lock-string-face
)
61 ((eq (nth 7 state
) t
) font-lock-doc-face
)
62 (t font-lock-comment-face
)))
64 (define-derived-mode domtool-mode fundamental-mode
"Domtool"
65 ;; For some reason, whatever twiddling `define-derived-mode' does
66 ;; with the syntax table breaks recognition of (*...*) comments. So
67 ;; we need to tell d-d-m to leave our syntax table alone.
68 :syntax-table domtool-mode-syntax-table
69 (set (make-local-variable 'indent-line-function
) 'domtool-indent-line
)
70 (set (make-local-variable 'font-lock-defaults
)
71 '(domtool-font-lock-keywords
73 (font-lock-syntactic-keywords
74 . domtool-font-lock-syntactic-keywords
)
75 (font-lock-syntactic-face-function
76 . domtool-font-lock-syntactic-face-function
))))
78 (defun domtool-indent-line ()
79 (let ((savep (> (current-column) (current-indentation)))
80 (indent (domtool-calculate-indent)))
82 ((eq indent
'noindent
) indent
)
83 (savep (save-excursion (indent-line-to indent
)))
84 (t (indent-line-to indent
)))))
86 (defun domtool-calculate-indent ()
89 (multiple-value-bind (previous-keyword base-indent
)
91 (if (re-search-backward "\\_<\\(with\\|where\\|end\\)\\_>"
93 (values (match-string 0) (current-indentation))
95 (let ((state (syntax-ppss)))
100 (domtool-calculate-comment-indent state
))
101 ((and (looking-at "\\_<end\\_>")
102 (string= previous-keyword
"end"))
103 (- base-indent domtool-indent
))
104 ((looking-at "\\_<\\(with\\|end\\)\\_>")
106 ((not previous-keyword
)
108 ((string= previous-keyword
"end")
111 (+ base-indent domtool-indent
)))))))
113 (defun domtool-calculate-comment-indent (state)
116 ((syntax-table) 'noindent
) ; can't happen
117 ((nil) (let ((start (nth 8 state
))
119 (while (> (point) start
)
120 (re-search-backward "(\\*\\|\\*)" start t
)
121 (if (looking-at "(\\*")
124 (+ (current-indentation) depth
)))))