parent
e9077cae64
commit
c44b9d7488
|
@ -1,7 +1,7 @@
|
|||
import code, os, re, string, StringIO, sys, traceback
|
||||
import buffer, color, completer, lex, method, mode, window
|
||||
from lex import Grammar, PatternRule
|
||||
from mode.sh import ShGrammar
|
||||
from lex import Grammar, PatternRule, RegionRule
|
||||
from mode.sh import StringGrammar
|
||||
from point import Point
|
||||
from method import Method
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
|
@ -150,7 +150,7 @@ class ShellTab(Method):
|
|||
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
||||
return
|
||||
|
||||
l = lex.Lexer(w.mode, ShGrammar)
|
||||
l = lex.Lexer(w.mode, ShellMiniGrammar)
|
||||
tokens = list(l.lex([s]))
|
||||
|
||||
curr_t = None
|
||||
|
@ -163,18 +163,23 @@ class ShellTab(Method):
|
|||
if curr_t is None:
|
||||
return
|
||||
|
||||
w.set_error(repr(curr_t))
|
||||
return
|
||||
|
||||
if i == len(names) - 1:
|
||||
if obj is not None:
|
||||
newnames = dir(obj)
|
||||
if(i == 0) and '/' not in curr_t.string:
|
||||
# we are completing a command
|
||||
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)]
|
||||
# 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)]
|
||||
|
||||
s = completer.find_common_string(candidates)[len(name):]
|
||||
w.insert_string_at_cursor(s)
|
||||
|
@ -216,9 +221,16 @@ class OpenShell(Method):
|
|||
f = lambda x: None
|
||||
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):
|
||||
modename = 'ShellMini'
|
||||
grammar = ShGrammar
|
||||
grammar = ShellMiniGrammar
|
||||
actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev,
|
||||
ShellHistoryNext, ShellTab,
|
||||
ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd,
|
||||
|
|
Loading…
Reference in New Issue