… | |
… | |
7 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
7 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
8 | |
8 | |
9 | () |
9 | () |
10 | } |
10 | } |
11 | |
11 | |
|
|
12 | # "find interetsing things"-patterns |
12 | my @patterns = ( |
13 | my @mark_patterns = ( |
13 | # urls, just a heuristic |
14 | # urls, just a heuristic |
14 | qr{( |
15 | qr{( |
15 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
16 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
16 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often |
17 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often |
17 | )}x, |
18 | )}x, |
|
|
19 | |
|
|
20 | # common forms of quoting |
|
|
21 | qr{(?:^|\s) [‘`] ([^‘`’']+) [’'] (?:\s|$)}x, |
18 | |
22 | |
19 | # shell-like argument quoting |
23 | # shell-like argument quoting |
20 | qr{\G [\ \t|&;<>()] *( |
24 | qr{\G [\ \t|&;<>()] *( |
21 | (?: |
25 | (?: |
22 | [^\\"'\ \t|&;<>()]+ |
26 | [^\\"'\ \t|&;<>()]+ |
23 | | \\. |
27 | | \\. |
24 | | " (?: [^\\"]+ | \\. )* " |
28 | | " (?: [^\\"]+ | \\. )* " |
25 | | ' [^']* ' |
29 | | ' [^']* ' |
26 | )+ |
30 | )+ |
27 | )}xs, |
31 | )}x, |
|
|
32 | ); |
|
|
33 | |
|
|
34 | # "correct obvious? crap"-patterns |
|
|
35 | my @simplify_patterns = ( |
|
|
36 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
|
|
37 | qr{^(.*)[,\-]$}, # strip off trailing , and - |
28 | ); |
38 | ); |
29 | |
39 | |
30 | sub on_sel_extend { |
40 | sub on_sel_extend { |
31 | my ($self) = @_; |
41 | my ($self) = @_; |
32 | |
42 | |
33 | my ($row, $col) = $self->selection_mark; |
43 | my ($row, $col) = $self->selection_mark; |
34 | my $line = $self->line ($row); |
44 | my $line = $self->line ($row); |
35 | my $offset = $line->offset_of ($row, $col); |
45 | my $offset = $line->offset_of ($row, $col); |
36 | my $text = $line->t; |
46 | my $text = $line->t; |
37 | |
47 | |
38 | for my $regex (@patterns) { |
48 | for my $regex (@mark_patterns) { |
39 | while ($text =~ /$regex/g) { |
49 | while ($text =~ /$regex/g) { |
40 | if ($-[1] <= $offset and $offset <= $+[1]) { |
50 | if ($-[1] <= $offset and $offset <= $+[1]) { |
|
|
51 | my $ofs = $-[1]; |
|
|
52 | my $match = $1; |
|
|
53 | |
|
|
54 | for my $regex (@simplify_patterns) { |
|
|
55 | if ($match =~ $regex) { |
|
|
56 | $match = $1; |
|
|
57 | $ofs += $-[1]; |
|
|
58 | } |
|
|
59 | } |
|
|
60 | |
41 | $self->selection_beg ($line->coord_of ($-[1])); |
61 | $self->selection_beg ($line->coord_of ($ofs)); |
42 | $self->selection_end ($line->coord_of ($+[1])); |
62 | $self->selection_end ($line->coord_of ($ofs + length $match)); |
43 | return 1; |
63 | return 1; |
44 | } |
64 | } |
45 | } |
65 | } |
46 | } |
66 | } |
47 | |
67 | |