branch : pmacs2
This commit is contained in:
moculus 2008-09-19 19:57:00 +00:00
parent e9077cae64
commit c44b9d7488
1 changed files with 31 additions and 19 deletions

View File

@ -1,7 +1,7 @@
import code, os, re, string, StringIO, sys, traceback import code, os, re, string, StringIO, sys, traceback
import buffer, color, completer, lex, method, mode, window import buffer, color, completer, lex, method, mode, window
from lex import Grammar, PatternRule from lex import Grammar, PatternRule, RegionRule
from mode.sh import ShGrammar from mode.sh import StringGrammar
from point import Point from point import Point
from method import Method from method import Method
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
@ -150,7 +150,7 @@ class ShellTab(Method):
w.insert_string_at_cursor(' ' * w.mode.tabwidth) w.insert_string_at_cursor(' ' * w.mode.tabwidth)
return return
l = lex.Lexer(w.mode, ShGrammar) l = lex.Lexer(w.mode, ShellMiniGrammar)
tokens = list(l.lex([s])) tokens = list(l.lex([s]))
curr_t = None curr_t = None
@ -163,18 +163,23 @@ class ShellTab(Method):
if curr_t is None: if curr_t is None:
return return
w.set_error(repr(curr_t)) if(i == 0) and '/' not in curr_t.string:
return # we are completing a command
candidates = []
if i == len(names) - 1:
if obj is not None:
newnames = dir(obj)
else: else:
newnames = set() # we are completing a path
newnames.update(__builtins__) cwd = os.getcwd()
newnames.update(w.mode.locals) if not cwd.endswith('/'):
newnames.update(w.mode.globals) cwd += '/'
candidates = [x for x in newnames if x.startswith(name)] path = cwd + curr_t.string
(d, name) = os.path.split(path)
names = []
for x in os.listdir(d):
if os.path.isdir(os.path.join(d, x)):
names.append(x + '/')
else:
names.append(x)
candidates = [x for x in names if x.startswith(name)]
s = completer.find_common_string(candidates)[len(name):] s = completer.find_common_string(candidates)[len(name):]
w.insert_string_at_cursor(s) w.insert_string_at_cursor(s)
@ -216,9 +221,16 @@ class OpenShell(Method):
f = lambda x: None f = lambda x: None
w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini') w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini')
class ShellMiniGrammar(Grammar):
rules = [
PatternRule(r'word', r"'.*'"),
PatternRule(r'word', r'"(:\\.|[^"\\])*"'),
PatternRule(r'word', r'(?:[^ \n"\'\\]|\\.)+'),
]
class ShellMini(mode.Fundamental): class ShellMini(mode.Fundamental):
modename = 'ShellMini' modename = 'ShellMini'
grammar = ShGrammar grammar = ShellMiniGrammar
actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev, actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev,
ShellHistoryNext, ShellTab, ShellHistoryNext, ShellTab,
ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd, ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd,