mode refactor

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-19 03:32:08 +00:00
parent 4c0f08a913
commit 815adf18fc
29 changed files with 721 additions and 819 deletions

View File

@ -1,6 +1,6 @@
int main() {
while(1 < 2) {
pritf("hola\n"):
pritf("hola\n");
}
if(1 == 2)

View File

@ -87,7 +87,7 @@ class Fundamental(Handler):
tabber = None
colors = {}
config = {}
methods = []
actions = []
# margin/line numbering
show_line_numbers = False
@ -106,7 +106,7 @@ class Fundamental(Handler):
app.token_colors[key] = val
for (key, val) in cls.config.iteritems():
app.config[key] = val
for mcls in cls.methods:
for mcls in cls.actions:
m = mcls()
if m.name in app.methods:
return

View File

@ -22,31 +22,6 @@ class BDSGrammar(Grammar):
PatternRule(r'bds_operator', r'(?:&gt;=|&lt;=|&gt;|&lt;|==|&amp;&amp;|\|\||eq|ne)'),
]
class BDS(mode.Fundamental):
modename = 'BDS'
basenames = ['components.xml']
grammar = BDSGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'bds_derived': ('yellow', 'default'),
'bds_question': ('yellow', 'default'),
'bds_misquoted': ('yellow', 'red'),
'bds_function': ('magenta', 'default'),
'bds_perlfunc': ('magenta', 'default'),
'bds_operator': ('magenta', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_action(BDSMakeInstall())
self.add_action(BDSCompileResources())
self.add_action(BDSRestart())
class BDSMakeInstall(Method):
def _execute(self, w, **vargs):
cmd = "perl Makefile.PL && make && make install"
@ -63,4 +38,27 @@ class BDSRestart(Method):
def _execute(self, w, **vargs):
pass
class BDS(mode.Fundamental):
modename = 'BDS'
basenames = ['components.xml']
grammar = BDSGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'bds_derived': ('yellow', 'default'),
'bds_question': ('yellow', 'default'),
'bds_misquoted': ('yellow', 'red'),
'bds_function': ('magenta', 'default'),
'bds_perlfunc': ('magenta', 'default'),
'bds_operator': ('magenta', 'default'),
}
actions = [BDSMakeInstall, BDSCompileResources, BDSRestart]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
install = BDS.install

View File

@ -177,6 +177,32 @@ class CTabber(tab.StackTabber):
self._opt_append('cont', currlvl + w)
return currlvl
class CCheckSyntax(method.shell.Exec):
'''Build this C program (using the mode's make cmd)'''
show_success = False
args = []
def _execute(self, w, **vargs):
if w.application.config['c.syntax-rel-dir']:
d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax')
class CMake(method.shell.Exec):
'''Build this C program (using the mode's make cmd)'''
show_success = False
args = []
def _execute(self, w, **vargs):
if w.application.config['c.make-rel-dir']:
d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make')
class C(mode.Fundamental):
modename = 'C'
extensions = ['.c']
@ -216,38 +242,13 @@ class C(mode.Fundamental):
'c.make-cmd': "make",
'c.make-rel-dir': True,
}
actions = [CCheckSyntax, CMake]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_action_and_bindings(CCheckSyntax(), ('C-c s',))
self.add_action_and_bindings(CMake(), ('C-c C-c',))
class CCheckSyntax(method.shell.Exec):
'''Build this C program (using the mode's make cmd)'''
show_success = False
args = []
def _execute(self, w, **vargs):
if w.application.config['c.syntax-rel-dir']:
d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.syntax-cmd'],
cmdname='c-check-syntax')
class CMake(method.shell.Exec):
'''Build this C program (using the mode's make cmd)'''
show_success = False
args = []
def _execute(self, w, **vargs):
if w.application.config['c.make-rel-dir']:
d = os.path.dirname(w.buffer.path)
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make', cmddir=d)
else:
self._doit(w, w.buffer.path, w.application.config['c.make-cmd'],
cmdname='c-make')
self.add_bindings('c-check-syntax', ('C-c s',))
self.add_bindings('c-make', ('C-c C-c',))
install = C.install

View File

