… | |
… | |
28 | C<matcher.pattern.0> resource, and additional patterns can be specified |
28 | C<matcher.pattern.0> resource, and additional patterns can be specified |
29 | with numbered patterns, in a manner similar to the "selection" extension. |
29 | with numbered patterns, in a manner similar to the "selection" extension. |
30 | The launcher can also be overridden on a per-pattern basis. |
30 | The launcher can also be overridden on a per-pattern basis. |
31 | |
31 | |
32 | It is possible to activate the most recently seen match or a list of matches |
32 | It is possible to activate the most recently seen match or a list of matches |
33 | from the keyboard. Simply bind a keysym to "perl:matcher:last" or |
33 | from the keyboard. Simply bind a keysym to "matcher:last" or |
34 | "perl:matcher:list" as seen in the example below. |
34 | "matcher:list" as seen in the example below. |
35 | |
35 | |
36 | Example: load and use the matcher extension with defaults. |
36 | Example: load and use the matcher extension with defaults. |
37 | |
37 | |
38 | URxvt.perl-ext: default,matcher |
38 | URxvt.perl-ext: default,matcher |
39 | |
39 | |
40 | Example: use a custom configuration. |
40 | Example: use a custom configuration. |
41 | |
41 | |
42 | URxvt.url-launcher: sensible-browser |
42 | URxvt.url-launcher: sensible-browser |
43 | URxvt.keysym.C-Delete: perl:matcher:last |
43 | URxvt.keysym.C-Delete: matcher:last |
44 | URxvt.keysym.M-Delete: perl:matcher:list |
44 | URxvt.keysym.M-Delete: matcher:list |
45 | URxvt.matcher.button: 1 |
45 | URxvt.matcher.button: 1 |
46 | URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-] |
46 | URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-] |
47 | URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) |
47 | URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) |
48 | URxvt.matcher.launcher.2: gvim +$2 $1 |
48 | URxvt.matcher.launcher.2: gvim +$2 $1 |
49 | |
49 | |
… | |
… | |
92 | } |
92 | } |
93 | |
93 | |
94 | () |
94 | () |
95 | } |
95 | } |
96 | |
96 | |
|
|
97 | sub on_action { |
|
|
98 | my ($self, $action) = @_; |
|
|
99 | |
|
|
100 | if ($action eq "list") { |
|
|
101 | $self->matchlist; |
|
|
102 | } elsif ($action eq "last") { |
|
|
103 | $self->most_recent; |
|
|
104 | } |
|
|
105 | |
|
|
106 | () |
|
|
107 | } |
|
|
108 | |
97 | sub matchlist { |
109 | sub matchlist { |
98 | my ($self) = @_; |
110 | my ($self) = @_; |
99 | |
111 | |
100 | @{ $self->{matches} } = (); |
112 | @{ $self->{matches} } = (); |
101 | my $row = $self->nrow - 1; |
113 | my $row = $self->nrow - 1; |
102 | while ($row >= 0 && @{ $self->{matches} } < 10) { |
114 | while ($row >= 0 && @{ $self->{matches} } < 10) { |
103 | my $line = $self->line ($row); |
115 | my $line = $self->line ($row); |
104 | my $text = $line->t; |
116 | my @matches = $self->find_matches ($row); |
105 | |
117 | |
106 | # FIXME: code duplicated from 'command_for' |
118 | for (sort { $b->[0] <=> $a->[0] } @matches) { |
107 | for my $matcher (@{$self->{matchers}}) { |
119 | shift @$_; |
108 | my $launcher = $matcher->[1] || $self->{launcher}; |
120 | push @{ $self->{matches} }, $_; |
109 | while ($text =~ /$matcher->[0]/g) { |
121 | last if @{ $self->{matches} } == 10; |
110 | my $match = substr ($text, $-[0], $+[0] - $-[0]); |
|
|
111 | my @beg = @-; |
|
|
112 | my @end = @+; |
|
|
113 | my @exec; |
|
|
114 | |
|
|
115 | if ($launcher !~ /\$/) { |
|
|
116 | @exec = ($launcher, $match); |
|
|
117 | } else { |
|
|
118 | @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
|
|
119 | substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2]) |
|
|
120 | /egx; $_ } split /\s+/, $launcher; |
|
|
121 | } |
|
|
122 | |
|
|
123 | push @{ $self->{matches} }, [ $match, @exec ]; |
|
|
124 | } |
|
|
125 | } |
122 | } |
126 | |
123 | |
127 | $row = $line->beg - 1; |
124 | $row = $line->beg - 1; |
128 | } |
125 | } |
129 | |
126 | |
… | |
… | |
258 | | urxvt::ShiftMask | urxvt::ControlMask; |
255 | | urxvt::ShiftMask | urxvt::ControlMask; |
259 | return ($event->{button} == $self->{button} && |
256 | return ($event->{button} == $self->{button} && |
260 | ($event->{state} & $mask) == $self->{state}); |
257 | ($event->{state} & $mask) == $self->{state}); |
261 | } |
258 | } |
262 | |
259 | |
263 | sub command_for { |
260 | sub find_matches { |
264 | my ($self, $row, $col) = @_; |
261 | my ($self, $row, $col) = @_; |
265 | my $line = $self->line ($row); |
262 | my $line = $self->line ($row); |
266 | my $text = $line->t; |
263 | my $text = $line->t; |
|
|
264 | my $off = $line->offset_of ($row, $col) if $col; |
267 | |
265 | |
|
|
266 | my @matches; |
268 | for my $matcher (@{$self->{matchers}}) { |
267 | for my $matcher (@{$self->{matchers}}) { |
269 | my $launcher = $matcher->[1] || $self->{launcher}; |
268 | my $launcher = $matcher->[1] || $self->{launcher}; |
270 | while (($text =~ /$matcher->[0]/g)) { |
269 | while ($text =~ /$matcher->[0]/g) { |
271 | my $match = $&; |
270 | my $match = substr $text, $-[0], $+[0] - $-[0]; |
272 | my @begin = @-; |
271 | my @begin = @-; |
273 | my @end = @+; |
272 | my @end = @+; |
|
|
273 | my @exec; |
|
|
274 | |
274 | if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { |
275 | if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) { |
275 | if ($launcher !~ /\$/) { |
276 | if ($launcher !~ /\$/) { |
276 | return ($launcher,$match); |
277 | @exec = ($launcher, $match); |
277 | } else { |
278 | } else { |
278 | # It'd be nice to just access a list like ($&,$1,$2...), |
279 | # It'd be nice to just access a list like ($&,$1,$2...), |
279 | # but alas, m//g behaves differently in list context. |
280 | # but alas, m//g behaves differently in list context. |
280 | my @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
281 | @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
281 | substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) |
282 | substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2] |
282 | /egx; $_ } split(/\s+/, $launcher); |
283 | /egx; $_ } split /\s+/, $launcher; |
283 | return @exec; |
|
|
284 | } |
284 | } |
|
|
285 | |
|
|
286 | push @matches, [ $begin[0], $match, @exec ]; |
285 | } |
287 | } |
286 | } |
288 | } |
|
|
289 | } |
|
|
290 | |
|
|
291 | @matches; |
|
|
292 | } |
|
|
293 | |
|
|
294 | sub command_for { |
|
|
295 | my ($self, $row, $col) = @_; |
|
|
296 | |
|
|
297 | my @matches = $self->find_matches ($row, $col); |
|
|
298 | if (@matches) { |
|
|
299 | my @match = @{ $matches[0] }; |
|
|
300 | return @match[2 .. $#match]; |
287 | } |
301 | } |
288 | |
302 | |
289 | () |
303 | () |
290 | } |
304 | } |
291 | |
305 | |