Initial Commit
[packages] / xemacs-packages / mmm-mode / mmm-mason.el
1 ;;; mmm-mason.el --- MMM submode class for Mason components
2
3 ;; Copyright (C) 2000 by Michael Abraham Shulman
4
5 ;; Author: Michael Abraham Shulman <viritrilbia@users.sourceforge.net>
6 ;; Version: $Id: mmm-mason.el,v 1.2 2008-12-22 14:02:24 mharnisch Exp $
7
8 ;;{{{ GPL
9
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;}}}
26
27 ;;; Commentary:
28
29 ;; This file contains the definition of an MMM Mode submode class for
30 ;; editing Mason components.  See the file README.Mason for more
31 ;; details.
32
33 ;;; Code:
34
35 (require 'mmm-compat)
36 (require 'mmm-vars)
37 (require 'mmm-auto)
38
39 ;;{{{ Perl Tags
40
41 (defvar mmm-mason-perl-tags
42   '("perl" "init" "cleanup" "once" "filter" "shared"
43     "perl_init" "perl_cleanup" "perl_once" "perl_filter"))
44
45 (defvar mmm-mason-pseudo-perl-tags
46   '("args" "perl_args" "attr" "flags"))
47
48 (defvar mmm-mason-non-perl-tags
49   '("doc" "perl_doc" "text" "perl_text" "def" "perl_def" "method"))
50
51 (defvar mmm-mason-perl-tags-regexp
52   (concat "<%" (mmm-regexp-opt mmm-mason-perl-tags t) ">")
53   "Matches tags beginning Mason sections containing Perl code.
54 Saves the name of the tag matched.")
55
56 (defvar mmm-mason-pseudo-perl-tags-regexp
57   (concat "<%" (mmm-regexp-opt mmm-mason-pseudo-perl-tags t) ">")
58   "Match tags beginning Mason sections that look like Perl but aren't.
59 Saves the name of the tag matched.")
60
61 (defvar mmm-mason-tag-names-regexp
62   (regexp-opt (append mmm-mason-perl-tags mmm-mason-non-perl-tags) t)
63   "Matches any Mason tag name after the \"<%\". Used to verify that a
64 \"<%\" sequence starts an inline section.")
65
66 (defun mmm-mason-verify-inline ()
67   (not (looking-at mmm-mason-tag-names-regexp)))
68
69 ;;}}}
70 ;;{{{ Add Classes
71
72 (mmm-add-group
73  'mason
74  `((mason-text
75     :submode nil
76     :front "<%text>"
77     :back "</%text>"
78     :insert ((?t mason-<%text> nil @ "<%text>" @ "\n"
79                  _ "\n" @ "</%text>" @)))
80    (mason-doc
81     :submode text-mode
82     :face mmm-comment-submode-face
83     :front "<%doc>"
84     :back "</%doc>"
85     :face nil
86     :insert ((?d mason-<%doc> nil @ "<%doc>" @ "\n"
87                  _ "\n" @ "</%doc>" @)))
88    (mason-perl
89     :submode perl
90     :match-face (("<%perl>" . mmm-code-submode-face)
91                  ("<%init>" . mmm-init-submode-face)
92                  ("<%cleanup>" . mmm-cleanup-submode-face)
93                  ("<%once>" . mmm-init-submode-face)
94                  ("<%filter>" . mmm-special-submode-face)
95                  ("<%shared>" . mmm-init-submode-face))
96     :front ,mmm-mason-perl-tags-regexp
97     :back "</%~1>"
98     :save-matches 1
99     :match-name "~1"
100     :save-name 1
101     :insert ((?, mason-<%TAG> "Perl section: " @ "<%" str ">" @
102                  ";\n" _ "\n" @ "</%" str ">" @)
103              (?< mason-<%TAG> ?, . nil)
104              (?p mason-<%perl> ?, . "perl")
105              (?i mason-<%init> ?, . "init")
106              (?c mason-<%cleanup> ?, . "cleanup")
107              (?o mason-<%once> ?, . "once")
108              (?l mason-<%filter> ?, . "filter")
109              (?s mason-<%shared> ?, . "shared")))
110    (mason-pseudo-perl
111     :submode perl
112     :face mmm-declaration-submode-face
113     :front ,mmm-mason-pseudo-perl-tags-regexp
114     :back "</%~1>"
115     :save-matches 1
116     :insert ((?. mason-pseudo-<%TAG> "Pseudo-perl section: " @ "<%" str ">" @
117                  "\n" _ "\n" @ "</%" str ">" @)
118              (?> mason-pseudo-<%TAG> ?, . nil)
119              (?a mason-<%args> ?. . "args")
120              (?f mason-<%flags> ?. . "flags")
121              (?r mason-<%attr> ?. . "attr")))
122    (mason-inline
123     :submode perl
124     :face mmm-output-submode-face
125     :front "<%"
126     :front-verify mmm-mason-verify-inline
127     :back "%>"
128     :insert ((?% mason-<%-%> nil @ "<%" @ " " _ " " @ "%>" @)
129              (?5 mason-<%-%> ?% . nil)))
130    (mason-call
131     :submode perl
132     :face mmm-special-submode-face
133     :front "<&"
134     :back "&>"
135     :insert ((?& mason-<&-&> nil @ "<&" @ " " _ " " @ "&>" @)
136              (?7 mason-<&-&> ?% . nil)))
137    (mason-one-line-comment
138     :submode text-mode
139     :face mmm-comment-submode-face
140     :front "^%#"
141     :back "\n"
142     :insert ((?# mason-%-comment nil (mmm-mason-start-line)
143                 @ "%" @ "# " _ @ '(mmm-mason-end-line) "\n" @)
144              (?3 mason-%-comment ?# . nil)))
145    (mason-one-line
146     :submode perl
147     :face mmm-code-submode-face
148     :front "^%"
149     :back "\n"
150     :insert ((return mason-%-line nil (mmm-mason-start-line)
151                      @ "%" @ " " _ @ '(mmm-mason-end-line) "\n" @)))))
152
153 ;;}}}
154 ;;{{{ One-line Sections
155
156 (defun mmm-mason-start-line ()
157   (if (bolp)
158       ""
159     "\n"))
160
161 (defun mmm-mason-end-line ()
162   (if (eolp)
163       (delete-char 1)))
164
165 ;;}}}
166 ;;{{{ Set Mode Line
167
168 (defun mmm-mason-set-mode-line ()
169   (setq mmm-buffer-mode-display-name "Mason"))
170 (add-hook 'mmm-mason-class-hook 'mmm-mason-set-mode-line)
171
172 ;;}}}
173
174 (provide 'mmm-mason)
175
176 ;;; mmm-mason.el ends here