parent
2712aa11e1
commit
e382dcf8bb
|
@ -35,34 +35,30 @@ class IperlTab(method.Method):
|
||||||
a = w.application
|
a = w.application
|
||||||
s = w.buffer.make_string()
|
s = w.buffer.make_string()
|
||||||
|
|
||||||
x = w.logical_cursor().x
|
x2 = w.logical_cursor().x
|
||||||
if not s or s[:x].isspace():
|
if not s or s[:x2].isspace():
|
||||||
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
||||||
return
|
return
|
||||||
|
|
||||||
l = lex.Lexer(w.mode, PerlGrammar)
|
r = re.compile('^[a-zA-Z0-9_:$@*&%]$')
|
||||||
tokens = list(l.lex([s]))
|
line = s
|
||||||
|
x1 = x2
|
||||||
|
while x1 > 0 and r.match(s[x1 - 1]):
|
||||||
|
x1 -= 1
|
||||||
|
word = line[x1:x2]
|
||||||
|
|
||||||
t = None
|
w.mode.pipe.stdin.write("COMPLETE2:%d:%d:%s\n" % (x1, x2, s))
|
||||||
for t2 in tokens:
|
|
||||||
if t2.x < x and t2.end_x() >= x:
|
|
||||||
t = t2
|
|
||||||
break
|
|
||||||
if t is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
s = t.string
|
|
||||||
w.mode.pipe.stdin.write("COMPLETE:%s\n" % s)
|
|
||||||
w.mode.pipe.stdin.flush()
|
w.mode.pipe.stdin.flush()
|
||||||
(typ_, value) = w.mode._readline()
|
(typ_, value) = w.mode._readline()
|
||||||
assert typ_ == 'COMPLETIONS'
|
assert typ_ == 'COMPLETIONS', '%r %r' % (typ_, value)
|
||||||
|
|
||||||
candidates = [x for x in value.split('|') if x]
|
candidates = [x for x in value.split('|') if x]
|
||||||
w.mode._read()
|
w.mode._read()
|
||||||
|
|
||||||
if candidates:
|
if candidates:
|
||||||
s = completer.find_common_string(candidates)
|
s = completer.find_common_string(candidates)
|
||||||
w.buffer.delete(Point(t.x, 0), Point(t.end_x(), 0), force=True)
|
#w.buffer.delete(Point(t.x, 0), Point(t.end_x(), 0), force=True)
|
||||||
|
w.buffer.delete(Point(x1, 0), Point(x2, 0), force=True)
|
||||||
w.insert_string_at_cursor(s)
|
w.insert_string_at_cursor(s)
|
||||||
mode.mini.use_completion_window(a, s, candidates)
|
mode.mini.use_completion_window(a, s, candidates)
|
||||||
|
|
||||||
|
@ -108,8 +104,6 @@ class IperlMini(mode.Fundamental):
|
||||||
if type_ == 'PROMPT':
|
if type_ == 'PROMPT':
|
||||||
self.window.application.set_mini_buffer_prompt(value + ' ')
|
self.window.application.set_mini_buffer_prompt(value + ' ')
|
||||||
break
|
break
|
||||||
if type_ in ('ERROR', 'RESULT'):
|
|
||||||
value = value.replace('\\n', '\n').replace('\\\\', '\\')
|
|
||||||
value.rstrip()
|
value.rstrip()
|
||||||
if value:
|
if value:
|
||||||
output.append(value)
|
output.append(value)
|
||||||
|
|
31
tools/iperl
31
tools/iperl
|
@ -150,13 +150,16 @@ sub resolve_ref {
|
||||||
|
|
||||||
# use sigilfind to get completions for particular word(s)
|
# use sigilfind to get completions for particular word(s)
|
||||||
sub complete {
|
sub complete {
|
||||||
my ($word, $line, $x1, $x2) = @_;
|
my ($word, $line, $x) = @_;
|
||||||
|
|
||||||
|
#print STDERR "'$word' '$line' $x\n";
|
||||||
|
|
||||||
$word =~ m/^([&\$%@\*]?)(.*)$/;
|
$word =~ m/^([&\$%@\*]?)(.*)$/;
|
||||||
my $sigil = $1;
|
my $sigil = $1;
|
||||||
my $name = $2;
|
my $name = $2;
|
||||||
my $pre = substr($line, 0, $x1);
|
my $pre = substr($line, 0, $x);
|
||||||
|
|
||||||
if(length($line) == $x1 && $pre =~ m/^[ \t]*$/) {
|
if(length($line) == $x && $pre =~ m/^[ \t]*$/) {
|
||||||
# hack to handle the case where we really do want a tab
|
# hack to handle the case where we really do want a tab
|
||||||
return ("\t");
|
return ("\t");
|
||||||
}
|
}
|
||||||
|
@ -200,6 +203,8 @@ sub complete {
|
||||||
# completions.
|
# completions.
|
||||||
@candidates = map {
|
@candidates = map {
|
||||||
"${sigil}${_}"
|
"${sigil}${_}"
|
||||||
|
} grep {
|
||||||
|
$_ =~ m/^$name/
|
||||||
} sigilread($pkgname, $sigil);
|
} sigilread($pkgname, $sigil);
|
||||||
} else {
|
} else {
|
||||||
# if we don't have a sigil, the user might wanna call a function,
|
# if we don't have a sigil, the user might wanna call a function,
|
||||||
|
@ -218,7 +223,7 @@ sub complete {
|
||||||
# display completions to the user
|
# display completions to the user
|
||||||
sub draw_completions {
|
sub draw_completions {
|
||||||
my (@items) = @_;
|
my (@items) = @_;
|
||||||
my($prefix, $delim) = $pipe ? ("COMPLETIONS", "|") : ("", "\n");
|
my($prefix, $delim) = $pipe ? ("COMPLETIONS:", "|") : ("", "\n");
|
||||||
print $prefix . join($delim, @items) . "\n";
|
print $prefix . join($delim, @items) . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,13 +312,23 @@ sub main {
|
||||||
|
|
||||||
# if we're in pipe-mode then we expect input in a special form
|
# if we're in pipe-mode then we expect input in a special form
|
||||||
if($pipe) {
|
if($pipe) {
|
||||||
if($line =~ m/ENTER:(.*)$/) {
|
if($line =~ m/^ENTER:(.*)$/) {
|
||||||
$line = $1;
|
$line = $1;
|
||||||
} elsif($line =~ m/COMPLETE:(.*)$/) {
|
} elsif($line =~ m/^COMPLETE:(.*)$/) {
|
||||||
draw_completions(complete($1));
|
my $line = $1;
|
||||||
|
while($line =~ m/\G(?<=[^a-zA-Z0-9_])[a-zA-Z0-9_]/g) {}
|
||||||
|
my $x = pos($line) ? pos($line) : 0;
|
||||||
|
my $word = substr($line, $x);
|
||||||
|
draw_completions(complete($line, $word, $x));
|
||||||
|
next;
|
||||||
|
} elsif($line =~ m/^COMPLETE2:(\d+):(\d+):(.*)$/) {
|
||||||
|
my $x = $2;
|
||||||
|
my $line = $3;
|
||||||
|
my $word = substr($line, $1, $x - $1);
|
||||||
|
draw_completions(complete($line, $word, $x));
|
||||||
next;
|
next;
|
||||||
} else {
|
} else {
|
||||||
print "malformed pipe input line\n";
|
print "malformed pipe input line: $line\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue