1 ;;; mumamo-fun.el --- Multi major mode functions
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-03-09T01:35:21+0100 Sun
6 ;; Last-Updated: 2008-08-04T17:54:29+0200 Mon
11 ;; Features that might be required by this library:
13 ;; `backquote', `bytecomp', `cl', `flyspell', `ispell', `mumamo',
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ;; This program is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 3, or (at your option)
23 ;; This program is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 ;; Boston, MA 02110-1301, USA.
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;; Defines some "multi major modes" functions. See mumamo.el for more
43 ;; See mumamo.el for how to use the multi major mode functions
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 (eval-when-compile (require 'cl))
55 (eval-when-compile (add-to-list 'load-path default-directory))
56 (eval-when-compile (require 'mumamo))
57 (eval-when-compile (require 'sgml-mode))
61 ;;(defun mumamo-fun-require ())
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;;;; File wide key bindings
66 (defun mumamo-multi-mode-map ()
67 "Return mumamo multi mode keymap."
69 (intern-soft (concat (symbol-name mumamo-multi-major-mode) "-map"))))
71 ;; (defun mumamo-multi-mode-hook-symbol ()
72 ;; "Return mumamo multi mode hook symbol."
73 ;; (intern-soft (concat (symbol-name mumamo-multi-major-mode) "-hook")))
76 (defun mumamo-define-html-file-wide-keys ()
77 "Define keys in multi major mode keymap for html files."
78 (let ((map (mumamo-multi-mode-map)))
79 (define-key map [(control ?c) (control ?h) ?b] 'nxhtml-browse-file)
81 ;; (defun mumamo-add-html-file-wide-keys (hook)
82 ;; (add-hook hook 'mumamo-define-html-file-wide-keys)
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 ;;;; Chunk search routines for XHTML things
88 (defun mumamo-chunk-attr= (pos min max attr= attr=is-regex attr-regex submode)
89 "This should work similar to `mumamo-find-possible-chunk'.
90 See `mumamo-chunk-style=' for an example of use.
91 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
92 (mumamo-chunk-attr=-new pos max attr= attr=is-regex attr-regex submode))
94 (defun mumamo-chunk-attr=-new-fw-exc-fun (pos max)
95 ;;(msgtrc "(mumamo-chunk-attr=-new-fw-exc-fun %s %s)" pos max)
100 (this-chunk (mumamo-get-existing-new-chunk-at pos)))
102 (goto-char (overlay-end this-chunk))
103 (goto-char (overlay-end mumamo-last-chunk)))
104 (setq first-dq (search-forward "\"" max t))
108 (with-syntax-table (standard-syntax-table)
109 (setq next-dq (scan-sexps (point) 1)))
115 (defun mumamo-chunk-attr=-new-find-borders-fun (start-border end-border dummy)
116 ;;(setq borders (funcall find-borders-fun start-border end-border exc-mode))
119 (end2 (when end-border (1- end-border)))
121 (goto-char start-border)
123 (setq start2 (search-forward "\"" (+ start-border 200) t)))
125 (list start2 end2))))
127 (defun mumamo-chunk-attr=-new (pos
134 ;;(message "\n(mumamo-chunk-attr=-new %s %s %s %s %s %s)" pos max attr= attr=is-regex attr-regex submode)
135 ;;(mumamo-condition-case err
141 (if (not attr=is-regex)
142 (goto-char (+ pos (length attr=)))
144 (skip-chars-forward "a-zA-Z="))
147 (re-search-forward attr= max t)
148 (search-forward attr= max t))))
163 ;; make sure if we have find prev-attr= or not
164 (unless (eq (char-after) ?\")
165 (setq next-attr= nil))
168 (skip-chars-forward "^\"")
169 (setq look-max (+ (point) 2)))
170 (while (and next-attr=
174 ;;(msgtrc "attr=-new: min=%s, point=%s" min (point))
175 (setq tries (1+ tries))
176 ;;(if (not (re-search-backward "<[^?]" (- min 300) t))
177 (if (not (re-search-backward "<[^?]\\|\?>" (- min 300) t))
178 (setq next-attr= nil)
179 ;;(if (looking-at attr-regex)
180 (if (let ((here (point)))
182 (re-search-forward attr-regex look-max t)
184 ;;(if (mumamo-end-in-code (point) next-attr= 'php-mode)
185 (setq next-attr-sure 'found)
188 ;;(msgtrc "attr=-new 1: min=%s, point=%s" min (point))
189 (setq next-attr= (if attr=is-regex
190 (re-search-backward attr= (- min 300) t)
191 (search-backward attr= (- min 300) t)))))))
192 (unless next-attr-sure (setq next-attr= nil))
195 ;; find prev change and if inside style= the next change
197 (setq exc-start-next (match-beginning 1))
198 (setq exc-end-next (match-end 2))
199 (when (>= exc-start-next pos)
200 (if (> pos exc-end-next)
202 (setq start (+ (match-end 2) 1))
203 ;;(setq start-border (+ (match-end 2) 2))
205 (setq exc-mode submode)
206 (setq start (match-beginning 1))
207 (setq start-border (match-beginning 2))
208 (setq end (1+ (match-end 2)))
209 (setq end-border (1- end)))
216 (search-backward "<" min t))
217 ;;(msgtrc "attr=-new 2: min=%s, point=%s" min (point))
218 (setq next-attr= (if attr=is-regex
219 (re-search-forward attr= max t)
220 (search-forward attr= max t)))
221 (when (and next-attr=
222 (search-backward "<" min t))
223 (when (looking-at attr-regex)
224 (setq end (match-beginning 1)))))
225 (when start (assert (>= start pos) t))
226 (when end (assert (<= pos end) t))
227 ;;(message "start-border=%s end-border=%s" start-border end-border)
228 (when (or start-border end-border)
229 (setq borders (list start-border end-border nil)))
230 ;; (message "mumamo-chunk-attr=-new: %s"
235 ;; nil ;; parseable-by
236 ;; 'mumamo-chunk-attr=-new-fw-exc-fun ;; fw-exc-fun
237 ;; 'mumamo-chunk-attr=-new-find-borders-fun ;; find-borders-fun
247 'mumamo-chunk-attr=-new-fw-exc-fun ;; fw-exc-fun
248 'mumamo-chunk-attr=-new-find-borders-fun ;; find-borders-fun
250 (error (mumamo-display-error 'mumamo-chunk-attr=-new "%s" (error-message-string err)))
255 (defvar mumamo-xml-pi-mode-alist
257 ("python" . python-mode))
258 "Alist used by `mumamo-chunk-xml-pi' to get exception mode." )
260 ;; Fix-me: make it possible to make the borders part of the php chunk
261 ;; so that parsing of them by nxml may be skipped. Or, rather if the
262 ;; borders are not part of the chunk then assume nxml can not parse
263 ;; the chunk and the borders.
264 ;; (defun mumamo-search-bw-exc-start-xml-pi-1 (pos min lt-chars)
265 ;; "Helper for `mumamo-chunk-xml-pi'.
266 ;; POS is where to start search and MIN is where to stop.
267 ;; LT-CHARS is just <?.
269 ;; Actual use is in `mumamo-search-bw-exc-start-xml-pi'."
270 ;; (let ((exc-start (mumamo-chunk-start-bw-str (+ pos 2) min lt-chars))
275 ;; (goto-char exc-start)
276 ;; (when (and (not (looking-at "xml"))
277 ;; (looking-at (rx (0+ (any "a-z")))))
278 ;; ;; (setq exc-start (match-end 0)) include it in sub chunk instead
279 ;; (setq exc-start (- exc-start 2))
280 ;; (setq spec (match-string-no-properties 0))
281 ;; (setq exc-mode (assoc spec mumamo-xml-pi-mode-alist))
282 ;; (when exc-mode (setq exc-mode (cdr exc-mode)))
287 ;; ;;(setq exc-mode 'fundamental-mode)
288 ;; ;; Fix-me: Better assume php-mode
289 ;; (setq exc-mode 'php-mode))
290 ;; (when (<= exc-start pos)
291 ;; ;;(cons exc-start exc-mode)
292 ;; (list exc-start exc-mode nil)
295 ;; (defun mumamo-search-bw-exc-start-xml-pi (pos min)
296 ;; "Helper for `mumamo-chunk-xml-pi'.
297 ;; POS is where to start search and MIN is where to stop."
298 ;; (mumamo-search-bw-exc-start-xml-pi-1 pos min "<?"))
300 (defun mumamo-search-fw-exc-start-xml-pi-new (pos max)
306 (setq start (search-forward "<?" max t))
308 (looking-at (rx (0+ (any "a-z")))))
309 (setq spec (match-string-no-properties 0))
310 (unless (string= spec "xml")
311 (when (= 0 (length spec))
313 (setq exc-mode (assoc spec mumamo-xml-pi-mode-alist))
315 (setq exc-mode (cdr exc-mode))
316 (setq exc-mode 'mumamo-bad-mode))
317 (setq ret (list (- start 2) exc-mode nil))))
321 (defun mumamo-xml-pi-end-is-xml-end (pos)
322 "Return t if the ?> at pos is end of <?xml."
324 ;;; (assert (and (= (char-after pos) ??)
325 ;;; (= (char-after (1+ pos)) ?>)))
330 (when (search-backward "<" (- pos 150) t)
331 (when (looking-at (rx line-start "<\?xml" (1+ space)))
332 (mumamo-msgfntfy "mumamo-xml-pi-end-is-xml-end %s => t" pos)
335 ;; (defun mumamo-search-bw-exc-end-xml-pi (pos min)
336 ;; "Helper for `mumamo-chunk-xml-pi'.
337 ;; POS is where to start search and MIN is where to stop."
338 ;; ;; Fix me: merge xml header
339 ;; (mumamo-msgfntfy "mumamo-search-bw-exc-end-xml-pi %s %s" pos min)
340 ;; ;;(let ((end-pos (mumamo-chunk-end-bw-str pos min "?>")))
341 ;; (let ((end-pos (mumamo-chunk-end-bw-str-inc pos min "?>")))
342 ;; (mumamo-msgfntfy " end-pos=%s" end-pos)
344 ;; (unless (or (mumamo-xml-pi-end-is-xml-end end-pos)
345 ;; (= (save-restriction
347 ;; (char-after (- end-pos 1)))
349 ;; (mumamo-msgfntfy " returning end-pos")
352 (defun mumamo-search-fw-exc-end-xml-pi (pos max)
353 "Helper for `mumamo-chunk-xml-pi'.
354 POS is where to start search and MAX is where to stop."
355 ;; Fix me: merge xml header
356 ;;(let ((end-pos (mumamo-chunk-end-fw-str pos max "?>")))
358 (let ((end-pos (mumamo-chunk-end-fw-str-inc pos max "?>")))
360 (unless (mumamo-xml-pi-end-is-xml-end end-pos)
363 (defun mumamo-search-fw-exc-start-xml-pi-1 (pos max lt-chars)
364 "Helper for `mumamo-chunk-xml-pi'.
365 POS is where to start search and MAX is where to stop.
367 Used in `mumamo-search-fw-exc-start-xml-pi'. For an explanation
368 of LT-CHARS see `mumamo-search-bw-exc-start-xml-pi-1'."
370 (skip-chars-backward "a-zA-Z")
371 ;;(let ((end-out (mumamo-chunk-start-fw-str (point) max lt-chars)))
372 (let ((end-out (mumamo-chunk-start-fw-str-inc (point) max lt-chars))
376 (when (looking-at "xml")
378 (setq end-out (mumamo-chunk-start-fw-str-inc (1+ (point)) max lt-chars))
382 (if (looking-at (rx (0+ (any "a-z"))))
384 ;;(setq end-out (match-end 0))
385 (setq end-out (- (match-beginning 0) 2))
386 (setq spec (match-string-no-properties 0))
387 (setq exc-mode (assoc spec mumamo-xml-pi-mode-alist))
389 (setq exc-mode (cdr exc-mode))
390 (setq exc-mode 'php-mode))
391 (setq end-out (list end-out exc-mode nil))
396 (defun mumamo-search-fw-exc-start-xml-pi-old (pos max)
397 "Helper for `mumamo-chunk-xml-pi'.
398 POS is where to start search and MAX is where to stop."
399 (mumamo-search-fw-exc-start-xml-pi-1 pos max "<?"))
401 ;; Add a find-borders-fun here so that for example src="<?php some
402 ;; code ?>" can be handled.
404 ;; Fix-me: Maybe generalize for other values than <?php
405 (defun mumamo-find-borders-xml-pi (start end exc-mode)
409 ;;(begin-mark "<?php")
413 (if (and inc) ;; exc-mode)
416 ;;(setq start-border (+ start (length begin-mark)))
417 (goto-char (+ start (length begin-mark)))
418 (skip-chars-forward "=a-zA-Z")
419 (setq start-border (point))
423 (- end (length end-mark)))))
424 (if (and (not inc) (not exc-mode))
428 (+ start (length end-mark))))
430 (setq end-border (- end (length begin-mark)))
432 ;;(skip-chars-forward "=a-zA-Z")
433 ;;(setq end-border (point))
436 (when (or start-border end-border)
437 (list start-border end-border))))
439 (defun mumamo-chunk-xml-pi (pos min max)
440 "Find process instruction, <? ... ?>. Return range and wanted mode.
441 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
442 ;; (mumamo-find-possible-chunk pos min max
443 ;; 'mumamo-search-bw-exc-start-xml-pi
444 ;; 'mumamo-search-bw-exc-end-xml-pi
445 ;; 'mumamo-search-fw-exc-start-xml-pi-old
446 ;; 'mumamo-search-fw-exc-end-xml-pi
447 ;; 'mumamo-find-borders-xml-pi)
448 (mumamo-possible-chunk-forward pos max
449 'mumamo-search-fw-exc-start-xml-pi-new
450 'mumamo-search-fw-exc-end-xml-pi
451 'mumamo-find-borders-xml-pi))
456 (defconst mumamo-style-tag-start-regex
469 ;; FIX-ME: Commented out because of bug in Emacs
471 ;;(optional (0+ space) "<![CDATA[")
474 ;; (defun mumamo-search-bw-exc-start-inlined-style (pos min)
475 ;; "Helper for `mumamo-chunk-inlined-style'.
476 ;; POS is where to start search and MIN is where to stop."
477 ;; (goto-char (+ pos 6))
478 ;; (let ((marker-start (search-backward "<style" min t))
481 ;; (when marker-start
482 ;; (when (looking-at mumamo-style-tag-start-regex)
483 ;; (setq exc-start (match-end 0))
484 ;; (goto-char exc-start)
485 ;; (when (<= exc-start pos)
486 ;; ;;(cons (point) 'css-mode)
487 ;; ;;(list (point) 'css-mode '(nxml-mode))
488 ;; ;; Fix-me: Kubica looping problem
489 ;; (list (point) 'css-mode)
493 ;; (defun mumamo-search-bw-exc-end-inlined-style (pos min)
494 ;; "Helper for `mumamo-chunk-inlined-style'.
495 ;; POS is where to start search and MIN is where to stop."
496 ;; (mumamo-chunk-end-bw-str pos min "</style>"))
498 ;; (defun mumamo-search-fw-exc-start-inlined-style-old (pos max)
499 ;; "Helper for `mumamo-chunk-inlined-style'.
500 ;; POS is where to start search and MAX is where to stop."
501 ;; (goto-char (1+ pos))
502 ;; (skip-chars-backward "^<")
503 ;; ;; Handle <![CDATA[
505 ;; (eq ?< (char-before))
506 ;; (eq ?! (char-after))
509 ;; (skip-chars-backward "^<"))
511 ;; (backward-char 1))
512 ;; (let ((exc-start (search-forward "<style" max t))
515 ;; (goto-char (- exc-start 6))
516 ;; (when (looking-at mumamo-style-tag-start-regex)
517 ;; (goto-char (match-end 0))
521 (defun mumamo-search-fw-exc-end-inlined-style (pos max)
522 "Helper for `mumamo-chunk-inlined-style'.
523 POS is where to start search and MAX is where to stop."
525 (mumamo-chunk-end-fw-str pos max "</style>")))
527 ;; (defun mumamo-chunk-inlined-style-old (pos min max)
528 ;; "Find <style>...</style>. Return range and 'css-mode.
529 ;; See `mumamo-find-possible-chunk' for POS, MIN and MAX."
530 ;; (mumamo-find-possible-chunk pos min max
531 ;; 'mumamo-search-bw-exc-start-inlined-style
532 ;; 'mumamo-search-bw-exc-end-inlined-style
533 ;; 'mumamo-search-fw-exc-start-inlined-style-old
534 ;; 'mumamo-search-fw-exc-end-inlined-style))
536 (defun mumamo-search-fw-exc-start-inlined-style (pos max)
537 "Helper for `mumamo-chunk-inlined-style'.
538 POS is where to start search and MAX is where to stop."
540 (skip-chars-backward "^<")
543 (eq ?< (char-before))
547 (skip-chars-backward "^<"))
550 (let ((exc-start (search-forward "<style" max t))
553 (goto-char (- exc-start 6))
554 (when (looking-at mumamo-style-tag-start-regex)
555 (goto-char (match-end 0))
556 (list (point) 'css-mode nil)
559 (defun mumamo-chunk-inlined-style (pos min max)
560 "Find <style>...</style>. Return range and 'css-mode.
561 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
562 (mumamo-possible-chunk-forward pos max
563 'mumamo-search-fw-exc-start-inlined-style
564 'mumamo-search-fw-exc-end-inlined-style))
568 (defconst mumamo-script-tag-start-regex
577 ;;(or "text" "application")
579 ;;(or "javascript" "ecmascript")
584 ;; FIX-ME: Commented out because of bug in Emacs
586 ;;(optional (0+ space) "<![CDATA[" )
589 ;; (defun mumamo-search-bw-exc-start-inlined-script (pos min)
590 ;; "Helper for `mumamo-chunk-inlined-script'.
591 ;; POS is where to start search and MIN is where to stop."
592 ;; (goto-char (+ pos 7))
593 ;; (let ((marker-start (when (< min (point)) (search-backward "<script" min t)))
596 ;; (when marker-start
597 ;; (when (looking-at mumamo-script-tag-start-regex)
598 ;; (setq exc-start (match-end 0))
599 ;; (goto-char exc-start)
600 ;; (when (<= exc-start pos)
601 ;; ;;(cons (point) 'javascript-mode)
602 ;; (list (point) 'javascript-mode '(nxml-mode))
606 ;; (defun mumamo-search-bw-exc-end-inlined-script (pos min)
607 ;; "Helper for `mumamo-chunk-inlined-script'.
608 ;; POS is where to start search and MIN is where to stop."
609 ;; (mumamo-chunk-end-bw-str pos min "</script>"))
611 ;; (defun mumamo-search-fw-exc-start-inlined-script-old (pos max)
612 ;; "Helper for `mumamo-chunk-inlined-script'.
613 ;; POS is where to start search and MAX is where to stop."
614 ;; (goto-char (1+ pos))
615 ;; (skip-chars-backward "^<")
616 ;; ;; Handle <![CDATA[
618 ;; (eq ?< (char-before))
619 ;; (eq ?! (char-after))
622 ;; (skip-chars-backward "^<"))
624 ;; (backward-char 1))
625 ;; (let ((exc-start (search-forward "<script" max t))
628 ;; (goto-char (- exc-start 7))
629 ;; (when (looking-at mumamo-script-tag-start-regex)
630 ;; (goto-char (match-end 0))
634 (defun mumamo-search-fw-exc-end-inlined-script (pos max)
635 "Helper for `mumamo-chunk-inlined-script'.
636 POS is where to start search and MAX is where to stop."
638 (mumamo-chunk-end-fw-str pos max "</script>")))
640 ;; (defun mumamo-chunk-inlined-script-old (pos min max)
641 ;; "Find <script>...</script>. Return range and 'javascript-mode.
642 ;; See `mumamo-find-possible-chunk' for POS, MIN and MAX."
643 ;; (mumamo-find-possible-chunk pos min max
644 ;; 'mumamo-search-bw-exc-start-inlined-script
645 ;; 'mumamo-search-bw-exc-end-inlined-script
646 ;; 'mumamo-search-fw-exc-start-inlined-script-old
647 ;; 'mumamo-search-fw-exc-end-inlined-script))
649 (defun mumamo-search-fw-exc-start-inlined-script (pos max)
650 "Helper for `mumamo-chunk-inlined-script'.
651 POS is where to start search and MAX is where to stop."
653 (skip-chars-backward "^<")
656 (eq ?< (char-before))
660 (skip-chars-backward "^<"))
663 (let ((exc-start (search-forward "<script" max t))
666 (goto-char (- exc-start 7))
667 (when (looking-at mumamo-script-tag-start-regex)
668 (goto-char (match-end 0))
669 (list (point) 'javascript-mode '(nxml-mode))
672 (defun mumamo-chunk-inlined-script (pos min max)
673 "Find <script>...</script>. Return range and 'javascript-mode.
674 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
675 (mumamo-possible-chunk-forward pos max
676 'mumamo-search-fw-exc-start-inlined-script
677 'mumamo-search-fw-exc-end-inlined-script))
679 ;;;; on[a-z]+=\"javascript:"
681 (defconst mumamo-onjs=-attr=
684 (or "onclick" "ondblclick" "onmousedown" "onmousemove" "onmouseout" "onmouseover" "onmouseup" "onkeydown" "onkeypress" "onkeyup")
687 (defconst mumamo-onjs=-attr-regex
693 ;;"on" (1+ (any "a-za-z"))
694 (or "onclick" "ondblclick" "onmousedown" "onmousemove" "onmouseout" "onmouseover" "onmouseup" "onkeydown" "onkeypress" "onkeyup")
704 (defun mumamo-chunk-onjs=(pos min max)
705 "Find javascript on...=\"...\". Return range and 'javascript-mode."
706 (mumamo-chunk-attr= pos min max mumamo-onjs=-attr= t mumamo-onjs=-attr-regex
709 ;;;; py:somthing=\"python\"
711 (defconst mumamo-py:=-attr= "py:[a-z]+=")
713 (defconst mumamo-py:=-attr-regex
719 "py:" (1+ (any "a-za-z"))
728 (defun mumamo-chunk-py:=(pos min max)
729 "Find python py:...=\"...\". Return range and 'python-mode."
730 (mumamo-chunk-attr= pos min max mumamo-py:=-attr= t mumamo-py:=-attr-regex
733 (defun mumamo-chunk-py:match (pos min max)
738 (re-search-forward (rx "py:match"
752 (setq start (match-beginning 1))
753 (setq end (match-end 2))
754 (setq borders (list (match-end 1) (1- end)))
763 'mumamo-chunk-attr=-new-fw-exc-fun ;; fw-exc-fun
764 'mumamo-chunk-attr=-new-find-borders-fun ;; find-borders-fun
769 (defconst mumamo-style=start-regex
781 (defun mumamo-chunk-style=(pos min max)
782 "Find style=\"...\". Return range and 'css-mode."
783 (mumamo-chunk-attr= pos min max "style=" nil mumamo-style=start-regex
787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
788 ;;;; HTML w html-mode
790 (put 'mumamo-alt-php-tags-mode 'permanent-local t)
791 (define-minor-mode mumamo-alt-php-tags-mode
792 "Minor mode for using '(?php' instead of '<?php' in buffer.
793 When turning on this mode <?php is replace with (?php in the buffer.
794 If you write the buffer to file (?php is however written as <?php.
796 When turning off this mode (?php is replace with <?php in the buffer.
798 The purpose of this minor mode is to work around problems with
799 using the `nxml-mode' parser in php files. `nxml-mode' knows
800 damned well that you can not have the character < in strings and
801 I can't make it forget that. For PHP programmers it is however
802 very convient to use <?php ... ?> in strings.
804 There is no reason to use this minor mode unless you want XML
805 validation and/or completion in your php file. If you do not
806 want that then you can simply use a multi major mode based on
807 `html-mode' instead of `nxml-mode'/`nxhtml-mode'. Or, of course,
808 just `php-mode' if there is no html code in the file."
810 (if mumamo-alt-php-tags-mode
812 ;;(unless mumamo-multi-major-mode (error "Only for mumamo multi major modes"))
813 (unless (let ((major-mode (mumamo-main-major-mode)))
814 (derived-mode-p 'nxml-mode))
815 ;;(error "Mumamo multi major mode must be based on nxml-mode")
817 (unless (memq 'mumamo-chunk-alt-php (caddr mumamo-current-chunk-family))
818 (error "Mumamo multi major must have chunk function mumamo-chunk-alt-php"))
820 ;; Be paranoid about the file/content write hooks
821 (when (<= emacs-major-version 22)
823 (when local-write-file-hooks ;; obsolete, but check!
824 (error "Will not do this because local-write-file-hooks is non-nil"))))
825 (remove-hook 'write-contents-functions 'mumamo-alt-php-write-contents t)
826 (when write-contents-functions
827 (error "Will not do this because write-contents-functions is non-nil"))
828 (when (delq 'recentf-track-opened-file (copy-sequence write-file-functions))
829 (error "Will not do this because write-file-functions is non-nil"))
831 (add-hook 'write-contents-functions 'mumamo-alt-php-write-contents t t)
832 (put 'write-contents-functions 'permanent-local t)
834 (let ((here (point)))
836 (goto-char (point-min))
837 (while (search-forward "<?php" nil t)
838 (replace-match "(?php"))
839 (goto-char (point-min))
840 (while (search-forward "<?=" nil t)
841 (replace-match "(?="))
842 (goto-char (point-min))
843 (while (search-forward "?>" nil t)
844 (replace-match "?)"))
847 (let ((here (point)))
849 (goto-char (point-min))
850 (while (search-forward "(?php" nil t)
851 (replace-match "<?php"))
852 (goto-char (point-min))
853 (while (search-forward "(?=" nil t)
854 (replace-match "<?="))
855 (goto-char (point-min))
856 (while (search-forward "?)" nil t)
857 (replace-match "?>"))
859 (remove-hook 'write-contents-functions 'mumamo-alt-php-write-contents t)))
861 (defun mumamo-chunk-alt-php (pos min max)
862 "Find (?php ... ?), return range and `php-mode'.
863 Workaround for the problem that I can not tame `nxml-mode' to recognize <?php.
865 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
866 (when mumamo-alt-php-tags-mode
867 (mumamo-quick-static-chunk pos min max "(?php" "?)" t 'php-mode t)))
869 (defun mumamo-chunk-alt-php= (pos min max)
870 "Find (?= ... ?), return range and `php-mode'.
871 Workaround for the problem that I can not tame `nxml-mode' to recognize <?php.
873 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
874 (when mumamo-alt-php-tags-mode
875 (mumamo-quick-static-chunk pos min max "(?=" "?)" t 'php-mode t)))
878 (define-mumamo-multi-major-mode html-mumamo-mode
879 "Turn on multiple major modes for (X)HTML with main mode `html-mode'.
880 This covers inlined style and javascript and PHP."
881 ("HTML Family" html-mode
884 mumamo-chunk-alt-php=
885 mumamo-chunk-inlined-style
886 mumamo-chunk-inlined-script
890 (add-hook 'html-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
891 (mumamo-inherit-sub-chunk-family 'html-mumamo-mode)
893 ;; (define-mumamo-multi-major-mode xml-pi-only-mumamo-mode
895 ;; ("HTML Family" html-mode
896 ;; (mumamo-chunk-xml-pi
900 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901 ;;;; XHTML w nxml-mode
903 (defun mumamo-alt-php-write-contents ()
904 "For `write-contents-functions' when `mumamo-chunk-alt-php' is used."
905 (let ((here (point)))
912 (goto-char (point-min))
913 (while (search-forward "(?php" nil t)
914 (replace-match "<?php"))
915 (goto-char (point-min))
916 (while (search-forward "(?=" nil t)
917 (replace-match "<?="))
918 (goto-char (point-min))
919 (while (search-forward "?)" nil t)
920 (replace-match "?>"))
921 (basic-save-buffer-1)
922 (signal 'mumamo-error-ind-0 nil)))
923 (mumamo-error-ind-0)))
924 (set-buffer-modified-p nil))
930 (define-mumamo-multi-major-mode nxml-mumamo-mode
931 "Turn on multiple major modes for (X)HTML with main mode `nxml-mode'.
932 This covers inlined style and javascript and PHP.
934 See also `mumamo-alt-php-tags-mode'."
935 ("nXml Family" nxml-mode
938 mumamo-chunk-inlined-style
939 mumamo-chunk-inlined-script
943 (add-hook 'nxml-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
947 ;;;; Mason (not ready)
948 ;; http://www.masonhq.com/docs/manual/Devel.html#examples_and_recommended_usage
950 (defun mumamo-chunk-mason-perl-line (pos min max)
951 (mumamo-whole-line-chunk pos min max "%" 'perl-mode))
953 (defun mumamo-chunk-mason-perl-single (pos min max)
954 (mumamo-quick-static-chunk pos min max "<% " " %>" t 'perl-mode t))
956 (defun mumamo-chunk-mason-perl-block (pos min max)
957 (mumamo-quick-static-chunk pos min max "<%perl>" "</%perl>" t 'perl-mode t))
959 (defun mumamo-chunk-mason-perl-init (pos min max)
960 (mumamo-quick-static-chunk pos min max "<%init>" "</%init>" t 'perl-mode t))
962 (defun mumamo-chunk-mason-perl-once (pos min max)
963 (mumamo-quick-static-chunk pos min max "<%once>" "</%once>" t 'perl-mode t))
965 (defun mumamo-chunk-mason-perl-cleanup (pos min max)
966 (mumamo-quick-static-chunk pos min max "<%cleanup>" "</%cleanup>" t 'perl-mode t))
968 (defun mumamo-chunk-mason-perl-shared (pos min max)
969 (mumamo-quick-static-chunk pos min max "<%shared>" "</%shared>" t 'perl-mode t))
971 (defun mumamo-chunk-mason-simple-comp (pos min max)
972 (mumamo-quick-static-chunk pos min max "<& " " &>" t 'text-mode t))
974 (defun mumamo-chunk-mason-args (pos min max)
975 ;; Fix-me: perl-mode is maybe not the best here?
976 (mumamo-quick-static-chunk pos min max "<%args>" "</%args>" t 'perl-mode t))
978 (defun mumamo-chunk-mason-doc (pos min max)
979 (mumamo-quick-static-chunk pos min max "<%doc>" "</%doc>" t 'mumamo-comment-mode t))
981 (defun mumamo-chunk-mason-text (pos min max)
982 (mumamo-quick-static-chunk pos min max "<%text>" "</%text>" t 'text-mode t))
984 ;; component calls with content
986 ;; (defun mumamo-chunk-mason-compcont-bw-exc-start-fun (pos min)
987 ;; (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "<&| ")))
989 ;; (<= exc-start pos)
990 ;; (cons exc-start 'html-mode))))
992 ;; (defun mumamo-chunk-mason-compcont-fw-exc-start-fun-old (pos max)
993 ;; (mumamo-chunk-start-fw-str-inc pos max "<&| "))
995 (defun mumamo-chunk-mason-compcont-fw-exc-end-fun (pos max)
996 (mumamo-chunk-end-fw-str-inc pos max "</&>"))
998 (defun mumamo-chunk-mason-compcont-find-borders-fun (start end dummy)
1003 (let ((here (point))
1006 (when (re-search-forward "[^>]* &>" end t)
1011 (when end (- end 4))
1014 ;; (defun mumamo-chunk-mason-compcont-old (pos min max)
1015 ;; (mumamo-find-possible-chunk-new pos
1017 ;; 'mumamo-chunk-mason-compcont-bw-exc-start-fun
1018 ;; 'mumamo-chunk-mason-compcont-fw-exc-start-fun-old
1019 ;; 'mumamo-chunk-mason-compcont-fw-exc-end-fun
1020 ;; 'mumamo-chunk-mason-compcont-find-borders-fun))
1022 (defun mumamo-chunk-mason-compcont-fw-exc-start-fun (pos max)
1023 (let ((where (mumamo-chunk-start-fw-str-inc pos max "<&| ")))
1025 (list where 'html-mode nil))))
1027 (defun mumamo-chunk-mason-compcont (pos min max)
1028 (mumamo-possible-chunk-forward pos max
1029 'mumamo-chunk-mason-compcont-fw-exc-start-fun
1030 'mumamo-chunk-mason-compcont-fw-exc-end-fun
1031 'mumamo-chunk-mason-compcont-find-borders-fun))
1034 (define-mumamo-multi-major-mode mason-html-mumamo-mode
1035 "Turn on multiple major modes for Mason using main mode `html-mode'.
1036 This covers inlined style and javascript."
1037 ("Mason html Family" html-mode
1039 mumamo-chunk-mason-perl-line
1040 mumamo-chunk-mason-perl-single
1041 mumamo-chunk-mason-perl-block
1042 mumamo-chunk-mason-perl-init
1043 mumamo-chunk-mason-perl-once
1044 mumamo-chunk-mason-perl-cleanup
1045 mumamo-chunk-mason-perl-shared
1046 mumamo-chunk-mason-simple-comp
1047 mumamo-chunk-mason-compcont
1048 mumamo-chunk-mason-args
1049 mumamo-chunk-mason-doc
1050 mumamo-chunk-mason-text
1051 mumamo-chunk-inlined-style
1052 mumamo-chunk-inlined-script
1056 (add-hook 'mason-html-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
1057 (mumamo-inherit-sub-chunk-family-locally 'mason-html-mumamo-mode 'mason-html-mumamo-mode)
1059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1062 (defun mumamo-chunk-embperl-<- (pos min max)
1063 "Find [- ... -], return range and `perl-mode'.
1064 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1065 (mumamo-quick-static-chunk pos min max "[-" "-]" t 'perl-mode t))
1067 (defun mumamo-chunk-embperl-<+ (pos min max)
1068 "Find [+ ... +], return range and `perl-mode'.
1069 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1070 (mumamo-quick-static-chunk pos min max "[+" "+]" t 'perl-mode nil))
1072 (defun mumamo-chunk-embperl-<! (pos min max)
1073 "Find [! ... !], return range and `perl-mode'.
1074 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1075 (mumamo-quick-static-chunk pos min max "[!" "!]" t 'perl-mode t))
1077 (defun mumamo-chunk-embperl-<$ (pos min max)
1078 "Find [$ ... $], return range and `perl-mode'.
1079 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1080 ;; This is a bit tricky since [$var] etc must be avoided.
1081 (let* ((begin-mark "[$")
1083 (good-chars '(32 ;space
1087 ;; (search-bw-exc-start (lambda (pos min)
1088 ;; (let ((not-found t)
1090 ;; (exc-start (mumamo-chunk-start-bw-str
1091 ;; pos min begin-mark))
1093 ;; (while (and not-found
1095 ;; (setq next-char (char-after (+ (point) 2)))
1096 ;; (if (memq next-char good-chars)
1097 ;; (setq not-found nil)
1099 ;; (search-backward begin-mark
1101 ;; (when (and exc-start
1102 ;; (<= exc-start pos))
1103 ;; (cons exc-start 'perl-mode)))))
1104 ;; (search-bw-exc-end (lambda (pos min)
1105 ;; (mumamo-chunk-end-bw-str pos min end-mark)))
1106 ;; (search-fw-exc-start-old (lambda (pos max)
1107 ;; (let ((not-found t)
1109 ;; (exc-start (mumamo-chunk-start-fw-str
1110 ;; pos max begin-mark))
1112 ;; (while (and not-found
1114 ;; (setq next-char (char-after))
1115 ;; (if (memq next-char good-chars)
1116 ;; (setq not-found nil)
1118 ;; (search-forward begin-mark
1121 (search-fw-exc-start (lambda (pos max)
1124 (exc-start (mumamo-chunk-start-fw-str
1125 pos max begin-mark))
1127 (while (and not-found
1129 (setq next-char (char-after))
1130 (if (memq next-char good-chars)
1131 (setq not-found nil)
1133 (search-forward begin-mark
1135 (list exc-start 'perl-mode))))
1136 (search-fw-exc-end (lambda (pos max)
1138 (mumamo-chunk-end-fw-str pos max end-mark))))
1140 ;; (mumamo-find-possible-chunk pos min max
1141 ;; search-bw-exc-start
1142 ;; search-bw-exc-end
1143 ;; search-fw-exc-start-old
1144 ;; search-fw-exc-end)
1145 (mumamo-possible-chunk-forward pos max
1151 (define-mumamo-multi-major-mode embperl-html-mumamo-mode
1152 "Turn on multiple major modes for Embperl files with main mode `html-mode'.
1153 This also covers inlined style and javascript."
1154 ("Embperl HTML Family" html-mode
1155 (mumamo-chunk-embperl-<-
1156 mumamo-chunk-embperl-<+
1157 mumamo-chunk-embperl-<!
1158 mumamo-chunk-embperl-<$
1159 mumamo-chunk-inlined-style
1160 mumamo-chunk-inlined-script
1166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1169 (defun mumamo-chunk-django4(pos min max)
1170 "Find {% comment %}. Return range and `django-mode'.
1171 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1172 (mumamo-quick-static-chunk pos min max "{% comment %}" "{% endcomment %}" t 'mumamo-comment-mode t))
1174 (defun mumamo-chunk-django3(pos min max)
1175 "Find {# ... #}. Return range and `django-mode'.
1176 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1177 (mumamo-quick-static-chunk pos min max "{#" "#}" t 'mumamo-comment-mode t))
1179 (defun mumamo-chunk-django2(pos min max)
1180 "Find {{ ... }}. Return range and `django-mode'.
1181 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1182 (mumamo-quick-static-chunk pos min max "{{" "}}" t 'django-variable-mode t))
1184 (defun mumamo-chunk-django (pos min max)
1185 "Find {% ... %}. Return range and `django-mode'.
1186 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1187 (let ((chunk (mumamo-quick-static-chunk pos min max "{%" "%}" t 'django-mode t)))
1189 (setcdr (last chunk) '(mumamo-template-indentor))
1192 ;; (defun mumamo-search-bw-exc-start-django (pos min)
1193 ;; "Helper for `mumamo-chunk-django'.
1194 ;; POS is where to start search and MIN is where to stop."
1195 ;; (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{%")))
1197 ;; (<= exc-start pos)
1198 ;; (cons exc-start 'django-mode))))
1200 ;; (defun mumamo-search-bw-exc-start-django2(pos min)
1201 ;; "Helper for `mumamo-chunk-django2'.
1202 ;; POS is where to start search and MIN is where to stop."
1203 ;; (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{{")))
1205 ;; (<= exc-start pos)
1206 ;; (cons exc-start 'django-mode))))
1208 ;; (defun mumamo-search-bw-exc-start-django3(pos min)
1209 ;; "Helper for `mumamo-chunk-django3'.
1210 ;; POS is where to start search and MIN is where to stop."
1211 ;; (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{#")))
1213 ;; (<= exc-start pos)
1214 ;; (cons exc-start 'mumamo-comment-mode))))
1216 ;; (defun mumamo-search-bw-exc-start-django4(pos min)
1217 ;; "Helper for `mumamo-chunk-django4'.
1218 ;; POS is where to start search and MIN is where to stop."
1219 ;; (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min
1220 ;; "{% comment %}")))
1222 ;; (<= exc-start pos)
1223 ;; (cons exc-start 'mumamo-comment-mode))))
1225 ;; (defun mumamo-search-bw-exc-end-django (pos min)
1226 ;; "Helper for `mumamo-chunk-django'.
1227 ;; POS is where to start search and MIN is where to stop."
1228 ;; (mumamo-chunk-end-bw-str-inc pos min "%}"))
1230 ;; (defun mumamo-search-bw-exc-end-django2(pos min)
1231 ;; "Helper for `mumamo-chunk-django2'.
1232 ;; POS is where to start search and MIN is where to stop."
1233 ;; (mumamo-chunk-end-bw-str-inc pos min "}}"))
1235 ;; (defun mumamo-search-bw-exc-end-django3(pos min)
1236 ;; "Helper for `mumamo-chunk-django3'.
1237 ;; POS is where to start search and MIN is where to stop."
1238 ;; (mumamo-chunk-end-bw-str-inc pos min "#}"))
1240 ;; (defun mumamo-search-bw-exc-end-django4(pos min)
1241 ;; "Helper for `mumamo-chunk-django4'.
1242 ;; POS is where to start search and MIN is where to stop."
1243 ;; (mumamo-chunk-end-bw-str-inc pos min "{% endcomment %}"))
1245 (defun mumamo-search-fw-exc-start-django (pos max)
1246 "Helper for `mumamo-chunk-django'.
1247 POS is where to start search and MAX is where to stop."
1248 (mumamo-chunk-start-fw-str-inc pos max "{%"))
1250 (defun mumamo-search-fw-exc-start-django2(pos max)
1251 "Helper for `mumamo-chunk-django2'.
1252 POS is where to start search and MAX is where to stop."
1253 (mumamo-chunk-start-fw-str-inc pos max "{{"))
1255 (defun mumamo-search-fw-exc-start-django3(pos max)
1256 "Helper for `mumamo-chunk-django3'.
1257 POS is where to start search and MAX is where to stop."
1258 (mumamo-chunk-start-fw-str-inc pos max "{#"))
1260 (defun mumamo-search-fw-exc-start-django4(pos max)
1261 "Helper for `mumamo-chunk-django4'.
1262 POS is where to start search and MAX is where to stop."
1263 (mumamo-chunk-start-fw-str-inc pos max "{% comment %}"))
1265 (defun mumamo-search-fw-exc-end-django (pos max)
1266 "Helper for `mumamo-chunk-django'.
1267 POS is where to start search and MAX is where to stop."
1268 (mumamo-chunk-end-fw-str-inc pos max "%}"))
1270 (defun mumamo-search-fw-exc-end-django2(pos max)
1271 "Helper for `mumamo-chunk-django2'.
1272 POS is where to start search and MAX is where to stop."
1273 (mumamo-chunk-end-fw-str-inc pos max "}}"))
1275 (defun mumamo-search-fw-exc-end-django3(pos max)
1276 "Helper for `mumamo-chunk-django3'.
1277 POS is where to start search and MAX is where to stop."
1278 (mumamo-chunk-end-fw-str-inc pos max "#}"))
1280 (defun mumamo-search-fw-exc-end-django4(pos max)
1281 "Helper for `mumamo-chunk-django4'.
1282 POS is where to start search and MAX is where to stop."
1283 (mumamo-chunk-end-fw-str-inc pos max "{% endcomment %}"))
1286 (define-mumamo-multi-major-mode django-html-mumamo-mode
1287 "Turn on multiple major modes for Django with main mode `html-mode'.
1288 This also covers inlined style and javascript."
1289 ("Django HTML Family" html-mode
1290 (mumamo-chunk-django4
1292 mumamo-chunk-django2
1293 mumamo-chunk-django3
1294 mumamo-chunk-inlined-style
1295 mumamo-chunk-inlined-script
1301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1305 (defun mumamo-chunk-genshi%(pos min max)
1306 "Find {% python ... %}. Return range and `genshi-mode'.
1307 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1308 (mumamo-quick-static-chunk pos min max "{% python" "%}" t 'python-mode t))
1311 (defun mumamo-chunk-genshi$(pos min max)
1312 "Find ${ ... }, return range and `python-mode'.
1313 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1315 (mumamo-quick-static-chunk pos min max "${" "}" t 'python-mode t)))
1317 ;; Test for clash with %}
1318 (let ((sub-mode (nth 2 chunk))
1319 (start (nth 0 chunk)))
1322 ;;(message "point.1=%s" (point))
1324 (eq ?% (char-before start)))
1325 ;;(message "point.2=%s" (point))
1326 ;;(message "clash with %%}, chunk=%s" chunk)
1328 (setcar chunk (1- start))
1330 ;;(message "chunk.return=%s" chunk)
1333 ;; Fix-me: Because of the way chunks currently are searched for there
1334 ;; is an error when a python chunk is used. This is because mumamo
1335 ;; gets confused by the %} ending and the } ending. This can be
1336 ;; solved by running a separate phase to get the chunks first and
1337 ;; during that phase match start and end of the chunk.
1340 ;; Note: You will currently get fontification errors if you use
1345 ;; The reason is that the chunk routines currently do not know when
1346 ;; to just look for the } or %} endings. However this should not
1347 ;; affect your editing normally.
1350 (define-mumamo-multi-major-mode genshi-html-mumamo-mode
1351 "Turn on multiple major modes for Genshi with main mode `html-mode'.
1352 This also covers inlined style and javascript."
1353 ("Genshi HTML Family" html-mode
1355 ;;mumamo-chunk-genshi%
1356 mumamo-chunk-genshi$
1358 mumamo-chunk-py:match
1360 mumamo-chunk-inlined-style
1361 mumamo-chunk-inlined-script
1366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1370 (defun mumamo-chunk-mjt$(pos min max)
1371 "Find ${ ... }, return range and `javascript-mode'.
1372 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1373 (mumamo-quick-static-chunk pos min max "${" "}" t 'javascript-mode t))
1376 (define-mumamo-multi-major-mode mjt-html-mumamo-mode
1377 "Turn on multiple major modes for MJT with main mode `html-mode'.
1378 This also covers inlined style and javascript."
1379 ("MJT HTML Family" html-mode
1383 mumamo-chunk-inlined-style
1384 mumamo-chunk-inlined-script
1390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1393 (defun mumamo-chunk-smarty-literal (pos min max)
1394 "Find {literal} ... {/literal}. Return range and 'html-mode.
1395 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1396 (mumamo-quick-static-chunk pos min max "{literal}" "{/literal}" t 'html-mode t))
1398 (defun mumamo-chunk-smarty-t (pos min max)
1399 "Find {t} ... {/t}. Return range and 'html-mode.
1400 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1401 (mumamo-quick-static-chunk pos min max "{t}" "{/t}" t 'text-mode t))
1403 (defun mumamo-chunk-smarty-comment (pos min max)
1404 "Find {* ... *}. Return range and 'mumamo-comment-mode.
1405 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1406 (mumamo-quick-static-chunk pos min max "{*" "*}" t 'mumamo-comment-mode nil))
1408 (defun mumamo-chunk-smarty (pos min max)
1409 "Find { ... }. Return range and 'smarty-mode.
1410 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1411 (mumamo-quick-static-chunk pos min max "{" "}" t 'smarty-mode nil))
1414 (define-mumamo-multi-major-mode smarty-html-mumamo-mode
1415 "Turn on multiple major modes for Smarty with main mode `html-mode'.
1416 This also covers inlined style and javascript."
1417 ("Smarty HTML Family" html-mode
1418 (mumamo-chunk-xml-pi
1421 ;;mumamo-chunk-inlined-style
1422 ;;mumamo-chunk-inlined-script
1423 mumamo-chunk-smarty-literal
1424 mumamo-chunk-smarty-t
1425 mumamo-chunk-smarty-comment
1430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1431 ;;;; ssjs - server side javascript
1433 ;; http://www.sitepoint.com/blogs/2009/03/10/server-side-javascript-will-be-as-common-as-php/
1435 ;; It looks like there are different syntaxes, both
1437 ;; <script runat="server">...</script> and <% ... %>.
1439 (defun mumamo-chunk-ssjs-% (pos min max)
1440 "Find <% ... %>. Return range and 'javascript-mode.
1441 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1442 (mumamo-quick-static-chunk pos min max "<%" "%>" t 'javascript-mode t))
1444 (defconst mumamo-ssjs-tag-start-regex
1447 (0+ (not (any ">")))
1453 ;;(or "text" "application")
1455 ;;(or "javascript" "ecmascript")
1456 (or "server" "both" "server-proxy")
1458 (0+ (not (any ">")))
1460 ;; FIX-ME: Commented out because of bug in Emacs
1462 ;;(optional (0+ space) "<![CDATA[" )
1465 ;; (defun mumamo-search-bw-exc-start-inlined-ssjs (pos min)
1466 ;; "Helper for `mumamo-chunk-inlined-ssjs'.
1467 ;; POS is where to start search and MIN is where to stop."
1468 ;; (goto-char (+ pos 7))
1469 ;; (let ((marker-start (when (< min (point)) (search-backward "<script" min t)))
1472 ;; (when marker-start
1473 ;; (when (looking-at mumamo-ssjs-tag-start-regex)
1474 ;; (setq exc-start (match-end 0))
1475 ;; (goto-char exc-start)
1476 ;; (when (<= exc-start pos)
1477 ;; ;;(cons (point) 'javascript-mode)
1478 ;; (list (point) 'javascript-mode '(nxml-mode))
1482 ;; (defun mumamo-search-fw-exc-start-inlined-ssjs-old (pos max)
1483 ;; "Helper for `mumamo-chunk-inlined-ssjs'.
1484 ;; POS is where to start search and MAX is where to stop."
1485 ;; (goto-char (1+ pos))
1486 ;; (skip-chars-backward "^<")
1487 ;; ;; Handle <![CDATA[
1489 ;; (eq ?< (char-before))
1490 ;; (eq ?! (char-after))
1493 ;; (skip-chars-backward "^<"))
1495 ;; (backward-char 1))
1496 ;; (let ((exc-start (search-forward "<script" max t))
1499 ;; (goto-char (- exc-start 7))
1500 ;; (when (looking-at mumamo-ssjs-tag-start-regex)
1501 ;; (goto-char (match-end 0))
1505 (defun mumamo-search-fw-exc-start-inlined-ssjs (pos max)
1506 "Helper for `mumamo-chunk-inlined-ssjs'.
1507 POS is where to start search and MAX is where to stop."
1508 (goto-char (1+ pos))
1509 (skip-chars-backward "^<")
1512 (eq ?< (char-before))
1513 (eq ?! (char-after))
1516 (skip-chars-backward "^<"))
1519 (let ((exc-start (search-forward "<script" max t))
1522 (goto-char (- exc-start 7))
1523 (when (looking-at mumamo-ssjs-tag-start-regex)
1524 (goto-char (match-end 0))
1525 (list (point) 'javascript-mode)
1528 (defun mumamo-chunk-inlined-ssjs (pos min max)
1529 "Find <script runat=...>...</script>. Return range and 'javascript-mode.
1530 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1531 ;; (mumamo-find-possible-chunk pos min max
1532 ;; 'mumamo-search-bw-exc-start-inlined-ssjs
1533 ;; 'mumamo-search-bw-exc-end-inlined-script
1534 ;; 'mumamo-search-fw-exc-start-inlined-ssjs-old
1535 ;; 'mumamo-search-fw-exc-end-inlined-script)
1536 (mumamo-possible-chunk-forward pos max
1537 'mumamo-search-fw-exc-start-inlined-ssjs
1538 'mumamo-search-fw-exc-end-inlined-script))
1541 (define-mumamo-multi-major-mode ssjs-html-mumamo-mode
1542 "Turn on multiple major modes for SSJS with main mode `html-mode'.
1543 This covers inlined style and javascript."
1544 ("HTML Family" html-mode
1545 (mumamo-chunk-inlined-style
1546 mumamo-chunk-inlined-script
1547 mumamo-chunk-inlined-ssjs
1552 (add-hook 'html-mumamo-mode-hook 'mumamo-define-html-file-wide-keys)
1553 (mumamo-inherit-sub-chunk-family 'ssjs-html-mumamo-mode)
1555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1558 (defun mumamo-chunk-gsp (pos min max)
1559 "Find <% ... %>. Return range and 'groovy-mode.
1560 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1561 (mumamo-quick-static-chunk pos min max "<%" "%>" t 'groovy-mode t))
1564 (define-mumamo-multi-major-mode gsp-html-mumamo-mode
1565 "Turn on multiple major modes for GSP with main mode `html-mode'.
1566 This also covers inlined style and javascript."
1567 ("GSP HTML Family" html-mode
1569 mumamo-chunk-inlined-style
1570 mumamo-chunk-inlined-script
1575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1576 ;;;; jsp - Java Server Pages
1578 (defun mumamo-chunk-jsp (pos min max)
1579 "Find <% ... %>. Return range and 'java-mode.
1580 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1581 (mumamo-quick-static-chunk pos min max "<%" "%>" t 'java-mode t))
1584 (define-mumamo-multi-major-mode jsp-html-mumamo-mode
1585 "Turn on multiple major modes for JSP with main mode `html-mode'.
1586 This also covers inlined style and javascript."
1587 ("JSP HTML Family" html-mode
1589 mumamo-chunk-inlined-style
1590 mumamo-chunk-inlined-script
1596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1599 ;; Fix-me: Maybe take care of <%= and <%- and -%>, but first ask the
1600 ;; ruby people if this is worth doing.
1602 ;; See also http://wiki.rubyonrails.org/rails/pages/UnderstandingViews
1603 (defun mumamo-chunk-eruby (pos min max)
1604 "Find <% ... %>. Return range and 'ruby-mode.
1605 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
1606 (let ((chunk (mumamo-quick-static-chunk pos min max "<%" "%>" t 'ruby-mode t)))
1608 ;; Put indentation type on 'mumamo-next-indent on the chunk:
1609 ;; Fix-me: use this!
1610 (setcdr (last chunk) '(mumamo-template-indentor))
1613 (defun mumamo-chunk-eruby-quoted (pos min max)
1614 "Find \"<%= ... %>\". Return range and 'ruby-mode.
1615 See `mumamo-find-possible-chunk' for POS, MIN and MAX.
1617 This is a workaround for problems with strings."
1618 (let ((chunk (mumamo-quick-static-chunk pos min max "\"<%=" "%>\"" t 'ruby-mode t)))
1620 ;; Put indentation type on 'mumamo-next-indent on the chunk:
1621 ;; Fix-me: use this!
1622 (setcdr (last chunk) '(mumamo-template-indentor))
1625 (defun mumamo-chunk-eruby-comment (pos min max)
1626 "Find <%# ... %>. Return range and 'ruby-mode.
1627 See `mumamo-find-possible-chunk' for POS, MIN and MAX.
1629 This is needed since otherwise the end marker is thought to be
1631 (mumamo-quick-static-chunk pos min max "<%#" "%>" t 'mumamo-comment-mode t))
1633 ;; (defun mumamo-search-bw-exc-start-ruby (pos min)
1634 ;; "Helper for `mumamo-chunk-ruby'.
1635 ;; POS is where to start search and MIN is where to stop."
1636 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "<%")))
1637 ;; (when (and exc-start
1638 ;; (<= exc-start pos))
1639 ;; (cons exc-start 'ruby-mode))))
1642 (define-mumamo-multi-major-mode eruby-mumamo-mode
1643 "Turn on multiple major mode for eRuby with unspecified main mode.
1644 Current major-mode will be used as the main major mode."
1646 (mumamo-chunk-eruby-comment
1651 (define-mumamo-multi-major-mode eruby-html-mumamo-mode
1652 "Turn on multiple major modes for eRuby with main mode `html-mode'.
1653 This also covers inlined style and javascript."
1654 ("eRuby Html Family" html-mode
1656 mumamo-chunk-eruby-comment
1658 mumamo-chunk-inlined-style
1659 mumamo-chunk-inlined-script
1665 (define-mumamo-multi-major-mode eruby-javascript-mumamo-mode
1666 "Turn on multiple major modes for eRuby with main mode `javascript-mode'."
1667 ("eRuby Html Family" javascript-mode
1669 mumamo-chunk-eruby-comment
1670 mumamo-chunk-eruby-quoted
1672 ;;mumamo-chunk-inlined-style
1673 ;;mumamo-chunk-inlined-script
1674 ;;mumamo-chunk-style=
1675 ;;mumamo-chunk-onjs=
1679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1682 (defcustom mumamo-heredoc-modes
1686 ("JAVASCRIPT" javascript-mode)
1688 ("GROOVY" groovy-mode)
1691 "Matches for heredoc modes.
1692 The entries in this list have the form
1694 (REGEXP MAJOR-MODE-SPEC)
1696 where REGEXP is a regular expression that should match the
1697 heredoc marker line and MAJOR-MODE-SPEC is the major mode spec to
1698 use in the heredoc part.
1700 The major mode spec is translated to a major mode using
1701 `mumamo-major-mode-from-modespec'."
1705 (function :tag "Major mode")))
1706 :group 'mumamo-modes)
1708 (defun mumamo-mode-for-heredoc (marker)
1709 "Return major mode associated with MARKER.
1710 Use first match in `mumamo-heredoc-modes'.
1711 If no match use `text-mode'."
1712 (let ((mode (catch 'mode
1714 (dolist (rec mumamo-heredoc-modes)
1715 (let ((regexp (nth 0 rec))
1717 (when (string-match regexp marker)
1718 (throw 'mode mode))))))))
1720 (mumamo-major-mode-from-modespec mode)
1723 (defun mumamo-chunk-heredoc (pos min max lang)
1724 "This should work similar to `mumamo-find-possible-chunk'.
1725 POS, MIN and MAX have the same meaning as there.
1727 LANG is the programming language.
1728 Supported values are 'perl."
1730 ;; Fix-me: use mumamo-end-in-code
1731 (mumamo-condition-case err
1732 (let ((old-point (point)))
1756 (setq allow-code-after t)
1758 (setq next-<< (search-forward "<<" max t))
1760 (setq want-<< nil) ;; give up
1761 ;; Check inside string or comment.
1762 (setq ps (parse-partial-sexp (line-beginning-position) (point)))
1763 (unless (or (nth 3 ps) (nth 4 ps))
1764 (setq want-<< nil))))
1766 (setq start-outer (- (point) 2))
1767 (when (= (char-after) ?-)
1769 (unless (eolp) (forward-char)))
1771 (setq skipped (skip-chars-forward " \t"))
1772 (when (memq (char-after) '(?\" ?\'))
1773 (setq delimiter (list (char-after))))
1774 (if (and (> skipped 0) (not delimiter))
1775 (setq heredoc-mark "")
1776 (when (looking-at (rx-to-string
1777 `(and (regexp ,(if delimiter
1778 (concat delimiter "\\([^\n<>;]+\\)" delimiter)
1779 "\\([^ \t\n<>;]+\\)"))
1780 (or blank line-end))))
1781 (setq heredoc-mark (buffer-substring-no-properties
1785 (setq heredoc-line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1786 (setq start-inner (1+ (point-at-eol)))
1787 (setq end-mark-len (length heredoc-mark))
1789 ('w32-ps (error "No support for windows power shell yet"))
1792 (setq next-<< (search-forward "<<<" max t))
1793 ;; Check inside string or comment.
1795 (setq want-<< nil) ;; give up
1796 (setq ps (parse-partial-sexp (line-beginning-position) (- (point) 0)))
1797 (unless (or (nth 3 ps) (nth 4 ps))
1798 (setq want-<< nil))))
1800 (setq start-outer (- (point) 3))
1801 (skip-chars-forward " \t")
1802 (when (looking-at (concat "\\([^\n;]*\\)[[:blank:]]*\n"))
1803 (setq heredoc-mark (buffer-substring-no-properties
1806 (setq heredoc-line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1808 (when (and (= ?\' (string-to-char heredoc-mark))
1809 (= ?\' (string-to-char (substring heredoc-mark (1- (length heredoc-mark))))))
1810 (setq heredoc-mark (substring heredoc-mark 1 (- (length heredoc-mark) 1))))
1811 (setq end-mark-len (1+ (length heredoc-mark)))
1812 (setq start-inner (match-end 0)))))
1814 (setq allow-code-after t)
1816 (setq next-<< (search-forward "<<" max t))
1818 (setq want-<< nil) ;; give up
1819 ;; Check inside string or comment.
1820 (setq ps (parse-partial-sexp (line-beginning-position) (point)))
1821 (unless (or (nth 3 ps) (nth 4 ps))
1822 (setq want-<< nil))))
1824 (setq start-outer (- (point) 2))
1826 (setq skipped (skip-chars-forward " \t"))
1827 (when (memq (char-after) '(?\" ?\'))
1828 (setq delimiter (list (char-after))))
1829 (if (and (> skipped 0) (not delimiter))
1830 (setq heredoc-mark "") ;; blank line
1831 (when (looking-at (rx-to-string
1832 `(and (regexp ,(if delimiter
1833 (concat delimiter "\\([^\n;]*\\)" delimiter)
1834 "\\([^ \t\n<>;]+\\)"))
1836 (setq heredoc-mark (buffer-substring-no-properties
1840 (setq heredoc-line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1841 ;;(setq start-inner (1+ (match-end 0)))
1842 (setq start-inner (1+ (point-at-eol)))
1843 (setq end-mark-len (length heredoc-mark))
1846 (unless (eobp) (forward-char))
1848 (setq next-<< (re-search-forward "\"\"\"\\|'''" max t))
1849 (setq start-outer (- (point) 3))
1851 (setq want-<< nil) ;; give up
1852 ;; Check inside string or comment.
1853 (setq ps (parse-partial-sexp (line-beginning-position) (- (point) 3)))
1854 (unless (or (nth 3 ps) (nth 4 ps))
1855 (setq want-<< nil)))))
1858 (setq next-<< (search-forward "<<" max t))
1860 (setq want-<< nil) ;; give up
1861 ;; Check inside string or comment.
1862 (setq ps (parse-partial-sexp (line-beginning-position) (point)))
1863 (unless (or (nth 3 ps) (nth 4 ps))
1864 (setq want-<< nil))))
1866 (setq start-outer (- (point) 2))
1867 (when (= (char-after) ?-)
1868 (setq skip-b "[ \t]*")
1870 (when (looking-at (concat "[^\n[:blank:]]*"))
1871 (setq heredoc-mark (buffer-substring-no-properties
1874 (setq end-mark-len (length heredoc-mark))
1875 (setq heredoc-line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1876 (setq start-inner (match-end 0)))))
1877 (t (error "next-<< not implemented for lang %s" lang)))
1878 (when start-inner (assert (<= pos start-inner) t))
1879 (goto-char old-point)
1880 (when (or start-inner end)
1881 (let ((endmark-regexp
1883 ('sh (concat "^" skip-b heredoc-mark "$"))
1884 ('php (concat "^" heredoc-mark ";?$"))
1885 ('perl (concat "^" heredoc-mark "$"))
1886 ('python (concat "^" heredoc-mark "[[:space:]]*"))
1887 ('ruby (concat "^" skip-b heredoc-mark "$"))
1888 (t (error "mark-regexp not implemented for %s" lang)))))
1889 ;; Fix-me: rename start-inner <=> start-outer...
1890 (setq border-fun `(lambda (start end exc-mode)
1891 ;; Fix-me: use lengths...
1893 (if ,allow-code-after nil (+ start (- ,start-inner ,start-outer 1)))
1894 (when end (- end ,end-mark-len)))))
1895 (setq fw-exc-fun `(lambda (pos max)
1897 (let ((here (point)))
1900 (when (re-search-forward ,endmark-regexp max t)
1901 (- (point) 1 ,(length heredoc-mark))
1904 (goto-char here)))))))
1905 (setq exc-mode (mumamo-mode-for-heredoc heredoc-line))
1906 (list start-inner end exc-mode nil nil fw-exc-fun nil)
1907 ;; Fix me: Add overriding for inner chunks (see
1908 ;; http://www.emacswiki.org/emacs/NxhtmlMode#toc13). Maybe
1909 ;; make fw-exc-fun a list (or a cons, since overriding is
1910 ;; probably all that I want to add)? And make the
1911 ;; corresponding chunk property a list too?
1912 ;;(list start-outer end exc-mode (list start-inner end) nil fw-exc-fun border-fun 'heredoc)
1913 (list (if allow-code-after start-inner start-outer)
1914 end exc-mode (list start-inner end) nil fw-exc-fun border-fun 'heredoc)
1916 (error (mumamo-display-error 'mumamo-chunk-heredoc
1917 "%s" (error-message-string err)))))
1920 ;;;; Unix style sh heredoc
1922 (defun mumamo-chunk-sh-heredoc (pos min max)
1924 See `mumamo-find-possible-chunk' for POS, MIN
1926 (let ((r (mumamo-chunk-heredoc pos min max 'sh)))
1930 (define-mumamo-multi-major-mode sh-heredoc-mumamo-mode
1931 "Turn on multiple major modes for sh heredoc document.
1932 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
1933 ("SH HereDoc" sh-mode
1934 (mumamo-chunk-sh-heredoc
1936 (mumamo-inherit-sub-chunk-family 'sh-heredoc-mumamo-mode)
1941 (defun mumamo-chunk-php-heredoc (pos min max)
1942 "Find PHP here docs.
1943 See `mumamo-find-possible-chunk' for POS, MIN
1945 (let ((r (mumamo-chunk-heredoc pos min max 'php)))
1949 (define-mumamo-multi-major-mode php-heredoc-mumamo-mode
1950 "Turn on multiple major modes for PHP heredoc document.
1951 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
1952 ("PHP HereDoc" php-mode
1953 (mumamo-chunk-php-heredoc
1955 (mumamo-inherit-sub-chunk-family 'php-heredoc-mumamo-mode)
1956 (mumamo-inherit-sub-chunk-family-locally 'php-heredoc-mumamo-mode 'html-mumamo-mode)
1961 (defun mumamo-chunk-perl-heredoc (pos min max)
1962 "Find perl here docs.
1963 See `mumamo-find-possible-chunk' for POS, MIN
1965 (let ((r (mumamo-chunk-heredoc pos min max 'perl)))
1969 (define-mumamo-multi-major-mode perl-heredoc-mumamo-mode
1970 "Turn on multiple major modes for Perl heredoc document.
1971 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
1972 ("Perl HereDoc" perl-mode
1973 (mumamo-chunk-perl-heredoc
1975 (mumamo-inherit-sub-chunk-family 'perl-heredoc-mumamo-mode)
1978 (define-mumamo-multi-major-mode cperl-heredoc-mumamo-mode
1979 "Turn on multiple major modes for Perl heredoc document.
1980 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
1981 ("Perl HereDoc" cperl-mode
1982 (mumamo-chunk-perl-heredoc
1984 (mumamo-inherit-sub-chunk-family 'cperl-heredoc-mumamo-mode)
1989 (defun mumamo-chunk-python-heredoc (pos min max)
1990 "Find python here docs.
1991 See `mumamo-find-possible-chunk' for POS, MIN
1993 (let ((r (mumamo-chunk-heredoc pos min max 'python)))
1997 (define-mumamo-multi-major-mode python-heredoc-mumamo-mode
1998 "Turn on multiple major modes for Perl heredoc document.
1999 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
2000 ("Python HereDoc" python-mode
2001 (mumamo-chunk-python-heredoc
2003 (mumamo-inherit-sub-chunk-family 'python-heredoc-mumamo-mode)
2008 (defun mumamo-chunk-ruby-heredoc (pos min max)
2009 "Find Ruby here docs.
2010 See `mumamo-find-possible-chunk' for POS, MIN
2012 (let ((r (mumamo-chunk-heredoc pos min max 'ruby)))
2016 (define-mumamo-multi-major-mode ruby-heredoc-mumamo-mode
2017 "Turn on multiple major modes for Ruby heredoc document.
2018 See `mumamo-heredoc-modes' for how to specify heredoc major modes."
2019 ("Ruby HereDoc" ruby-mode
2020 (mumamo-chunk-ruby-heredoc
2022 (mumamo-inherit-sub-chunk-family 'ruby-heredoc-mumamo-mode)
2025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2028 ;; (defun mumamo-search-bw-textext-start (pos min)
2029 ;; "Helper for `mumamo-chunk-textext'.
2030 ;; POS is where to start search and MIN is where to stop."
2031 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "textext(\""))
2032 ;; (exc-mode 'plain-tex-mode))
2034 ;; (when (<= exc-start pos)
2035 ;; (cons exc-start exc-mode)))))
2037 (defconst mumamo-textext-end-regex
2040 (0+ (not (any "\"()")))
2042 (0+ (not (any "\"")))
2045 (0+ (not (any "\"()")))
2048 (defun mumamo-textext-test-is-end (pos)
2049 "Helper for `mumamo-chunk-textext'.
2050 Return POS if POS is at the end of textext chunk."
2052 (let ((here (point))
2054 (goto-char (+ 2 pos))
2055 (when (looking-back mumamo-textext-end-regex)
2060 ;; (defun mumamo-search-bw-textext-end (pos min)
2061 ;; "Helper for `mumamo-chunk-textext'.
2062 ;; POS is where to start search and MIN is where to stop."
2063 ;; (let ((end (mumamo-chunk-end-bw-str pos min "\")"))
2066 ;; (not (setq res (mumamo-textext-test-is-end end))))
2067 ;; (setq end (mumamo-chunk-end-bw-str (1- end) min "\")")))
2070 ;; (defun mumamo-search-fw-textext-start-old (pos max)
2071 ;; "Helper for `mumamo-chunk-textext'.
2072 ;; POS is where to start search and MAX is where to stop."
2073 ;; (mumamo-chunk-start-fw-str pos max "textext(\""))
2075 (defun mumamo-search-fw-textext-start (pos max)
2076 "Helper for `mumamo-chunk-textext'.
2077 POS is where to start search and MAX is where to stop."
2078 (let ((where (mumamo-chunk-start-fw-str pos max "textext(\"")))
2080 (list where 'plain-tex-mode))))
2082 (defun mumamo-search-fw-textext-end (pos max)
2083 "Helper for `mumamo-chunk-textext'.
2084 POS is where to start search and MAX is where to stop."
2086 (let ((end (mumamo-chunk-end-fw-str pos max "\")")))
2087 (mumamo-textext-test-is-end end))))
2089 (defun mumamo-chunk-textext (pos min max)
2090 "Find textext or TEX chunks. Return range and 'plain-tex-mode.
2091 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2092 ;; (mumamo-find-possible-chunk pos min max
2093 ;; 'mumamo-search-bw-textext-start
2094 ;; 'mumamo-search-bw-textext-end
2095 ;; 'mumamo-search-fw-textext-start-old
2096 ;; 'mumamo-search-fw-textext-end)
2097 (mumamo-possible-chunk-forward pos max
2098 'mumamo-search-fw-textext-start
2099 'mumamo-search-fw-textext-end))
2101 ;; (defun mumamo-search-bw-verbatimtex-start (pos min)
2102 ;; "Helper for `mumamo-chunk-verbatimtextext'.
2103 ;; POS is where to start search and MIN is where to stop."
2104 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "\nverbatimtex"))
2105 ;; (exc-mode 'plain-tex-mode))
2107 ;; (when (<= exc-start pos)
2108 ;; (cons exc-start exc-mode)))))
2110 ;; (defun mumamo-search-bw-verbatimtex-end (pos min)
2111 ;; "Helper for `mumamo-chunk-verbatimtextext'.
2112 ;; POS is where to start search and MIN is where to stop."
2113 ;; (mumamo-chunk-end-bw-str pos min "\netex"))
2115 ;; (defun mumamo-search-fw-verbatimtex-start-old (pos max)
2116 ;; "Helper for `mumamo-chunk-verbatimtextext'.
2117 ;; POS is where to start search and MAX is where to stop."
2118 ;; (mumamo-chunk-start-fw-str pos max "\nverbatimtex"))
2120 (defun mumamo-search-fw-verbatimtex-start (pos max)
2121 "Helper for `mumamo-chunk-verbatimtextext'.
2122 POS is where to start search and MAX is where to stop."
2123 (let ((where (mumamo-chunk-start-fw-str pos max "\nverbatimtex")))
2125 (list where 'plain-tex-mode))))
2127 (defun mumamo-search-fw-verbatimtex-end (pos max)
2128 "Helper for `mumamo-chunk-verbatimtextext'.
2129 POS is where to start search and MAX is where to stop."
2131 (mumamo-chunk-end-fw-str pos max "\netex")))
2133 (defun mumamo-chunk-verbatimtex (pos min max)
2134 "Find verbatimtex - etex chunks. Return range and 'plain-tex-mode.
2135 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2136 ;; (mumamo-find-possible-chunk pos min max
2137 ;; 'mumamo-search-bw-verbatimtex-start
2138 ;; 'mumamo-search-bw-verbatimtex-end
2139 ;; 'mumamo-search-fw-verbatimtex-start-old
2140 ;; 'mumamo-search-fw-verbatimtex-end)
2141 (mumamo-possible-chunk-forward pos max
2142 'mumamo-search-fw-verbatimtex-start
2143 'mumamo-search-fw-verbatimtex-end))
2145 ;; (defun mumamo-search-bw-btex-start (pos min)
2146 ;; "Helper for `mumamo-chunk-btex'.
2147 ;; POS is where to start search and MIN is where to stop."
2148 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "\nverbatimtex"))
2149 ;; (exc-mode 'plain-tex-mode))
2151 ;; (when (<= exc-start pos)
2152 ;; (cons exc-start exc-mode)))))
2154 ;; (defun mumamo-search-bw-btex-end (pos min)
2155 ;; "Helper for `mumamo-chunk-btex'.
2156 ;; POS is where to start search and MIN is where to stop."
2157 ;; (mumamo-chunk-end-bw-str pos min "\netex"))
2159 ;; (defun mumamo-search-fw-btex-start-old (pos max)
2160 ;; "Helper for `mumamo-chunk-btex'.
2161 ;; POS is where to start search and MAX is where to stop."
2162 ;; (mumamo-chunk-start-fw-str pos max "\nverbatimtex"))
2164 (defun mumamo-search-fw-btex-start (pos max)
2165 "Helper for `mumamo-chunk-btex'.
2166 POS is where to start search and MAX is where to stop."
2167 (let ((where (mumamo-chunk-start-fw-str pos max "\nverbatimtex")))
2169 (list where 'plain-tex-mode))))
2171 (defun mumamo-search-fw-btex-end (pos max)
2172 "Helper for `mumamo-chunk-btex'.
2173 POS is where to start search and MAX is where to stop."
2175 (mumamo-chunk-end-fw-str pos max "\netex")))
2177 (defun mumamo-chunk-btex (pos min max)
2178 "Find btex - etex chunks.
2179 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2180 ;; (mumamo-find-possible-chunk pos min max
2181 ;; 'mumamo-search-bw-btex-start
2182 ;; 'mumamo-search-bw-btex-end
2183 ;; 'mumamo-search-fw-btex-start-old
2184 ;; 'mumamo-search-fw-btex-end)
2185 (mumamo-possible-chunk-forward pos max
2186 'mumamo-search-fw-btex-start
2187 'mumamo-search-fw-btex-end))
2190 (define-mumamo-multi-major-mode metapost-mumamo-mode
2191 "Turn on multiple major modes for MetaPost."
2192 ("MetaPost TeX Family" metapost-mode
2193 (mumamo-chunk-textext
2194 mumamo-chunk-verbatimtex
2198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2201 (defconst mumamo-lzx-method-tag-start-regex
2205 (0+ (not (any ">"))))
2207 ;; FIX-ME: Commented out because of bug in Emacs
2209 ;;(optional (0+ space) "<![CDATA[" )
2212 (defun mumamo-search-bw-exc-start-inlined-lzx-method (pos min)
2213 "Helper for `mumamo-chunk-inlined-lzx-method'.
2214 POS is where to start search and MIN is where to stop."
2215 (goto-char (+ pos 7))
2216 (let ((marker-start (search-backward "<method" min t))
2220 (when (looking-at mumamo-lzx-method-tag-start-regex)
2221 (setq exc-start (match-end 0))
2222 (goto-char exc-start)
2223 (when (<= exc-start pos)
2224 (cons (point) 'javascript-mode))
2227 ;; (defun mumamo-search-bw-exc-end-inlined-lzx-method (pos min)
2228 ;; "Helper for `mumamo-chunk-inlined-lzx-method'.
2229 ;; POS is where to start search and MIN is where to stop."
2230 ;; (mumamo-chunk-end-bw-str pos min "</method>"))
2232 ;; (defun mumamo-search-fw-exc-start-inlined-lzx-method-old (pos max)
2233 ;; "Helper for `mumamo-chunk-inlined-lzx-method'.
2234 ;; POS is where to start search and MAX is where to stop."
2235 ;; (goto-char (1+ pos))
2236 ;; (skip-chars-backward "^<")
2237 ;; ;; Handle <![CDATA[
2239 ;; (eq ?< (char-before))
2240 ;; (eq ?! (char-after))
2243 ;; (skip-chars-backward "^<"))
2245 ;; (backward-char 1))
2246 ;; (let ((exc-start (search-forward "<method" max t))
2249 ;; (goto-char (- exc-start 7))
2250 ;; (when (looking-at mumamo-lzx-method-tag-start-regex)
2251 ;; (goto-char (match-end 0))
2255 (defun mumamo-search-fw-exc-start-inlined-lzx-method (pos max)
2256 "Helper for `mumamo-chunk-inlined-lzx-method'.
2257 POS is where to start search and MAX is where to stop."
2258 (goto-char (1+ pos))
2259 (skip-chars-backward "^<")
2262 (eq ?< (char-before))
2263 (eq ?! (char-after))
2266 (skip-chars-backward "^<"))
2269 (let ((exc-start (search-forward "<method" max t))
2272 (goto-char (- exc-start 7))
2273 (when (looking-at mumamo-lzx-method-tag-start-regex)
2274 (goto-char (match-end 0))
2275 (list (point) 'javascript-mode)
2278 (defun mumamo-search-fw-exc-end-inlined-lzx-method (pos max)
2279 "Helper for `mumamo-chunk-inlined-lzx-method'.
2280 POS is where to start search and MAX is where to stop."
2282 (mumamo-chunk-end-fw-str pos max "</method>")))
2284 (defun mumamo-chunk-inlined-lzx-method (pos min max)
2285 "Find <method>...</method>. Return range and 'javascript-mode.
2286 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2287 ;; (mumamo-find-possible-chunk pos min max
2288 ;; 'mumamo-search-bw-exc-start-inlined-lzx-method
2289 ;; 'mumamo-search-bw-exc-end-inlined-lzx-method
2290 ;; 'mumamo-search-fw-exc-start-inlined-lzx-method-old
2291 ;; 'mumamo-search-fw-exc-end-inlined-lzx-method)
2292 (mumamo-possible-chunk-forward pos max
2293 'mumamo-search-fw-exc-start-inlined-lzx-method
2294 'mumamo-search-fw-exc-end-inlined-lzx-method))
2296 (defconst mumamo-lzx-handler-tag-start-regex
2300 (0+ (not (any ">"))))
2302 ;; FIX-ME: Commented out because of bug in Emacs
2304 ;;(optional (0+ space) "<![CDATA[" )
2307 ;; (defun mumamo-search-bw-exc-start-inlined-lzx-handler (pos min)
2308 ;; "Helper for `mumamo-chunk-inlined-lzx-handler'.
2309 ;; POS is where to start search and MIN is where to stop."
2310 ;; (goto-char (+ pos 8))
2311 ;; (let ((marker-start (search-backward "<handler" min t))
2314 ;; (when marker-start
2315 ;; (when (looking-at mumamo-lzx-handler-tag-start-regex)
2316 ;; (setq exc-start (match-end 0))
2317 ;; (goto-char exc-start)
2318 ;; (when (<= exc-start pos)
2319 ;; (cons (point) 'javascript-mode))
2322 ;; (defun mumamo-search-bw-exc-end-inlined-lzx-handler (pos min)
2323 ;; "Helper for `mumamo-chunk-inlined-lzx-handler'.
2324 ;; POS is where to start search and MIN is where to stop."
2325 ;; (mumamo-chunk-end-bw-str pos min "</handler>"))
2327 ;; (defun mumamo-search-fw-exc-start-inlined-lzx-handler-old (pos max)
2328 ;; "Helper for `mumamo-chunk-inlined-lzx-handler'.
2329 ;; POS is where to start search and MAX is where to stop."
2330 ;; (goto-char (1+ pos))
2331 ;; (skip-chars-backward "^<")
2332 ;; ;; Handle <![CDATA[
2334 ;; (eq ?< (char-before))
2335 ;; (eq ?! (char-after))
2338 ;; (skip-chars-backward "^<"))
2340 ;; (backward-char 1))
2341 ;; (let ((exc-start (search-forward "<handler" max t))
2344 ;; (goto-char (- exc-start 8))
2345 ;; (when (looking-at mumamo-lzx-handler-tag-start-regex)
2346 ;; (goto-char (match-end 0))
2350 (defun mumamo-search-fw-exc-start-inlined-lzx-handler (pos max)
2351 "Helper for `mumamo-chunk-inlined-lzx-handler'.
2352 POS is where to start search and MAX is where to stop."
2353 (goto-char (1+ pos))
2354 (skip-chars-backward "^<")
2357 (eq ?< (char-before))
2358 (eq ?! (char-after))
2361 (skip-chars-backward "^<"))
2364 (let ((exc-start (search-forward "<handler" max t))
2367 (goto-char (- exc-start 8))
2368 (when (looking-at mumamo-lzx-handler-tag-start-regex)
2369 (goto-char (match-end 0))
2370 (list (point) 'javascript-mode)
2373 (defun mumamo-search-fw-exc-end-inlined-lzx-handler (pos max)
2374 "Helper for `mumamo-chunk-inlined-lzx-handler'.
2375 POS is where to start search and MAX is where to stop."
2377 (mumamo-chunk-end-fw-str pos max "</handler>")))
2379 (defun mumamo-chunk-inlined-lzx-handler (pos min max)
2380 "Find <handler>...</handler>. Return range and 'javascript-mode.
2381 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2382 ;; (mumamo-find-possible-chunk pos min max
2383 ;; 'mumamo-search-bw-exc-start-inlined-lzx-handler
2384 ;; 'mumamo-search-bw-exc-end-inlined-lzx-handler
2385 ;; 'mumamo-search-fw-exc-start-inlined-lzx-handler-old
2386 ;; 'mumamo-search-fw-exc-end-inlined-lzx-handler)
2387 (mumamo-possible-chunk-forward pos max
2388 'mumamo-search-fw-exc-start-inlined-lzx-handler
2389 'mumamo-search-fw-exc-end-inlined-lzx-handler))
2393 (define-mumamo-multi-major-mode laszlo-nxml-mumamo-mode
2394 "Turn on multiple major modes for OpenLaszlo."
2395 ("OpenLaszlo Family" nxml-mode
2396 (mumamo-chunk-inlined-script
2397 mumamo-chunk-inlined-lzx-method
2398 mumamo-chunk-inlined-lzx-handler
2402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2405 ;; (defun mumamo-search-bw-exc-start-csound-orc (pos min)
2406 ;; "Helper for `mumamo-chunk-csound-orc'.
2407 ;; POS is where to start search and MIN is where to stop."
2408 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "<csinstruments>")))
2410 ;; (<= exc-start pos)
2411 ;; (cons exc-start 'csound-orc-mode))))
2413 ;; (defun mumamo-search-bw-exc-end-csound-orc (pos min)
2414 ;; "Helper for `mumamo-chunk-csound-orc'.
2415 ;; POS is where to start search and MIN is where to stop."
2416 ;; (mumamo-chunk-end-bw-str pos min "</csinstruments>"))
2418 ;; (defun mumamo-search-fw-exc-start-csound-orc-old (pos max)
2419 ;; "Helper for `mumamo-chunk-csound-orc'.
2420 ;; POS is where to start search and MAX is where to stop."
2421 ;; (mumamo-chunk-start-fw-str pos max "<csinstruments>"))
2423 (defun mumamo-search-fw-exc-start-csound-orc (pos max)
2424 "Helper for `mumamo-chunk-csound-orc'.
2425 POS is where to start search and MAX is where to stop."
2426 (let ((where (mumamo-chunk-start-fw-str pos max "<csinstruments>")))
2428 (list where 'csound-orc-mode))))
2430 (defun mumamo-search-fw-exc-end-csound-orc (pos max)
2431 "Helper for `mumamo-chunk-csound-orc'.
2432 POS is where to start search and MAX is where to stop."
2434 (mumamo-chunk-end-fw-str pos max "</csinstruments>")))
2436 (defun mumamo-chunk-csound-orc (pos min max)
2437 "Find <csinstruments>...</...>. Return range and 'csound-orc-mode.
2438 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2439 ;; (mumamo-find-possible-chunk pos min max
2440 ;; 'mumamo-search-bw-exc-start-csound-orc
2441 ;; 'mumamo-search-bw-exc-end-csound-orc
2442 ;; 'mumamo-search-fw-exc-start-csound-orc-old
2443 ;; 'mumamo-search-fw-exc-end-csound-orc)
2444 (mumamo-possible-chunk-forward pos max
2445 'mumamo-search-fw-exc-start-csound-orc
2446 'mumamo-search-fw-exc-end-csound-orc))
2448 ;; (defun mumamo-search-bw-exc-start-csound-sco (pos min)
2449 ;; "Helper for `mumamo-chunk-csound-sco'.
2450 ;; POS is where to start search and MIN is where to stop."
2451 ;; (let ((exc-start (mumamo-chunk-start-bw-str pos min "<csscore>")))
2453 ;; (<= exc-start pos)
2454 ;; (cons exc-start 'csound-sco-mode))))
2456 ;; (defun mumamo-search-bw-exc-end-csound-sco (pos min)
2457 ;; "Helper for `mumamo-chunk-csound-sco'.
2458 ;; POS is where to start search and MIN is where to stop."
2459 ;; (mumamo-chunk-end-bw-str pos min "</csscore>"))
2461 ;; (defun mumamo-search-fw-exc-start-csound-sco-old (pos max)
2462 ;; "Helper for `mumamo-chunk-csound-sco'.
2463 ;; POS is where to start search and MAX is where to stop."
2464 ;; (mumamo-chunk-start-fw-str pos max "<csscore>"))
2466 (defun mumamo-search-fw-exc-start-csound-sco (pos max)
2467 "Helper for `mumamo-chunk-csound-sco'.
2468 POS is where to start search and MAX is where to stop."
2469 (let ((where (mumamo-chunk-start-fw-str pos max "<csscore>")))
2471 (list where 'csound-sco-mode))))
2473 (defun mumamo-search-fw-exc-end-csound-sco (pos max)
2474 "Helper for `mumamo-chunk-csound-sco'.
2475 POS is where to start search and MAX is where to stop."
2477 (mumamo-chunk-end-fw-str pos max "</csscore>")))
2479 (defun mumamo-chunk-csound-sco (pos min max)
2480 "Found <csscore>...</csscore>. Return range and 'csound-sco-mode.
2481 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2482 ;; (mumamo-find-possible-chunk pos min max
2483 ;; 'mumamo-search-bw-exc-start-csound-sco
2484 ;; 'mumamo-search-bw-exc-end-csound-sco
2485 ;; 'mumamo-search-fw-exc-start-csound-sco-old
2486 ;; 'mumamo-search-fw-exc-end-csound-sco)
2487 (mumamo-possible-chunk-forward pos max
2488 'mumamo-search-fw-exc-start-csound-sco
2489 'mumamo-search-fw-exc-end-csound-sco))
2492 (define-mumamo-multi-major-mode csound-sgml-mumamo-mode
2493 "Turn on mutiple major modes for CSound orc/sco Modes."
2494 ("CSound orc/sco Modes" sgml-mode
2495 (mumamo-chunk-csound-sco
2496 mumamo-chunk-csound-orc
2500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2504 (defgroup mumamo-noweb2 nil
2505 "Customization group for `noweb2-mumamo-mode'."
2506 :group 'mumamo-modes)
2508 (defcustom mumamo-noweb2-mode-from-ext
2513 "File extension regexp to major mode mapping.
2514 Used by `noweb2-mumamo-mode'."
2516 (cons regexp major-mode-function))
2517 :group 'mumamo-noweb2)
2519 (defvar mumamo-noweb2-found-mode-from-ext nil
2520 "Major modes determined from file names. Internal use.")
2522 (defun mumamo-noweb2-chunk-start-fw (pos max)
2523 "Helper for `mumamo-noweb2-chunk'.
2524 POS is where to start search and MAX is where to stop."
2525 (let ((where (mumamo-chunk-start-fw-re pos max "^<<\\(.*?\\)>>="))
2526 (exc-mode 'text-mode))
2528 (let* ((file-name (match-string-no-properties 1))
2529 (file-ext (when file-name (file-name-extension file-name))))
2531 (setq exc-mode (catch 'major
2532 (dolist (rec mumamo-noweb2-mode-from-ext)
2533 (when (string-match (car rec) file-ext)
2534 (throw 'major (cdr rec))))
2536 (list where exc-mode))))
2538 ;; (defun mumamo-noweb2-chunk-start-bw (pos min)
2539 ;; "Helper for `mumamo-noweb2-chunk'.
2540 ;; POS is where to start search and MIN is where to stop."
2541 ;; (let ((exc-start (mumamo-chunk-start-bw-re pos min "^<<\\(.*?\\)>>="))
2542 ;; (exc-mode 'text-mode))
2544 ;; (let* ((file-name (match-string 1))
2545 ;; (file-ext (when file-name (file-name-extension file-name))))
2547 ;; (setq exc-mode (catch 'major
2548 ;; (dolist (rec mumamo-noweb2-mode-from-ext)
2549 ;; (when (string-match (car rec) file-ext)
2550 ;; (throw 'major (cdr rec))))
2554 ;; (cdr (assoc file-ext mumamo-noweb2-found-mode-from-ext)))
2556 ;; ;; Get the major mode from file name
2557 ;; (with-temp-buffer
2558 ;; (setq buffer-file-name file-name)
2559 ;; (condition-case err
2561 ;; (error (message "error (normal-mode): %s"
2562 ;; (error-message-string err))))
2563 ;; (setq exc-mode (or major-mode
2565 ;; (add-to-list 'mumamo-noweb2-found-mode-from-ext
2566 ;; (cons file-ext exc-mode)))
2568 ;; (cons exc-start exc-mode))))
2570 (defun mumamo-noweb2-chunk-end-fw (pos max)
2571 "Helper for `mumamo-noweb2-chunk'.
2572 POS is where to start search and MAX is where to stop."
2574 (mumamo-chunk-end-fw-re pos max "^@")))
2576 ;; (defun mumamo-noweb2-chunk-end-bw (pos min)
2577 ;; "Helper for `mumamo-noweb2-chunk'.
2578 ;; POS is where to start search and MIN is where to stop."
2579 ;; (mumamo-chunk-end-bw-re pos min "^@"))
2581 (defun mumamo-noweb2-code-chunk (pos min max)
2582 "Find noweb chunks. Return range and found mode.
2583 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2585 ;; (mumamo-find-possible-chunk pos min max
2586 ;; 'mumamo-noweb2-chunk-start-bw
2587 ;; 'mumamo-noweb2-chunk-end-bw
2588 ;; 'mumamo-noweb2-chunk-start-fw-old
2589 ;; 'mumamo-noweb2-chunk-end-fw)
2590 (mumamo-possible-chunk-forward pos max
2591 'mumamo-noweb2-chunk-start-fw
2592 'mumamo-noweb2-chunk-end-fw)))
2596 (define-mumamo-multi-major-mode noweb2-mumamo-mode
2597 "Multi major mode for noweb files."
2598 ("noweb Family" latex-mode
2599 (mumamo-noweb2-code-chunk)))
2602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2603 ;;;; Template-Toolkit
2607 ;; (setq auto-mode-alist
2608 ;; (append '(("\\.tt2?$" . tt-mode)) auto-mode-alist ))
2610 ;;(require 'tt-mode)
2611 (defun mumamo-chunk-tt (pos min max)
2612 "Find [% ... %], return range and `tt-mode'.
2613 See `mumamo-find-possible-chunk' for POS, MIN and MAX.
2615 This is for Template Toolkit.
2616 See URL `http://dave.org.uk/emacs/' for `tt-mode'."
2617 (mumamo-quick-static-chunk pos min max "[%" "%]" t 'tt-mode nil))
2619 (define-mumamo-multi-major-mode tt-html-mumamo-mode
2620 "Turn on multiple major modes for TT files with main mode `nxhtml-mode'.
2621 TT = Template-Toolkit.
2623 This also covers inlined style and javascript."
2624 ("TT HTML Family" html-mode
2626 mumamo-chunk-inlined-style
2627 mumamo-chunk-inlined-script
2633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2636 ;;;; asp <%@language="javscript"%>
2638 (defvar mumamo-asp-default-major 'asp-js-mode)
2639 (make-variable-buffer-local 'mumamo-asp-default-major)
2640 (put 'mumamo-asp-default-major 'permanent-local t)
2642 (defconst mumamo-asp-lang-marker
2650 (submatch (1+ (not (any "\""))))
2654 (defun mumamo-search-fw-exc-start-jsp (pos min max)
2657 (defun mumamo-chunk-asp (pos min max)
2658 "Find <% ... %>. Return range and 'asp-js-mode.
2659 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2660 ;; Fix-me: this is broken!
2661 ;; (mumamo-find-possible-chunk pos min max
2662 ;; 'mumamo-search-bw-exc-start-asp
2663 ;; 'mumamo-search-bw-exc-end-jsp
2664 ;; 'mumamo-search-fw-exc-start-jsp-old
2665 ;; 'mumamo-search-fw-exc-end-jsp)
2666 (mumamo-possible-chunk-forward pos max
2667 'mumamo-search-fw-exc-start-asp
2668 'mumamo-search-fw-exc-end-jsp))
2673 (defun mumamo-chunk-asp% (pos min max)
2674 "Find <% ... %>. Return range and 'asp-js-mode or 'asp-vb-mode.
2675 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2676 (let* ((chunk (mumamo-quick-static-chunk pos min max "<%" "%>" t 'java-mode t))
2682 (if (looking-at mumamo-asp-lang-marker)
2684 (setq glang (downcase (match-string 1)))
2686 ((string= glang "javascript")
2687 (setq mumamo-asp-default-major 'asp-js-mode))
2688 ((string= glang "vbscript")
2689 (setq mumamo-asp-default-major 'asp-vb-mode))
2691 (setcar (nthcdr 2 chunk) 'mumamo-comment-mode))
2692 (setcar (nthcdr 2 chunk) mumamo-asp-default-major))
2695 ;;;; asp <script ...>
2697 (defconst mumamo-asp-script-tag-start-regex
2700 (0+ (not (any ">")))
2706 ;;(or "text" "application")
2708 ;;(or "javascript" "ecmascript")
2709 ;; "text/javascript"
2711 (or "javascript" "vbscript"))
2713 (0+ (not (any ">")))
2715 ;; FIX-ME: Commented out because of bug in Emacs
2717 ;;(optional (0+ space) "<![CDATA[" )
2720 ;; (defun mumamo-asp-search-bw-exc-start-inlined-script (pos min)
2721 ;; "Helper function for `mumamo-asp-chunk-inlined-script'.
2722 ;; POS is where to start search and MIN is where to stop."
2723 ;; (goto-char (+ pos 7))
2724 ;; (let ((marker-start (search-backward "<script" min t))
2725 ;; (exc-mode 'asp-vb-mode)
2728 ;; (when marker-start
2729 ;; (when (looking-at mumamo-asp-script-tag-start-regex)
2730 ;; (setq lang (downcase (match-string-no-properties 1)))
2732 ;; ((string= lang "javascript")
2733 ;; (setq exc-mode 'asp-js-mode))
2734 ;; ((string= lang "vbscript")
2735 ;; (setq exc-mode 'asp-vb-mode))))
2736 ;; (setq exc-start (match-end 0))
2737 ;; (goto-char exc-start)
2738 ;; (when (<= exc-start pos)
2739 ;; (cons (point) exc-mode))
2742 ;; (defun mumamo-asp-search-fw-exc-start-inlined-script-old (pos max)
2743 ;; "Helper for `mumamo-chunk-inlined-script'.
2744 ;; POS is where to start search and MAX is where to stop."
2745 ;; (goto-char (1+ pos))
2746 ;; (skip-chars-backward "^<")
2747 ;; ;; Handle <![CDATA[
2749 ;; (eq ?< (char-before))
2750 ;; (eq ?! (char-after))
2753 ;; (skip-chars-backward "^<"))
2755 ;; (backward-char 1))
2756 ;; (let ((exc-start (search-forward "<script" max t))
2759 ;; (goto-char (- exc-start 7))
2760 ;; (when (looking-at mumamo-asp-script-tag-start-regex)
2761 ;; (goto-char (match-end 0))
2765 (defun mumamo-asp-search-fw-exc-start-inlined-script (pos max)
2766 "Helper for `mumamo-chunk-inlined-script'.
2767 POS is where to start search and MAX is where to stop."
2768 (goto-char (1+ pos))
2769 (skip-chars-backward "^<")
2772 (eq ?< (char-before))
2773 (eq ?! (char-after))
2776 (skip-chars-backward "^<"))
2779 (let ((exc-start (search-forward "<script" max t))
2780 (exc-mode 'asp-vb-mode)
2783 (goto-char (- exc-start 7))
2784 (when (looking-at mumamo-asp-script-tag-start-regex)
2785 (goto-char (match-end 0))
2786 (setq lang (downcase (match-string-no-properties 1)))
2788 ((string= lang "javascript")
2789 (setq exc-mode 'asp-js-mode))
2790 ((string= lang "vbscript")
2791 (setq exc-mode 'asp-vb-mode)))
2792 (list (point) exc-mode)
2795 (defun mumamo-asp-chunk-inlined-script (pos min max)
2796 "Find <script language=... runat=...>...</script>. Return 'asp-js-mode.
2797 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2798 ;; (mumamo-find-possible-chunk pos min max
2799 ;; 'mumamo-asp-search-bw-exc-start-inlined-script
2800 ;; 'mumamo-search-bw-exc-end-inlined-script
2801 ;; 'mumamo-asp-search-fw-exc-start-inlined-script-old
2802 ;; 'mumamo-search-fw-exc-end-inlined-script)
2803 (mumamo-possible-chunk-forward pos max
2804 'mumamo-asp-search-fw-exc-start-inlined-script
2805 'mumamo-search-fw-exc-end-inlined-script))
2808 (define-mumamo-multi-major-mode asp-html-mumamo-mode
2809 "Turn on multiple major modes for ASP with main mode `html-mode'.
2810 This also covers inlined style and javascript."
2811 ("ASP Html Family" html-mode
2813 mumamo-asp-chunk-inlined-script
2814 mumamo-chunk-inlined-script
2820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2823 (defcustom mumamo-org-submodes
2825 (emacs-lisp emacs-lisp-mode)
2827 (python python-mode)
2830 (ditaa picture-mode)
2832 "Alist for conversion of org #+BEGIN_SRC specifier to major mode.
2833 Works kind of like `mumamo-major-modes'.
2835 This may be used for example for org-babel \(see URL
2836 `http://orgmode.org/worg/org-contrib/babel/')."
2838 :key-type (symbol :tag "Symbol in #BEGIN_SRC specifier")
2839 :value-type (repeat (choice
2840 (command :tag "Major mode")
2841 (symbol :tag "Major mode (not yet loaded)")))
2843 :group 'mumamo-modes)
2845 (defun mumamo-org-mode-from-spec (major-spec)
2846 "Translate MAJOR-SPEC to a major mode.
2847 Translate MAJOR-SPEC used in #BEGIN_SRC to a major mode.
2849 See `mumamo-org-submodes' for an explanation."
2850 (mumamo-major-mode-from-spec major-spec mumamo-org-submodes))
2852 (defun mumamo-chunk-org-html (pos min max)
2853 "Find #+BEGIN_HTML ... #+END_HTML, return range and `html-mode'.
2854 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2855 (mumamo-quick-static-chunk pos min max "#+BEGIN_HTML" "#+END_HTML" nil 'html-mode nil))
2857 ;; (defun mumamo-search-bw-org-src-start (pos min)
2858 ;; "Helper for `mumamo-chunk-org-src'.
2859 ;; POS is where to start search and MIN is where to stop."
2860 ;; (let* ((exc-start (mumamo-chunk-start-bw-str pos min "#+BEGIN_SRC"))
2861 ;; (exc-mode (when exc-start
2862 ;; (let ((here (point)))
2863 ;; (goto-char exc-start)
2865 ;; (read (current-buffer))
2866 ;; (goto-char here))))))
2867 ;; (setq exc-mode (mumamo-org-mode-from-spec exc-mode))
2868 ;; ;;(setq exc-mode (eval exc-mode))
2869 ;; ;;(setq exc-mode 'text-mode)
2870 ;; ;;(when exc-mode (setq exc-mode (quote exc-mode)))
2871 ;; ;;(assert (eq exc-mode 'emacs-lisp-mode) t)
2873 ;; (when (<= exc-start pos)
2874 ;; (cons exc-start exc-mode)))))
2876 ;; (defun mumamo-search-bw-org-src-end (pos min)
2877 ;; "Helper for `mumamo-chunk-org-src'.
2878 ;; POS is where to start search and MIN is where to stop."
2879 ;; (mumamo-chunk-end-bw-str pos min "#+END_SRC"))
2881 ;; (defun mumamo-search-fw-org-src-start-old (pos max)
2882 ;; "Helper for `mumamo-chunk-org-src'.
2883 ;; POS is where to start search and MAX is where to stop."
2884 ;; (mumamo-chunk-start-fw-str pos max "#+BEGIN_SRC"))
2886 (defun mumamo-search-fw-org-src-start (pos max)
2887 "Helper for `mumamo-chunk-org-src'.
2888 POS is where to start search and MAX is where to stop."
2889 (let ((where (mumamo-chunk-start-fw-str pos max "#+BEGIN_SRC")))
2891 (let ((exc-mode (let ((here (point)))
2894 (read (current-buffer))
2895 (goto-char here)))))
2896 (setq exc-mode (mumamo-org-mode-from-spec exc-mode))
2897 (list where exc-mode)))))
2899 (defun mumamo-search-fw-org-src-end (pos max)
2900 "Helper for `mumamo-chunk-org-src'.
2901 POS is where to start search and MAX is where to stop."
2903 (mumamo-chunk-end-fw-str pos max "#+END_SRC")))
2905 (defun mumamo-chunk-org-src (pos min max)
2906 "Find #+BEGIN_SRC ... #+END_SRC, return range and choosen major mode.
2907 See `mumamo-find-possible-chunk' for POS, MIN and MAX.
2909 See Info node `(org) Literal Examples' for how to specify major
2911 ;; (mumamo-find-possible-chunk pos min max
2912 ;; 'mumamo-search-bw-org-src-start
2913 ;; 'mumamo-search-bw-org-src-end
2914 ;; 'mumamo-search-fw-org-src-start-old
2915 ;; 'mumamo-search-fw-org-src-end)
2916 (mumamo-possible-chunk-forward pos max
2917 'mumamo-search-fw-org-src-start
2918 'mumamo-search-fw-org-src-end))
2921 (define-mumamo-multi-major-mode org-mumamo-mode
2922 "Turn on multiple major modes for `org-mode' files with main mode `org-mode'.
2923 ** Note about HTML subchunks:
2924 Unfortunately this only allows `html-mode' (not `nxhtml-mode') in
2926 ("Org Mode + Html" org-mode
2927 (mumamo-chunk-org-html
2928 mumamo-chunk-org-src
2932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2935 ;; See http://www.makotemplates.org/docs/syntax.html
2938 ;; Fix-me: move to mumamo.el
2939 (defconst mumamo-comment-font-lock-keywords
2941 (cons "\\(.*\\)" (list 1 font-lock-comment-face))
2943 (defvar mumamo-comment-font-lock-defaults
2944 '(mumamo-comment-font-lock-keywords t t))
2946 (define-derived-mode mumamo-comment-mode nil "Comment chunk"
2947 "For comment blocks."
2948 (set (make-local-variable 'font-lock-defaults) mumamo-comment-font-lock-defaults))
2952 (defun mumamo-chunk-mako-<% (pos min max)
2953 "Find <% ... %> and <%! ... %>. Return range and `python-mode'.
2954 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
2955 ;; (mumamo-find-possible-chunk pos min max
2956 ;; 'mumamo-mako-<%-bw-start
2957 ;; 'mumamo-mako-<%-bw-end
2958 ;; 'mumamo-mako-<%-fw-start-old
2959 ;; 'mumamo-mako-<%-fw-end
2960 ;; 'mumamo-mako-<%-find-borders)
2961 (let ((chunk (mumamo-possible-chunk-forward pos max
2962 'mumamo-mako-<%-fw-start
2963 'mumamo-mako-<%-fw-end
2964 'mumamo-mako-<%-find-borders
2967 (setcdr (last chunk) '(mumamo-template-indentor))
2970 (defun mumamo-mako-<%-find-borders (start end exc-mode)
2975 (if (eq ?! (char-after (+ start 2)))
2978 (when end (- end 2))
2981 ;; (defun mumamo-mako-<%-bw-start (pos min)
2982 ;; (let ((here (point))
2986 ;; (goto-char (+ pos 3))
2987 ;; (setq start (re-search-backward "<%!?\\(?:[ \t]\\|$\\)" min t))
2988 ;; (when (and start (<= start pos))
2989 ;; (setq ret (list start 'python-mode)))
2993 ;; (defun mumamo-mako-<%-bw-end (pos min)
2994 ;; (mumamo-chunk-end-bw-str-inc pos min "%>")) ;; ok
2996 ;; (defun mumamo-mako-<%-fw-start-old (pos max)
2997 ;; (let ((here (point))
3002 ;; (re-search-forward "<%!?\\(?:[ \t]\\|$\\)" max t))
3004 ;; (setq ret (match-beginning 0)))
3008 (defun mumamo-mako-<%-fw-start (pos max)
3009 (let ((here (point))
3014 (re-search-forward "<%!?\\(?:[ \t]\\|$\\)" max t))
3016 (setq ret (match-beginning 0)))
3019 (list ret 'python-mode))))
3021 (defun mumamo-mako-<%-fw-end (pos max)
3023 (mumamo-chunk-end-fw-str-inc pos max "%>"))) ;; ok
3027 (defun mumamo-chunk-mako-% (pos min max)
3028 "Find % python EOL. Return range and `python-mode'.
3029 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
3030 (let ((chunk (mumamo-whole-line-chunk pos min max "%" 'python-mode)))
3032 (setcdr (last chunk) '(mumamo-template-indentor))
3035 (defun mumamo-chunk-mako-one-line-comment (pos min max)
3036 "Find ## comment EOL. Return range and `python-mode'.
3037 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
3038 (mumamo-whole-line-chunk pos min max "##" 'mumamo-comment-mode))
3040 ;; Fix-me: Move this to mumamo.el
3041 ;; Fix-me: does not work with new chunk div
3042 (defun mumamo-whole-line-chunk-fw-exc-end-fun (pos max)
3043 (let ((here (point)))
3049 (defun mumamo-whole-line-chunk (pos min max marker mode)
3050 (let* ((here (point))
3051 (len-marker (length marker))
3052 (pattern (rx-to-string `(and bol (0+ blank) ,marker blank) t))
3053 (whole-line-chunk-borders-fun
3054 `(lambda (start end dummy)
3055 (let ((start-border (+ start ,len-marker)))
3056 (list start-border nil))))
3061 (setq beg (re-search-forward pattern max t))
3063 (setq beg (- beg len-marker 1))
3064 (setq end (line-end-position))
3068 (let ((start-border (+ beg len-marker)))
3069 (list start-border nil))
3071 'mumamo-whole-line-chunk-fw-exc-end-fun
3072 whole-line-chunk-borders-fun
3077 ;; (defun mumamo-single-regexp-chunk (pos min max begin-mark end-mark mode)
3078 ;; "Not ready yet. `mumamo-quick-static-chunk'"
3079 ;; (let ((here (point))
3080 ;; (len-marker (length marker))
3085 ;; (setq beg (line-beginning-position))
3086 ;; (setq end (line-end-position))
3087 ;; (unless (or (when min (< beg min))
3088 ;; (when max (> end max))
3091 ;; (skip-chars-forward " \t")
3093 ;; (string= marker (buffer-substring-no-properties (point) (+ (point) len-marker)))
3094 ;; (memq (char-after (+ (point) len-marker))
3096 ;; (>= pos (point)))
3101 ;; (let ((start-border (+ (point) len-marker)))
3102 ;; (list start-border nil))))))
3104 ;; (let ((range-regexp
3105 ;; (concat "^[ \t]*"
3107 ;; (regexp-quote marker)
3108 ;; "[ \t\n].*\\)$")))
3111 ;; (unless (= pos (line-end-position))
3112 ;; (goto-char (line-beginning-position)))
3113 ;; (setq beg (re-search-backward range-regexp min t))
3114 ;; (when beg (setq beg (match-end 1)))
3115 ;; ;; Forward, take care of indentation part
3117 ;; (unless (= pos (line-end-position))
3118 ;; (goto-char (line-beginning-position)))
3119 ;; (setq end (re-search-forward range-regexp max t))
3120 ;; (when end (setq end (match-beginning 1))))
3121 ;; (setq ret (list beg end)))
3127 (defun mumamo-chunk-mako-<%doc (pos min max)
3128 (mumamo-quick-static-chunk pos min max "<%doc>" "</%doc>" t 'mumamo-comment-mode t))
3130 (defun mumamo-chunk-mako-<%include (pos min max)
3131 (mumamo-quick-static-chunk pos min max "<%include" "/>" t 'html-mode t))
3133 (defun mumamo-chunk-mako-<%inherit (pos min max)
3134 (mumamo-quick-static-chunk pos min max "<%inherit" "/>" t 'html-mode t))
3136 (defun mumamo-chunk-mako-<%namespace (pos min max)
3137 (mumamo-quick-static-chunk pos min max "<%namespace" "/>" t 'html-mode t))
3139 (defun mumamo-chunk-mako-<%page (pos min max)
3140 (mumamo-quick-static-chunk pos min max "<%page" "/>" t 'html-mode t))
3142 ;; Fix-me: this is not correct
3143 (defun mumamo-chunk-mako-<%def (pos min max)
3144 (mumamo-quick-static-chunk pos min max "<%def" "</%def>" t 'html-mode t))
3146 (defun mumamo-chunk-mako$(pos min max)
3147 "Find ${ ... }, return range and `python-mode'.
3148 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
3149 (mumamo-quick-static-chunk pos min max "${" "}" t 'python-mode t))
3152 (define-mumamo-multi-major-mode mako-html-mumamo-mode
3153 "Turn on multiple major modes for Mako with main mode `html-mode'.
3154 This also covers inlined style and javascript."
3155 ;; Fix-me: test case
3157 ;; Fix-me: Add chunks for the tags, but make sure these are made
3158 ;; invisible to nxml-mode parser.
3160 ;; Fix-me: Maybe finally add that indentation support for one-line chunks?
3161 ("Mako HTML Family" html-mode
3163 mumamo-chunk-mako-one-line-comment
3164 mumamo-chunk-mako-<%doc
3165 mumamo-chunk-mako-<%include
3166 mumamo-chunk-mako-<%inherit
3167 mumamo-chunk-mako-<%namespace
3168 mumamo-chunk-mako-<%page
3170 mumamo-chunk-mako-<%def
3171 ;;mumamo-chunk-mako-<%namesp:name
3172 ;;mumamo-chunk-mako-<%call
3173 ;;mumamo-chunk-mako-<%text
3175 mumamo-chunk-mako-<%
3180 mumamo-chunk-inlined-style
3181 mumamo-chunk-inlined-script
3185 (mumamo-inherit-sub-chunk-family-locally 'mako-html-mumamo-mode 'mako-html-mumamo-mode)
3188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3192 (define-mumamo-multi-major-mode xsl-nxml-mumamo-mode
3193 "Turn on multi major mode for XSL with main mode `nxml-mode'.
3194 This covers inlined style and javascript."
3195 ("XSL nXtml Family" nxml-mode
3197 mumamo-chunk-inlined-style
3198 mumamo-chunk-inlined-script
3202 (define-mumamo-multi-major-mode xsl-sgml-mumamo-mode
3203 "Turn on multi major mode for XSL with main mode `sgml-mode'.
3204 This covers inlined style and javascript."
3205 ("XSL SGML Family" sgml-mode
3207 mumamo-chunk-inlined-style
3208 mumamo-chunk-inlined-script
3211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3214 (defun mumamo-chunk-markdown-html-1 (pos min max)
3217 (narrow-to-region (or min (point)) (or max (point-max)))
3219 (let ((here (point)))
3220 (when (re-search-forward (rx (* space)
3223 (or ">" (any " \t\n")))
3225 (let ((beg (match-beginning 1))
3230 (while (not (sgml-skip-tag-forward 1)))
3232 (error (message "mumamo-chunk-markdown-html-1: %s" err)))
3235 (cons beg end))))))))
3237 (defun mumamo-chunk-markdown-html-fw-exc-fun (pos max)
3238 (let ((beg-end (mumamo-chunk-markdown-html-1 pos nil max)))
3241 (defun mumamo-chunk-markdown-html (pos min max)
3242 "Find a chunk of html code in `markdown-mode'.
3243 Return range and `html-mode'.
3244 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
3245 (let ((beg-end (mumamo-chunk-markdown-html-1 pos nil max)))
3247 (let ((beg (car beg-end))
3248 (end (cdr beg-end)))
3249 (list beg end 'html-mode
3252 'mumamo-chunk-markdown-html-fw-exc-fun
3253 nil ;; find-borders fun
3257 (define-mumamo-multi-major-mode markdown-html-mumamo-mode
3258 "Turn on multi major markdown mode in buffer.
3259 Main major mode will be `markdown-mode'.
3260 Inlined html will be in `html-mode'.
3262 You need `markdown-mode' which you can download from URL
3263 `http://jblevins.org/projects/markdown-mode/'."
3264 ("Markdown HTML Family" markdown-mode
3266 mumamo-chunk-markdown-html
3271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3274 (defun mumamo-latex-closure-chunk (pos min max)
3275 (mumamo-quick-static-chunk pos min max "\\begin{clojure}" "\\end{clojure}" t 'clojure-mode t))
3278 (define-mumamo-multi-major-mode latex-clojure-mumamo-mode
3279 "Turn on multi major mode latex+clojure.
3280 Main major mode will be `latex-mode'.
3281 Subchunks will be in `clojure-mode'.
3283 You will need `clojure-mode' which you can download from URL
3284 `http://github.com/jochu/clojure-mode/tree'."
3285 ("Latex+clojur Family" latex-mode
3287 mumamo-latex-closure-chunk
3290 (add-to-list 'auto-mode-alist '("\\.lclj\\'" . latex-clojure-mumamo-mode))
3293 (defun mumamo-latex-haskell-chunk (pos min max)
3294 (mumamo-quick-static-chunk pos min max "\\begin{code}" "\\end{code}" t 'haskell-mode t))
3297 (define-mumamo-multi-major-mode latex-haskell-mumamo-mode
3298 "Turn on multi major mode latex+haskell.
3299 Main major mode will be `latex-mode'.
3300 Subchunks will be in `haskell-mode'.
3302 You will need `haskell-mode' which you can download from URL
3303 `http://projects.haskell.org/haskellmode-emacs/'."
3304 ("Latex+haskell Family" latex-mode
3306 mumamo-latex-haskell-chunk
3311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3316 (defun python-rst-long-string-chunk (pos min max)
3317 "Find Python long strings. Return range and 'mumamo-comment-mode.
3318 See `mumamo-find-possible-chunk' for POS, MIN and MAX."
3319 ;;(mumamo-quick-static-chunk pos min max "\"\"\"((" "))\"\"\"" nil 'rst-mode nil))
3320 (mumamo-quick-static-chunk pos min max "\"\"\"" "\"\"\"" t 'rst-mode t))
3323 (define-mumamo-multi-major-mode python-rst-mumamo-mode
3324 "Turn on multiple major modes for Python with RestructuredText docstrings."
3325 ("Python ReST Family" python-mode
3327 python-rst-long-string-chunk
3331 (provide 'mumamo-fun)
3332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3333 ;;; mumamo-fun.el ends here