renamed method.DATATYPES

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-11-08 16:18:48 +00:00
parent e66d1592ba
commit 3c605f85da
12 changed files with 42 additions and 50 deletions

View File

@ -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

View File

@ -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]

View File

@ -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:

View File

@ -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'''

View File

@ -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'''

View File

@ -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'''

View File

@ -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'''

View File

@ -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):

View File

@ -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'''

View File

@ -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'''

View File

@ -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'''

View File

@ -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))