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