From 3c605f85dab426d0aefe36e83aa213eaef97ab3e Mon Sep 17 00:00:00 2001 From: moculus Date: Sat, 8 Nov 2008 16:18:48 +0000 Subject: [PATCH] renamed method.DATATYPES --HG-- branch : pmacs2 --- application.py | 38 +++++++++++++++----------------------- completer.py | 17 +++++++++++++---- method/__init__.py | 15 ++------------- method/buffers.py | 2 +- method/cvs.py | 2 +- method/help.py | 2 +- method/introspect.py | 2 +- method/move.py | 4 +++- method/search.py | 2 +- method/shell.py | 2 +- method/svn.py | 2 +- mode/shellmini.py | 4 ++-- 12 files changed, 42 insertions(+), 50 deletions(-) diff --git a/application.py b/application.py index 880a575..6af6730 100755 --- a/application.py +++ b/application.py @@ -3,7 +3,8 @@ import curses, curses.ascii, getpass, os, re, string, sys, termios, time import traceback from subprocess import Popen, PIPE, STDOUT -import buffer, buffer.about, buffer.color, buffer.console, buffer.data, buffer.fs +import buffer, buffer.about, buffer.color, buffer.console, buffer.data +import buffer.fs import bufferlist, color, completer, keyinput, method, minibuffer, mode import util, window from point import Point @@ -15,8 +16,6 @@ class Application(object): self.y, self.x = self.stdscr.getmaxyx() # initialize some basic stuff - # a highlighted_range contains three things: (window, start_p, end_p) - #self.state = defaultdict(lambda: {}) self.state = {} self.config = {} self.highlighted_ranges = [] @@ -73,7 +72,6 @@ class Application(object): curses.use_default_colors() color.default_color = True except: - # guess we weren't on 2.4 color.default_color = False color.init() @@ -116,7 +114,6 @@ class Application(object): 'tt', 'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', 'latex', 'insertmini', 'conf', 'haskell', 'erlang', 'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk', - 'bds', #XYZ 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', ) for name in names: @@ -129,11 +126,9 @@ class Application(object): obj = method.OverwriteChar(c) self.methods[obj.name] = obj - # window/slot height/width + # buffer list stuff height = self.y - 1 width = self.x - - # buffer list stuff self.bufferlist = bufferlist.BufferList(height, width) self.active_slot = 0 self.complete_slot = None @@ -145,7 +140,6 @@ class Application(object): # initialize our buffers # note that only the first buffer will be initially visible buffers.append(buffer.about.AboutBuffer()) - #buffers.append(buffer.console.ConsoleBuffer()) if self.rcerror: buffers.insert(0, buffer.data.DataBuffer('*RcError*', self.rcerror)) @@ -159,7 +153,7 @@ class Application(object): self.bufferlist.set_slot(self.active_slot, buffers[0]) # see if the user has requested that we go to a particular line - if jump_to_line: + if not self.rcerror and jump_to_line: w = self.bufferlist.slots[0].window self.methods['goto-line'].execute(w, lineno=jump_to_line) @@ -173,15 +167,15 @@ class Application(object): self.registers = {} # initialize tab handlers - method.DATATYPES['path'] = completer.FileCompleter(self) - method.DATATYPES['buffer'] = completer.BufferCompleter(self) - method.DATATYPES['command'] = completer.CommandCompleter(self) - method.DATATYPES['shell'] = completer.ShellCompleter(self) - method.DATATYPES['config'] = completer.ConfigCompleter(self) - method.DATATYPES['method'] = completer.MethodCompleter(self) - method.DATATYPES['register'] = completer.RegisterCompleter(self) - method.DATATYPES['mode'] = completer.ModeCompleter(self) - method.DATATYPES['token'] = completer.TokenCompleter(self) + completer.set('path', completer.FileCompleter(self)) + completer.set('buffer', completer.BufferCompleter(self)) + completer.set('command', completer.CommandCompleter(self)) + completer.set('shell', completer.ShellCompleter(self)) + completer.set('config', completer.ConfigCompleter(self)) + completer.set('method', completer.MethodCompleter(self)) + completer.set('register', completer.RegisterCompleter(self)) + completer.set('mode', completer.ModeCompleter(self)) + completer.set('token', completer.TokenCompleter(self)) # set up curses self.win = curses.newwin(self.y, self.x, 0, 0) @@ -190,7 +184,6 @@ class Application(object): curses.cbreak() curses.noecho() curses.nonl() - # for non-blocking junk curses.halfdelay(1) curses.def_prog_mode() @@ -228,7 +221,6 @@ class Application(object): if not opened: previous = self.bufferlist.slots[n].window.buffer - #lines = ["This is a completion buffer:", ""] lines = [] clen = len(candidates) if clen > self.bufferlist.slots[n].height: @@ -270,8 +262,8 @@ class Application(object): self.close_buffer(w.buffer) self.complete_slot = None - def set_completer(self, datatype, completer): - method.DATATYPES[datatype] = completer + def set_completer(self, datatype, comp): + completer.set(datatype, comp) # this sets up a mode, as well as optionally adding information on when to # auto-load the mode diff --git a/completer.py b/completer.py index bf5826f..f3d47e6 100644 --- a/completer.py +++ b/completer.py @@ -1,6 +1,15 @@ import glob, os, pwd import method, util +_completers = {} + +def set(name, completer): + global _completers + _completers[name] = completer + +def get(*args): + return _completers.get(*args) + def find_common_string(candidates): if len(candidates) == 0: return "" @@ -50,7 +59,7 @@ class FileCompleter(Completer): # ignore some suffixes by default, unless the only possible completions # ALL have ignored-suffixes, in which case just return them all. - cand2 = [] + candidates2 = [] for c in candidates: ok = True for suffix in self.application.config['ignore-suffix']: @@ -58,9 +67,9 @@ class FileCompleter(Completer): ok = False break if ok: - cand2.append(c) - if cand2: - candidates = cand2 + candidates2.append(c) + if candidates2: + candidates = candidates2 for i in range(0, len(candidates)): c = candidates[i] diff --git a/method/__init__.py b/method/__init__.py index a11de8e..5eee318 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -1,20 +1,9 @@ import os, commands, re, tempfile from subprocess import Popen, PIPE, STDOUT -import buffer, default, dirutil, regex, util, window +import buffer, completer, default, dirutil, regex, util, window from point import Point -DATATYPES = { - "path": None, - "buffer": None, - "config": None, - "method": None, - "register": None, - "command": None, - "shell": None, - "shellcommand": None, -} - class MethodError(Exception): pass @@ -63,7 +52,7 @@ class Argument(object): vargs2[self.name] = self.coerce_to_type(v) app.close_mini_buffer() method.execute(w, **vargs2) - tabber = DATATYPES.get(self.datatype, None) + tabber = completer.get(self.datatype) if d is not None: p = self.prompt + "(%s) " % (d) else: diff --git a/method/buffers.py b/method/buffers.py index 9189e26..3ad6111 100644 --- a/method/buffers.py +++ b/method/buffers.py @@ -3,7 +3,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, regex, util, window from point import Point -from method import DATATYPES, Method, Argument, arg +from method import Method, Argument, arg class OpenFile(Method): '''Open file in a new buffer, or go to file's open buffer''' diff --git a/method/cvs.py b/method/cvs.py index fcc6433..e75658b 100644 --- a/method/cvs.py +++ b/method/cvs.py @@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, lex, regex, util, window from point import Point -from method import DATATYPES, Method, Argument, arg +from method import Method, Argument, arg class CvsCommit(Method): '''diff the current file with the version in CVS''' diff --git a/method/help.py b/method/help.py index 311fff2..9d72be7 100644 --- a/method/help.py +++ b/method/help.py @@ -5,7 +5,7 @@ import buffer, buffer.about import default, dirutil, regex, util, window from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class ShowBindingsBuffer(Method): '''Dump all keybindings for current mode into a new buffer''' diff --git a/method/introspect.py b/method/introspect.py index 29c8d1d..797966e 100644 --- a/method/introspect.py +++ b/method/introspect.py @@ -6,7 +6,7 @@ import completer, default, dirutil, regex, util, window import mode.mini from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class DumpContext(Method): '''debug context''' diff --git a/method/move.py b/method/move.py index 3966d99..c064958 100644 --- a/method/move.py +++ b/method/move.py @@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, regex, util, window from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class StartOfLine(Method): '''Move the cursor to the start of the current line''' @@ -45,10 +45,12 @@ class PageDown(Method): class GotoBeginning(Method): '''Move the cursor to the beginning of the buffer''' def _execute(self, w, **vargs): + w.set_mark() w.goto_beginning() class GotoEnd(Method): '''Move the cursor to the end of the buffer''' def _execute(self, w, **vargs): + w.set_mark() w.goto_end() class RightWord(Method): diff --git a/method/search.py b/method/search.py index 061f639..6388d5a 100644 --- a/method/search.py +++ b/method/search.py @@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, regex, util, window from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class Search(Method): '''Interactive search; finds next occurance of text in buffer''' diff --git a/method/shell.py b/method/shell.py index 3738e50..c5fa99e 100644 --- a/method/shell.py +++ b/method/shell.py @@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, regex, term, util, window from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class Exec(Method): '''Execute a command in a shell and put the output in a new buffer''' diff --git a/method/svn.py b/method/svn.py index 68e946a..bb3b28f 100644 --- a/method/svn.py +++ b/method/svn.py @@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, lex, regex, util, window from point import Point -from method import DATATYPES, Method, Argument +from method import Method, Argument class SvnCommit(Method): '''diff the current file with the version in SVN''' diff --git a/mode/shellmini.py b/mode/shellmini.py index e7c0bd6..ce91b70 100644 --- a/mode/shellmini.py +++ b/mode/shellmini.py @@ -85,9 +85,9 @@ class ShellTab(Method): s1 = curr_t.string if(curr_i == 0) and '/' not in s1: - completer = method.DATATYPES['command'] + completer = completer.get['command'] else: - completer = method.DATATYPES['path'] + completer = completer.get['path'] s2, exists, complete = completer.tab_string(s1, w) w.delete(Point(curr_t.x, curr_t.y), Point(curr_t.end_x(), curr_t.y))