commit
1e9841055e
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:
|
2009/05/05:
|
||||||
|
|
||||||
Either give buffers direct access to the application object, or make the
|
Either give buffers direct access to the application object, or make the
|
||||||
|
|
|
@ -405,10 +405,12 @@ class Application(object):
|
||||||
return self.mini_buffer is not None
|
return self.mini_buffer is not None
|
||||||
def open_mini_buffer(self, prompt, cb, method=None, tabber=None,
|
def open_mini_buffer(self, prompt, cb, method=None, tabber=None,
|
||||||
modename=None, startvalue=None, queue='default'):
|
modename=None, startvalue=None, queue='default'):
|
||||||
|
parentw = self.bufferlist.slots[self.active_slot].window
|
||||||
if self.mini_buffer_is_open():
|
if self.mini_buffer_is_open():
|
||||||
self.close_mini_buffer()
|
self.close_mini_buffer()
|
||||||
self.mini_prompt = prompt
|
self.mini_prompt = prompt
|
||||||
self.mini_buffer = MiniBuffer(cb, self, method, tabber, modename, queue)
|
self.mini_buffer = MiniBuffer(cb, self, method, tabber, modename, queue,
|
||||||
|
parentw)
|
||||||
try:
|
try:
|
||||||
w = self.x - 1 - len(self.mini_prompt) - 1
|
w = self.x - 1 - len(self.mini_prompt) - 1
|
||||||
window.Window(self.mini_buffer, self, height=1, width=w)
|
window.Window(self.mini_buffer, self, height=1, width=w)
|
||||||
|
|
|
@ -685,14 +685,14 @@ class FileBuffer(Buffer):
|
||||||
try:
|
try:
|
||||||
data = self.make_string()
|
data = self.make_string()
|
||||||
if self.windows[0].mode.savetabs:
|
if self.windows[0].mode.savetabs:
|
||||||
data = data.replace(" ", "\t").encode(self.codec)
|
data = data.replace(" ", "\t")
|
||||||
|
data = self.write_filter(data.encode(self.codec))
|
||||||
data = self.write_filter(data)
|
|
||||||
|
|
||||||
f2 = self._open_file_w(self.path, preserve=False)
|
f2 = self._open_file_w(self.path, preserve=False)
|
||||||
f2.write(self.bytemark + data)
|
f2.write(self.bytemark + data)
|
||||||
f2.close()
|
f2.close()
|
||||||
except Exception, e:
|
#except Exception, e:
|
||||||
|
except NameError, e:
|
||||||
if exists: shutil.copyfile(temp_path, self.path)
|
if exists: shutil.copyfile(temp_path, self.path)
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -159,7 +159,9 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
self._towrite = self._towrite[n:]
|
self._towrite = self._towrite[n:]
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
if efd:
|
if efd:
|
||||||
raise Exception, "exception is ready: %s" % repr(efd)
|
self.term_receive(repr(efd))
|
||||||
|
#raise Exception, "exception is ready: %s" % repr(efd)
|
||||||
|
pass
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MiniBuffer(buffer.Buffer):
|
||||||
return mini
|
return mini
|
||||||
# the callback function should take one argument (window)
|
# the callback function should take one argument (window)
|
||||||
def __init__(self, func, app, method=None, tabber=None, modename=None,
|
def __init__(self, func, app, method=None, tabber=None, modename=None,
|
||||||
queue=None):
|
queue=None, parentw=None):
|
||||||
buffer.Buffer.__init__(self)
|
buffer.Buffer.__init__(self)
|
||||||
self.app = app
|
self.app = app
|
||||||
self.callback = func
|
self.callback = func
|
||||||
|
@ -22,6 +22,7 @@ class MiniBuffer(buffer.Buffer):
|
||||||
self.tabber = tabber
|
self.tabber = tabber
|
||||||
self.modename = modename
|
self.modename = modename
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
|
self.parentw = parentw
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "*Minibuffer*"
|
return "*Minibuffer*"
|
||||||
|
|
|
@ -93,11 +93,12 @@ class ConsoleCancel(Method):
|
||||||
w.application.close_completion_buffer()
|
w.application.close_completion_buffer()
|
||||||
class ConsoleClear(Method):
|
class ConsoleClear(Method):
|
||||||
def execute(self, w, **vargs):
|
def execute(self, w, **vargs):
|
||||||
a = w.application
|
#a = w.application
|
||||||
if not a.has_buffer_name('*Console*'):
|
#if not a.has_buffer_name('*Console*'):
|
||||||
raise Exception, "No console found!"
|
# raise Exception, "No console found!"
|
||||||
b = a.bufferlist.get_buffer_by_name('*Console*')
|
#b = a.bufferlist.get_buffer_by_name('*Console*')
|
||||||
b.clear()
|
#b.clear()
|
||||||
|
w.buffer.parentw.buffer.clear()
|
||||||
|
|
||||||
class ConsoleHistoryPrev(Method):
|
class ConsoleHistoryPrev(Method):
|
||||||
def execute(self, w, **vargs):
|
def execute(self, w, **vargs):
|
||||||
|
|
|
@ -17,7 +17,7 @@ rules = [
|
||||||
]
|
]
|
||||||
|
|
||||||
class HeaderGrammar(Grammar):
|
class HeaderGrammar(Grammar):
|
||||||
rules = [PatternRule('header', '^[^ ].*:')] + rules
|
rules = [PatternRule('header', '^[^ ][^:]*:')] + rules
|
||||||
class BodyGrammar(Grammar): rules = rules
|
class BodyGrammar(Grammar): rules = rules
|
||||||
class MuttGrammar(Grammar):
|
class MuttGrammar(Grammar):
|
||||||
rules = [RegionRule('mutt', '^', HeaderGrammar, '^\n$', BodyGrammar, '')]
|
rules = [RegionRule('mutt', '^', HeaderGrammar, '^\n$', BodyGrammar, '')]
|
||||||
|
|
|
@ -698,7 +698,8 @@ class PerlContext(context.Context):
|
||||||
class Perl(Fundamental):
|
class Perl(Fundamental):
|
||||||
name = 'Perl'
|
name = 'Perl'
|
||||||
extensions = ['.pl', '.pm', '.pod']
|
extensions = ['.pl', '.pm', '.pod']
|
||||||
detection = ['perl']
|
#detection = ['perl']
|
||||||
|
detection = [re.compile('^#!(?:.+/)?perl')]
|
||||||
tabbercls = PerlTabber2
|
tabbercls = PerlTabber2
|
||||||
grammar = PerlGrammar
|
grammar = PerlGrammar
|
||||||
commentc = '#'
|
commentc = '#'
|
||||||
|
|
|
@ -61,7 +61,7 @@ class PythonGrammar(Grammar):
|
||||||
RegionRule('string', 'u?"', StringGrammar2, '"'),
|
RegionRule('string', 'u?"', StringGrammar2, '"'),
|
||||||
RegionRule('string', "u?'", StringGrammar1, "'"),
|
RegionRule('string', "u?'", StringGrammar1, "'"),
|
||||||
|
|
||||||
PatternRule('delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='),
|
PatternRule('delimiter', r'\(|\)|\[|\]|{|}|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='),
|
||||||
PatternRule(r"python.integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
|
PatternRule(r"python.integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
|
||||||
PatternRule(r"python.float", r"(?<![\.0-9a-zA-Z_])(?:-?[0-9]+\.[0-9]*|-?\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|-?\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
|
PatternRule(r"python.float", r"(?<![\.0-9a-zA-Z_])(?:-?[0-9]+\.[0-9]*|-?\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|-?\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
|
||||||
PatternRule(r"python.imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
|
PatternRule(r"python.imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
|
||||||
|
@ -71,7 +71,7 @@ class PythonGrammar(Grammar):
|
||||||
OverridePatternRule('comment', '#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
OverridePatternRule('comment', '#@@:(?P<token>[.a-zA-Z0-9_]+):(?P<mode>[.a-zA-Z0-9_]+) *$'),
|
||||||
PatternRule('comment', '#.*$'),
|
PatternRule('comment', '#.*$'),
|
||||||
PatternRule('continuation', r'\\\n$'),
|
PatternRule('continuation', r'\\\n$'),
|
||||||
PatternRule('decorator', '@[a-zA-Z_][a-zA-Z0-9_]*'),
|
PatternRule('python.decorator', '@[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule('spaces', ' +'),
|
PatternRule('spaces', ' +'),
|
||||||
PatternRule('eol', r'\n$'),
|
PatternRule('eol', r'\n$'),
|
||||||
]
|
]
|
||||||
|
@ -335,7 +335,8 @@ class PythonSemanticComplete(method.introspect.TokenComplete):
|
||||||
a = w.application
|
a = w.application
|
||||||
a.methods['ipython-path-start'].execute(w, switch=False)
|
a.methods['ipython-path-start'].execute(w, switch=False)
|
||||||
|
|
||||||
name = buffer.IperlBuffer.create_name(w.buffer)
|
#name = buffer.IperlBuffer.create_name(w.buffer)
|
||||||
|
name = buffer.IpythonBuffer.create_name(w.buffer)
|
||||||
b = a.get_buffer_by_name(name)
|
b = a.get_buffer_by_name(name)
|
||||||
|
|
||||||
line = w.buffer.lines[t.y]
|
line = w.buffer.lines[t.y]
|
||||||
|
@ -560,7 +561,8 @@ class Python(mode.Fundamental):
|
||||||
'''
|
'''
|
||||||
name = 'Python'
|
name = 'Python'
|
||||||
extensions = ['.py']
|
extensions = ['.py']
|
||||||
detection = ['python']
|
#detection = ['python']
|
||||||
|
detection = [re.compile('^#!(?:.+/)python')]
|
||||||
tabbercls = PythonTabber
|
tabbercls = PythonTabber
|
||||||
grammar = PythonGrammar
|
grammar = PythonGrammar
|
||||||
opentokens = ('delimiter',)
|
opentokens = ('delimiter',)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import re
|
||||||
|
|
||||||
import commands
|
import commands
|
||||||
from tab import StackTabber
|
from tab import StackTabber
|
||||||
from mode import Fundamental
|
from mode import Fundamental
|
||||||
|
@ -190,7 +192,8 @@ class Sh(Fundamental):
|
||||||
paths = ['/etc/profile']
|
paths = ['/etc/profile']
|
||||||
basenames = ['.bashrc', '.bash_profile', '.profile']
|
basenames = ['.bashrc', '.bash_profile', '.profile']
|
||||||
extensions = ['.bash', '.sh']
|
extensions = ['.bash', '.sh']
|
||||||
detection = ['sh', 'bash']
|
#detection = ['sh', 'bash']
|
||||||
|
detection = [re.compile('^#!(?:.+/)sh'), re.compile('^#!(?:.+/)bash')]
|
||||||
grammar = ShGrammar
|
grammar = ShGrammar
|
||||||
tabbercls = ShTabber
|
tabbercls = ShTabber
|
||||||
opentokens = ('delimiter', 'sh_reserved', 'case.start')
|
opentokens = ('delimiter', 'sh_reserved', 'case.start')
|
||||||
|
|
63
mode/xml.py
63
mode/xml.py
|
@ -1,50 +1,55 @@
|
||||||
|
import re
|
||||||
|
|
||||||
import color, method, mode
|
import color, method, mode
|
||||||
from lex import Grammar, Rule, PatternRule, RegionRule, PatternMatchRule
|
from lex import Grammar, Rule, PatternRule, RegionRule, PatternMatchRule
|
||||||
|
|
||||||
class StringGrammar1(Grammar):
|
class StringGrammar1(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'data', r'[^"&]+'),
|
PatternRule('data', '[^"&]+'),
|
||||||
PatternRule(r'escaped', r'&[a-z]+;'),
|
PatternRule('escaped', '&[a-z]+;'),
|
||||||
]
|
]
|
||||||
class StringGrammar2(Grammar):
|
class StringGrammar2(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'data', r"[^'&]+"),
|
PatternRule('data', r"[^'&]+"),
|
||||||
PatternRule(r'escaped', r'&[a-z]+;'),
|
PatternRule('escaped', '&[a-z]+;'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class CDataGrammar(Grammar):
|
class CDataGrammar(Grammar):
|
||||||
rules = [PatternRule(r'data', r'(?:[^\]]|\](?!\])|\]\](?!>))+')]
|
rules = [PatternRule('data', r'(?:[^\]]|\](?!\])|\]\](?!>))+')]
|
||||||
class CommentGrammar(Grammar):
|
class CommentGrammar(Grammar):
|
||||||
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
|
rules = [PatternRule('data', '(?:[^-]|-(?!-)|--(?!>))+')]
|
||||||
class MetadataGrammar(Grammar):
|
|
||||||
rules = [PatternRule(r'data', r'(?:[^?]|\?(?!>))+')]
|
|
||||||
|
|
||||||
class TagGrammar(Grammar):
|
class TagGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
PatternRule('attrname', '[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||||
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
|
PatternRule('namespace', '[a-zA-Z_]+(?=:)'),
|
||||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
PatternRule('name', '[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule(r'delimiter', r'[:/=]'),
|
PatternRule('delimiter', '[:/=]'),
|
||||||
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
RegionRule('string', '"', StringGrammar1, '"'),
|
||||||
RegionRule(r'string', r"'", StringGrammar2, r"'"),
|
RegionRule('string', "'", StringGrammar2, "'"),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule('spaces', ' +'),
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule('eol', r'\n'),
|
||||||
]
|
]
|
||||||
|
class MetadataGrammar(Grammar):
|
||||||
|
rules = [PatternRule('meta', r'\?(?:xml)?')] + TagGrammar.rules
|
||||||
|
class DoctypeGrammar(Grammar):
|
||||||
|
rules = [PatternRule('doctype', '!DOCTYPE')] + TagGrammar.rules
|
||||||
|
|
||||||
class XMLGrammar(Grammar):
|
class XMLGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
# TODO: how does cdata work again?
|
# TODO: how does cdata work again?
|
||||||
PatternRule(r'data', r'[^<& \n]+'),
|
PatternRule('data', r'[^<& \n]+'),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule('spaces', ' +'),
|
||||||
PatternRule(r'xml.entity', r'&[a-z]+;'),
|
PatternRule('xml.entity', '&[a-z]+;'),
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule('eol', r'\n'),
|
||||||
PatternMatchRule('x', r'(<)(/)([a-zA-Z_][a-zA-Z0-9_]*)(>)',
|
PatternMatchRule('x', '(<)(/)([a-zA-Z_][a-zA-Z0-9_]*)(>)',
|
||||||
'xml.tag.start', 'xml.tag.delimiter', 'xml.tag.name',
|
'xml.tag.start', 'xml.tag.delimiter', 'xml.tag.name',
|
||||||
'xml.tag.end'),
|
'xml.tag.end'),
|
||||||
RegionRule(r'xml.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
|
RegionRule('xml.tag', r'<(?![\?!])', TagGrammar, '/?>'),
|
||||||
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
|
RegionRule('xml.tag', r'<(?![\?!])', TagGrammar, '/?>'),
|
||||||
RegionRule(r'xml.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
RegionRule('comment', '<!--', CommentGrammar, '-->'),
|
||||||
RegionRule(r'xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
RegionRule('xml.tag', r'<(?=\?)', MetadataGrammar, r'\?>'),
|
||||||
|
RegionRule('xml.tag', '<(?!!)', DoctypeGrammar, '>'),
|
||||||
|
RegionRule('xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class XmlValidate(method.shell.Exec):
|
class XmlValidate(method.shell.Exec):
|
||||||
|
@ -84,11 +89,11 @@ class XmlCreateCdata(method.Method):
|
||||||
class XML(mode.Fundamental):
|
class XML(mode.Fundamental):
|
||||||
name = 'XML'
|
name = 'XML'
|
||||||
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
||||||
|
detection = [re.compile(r'^<\?xml')]
|
||||||
grammar = XMLGrammar
|
grammar = XMLGrammar
|
||||||
colors = {
|
colors = {
|
||||||
'xml.metadata.start': ('magenta', 'default', 'bold'),
|
'xml.tag.meta': ('magenta', 'default', 'bold'),
|
||||||
'xml.metadata.data': ('magenta', 'default', 'bold'),
|
'xml.tag.doctype': ('magenta', 'default', 'bold'),
|
||||||
'xml.metadata.end': ('magenta', 'default', 'bold'),
|
|
||||||
'xml.tag.start': ('default', 'default', 'bold'),
|
'xml.tag.start': ('default', 'default', 'bold'),
|
||||||
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||||
'xml.tag.name': ('blue', 'default', 'bold'),
|
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||||
|
|
10
window.py
10
window.py
|
@ -64,11 +64,11 @@ class Window(object):
|
||||||
mode_name = regex.auto_mode_emacs.search(firstline).group(1)
|
mode_name = regex.auto_mode_emacs.search(firstline).group(1)
|
||||||
elif regex.auto_mode_vi.search(firstline):
|
elif regex.auto_mode_vi.search(firstline):
|
||||||
mode_name = regex.auto_mode_vi.search(firstline).group(1)
|
mode_name = regex.auto_mode_vi.search(firstline).group(1)
|
||||||
elif firstline.startswith('#!'):
|
else:
|
||||||
line = b.lines[0]
|
for (r, name) in a.mode_detection.items():
|
||||||
for word in a.mode_detection:
|
if r.match(b.lines[0]):
|
||||||
if word in line:
|
mode_name = name
|
||||||
mode_name = a.mode_detection[word]
|
break
|
||||||
|
|
||||||
cls = a.modes.get(mode_name, a.modes['fundamental'])
|
cls = a.modes.get(mode_name, a.modes['fundamental'])
|
||||||
self.set_mode(cls(self))
|
self.set_mode(cls(self))
|
||||||
|
|
Loading…
Reference in New Issue