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 |
root |
1.10 |
# 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 |
root |
1.9 |
|
19 |
|
|
# shell-like argument quoting |
20 |
|
|
qr{\G\s*( |
21 |
|
|
(?: |
22 |
|
|
[^"'\\ \t]+ |
23 |
|
|
| \\. |
24 |
|
|
| " ([^\\"]+ | \\. )* " |
25 |
|
|
| ' [^']* ' |
26 |
|
|
)+ |
27 |
|
|
)}xs, |
28 |
root |
1.8 |
); |
29 |
|
|
|
30 |
root |
1.6 |
sub on_sel_extend { |
31 |
root |
1.7 |
my ($self) = @_; |
32 |
root |
1.8 |
|
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 |
root |
1.9 |
if ($-[1] <= $offset and $offset <= $+[1]) { |
41 |
|
|
$self->selection_beg ($line->coord_of ($-[1])); |
42 |
|
|
$self->selection_end ($line->coord_of ($+[1])); |
43 |
root |
1.8 |
return 1; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
|
48 |
root |
1.5 |
() |
49 |
|
|
} |