… | |
… | |
21 | $res = $self->locale_decode ($res); |
21 | $res = $self->locale_decode ($res); |
22 | utf8::encode $res; |
22 | utf8::encode $res; |
23 | push @{ $self->{patterns} }, qr/$res/; |
23 | push @{ $self->{patterns} }, qr/$res/; |
24 | } |
24 | } |
25 | |
25 | |
|
|
26 | $self->{enabled} = 1; |
|
|
27 | |
|
|
28 | push @{ $self->{term}{option_popup_hook} }, sub { |
|
|
29 | ("new selection" => $self->{enabled}, sub { $self->{enabled} = shift }) |
|
|
30 | }; |
|
|
31 | |
26 | () |
32 | () |
27 | } |
33 | } |
28 | |
34 | |
29 | # "find interesting things"-patterns |
35 | # "find interesting things"-patterns |
30 | my @mark_patterns = ( |
36 | my @mark_patterns = ( |
… | |
… | |
38 | qr{ \[ ([^{}[:space:]]+) \] }x, |
44 | qr{ \[ ([^{}[:space:]]+) \] }x, |
39 | qr{ \( ([^()[:space:]]+) \) }x, |
45 | qr{ \( ([^()[:space:]]+) \) }x, |
40 | |
46 | |
41 | # urls, just a heuristic |
47 | # urls, just a heuristic |
42 | qr{( |
48 | qr{( |
43 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
49 | (?:https?://|ftp://|news://|mailto:|file://|\bwww\.)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~#]+ |
44 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) |
50 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+*()~] # exclude some trailing characters (heuristic) |
45 | )}x, |
51 | )}x, |
46 | |
52 | |
47 | # shell-like argument quoting, basically always matches |
53 | # shell-like argument quoting, basically always matches |
48 | qr{\G [\ \t|&;<>()]* ( |
54 | qr{\G [\ \t|&;<>()]* ( |
49 | (?: |
55 | (?: |
… | |
… | |
62 | ); |
68 | ); |
63 | |
69 | |
64 | sub on_sel_extend { |
70 | sub on_sel_extend { |
65 | my ($self, $time) = @_; |
71 | my ($self, $time) = @_; |
66 | |
72 | |
|
|
73 | $self->{enabled} |
|
|
74 | or return; |
|
|
75 | |
67 | my ($row, $col) = $self->selection_mark; |
76 | my ($row, $col) = $self->selection_mark; |
68 | my $line = $self->line ($row); |
77 | my $line = $self->line ($row); |
69 | my $text = $line->t; |
78 | my $text = $line->t; |
70 | my $markofs = $line->offset_of ($row, $col); |
79 | my $markofs = $line->offset_of ($row, $col); |
71 | my $curlen = $line->offset_of ($self->selection_end) |
80 | my $curlen = $line->offset_of ($self->selection_end) |
72 | - $line->offset_of ($self->selection_beg); |
81 | - $line->offset_of ($self->selection_beg); |
73 | |
82 | |
74 | my @matches; |
83 | my @matches; |
75 | |
84 | |
76 | if ($markofs < $line->l) { |
85 | if ($markofs < $line->l) { |
77 | # convert markofs form character to UTF-8 offset space |
86 | # convert markofs from character to UTF-8 offset space |
78 | { |
87 | { |
79 | my $prefix = substr $text, 0, $markofs; |
88 | my $prefix = substr $text, 0, $markofs; |
80 | utf8::encode $prefix; |
89 | utf8::encode $prefix; |
81 | $markofs = length $prefix; |
90 | $markofs = length $prefix; |
82 | } |
91 | } |