Hi!

This patch was rewritten from scratch for rxvt-unicode-9.21.
This time it's really trivial, so, Marc, please reconsider merging it.


Also I've found several minor issues with original matcher plugin:

> line 180:
   my $i = 0;
Var shadowing, should be:
   $i = 0;

> sub most_recent {}
The problem is it doesn't actually run "recent". It runs "first match
returned by find_matches found in latest line with some matches" - which
in practice for end-user means "usually recent but sometimes random".
This function probably should call find_matches instead of command_for and
do sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } to find "recent".

> line 304:
   my $off = $line->offset_of ($row, $col) if defined $col;
Conditional my, which result in accessing global $off instead of local
later.

> line 151:
   while ($row >= 0 && @{ $self->{matches} } < 10) {
I'm not sure, but probably it should be
   while ($row >= $self->top_row && @{ $self->{matches} } < 10) {

-- 
                        WBR, Alex.
--- a/matcher   2017-03-24 17:56:41.529686962 +0200
+++ b/matcher   2017-03-25 04:08:06.579725267 +0200
@@ -3,6 +3,7 @@
 # Author: Tim Pope <[email protected]>
 #         Bob Farrell <[email protected]>
 #         Emanuele Giaquinta
+#         Alex Efros <[email protected]>
 
 #:META:RESOURCE:%.launcher:string:default launcher command
 #:META:RESOURCE:%.button:string:the mouse button used to activate a match
@@ -150,7 +151,7 @@
    $self->{matches} = [];
    my $row = $self->nrow - 1;
    while ($row >= 0 && @{ $self->{matches} } < 10) {
-      my $line = $self->line ($row);
+      my $line = $self->glued_line ($row);
       my @matches = $self->find_matches ($row);
 
       for (sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } @matches) {
@@ -193,7 +194,7 @@
    my $row = $self->nrow - 1;
    my @exec;
    while ($row >= $self->top_row) {
-      my $line = $self->line ($row);
+      my $line = $self->glued_line ($row);
       @exec = $self->command_for($row);
       last if(@exec);
 
@@ -267,7 +268,7 @@
    my ($self, $row) = @_;
 
    # fetch the line that has changed
-   my $line = $self->line ($row);
+   my $line = $self->glued_line ($row);
    my $text = $line->t;
    my $rend;
 
@@ -299,7 +300,7 @@
 
 sub find_matches {
    my ($self, $row, $col) = @_;
-   my $line = $self->line ($row);
+   my $line = $self->glued_line ($row);
    my $text = $line->t;
    my $off = $line->offset_of ($row, $col) if defined $col;
 
@@ -413,7 +414,7 @@
    my ($self, $dir, $row) = @_;
 
    while ($self->nrow > $row && $row >= $self->top_row) {
-      my $line = $self->line ($row)
+      my $line = $self->glued_line ($row)
           or last;
 
       my @matches = $self->find_matches ($row);
@@ -471,7 +472,7 @@
          $self->{id}--;
          $self->want_refresh;
       } else {
-         my $line = $self->line ($self->{cur_row});
+         my $line = $self->glued_line ($self->{cur_row});
          $self->select_search (-1, $line->beg - 1)
             if $line->beg > $self->top_row;
       }
@@ -480,7 +481,7 @@
          $self->{id}++;
          $self->want_refresh;
       } else {
-         my $line = $self->line ($self->{cur_row});
+         my $line = $self->glued_line ($self->{cur_row});
          $self->select_search (+1, $line->end + 1)
             if $line->end < $self->nrow;
       }
@@ -489,4 +490,51 @@
    1
 }
 
+=item $line = $term->glued_line ($row_number)
+
+Create and return a new C<urxvt::line> object that stores information
+about the logical line that row C<$row_number> is part of. Unlike
+C<< $term->line >> this tries to handle logical lines which was broken to
+physical screen lines by ncurses/slang applications.
+
+=back
+
+=cut
+
+sub urxvt::term::glued_line {
+   my ($self, $row) = @_;
+
+   my $line = $self->line ($row);
+   my $beg = $line->beg;
+   my $end = $line->end;
+   my $ncol= $self->ncol;
+
+   # skip empty and multi-row (indication of non-ncurses output) lines
+   return $line if $beg != $end || !$line->l;
+
+   # join previous lines up to nearest line with space at EOL
+   while ($beg > $self->top_row) {
+      my $prevline = $self->line ($beg-1);
+      return $line if $prevline->beg != $prevline->end;
+      last if $prevline->l < $ncol || $prevline->t =~ /\s\z/;
+      $beg--;
+   }
+   # join next lines up to nearest line with space at EOL
+   if ($line->l == $ncol && $line->t =~ /\S\z/) {
+      while ($self->nrow > $end+1) {
+         my $nextline = $self->line (++$end);
+         return $line if $nextline->beg != $nextline->end;
+         last if $nextline->l < $ncol || $nextline->t =~ /\s\z/;
+      }
+   }
+
+   bless {
+      term => $self,
+      beg  => $beg,
+      end  => $end,
+      ncol => $ncol,
+      len  => ($end - $beg) * $ncol + $self->ROW_l ($end),
+   }, urxvt::line::
+}
+
 # vim:set sw=3 sts=3 et:
_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode

Reply via email to