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 import traceback
from subprocess import Popen, PIPE, STDOUT 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 bufferlist, color, completer, keyinput, method, minibuffer, mode
import util, window import util, window
from point import Point from point import Point
@ -15,8 +16,6 @@ class Application(object):
self.y, self.x = self.stdscr.getmaxyx() self.y, self.x = self.stdscr.getmaxyx()
# initialize some basic stuff # initialize some basic stuff
# a highlighted_range contains three things: (window, start_p, end_p)
#self.state = defaultdict(lambda: {})
self.state = {} self.state = {}
self.config = {} self.config = {}
self.highlighted_ranges = [] self.highlighted_ranges = []
@ -73,7 +72,6 @@ class Application(object):
curses.use_default_colors() curses.use_default_colors()
color.default_color = True color.default_color = True
except: except:
# guess we weren't on 2.4
color.default_color = False color.default_color = False
color.init() color.init()
@ -116,7 +114,6 @@ class Application(object):
'tt', 'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', 'tt', 'text', 'text2', 'which', 'xml', 'cheetah', 'colortext',
'latex', 'insertmini', 'conf', 'haskell', 'erlang', 'latex', 'insertmini', 'conf', 'haskell', 'erlang',
'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk', 'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk',
'bds', #XYZ
'shell', 'shellmini', 'fstab', 'yacc', 'pipe', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe',
) )
for name in names: for name in names:
@ -129,11 +126,9 @@ class Application(object):
obj = method.OverwriteChar(c) obj = method.OverwriteChar(c)
self.methods[obj.name] = obj self.methods[obj.name] = obj
# window/slot height/width # buffer list stuff
height = self.y - 1 height = self.y - 1
width = self.x width = self.x
# buffer list stuff
self.bufferlist = bufferlist.BufferList(height, width) self.bufferlist = bufferlist.BufferList(height, width)
self.active_slot = 0 self.active_slot = 0
self.complete_slot = None self.complete_slot = None
@ -145,7 +140,6 @@ class Application(object):
# initialize our buffers # initialize our buffers
# note that only the first buffer will be initially visible # note that only the first buffer will be initially visible
buffers.append(buffer.about.AboutBuffer()) buffers.append(buffer.about.AboutBuffer())
#buffers.append(buffer.console.ConsoleBuffer())
if self.rcerror: if self.rcerror:
buffers.insert(0, buffer.data.DataBuffer('*RcError*', 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]) self.bufferlist.set_slot(self.active_slot, buffers[0])
# see if the user has requested that we go to a particular line # 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 w = self.bufferlist.slots[0].window
self.methods['goto-line'].execute(w, lineno=jump_to_line) self.methods['goto-line'].execute(w, lineno=jump_to_line)
@ -173,15 +167,15 @@ class Application(object):
self.registers = {} self.registers = {}
# initialize tab handlers # initialize tab handlers
method.DATATYPES['path'] = completer.FileCompleter(self) completer.set('path', completer.FileCompleter(self))
method.DATATYPES['buffer'] = completer.BufferCompleter(self) completer.set('buffer', completer.BufferCompleter(self))
method.DATATYPES['command'] = completer.CommandCompleter(self) completer.set('command', completer.CommandCompleter(self))
method.DATATYPES['shell'] = completer.ShellCompleter(self) completer.set('shell', completer.ShellCompleter(self))
method.DATATYPES['config'] = completer.ConfigCompleter(self) completer.set('config', completer.ConfigCompleter(self))
method.DATATYPES['method'] = completer.MethodCompleter(self) completer.set('method', completer.MethodCompleter(self))
method.DATATYPES['register'] = completer.RegisterCompleter(self) completer.set('register', completer.RegisterCompleter(self))
method.DATATYPES['mode'] = completer.ModeCompleter(self) completer.set('mode', completer.ModeCompleter(self))
method.DATATYPES['token'] = completer.TokenCompleter(self) completer.set('token', completer.TokenCompleter(self))
# set up curses # set up curses
self.win = curses.newwin(self.y, self.x, 0, 0) self.win = curses.newwin(self.y, self.x, 0, 0)
@ -190,7 +184,6 @@ class Application(object):
curses.cbreak() curses.cbreak()
curses.noecho() curses.noecho()
curses.nonl() curses.nonl()
# for non-blocking junk
curses.halfdelay(1) curses.halfdelay(1)
curses.def_prog_mode() curses.def_prog_mode()
@ -228,7 +221,6 @@ class Application(object):
if not opened: if not opened:
previous = self.bufferlist.slots[n].window.buffer previous = self.bufferlist.slots[n].window.buffer
#lines = ["This is a completion buffer:", ""]
lines = [] lines = []
clen = len(candidates) clen = len(candidates)
if clen > self.bufferlist.slots[n].height: if clen > self.bufferlist.slots[n].height:
@ -270,8 +262,8 @@ class Application(object):
self.close_buffer(w.buffer) self.close_buffer(w.buffer)
self.complete_slot = None self.complete_slot = None
def set_completer(self, datatype, completer): def set_completer(self, datatype, comp):
method.DATATYPES[datatype] = completer completer.set(datatype, comp)
# this sets up a mode, as well as optionally adding information on when to # this sets up a mode, as well as optionally adding information on when to
# auto-load the mode # auto-load the mode

