expand mode-detection beyond #! to <?xml>
--HG-- branch : pmacs2
This commit is contained in:
parent
f274cdd973
commit
a098646d42
5
IDEAS
5
IDEAS
|
@ -1,3 +1,8 @@
|
|||
2009/07/11:
|
||||
|
||||
Redo mode detection so that it uses regexes not words. Then fix all the modes
|
||||
that want #! detection.
|
||||
|
||||
2009/05/05:
|
||||
|
||||
Either give buffers direct access to the application object, or make the
|
||||
|
|
42
mode/xml.py
42
mode/xml.py
|
@ -18,11 +18,15 @@ class CommentGrammar(Grammar):
|
|||
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
|
||||
class MetadataGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'(?:[^?]|\?(?!>))+')]
|
||||
class DoctypeGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'[^>]+')]
|
||||
|
||||
class TagGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
|
||||
PatternRule(r'meta', r'\?xml'),
|
||||
PatternRule(r'doctype', r'!DOCTYPE'),
|
||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule(r'delimiter', r'[:/=]'),
|
||||
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
||||
|
@ -41,9 +45,11 @@ class XMLGrammar(Grammar):
|
|||
PatternMatchRule('x', r'(<)(/)([a-zA-Z_][a-zA-Z0-9_]*)(>)',
|
||||
'xml.tag.start', 'xml.tag.delimiter', 'xml.tag.name',
|
||||
'xml.tag.end'),
|
||||
RegionRule(r'xml.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
|
||||
#RegionRule(r'xml.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
|
||||
RegionRule(r'xml.tag', r'<', TagGrammar, r'/?>'),
|
||||
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
|
||||
RegionRule(r'xml.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
||||
#RegionRule(r'xml.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
||||
#RegionRule(r'xml.doctype', '<!', DoctypeGrammar, '>'),
|
||||
RegionRule(r'xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
||||
]
|
||||
|
||||
|
@ -84,20 +90,28 @@ class XmlCreateCdata(method.Method):
|
|||
class XML(mode.Fundamental):
|
||||
name = 'XML'
|
||||
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
||||
detection = ['?xml']
|
||||
grammar = XMLGrammar
|
||||
colors = {
|
||||
'xml.metadata.start': ('magenta', 'default', 'bold'),
|
||||
'xml.metadata.data': ('magenta', 'default', 'bold'),
|
||||
'xml.metadata.end': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.start': ('default', 'default', 'bold'),
|
||||
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||
'xml.tag.attrname': ('cyan', 'default', 'bold'),
|
||||
'xml.tag.end': ('default', 'default', 'bold'),
|
||||
'xml.entity': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.start': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.data': ('green', 'default', 'bold'),
|
||||
'xml.cdata.end': ('magenta', 'default', 'bold'),
|
||||
#'xml.metadata.start': ('magenta', 'default', 'bold'),
|
||||
#'xml.metadata.data': ('magenta', 'default', 'bold'),
|
||||
#'xml.metadata.end': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.start': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.data': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.end': ('magenta', 'default', 'bold'),
|
||||
|
||||
'xml.tag.meta': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.doctype': ('magenta', 'default', 'bold'),
|
||||
|
||||
'xml.tag.start': ('default', 'default', 'bold'),
|
||||
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||
'xml.tag.attrname': ('cyan', 'default', 'bold'),
|
||||
'xml.tag.end': ('default', 'default', 'bold'),
|
||||
'xml.entity': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.start': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.data': ('green', 'default', 'bold'),
|
||||
'xml.cdata.end': ('magenta', 'default', 'bold'),
|
||||
}
|
||||
actions = [XmlValidate, XmlCreateTag, XmlCreateComment, XmlCreateCdata]
|
||||
_bindings = {
|
||||
|
|
|
@ -64,7 +64,7 @@ class Window(object):
|
|||
mode_name = regex.auto_mode_emacs.search(firstline).group(1)
|
||||
elif regex.auto_mode_vi.search(firstline):
|
||||
mode_name = regex.auto_mode_vi.search(firstline).group(1)
|
||||
elif firstline.startswith('#!'):
|
||||
else:
|
||||
line = b.lines[0]
|
||||
for word in a.mode_detection:
|
||||
if word in line:
|
||||
|
|
Loading…
Reference in New Issue