@ -4,54 +4,6 @@ from lex import Grammar, PatternRule
from mode.python import PythonGrammar
from point import Point
class ConsoleMini(mode.Fundamental):
modename = 'ConsoleMini'
grammar = PythonGrammar
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
self.globals = dict(w.application.globals())
self.locals = dict(w.application.locals())
self.saved_input = ""
self.history = ['']
self.hindex = 0
self.add_bindings('start-of-line', ('C-a', 'HOME',))
self.add_bindings('end-of-line', ('C-e', 'END',))
self.add_bindings('backward', ('C-b', 'L_ARROW',))
self.add_bindings('forward', ('C-f', 'R_ARROW',))
self.add_bindings('delete-left', ('DELETE', 'BACKSPACE',))
self.add_bindings('delete-left-word', ('M-DELETE', 'M-BACKSPACE',))
self.add_bindings('delete-right', ('C-d',))
self.add_bindings('delete-right-word', ('M-d',))
self.add_bindings('kill-region', ('C-w',))
self.add_bindings('copy-region', ('M-w',))
self.add_bindings('kill', ('C-k',))
self.add_bindings('copy', ('M-k',))
self.add_bindings('yank', ('C-y',))
self.add_bindings('pop-kill', ('M-y',))
self.add_bindings('right-word', ('M-f',))
self.add_bindings('left-word', ('M-b',))
self.add_bindings('set-mark', ('C-@',))
self.add_bindings('switch-mark', ('C-x C-x',))
self.add_bindings('undo', ('C-/', 'C-x u',))
self.add_bindings('redo', ('M-/', 'M-_', 'C-x r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('transpose-words', ('M-t',))
self.add_bindings('delete-left-whitespace', ('C-c DELETE', 'C-c BACKSPACE',))
self.add_bindings('delete-right-whitespace', ('C-c d',))
self.add_bindings('insert-space', ('SPACE',))
self.add_bindings('insert-tab', ('TAB',))
self.add_action_and_bindings(ConsoleExec(), ('RETURN',))
self.add_action_and_bindings(ConsoleClear(), ('C-l',))
self.add_action_and_bindings(ConsoleCancel(), ('C-]',))
self.add_action_and_bindings(ConsoleHistoryPrev(), ('C-p',))
self.add_action_and_bindings(ConsoleHistoryNext(), ('C-n',))
self.add_action_and_bindings(ConsoleTab(), ('TAB',))
for c in string.letters + string.digits + string.punctuation:
self.add_binding('insert-string-%s' % c, c)
class ConsoleExec(method.Method):
def _execute(self, w, **vargs):
s = w.buffer.make_string()
@ -211,4 +163,54 @@ class ConsoleTab(method.Method):
s = candidates[0][len(name):]
w.insert_string_at_cursor(s)
class ConsoleMini(mode.Fundamental):
modename = 'ConsoleMini'
grammar = PythonGrammar
actions = [ConsoleExec, ConsoleClear, ConsoleCancel, ConsoleHistoryPrev,
ConsoleHistoryNext, ConsoleTab]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
self.globals = dict(w.application.globals())
self.locals = dict(w.application.locals())
self.saved_input = ""
self.history = ['']
self.hindex = 0
self.add_bindings('start-of-line', ('C-a', 'HOME',))
self.add_bindings('end-of-line', ('C-e', 'END',))
self.add_bindings('backward', ('C-b', 'L_ARROW',))
self.add_bindings('forward', ('C-f', 'R_ARROW',))
self.add_bindings('delete-left', ('DELETE', 'BACKSPACE',))
self.add_bindings('delete-left-word', ('M-DELETE', 'M-BACKSPACE',))
self.add_bindings('delete-right', ('C-d',))
self.add_bindings('delete-right-word', ('M-d',))
self.add_bindings('kill-region', ('C-w',))
self.add_bindings('copy-region', ('M-w',))
self.add_bindings('kill', ('C-k',))
self.add_bindings('copy', ('M-k',))
self.add_bindings('yank', ('C-y',))
self.add_bindings('pop-kill', ('M-y',))
self.add_bindings('right-word', ('M-f',))
self.add_bindings('left-word', ('M-b',))
self.add_bindings('set-mark', ('C-@',))
self.add_bindings('switch-mark', ('C-x C-x',))
self.add_bindings('undo', ('C-/', 'C-x u',))
self.add_bindings('redo', ('M-/', 'M-_', 'C-x r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('transpose-words', ('M-t',))
self.add_bindings('delete-left-whitespace', ('C-c DELETE', 'C-c BACKSPACE',))
self.add_bindings('delete-right-whitespace', ('C-c d',))
self.add_bindings('insert-space', ('SPACE',))
self.add_bindings('insert-tab', ('TAB',))
self.add_bindings('console-exec', ('RETURN',))
self.add_bindings('console-clear', ('C-l',))
self.add_bindings('console-cancel', ('C-]',))
self.add_bindings('console-history-prev', ('C-p',))
self.add_bindings('console-history-next', ('C-n',))
self.add_bindings('console-tab', ('TAB',))
for c in string.letters + string.digits + string.punctuation:
self.add_binding('insert-string-%s' % c, c)
install = ConsoleMini.install

View File

@ -38,47 +38,6 @@ class DirGrammar(Grammar):
RegionRule(r'dir_unk', r'^\?', PathGrammar, r'\n'),
]
class Dir(mode.Fundamental):
modename = 'Dir'
grammar = DirGrammar()
colors = {
'dir_blk.start': ('cyan', 'default'),
'dir_blk.name': ('cyan', 'default'),
'dir_chr.start': ('yellow', 'default'),
'dir_chr.name': ('yellow', 'default'),
'dir_dir.start': ('blue', 'default'),
'dir_dir.dir_name': ('blue', 'default'),
'dir_lnk.start': ('green', 'default'),
'dir_lnk.name': ('green', 'default'),
'dir_fifo.start': ('red', 'default'),
'dir_fifo.name': ('red', 'default'),
'dir_sock.start': ('red', 'default'),
'dir_sock.name': ('red', 'default'),
'dir_unk.start': ('magenta', 'default'),
'dir_unk.name': ('magenta', 'default'),
'dir_perm.perm_setid': ('yellow', 'default'),
'dir_perm.perm_sticky': ('yellow', 'default'),
'dir_perm.perm_read': ('magenta', 'default'),
'dir_perm.perm_write': ('magenta', 'default'),
'dir_perm.perm_exec': ('magenta', 'default'),
'dir_owner': ('cyan', 'default'),
'dir_group': ('cyan', 'default'),
'dir_size': ('yellow', 'default'),
'dir_mtime': ('green', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(RefreshView(), ('C-c r',))
self.add_action_and_bindings(OpenPath(), ('RETURN',))
self.add_action_and_bindings(DirGrep(), ('C-c G',))
self.add_action_and_bindings(Chmod(), ('C-c m',))
self.add_action_and_bindings(Chown(), ('C-c o',))
self.add_action_and_bindings(Chgrp(), ('C-c g',))
self.add_action_and_bindings(TouchPath(), ('C-c t',))
self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d'))
class RefreshView(Method):
def _execute(self, w, **vargs):
t = dirutil.resolve_token(w)
@ -202,4 +161,47 @@ class RemovePath(Method):
except:
w.set_error("failed to delete %r" % path)
class Dir(mode.Fundamental):
modename = 'Dir'
grammar = DirGrammar()
colors = {
'dir_blk.start': ('cyan', 'default'),
'dir_blk.name': ('cyan', 'default'),
'dir_chr.start': ('yellow', 'default'),
'dir_chr.name': ('yellow', 'default'),
'dir_dir.start': ('blue', 'default'),
'dir_dir.dir_name': ('blue', 'default'),
'dir_lnk.start': ('green', 'default'),
'dir_lnk.name': ('green', 'default'),
'dir_fifo.start': ('red', 'default'),
'dir_fifo.name': ('red', 'default'),
'dir_sock.start': ('red', 'default'),
'dir_sock.name': ('red', 'default'),
'dir_unk.start': ('magenta', 'default'),
'dir_unk.name': ('magenta', 'default'),
'dir_perm.perm_setid': ('yellow', 'default'),
'dir_perm.perm_sticky': ('yellow', 'default'),
'dir_perm.perm_read': ('magenta', 'default'),
'dir_perm.perm_write': ('magenta', 'default'),
'dir_perm.perm_exec': ('magenta', 'default'),
'dir_owner': ('cyan', 'default'),
'dir_group': ('cyan', 'default'),
'dir_size': ('yellow', 'default'),
'dir_mtime': ('green', 'default'),
}
actions = [RefreshView, OpenPath, DirGrep, Chmod, Chown, Chgrp, TouchPath,
RemovePath]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('refresh-view', ('C-c r',))
self.add_bindings('open-path', ('RETURN',))
self.add_bindings('dir-grep', ('C-c G',))
self.add_bindings('chmod', ('C-c m',))
self.add_bindings('chown', ('C-c o',))
self.add_bindings('chgrp', ('C-c g',))
self.add_bindings('touch-path', ('C-c t',))
self.add_bindings('remove-path', ('DELETE', 'BACKSPACE', 'C-d'))
install = Dir.install

View File

@ -46,11 +46,8 @@ class ELisp(mode.Fundamental):
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# tag matching
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
## add lisp-specific methods
#self.add_action_and_bindings(LispCheckSyntax(), ('C-c s',))
install = ELisp.install

View File

@ -5,164 +5,6 @@ from lex import Grammar, PatternRule, RegionRule
from method import Method, Argument
from point import Point
class Hex(mode.Fundamental):
modename = 'Hex'
config = {
'hex.disinst': 'disinst',
}
lmargin = 12
rmargin = 18
_ctrans = ['.'] * 256
byteorder = 'native'
byteorders = {
'native': '=',
'little': '<',
'big': '>',
}
cgreen = color.build('green', 'default', 'bold')
ccyan = color.build('cyan', 'default', 'bold')
ccursor = color.build('default', 'default', 'bold', 'reverse')
for c in string.letters + string.digits + string.punctuation + ' ':
_ctrans[ord(c)] = c
ctrans = ''.join(_ctrans)
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
self.add_bindings('center-view', ('C-l',))
self.add_bindings('next-line', ('C-n', 'D_ARROW',))
self.add_bindings('previous-line', ('C-p', 'U_ARROW',))
self.add_bindings('next-section', ('M-n', 'M-D_ARROW',))
self.add_bindings('previous-section', ('M-p', 'M-U_ARROW',))
self.add_bindings('page-down', ('C-v', 'PG_DN',))
self.add_bindings('page-up', ('M-v', 'PG_UP',))
self.add_bindings('goto-beginning', ('M-<',))
self.add_bindings('goto-end', ('M->',))
self.add_bindings('right-word', ('M-f',))
self.add_bindings('left-word', ('M-b',))
self.add_bindings('set-mark', ('C-@',))
self.add_bindings('switch-buffer', ('C-x b',))
self.add_bindings('switch-mark', ('C-x C-x',))
self.add_bindings('undo', ('C-/', 'C-x u',))
self.add_bindings('redo', ('M-/', 'M-_', 'C-x r',))
self.add_bindings('goto-line', ('M-g',))
self.add_bindings('forward-chars', ('C-x M-c',))
self.add_bindings('forward-lines', ('C-x M-n',))
self.add_bindings('search', ('C-s',))
self.add_bindings('reverse-search', ('C-r',))
self.add_bindings('regex-search', ('M-C-s',))
self.add_bindings('regex-reverse-search', ('M-C-r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('open-file', ('C-x C-f',))
self.add_bindings('kill-buffer', ('C-x k',))
self.add_bindings('list-buffers', ('C-x C-b',))
self.add_bindings('meta-x', ('M-x',))
self.add_bindings('save-buffer', ('C-x C-s',))
self.add_bindings('save-buffer-as', ('C-x C-w',))
self.add_bindings('exit', ('C-x C-c',))
self.add_bindings('split-window', ('C-x s', 'C-x 2',))
self.add_bindings('unsplit-window', ('C-u s', 'C-x 1',))
self.add_bindings('toggle-window', ('C-x o',))
self.add_bindings('open-console', ('M-e',))
self.add_bindings('show-bindings-buffer', ('C-c M-h',))
self.add_bindings('show-functions-buffer', ('C-c M-?',))
self.add_bindings('which-command', ('M-h',))
self.add_bindings('cmd-help-buffer', ('M-?',))
self.add_bindings('set-mode', ('C-x m',))
self.add_bindings('cancel', ('C-]',))
self.add_bindings('exec', ('C-c e', 'C-c !'))
self.add_bindings('grep', ('C-c g',))
self.add_bindings('pipe', ('C-c p', 'C-c |'))
self.add_bindings('view-buffer-parent', ('C-c .',))
self.add_bindings('get-token', ('C-c t',))
self.add_action_and_bindings(HexForward(), ('C-f', 'R_ARROW',))
self.add_action_and_bindings(HexBackward(), ('C-b', 'L_ARROW',))
self.add_action_and_bindings(HexForwardWord(), ('M-f', 'M-R_ARROW',))
self.add_action_and_bindings(HexBackwardWord(), ('M-b', 'M-L_ARROW',))
self.add_action_and_bindings(HexStartOfLine(), ('C-a', 'HOME',))
self.add_action_and_bindings(HexEndOfLine(), ('C-e', 'END',))
self.add_action_and_bindings(HexRead('char', 'b'), ('C-c b',))
self.add_action_and_bindings(HexRead('uchar', 'B'), ('C-c B',))
self.add_action_and_bindings(HexRead('short', 'h'), ('C-c h',))
self.add_action_and_bindings(HexRead('ushort', 'H'), ('C-c H',))
self.add_action_and_bindings(HexRead('int', 'i'), ('C-c i',))
self.add_action_and_bindings(HexRead('uint', 'I'), ('C-c I',))
self.add_action_and_bindings(HexRead('long', 'l'), ('C-c l',))
self.add_action_and_bindings(HexRead('ulong', 'L'), ('C-c L',))
self.add_action_and_bindings(HexRead('float', 'f'), ('C-c f',))
self.add_action_and_bindings(HexRead('double', 'd'), ('C-c d',))
self.add_action_and_bindings(HexReadAligned('char', 'b'), ('C-u b',))
self.add_action_and_bindings(HexReadAligned('uchar', 'B'), ('C-u B',))
self.add_action_and_bindings(HexReadAligned('short', 'h'), ('C-u h',))
self.add_action_and_bindings(HexReadAligned('ushort', 'H'), ('C-u H',))
self.add_action_and_bindings(HexReadAligned('int', 'i'), ('C-u i',))
self.add_action_and_bindings(HexReadAligned('uint', 'I'), ('C-u I',))
self.add_action_and_bindings(HexReadAligned('long', 'l'), ('C-u l',))
self.add_action_and_bindings(HexReadAligned('ulong', 'L'), ('C-u L',))
self.add_action_and_bindings(HexReadAligned('float', 'f'), ('C-u f',))
self.add_action_and_bindings(HexReadAligned('double', 'd'), ('C-u d',))
self.add_action_and_bindings(ShowAddress(), ('C-c a',))
self.add_action_and_bindings(ShowX86Instruction(), ('C-c x',))
self.add_action_and_bindings(GotoAddress(), ('C-c M-g',))
self.add_action(HexSetByteOrder())
# create all the insert actions for the basic text input
for c in string.letters + string.digits + string.punctuation:
if c in string.hexdigits:
self.add_action_and_bindings(HexOverwriteChar(c), (c,))
def get_address(self, y, x):
return (y * 16) + x
def get_lmargin(self, y, x=0, ended=False, cont=False):
lm = self.lmargin
if ended:
s = ' -------- '
else:
addr = self.get_address(y, x)
s = '0x%08x ' % addr
return ((0, s, self.ccyan),)
def get_rmargin(self, y, x=0, ended=False, cont=False):
if ended:
return ((0, '', 0),)
else:
(cx, cy) = self.window.cursor.xy()
s = string.translate(self.window.buffer.rawdata[y], self.ctrans)
if cy == y:
i = self.window.buffer.cursorx_to_datax(cy, cx)
if i is None:
rmargins = ((0, s, self.cgreen),)
elif i < len(s):
rmargins = ((0, s[0:i], self.cgreen),
(i, s[i], self.ccursor),
(i + 1, s[i+1:], self.cgreen))
else:
rmargins= ((0, s[0:i], self.cgreen),
(i, s[i], self.cgreen),)
return rmargins
else:
return ((0, s, self.cgreen),)
def read_data(self, cy, ix, size):
b = self.window.buffer
s = b.rawdata[cy][ix:]
if len(s) < size:
if cy < len(b.rawdata) - 1:
s += b.rawdata[cy + 1]
s = s[:size]
return s
def read_struct(self, cy, ix, fmt, size):
s = self.read_data(cy, ix, size)
fmt = '%s%s' % (self.byteorders[self.byteorder], fmt)
return struct.unpack(fmt, s)[0]
class HexSetByteOrder(Method):
'''Sets the byte-order to use to 'little', 'big', or 'native' order'''
args = [Argument("byteorder", type=type(''), prompt="Byte order: ")]
@ -306,4 +148,163 @@ class ShowAddress(Method):
addr = w.buffer.get_address(cy, ix)
w.set_error("Cursor's address is 0x%08x" % addr)
class Hex(mode.Fundamental):
modename = 'Hex'
config = {
'hex.disinst': 'disinst',
}
lmargin = 12
rmargin = 18
_ctrans = ['.'] * 256
byteorder = 'native'
byteorders = {
'native': '=',
'little': '<',
'big': '>',
}
cgreen = color.build('green', 'default', 'bold')
ccyan = color.build('cyan', 'default', 'bold')
ccursor = color.build('default', 'default', 'bold', 'reverse')
for c in string.letters + string.digits + string.punctuation + ' ':
_ctrans[ord(c)] = c
ctrans = ''.join(_ctrans)
actions = [HexForward, HexBackward, HexForwardWord, HexBackwardWord,
HexStartOfLine, HexEndOfLine, ShowAddress, ShowX86Instruction,
GotoAddress, HexSetByteOrder]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
self.add_bindings('center-view', ('C-l',))
self.add_bindings('next-line', ('C-n', 'D_ARROW',))
self.add_bindings('previous-line', ('C-p', 'U_ARROW',))
self.add_bindings('next-section', ('M-n', 'M-D_ARROW',))
self.add_bindings('previous-section', ('M-p', 'M-U_ARROW',))
self.add_bindings('page-down', ('C-v', 'PG_DN',))
self.add_bindings('page-up', ('M-v', 'PG_UP',))
self.add_bindings('goto-beginning', ('M-<',))
self.add_bindings('goto-end', ('M->',))
self.add_bindings('right-word', ('M-f',))
self.add_bindings('left-word', ('M-b',))
self.add_bindings('set-mark', ('C-@',))
self.add_bindings('switch-buffer', ('C-x b',))
self.add_bindings('switch-mark', ('C-x C-x',))
self.add_bindings('undo', ('C-/', 'C-x u',))
self.add_bindings('redo', ('M-/', 'M-_', 'C-x r',))
self.add_bindings('goto-line', ('M-g',))
self.add_bindings('forward-chars', ('C-x M-c',))
self.add_bindings('forward-lines', ('C-x M-n',))
self.add_bindings('search', ('C-s',))
self.add_bindings('reverse-search', ('C-r',))
self.add_bindings('regex-search', ('M-C-s',))
self.add_bindings('regex-reverse-search', ('M-C-r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('open-file', ('C-x C-f',))
self.add_bindings('kill-buffer', ('C-x k',))
self.add_bindings('list-buffers', ('C-x C-b',))
self.add_bindings('meta-x', ('M-x',))
self.add_bindings('save-buffer', ('C-x C-s',))
self.add_bindings('save-buffer-as', ('C-x C-w',))
self.add_bindings('exit', ('C-x C-c',))
self.add_bindings('split-window', ('C-x s', 'C-x 2',))
self.add_bindings('unsplit-window', ('C-u s', 'C-x 1',))
self.add_bindings('toggle-window', ('C-x o',))
self.add_bindings('open-console', ('M-e',))
self.add_bindings('show-bindings-buffer', ('C-c M-h',))
self.add_bindings('show-functions-buffer', ('C-c M-?',))
self.add_bindings('which-command', ('M-h',))
self.add_bindings('cmd-help-buffer', ('M-?',))
self.add_bindings('set-mode', ('C-x m',))
self.add_bindings('cancel', ('C-]',))
self.add_bindings('exec', ('C-c e', 'C-c !'))
self.add_bindings('grep', ('C-c g',))
self.add_bindings('pipe', ('C-c p', 'C-c |'))
self.add_bindings('view-buffer-parent', ('C-c .',))
self.add_bindings('get-token', ('C-c t',))
self.add_bindings('hex-forward', ('C-f', 'R_ARROW',))
self.add_bindings('hex-backward', ('C-b', 'L_ARROW',))
self.add_bindings('hex-forward-word', ('M-f', 'M-R_ARROW',))
self.add_bindings('hex-backward-word', ('M-b', 'M-L_ARROW',))
self.add_bindings('hex-start-of-line', ('C-a', 'HOME',))
self.add_bindings('hex-end-of-line', ('C-e', 'END',))
self.add_action_and_bindings(HexRead('char', 'b'), ('C-c b',))
self.add_action_and_bindings(HexRead('uchar', 'B'), ('C-c B',))
self.add_action_and_bindings(HexRead('short', 'h'), ('C-c h',))
self.add_action_and_bindings(HexRead('ushort', 'H'), ('C-c H',))
self.add_action_and_bindings(HexRead('int', 'i'), ('C-c i',))
self.add_action_and_bindings(HexRead('uint', 'I'), ('C-c I',))
self.add_action_and_bindings(HexRead('long', 'l'), ('C-c l',))
self.add_action_and_bindings(HexRead('ulong', 'L'), ('C-c L',))
self.add_action_and_bindings(HexRead('float', 'f'), ('C-c f',))
self.add_action_and_bindings(HexRead('double', 'd'), ('C-c d',))
self.add_action_and_bindings(HexReadAligned('char', 'b'), ('C-u b',))
self.add_action_and_bindings(HexReadAligned('uchar', 'B'), ('C-u B',))
self.add_action_and_bindings(HexReadAligned('short', 'h'), ('C-u h',))
self.add_action_and_bindings(HexReadAligned('ushort', 'H'), ('C-u H',))
self.add_action_and_bindings(HexReadAligned('int', 'i'), ('C-u i',))
self.add_action_and_bindings(HexReadAligned('uint', 'I'), ('C-u I',))
self.add_action_and_bindings(HexReadAligned('long', 'l'), ('C-u l',))
self.add_action_and_bindings(HexReadAligned('ulong', 'L'), ('C-u L',))
self.add_action_and_bindings(HexReadAligned('float', 'f'), ('C-u f',))
self.add_action_and_bindings(HexReadAligned('double', 'd'), ('C-u d',))
self.add_bindings('show-address', ('C-c a',))
self.add_bindings('show-x86-instruction', ('C-c x',))
self.add_bindings('goto-address', ('C-c M-g',))
# create all the insert actions for the basic text input
for c in string.letters + string.digits + string.punctuation:
if c in string.hexdigits:
self.add_action_and_bindings(HexOverwriteChar(c), (c,))
def get_address(self, y, x):
return (y * 16) + x
def get_lmargin(self, y, x=0, ended=False, cont=False):
lm = self.lmargin
if ended:
s = ' -------- '
else:
addr = self.get_address(y, x)
s = '0x%08x ' % addr
return ((0, s, self.ccyan),)
def get_rmargin(self, y, x=0, ended=False, cont=False):
if ended:
return ((0, '', 0),)
else:
(cx, cy) = self.window.cursor.xy()
s = string.translate(self.window.buffer.rawdata[y], self.ctrans)
if cy == y:
i = self.window.buffer.cursorx_to_datax(cy, cx)
if i is None:
rmargins = ((0, s, self.cgreen),)
elif i < len(s):
rmargins = ((0, s[0:i], self.cgreen),
(i, s[i], self.ccursor),
(i + 1, s[i+1:], self.cgreen))
else:
rmargins= ((0, s[0:i], self.cgreen),
(i, s[i], self.cgreen),)
return rmargins
else:
return ((0, s, self.cgreen),)
def read_data(self, cy, ix, size):
b = self.window.buffer
s = b.rawdata[cy][ix:]
if len(s) < size:
if cy < len(b.rawdata) - 1:
s += b.rawdata[cy + 1]
s = s[:size]
return s
def read_struct(self, cy, ix, fmt, size):
s = self.read_data(cy, ix, size)
fmt = '%s%s' % (self.byteorders[self.byteorder], fmt)
return struct.unpack(fmt, s)[0]
install = Hex.install

View File

@ -17,41 +17,8 @@ class HTMLGrammar(Grammar):
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
]
class HTML(mode.Fundamental):
modename = 'HTML'
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar
colors = {}
config = {
'html.viewcmd': 'firefox&',
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_action(HtmlViewPage())
self.add_action(HtmlCheckSpelling())
_colorbase = {
'start': ('default', 'default'),
'namespace': ('magenta', 'default'),
'name': ('blue', 'default'),
'attrname': ('cyan', 'default'),
'string.start': ('green', 'default'),
'string.null': ('green', 'default'),
'string.end': ('green', 'default'),
'end': ('default', 'default'),
}
for _name in _colorbase:
HTML.colors['script.%s' % _name] = _colorbase[_name]
HTML.colors['style.%s' % _name] = _colorbase[_name]
HTML.colors['tag.%s' % _name] = _colorbase[_name]
class HtmlViewPage(method.Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer'''
'''View the HTML data in a browser (curses or external)'''
def _execute(self, w, **vargs):
viewcmd = w.application.config.get('html.viewcmd')
viewbg = viewcmd.endswith('&')
@ -77,4 +44,36 @@ class HtmlCheckSpelling(method.Method):
if w.buffer.changed_on_disk():
w.buffer.reload()
class HTML(mode.Fundamental):
modename = 'HTML'
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar
colors = {}
config = {
'html.viewcmd': 'firefox&',
}
_colorbase = {
'start': ('default', 'default'),
'namespace': ('magenta', 'default'),
'name': ('blue', 'default'),
'attrname': ('cyan', 'default'),
'string.start': ('green', 'default'),
'string.null': ('green', 'default'),
'string.end': ('green', 'default'),
'end': ('default', 'default'),
}
for _name in _colorbase:
colors['script.%s' % _name] = _colorbase[_name]
colors['style.%s' % _name] = _colorbase[_name]
colors['tag.%s' % _name] = _colorbase[_name]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_action(HtmlViewPage())
self.add_action(HtmlCheckSpelling())
install = HTML.install

View File

@ -4,8 +4,30 @@ from lex import Grammar, PatternRule
from mode.python import PythonGrammar
from point import Point
def insert_line(w):
s = w.buffer.make_string()
w.mode.lines.append(s)
w.buffer.set_data('')
class MiniInsertTab(method.Method):
def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
class MiniInsertLine(method.Method):
def _execute(self, w, **vargs):
insert_line(w)
class MiniInsertComplete(method.Method):
def execute(self, w, **vargs):
insert_line(w)
w.buffer.callback('\n'.join(w.mode.lines))
w.application.close_mini_buffer()
class MiniInsertCancel(method.Method):
def execute(self, w, **vargs):
w.application.close_mini_buffer()
class InsertMini(mode.Fundamental):
modename = 'InsertMini'
actions = [MiniInsertLine, MiniInsertComplete, MiniInsertCancel,
MiniInsertTab]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
@ -41,31 +63,11 @@ class InsertMini(mode.Fundamental):
self.add_bindings('delete-right-whitespace', ('C-c d',))
self.add_bindings('insert-space', ('SPACE',))
self.add_bindings('insert-tab', ('TAB',))
self.add_action_and_bindings(InsertLine(), ('RETURN',))
self.add_action_and_bindings(InsertComplete(), ('M-RETURN',))
self.add_action_and_bindings(InsertCancel(), ('C-]',))
self.add_action_and_bindings(InsertTab(), ('TAB',))
self.add_bindings('mini-insert-line', ('RETURN',))
self.add_bindings('mini-insert-complete', ('M-RETURN',))
self.add_bindings('mini-insert-cancel', ('C-]',))
self.add_bindings('mini-insert-tab', ('TAB',))
for c in string.letters + string.digits + string.punctuation:
self.add_binding('insert-string-%s' % c, c)
def insert_line(w):
s = w.buffer.make_string()
w.mode.lines.append(s)
w.buffer.set_data('')
class InsertTab(method.Method):
def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
class InsertLine(method.Method):
def _execute(self, w, **vargs):
insert_line(w)
class InsertComplete(method.Method):
def execute(self, w, **vargs):
insert_line(w)
w.buffer.callback('\n'.join(w.mode.lines))
w.application.close_mini_buffer()
class InsertCancel(method.Method):
def execute(self, w, **vargs):
w.application.close_mini_buffer()
install = InsertMini.install

View File

@ -33,7 +33,6 @@ class JavaTabber(CTabber):
def is_base(self, y):
if y == 0:
return True
#return False
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
if not highlighter.tokens[y]:
@ -165,29 +164,15 @@ class Java(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
#'comment': ('red', 'default'),
#'comment.start': ('red', 'default'),
#'comment.end': ('red', 'default'),
#'comment.null': ('red', 'default'),
'doccomment.start': ('red', 'default'),
'doccomment.end': ('red', 'default'),
'doccomment.null': ('red', 'default'),
'import': ('blue', 'default'),
'java_label': ('magenta', 'default'),
#'keyword': ('cyan', 'default'),
#'function': ('blue', 'default'),
'java_builtin': ('magenta', 'default'),
'java_char': ('green', 'default'),
#'string.start': ('green', 'default'),
#'string.octal': ('green', 'default'),
#'string.escaped': ('green', 'default'),
#'string.null': ('green', 'default'),
#'string.end': ('green', 'default'),
'java_integer': ('green', 'default'),
'java_float': ('green', 'default'),
'doccomment.start': ('red', 'default'),
'doccomment.end': ('red', 'default'),
'doccomment.null': ('red', 'default'),
'import': ('blue', 'default'),
'java_label': ('magenta', 'default'),
'java_builtin': ('magenta', 'default'),
'java_char': ('green', 'default'),
'java_integer': ('green', 'default'),
'java_float': ('green', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -15,39 +15,6 @@ class LatexGrammar(Grammar):
PatternRule(r'latex_special', r'[{}$^_%~#&]'),
]
class Latex(mode.Fundamental):
modename = 'Latex'
extensions = ['.latex', '.tex']
grammar = LatexGrammar
colors = {
'latex_wrapper': ('magenta', 'default', 'bold'),
'latex_control': ('blue', 'default', 'bold'),
'latex_argument.null': ('cyan', 'default', 'bold'),
'latex_string.start': ('green', 'default', 'bold'),
'latex_string.null': ('green', 'default', 'bold'),
'latex_string.end': ('green', 'default', 'bold'),
'latex_escaped': ('magenta', 'default', 'bold'),
}
config = {
'latex.buildcmd': 'latex',
'latex.pdfbuildcmd': 'pdflatex',
'latex.pdfviewcmd': 'evince',
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('wrap-paragraph', ('M-q',))
self.add_action_and_bindings(LatexCommentRegion(), ('C-c #', "C-c \%"))
self.add_action_and_bindings(LatexUncommentRegion(), ('C-u C-c #', "C-u C-c \%"))
self.add_action_and_bindings(LatexInsertSquotes(), ("M-'",))
self.add_action_and_bindings(LatexInsertDquotes(), ('M-"',))
self.add_action_and_bindings(LatexInsertBraces(), ('M-{',))
self.add_action_and_bindings(LatexBuild(), ("C-c C-c", 'C-c B'))
self.add_action_and_bindings(LatexInsertSpace(), ('SPACE',))
self.add_action_and_bindings(LatexBuildPdf(), ("C-c C-p",))
self.add_action_and_bindings(LatexViewPdf(), ('C-c C-v',))
self.add_action(LatexCheckSpelling())
class LatexBuild(method.Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer'''
def _getcmd(self, w):
@ -131,4 +98,39 @@ class LatexCheckSpelling(method.Method):
if w.buffer.changed_on_disk():
w.buffer.reload()
class Latex(mode.Fundamental):
modename = 'Latex'
extensions = ['.latex', '.tex']
grammar = LatexGrammar
colors = {
'latex_wrapper': ('magenta', 'default', 'bold'),
'latex_control': ('blue', 'default', 'bold'),
'latex_argument.null': ('cyan', 'default', 'bold'),
'latex_string.start': ('green', 'default', 'bold'),
'latex_string.null': ('green', 'default', 'bold'),
'latex_string.end': ('green', 'default', 'bold'),
'latex_escaped': ('magenta', 'default', 'bold'),
}
config = {
'latex.buildcmd': 'latex',
'latex.pdfbuildcmd': 'pdflatex',
'latex.pdfviewcmd': 'evince',
}
actions = [LatexCommentRegion, LatexUncommentRegion, LatexInsertSquotes,
LatexInsertDquotes, LatexInsertBraces, LatexBuild,
LatexInsertSpace, LatexBuildPdf, LatexViewPdf,
LatexCheckSpelling]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('wrap-paragraph', ('M-q',))
self.add_bindings('latex-comment-region', ('C-c #', "C-c \%"))
self.add_bindings('latex-uncomment-region', ('C-u C-c #', "C-u C-c \%"))
self.add_bindings('latex-insert-squotes', ("M-'",))
self.add_bindings('latex-insert-dquotes', ('M-"',))
self.add_bindings('latex-insert-braces', ('M-{',))
self.add_bindings('latex-build', ("C-c C-c", 'C-c B'))
self.add_bindings('latex-insert-space', ('SPACE',))
self.add_bindings('latex-build-pdf', ("C-c C-p",))
self.add_bindings('latex-view-pdf', ('C-c C-v',))
install = Latex.install

View File

@ -39,14 +39,6 @@ class Lisp(mode.Fundamental):
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
#'comment': ('red', 'default'),
#'string.start': ('green', 'default'),
#'string.null': ('green', 'default'),
#'string.octal': ('magenta', 'default'),
#'string.escaped': ('magenta', 'default'),
#'string.end': ('green', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))

View File

@ -13,14 +13,9 @@ class MakeGrammar(Grammar):
rules = [
PatternRule(r'comment', r'#.*\n$'),
PatternRule(r'continuation', r'\\\n$'),
#PatternRule(r'assignment', r'^[^:= ]+(?= *=)'),
PatternRule(r'targets', r'^[^:= ]+(?= *:)'),
RegionRule(r'assignment', r'^[^:= ]+ *=', ShGrammar, r'\n'),
#RegionRule(r'targets', r'^[^:= ]+ *:', Grammar, r';|\n', ShGrammar, r'\n'),
RegionRule(r'actions', r'^ ', ShGrammar, r'\n'),
PatternRule(r'make_variable', r'\$\([a-zA-Z0-9_]+\)'),
PatternRule(r'make_variable', r'\${[a-zA-Z0-9_]+}'),
RegionRule(r'make_string', r'"', StringGrammar, r'"'),
@ -33,22 +28,14 @@ class Make(mode.Fundamental):
grammar = MakeGrammar
savetabs = True
colors = {
#'comment': ('red', 'default'),
#'continuation': ('red', 'default'),
'targets.start': ('cyan', 'default'),
'assignment.start': ('yellow', 'default'),
#'targets': ('cyan', 'default'),
#'assignment': ('yellow', 'default'),
'make_variable': ('yellow', 'default'),
'targets.start': ('cyan', 'default'),
'assignment.start': ('yellow', 'default'),
'make_variable': ('yellow', 'default'),
'make_string.start': ('green', 'default'),
'make_string.variable': ('yellow', 'default'),
'make_string.escaped': ('magenta', 'default'),
'make_string.null': ('green', 'default'),
'make_string.end': ('green', 'default'),
}
#colors.update(Sh.colors)
install = Make.install

View File

@ -1,32 +1,10 @@
import method, mode
class Mini(mode.Fundamental):
modename = 'Mini'
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# delete actions relating to multiple lines
self.del_action('center-view')
self.del_action('next-line')
self.del_action('previous-line')
self.del_action('page-down')
self.del_action('page-up')
self.del_action('goto-beginning')
self.del_action('goto-end')
self.del_action('switch-buffer')
# add some new actions for the minibuffer
self.add_action_and_bindings(MiniCallback(), ('RETURN',))
self.add_action_and_bindings(MiniTabComplete(), ('TAB',))
class MiniCallback(method.Method):
def execute(self, window, **vargs):
window.buffer.do_callback()
class MiniTabComplete(method.Method):
def __init__(self):
self.name = "tab-complete"
self.args = []
def execute(self, window, **vargs):
b = window.buffer
if b.tabber is None:
@ -36,4 +14,24 @@ class MiniTabComplete(method.Method):
s2, exists, complete = b.tabber.tab_string(s1, window)
b.set_data(s2)
class Mini(mode.Fundamental):
modename = 'Mini'
actions = [MiniCallback, MiniTabComplete]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# delete actions relating to multiple lines
#self.del_action('center-view')
#self.del_action('next-line')
#self.del_action('previous-line')
#self.del_action('page-down')
#self.del_action('page-up')
#self.del_action('goto-beginning')
#self.del_action('goto-end')
#self.del_action('switch-buffer')
# add some new actions for the minibuffer
self.add_bindings('mini-callback', ('RETURN',))
self.add_bindings('mini-tab-complete', ('TAB',))
install = Mini.install

View File

@ -17,6 +17,12 @@ class MuttGrammar(Grammar):
PatternRule(name=r'stuff', pattern=r'[a-zA-Z0-9_]+'),
]
class MuttWrapParagraph(method.WrapParagraph):
limit = 72
empty_re = re.compile('^(?: *>.*| *)$')
class MuttInsertSpace(mode.text.TextInsertSpace):
wrapper = MuttWrapParagraph
class Mutt(mode.Fundamental):
modename = 'Mutt'
grammar = MuttGrammar()
@ -36,15 +42,8 @@ class Mutt(mode.Fundamental):
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(mode.text.LearnWord(), ('C-c l',))
self.add_action_and_bindings(MuttWrapParagraph(), ('M-q',))
self.add_action_and_bindings(MuttInsertSpace(), ('SPACE',))
class MuttWrapParagraph(method.WrapParagraph):
limit = 72
empty_re = re.compile('^(?: *>.*| *)$')
class MuttInsertSpace(mode.text.TextInsertSpace):
wrapper = MuttWrapParagraph
self.add_bindings('learn-word', ('C-c l',))
self.add_bindings('mutt-wrap-paragraph', ('M-q',))
self.add_bindings('mutt-insert-space', ('SPACE',))
install = Mutt.install

View File

@ -20,9 +20,7 @@ class OcamlGrammar(Grammar):
PatternRule(r'spaces', r' +'),
PatternRule(r'eol', r'\n'),
RegionRule(r'comment', r'\(\*', CommentGrammar, r'\*\)'),
PatternRule(r'linenum', r'#[0-9]+ *(?:"(?:[^"\\]|\\[0-9]{3}|\\x[0-9A-Za-z]{2}|\\.)*")?'),
PatternRule(r'delimiter', r"[()]"),
PatternRule(r'ocaml_keyword', r"(?:with|while|when|virtual|val|type|try|true|to|then|struct|sig|rec|private|parser|or|open|of|object|new|mutable|module|mod|method|match|lxor|lsr|lsl|lor|let|lazy|land|initializer|inherti|include|in|if|functor|function|fun|for|false|external|exception|end|else|downto|done|do|constraint|class|begin|asr|assert|as|and)(?!['a-zA-Z0-9_])"),
@ -30,26 +28,21 @@ class OcamlGrammar(Grammar):
PatternRule(r'builtin', r"(?:int|char|string|float|bool|false|true|unit|exn|array|list|option|int32|int64|nativeint|format4|lazy_t)(?!['a-zA-Z0-9_])"),
PatternRule(r'builtin_exception', r"(?:Match_failure|Assert_failure|Invalid_argument|Failure|Not_found|Out_of_memory|Stack_overflow|Sys_error|End_of_file|Division_by_zero|Sys_blocked_io|Undefined_recursive_module|Exit)(?!['a-zA-Z0-9_])"),
PatternRule(r'builtin_function', r"raise|invalid_arg|failwith"),
NocasePatternRule(r'identifier', r"[a-z_]['a-z0-9_]*"),
NocasePatternRule(r'integer', r"-?[0-9][0-9_]*"),
NocasePatternRule(r'integer', r"-?0x[0-9a-f][0-9a-f_]*"),
NocasePatternRule(r'integer', r"-?0o[0-7][0-7_]*"),
NocasePatternRule(r'integer', r"-?0b[01][01_]*"),
NocasePatternRule(r'float', r"-?[0-9][0-9_]*(?:\.[0-9_]*)?(?:e[+-]?[0-9][0-9_]*)?"),
PatternRule(r'char', r"'[^\\']'"),
PatternRule(r'char', r"'\\[\\ \"'ntbr]'"),
PatternRule(r'char', r"'\\[0-9]{3}'"),
PatternRule(r'char', r"'\\x[0-9A-Fa-f]{2}'"),
RegionRule(r'ocaml_string', r'"', StringGrammar, '"'),
PatternRule(r'label', r"~[a-z_]['a-zA-Z0-9_]*:"),
PatternRule(r'optlabel', r"\?[a-z_]['a-zA-Z0-9_]*:"),
PatternRule(r'infix', r'[-=<>@^|&+*/$%][-!$%&*+\./:<=>?@^|~]*'),
PatternRule(r'prefix', r'[!?~][-!$%&*+\./:<=>?@^|~]*'),
]
@ -63,29 +56,16 @@ class Ocaml(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
#'comment.start': ('red', 'default'),
#'comment.null': ('red', 'default'),
#'comment.end': ('red', 'default'),
'linenum': ('red', 'default'),
'ocaml_keyword': ('cyan', 'default'),
#'builtin': ('magenta', 'default'),
#'builtin_exception': ('magenta', 'default'),
#'builtin_function': ('magenta', 'default'),
'ocaml_label': ('blue', 'default'),
'optlabel': ('blue', 'default'),
'ocaml_string.start': ('green', 'default'),
'ocaml_string.null': ('green', 'default'),
'ocaml_string.octal': ('magenta', 'default'),
'ocaml_string.hex': ('magenta', 'default'),
'ocaml_string.escaped': ('magenta', 'default'),
'ocaml_string.end': ('green', 'default'),
#'char': ('green', 'default'),
#'integer': ('default', 'default'),
#'float': ('default', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -196,155 +196,6 @@ class PerlTabber(tab.StackTabber):
self._opt_append('cont', currlvl + w)
return currlvl
class Perl(mode.Fundamental):
modename = 'Perl'
extensions = ['.pl', '.pm']
detection = ['perl']
tabbercls = PerlTabber
grammar = PerlGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
# comments
'endblock.start': ('red', 'default'),
'endblock.null': ('red', 'default'),
'endblock.end': ('red', 'default'),
# pod
'pod.start': ('red', 'default'),
'pod.null': ('red', 'default'),
'pod.entry.start': ('magenta', 'default'),
'pod.entry.null': ('magenta', 'default'),
'pod.entry.end': ('magenta', 'default'),
'pod.end': ('red', 'default'),
# basic stuff
'escaped': ('magenta', 'default'),
'null': ('default', 'default'),
#'delimiter': ('default', 'default'),
'sub': ('cyan', 'default'),
'prototype': ('magenta', 'default'),
'number': ('default', 'default'),
'operator': ('default', 'default'),
'noperator': ('magenta', 'default'),
'endblock': ('red', 'default'),
'perl_keyword': ('magenta', 'default'),
'cast': ('yellow', 'default'),
'scalar': ('yellow', 'default'),
'array': ('yellow', 'default'),
'deref': ('yellow', 'default'),
'perl_hash': ('yellow', 'default'),
'hash_key': ('green', 'default'),
'perl_function': ('cyan', 'default'),
'perl_builtin': ('magenta', 'default'),
#'method': ('cyan', 'default'),
#'bareword': ('default', 'default'),
'perl_label': ('cyan', 'default'),
'package': ('cyan', 'default'),
'perl_class': ('cyan', 'default'),
'use': ('cyan', 'default'),
'require': ('cyan', 'default'),
#'method': ('cyan', 'default'),
# heredoc/evaldoc
'heredoc.start': ('green', 'default'),
'heredoc.null': ('green', 'default'),
'heredoc.end': ('green', 'default'),
'evaldoc.start': ('cyan', 'default'),
'evaldoc.null': ('cyan', 'default'),
'evaldoc.end': ('cyan', 'default'),
# strings
'perl_string.start': ('green', 'default'),
'perl_string.null': ('green', 'default'),
'perl_string.escaped': ('magenta', 'default'),
'perl_string.deref': ('yellow', 'default'),
'perl_string.end': ('green', 'default'),
# `` strings
'evalstring.start': ('cyan', 'default'),
'evalstring.null': ('cyan', 'default'),
'evalstring.escaped': ('magenta', 'default'),
'evalstring.deref': ('yellow', 'default'),
'evalstring.end': ('cyan', 'default'),
# quoted region
'quoted': ('cyan', 'default'),
'quoted.start': ('cyan', 'default'),
'quoted.null': ('cyan', 'default'),
'quoted.escaped': ('magenta', 'default'),
'quoted.deref': ('yellow', 'default'),
'quoted.end': ('cyan', 'default'),
# match regex
'match.start': ('cyan', 'default'),
'match.end': ('cyan', 'default'),
'match.null': ('cyan', 'default'),
# replace regex
'replace.start': ('cyan', 'default'),
'replace.middle0': ('cyan', 'default'),
'replace.end': ('cyan', 'default'),
'replace.null': ('cyan', 'default'),
'replace.escaped': ('magenta', 'default'),
'replace.deref': ('yellow', 'default'),
'replace.length': ('yellow', 'default'),
'replace.scalar': ('yellow', 'default'),
'replace.perl_hash': ('yellow', 'default'),
'replace.cast': ('yellow', 'default'),
# translate regex
'translate.start': ('magenta', 'default'),
'translate.middle0': ('magenta', 'default'),
'translate.end': ('magenta', 'default'),
'translate.null': ('magenta', 'default'),
}
config = {
'perl.lib': 'lib',
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(PerlSetLib(), ('C-c l',))
self.add_action_and_bindings(PerlCheckSyntax(), ('C-c s',))
self.add_action_and_bindings(PerlHashCleanup(), ('C-c h',))
#self.add_action_and_bindings(PerlHashCleanup2(), ('C-c h',))
self.add_action_and_bindings(PerlViewModulePerldoc(), ('C-c v',))
self.add_action_and_bindings(PerlViewWordPerldoc(), ('C-c p',))
self.add_action_and_bindings(PerlWrapParagraph(), ('M-q',))
self.add_action_and_bindings(PerlInitFunctions(), ('C-c M-g',))
self.add_action_and_bindings(PerlGotoFunction(), ('C-c M-g',))
self.add_action_and_bindings(PerlWhichFunction(), ('C-c w',))
self.add_action_and_bindings(PerlListFunctions(), ('C-c W',))
# visual tag matching
self.add_bindings('close-paren', (')'))
self.add_bindings('close-bracket', (']'))
self.add_bindings('close-brace', ('}'))
# perl-specific
self.functions = None
def build_function_map(self):
b = self.window.buffer
self.functions = {}
for i in range(0, len(b.lines)):
m = regex.perl_function.match(b.lines[i])
if m:
self.functions[m.group(1)] = i
def get_functions(self):
if self.functions is None:
self.build_function_map()
return self.functions
def get_function_names(self):
functions = self.get_functions()
pairs = [[functions[key], key] for key in functions]
pairs.sort()
names = [x[1] for x in pairs]
return names
class PerlSetLib(Method):
'''Set the path(s) to find perl modules'''
args = [Argument("lib", type=type(""), prompt="Location of lib: ",
@ -726,4 +577,154 @@ class PerlWrapParagraph(method.WrapParagraph):
else:
w.set_error("did not detect comment or pod lines")
class Perl(mode.Fundamental):
modename = 'Perl'
extensions = ['.pl', '.pm']
detection = ['perl']
tabbercls = PerlTabber
grammar = PerlGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
# comments
'endblock.start': ('red', 'default'),
'endblock.null': ('red', 'default'),
'endblock.end': ('red', 'default'),
# pod
'pod.start': ('red', 'default'),
'pod.null': ('red', 'default'),
'pod.entry.start': ('magenta', 'default'),
'pod.entry.null': ('magenta', 'default'),
'pod.entry.end': ('magenta', 'default'),
'pod.end': ('red', 'default'),
# basic stuff
'escaped': ('magenta', 'default'),
'null': ('default', 'default'),
#'delimiter': ('default', 'default'),
'sub': ('cyan', 'default'),
'prototype': ('magenta', 'default'),
'number': ('default', 'default'),
'operator': ('default', 'default'),
'noperator': ('magenta', 'default'),
'endblock': ('red', 'default'),
'perl_keyword': ('magenta', 'default'),
'cast': ('yellow', 'default'),
'scalar': ('yellow', 'default'),
'array': ('yellow', 'default'),
'deref': ('yellow', 'default'),
'perl_hash': ('yellow', 'default'),
'hash_key': ('green', 'default'),
'perl_function': ('cyan', 'default'),
'perl_builtin': ('magenta', 'default'),
#'method': ('cyan', 'default'),
#'bareword': ('default', 'default'),
'perl_label': ('cyan', 'default'),
'package': ('cyan', 'default'),
'perl_class': ('cyan', 'default'),
'use': ('cyan', 'default'),
'require': ('cyan', 'default'),
#'method': ('cyan', 'default'),
# heredoc/evaldoc
'heredoc.start': ('green', 'default'),
'heredoc.null': ('green', 'default'),
'heredoc.end': ('green', 'default'),
'evaldoc.start': ('cyan', 'default'),
'evaldoc.null': ('cyan', 'default'),
'evaldoc.end': ('cyan', 'default'),
# strings
'perl_string.start': ('green', 'default'),
'perl_string.null': ('green', 'default'),
'perl_string.escaped': ('magenta', 'default'),
'perl_string.deref': ('yellow', 'default'),
'perl_string.end': ('green', 'default'),
# `` strings
'evalstring.start': ('cyan', 'default'),
'evalstring.null': ('cyan', 'default'),
'evalstring.escaped': ('magenta', 'default'),
'evalstring.deref': ('yellow', 'default'),
'evalstring.end': ('cyan', 'default'),
# quoted region
'quoted': ('cyan', 'default'),
'quoted.start': ('cyan', 'default'),
'quoted.null': ('cyan', 'default'),
'quoted.escaped': ('magenta', 'default'),
'quoted.deref': ('yellow', 'default'),
'quoted.end': ('cyan', 'default'),
# match regex
'match.start': ('cyan', 'default'),
'match.end': ('cyan', 'default'),
'match.null': ('cyan', 'default'),
# replace regex
'replace.start': ('cyan', 'default'),
'replace.middle0': ('cyan', 'default'),
'replace.end': ('cyan', 'default'),
'replace.null': ('cyan', 'default'),
'replace.escaped': ('magenta', 'default'),
'replace.deref': ('yellow', 'default'),
'replace.length': ('yellow', 'default'),
'replace.scalar': ('yellow', 'default'),
'replace.perl_hash': ('yellow', 'default'),
'replace.cast': ('yellow', 'default'),
# translate regex
'translate.start': ('magenta', 'default'),
'translate.middle0': ('magenta', 'default'),
'translate.end': ('magenta', 'default'),
'translate.null': ('magenta', 'default'),
}
config = {
'perl.lib': 'lib',
}
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
PerlViewModulePerldoc, PerlViewWordPerldoc, PerlWrapParagraph,
PerlInitFunctions, PerlGotoFunction, PerlWhichFunction,
PerlListFunctions]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('perl-set-lib', ('C-c l',))
self.add_bindings('perl-check-syntax', ('C-c s',))
self.add_bindings('perl-hash-cleanup', ('C-c h',))
self.add_bindings('perl-view-module-perldoc', ('C-c v',))
self.add_bindings('perl-view-word-perldoc', ('C-c p',))
self.add_bindings('perl-wrap-paragraph', ('M-q',))
self.add_bindings('perl-init-functions', ('C-c M-g',))
self.add_bindings('perl-goto-function', ('C-c M-g',))
self.add_bindings('perl-which-function', ('C-c w',))
self.add_bindings('perl-list-functions', ('C-c W',))
self.add_bindings('close-paren', (')'))
self.add_bindings('close-bracket', (']'))
self.add_bindings('close-brace', ('}'))
# perl-specific
self.functions = None
def build_function_map(self):
b = self.window.buffer
self.functions = {}
for i in range(0, len(b.lines)):
m = regex.perl_function.match(b.lines[i])
if m:
self.functions[m.group(1)] = i
def get_functions(self):
if self.functions is None:
self.build_function_map()
return self.functions
def get_function_names(self):
functions = self.get_functions()
pairs = [[functions[key], key] for key in functions]
pairs.sort()
names = [x[1] for x in pairs]
return names
install = Perl.install

View File

@ -332,7 +332,7 @@ class Python(mode.Fundamental):
config = {
'python.lib': '.',
}
methods = [PythonInitFunctions, PythonListFunctions, PythonGotoFunction,
actions = [PythonInitFunctions, PythonListFunctions, PythonGotoFunction,
PythonCheckSyntax, PythonDictCleanup, PythonInsertTripleSquotes,
PythonInsertTripleDquotes]
def __init__(self, w):

View File

@ -5,27 +5,6 @@ from point import Point
subgroup_re = re.compile(r'((?:\\\\)*)\\(0|[1-9][0-9]*)')
class Replace(mode.Fundamental):
modename = 'Replace'
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.actions = {}
self.bindings = {}
self.add_action_and_bindings(ReplaceAll(), ('a', '!',))
self.add_action_and_bindings(ReplaceDone(), ('d',))
self.add_action_and_bindings(ReplaceOne(), ('y', 'SPACE',))
self.add_action_and_bindings(SkipReplace(), ('n', 'DELETE',))
self.add_action_and_bindings(CancelReplace(), ('q', 'RETURN', 'C-]', 'C-n', 'C-p', 'C-a', 'C-e', 'C-f', 'C-b'))
m = w.buffer.method
found = _find_next(m, False)
if not found:
w.set_error('%r was not found' % m.before)
raise minibuffer.MiniBufferError
_set_prompt(m)
class ReplaceOne(method.Method):
def execute(self, w, **vargs):
m = w.buffer.method
@ -143,4 +122,25 @@ def _end(w):
w.buffer.method.old_window = None
assert not w.application.mini_active
class Replace(mode.Fundamental):
modename = 'Replace'
actions = [ReplaceAll, ReplaceDone, ReplaceOne, SkipReplace, CancelReplace]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.actions = {}
self.bindings = {}
self.add_bindings('replace-all', ('a', '!',))
self.add_bindings('replace-done', ('d',))
self.add_bindings('replace-one', ('y', 'SPACE',))
self.add_bindings('skip-replace', ('n', 'DELETE',))
self.add_bindings('cancel-replace', ('q', 'RETURN', 'C-]', 'C-n', 'C-p', 'C-a', 'C-e', 'C-f', 'C-b'))
m = w.buffer.method
found = _find_next(m, False)
if not found:
w.set_error('%r was not found' % m.before)
raise minibuffer.MiniBufferError
_set_prompt(m)
install = Replace.install

View File

@ -42,6 +42,11 @@ class RSTGrammar(Grammar):
PatternRule(r'enumeration', r'^ *(?:[0-9]+|#)\.'),
]
class RstInsertSpace(TextInsertSpace):
limit = 75
class RstWrapParagraph(method.WrapParagraph):
limit = 75
class RST(mode.Fundamental):
modename = 'RST'
extensions = ['.rst']
@ -77,14 +82,10 @@ class RST(mode.Fundamental):
'bullet': ('magenta', 'default'),
'enumeration': ('magenta', 'default'),
}
actions = [RstInsertSpace, RstWrapParagraph]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(RstInsertSpace(), ('SPACE',))
self.add_action_and_bindings(RstWrapParagraph(), ('M-q',))
self.add_bindings('rst-insert-space', ('SPACE',))
self.add_bindings('rst-wrap-paragraph', ('M-q',))
install = RST.install
class RstInsertSpace(TextInsertSpace):
limit = 75
class RstWrapParagraph(method.WrapParagraph):
limit = 75

View File

@ -25,37 +25,6 @@ class SchemeGrammar(Grammar):
PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'),
]
class Scheme(mode.Fundamental):
modename = 'Scheme'
extensions = ['.scm']
tabwidth = 2
tabbercls = mode.lisp.LispTabber
grammar = SchemeGrammar
opentokens = ('delimiter',)
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
#'comment': ('red', 'default'),
'scheme_keyword': ('cyan', 'default'),
#'string.start': ('green', 'default'),
#'string.null': ('green', 'default'),
#'string.octal': ('magenta', 'default'),
#'string.escaped': ('magenta', 'default'),
#'string.end': ('green', 'default'),
'scheme_char': ('green', 'default'),
'scheme_boolean': ('magenta', 'default'),
'scheme_number': ('default', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_action_and_bindings(SchemeCheckSyntax(), ('C-c s',))
class SchemeCheckSyntax(method.Method):
'''Check the syntax of a scheme file'''
def _execute(self, w, **vargs):
@ -68,4 +37,28 @@ class SchemeCheckSyntax(method.Method):
else:
app.data_buffer("*Scheme-Check-Syntax*", output)
class Scheme(mode.Fundamental):
modename = 'Scheme'
extensions = ['.scm']
tabwidth = 2
tabbercls = mode.lisp.LispTabber
grammar = SchemeGrammar
opentokens = ('delimiter',)
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
colors = {
'scheme_keyword': ('cyan', 'default'),
'scheme_char': ('green', 'default'),
'scheme_boolean': ('magenta', 'default'),
'scheme_number': ('default', 'default'),
}
actions = [SchemeCheckSyntax]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('scheme-check-syntax', ('C-c s',))
install = Scheme.install

View File

@ -3,32 +3,9 @@ import re, sets, string
import color, method, minibuffer, mode, searchutil
from point import Point
selected_color = 'magenta'
selected_color = 'magenta'
unselected_color = 'yellow'
class Search(mode.Fundamental):
modename = 'Search'
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# clear out all the defaults that we don't want/need
self.actions = {}
self.bindings = {}
# add some useful bindings
self.add_action_and_bindings(SearchNext(), ('C-s',))
self.add_action_and_bindings(SearchPrevious(), ('C-r',))
self.add_action_and_bindings(EndSearch(), ('RETURN', 'C-n', 'C-p', 'C-a', 'C-e', 'C-f', 'C-b',))
self.add_action_and_bindings(CancelSearch(), ('C-]',))
self.add_action_and_bindings(SearchDeleteLeft(), ('DELETE', 'BACKSPACE',))
self.add_action_and_bindings(SearchDeleteLeftWord(), ('M-DELETE', 'M-BACKSPACE',))
# create all the insert actions for the character ranges we like
for collection in (string.letters, string.digits, string.punctuation):
for c in collection:
self.add_action_and_bindings(InsertSearchString(c), (c,))
self.add_action_and_bindings(InsertSearchString(' '), ('SPACE',))
def _make_regex(w, s):
try:
if w.buffer.method.is_literal:
@ -138,4 +115,27 @@ def _end(w):
w.application.clear_highlighted_ranges()
w.application.last_search = w.buffer.make_string()
class Search(mode.Fundamental):
modename = 'Search'
actions = [SearchNext, SearchPrevious, EndSearch, CancelSearch,
SearchDeleteLeft, SearchDeleteLeftWord]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# clear out all the defaults that we don't want/need, and add ours
self.actions = {}
self.bindings = {}
self.add_bindings('search-next', ('C-s',))
self.add_bindings('search-previous', ('C-r',))
self.add_bindings('end-search', ('RETURN', 'C-n', 'C-p', 'C-a', 'C-e', 'C-f', 'C-b',))
self.add_bindings('cancel-search', ('C-]',))
self.add_bindings('search-delete-left', ('DELETE', 'BACKSPACE',))
self.add_bindings('search-delete-left-word', ('M-DELETE', 'M-BACKSPACE',))
# create all the insert actions for the character ranges we like
for collection in (string.letters, string.digits, string.punctuation):
for c in collection:
self.add_action_and_bindings(InsertSearchString(c), (c,))
self.add_action_and_bindings(InsertSearchString(' '), ('SPACE',))
install = Search.install

View File

@ -64,8 +64,6 @@ class ShGrammar(Grammar):
RegionRule(r'test', r'test', TestGrammar, r'\n'),
RegionRule(r'test2', r'\[', TestGrammar, r'\]'),
PatternRule(r'delimiter', r";;|[();{}|&><]"),
#RegionRule(r'eval', r'`', StringGrammar, r'`'),
#RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'),
RegionRule(r'eval', r'`', EvalGrammar, r'`'),
RegionRule(r'neval', r'\$\(', EvalGrammar, r'\)'),
PatternRule(r'variable', r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z0-9_]*(?==)"),
@ -115,6 +113,18 @@ class ShTabber(tab.StackTabber):
self._opt_pop("cont")
return currlvl
class ShCheckSyntax(Method):
'''Check the syntax of a shell script'''
def _execute(self, w, **vargs):
app = w.application
cmd = "bash -n %r" % w.buffer.path
(status, output) = commands.getstatusoutput(cmd)
if status == 0:
app.set_error("Syntax OK")
app.data_buffer("*Sh-Check-Syntax*", output, switch_to=False)
else:
app.data_buffer("*Sh-Check-Syntax*", output)
class Sh(mode.Fundamental):
modename = 'sh'
paths = ['/etc/profile']
@ -129,10 +139,10 @@ class Sh(mode.Fundamental):
closetags = {')': '(', ']': '[', '}': '{',
'done': 'do', 'fi': 'then', 'esac': 'case'}
colors = {
'sh_builtin': ('cyan', 'default', 'bold'),
'sh_function': ('magenta', 'default', 'bold'),
'sh_reserved': ('magenta', 'default', 'bold'),
'variable': ('yellow', 'default', 'bold'),
'sh_builtin': ('cyan', 'default', 'bold'),
'sh_function': ('magenta', 'default', 'bold'),
'sh_reserved': ('magenta', 'default', 'bold'),
'variable': ('yellow', 'default', 'bold'),
# case statements
'case.start': ('magenta', 'default', 'bold'),
@ -147,39 +157,18 @@ class Sh(mode.Fundamental):
'binop': ('magenta', 'default', 'bold'),
'unop': ('magenta', 'default', 'bold'),
#'string.start': ('green', 'default'),
#'string.variable': ('yellow', 'default'),
#'string.escaped': ('magenta', 'default'),
#'string.null': ('green', 'default'),
#'string.end': ('green', 'default'),
'eval.start': ('cyan', 'default'),
'eval.variable': ('yellow', 'default'),
'eval.null': ('cyan', 'default'),
'eval.end': ('cyan', 'default'),
'neval.start': ('yellow', 'default'),
'neval.variable': ('yellow', 'default'),
'neval.null': ('cyan', 'default'),
'neval.end': ('yellow', 'default'),
#'comment': ('red', 'default'),
#'continuation': ('red', 'default'),
'eval.start': ('cyan', 'default'),
'eval.variable': ('yellow', 'default'),
'eval.null': ('cyan', 'default'),
'eval.end': ('cyan', 'default'),
'neval.start': ('yellow', 'default'),
'neval.variable': ('yellow', 'default'),
'neval.null': ('cyan', 'default'),
'neval.end': ('yellow', 'default'),
}
actions = [ShCheckSyntax]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(ShCheckSyntax(), ('C-c s',))
class ShCheckSyntax(Method):
'''Check the syntax of a shell script'''
def _execute(self, w, **vargs):
app = w.application
cmd = "bash -n %r" % w.buffer.path
(status, output) = commands.getstatusoutput(cmd)
if status == 0:
app.set_error("Syntax OK")
app.data_buffer("*Sh-Check-Syntax*", output, switch_to=False)
else:
app.data_buffer("*Sh-Check-Syntax*", output)
self.add_bindings('sh-check-syntax', ('C-c s',))
install = Sh.install

View File

@ -117,23 +117,17 @@ class Sql(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
#'comment': ('red', 'default'),
'sql_operator': ('yellow', 'default'),
'attribute': ('magenta', 'default'),
'sql_keyword': ('cyan', 'default'),
'pseudokeyword': ('cyan', 'default'),
'sql_type': ('green', 'default'),
'sql_builtin': ('yellow', 'default'),
'sql_quoted.start': ('yellow', 'default'),
'sql_quoted.null': ('yellow', 'default'),
'sql_quoted.end': ('yellow', 'default'),
#'string.start': ('green', 'default'),
#'string.null': ('green', 'default'),
#'string.escaped': ('magenta', 'default'),
#'string.octal': ('magenta', 'default'),
#'string.end': ('green', 'default'),
'sql_variable': ('yellow', 'default'),
'sql_bareword': ('default', 'default'),
'sql_operator': ('yellow', 'default'),
'attribute': ('magenta', 'default'),
'sql_keyword': ('cyan', 'default'),
'pseudokeyword': ('cyan', 'default'),
'sql_type': ('green', 'default'),
'sql_builtin': ('yellow', 'default'),
'sql_quoted.start': ('yellow', 'default'),
'sql_quoted.null': ('yellow', 'default'),
'sql_quoted.end': ('yellow', 'default'),
'sql_variable': ('yellow', 'default'),
'sql_bareword': ('default', 'default'),
'function.start': ('cyan', 'default'),
'function.null': ('default', 'default'),
@ -141,10 +135,10 @@ class Sql(mode.Fundamental):
'function.language': ('magenta', 'default'),
'function.end': ('default', 'default'),
'function.definition.start': ('magenta', 'default'),
'function.definition.start': ('magenta', 'default'),
'function.definition.sql_bareword': ('magenta', 'default'),
'function.definition.null': ('magenta', 'default'),
'function.definition.end': ('magenta', 'default'),
'function.definition.null': ('magenta', 'default'),
'function.definition.end': ('magenta', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -34,24 +34,6 @@ class TextGrammar(Grammar):
PatternRule(r'stuff', r'[a-zA-Z0-9_]+'),
]
class Text(mode.Fundamental):
modename = 'Text'
extensions=['.txt']
grammar = TextGrammar
colors = {
#'misspelled': ('red', 'default'),
#'cont.start': ('default', 'default'),
#'cont.end': ('default', 'default'),
#'word': ('default', 'default'),
#'punct': ('default', 'default'),
#'stuff': ('default', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_action_and_bindings(LearnWord(), ('C-c l',))
self.add_action_and_bindings(TextInsertSpace(), ('SPACE',))
self.add_action_and_bindings(TextWrapParagraph(), ('M-q',))
class TextWrapParagraph(method.WrapParagraph):
pass
@ -89,4 +71,15 @@ class LearnWord(method.Method):
w.insert_string_at_cursor(' ')
w.left_delete()
class Text(mode.Fundamental):
modename = 'Text'
extensions=['.txt']
grammar = TextGrammar
actions = [LearnWord, TextInsertSpace, TextWrapParagraph]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('learn-word', ('C-c l',))
self.add_bindings('text-insert-space', ('SPACE',))
self.add_bindings('text-wrap-paragraph', ('M-q',))
install = Text.install

View File

@ -20,12 +20,6 @@ class Text2(mode.text.Text):
colors = {
'text2_email': ('cyan', 'default'),
'text2_url': ('green', 'default'),
#'misspelled': ('red', 'default'),
#'cont.start': ('default', 'default'),
#'cont.end': ('default', 'default'),
#'word': ('default', 'default'),
#'punct': ('default', 'default'),
#'stuff': ('default', 'default'),
}
install = Text2.install

View File

@ -1,6 +1,5 @@
import color, mode
from lex import Grammar, PatternRule, RegionRule
#from mode.xml import TagGrammar
from mode.perl import StringGrammar
class DirectiveGrammar(Grammar):
@ -33,10 +32,6 @@ class Template(mode.Fundamental):
extensions = ['.tt']
grammar = TemplateGrammar
colors = {
#'comment.start': ('red', 'default'),
#'comment.null': ('red', 'default'),
#'comment.end': ('red', 'default'),
'directive.start': ('magenta', 'default'),
'directive.comment': ('red', 'default'),
'directive.keyword': ('cyan', 'default'),

View File

@ -22,9 +22,6 @@ class XML(mode.Fundamental):
extensions = ['.xml', '.xml.in']
grammar = XMLGrammar
colors = {
#'comment.start': ('red', 'default'),
#'comment.null': ('red', 'default'),
#'comment.end': ('red', 'default'),
'xml_tag.start': ('default', 'default'),
'xml_tag.namespace': ('magenta', 'default'),
'xml_tag.name': ('blue', 'default'),