View File

@ -1,6 +1,15 @@
import glob, os, pwd import glob, os, pwd
import method, util 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): def find_common_string(candidates):
if len(candidates) == 0: if len(candidates) == 0:
return "" return ""
@ -50,7 +59,7 @@ class FileCompleter(Completer):
# ignore some suffixes by default, unless the only possible completions # ignore some suffixes by default, unless the only possible completions
# ALL have ignored-suffixes, in which case just return them all. # ALL have ignored-suffixes, in which case just return them all.
cand2 = [] candidates2 = []
for c in candidates: for c in candidates:
ok = True ok = True
for suffix in self.application.config['ignore-suffix']: for suffix in self.application.config['ignore-suffix']:
@ -58,9 +67,9 @@ class FileCompleter(Completer):
ok = False ok = False
break break
if ok: if ok:
cand2.append(c) candidates2.append(c)
if cand2: if candidates2:
candidates = cand2 candidates = candidates2
for i in range(0, len(candidates)): for i in range(0, len(candidates)):
c = candidates[i] c = candidates[i]

View File

@ -1,20 +1,9 @@
import os, commands, re, tempfile import os, commands, re, tempfile
from subprocess import Popen, PIPE, STDOUT 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 from point import Point
DATATYPES = {
"path": None,
"buffer": None,
"config": None,
"method": None,
"register": None,
"command": None,
"shell": None,
"shellcommand": None,
}
class MethodError(Exception): class MethodError(Exception):
pass pass
@ -63,7 +52,7 @@ class Argument(object):
vargs2[self.name] = self.coerce_to_type(v) vargs2[self.name] = self.coerce_to_type(v)
app.close_mini_buffer() app.close_mini_buffer()
method.execute(w, **vargs2) method.execute(w, **vargs2)
tabber = DATATYPES.get(self.datatype, None) tabber = completer.get(self.datatype)
if d is not None: if d is not None:
p = self.prompt + "(%s) " % (d) p = self.prompt + "(%s) " % (d)
else: else:

View File

@ -3,7 +3,7 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, regex, util, window import buffer, default, dirutil, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument, arg from method import Method, Argument, arg
class OpenFile(Method): class OpenFile(Method):
'''Open file in a new buffer, or go to file's open buffer''' '''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 import buffer, default, dirutil, lex, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument, arg from method import Method, Argument, arg
class CvsCommit(Method): class CvsCommit(Method):
'''diff the current file with the version in CVS''' '''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 import default, dirutil, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class ShowBindingsBuffer(Method): class ShowBindingsBuffer(Method):
'''Dump all keybindings for current mode into a new buffer''' '''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 import mode.mini
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class DumpContext(Method): class DumpContext(Method):
'''debug context''' '''debug context'''

View File

@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, regex, util, window import buffer, default, dirutil, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class StartOfLine(Method): class StartOfLine(Method):
'''Move the cursor to the start of the current line''' '''Move the cursor to the start of the current line'''
@ -45,10 +45,12 @@ class PageDown(Method):
class GotoBeginning(Method): class GotoBeginning(Method):
'''Move the cursor to the beginning of the buffer''' '''Move the cursor to the beginning of the buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_mark()
w.goto_beginning() w.goto_beginning()
class GotoEnd(Method): class GotoEnd(Method):
'''Move the cursor to the end of the buffer''' '''Move the cursor to the end of the buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_mark()
w.goto_end() w.goto_end()
class RightWord(Method): class RightWord(Method):

View File

@ -4,7 +4,7 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, regex, util, window import buffer, default, dirutil, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class Search(Method): class Search(Method):
'''Interactive search; finds next occurance of text in buffer''' '''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 import buffer, default, dirutil, regex, term, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class Exec(Method): class Exec(Method):
'''Execute a command in a shell and put the output in a new buffer''' '''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 import buffer, default, dirutil, lex, regex, util, window
from point import Point from point import Point
from method import DATATYPES, Method, Argument from method import Method, Argument
class SvnCommit(Method): class SvnCommit(Method):
'''diff the current file with the version in SVN''' '''diff the current file with the version in SVN'''

View File

@ -85,9 +85,9 @@ class ShellTab(Method):
s1 = curr_t.string s1 = curr_t.string
if(curr_i == 0) and '/' not in s1: if(curr_i == 0) and '/' not in s1:
completer = method.DATATYPES['command'] completer = completer.get['command']
else: else:
completer = method.DATATYPES['path'] completer = completer.get['path']
s2, exists, complete = completer.tab_string(s1, w) 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)) w.delete(Point(curr_t.x, curr_t.y), Point(curr_t.end_x(), curr_t.y))