diff --git a/application.py b/application.py index 188896f..4fc9179 100755 --- a/application.py +++ b/application.py @@ -2,8 +2,8 @@ import curses, curses.ascii, getpass, os, re, string, sets, sys, termios, time import traceback -import buffer, bufferlist, color, completer, keyinput, method, minibuffer, mode, mode2 -import util, window2 +import buffer, bufferlist, color, completer, keyinput, method, minibuffer, mode, mode +import util, window from point import Point def run(buffers, jump_to_line=None, init_mode=None): @@ -81,7 +81,7 @@ class Application(object): self.mode_detection = {} # ok, now let's load all the "standard" modes - mode2.install(self) + mode.install(self) for name in ('blame', 'c', 'console', 'consolemini', 'css', 'diff', 'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp', 'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', @@ -124,9 +124,9 @@ class Application(object): # build windows for our buffers for b in buffers: if b.name() == '*Console*': - window2.Window(b, self, height, width, mode_name='console') + window.Window(b, self, height, width, mode_name='console') else: - window2.Window(b, self, height, width, mode_name=init_mode) + window.Window(b, self, height, width, mode_name=init_mode) self.bufferlist.add_buffer(b) self.bufferlist.set_slot(0, buffers[0]) @@ -239,7 +239,7 @@ class Application(object): else: raise Exception, "not a file or dir: %r" % path b.open() - window2.Window(b, self, height=0, width=0, mode_name=mode_name) + window.Window(b, self, height=0, width=0, mode_name=mode_name) self.add_buffer(b) return b @@ -254,7 +254,7 @@ class Application(object): self.mini_prompt = prompt self.mini_buffer = minibuffer.MiniBuffer(callback, method, tabber, modename) try: - window2.Window(self.mini_buffer, self, height=1, + window.Window(self.mini_buffer, self, height=1, width=self.x-1-len(self.mini_prompt)-1) self.mini_active = True except minibuffer.MiniBufferError: @@ -299,7 +299,7 @@ class Application(object): f.close() b = buffer.FileBuffer(path) b.open() - window2.Window(b, self, height=0, width=0) + window.Window(b, self, height=0, width=0) self.add_buffer(b) if switch_to: self.switch_buffer(b) @@ -310,7 +310,7 @@ class Application(object): b = buffer.DataBuffer(name, data) if modename is not None: b.modename = modename - window2.Window(b, self, height=0, width=0) + window.Window(b, self, height=0, width=0) self.add_buffer(b) if switch_to: self.switch_buffer(b) @@ -343,7 +343,7 @@ class Application(object): # XYZ if not b.has_window(slotname): slot = self.bufferlist.slots[slotname] - window2.Window(b, self, height=slot.height, width=slot.width) + window.Window(b, self, height=slot.height, width=slot.width) # error string handling def set_error(self, s): @@ -787,7 +787,7 @@ if __name__ == "__main__": # if debugging, disable error handling to produce backtraces if opts.debug: - mode2.DEBUG = True + mode.DEBUG = True # we will support using +19 as the first argument to indicate opening the # first file on line 19 (same as -g 19 or --goto 19) diff --git a/buffer.py b/buffer.py index 19f37b1..8bc3f1d 100644 --- a/buffer.py +++ b/buffer.py @@ -1,5 +1,5 @@ import datetime, grp, md5, os, pwd, re, sets, shutil, stat, string -import aes, dirutil, regex, highlight2 +import aes, dirutil, regex, highlight from point import Point # undo/redo stack constants @@ -108,7 +108,7 @@ class Buffer(object): self.windows.append(w) modename = w.mode.name() if modename not in self.highlights and w.mode.lexer is not None: - self.highlights[modename] = highlight2.Highlighter(w.mode.lexer) + self.highlights[modename] = highlight.Highlighter(w.mode.lexer) self.highlights[modename].highlight(self.lines) #if modename not in self.tabbing and w.mode.tabber is not None: # self.tabbing[modename] = diff --git a/bufferlist.py b/bufferlist.py index ee8bcb0..8581653 100644 --- a/bufferlist.py +++ b/bufferlist.py @@ -1,5 +1,5 @@ import sets -import window2 +import window class Slot: def __init__(self, height, width, offset): @@ -93,7 +93,7 @@ class BufferList: self.hidden_buffers.remove(b) if self.is_window_visible(b.windows[0]): app = b.windows[0].application - w = window2.Window(b, app, height=slot.height, width=slot.width) + w = window.Window(b, app, height=slot.height, width=slot.width) else: w = b.windows[0] slot.set(w) diff --git a/method.py b/method.py index dab734a..ba66ca0 100644 --- a/method.py +++ b/method.py @@ -1,5 +1,5 @@ import os, commands, popen2, re, sets -import buffer, default, dirutil, regex, util, window2 +import buffer, default, dirutil, regex, util, window from point import Point WHITESPACE = [' ', '\n'] diff --git a/mode/__init__.py b/mode/__init__.py index e69de29..5fcc73a 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -0,0 +1,280 @@ +import os, sets, string +import color, method +from lex import Lexer +from point import Point + +DEBUG = False + +class ActionError(Exception): + pass + +class Handler(object): + def __init__(self): + self.prefixes = sets.Set(["C-x", "C-c", "C-u"]) + self.last_sequence = '' + self.curr_tokens = [] + self.bindings = {} + + # handle adding and removing actions + def add_action(self, action): + if self.window is None: + return + elif action.name in self.window.application.methods: + return + else: + self.window.application.methods[action.name] = action + def del_action(self, name): + if self.window is None: + return + for binding in self.bindings.keys(): + if self.bindings[binding] == name: + del self.bindings[binding] + def add_binding(self, name, sequence): + if self.window is None: + return + elif not hasattr(self.window, 'application'): + raise Exception, "argh %r %r" % (self, self.window) + elif name not in self.window.application.methods: + raise Exception, "No action called %r found" % name + else: + self.bindings[sequence] = name + def add_bindings(self, name, sequences): + if self.window is None: + return + for sequence in sequences: + self.add_binding(name, sequence) + def del_binding(self, sequence): + if self.window is None: + return + del self.bindings[sequence] + def add_action_and_bindings(self, action, sequences): + if self.window is None: + return + self.add_action(action) + for sequence in sequences: + self.add_binding(action.name, sequence) + + def handle_token(self, t): + '''self.handle_token(token): returns None, or the action to + take. raises an exception on unknown input''' + self.curr_tokens.append(t) + sequence = " ".join(self.curr_tokens) + if sequence in self.bindings: + act = self.window.application.methods[self.bindings[sequence]] + self.last_sequence = sequence + self.curr_tokens = [] + return act + elif t in self.prefixes: + for binding in self.bindings: + if binding.startswith(sequence): + return None + self.curr_tokens = [] + self.last_sequence = sequence + raise ActionError, "no action defined for %r" % (sequence) + +class Fundamental(Handler): + '''This is the default mode''' + modename = "Fundamental" + paths = [] + basenames = [] + extensions = [] + detection = [] + savetabs = False + tabwidth = 4 + tabbercls = None + grammar = None + lexer = None + tabber = None + default_color = ('default', 'default',) + colors = {} + + def install(cls, app): + app.setmode(cls.modename.lower(), cls, paths=cls.paths, + basenames=cls.basenames, extensions=cls.extensions, + detection=cls.detection) + install = classmethod(install) + + def __init__(self, w): + self.window = w + + # we need to defer this due to curses startup + #self.default_color = color.pairs('default', 'default') + Handler.__init__(self) + + # first let's add all the "default" actions + 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('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('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-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('replace', ('M-%',)) + self.add_bindings('regex-replace', ('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('wrap-line', ('M-q',)) + self.add_bindings('transpose-words', ('M-t',)) + self.add_bindings('save-buffer', ('C-x C-s',)) + self.add_bindings('save-buffer-as', ('C-x C-w',)) + self.add_bindings('relex-buffer', ('M-r',)) + 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('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('insert-newline', ('RETURN',)) + self.add_bindings('comment-region', ('C-c #',)) + self.add_bindings('uncomment-region', ('C-u C-c #',)) + self.add_bindings('justify-right', ('C-c f',)) + self.add_bindings('justify-left', ('C-c b',)) + self.add_bindings('indent-block', ('C-c >',)) + self.add_bindings('unindent-block', ('C-c <',)) + self.add_bindings('token-complete', ('M-c', 'C-c c')) + self.add_bindings('shell-cmd', ('C-c !',)) + self.add_bindings('open-aes-file', ('C-c a',)) + self.add_bindings('open-console', ('M-e',)) + self.add_bindings('show-bindings-buffer', ('C-c M-h','C-c M-?',)) + self.add_bindings('which-command', ('M-?',)) + self.add_bindings('cmd-help-buffer', ('M-h',)) + self.add_bindings('set-mode', ('C-x m',)) + self.add_bindings('cancel', ('C-]',)) + self.add_bindings('exec', ('C-c e',)) + self.add_bindings('grep', ('C-c g',)) + self.add_bindings('pipe', ('C-c p',)) + self.add_bindings('view-buffer-parent', ('C-c .',)) + + # unbound actions + self.add_action(method.GetToken()) + + # create all the insert actions for the basic text input + for c in string.letters + string.digits + string.punctuation: + self.add_binding('insert-string-%s' % c, c) + + # lexing for highlighting, etc. + if self.grammar: + self.lexer = Lexer(self, self.grammar) + self.gstack = {} + self.ghist = {} + + # tab handling + if self.tabbercls: + self.tabber = self.tabbercls(self) + + # get mode name + def name(self): + return self.modename + + # handle input tokens + def handle_token(self, t): + '''self.handle_token(token): handles input "token"''' + self.window.active_point = None + #self.window.application.clear_error() + self.window.clear_error() + try: + act = Handler.handle_token(self, t) + if act is None: + self.window.set_error(' '.join(self.curr_tokens)) + return + else: + act.execute(self.window) + self.window.application.last_action = act.name + except ActionError, e: + if t != 'C-]': + self.window.set_error(str(e)) + else: + self.window.set_error('Cancelled') + except Exception, e: + if DEBUG: + raise + else: + err = "%s in mode '%s'" % (e, self.name()) + self.window.set_error(err) + + def region_added(self, p, newlines): + if self.tabber is not None: + self.tabber.region_added(p, newlines) + if self.lexer: + ydelta = len(newlines) - 1 + xdelta = len(newlines[-1]) + ghist = {} + for name in self.ghist: + for gp in self.ghist[name]: + if gp < p: + newp = gp + elif ydelta == 0: + if p.y == gp.y: + newp = Point(gp.x + xdelta, gp.y) + else: + newp = gp + else: + if gp.y == p.y: + newp = Point(gp.x + xdelta, gp.y + ydelta) + else: + newp = Point(gp.x, gp.y + ydelta) + ghist.setdefault(name, {}) + ghist[name][newp] = self.ghist[name][gp] + self.ghist = ghist + def region_removed(self, p1, p2): + if self.tabber is not None: + self.tabber.region_removed(p1, p2) + if self.lexer: + ydelta = p2.y - p1.y + xdelta = p2.x - p1.x + ghist = {} + for name in self.ghist: + for gp in self.ghist[name]: + if gp < p1: + newp = gp + elif p1 <= gp and gp < p2: + continue + elif ydelta == 0: + if gp.y == p2.y: + newp = Point(gp.x - xdelta, gp.y) + else: + newp = gp + else: + if gp.y == p2.y: + newp = Point(gp.x - xdelta, gp.y - ydelta) + else: + newp = Point(gp.x, gp.y - ydelta) + ghist.setdefault(name, {}) + ghist[name][newp] = self.ghist[name][gp] + self.ghist = ghist +install = Fundamental.install diff --git a/mode/bds.py b/mode/bds.py index 26e6f66..019f754 100644 --- a/mode/bds.py +++ b/mode/bds.py @@ -1,5 +1,5 @@ import commands -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule, Grammar from method import Method from mode.perl import PerlGrammar @@ -22,7 +22,7 @@ class BDSGrammar(Grammar): PatternRule(r'operator', r'(?:>=|<=|>|<|==|&&|\|\||eq|ne)'), ] -class BDS(mode2.Fundamental): +class BDS(mode.Fundamental): modename = 'BDS' basenames = ['components.xml'] grammar = BDSGrammar @@ -59,7 +59,7 @@ class BDS(mode2.Fundamental): 'operator': ('magenta', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/blame.py b/mode/blame.py index 57c2cf3..65a8f7e 100644 --- a/mode/blame.py +++ b/mode/blame.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from point import Point from lex import Grammar, PatternRule, RegionRule @@ -14,7 +14,7 @@ class BlameGrammar(Grammar): PatternRule(r'data', r'.+$'), ] -class Blame(mode2.Fundamental): +class Blame(mode.Fundamental): modename = 'Blame' grammar = BlameGrammar colors = { diff --git a/mode/c.py b/mode/c.py index 10cfad3..07f2ec7 100644 --- a/mode/c.py +++ b/mode/c.py @@ -1,5 +1,5 @@ import os, popen2, re -import color, default, method, mode2, tab2 +import color, default, method, mode, tab from lex import Grammar, PatternRule, RegionRule from mode.python import StringGrammar @@ -53,7 +53,7 @@ class CGrammar(Grammar): PatternRule(r'eol', r"\n$"), ] -class CTabber(tab2.StackTabber): +class CTabber(tab.StackTabber): wst = ('spaces', 'eol', 'comment', 'comment.start', 'comment.null', 'comment.end') def token_is_whitespace(self, y, i): token = self.get_token(y, i) @@ -101,11 +101,11 @@ class CTabber(tab2.StackTabber): self._opt_pop('cont') if self.is_leftmost_token(y, i): currlvl = self.get_curr_level() - tab2.StackTabber._handle_open_token(self, currlvl, y, i) + tab.StackTabber._handle_open_token(self, currlvl, y, i) return currlvl def _handle_close_token(self, currlvl, y, i): self._opt_pop('cont') - currlvl = tab2.StackTabber._handle_close_token(self, currlvl, y, i) + currlvl = tab.StackTabber._handle_close_token(self, currlvl, y, i) token = self.get_token(y, i) if self.is_rightmost_token(y, i): if token.string == '}': @@ -175,7 +175,7 @@ class CTabber(tab2.StackTabber): self._opt_append('cont', currlvl + 4) return currlvl -class C(mode2.Fundamental): +class C(mode.Fundamental): modename = 'C' extensions = ['.c'] tabbercls = CTabber @@ -235,7 +235,7 @@ class C(mode2.Fundamental): 'bizzaro': ('magenta', 'green'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/console.py b/mode/console.py index 22bc10c..a8f6a6d 100644 --- a/mode/console.py +++ b/mode/console.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule from mode.python import StringGrammar @@ -13,7 +13,7 @@ class ConsoleGrammar(Grammar): RegionRule(r'string', r"'", StringGrammar, r"'"), PatternRule(r'bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'), ] -class Console(mode2.Fundamental): +class Console(mode.Fundamental): modename = 'Console' grammar = ConsoleGrammar() colors = { diff --git a/mode/consolemini.py b/mode/consolemini.py index 154bb88..4f872b3 100644 --- a/mode/consolemini.py +++ b/mode/consolemini.py @@ -1,12 +1,12 @@ import code, string, StringIO, sys, traceback -import color, completer, method, mode2 +import color, completer, method, mode from lex import Grammar, PatternRule from point import Point -class ConsoleMini(mode2.Fundamental): +class ConsoleMini(mode.Fundamental): modename = 'ConsoleMini' def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.bindings = {} self.globals = dict(w.application.globals()) self.locals = dict(w.application.locals()) diff --git a/mode/css.py b/mode/css.py index 0c73dff..54dedc0 100644 --- a/mode/css.py +++ b/mode/css.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule from point import Point @@ -41,7 +41,7 @@ class CSSGrammar(Grammar): RegionRule(r'string', '"', StringGrammar, r'"'), ] -class CSS(mode2.Fundamental): +class CSS(mode.Fundamental): modename = 'CSS' extensions = ['.css'] grammar = CSSGrammar @@ -91,7 +91,7 @@ class CSS(mode2.Fundamental): 'string.end': ('green', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/diff.py b/mode/diff.py index f96a571..a61fa64 100644 --- a/mode/diff.py +++ b/mode/diff.py @@ -1,4 +1,4 @@ -import color, method, mode2, re +import color, method, mode, re from lex import Grammar, PatternRule, RegionRule class DiffGrammar(Grammar): @@ -11,7 +11,7 @@ class DiffGrammar(Grammar): PatternRule(name=r'common', pattern=r"^.*\n$"), ] -class Diff(mode2.Fundamental): +class Diff(mode.Fundamental): modename = 'diff' grammar = DiffGrammar() colors = { @@ -22,7 +22,7 @@ class Diff(mode2.Fundamental): 'location': ('magenta', 'default', 'bold'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) #self.add_action_and_bindings(DiffNextSection(), ('M-n', 'M-D_ARROW',)) #self.add_action_and_bindings(DiffPreviousSection(), ('M-p', 'M-U_ARROW',)) diff --git a/mode/dir.py b/mode/dir.py index ddd2bb3..b22790c 100644 --- a/mode/dir.py +++ b/mode/dir.py @@ -1,5 +1,5 @@ -import commands, dirutil, grp, method, mode2, os.path, pwd, re -import buffer, window2 +import commands, dirutil, grp, method, mode, os.path, pwd, re +import buffer, window from lex import Grammar, PatternRule, RegionRule, PatternGroupRule from point import Point from method import Method, Argument @@ -35,7 +35,7 @@ class DirGrammar(Grammar): RegionRule(r'unk', r'^\?', PathGrammar, r'\n'), ] -class Dir(mode2.Fundamental): +class Dir(mode.Fundamental): modename = 'Dir' grammar = DirGrammar() colors = { @@ -66,7 +66,7 @@ class Dir(mode2.Fundamental): 'mtime': ('green', 'default'), } def __init__(self, w): - mode2.Fundamental.__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',)) @@ -97,7 +97,7 @@ class DirGrep(Method): b = buffer.PathListBuffer(bufname, paths) b.modename = 'dir' b.open() - window2.Window(b, w.application, height=0, width=0) + window.Window(b, w.application, height=0, width=0) w.application.add_buffer(b) w.application.switch_buffer(b) w.set_error("grep exited with %d" % status) diff --git a/mode/elisp.py b/mode/elisp.py index 771fae7..be0b013 100644 --- a/mode/elisp.py +++ b/mode/elisp.py @@ -1,5 +1,5 @@ import commands, os.path, sets, string, sys, traceback -import color, completer, default, mode2, method, regex, tab2 +import color, completer, default, mode, method, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule @@ -25,10 +25,10 @@ class ELispGrammar(Grammar): PatternRule(r'eol', r'\n$'), ] -class ELispTabber(tab2.StackTabber): +class ELispTabber(tab.StackTabber): pass -class ELisp(mode2.Fundamental): +class ELisp(mode.Fundamental): modename = 'ELisp' basenames = ['.emacs'] extensions = ['.el'] @@ -55,7 +55,7 @@ class ELisp(mode2.Fundamental): 'comment': ('red', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) # tag matching self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) diff --git a/mode/hex.py b/mode/hex.py index 1098d59..58f1b79 100644 --- a/mode/hex.py +++ b/mode/hex.py @@ -1,5 +1,5 @@ import string -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule from method import Method, Argument from point import Point @@ -10,7 +10,7 @@ class HexGrammar(Grammar): PatternRule(r'byte', r'[0-f][0-f]'), ] -class Hex(mode2.Fundamental): +class Hex(mode.Fundamental): modename = 'Hex' grammar = HexGrammar colors = { @@ -18,7 +18,7 @@ class Hex(mode2.Fundamental): 'byte': ('white', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_action_and_bindings(GotoWord(), ('M-g',)) self.add_action(FindStrings()) diff --git a/mode/html.py b/mode/html.py index 5c759b0..c9c8e10 100644 --- a/mode/html.py +++ b/mode/html.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule from mode.xml import TagGrammar from mode.javascript import JavascriptGrammar, Javascript @@ -14,7 +14,7 @@ class HTMLGrammar(Grammar): RegionRule(r'tag', r''), ] -class HTML(mode2.Fundamental): +class HTML(mode.Fundamental): modename = 'HTML' extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] grammar = HTMLGrammar @@ -43,7 +43,7 @@ class HTML(mode2.Fundamental): } colors.update(Javascript.colors) def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/java.py b/mode/java.py index 66c6b33..153ea2f 100644 --- a/mode/java.py +++ b/mode/java.py @@ -1,4 +1,4 @@ -import color, mode2, tab2 +import color, mode, tab from lex import Grammar, PatternRule, RegionRule from mode.python import StringGrammar from mode.c import CTabber @@ -82,11 +82,11 @@ class JavaTabber(CTabber): token = self.get_token(y, i) if token.string == '{': self._opt_pop('cond') - currlvl = tab2.StackTabber._handle_open_token(self, currlvl, y, i) + currlvl = tab.StackTabber._handle_open_token(self, currlvl, y, i) return currlvl def _handle_close_token(self, currlvl, y, i): self._opt_pop('cont') - currlvl = tab2.StackTabber._handle_close_token(self, currlvl, y, i) + currlvl = tab.StackTabber._handle_close_token(self, currlvl, y, i) token = self.get_token(y, i) if self.is_rightmost_token(y, i): if token.string == '}': @@ -153,7 +153,7 @@ class JavaTabber(CTabber): self._opt_append('cont', currlvl + 4) return currlvl -class Java(mode2.Fundamental): +class Java(mode.Fundamental): modename = 'Java' extensions = ['.java'] tabbercls = JavaTabber @@ -188,7 +188,7 @@ class Java(mode2.Fundamental): 'float': ('green', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/javascript.py b/mode/javascript.py index 97f9d20..4a9600a 100644 --- a/mode/javascript.py +++ b/mode/javascript.py @@ -1,4 +1,4 @@ -import color, mode2, tab2 +import color, mode, tab from lex import Grammar, PatternRule, RegionRule from point import Point from mode.python import StringGrammar @@ -34,7 +34,7 @@ class JavascriptGrammar(Grammar): RegionRule('string', '"', StringGrammar, '"'), ] -class JavascriptTabber(tab2.StackTabber): +class JavascriptTabber(tab.StackTabber): def is_base(self, y): if y == 0: return True @@ -52,7 +52,7 @@ class JavascriptTabber(tab2.StackTabber): self._opt_pop("cont") return currlvl -class Javascript(mode2.Fundamental): +class Javascript(mode.Fundamental): modename = 'Javascript' extensions = ['.js'] grammar = JavascriptGrammar @@ -91,7 +91,7 @@ class Javascript(mode2.Fundamental): 'regex.end': ('cyan', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/lisp.py b/mode/lisp.py index c8a68f1..daa8278 100644 --- a/mode/lisp.py +++ b/mode/lisp.py @@ -1,5 +1,5 @@ import commands, os.path, sets, string, sys, traceback -import color, completer, default, mode2, method, regex, tab2 +import color, completer, default, mode, method, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule from mode.python import StringGrammar @@ -13,7 +13,7 @@ class LispGrammar(Grammar): PatternRule(r'eol', r'\n'), ] -class LispTabber(tab2.StackTabber): +class LispTabber(tab.StackTabber): wsre = regex.whitespace wst = ('spaces', 'null', 'eol',) sre = regex.space @@ -30,7 +30,7 @@ class LispTabber(tab2.StackTabber): self._append(token.string, level) return currlvl -class Lisp(mode2.Fundamental): +class Lisp(mode.Fundamental): modename = 'Lisp' tabwidth = 2 tabbercls = LispTabber @@ -48,7 +48,7 @@ class Lisp(mode2.Fundamental): 'string.end': ('green', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/make.py b/mode/make.py index 07e699f..f348f64 100644 --- a/mode/make.py +++ b/mode/make.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule, PatternGroupRule from mode.sh import ShGrammar, Sh @@ -27,7 +27,7 @@ class MakeGrammar(Grammar): RegionRule(r'string', r"'", StringGrammar, r"'"), ] -class Make(mode2.Fundamental): +class Make(mode.Fundamental): modename = 'Make' basenames = ['Makefile'] grammar = MakeGrammar diff --git a/mode/mini.py b/mode/mini.py index 75493aa..be1a0ec 100644 --- a/mode/mini.py +++ b/mode/mini.py @@ -1,9 +1,9 @@ -import method, mode2 +import method, mode -class Mini(mode2.Fundamental): +class Mini(mode.Fundamental): modename = 'Mini' def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) # delete actions relating to multiple lines self.del_action('center-view') diff --git a/mode/mutt.py b/mode/mutt.py index 0ef2a79..a97e746 100644 --- a/mode/mutt.py +++ b/mode/mutt.py @@ -1,5 +1,5 @@ import re -import color, mode2, method +import color, mode, method import mode.text from lex import Grammar, PatternRule @@ -17,7 +17,7 @@ class MuttGrammar(Grammar): PatternRule(name=r'stuff', pattern=r'[a-zA-Z0-9_]+'), ] -class Mutt(mode2.Fundamental): +class Mutt(mode.Fundamental): modename = 'Mutt' grammar = MuttGrammar() colors = { @@ -35,7 +35,7 @@ class Mutt(mode2.Fundamental): 'stuff': ('default', 'default'), } def __init__(self, w): - mode2.Fundamental.__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',)) diff --git a/mode/nasm.py b/mode/nasm.py index aaeb36b..6ea60eb 100644 --- a/mode/nasm.py +++ b/mode/nasm.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule class StringGrammar(Grammar): @@ -26,7 +26,7 @@ class NasmGrammar(Grammar): ] -class Nasm(mode2.Fundamental): +class Nasm(mode.Fundamental): modename = 'nasm' extensions = ['.s'] grammar = NasmGrammar diff --git a/mode/ocaml.py b/mode/ocaml.py index 39b05eb..d39a63d 100644 --- a/mode/ocaml.py +++ b/mode/ocaml.py @@ -1,5 +1,5 @@ import commands, os.path, sets, string, sys, traceback -import color, completer, default, mode2, method, regex, tab2 +import color, completer, default, mode, method, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, NocasePatternRule @@ -54,7 +54,7 @@ class OcamlGrammar(Grammar): PatternRule(r'prefix', r'[!?~][-!$%&*+\./:<=>?@^|~]*'), ] -class Ocaml(mode2.Fundamental): +class Ocaml(mode.Fundamental): modename = 'ocaml' extensions = ['.mli', '.ml'] grammar = OcamlGrammar @@ -88,7 +88,7 @@ class Ocaml(mode2.Fundamental): 'float': ('default', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/perl.py b/mode/perl.py index 72ad4a8..31d7440 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -1,5 +1,5 @@ import re, sets, string, sys -import color, commands, default, method, mode2, regex, tab2 +import color, commands, default, method, mode, regex, tab from point import Point from lex import Grammar, PatternRule, ContextPatternRule, RegionRule, OverridePatternRule, PatternGroupRule from method import Argument, Method, WrapParagraph @@ -129,7 +129,7 @@ class PerlGrammar(Grammar): PatternRule(r"eol", r"\n$"), ] -class PerlTabber(tab2.StackTabber): +class PerlTabber(tab.StackTabber): def is_base(self, y): if y == 0: return True @@ -139,11 +139,11 @@ class PerlTabber(tab2.StackTabber): t = highlighter.tokens[y][0] return t.name == 'keyword' and t.string == 'sub' def _handle_open_token(self, currlvl, y, i): - currlvl = tab2.StackTabber._handle_open_token(self, currlvl, y, i) + currlvl = tab.StackTabber._handle_open_token(self, currlvl, y, i) return currlvl def _handle_close_token(self, currlvl, y, i): self._opt_pop('cont') - currlvl = tab2.StackTabber._handle_close_token(self, currlvl, y, i) + currlvl = tab.StackTabber._handle_close_token(self, currlvl, y, i) token = self.get_token(y, i) if self.is_rightmost_token(y, i): if token.string == '}': @@ -194,7 +194,7 @@ class PerlTabber(tab2.StackTabber): self._opt_append('cont', currlvl + 4) return currlvl -class Perl(mode2.Fundamental): +class Perl(mode.Fundamental): modename = 'Perl' extensions = ['.pl', '.pm'] detection = ['perl'] @@ -301,7 +301,7 @@ class Perl(mode2.Fundamental): 'translate.null': ('magenta', 'default'), } def __init__(self, w): - mode2.Fundamental.__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',)) diff --git a/mode/python.py b/mode/python.py index 059cc13..2b2c70d 100644 --- a/mode/python.py +++ b/mode/python.py @@ -1,5 +1,5 @@ import commands, os.path, sets, string, sys, traceback -import color, completer, default, mode2, method, regex, tab2 +import color, completer, default, mode, method, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule @@ -50,12 +50,12 @@ class PythonGrammar(Grammar): PatternRule(r'eol', r'\n$'), ] -class PythonTabber(tab2.StackTabber): +class PythonTabber(tab.StackTabber): # NOTE: yield might initially seem like an endlevel name, but it's not one. endlevel_names = ('pass', 'return', 'raise', 'break', 'continue') startlevel_names = ('if', 'try', 'class', 'def', 'for', 'while', 'try') def __init__(self, m): - tab2.StackTabber.__init__(self, m) + tab.StackTabber.__init__(self, m) self.base_level = 0 def is_base(self, y): @@ -118,7 +118,7 @@ class PythonTabber(tab2.StackTabber): def _handle_close_token(self, currlvl, y, i): try: - return tab2.StackTabber._handle_close_token(self, currlvl, y, i) + return tab.StackTabber._handle_close_token(self, currlvl, y, i) except: return currlvl @@ -177,7 +177,7 @@ class PythonTabber(tab2.StackTabber): self._append(token.string, currlvl + 4) return currlvl -class Python(mode2.Fundamental): +class Python(mode.Fundamental): modename = 'Python' extensions = ['.py'] detection = ['python'] @@ -210,7 +210,7 @@ class Python(mode2.Fundamental): 'system_identifier': ('cyan', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) # tag matching self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) diff --git a/mode/replace.py b/mode/replace.py index 9eae4a8..57bcaa5 100644 --- a/mode/replace.py +++ b/mode/replace.py @@ -1,12 +1,12 @@ import re, sets, string -import color, method, minibuffer, mode2, searchutil +import color, method, minibuffer, mode, searchutil from point import Point -class Replace(mode2.Fundamental): +class Replace(mode.Fundamental): modename = 'Replace' def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.actions = {} self.bindings = {} diff --git a/mode/rst.py b/mode/rst.py index 6c4c007..581c773 100644 --- a/mode/rst.py +++ b/mode/rst.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule, PatternGroupRule class RSTString(Grammar): @@ -40,7 +40,7 @@ class RSTGrammar(Grammar): PatternRule(r'enumeration', r'^ *(?:[0-9]+|#)\.'), ] -class RST(mode2.Fundamental): +class RST(mode.Fundamental): modename = 'RST' extensions = ['.rst'] grammar = RSTGrammar diff --git a/mode/scheme.py b/mode/scheme.py index b075970..c79446c 100644 --- a/mode/scheme.py +++ b/mode/scheme.py @@ -1,5 +1,5 @@ import commands, os.path, sets, string, sys, traceback -import color, completer, default, mode2, method, regex, tab2 +import color, completer, default, mode, method, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule import mode.lisp @@ -25,7 +25,7 @@ class SchemeGrammar(Grammar): PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'), ] -class Scheme(mode2.Fundamental): +class Scheme(mode.Fundamental): modename = 'Scheme' extensions = ['.scm'] tabwidth = 2 @@ -51,7 +51,7 @@ class Scheme(mode2.Fundamental): 'number': ('default', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/search.py b/mode/search.py index 36cfcc3..66d24ff 100644 --- a/mode/search.py +++ b/mode/search.py @@ -1,15 +1,15 @@ import re, sets, string -import color, method, minibuffer, mode2, searchutil +import color, method, minibuffer, mode, searchutil from point import Point selected_color = 'magenta' unselected_color = 'yellow' -class Search(mode2.Fundamental): +class Search(mode.Fundamental): modename = 'Search' def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) # clear out all the defaults that we don't want/need self.actions = {} diff --git a/mode/sh.py b/mode/sh.py index e4f2749..21e61e4 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -1,5 +1,5 @@ import commands -import color, mode2, tab2 +import color, mode, tab from lex import Grammar, PatternRule, RegionRule from method import Method @@ -74,7 +74,7 @@ class ShGrammar(Grammar): CaseGrammar.rules[0].pairs[0] = (ShGrammar, CaseGrammar.rules[0].pairs[0][1]) #ShGrammar.rules[2].pairs[0] = (ShGrammar, ShGrammar.rules[0].pairs[0][1]) -class ShTabber(tab2.StackTabber): +class ShTabber(tab.StackTabber): def is_base(self, y): if y == 0: return True @@ -89,7 +89,7 @@ class ShTabber(tab2.StackTabber): # we have to ignore ) when used in "case" statements. return currlvl else: - return tab2.StackTabber._handle_close_token(self, currlvl, y, i) + return tab.StackTabber._handle_close_token(self, currlvl, y, i) def _handle_other_token(self, currlvl, y, i): token = self.get_token(y, i) fqname = token.fqname() @@ -101,7 +101,7 @@ class ShTabber(tab2.StackTabber): self._opt_pop("cont") return currlvl -class Sh(mode2.Fundamental): +class Sh(mode.Fundamental): modename = 'sh' paths = ['/etc/profile'] basenames = ['.bashrc', '.bash_profile', '.profile'] @@ -150,7 +150,7 @@ class Sh(mode2.Fundamental): 'continuation': ('red', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_action_and_bindings(ShCheckSyntax(), ('C-c s',)) class ShCheckSyntax(Method): diff --git a/mode/sql.py b/mode/sql.py index af72b43..6d07a65 100644 --- a/mode/sql.py +++ b/mode/sql.py @@ -1,4 +1,4 @@ -import mode2, tab2 +import mode, tab from lex import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule from mode.python import StringGrammar @@ -62,7 +62,7 @@ class SqlGrammar(Grammar): PatternRule(r'eol', r'\n'), ] -class SqlTabber(tab2.StackTabber): +class SqlTabber(tab.StackTabber): wst = ('null', 'eol',) def is_base(self, y): if y == 0: @@ -92,7 +92,7 @@ class SqlTabber(tab2.StackTabber): self._opt_pop("cont") return currlvl -class Sql(mode2.Fundamental): +class Sql(mode.Fundamental): modename = 'Sql' extensions = ['.sql'] grammar = SqlGrammar @@ -129,7 +129,7 @@ class Sql(mode2.Fundamental): 'function.definition.end': ('magenta', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/text.py b/mode/text.py index 1a8e95e..5e21f94 100644 --- a/mode/text.py +++ b/mode/text.py @@ -1,4 +1,4 @@ -import color, mode2, method, ispell +import color, mode, method, ispell from lex import Token, Rule, PatternRule, RegionRule, Grammar class WordRule(PatternRule): @@ -34,7 +34,7 @@ class TextGrammar(Grammar): PatternRule(r'stuff', r'[a-zA-Z0-9_]+'), ] -class Text(mode2.Fundamental): +class Text(mode.Fundamental): modename = 'Text' extensions=['.txt'] grammar = TextGrammar @@ -47,7 +47,7 @@ class Text(mode2.Fundamental): 'stuff': ('default', 'default'), } def __init__(self, w): - mode2.Fundamental.__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(method.WrapParagraph(), ('M-q',)) diff --git a/mode/text2.py b/mode/text2.py index ad21bc2..82fcff2 100644 --- a/mode/text2.py +++ b/mode/text2.py @@ -1,4 +1,4 @@ -import color, mode2, mode.text, method, ispell +import color, mode, mode.text, method, ispell from lex import Token, Rule, PatternRule, RegionRule, Grammar from mode.text import WordRule, ContinuedRule diff --git a/mode/tt.py b/mode/tt.py index cdfa9ba..be6d68c 100644 --- a/mode/tt.py +++ b/mode/tt.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule #from mode.xml import TagGrammar from mode.perl import StringGrammar @@ -28,7 +28,7 @@ class TemplateGrammar(Grammar): RegionRule(r'tag', r''), ] -class Template(mode2.Fundamental): +class Template(mode.Fundamental): modename = 'Template' extensions = ['.tt'] grammar = TemplateGrammar @@ -58,7 +58,7 @@ class Template(mode2.Fundamental): 'tag.end': ('default', 'default'), } def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) diff --git a/mode/which.py b/mode/which.py index 6423ae6..27850d8 100644 --- a/mode/which.py +++ b/mode/which.py @@ -1,17 +1,17 @@ -import color, method, mode2 +import color, method, mode from point import Point -class Which(mode2.Fundamental): +class Which(mode.Fundamental): modename = 'Which' def __init__(self, w): - mode2.Fundamental.__init__(self, w) + mode.Fundamental.__init__(self, w) old_mode = w.buffer.method.old_window.mode self.bindings = dict(old_mode.bindings) def handle_token(self, t): '''self.handle_token(token): handles input "token"''' self.window.active_point = None try: - act = mode2.Handler.handle_token(self, t) + act = mode.Handler.handle_token(self, t) if act is None: return else: @@ -19,7 +19,7 @@ class Which(mode2.Fundamental): self.window.application.set_error(s) self._end() except Exception, e: - if mode2.DEBUG: + if mode.DEBUG: raise else: err = "%s in mode '%s'" % (e, self.name()) diff --git a/mode/xml.py b/mode/xml.py index 26a2f5c..1af5c28 100644 --- a/mode/xml.py +++ b/mode/xml.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode from lex import Grammar, PatternRule, RegionRule class TagGrammar(Grammar): @@ -17,7 +17,7 @@ class XMLGrammar(Grammar): RegionRule(r'tag', r'<', TagGrammar, r'/?>'), ] -class XML(mode2.Fundamental): +class XML(mode.Fundamental): modename = 'XML' extensions = ['.xml', '.xml.in'] grammar = XMLGrammar diff --git a/window2.py b/window2.py index e35c178..7870982 100644 --- a/window2.py +++ b/window2.py @@ -1,5 +1,5 @@ import os.path, string -import highlight2, regex +import highlight, regex from point import Point WORD_LETTERS = list(string.letters + string.digits) @@ -83,7 +83,7 @@ class Window(object): self.mode = m modename = m.name() if modename not in self.buffer.highlights and m.lexer is not None: - self.buffer.highlights[modename] = highlight2.Highlighter(m.lexer) + self.buffer.highlights[modename] = highlight.Highlighter(m.lexer) self.buffer.highlights[modename].highlight(self.buffer.lines) #self.redraw()