-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmm-mako.el
180 lines (154 loc) · 4.86 KB
/
mmm-mako.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
;;; mmm-mako.el --- MMM submode class for Mako Templates
;;;
;; Copyright (C) 2007 by Philip Jenvey
;; Author: Philip Jenvey <[email protected]>
;; Version: 0.2 $Id$
;;{{{ GPL
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;}}}
;;; Commentary:
;; Parts of this code was borrowed from mmm-myghty mode. (Thanks Ben
;; Bangert and Michael Abraham Shulman)
;; Bugs -
;; mmm classes with :back delimeters of "$" (such as Mako's ## and %)
;; will carry the :back match over to the next line when <return> is
;; used to end the line (probably because the original "$" marker is
;; moved to the next line and mmm-mode doesn't automatically update
;; the match).
;;; Code:
(require 'mmm-auto)
(require 'mmm-compat)
(require 'mmm-vars)
;;{{{ Mako Tags
(defvar mmm-mako-block-tags
'("page" "include" "def" "namespace" "inherit" "call" "doc" "text"
"!"))
(defvar mmm-mako-block-tags-regexp
(mmm-regexp-opt mmm-mako-block-tags t)
"Matches any Mako tag name after the \"<%\".")
(defun mmm-mako-verify-python-block ()
(not (looking-at mmm-mako-block-tags-regexp)))
;;}}}
;;{{{ Add Classes
(mmm-add-group
'mako
`((mako-text
:submode text-mode
:face mmm-output-submode-face
:front "<%text>"
:back "</%text>"
:insert ((?t mako-<%text> nil @ "<%text>" @ "\n" _ "\n" @
"</%text>" @)))
(mako-doc
:submode text-mode
:face mmm-comment-submode-face
:front "<%doc>"
:back "</%doc>"
:insert ((?o mako-<%doc> nil @ "<%doc>" @ "\n" _ "\n" @ "</%doc>"
@)))
(mako-one-line-comment
:submode text-mode
:face mmm-comment-submode-face
:front "^[ \t]*##"
:back "$"
:insert ((?# mako-comment nil @ "##" @ " " _ @
'(mmm-mako-end-line) "\n" @)))
(mako-init
:submode python
:face mmm-init-submode-face
:front "<%!"
:back "%>"
:insert ((?! mako-<%!-%> nil @ "<%!" @ "\n" _ "\n" @ "%>" @)))
(mako-python
:submode python
:face mmm-code-submode-face
:front "<%"
:front-verify mmm-mako-verify-python-block
:back "%>"
:insert ((?% mako-<%-%> nil @ "<%" @ "\n" _ "\n" @ "%>" @)))
(mako-python-expression
:submode python
:face mmm-output-submode-face
:front "${"
:back "}"
:insert ((?$ mako-${-} nil @ "${" @ _ @ "}" @)))
(mako-control
:submode python
:face mmm-code-submode-face
:front "^[ \t]*%[^>]"
:back "$"
:insert ((tab mako-%-line nil @ "%" @ " " _ @
'(mmm-mako-end-line) "\n" @)))
(mako-def
:submode python
:face mmm-declaration-submode-face
:front "<%def[ \t]+name=\\([\"']\\)"
:save-matches 1
:back "~1[ \t]*>"
:insert ((?d mako-<%def> nil @ "<%def name=\"" @ _ "()" @ "\">" @
"\n</%def>")))
(mako-call
:submode python
:face mmm-output-submode-face
:front "<%call[ \t]+expr=\\([\"']\\)"
:save-matches 1
:back "~1[ \t]*>"
:insert ((?c mako-<%call> nil @ "<%call expr=\"" @ _ "()" @ "\">"
@ "\n</%call>")))
(mako-page
:submode python
:face mmm-declaration-submode-face
:front "<%page[ \t]+"
:back "/>"
:insert ((?p mako-<%page> nil @ "<%page " @ _ @ "/>" @)))
(mako-include
:submode text-mode
:face mmm-output-submode-face
:front "<%include[ \t]+file=\\([\"']\\)"
:save-matches 1
:back "~1[ \t]*/>"
:insert ((?u mako-<%include> nil @ "<%include file=\"" @ _ @
"\"/>" @)))
(mako-namespace
:submode text-mode
:face mmm-special-submode-face
:front "<%namespace[ \t]+"
:back "[ \t]*/>"
:insert ((?n mako-<%namespace> nil @ "<%namespace " @ _ @ "/>"
@)))
(mako-inherit
:submode text-mode
:face mmm-init-submode-face
:front "<%inherit[ \t]+file=\\([\"']\\)"
:save-matches 1
:back "~1[ \t]*/>"
:insert ((?i mako-<%inherit> nil @ "<%inherit file=\"" @ _ @
"\"/>" @)))))
;;}}}
;;{{{ One-line Sections
(defun mmm-mako-start-line ()
(if (bolp)
""
"\n"))
(defun mmm-mako-end-line ()
(if (eolp)
(delete-char 1)))
;;}}}
;;{{{ Set Mode Line
(defun mmm-mako-set-mode-line ()
(setq mmm-buffer-mode-display-name "Mako"))
(add-hook 'mmm-mako-class-hook 'mmm-mako-set-mode-line)
;;}}}
(provide 'mmm-mako)
;;; mmm-mako.el ends here