… | |
… | |
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 | sub on_init { |
|
|
13 | my ($self) = @_; |
|
|
14 | |
|
|
15 | for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) { |
|
|
16 | no re 'eval'; # just to be sure |
|
|
17 | push @{ $self->{patterns} }, qr/$res/; |
|
|
18 | } |
|
|
19 | |
|
|
20 | () |
|
|
21 | } |
|
|
22 | |
12 | # "find interetsing things"-patterns |
23 | # "find interetsing things"-patterns |
13 | my @mark_patterns = ( |
24 | my @mark_patterns = ( |
14 | qr{([[:alnum:]]+)}, |
|
|
15 | |
|
|
16 | # common "parentheses" |
25 | # common types of "parentheses" |
17 | qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, |
26 | qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, |
18 | qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, |
27 | qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, |
19 | qr{ \{ ([^{}]+?) \} }x, |
28 | qr{ \{ ([^{}]+?) \} }x, |
20 | qr{ \[ ([^{}]+?) \] }x, |
29 | qr{ \[ ([^{}]+?) \] }x, |
|
|
30 | qr{ \( ([^()]+?) \) }x, |
21 | |
31 | |
22 | # urls, just a heuristic |
32 | # urls, just a heuristic |
23 | qr{( |
33 | qr{( |
24 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
34 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
25 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) |
35 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) |
… | |
… | |
41 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
51 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
42 | qr{^(.*)[,\-]$}, # strip off trailing , and - |
52 | qr{^(.*)[,\-]$}, # strip off trailing , and - |
43 | ); |
53 | ); |
44 | |
54 | |
45 | sub on_sel_extend { |
55 | sub on_sel_extend { |
46 | my ($self) = @_; |
56 | my ($self, $time) = @_; |
47 | |
57 | |
48 | my ($row, $col) = $self->selection_mark; |
58 | my ($row, $col) = $self->selection_mark; |
49 | my $line = $self->line ($row); |
59 | my $line = $self->line ($row); |
50 | my $text = $line->t; |
60 | my $text = $line->t; |
51 | my $markofs = $line->offset_of ($row, $col); |
61 | my $markofs = $line->offset_of ($row, $col); |
52 | my $curlen = $line->offset_of ($self->selection_end) |
62 | my $curlen = $line->offset_of ($self->selection_end) |
53 | - $line->offset_of ($self->selection_beg); |
63 | - $line->offset_of ($self->selection_beg); |
54 | |
64 | |
55 | my @matches; |
65 | my @matches; |
56 | |
66 | |
57 | for my $regex (@mark_patterns) { |
67 | for my $regex (@mark_patterns, @{ $self->{patterns} }) { |
58 | while ($text =~ /$regex/g) { |
68 | while ($text =~ /$regex/g) { |
59 | if ($-[1] <= $markofs and $markofs <= $+[1]) { |
69 | if ($-[1] <= $markofs and $markofs <= $+[1]) { |
60 | my $ofs = $-[1]; |
70 | my $ofs = $-[1]; |
61 | my $match = $1; |
71 | my $match = $1; |
62 | |
72 | |
… | |
… | |
72 | push @matches, [$ofs, length $match]; |
82 | push @matches, [$ofs, length $match]; |
73 | } |
83 | } |
74 | } |
84 | } |
75 | } |
85 | } |
76 | |
86 | |
|
|
87 | # whole line |
|
|
88 | push @matches, [0, ($line->end - $line->beg + 1) * $self->ncol]; |
|
|
89 | |
77 | for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { |
90 | for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { |
78 | my ($ofs, $len) = @$_; |
91 | my ($ofs, $len) = @$_; |
79 | |
92 | |
80 | next if $len <= $curlen; |
93 | next if $len <= $curlen; |
81 | |
94 | |
82 | $self->selection_beg ($line->coord_of ($ofs)); |
95 | $self->selection_beg ($line->coord_of ($ofs)); |
83 | $self->selection_end ($line->coord_of ($ofs + $len)); |
96 | $self->selection_end ($line->coord_of ($ofs + $len)); |
84 | return 1; |
97 | return 1; |
85 | } |
98 | } |
86 | |
99 | |
87 | # whole line |
100 | () |
88 | $self->selection_beg ($line->beg, 0); |
|
|
89 | $self->selection_end ($line->end, $self->ncol); |
|
|
90 | |
|
|
91 | return 1; |
|
|
92 | } |
101 | } |