From 1e4f9af21a0bb71d9cbd5f0ebfceae77f3923702 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 3 Oct 2006 11:32:19 +0000 Subject: [PATCH] matcher --- Changes | 2 ++ src/perl/mark-urls | 63 ---------------------------------------------- src/perl/selection | 4 +-- src/urxvt.pm | 30 +++++++++++++++++----- 4 files changed, 28 insertions(+), 71 deletions(-) delete mode 100644 src/perl/mark-urls diff --git a/Changes b/Changes index 2a46957f..d71c93fb 100644 --- a/Changes +++ b/Changes @@ -30,6 +30,8 @@ TODO: (exg) rxvt -fn -misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1 U basefont, even if explicitly specified (tracked down by tpope). - fixed urxvt::strwidth to calculate width in the same way as screen.C. - fix a crash caused by passing negative widths to overlay functions. + - added 'matcher' extension by tpope, replacing the mark-urls extension. + - improve url regex to match anything www.* (tpope). - give proper diagnostic when RXVT_SOCKET is too long instead of corrupting the stack (patch by exg). - urxvtd no longer crashes when the client sends an inaccessible diff --git a/src/perl/mark-urls b/src/perl/mark-urls deleted file mode 100644 index a5f6fd47..00000000 --- a/src/perl/mark-urls +++ /dev/null @@ -1,63 +0,0 @@ -#! perl - -# same url as used in "selection" -my $url = - qr{( - (?:https?://|ftp://|news://|mailto:|file://)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~#]+ - [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) - )}x; - -sub on_start { - my ($self) = @_; - - $self->{browser} = $self->x_resource ("urlLauncher") || "x-www-browser"; - - () -} - -sub on_line_update { - my ($self, $row) = @_; - - # fetch the line that has changed - my $line = $self->line ($row); - my $text = $line->t; - - # find all urls (if any) - while ($text =~ /$url/g) { - my $rend = $line->r; - - # mark all characters as underlined. we _must_ not toggle underline, - # as we might get called on an already-marked url. - $_ |= urxvt::RS_Uline - for @{$rend}[ $-[1] .. $+[1] - 1]; - - $line->r ($rend); - } - - () -} - -sub on_button_release { - my ($self, $event) = @_; - - my $mask = $self->ModLevel3Mask | $self->ModMetaMask - | urxvt::ShiftMask | urxvt::ControlMask; - - if ($event->{button} == 2 && ($event->{state} & $mask) == 0) { - my $row = $event->{row}; - my $col = $event->{col}; - - my $line = $self->line ($row); - my $text = $line->t; - - while ($text =~ /$url/g) { - if ($-[1] <= $col && $+[1] >= $col) { - $self->exec_async ($self->{browser}, $1); - return 1; - } - } - } - - () -} - diff --git a/src/perl/selection b/src/perl/selection index 3c5ea547..7f025117 100644 --- a/src/perl/selection +++ b/src/perl/selection @@ -46,8 +46,8 @@ my @mark_patterns = ( # urls, just a heuristic qr{( - (?:https?://|ftp://|news://|mailto:|file://)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~#]+ - [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) + (?:https?://|ftp://|news://|mailto:|file://|\bwww\.)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~#]+ + [ab-zA-Z0-9\-\@;\/?:&=%\$_+*()~] # exclude some trailing characters (heuristic) )}x, # shell-like argument quoting, basically always matches diff --git a/src/urxvt.pm b/src/urxvt.pm index bd6bde11..0e5fde5c 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -242,12 +242,30 @@ following four resources (shown with defaults): See I in the @@RXVT_NAME@@(1) manpage for valid indices. -=item mark-urls - -Uses per-line display filtering (C) to underline urls and -make them clickable. When middle-clicked, the program specified in the -resource C (default C) will be started with -the URL as first argument. +=item matcher + +Uses per-line display filtering (C) to underline text +matching a certain pattern and make it clickable. When clicked with the +mouse button specified in the C resource (default 2, or +middle), the program specified in the C resource +(default, the C resource, C) will be started +with the matched text as first argument. The default configuration is +suitable for matching URLs and launching a web browser, like the +former "mark-urls" extension. + +The default pattern to match URLs can be overridden with the +C resource, and additional patterns can be specified +with numbered patterns, in a manner similar to the "selection" extension. +The launcher can also be overridden on a per-pattern basis. + +Example configuration: + + URxvt.perl-ext: default,matcher + URxvt.urlLauncher: sensible-browser + URxvt.matcher.button: 1 + URxvt.matcher.pattern.1: \\bwww\\.[\\w-]\\.[\\w./?&@#-]*[\\w/-] + URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) + URxvt.matcher.launcher.2: gvim +$2 $1 =item xim-onthespot -- 2.34.1