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.16 |
# "find interetsing things"-patterns |
13 |
root |
1.15 |
my @mark_patterns = ( |
14 |
root |
1.10 |
# urls, just a heuristic |
15 |
|
|
qr{( |
16 |
root |
1.12 |
(?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
17 |
|
|
[ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often |
18 |
root |
1.10 |
)}x, |
19 |
root |
1.9 |
|
20 |
root |
1.17 |
# common "parentheses" |
21 |
root |
1.18 |
qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, |
22 |
|
|
qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, |
23 |
|
|
qr{ \{ ([^{}]+?) \} }x, |
24 |
|
|
qr{ \[ ([^{}]+?) \] }x, |
25 |
root |
1.14 |
|
26 |
root |
1.17 |
# shell-like argument quoting, basically always matches |
27 |
root |
1.11 |
qr{\G [\ \t|&;<>()] *( |
28 |
root |
1.9 |
(?: |
29 |
root |
1.11 |
[^\\"'\ \t|&;<>()]+ |
30 |
root |
1.9 |
| \\. |
31 |
root |
1.13 |
| " (?: [^\\"]+ | \\. )* " |
32 |
root |
1.9 |
| ' [^']* ' |
33 |
|
|
)+ |
34 |
root |
1.14 |
)}x, |
35 |
root |
1.8 |
); |
36 |
|
|
|
37 |
root |
1.16 |
# "correct obvious? crap"-patterns |
38 |
root |
1.15 |
my @simplify_patterns = ( |
39 |
|
|
qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
40 |
root |
1.16 |
qr{^(.*)[,\-]$}, # strip off trailing , and - |
41 |
root |
1.15 |
); |
42 |
root |
1.14 |
|
43 |
root |
1.6 |
sub on_sel_extend { |
44 |
root |
1.7 |
my ($self) = @_; |
45 |
root |
1.8 |
|
46 |
|
|
my ($row, $col) = $self->selection_mark; |
47 |
|
|
my $line = $self->line ($row); |
48 |
|
|
my $offset = $line->offset_of ($row, $col); |
49 |
|
|
my $text = $line->t; |
50 |
|
|
|
51 |
root |
1.15 |
for my $regex (@mark_patterns) { |
52 |
root |
1.8 |
while ($text =~ /$regex/g) { |
53 |
root |
1.9 |
if ($-[1] <= $offset and $offset <= $+[1]) { |
54 |
root |
1.16 |
my $ofs = $-[1]; |
55 |
root |
1.15 |
my $match = $1; |
56 |
|
|
|
57 |
|
|
for my $regex (@simplify_patterns) { |
58 |
|
|
if ($match =~ $regex) { |
59 |
|
|
$match = $1; |
60 |
root |
1.16 |
$ofs += $-[1]; |
61 |
root |
1.15 |
} |
62 |
|
|
} |
63 |
|
|
|
64 |
root |
1.16 |
$self->selection_beg ($line->coord_of ($ofs)); |
65 |
|
|
$self->selection_end ($line->coord_of ($ofs + length $match)); |
66 |
root |
1.8 |
return 1; |
67 |
|
|
} |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|
71 |
root |
1.5 |
() |
72 |
|
|
} |