1 |
root |
1.4 |
#! perl |
2 |
|
|
|
3 |
elmex |
1.1 |
sub on_keyboard_command { |
4 |
root |
1.7 |
my ($self, $cmd) = @_; |
5 |
elmex |
1.2 |
|
6 |
|
|
$cmd eq "selection:rot13" |
7 |
root |
1.7 |
and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
8 |
elmex |
1.3 |
|
9 |
|
|
() |
10 |
elmex |
1.1 |
} |
11 |
root |
1.5 |
|
12 |
root |
1.8 |
my @patterns = ( |
13 |
|
|
# urls |
14 |
|
|
qr{ ([a-z0-9.+\-]+://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+) }x, |
15 |
root |
1.9 |
|
16 |
|
|
# shell-like argument quoting |
17 |
|
|
qr{\G\s*( |
18 |
|
|
(?: |
19 |
|
|
[^"'\\ \t]+ |
20 |
|
|
| \\. |
21 |
|
|
| " ([^\\"]+ | \\. )* " |
22 |
|
|
| ' [^']* ' |
23 |
|
|
)+ |
24 |
|
|
)}xs, |
25 |
root |
1.8 |
); |
26 |
|
|
|
27 |
root |
1.6 |
sub on_sel_extend { |
28 |
root |
1.7 |
my ($self) = @_; |
29 |
root |
1.8 |
|
30 |
|
|
my ($row, $col) = $self->selection_mark; |
31 |
|
|
my $line = $self->line ($row); |
32 |
|
|
my $offset = $line->offset_of ($row, $col); |
33 |
|
|
my $text = $line->t; |
34 |
|
|
|
35 |
|
|
for my $regex (@patterns) { |
36 |
|
|
while ($text =~ /$regex/g) { |
37 |
root |
1.9 |
if ($-[1] <= $offset and $offset <= $+[1]) { |
38 |
|
|
$self->selection_beg ($line->coord_of ($-[1])); |
39 |
|
|
$self->selection_end ($line->coord_of ($+[1])); |
40 |
root |
1.8 |
return 1; |
41 |
|
|
} |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
|
45 |
root |
1.5 |
() |
46 |
|
|
} |