initial commit
[emacs-init.git] / nxhtml / nxhtml / nxhtml-mumamo.el
1 ;;; nxhtml-mumamo.el --- Multi major modes using nxhtml
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-03-10T19:04:20+0100 Mon
5 (defconst nxhtml-mumamo:version "0.5")
6 ;; Last-Updated: 2009-01-06 Tue
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13   ;; `backquote', `bytecomp', `mumamo', `mumamo-fun'.
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;;
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Change log:
24 ;;
25 ;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 2, or
31 ;; (at your option) any later version.
32 ;;
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36 ;; General Public License for more details.
37 ;;
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING.  If not, write to
40 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
41 ;; Floor, Boston, MA 02110-1301, USA.
42 ;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;
45 ;;; Code:
46
47 (eval-when-compile (require 'cl))
48 (eval-when-compile (require 'nxhtml nil t))
49 (eval-when-compile (require 'nxhtml-base))
50 (eval-when-compile (require 'nxhtml-mode))
51 (eval-when-compile (require 'mumamo))
52 (eval-and-compile  (require 'mumamo-fun))
53 (eval-when-compile (require 'rng-valid nil t))
54 ;;(mumamo-fun-require)
55
56 ;; (defgroup nxhtml-auto-val-head nil
57 ;;   "Automatic turn on of XHTML validation headers."
58 ;;   :group 'nxhtml)
59
60 ;; (defmacro define-fictive-validation-header-toggle (fun-sym default-value)
61 ;;   (let* ((fun-name (symbol-name fun-sym))
62 ;;          (custom-sym (intern (concat fun-name "-auto-val-head")))
63 ;;          (hook-sym (intern-soft (concat fun-name "-hook")))
64 ;;          (docstring
65 ;;           (concat "Automatic XHTML validation header for `" fun-name "'.
66 ;; ยด")))
67 ;;     (assert hook-sym)
68 ;;     `(defcustom ,custom-sym ,default-value
69 ;;        ,docstring
70 ;;        :type 'boolean
71 ;;        :set (lambda (sym val)
72 ;;               (set-default sym val)
73 ;;               (if val
74 ;;                   (add-hook ',hook-sym 'nxhtml-turn-on-validation-header-mode)
75 ;;                 (remove-hook ',hook-sym 'nxhtml-turn-on-validation-header-mode)))
76 ;;        :group 'nxhtml-auto-val-head)
77 ;;     ))
78
79 ;; Fix-me: add chunk type attr string as last alternative. This will
80 ;; allow things like myattr="<?php echo ?>".
81
82 ;;;###autoload
83 (define-mumamo-multi-major-mode nxhtml-mumamo-mode
84   "Turn on multiple major modes for (X)HTML with main mode `nxhtml-mode'.
85 This covers inlined style and javascript and PHP.
86
87 See also `mumamo-alt-php-tags-mode'."
88   ("nXhtml Family" nxhtml-mode
89    (mumamo-chunk-xml-pi
90     mumamo-chunk-alt-php
91     mumamo-chunk-inlined-style
92     mumamo-chunk-inlined-script
93     mumamo-chunk-style=
94     mumamo-chunk-onjs=
95     )))
96 (add-hook 'nxhtml-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
97 ;;(define-fictive-validation-header-toggle nxhtml-mumamo-mode t)
98
99 ;;;###autoload
100 (define-mumamo-multi-major-mode embperl-nxhtml-mumamo-mode
101   "Turn on multiple major modes for Embperl files with main mode `nxhtml-mode'.
102 This also covers inlined style and javascript."
103   ("Embperl nXhtml Family" nxhtml-mode
104    (mumamo-chunk-embperl-<-
105     mumamo-chunk-embperl-<+
106     mumamo-chunk-embperl-<!
107     mumamo-chunk-embperl-<$
108     mumamo-chunk-inlined-style
109     mumamo-chunk-inlined-script
110     mumamo-chunk-style=
111     mumamo-chunk-onjs=
112     )))
113
114 ;;;###autoload
115 (define-mumamo-multi-major-mode django-nxhtml-mumamo-mode
116   "Turn on multiple major modes for Django with main mode `nxhtml-mode'.
117 This also covers inlined style and javascript."
118   ("Django nXhtml Family" nxhtml-mode
119    (mumamo-chunk-django4
120     mumamo-chunk-django
121     mumamo-chunk-django2
122     mumamo-chunk-django3
123     mumamo-chunk-inlined-style
124     mumamo-chunk-inlined-script
125     mumamo-chunk-style=
126     mumamo-chunk-onjs=
127     )))
128
129 ;;;###autoload
130 (define-mumamo-multi-major-mode mason-nxhtml-mumamo-mode
131   "Turn on multiple major modes for Mason using main mode `nxhtml-mode'.
132 This covers inlined style and javascript."
133   ("Mason nxhtml Family" nxhtml-mode
134    (
135     mumamo-chunk-mason-perl-line
136     mumamo-chunk-mason-perl-single
137     mumamo-chunk-mason-perl-block
138     mumamo-chunk-mason-perl-init
139     mumamo-chunk-mason-perl-once
140     mumamo-chunk-mason-perl-cleanup
141     mumamo-chunk-mason-perl-shared
142     mumamo-chunk-mason-simple-comp
143     mumamo-chunk-mason-compcont
144     mumamo-chunk-mason-args
145     mumamo-chunk-mason-doc
146     mumamo-chunk-mason-text
147     mumamo-chunk-inlined-style
148     mumamo-chunk-inlined-script
149     mumamo-chunk-style=
150     mumamo-chunk-onjs=
151     )))
152 (add-hook 'mason-nxhtml-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
153 ;;(mumamo-inherit-sub-chunk-family-locally 'mason-nxhtml-mumamo-mode 'mason-nxhtml-mumamo-mode)
154
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
156 ;;;; Genshi / kid
157
158 (define-derived-mode nxhtml-genshi-mode nxhtml-mode "gXhtml"
159   "Like `nxhtml-mode' but with Genshi rnc.
160 You should not use this! This is just a part of
161 `genshi-nxhtml-mumamo-mode', use that instead."
162   (let* ((schema-dir (expand-file-name "etc/schema/" nxhtml-install-dir))
163          (genshi-rnc (expand-file-name "qtmstr-xhtml.rnc" schema-dir)))
164     ;;(message "nxhtml-src-dir =%s" nxhtml-src-dir)
165     (message "schema-dir =%s" schema-dir)
166     (when (or (not rng-current-schema-file-name)
167               (string= "xhtml.rnc" (file-name-nondirectory rng-current-schema-file-name)))
168       (condition-case err
169           (progn
170             (rng-set-schema-file-1 genshi-rnc)
171             (rng-what-schema)
172             ;;(rng-save-schema-location-1 t)
173             )
174         (nxml-file-parse-error
175          (nxml-display-file-parse-error err)))
176       (when rng-validate-mode
177         (rng-validate-mode -1)
178         (rng-validate-mode 1)))))
179
180 ;;;###autoload
181 (define-mumamo-multi-major-mode genshi-nxhtml-mumamo-mode
182   "Turn on multiple major modes for Genshi with main mode `nxhtml-mode'.
183 This also covers inlined style and javascript."
184   ("Genshi HTML Family" nxhtml-genshi-mode
185    (;;mumamo-chunk-genshi%
186     mumamo-chunk-genshi$
187     mumamo-chunk-py:=
188     mumamo-chunk-py:match
189     mumamo-chunk-xml-pi
190     ;;mumamo-chunk-alt-php
191     mumamo-chunk-inlined-style
192     mumamo-chunk-inlined-script
193     mumamo-chunk-style=
194     mumamo-chunk-onjs=
195     )))
196
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 ;;;; MJT
199
200 ;; MJT is run in the browser. Some new tags and attributes are used.
201
202 (define-derived-mode nxhtml-mjt-mode nxhtml-mode "mjtXhtml"
203   "Like `nxhtml-mode' but with genshi rnc.
204 You should not use this! This is just a part of
205 `mjt-nxhtml-mumamo-mode', use that instead."
206   (let* ((schema-dir (expand-file-name "etc/schema/" nxhtml-install-dir))
207          (genshi-rnc (expand-file-name "mjt.rnc" schema-dir)))
208     ;;(message "nxhtml-src-dir =%s" nxhtml-src-dir)
209     (message "schema-dir =%s" schema-dir)
210     (when (or (not rng-current-schema-file-name)
211               (string= "xhtml.rnc" (file-name-nondirectory rng-current-schema-file-name)))
212       (condition-case err
213           (progn
214             (rng-set-schema-file-1 genshi-rnc)
215             (rng-what-schema)
216             ;;(rng-save-schema-location-1 t)
217             )
218         (nxml-file-parse-error
219          (nxml-display-file-parse-error err)))
220       (when rng-validate-mode
221         (rng-validate-mode -1)
222         (rng-validate-mode 1)))))
223
224 ;;;###autoload
225 (define-mumamo-multi-major-mode mjt-nxhtml-mumamo-mode
226   "Turn on multiple major modes for MJT with main mode `nxhtml-mode'.
227 This also covers inlined style and javascript."
228   ("MJT nXhtml Family" nxhtml-mjt-mode
229    (
230     mumamo-chunk-mjt$
231     mumamo-chunk-xml-pi
232     mumamo-chunk-inlined-style
233     mumamo-chunk-inlined-script
234     mumamo-chunk-style=
235     mumamo-chunk-onjs=
236     )))
237
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
239 ;;;; Smarty
240
241 ;;;###autoload
242 (define-mumamo-multi-major-mode smarty-nxhtml-mumamo-mode
243   "Turn on multiple major modes for Smarty with main mode `nxhtml-mode'.
244 This also covers inlined style and javascript."
245   ("Smarty nXhtml Family" nxhtml-mode
246    (mumamo-chunk-xml-pi
247     mumamo-chunk-style=
248     mumamo-chunk-onjs=
249     ;;mumamo-chunk-inlined-style
250     ;;mumamo-chunk-inlined-script
251     mumamo-chunk-smarty-literal
252     mumamo-chunk-smarty-t
253     mumamo-chunk-smarty-comment
254     mumamo-chunk-smarty
255     )))
256
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258 ;;;; GSP
259
260 ;;;###autoload
261 (define-mumamo-multi-major-mode gsp-nxhtml-mumamo-mode
262   "Turn on multiple major modes for GSP with main mode `nxhtml-mode'.
263 This also covers inlined style and javascript."
264   ("GSP nXhtml Family" nxhtml-mode
265    (mumamo-chunk-gsp
266     mumamo-chunk-inlined-style
267     mumamo-chunk-inlined-script
268     mumamo-chunk-style=
269     mumamo-chunk-onjs=
270     )))
271
272 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
273 ;;;; JSP
274
275 ;;;###autoload
276 (define-mumamo-multi-major-mode jsp-nxhtml-mumamo-mode
277   "Turn on multiple major modes for JSP with main mode `nxhtml-mode'.
278 This also covers inlined style and javascript."
279   ("JSP nXhtml Family" nxhtml-mode
280    (mumamo-chunk-jsp
281     mumamo-chunk-inlined-style
282     mumamo-chunk-inlined-script
283     mumamo-chunk-style=
284     mumamo-chunk-onjs=
285     )))
286
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
288 ;;;; eRuby
289
290 ;;;###autoload
291 (define-mumamo-multi-major-mode eruby-nxhtml-mumamo-mode
292   "Turn on multiple major modes for eRuby with main mode `nxhtml-mode'.
293 This also covers inlined style and javascript."
294   ("eRuby nXhtml Family" nxhtml-mode
295    (mumamo-chunk-eruby
296     mumamo-chunk-inlined-style
297     mumamo-chunk-inlined-script
298     mumamo-chunk-style=
299     mumamo-chunk-onjs=
300     )))
301
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 ;;;; ASP
304
305 ;;;###autoload
306 (define-mumamo-multi-major-mode asp-nxhtml-mumamo-mode
307   "Turn on multiple major modes for ASP with main mode `nxhtml-mode'.
308 This also covers inlined style and javascript."
309   ("ASP nXhtml Family" nxhtml-mode
310    (mumamo-chunk-asp%
311     mumamo-asp-chunk-inlined-script
312     mumamo-chunk-inlined-script
313     mumamo-chunk-style=
314     mumamo-chunk-onjs=
315     )))
316
317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
318 ;;;; Mako
319
320 ;;;###autoload
321 (define-mumamo-multi-major-mode mako-nxhtml-mumamo-mode
322   "Turn on multiple major modes for Mako with main mode `nxhtml-mode'.
323 This also covers inlined style and javascript."
324 ;; Fix-me: test case
325 ;;
326 ;; Fix-me: Add chunks for the tags, but make sure these are made
327 ;; invisible to nxml-mode parser.
328 ;;
329 ;; Fix-me: Maybe finally add that indentation support for one-line chunks?
330   ("Mako nXhtml Family" nxhtml-mode
331    (
332     mumamo-chunk-mako-one-line-comment
333     mumamo-chunk-mako-<%doc
334     mumamo-chunk-mako-<%include
335     mumamo-chunk-mako-<%inherit
336     mumamo-chunk-mako-<%namespace
337     mumamo-chunk-mako-<%page
338
339     ;;mumamo-chunk-mako-<%def
340     ;;mumamo-chunk-mako-<%call
341     ;;mumamo-chunk-mako-<%text
342
343     mumamo-chunk-mako-<%
344     mumamo-chunk-mako-%
345     mumamo-chunk-mako$
346
347     mumamo-chunk-xml-pi
348     mumamo-chunk-inlined-style
349     mumamo-chunk-inlined-script
350     mumamo-chunk-style=
351     mumamo-chunk-onjs=
352     )))
353
354 ;; Fix-me: This caused mumamo to loop during fontification since
355 ;; fmode-replace-default-mode was not defined. Mumamo tried to load
356 ;; the function in mumamo-fetch-major-mode-setup in (funcall major)
357 ;; where major mode is php-mode.
358
359 ;;(eval-after-load 'php-mode '(fmode-replace-default-mode 'php-mode 'nxhtml-mumamo-mode))
360
361
362
363 (provide 'nxhtml-mumamo)
364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 ;;; nxhtml-mumamo.el ends here