parent
5e648b2b39
commit
78cf08ec88
54
mode/perl.py
54
mode/perl.py
|
@ -493,51 +493,41 @@ class PerlWrapParagraph(method.WrapParagraph):
|
||||||
|
|
||||||
class PerlSemanticComplete(method.introspect.TokenComplete):
|
class PerlSemanticComplete(method.introspect.TokenComplete):
|
||||||
_mini_prompt = 'Semantic Complete'
|
_mini_prompt = 'Semantic Complete'
|
||||||
def _prune_candidates(self, t, minlen, candidates):
|
def _min_completion(self, w, x1, x2, y):
|
||||||
if not candidates:
|
|
||||||
return ([], t.string)
|
|
||||||
i = len(t.string)
|
|
||||||
while i < minlen:
|
|
||||||
c = candidates[0][i]
|
|
||||||
for s in candidates:
|
|
||||||
if s[i] != c:
|
|
||||||
return (candidates, candidates[0][:i])
|
|
||||||
i += 1
|
|
||||||
return (candidates, candidates[0][:minlen])
|
|
||||||
def _min_completion(self, w, t):
|
|
||||||
a = w.application
|
a = w.application
|
||||||
a.methods['iperl-path-start'].execute(w, switch=False)
|
a.methods['iperl-path-start'].execute(w, switch=False)
|
||||||
|
|
||||||
name = buffer.IperlBuffer.create_name(w.buffer)
|
name = buffer.IperlBuffer.create_name(w.buffer)
|
||||||
b = a.get_buffer_by_name(name)
|
b = a.get_buffer_by_name(name)
|
||||||
|
|
||||||
line = w.buffer.lines[t.y]
|
line = w.buffer.lines[y]
|
||||||
(x1, x2) = (t.x, t.end_x())
|
|
||||||
candidates = b.readline_completions(x1, x2, line)
|
candidates = b.readline_completions(x1, x2, line)
|
||||||
|
if not candidates:
|
||||||
|
return ([], line[x1:x2])
|
||||||
|
|
||||||
minlen = None
|
i = 0
|
||||||
for candidate in candidates:
|
while i < len(candidates[0]):
|
||||||
if minlen is None:
|
for s in candidates:
|
||||||
minlen = len(candidate)
|
if len(s) <= i or s[i] != candidates[0][i]:
|
||||||
else:
|
break
|
||||||
minlen = min(minlen, len(candidate))
|
i += 1
|
||||||
|
return (candidates, candidates[0][:i])
|
||||||
return self._prune_candidates(t, minlen, candidates)
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
t = w.get_token2()
|
b = w.buffer
|
||||||
|
x2, y = w.logical_cursor().xy()
|
||||||
if t is None:
|
if y >= len(b.lines):
|
||||||
w.set_error("No token to complete!")
|
|
||||||
return
|
|
||||||
elif regex.reserved_token_names.match(t.name):
|
|
||||||
w.set_error("Will not complete reserved token")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
(candidates, result) = self._min_completion(w, t)
|
x1 = x2
|
||||||
|
while x1 > 0 and b.lines[y][x1 - 1] in "$@%*&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_:":
|
||||||
|
x1 -= 1
|
||||||
|
assert x1 >= 0, "%r %r %r" % (x1, x2, len(b.lines[y]))
|
||||||
|
|
||||||
|
(candidates, result) = self._min_completion(w, x1, x2, y)
|
||||||
|
|
||||||
if candidates:
|
if candidates:
|
||||||
p1 = Point(t.x, t.y)
|
p1 = Point(x1, y)
|
||||||
p2 = Point(t.end_x(), t.y)
|
p2 = Point(x2, y)
|
||||||
w.buffer.delete(p1, p2)
|
w.buffer.delete(p1, p2)
|
||||||
w.insert_string(p1, result)
|
w.insert_string(p1, result)
|
||||||
|
|
||||||
|
|
24
tools/iperl
24
tools/iperl
|
@ -72,6 +72,7 @@ sub readline_complete {
|
||||||
my ($word, $line, $x) = @_;
|
my ($word, $line, $x) = @_;
|
||||||
my $full_word = readline_full_word($word, $line, $x);
|
my $full_word = readline_full_word($word, $line, $x);
|
||||||
my $delta = length($full_word) - length($word);
|
my $delta = length($full_word) - length($word);
|
||||||
|
#print STDERR "XYZ '$word' '$full_word' '$delta'\n";
|
||||||
my @candidates = complete($full_word);
|
my @candidates = complete($full_word);
|
||||||
return map { substr($_, $delta) } @candidates;
|
return map { substr($_, $delta) } @candidates;
|
||||||
}
|
}
|
||||||
|
@ -131,8 +132,9 @@ sub sigil_complete {
|
||||||
return @names;
|
return @names;
|
||||||
}
|
}
|
||||||
sub pkg_complete {
|
sub pkg_complete {
|
||||||
my ($pkg, $sep, $name) = @_;
|
my ($pkg, $sep, $name, $returnself) = @_;
|
||||||
my @pkgs = _pkg_complete($pkg, $sep, $name, !($pkg && $sep));
|
$returnself = defined($returnself) ? $returnself : !($pkg && $sep);
|
||||||
|
my @pkgs = _pkg_complete($pkg, $sep, $name, $returnself);
|
||||||
my $base = $pkg . $sep . $name;
|
my $base = $pkg . $sep . $name;
|
||||||
return grep {$_ =~ m/^$base/ } @pkgs;
|
return grep {$_ =~ m/^$base/ } @pkgs;
|
||||||
}
|
}
|
||||||
|
@ -179,12 +181,13 @@ sub complete {
|
||||||
} elsif($word =~ m/^${hash_re}(.*)$/) {
|
} elsif($word =~ m/^${hash_re}(.*)$/) {
|
||||||
# literal hash
|
# literal hash
|
||||||
my ($hash, $key) = ($1, $2);
|
my ($hash, $key) = ($1, $2);
|
||||||
#print STDERR "\n$hash|$key\n";
|
|
||||||
my $obj = eval("\\\%$hash");
|
my $obj = eval("\\\%$hash");
|
||||||
if($obj) {
|
my @keys = keys(%$obj);
|
||||||
@words = map { "\$${hash}{$_" } grep { $_ =~ m/^$key/ } keys(%$obj);
|
unless(@keys) {
|
||||||
|
$obj = eval("\\\%${PKG}::${hash}");
|
||||||
|
@keys = keys(%$obj);
|
||||||
}
|
}
|
||||||
#print STDERR Dumper(\@words);
|
@words = map { "\$${hash}{$_" } grep { $_ =~ m/^$key/ } @keys;
|
||||||
} elsif($word =~ m/^${hash_ref_re}(.*)$/) {
|
} elsif($word =~ m/^${hash_ref_re}(.*)$/) {
|
||||||
# hashref
|
# hashref
|
||||||
my ($hash, $key) = ($1, $2);
|
my ($hash, $key) = ($1, $2);
|
||||||
|
@ -211,12 +214,14 @@ sub complete {
|
||||||
@words = sigil_complete($sigil, $sigil, $pkg, $sep, $name);
|
@words = sigil_complete($sigil, $sigil, $pkg, $sep, $name);
|
||||||
} else {
|
} else {
|
||||||
push(@words, pkg_complete($pkg, $sep, $name));
|
push(@words, pkg_complete($pkg, $sep, $name));
|
||||||
|
push(@words, pkg_complete($name, '', '', 0)) unless $oldpkg;
|
||||||
push(@words, sigil_complete('&', '', $pkg, $sep, $name));
|
push(@words, sigil_complete('&', '', $pkg, $sep, $name));
|
||||||
}
|
}
|
||||||
if($oldpkg ne $pkg) {
|
if($oldpkg ne $pkg) {
|
||||||
@words = map { $_ =~ s/^${pkg}${sep}//; $_ } @words;
|
@words = map { $_ =~ s/${pkg}${sep}//; $_ } @words;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#print STDERR "XYZ" . join("|", @words) . "\n";
|
||||||
return sort(@words);
|
return sort(@words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +346,8 @@ sub run {
|
||||||
my $x = $2;
|
my $x = $2;
|
||||||
my $line = $3;
|
my $line = $3;
|
||||||
my $word = substr($line, $1, $x - $1);
|
my $word = substr($line, $1, $x - $1);
|
||||||
my @candidates = readline_complete($line, $word, $x);
|
#print STDERR "ABC '$1' '$2' '$3' '$word'\n";
|
||||||
|
my @candidates = readline_complete($word, $line, $x);
|
||||||
draw_completions(@candidates);
|
draw_completions(@candidates);
|
||||||
next;
|
next;
|
||||||
} else {
|
} else {
|
||||||
|
@ -387,7 +393,7 @@ sub run {
|
||||||
} else {
|
} else {
|
||||||
# we're dealing with a complete statement, so execute and display
|
# we're dealing with a complete statement, so execute and display
|
||||||
$input .= $line;
|
$input .= $line;
|
||||||
my @results = map { repr($_) } eval($input);
|
my @results = map { repr($_) } eval("package $PKG; $input");
|
||||||
if($@) {
|
if($@) {
|
||||||
print $@;
|
print $@;
|
||||||
} elsif(scalar(@results) == 0) {
|
} elsif(scalar(@results) == 0) {
|
||||||
|
|
Loading…
Reference in New Issue