… | |
… | |
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 @mark_patterns = ( |
13 | my @mark_patterns = ( |
|
|
14 | qr{([[:alnum:]]+)}, |
|
|
15 | |
|
|
16 | # common "parentheses" |
|
|
17 | qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, |
|
|
18 | qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, |
|
|
19 | qr{ \{ ([^{}]+?) \} }x, |
|
|
20 | qr{ \[ ([^{}]+?) \] }x, |
|
|
21 | |
13 | # urls, just a heuristic |
22 | # urls, just a heuristic |
14 | qr{( |
23 | qr{( |
15 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
24 | (?: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 |
25 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) |
17 | )}x, |
26 | )}x, |
18 | |
27 | |
19 | # common forms of quoting |
28 | # shell-like argument quoting, basically always matches |
20 | qr{(?:^|\s) [‘`] ([^‘`’']+) [’'] (?:\s|$)}x, |
|
|
21 | |
|
|
22 | # shell-like argument quoting |
|
|
23 | qr{\G [\ \t|&;<>()] *( |
29 | qr{\G [\ \t|&;<>()] *( |
24 | (?: |
30 | (?: |
25 | [^\\"'\ \t|&;<>()]+ |
31 | [^\\"'\ \t|&;<>()]+ |
26 | | \\. |
32 | | \\. |
27 | | " (?: [^\\"]+ | \\. )* " |
33 | | " (?: [^\\"]+ | \\. )* " |
28 | | ' [^']* ' |
34 | | ' [^']* ' |
29 | )+ |
35 | )+ |
30 | )}x, |
36 | )}x, |
31 | ); |
37 | ); |
32 | |
38 | |
|
|
39 | # "correct obvious? crap"-patterns |
33 | my @simplify_patterns = ( |
40 | my @simplify_patterns = ( |
34 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
41 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
35 | qr{^(.*)[,\-]$}, |
42 | qr{^(.*)[,\-]$}, # strip off trailing , and - |
36 | ); |
43 | ); |
37 | |
44 | |
38 | sub on_sel_extend { |
45 | sub on_sel_extend { |
39 | my ($self) = @_; |
46 | my ($self, $time) = @_; |
40 | |
47 | |
41 | my ($row, $col) = $self->selection_mark; |
48 | my ($row, $col) = $self->selection_mark; |
42 | my $line = $self->line ($row); |
49 | my $line = $self->line ($row); |
43 | my $offset = $line->offset_of ($row, $col); |
|
|
44 | my $text = $line->t; |
50 | my $text = $line->t; |
|
|
51 | my $markofs = $line->offset_of ($row, $col); |
|
|
52 | my $curlen = $line->offset_of ($self->selection_end) |
|
|
53 | - $line->offset_of ($self->selection_beg); |
|
|
54 | |
|
|
55 | my @matches; |
45 | |
56 | |
46 | for my $regex (@mark_patterns) { |
57 | for my $regex (@mark_patterns) { |
47 | while ($text =~ /$regex/g) { |
58 | while ($text =~ /$regex/g) { |
48 | if ($-[1] <= $offset and $offset <= $+[1]) { |
59 | if ($-[1] <= $markofs and $markofs <= $+[1]) { |
|
|
60 | my $ofs = $-[1]; |
49 | my $match = $1; |
61 | my $match = $1; |
50 | my ($ofs1, $ofs2) = ($-[1], $+[1]); |
62 | |
|
|
63 | push @matches, [$ofs, length $match]; |
51 | |
64 | |
52 | for my $regex (@simplify_patterns) { |
65 | for my $regex (@simplify_patterns) { |
53 | if ($match =~ $regex) { |
66 | if ($match =~ $regex) { |
54 | $match = $1; |
67 | $match = $1; |
55 | $ofs1 += $-[1]; |
68 | $ofs += $-[1]; |
56 | $ofs2 = $ofs1 + length $match; |
|
|
57 | } |
69 | } |
58 | } |
70 | } |
59 | |
71 | |
60 | $self->selection_beg ($line->coord_of ($ofs1)); |
72 | push @matches, [$ofs, length $match]; |
61 | $self->selection_end ($line->coord_of ($ofs2)); |
|
|
62 | return 1; |
|
|
63 | } |
73 | } |
64 | } |
74 | } |
65 | } |
75 | } |
66 | |
76 | |
|
|
77 | # whole line |
|
|
78 | push @matches, [0, ($line->end - $line->beg + 1) * $self->ncol]; |
|
|
79 | |
|
|
80 | for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { |
|
|
81 | my ($ofs, $len) = @$_; |
|
|
82 | |
|
|
83 | next if $len <= $curlen; |
|
|
84 | |
|
|
85 | $self->selection_beg ($line->coord_of ($ofs)); |
|
|
86 | $self->selection_end ($line->coord_of ($ofs + $len)); |
|
|
87 | return 1; |
|
|
88 | } |
|
|
89 | |
67 | () |
90 | () |
68 | } |
91 | } |