Re: select wrapped lines / click long url / bug 3453
Hi! On Wed, Oct 24, 2012 at 06:09:03AM +0300, Alex Efros wrote: > Looks like mark-urls was removed and replaced by matcher in current urxvt > version. Anyway, both doesn't support urls wrapped in several lines. > Chip Camden already mention this in previous email, but I've just tested > both and confirm this. Probably matcher can be modified (as Chip Camden > suggest) to support wrapped lines, but right now it doesn't work in this way. I've implemented this feature in matcher plugin. Modified version and patch attached (I'm using rxvt-unicode-9.15). I've implemented only url-highlighting and clicking support. It looks like matcher also support some "list" feature, but I've no idea what is it for and thus I didn't tried to add multiline match support for it. It would be nice to have some notification when url clicked and opened in browser, because this happens in background and inside mutt I didn't know is it was successfully opened or I clicked on wrong place and nothing happens - probably some status bar notification pop-up for 1 sec is the best. Is it possible to implement this in urxvt? Is it possible to somehow install modified version of matcher in my home dir instead of replacing system-wide version? If there is recommended way to send patches to urxvt please let me know. Now, I have to figure out how to configure urxvt in same way as my xterm was configured… -- WBR, Alex. --- matcher.orig 2012-10-24 05:38:42.747463293 +0300 +++ matcher 2012-10-24 20:36:13.653745332 +0300 @@ -202,24 +202,22 @@ sub on_line_update { my ($self, $row) = @_; - # fetch the line that has changed - my $line = $self->line ($row); - my $text = $line->t; - my $i = 0; + # fetch the line (enlarged to adjoining lines) that has changed + my ($text, $prev_cols, $next_cols, @lines) = $self->enlarge($row); # find all urls (if any) for my $matcher (@{$self->{matchers}}) { - while ($text =~ /$matcher->[0]/g) { - #print "$&\n"; - my $rend = $line->r; - - # mark all characters as underlined. we _must_ not toggle underline, - # as we might get called on an already-marked url. - &{$matcher->[2]} - for @{$rend}[ $-[0] .. $+[0] - 1]; - - $line->r ($rend); - } + $self->match($matcher->[0], $text, $prev_cols, $next_cols, \@lines, sub { + for (@_) { + my ($line, $from, $to) = @$_; + my $rend = $line->r; + # mark all characters as underlined. we _must_ not toggle underline, + # as we might get called on an already-marked url. + &{$matcher->[2]} + for @{$rend}[ $from .. $to - 1]; + $line->r($rend); + } + }); } () @@ -235,28 +233,45 @@ sub command_for { my ($self, $row, $col) = @_; - my $line = $self->line ($row); - my $text = $line->t; + + # fetch the line (enlarged to adjoining lines) that has changed + my ($text, $prev_cols, $next_cols, @lines) = $self->enlarge($row); for my $matcher (@{$self->{matchers}}) { my $launcher = $matcher->[1] || $self->{launcher}; - while (($text =~ /$matcher->[0]/g)) { - my $match = $&; - my @begin = @-; - my @end = @+; - if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { + my @exec; + $self->match($matcher->[0], $text, $prev_cols, $next_cols, \@lines, sub { + my $hit = 0; + my $match = q{}; + for (@_) { + my ($line, $from, $to) = @$_; + my $text = $line->t; + $match .= substr $text, $from, $to-$from; + if ($line->beg <= $row && $row <= $line->end) { + $hit ||= !defined $col; + if ($row < $line->end) { + $hit ||= 1; + } else { + $hit ||= $from <= $col && $col < $to; + } + } + } + if ($hit) { if ($launcher !~ /\$/) { - return ($launcher,$match); + @exec = ($launcher,$match); } else { + $match =~ /$matcher->[0]/; + my @begin = @-; + my @end = @+; # It'd be nice to just access a list like ($&,$1,$2...), # but alas, m//g behaves differently in list context. - my @exec = map { s/\$(\d+)|\$\{(\d+)\}/ + @exec = map { s/\$(\d+)|\$\{(\d+)\}/ substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) /egx; $_ } split(/\s+/, $launcher); - return @exec; } - } - } + } + }); + return @exec if @exec; } () @@ -300,4 +315,63 @@ 1; } +sub enlarge { + my ($self, $row) = @_; + + my $line = $self->line($row); + my $text = $line->t; + + # enlarge this line with prev&next lines up to nearest line with space char + my ($prev_cols, $next_cols) = (0, 0); + my (@prev_lines,@next_lines); + if ($line->l && $text !~ /\A\s/ms) { + for my $prev_row (reverse 0 .. $row-1) { + my $l = $self->line($prev_row); + my $t = $l->t; + last if $l->l < $self->ncol; + unshift @prev_lines, $l; +
Re: select wrapped lines / click long url / bug 3453
Hi Why don't you send this to the urxvt mailing list. I for example will be glad if this comes up in the next release and it will be a shame if it gets lost in this mailing list. rxvt-unic...@lists.schmorp.de seems to be the mailing list on the official page - you can try there. Best, Nikola On Wed, Oct 24, 2012 at 08:38:02PM +0300, Alex Efros wrote: > Hi! > > On Wed, Oct 24, 2012 at 06:09:03AM +0300, Alex Efros wrote: > > Looks like mark-urls was removed and replaced by matcher in current urxvt > > version. Anyway, both doesn't support urls wrapped in several lines. > > Chip Camden already mention this in previous email, but I've just tested > > both and confirm this. Probably matcher can be modified (as Chip Camden > > suggest) to support wrapped lines, but right now it doesn't work in this > > way. > > I've implemented this feature in matcher plugin. Modified version and > patch attached (I'm using rxvt-unicode-9.15). > > I've implemented only url-highlighting and clicking support. It looks like > matcher also support some "list" feature, but I've no idea what is it for > and thus I didn't tried to add multiline match support for it. > > It would be nice to have some notification when url clicked and opened in > browser, because this happens in background and inside mutt I didn't know > is it was successfully opened or I clicked on wrong place and nothing > happens - probably some status bar notification pop-up for 1 sec is the > best. Is it possible to implement this in urxvt? > > > Is it possible to somehow install modified version of matcher in my home > dir instead of replacing system-wide version? > > If there is recommended way to send patches to urxvt please let me know. > > Now, I have to figure out how to configure urxvt in same way as my xterm > was configured… > > -- > WBR, Alex. > #! perl > > # Author: Tim Pope > # Bob Farrell > > my $url = >qr{ > (?:https?://|ftp://|news://|mailto:|file://|\bwww\.) > [a-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27,~#]* > ( > \([a-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27,~#]*\)| # Allow a pair of > matched parentheses > [a-zA-Z0-9\-\@;\/?:&=%\$_+*~] # exclude some trailing characters > (heuristic) > )+ >}x; > > sub on_key_press { >my ($self, $event, $keysym, $octets) = @_; > >if (! $self->{showing} ) { > return; >} > >my $i = ($keysym == 96 ? 0 : $keysym - 48); >if (($i > scalar(@{$self->{urls}})) || ($i < 0)) { > $self->matchlist(); > return; >} > >my @args = ($self->{urls}[ -$i-1 ]); >$self->matchlist(); > >$self->exec_async( $self->{launcher}, @args ); > } > > sub on_user_command { >my ($self, $cmd) = @_; > >if($cmd =~ s/^matcher:list\b//) { > $self->matchlist(); >} else { > if($cmd =~ s/^matcher:last\b//) { > $self->most_recent; > } ># For backward compatibility > else { > if($cmd =~ s/^matcher\b//) { > $self->most_recent; > } >} > } >() > } > > sub matchlist { >my ($self) = @_; >if ( $self->{showing} ) { > $self->{url_overlay}->hide(); > $self->{showing} = 0; > return; >} > @{$self->{urls}} = (); > my $line; > for (my $i = 0; $i < $self->nrow; $i ++) { > $line = $self->line($i); > next if ($line->beg != $i); > for my $url ($self->get_urls_from_line($line->t)) { > if (scalar(@{$self->{urls}}) == 10) { > shift @{$self->{urls}}; > } > push @{$self->{urls}}, $url; > } > } > > if (! scalar(@{$self->{urls}})) { > return; > } > > my $max = 0; > my $i = scalar( @{$self->{urls}} ) - 1 ;; > > my @temp = (); > > for my $url (@{$self->{urls}}) { > my $url = "$i-$url"; > my $xpos = 0; > > if ($self->ncol + (length $url) >= $self->ncol) { > $url = substr( $url, 0, $self->ncol ); > } > > push @temp, $url; > > if( length $url > $max ) { > $max = length $url; > } > > $i--; > } > > @temp = reverse @temp; > > $self->{url_overlay} = $self->overlay(0, 0, $max, scalar( @temp ), > urxvt::OVERLAY_RSTYLE, 2); > my $i = 0; > for my $url (@temp) { > $self->{url_overlay}->set( 0, $i, $url, [(urxvt::OVERLAY_RSTYLE) x > length $url]); > $self->{showing} = 1; > $i++; > } > > } > > sub most_recent { >my ($self) = shift; >my $row = $self->nrow; >my @exec; >while($row-- > $self->top_row) { > @exec = $self->command_for($row); > last if(@exec); >} >if(@exec) { > return $self->exec_async (@exec); >} >() > } > > sub my_resource { >my $self = shift; >$self->x_resource ("$self->{name}.$_[0]"); > } > > # turn a rendition spec in the resource into a sub that implements it on $_ > sub parse_rend { >my ($self, $str) = @_; >my ($mask, $fg, $bg, $failed) = $str ? urxvt::rend2mask($str) >
Re: select wrapped lines / click long url / bug 3453
On Tue, Oct 23, 2012 at 06:48:54PM -0700, Chip Camden wrote: > Quoth J Wermont on Tuesday, 23 October 2012: > > Cameron Simpson wrote: > > > > > I'm using iTerm2 on a Mac, but on X11 setups I use rxvt-unicode > > > (command name "urxvt"). > > > > > > Both support URL clicking. > > > > Hi, could you explain how one would *use* rxvt-unicode? Is it something > > you type in at the prompt? Something you execute from within mutt (if so, > > how)? Or...? > > > > I'm on a Windows PC, I use SSH to connect to my ISP and log into my > > account, and that's where I run mutt. No X available to my knowledge. > > I'm assuming I would be running rxvt-unicode on the shell. > > > > Thanks, > > > > J. Wermont > > Sorry, rxvt-unicode requires X. It's an xterm replacement. It appears that is actually not quite true: http://o56o.com/rxvt.html There is a question of how trustworthy this code is... The page is pretty bare, and the server root has no content. This is also very old. It's not clear if this requires Cygwin, but I tend to think so. But I seem to recall that Cygwin allows use of rxvt without an X server too... Been a while since I used Cygwin though. There's also MinGW, which provides rxvt without an X server. http://www.mingw.org/ -- Derek D. Martinhttp://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 -=-=-=-=- This message is posted from an invalid address. Replying to it will result in undeliverable mail due to spam prevention. Sorry for the inconvenience. pgpfgsy2N41mo.pgp Description: PGP signature
Re: select wrapped lines / click long url / bug 3453
Quoth Derek Martin on Wednesday, 24 October 2012: > On Tue, Oct 23, 2012 at 06:48:54PM -0700, Chip Camden wrote: > > Quoth J Wermont on Tuesday, 23 October 2012: > > > Cameron Simpson wrote: > > > > > > > I'm using iTerm2 on a Mac, but on X11 setups I use rxvt-unicode > > > > (command name "urxvt"). > > > > > > > > Both support URL clicking. > > > > > > Hi, could you explain how one would *use* rxvt-unicode? Is it something > > > you type in at the prompt? Something you execute from within mutt (if so, > > > how)? Or...? > > > > > > I'm on a Windows PC, I use SSH to connect to my ISP and log into my > > > account, and that's where I run mutt. No X available to my knowledge. > > > I'm assuming I would be running rxvt-unicode on the shell. > > > > > > Thanks, > > > > > > J. Wermont > > > > Sorry, rxvt-unicode requires X. It's an xterm replacement. > > It appears that is actually not quite true: > > http://o56o.com/rxvt.html > > There is a question of how trustworthy this code is... The page is > pretty bare, and the server root has no content. This is also very > old. It's not clear if this requires Cygwin, but I tend to think so. > But I seem to recall that Cygwin allows use of rxvt without an X > server too... Been a while since I used Cygwin though. > > There's also MinGW, which provides rxvt without an X server. > > http://www.mingw.org/ > > -- > Derek D. Martinhttp://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 > -=-=-=-=- > This message is posted from an invalid address. Replying to it will result in > undeliverable mail due to spam prevention. Sorry for the inconvenience. > That might just be rxvt, though, and not rxvt-unicode. The latter supports a lot more than just Unicode. -- .O. | Sterling (Chip) Camden | http://camdensoftware.com ..O | sterl...@camdensoftware.com | http://chipsquips.com OOO | 2048R/D6DBAF91 | http://chipstips.com pgpty7BFjoKRa.pgp Description: PGP signature