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 (defun domtool-syms-re (&rest syms
)
41 (concat "\\<" (regexp-opt syms t
) "\\>"))
43 (defconst domtool-types-regexp
44 (domtool-syms-re "proxy_target" "proxy_port" "mod_rewrite_cond_flag" "mod_rewrite_flag" "rewrite_arg" "redirect_code" "autoindex_option" "autoindex_width" "homedir_path" "dnsRecord" "apache_option" "authType" "location" "ssl" "ssl_cert_path" "suexec_flag" "web_node" "aliasTarget" "aliasSource" "email" "emailUser" "mail_node" "dnsKind" "master" "dns_node" "soa" "serial" "your_path" "your_group" "your_user" "group" "user" "node" "your_domain_host" "your_domain" "domain" "host" "ip" "no_newlines" "no_spaces" "bool" "string" "int")
45 "A regexp that matches Domtool types from the standard library.")
47 (defconst domtool-contexts-regexp
48 (domtool-syms-re "Location" "Vhost" "Domain")
49 "A regexp that matches Domtool contexts from the standard library.")
51 (defconst domtool-actions-regexp
52 (domtool-syms-re "errorDocument" "scriptAlias" "alias" "proxyPassReverse" "proxyPass" "rewriteLogLevel" "localProxyRewrite" "rewriteBase" "rewriteCond" "rewriteRule" "setEnv" "davFilesystem" "readmeName" "headerName" "unset_indexOptions" "set_indexOptions" "indexOptions" "addDescription" "mailmanWebHost" "dnsDefault" "dnsAlias" "dnsMail" "dnsIP" "nameserver" "dom" "web" "webAt" "relayMail" "handleMail" "dns" "addDefaultCharset" "action" "forceTypeOff" "forceType" "directoryIndex" "unset_options" "set_options" "options" "satisfyAny" "satisfyAll" "denyFrom" "denyFromAll" "allowFrom" "allowFromAll" "orderDenyAllow" "orderAllowDeny" "requireGroup" "requireUser" "requireValidUser" "authUserFile" "authName" "authType" "serverAliasDefault" "serverAlias" "serverAliasHost" "directory" "location" "vhost" "defaultAlias" "aliasDrop" "aliasMulti" "emailAlias" "aliasPrim" "domain")
53 "A regexp that matches Domtool actions from the standard library.")
55 (defconst domtool-vals-regexp
56 (domtool-syms-re "ornext" "cond_nocase" "env" "skip" "redirectWith" "mimeType" "passthrough" "noescape" "qsappend" "nocase" "nosubreq" "chain" "last" "gone" "forbidden" "redirect" "redir307" "redir305" "redir304" "redir303" "redir302" "redir301" "redir300" "seeother" "permanent" "temp" "xhtml" "versionSort" "trackModified" "suppressSize" "suppressRules" "suppressLastModified" "suppressIcon" "suppressHtmlPreamble" "suppressDescription" "suppressColumnSorting" "scanHtmlTitles" "nameWidth" "ignoreClient" "ignoreCase" "iconWidth" "iconHeight" "iconsAreLinks" "htmlTable" "foldersFirst" "fancyIndexing" "descriptionWidth" "characters" "autofit" "home" "web_node" "default_node" "dnsDefaultA" "dnsNS" "dnsMX" "dnsCNAME" "dnsA" "indexes" "includesNOEXEC" "execCGI" "kerberos" "digest" "basic" "use_cert" "no_ssl" "web_node_to_node" "dropTarget" "addressesTarget" "addressTarget" "catchAllSource" "defaultSource" "userSource" "mail_node_to_node" "noDns" "useDns" "internalMaster" "externalMaster" "dns_node_to_node" "defaultSoa" "soa" "serialConst" "serialAuto" "ip_of_node" "true" "false")
57 "A regexp that matches Domtool vals from the standard library.")
59 (defconst domtool-env-vars-regexp
60 (domtool-syms-re "Aliases" "DNS" "DocumentRoot" "Group" "MailNodes" "Mailbox" "SSL" "ServerAdmin" "SuExec" "TTL" "User" "WebNodes")
61 "A regexp that matches Domtool env-vars from the standard library.")
63 (defvar domtool-font-lock-keywords
66 (regexp-opt '("let" "in" "begin" "end" "with" "where" "extern" "type"
67 "val" "context" "Root")
71 (,domtool-actions-regexp . font-lock-builtin-face
)
72 (,domtool-vals-regexp . font-lock-variable-name-face
)
73 (,domtool-contexts-regexp . font-lock-constant-face
)
74 (,domtool-env-vars-regexp . font-lock-constant-face
)
75 (,domtool-types-regexp . font-lock-type-face
)
77 ("type[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face
)
78 ("val[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-variable-name-face
)))
80 (defvar domtool-font-lock-syntactic-keywords
81 '(("\\(#\\).*\\(\n\\|\\'\\)"
85 (defun domtool-font-lock-syntactic-face-function (state)
86 "Major mode for editing Domtool files."
87 (cond ((nth 3 state
) font-lock-string-face
)
88 ((eq (nth 7 state
) t
) font-lock-doc-face
)
89 (t font-lock-comment-face
)))
91 (define-derived-mode domtool-mode fundamental-mode
"Domtool"
92 ;; For some reason, whatever twiddling `define-derived-mode' does
93 ;; with the syntax table breaks recognition of (*...*) comments. So
94 ;; we need to tell d-d-m to leave our syntax table alone.
95 :syntax-table domtool-mode-syntax-table
96 (set (make-local-variable 'indent-line-function
) 'domtool-indent-line
)
97 (set (make-local-variable 'font-lock-defaults
)
98 '(domtool-font-lock-keywords
100 (font-lock-syntactic-keywords
101 . domtool-font-lock-syntactic-keywords
)
102 (font-lock-syntactic-face-function
103 . domtool-font-lock-syntactic-face-function
))))
105 (defun domtool-indent-line ()
106 (let ((savep (> (current-column) (current-indentation)))
107 (indent (domtool-calculate-indent)))
109 ((eq indent
'noindent
) indent
)
110 (savep (save-excursion (indent-line-to indent
)))
111 (t (indent-line-to indent
)))))
113 (defun until-closed (level)
115 (re-search-backward "\\_<\\(with\\|where\\|begin\\|end\\)\\_>"
118 ((string= (match-string 0) "end")
119 (until-closed (+ level
1)))
121 (current-indentation))
123 (until-closed (- level
1))))
127 (defun domtool-calculate-indent ()
129 (back-to-indentation)
130 (multiple-value-bind (previous-keyword base-indent
)
132 (if (re-search-backward "\\_<\\(with\\|where\\|begin\\|end\\)\\_>"
134 (values (match-string 0) (current-indentation))
136 (let ((state (syntax-ppss)))
141 (domtool-calculate-comment-indent state
))
142 ((looking-at "\\_<\\(with\\|end\\)\\_>")
144 ((not previous-keyword
)
146 ((string= previous-keyword
"end")
149 (+ base-indent domtool-indent
)))))))
151 (defun domtool-calculate-comment-indent (state)
154 ((syntax-table) 'noindent
) ; can't happen
155 ((nil) (let ((start (nth 8 state
))
157 (while (> (point) start
)
158 (re-search-backward "(\\*\\|\\*)" start t
)
159 (if (looking-at "(\\*")
162 (+ (current-indentation) depth
)))))