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