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.6 by sf-tpope, Fri Aug 19 23:08:35 2011 UTC vs.
Revision 1.9 by root, Sun Jun 10 13:58:05 2012 UTC

1#! perl 1#! perl
2 2
3# Author: Tim Pope <rxvt-unicodeNOSPAM@tpope.info> 3# Author: Tim Pope <rxvt-unicodeNOSPAM@tpope.org>
4# Bob Farrell <robertanthonyfarrell@gmail.com> 4# Bob Farrell <robertanthonyfarrell@gmail.com>
5
6#:META:X_RESOURCE:%.launcher:string:default launcher command
7#:META:X_RESOURCE:%.button:string:the button, yeah
8#:META:X_RESOURCE:%.pattern.:string:extra pattern to match
9#:META:X_RESOURCE:%.launcher.:string:custom launcher for pattern
10#:META:X_RESOURCE:%.rend.:string:custom rednition for pattern
5 11
6my $url = 12my $url =
7 qr{ 13 qr{
8 (?:https?://|ftp://|news://|mailto:|file://|\bwww\.) 14 (?:https?://|ftp://|news://|mailto:|file://|\bwww\.)
9 [a-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27,~#]* 15 [a-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27,~#]*
122 } 128 }
123 () 129 ()
124} 130}
125 131
126sub my_resource { 132sub my_resource {
127 my $self = shift; 133 $_[0]->x_resource ("%.$_[1]")
128 $self->x_resource ("$self->{name}.$_[0]");
129} 134}
130 135
131# turn a rendition spec in the resource into a sub that implements it on $_ 136# turn a rendition spec in the resource into a sub that implements it on $_
132sub parse_rend { 137sub parse_rend {
133 my ($self, $str) = @_; 138 my ($self, $str) = @_;
144} 149}
145 150
146sub on_start { 151sub on_start {
147 my ($self) = @_; 152 my ($self) = @_;
148 153
149 ($self->{name} = __PACKAGE__) =~ s/.*:://; 154 $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser";
150 $self->{name} =~ tr/_/-/;
151 $self->{launcher} = $self->my_resource("launcher") ||
152 $self->x_resource("urlLauncher") ||
153 "sensible-browser";
154 155
155 $self->{urls} = []; 156 $self->{urls} = [];
156 $self->{showing} = 0; 157 $self->{showing} = 0;
157 $self->{button} = 2; 158 $self->{button} = 2;
158 $self->{state} = 0; 159 $self->{state} = 0;
159 if($self->{argv}[0] || $self->my_resource("button")) { 160 if($self->{argv}[0] || $self->my_resource ("button")) {
160 my @mods = split('', $self->{argv}[0] || $self->my_resource("button")); 161 my @mods = split '', $self->{argv}[0] || $self->my_resource ("button");
161 for my $mod (@mods) { 162 for my $mod (@mods) {
162 if($mod =~ /^\d+$/) { 163 if($mod =~ /^\d+$/) {
163 $self->{button} = $mod; 164 $self->{button} = $mod;
164 } elsif($mod eq "C") { 165 } elsif($mod eq "C") {
165 $self->{state} |= urxvt::ControlMask; 166 $self->{state} |= urxvt::ControlMask;
166 } elsif($mod eq "S") { 167 } elsif($mod eq "S") {
167 $self->{state} |= urxvt::ShiftMask; 168 $self->{state} |= urxvt::ShiftMask;
168 } elsif($mod eq "M") { 169 } elsif($mod eq "M") {
169 $self->{state} |= $self->ModMetaMask; 170 $self->{state} |= $self->ModMetaMask;
170 } elsif($mod ne "-" && $mod ne " ") { 171 } elsif($mod ne "-" && $mod ne " ") {
171 warn("$mod is invalid in $self->{name}<$self->{argv}[0]>\n"); 172 warn("$mod is invalid in $self->{_name}<$self->{argv}[0]>\n");
172 } 173 }
173 } 174 }
174 } 175 }
175 176
176 my @defaults = ($url); 177 my @defaults = ($url);
177 my @matchers; 178 my @matchers;
178 for (my $idx = 0; defined (my $res = $self->my_resource("pattern.$idx") || $defaults[$idx]); $idx++) { 179 for (my $idx = 0; defined (my $res = $self->my_resource ("pattern.$idx") || $defaults[$idx]); $idx++) {
179 $res = $self->locale_decode ($res); 180 $res = $self->locale_decode ($res);
180 utf8::encode $res; 181 utf8::encode $res;
181 my $launcher = $self->my_resource("launcher.$idx"); 182 my $launcher = $self->my_resource ("launcher.$idx");
182 $launcher =~ s/\$&|\$\{&\}/\${0}/g if ($launcher); 183 $launcher =~ s/\$&|\$\{&\}/\${0}/g if $launcher;
183 my $rend = $self->parse_rend($self->my_resource("rend.$idx")); 184 my $rend = $self->parse_rend($self->my_resource ("rend.$idx"));
184 unshift @matchers, [qr($res)x,$launcher,$rend]; 185 unshift @matchers, [qr($res)x,$launcher,$rend];
185 } 186 }
186 $self->{matchers} = \@matchers; 187 $self->{matchers} = \@matchers;
187 188
188 () 189 ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines