… | |
… | |
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, 0); |
105 | |
|
|
106 | # FIXME: code duplicated from 'command_for' |
|
|
107 | my @matches; |
|
|
108 | for my $matcher (@{$self->{matchers}}) { |
|
|
109 | my $launcher = $matcher->[1] || $self->{launcher}; |
|
|
110 | while ($text =~ /$matcher->[0]/g) { |
|
|
111 | my $match = substr ($text, $-[0], $+[0] - $-[0]); |
|
|
112 | my @beg = @-; |
|
|
113 | my @end = @+; |
|
|
114 | my @exec; |
|
|
115 | |
|
|
116 | if ($launcher !~ /\$/) { |
|
|
117 | @exec = ($launcher, $match); |
|
|
118 | } else { |
|
|
119 | @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
|
|
120 | substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2]) |
|
|
121 | /egx; $_ } split /\s+/, $launcher; |
|
|
122 | } |
|
|
123 | |
|
|
124 | push @matches, [ $beg[0], $match, @exec ]; |
|
|
125 | } |
|
|
126 | } |
|
|
127 | |
117 | |
128 | for (sort { $b->[0] <=> $a->[0] } @matches) { |
118 | for (sort { $b->[0] <=> $a->[0] } @matches) { |
129 | shift @$_; |
119 | shift @$_; |
130 | push @{ $self->{matches} }, $_; |
120 | push @{ $self->{matches} }, $_; |
131 | last if @{ $self->{matches} } == 10; |
121 | last if @{ $self->{matches} } == 10; |
… | |
… | |
265 | | urxvt::ShiftMask | urxvt::ControlMask; |
255 | | urxvt::ShiftMask | urxvt::ControlMask; |
266 | return ($event->{button} == $self->{button} && |
256 | return ($event->{button} == $self->{button} && |
267 | ($event->{state} & $mask) == $self->{state}); |
257 | ($event->{state} & $mask) == $self->{state}); |
268 | } |
258 | } |
269 | |
259 | |
270 | sub command_for { |
260 | sub find_matches { |
271 | my ($self, $row, $col) = @_; |
261 | my ($self, $row, $col) = @_; |
272 | my $line = $self->line ($row); |
262 | my $line = $self->line ($row); |
273 | my $text = $line->t; |
263 | my $text = $line->t; |
274 | |
264 | |
|
|
265 | my @matches; |
275 | for my $matcher (@{$self->{matchers}}) { |
266 | for my $matcher (@{$self->{matchers}}) { |
276 | my $launcher = $matcher->[1] || $self->{launcher}; |
267 | my $launcher = $matcher->[1] || $self->{launcher}; |
277 | while (($text =~ /$matcher->[0]/g)) { |
268 | while (($text =~ /$matcher->[0]/g)) { |
278 | my $match = $&; |
269 | my $match = substr $text, $-[0], $+[0] - $-[0]; |
279 | my @begin = @-; |
270 | my @begin = @-; |
280 | my @end = @+; |
271 | my @end = @+; |
|
|
272 | my @exec; |
|
|
273 | |
281 | if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { |
274 | if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { |
282 | if ($launcher !~ /\$/) { |
275 | if ($launcher !~ /\$/) { |
283 | return ($launcher,$match); |
276 | @exec = ($launcher, $match); |
284 | } else { |
277 | } else { |
285 | # It'd be nice to just access a list like ($&,$1,$2...), |
278 | # It'd be nice to just access a list like ($&,$1,$2...), |
286 | # but alas, m//g behaves differently in list context. |
279 | # but alas, m//g behaves differently in list context. |
287 | my @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
280 | @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
288 | substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) |
281 | substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) |
289 | /egx; $_ } split(/\s+/, $launcher); |
282 | /egx; $_ } split(/\s+/, $launcher); |
290 | return @exec; |
|
|
291 | } |
283 | } |
|
|
284 | |
|
|
285 | push @matches, [ $begin[0], $match, @exec ]; |
292 | } |
286 | } |
293 | } |
287 | } |
|
|
288 | } |
|
|
289 | |
|
|
290 | @matches; |
|
|
291 | } |
|
|
292 | |
|
|
293 | sub command_for { |
|
|
294 | my ($self, $row, $col) = @_; |
|
|
295 | |
|
|
296 | my @matches = $self->find_matches ($row, $col); |
|
|
297 | if (@matches) { |
|
|
298 | my @match = @{ $matches[0] }; |
|
|
299 | return @match[2 .. $#match]; |
294 | } |
300 | } |
295 | |
301 | |
296 | () |
302 | () |
297 | } |
303 | } |
298 | |
304 | |