ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/matcher
(Generate patch)

Comparing rxvt-unicode/src/perl/matcher (file contents):
Revision 1.18 by sf-exg, Sun Jun 1 11:47:20 2014 UTC vs.
Revision 1.20 by sf-exg, Thu Jun 12 06:03:49 2014 UTC

28C<matcher.pattern.0> resource, and additional patterns can be specified 28C<matcher.pattern.0> resource, and additional patterns can be specified
29with numbered patterns, in a manner similar to the "selection" extension. 29with numbered patterns, in a manner similar to the "selection" extension.
30The launcher can also be overridden on a per-pattern basis. 30The launcher can also be overridden on a per-pattern basis.
31 31
32It is possible to activate the most recently seen match or a list of matches 32It is possible to activate the most recently seen match or a list of matches
33from the keyboard. Simply bind a keysym to "perl:matcher:last" or 33from 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
36Example: load and use the matcher extension with defaults. 36Example: load and use the matcher extension with defaults.
37 37
38 URxvt.perl-ext: default,matcher 38 URxvt.perl-ext: default,matcher
39 39
40Example: use a custom configuration. 40Example: 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
97sub 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
97sub matchlist { 109sub 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 $text = $line->t;
105 117
106 # FIXME: code duplicated from 'command_for' 118 # FIXME: code duplicated from 'command_for'
119 my @matches;
107 for my $matcher (@{$self->{matchers}}) { 120 for my $matcher (@{$self->{matchers}}) {
108 my $launcher = $matcher->[1] || $self->{launcher}; 121 my $launcher = $matcher->[1] || $self->{launcher};
109 while ($text =~ /$matcher->[0]/g) { 122 while ($text =~ /$matcher->[0]/g) {
110 my $match = substr ($text, $-[0], $+[0] - $-[0]); 123 my $match = substr ($text, $-[0], $+[0] - $-[0]);
111 my @beg = @-; 124 my @beg = @-;
118 @exec = map { s/\$(\d+)|\$\{(\d+)\}/ 131 @exec = map { s/\$(\d+)|\$\{(\d+)\}/
119 substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2]) 132 substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2])
120 /egx; $_ } split /\s+/, $launcher; 133 /egx; $_ } split /\s+/, $launcher;
121 } 134 }
122 135
123 push @{ $self->{matches} }, [ $match, @exec ]; 136 push @matches, [ $beg[0], $match, @exec ];
124 } 137 }
138 }
139
140 for (sort { $b->[0] <=> $a->[0] } @matches) {
141 shift @$_;
142 push @{ $self->{matches} }, $_;
143 last if @{ $self->{matches} } == 10;
125 } 144 }
126 145
127 $row = $line->beg - 1; 146 $row = $line->beg - 1;
128 } 147 }
129 148

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines