parent
e9077cae64
commit
c44b9d7488
|
@ -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,22 +163,27 @@ 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 = []
|
||||||
|
else:
|
||||||
|
# we are completing a path
|
||||||
|
cwd = os.getcwd()
|
||||||
|
if not cwd.endswith('/'):
|
||||||
|
cwd += '/'
|
||||||
|
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)]
|
||||||
|
|
||||||
if i == len(names) - 1:
|
s = completer.find_common_string(candidates)[len(name):]
|
||||||
if obj is not None:
|
w.insert_string_at_cursor(s)
|
||||||
newnames = dir(obj)
|
mode.mini.use_completion_window(a, name, candidates)
|
||||||
else:
|
|
||||||
newnames = set()
|
|
||||||
newnames.update(__builtins__)
|
|
||||||
newnames.update(w.mode.locals)
|
|
||||||
newnames.update(w.mode.globals)
|
|
||||||
candidates = [x for x in newnames if x.startswith(name)]
|
|
||||||
|
|
||||||
s = completer.find_common_string(candidates)[len(name):]
|
|
||||||
w.insert_string_at_cursor(s)
|
|
||||||
mode.mini.use_completion_window(a, name, candidates)
|
|
||||||
|
|
||||||
class ShellBaseMethod(Method):
|
class ShellBaseMethod(Method):
|
||||||
subcls = Method
|
subcls = Method
|
||||||
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue