|
|
1 | #! perl |
|
|
2 | |
1 | sub on_keyboard_command { |
3 | sub on_keyboard_command { |
2 | my ($term, $cmd) = @_; |
4 | my ($self, $cmd) = @_; |
|
|
5 | |
3 | $cmd eq "selection:rot13" |
6 | $cmd eq "selection:rot13" |
4 | and $term->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $term->selection); |
7 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
|
|
8 | |
|
|
9 | () |
5 | } |
10 | } |
|
|
11 | |
|
|
12 | my @patterns = ( |
|
|
13 | # urls |
|
|
14 | qr{ ([a-z0-9.+\-]+://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+) }x, |
|
|
15 | ); |
|
|
16 | |
|
|
17 | sub on_sel_extend { |
|
|
18 | my ($self) = @_; |
|
|
19 | |
|
|
20 | my ($row, $col) = $self->selection_mark; |
|
|
21 | my $line = $self->line ($row); |
|
|
22 | my $offset = $line->offset_of ($row, $col); |
|
|
23 | my $text = $line->t; |
|
|
24 | |
|
|
25 | for my $regex (@patterns) { |
|
|
26 | while ($text =~ /$regex/g) { |
|
|
27 | if ($-[0] <= $offset and $offset <= $+[0]) { |
|
|
28 | $self->selection_beg ($line->coord_of ($-[0])); |
|
|
29 | $self->selection_end ($line->coord_of ($+[0])); |
|
|
30 | return 1; |
|
|
31 | } |
|
|
32 | } |
|
|
33 | } |
|
|
34 | |
|
|
35 | () |
|
|
36 | } |