--- rxvt-unicode/src/perl/searchable-scrollback 2012/09/04 22:41:12 1.30 +++ rxvt-unicode/src/perl/searchable-scrollback 2014/06/08 19:40:20 1.38 @@ -2,18 +2,19 @@ # this extension implements scrollback buffer search -#:META:X_RESOURCE:%:string:activation hotkey keysym +#:META:RESOURCE:%:string:activation hotkey keysym +#:META:BINDING:M-s:start =head1 NAME -searchable-scrollback - incremental scrollback search (enabled by default) +searchable-scrollback - incremental scrollback search (enabled by default) =head1 DESCRIPTION -Adds regex search functionality to the scrollback buffer, triggered -by a hotkey (default: C). While in search mode, normal terminal -input/output is suspended and a regex is displayed at the bottom of the -screen. +Adds regex search functionality to the scrollback buffer, triggered by +the C action (bound to C by +default). While in search mode, normal terminal input/output is +suspended and a regex is displayed at the bottom of the screen. Inputting characters appends them to the regex and continues incremental search. C removes a character from the regex, C and C @@ -34,20 +35,21 @@ sub on_init { my ($self) = @_; + # only for backwards compatibility my $hotkey = $self->{argv}[0] || $self->x_resource ("%") - || "M-s"; + || return; - $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") + $self->bind_action ($hotkey, "searchable-scrollback:start") # ugh or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; () } -sub on_user_command { - my ($self, $cmd) = @_; +sub on_action { + my ($self, $action) = @_; - $cmd eq "searchable-scrollback:start" + $action eq "start" and $self->enter; () @@ -91,7 +93,6 @@ delete $self->{manpage_overlay}; delete $self->{overlay}; - delete $self->{history}; delete $self->{search}; } @@ -102,10 +103,7 @@ } sub search { - my ($self, $dir) = @_; - - delete $self->{found}; - my $row = $self->{row}; + my ($self, $dir, $row) = @_; my $search = $self->special_encode ($self->{search}); @@ -117,6 +115,8 @@ my $text = $line->t; if ($text =~ /$re/g) { + delete $self->{found}; + do { push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; } while $text =~ /$re/g; @@ -168,14 +168,16 @@ $self->{row} = $self->nrow - 1; $self->view_start (0); } elsif ($keysym == 0xff52) { # up - $self->{row}-- if $self->{row} > $self->top_row; - $self->search (-1); + my $line = $self->line ($self->{row}); + $self->search (-1, $line->beg - 1) + if $line->beg > $self->top_row; } elsif ($keysym == 0xff54) { # down - $self->{row}++ if $self->{row} < $self->nrow; - $self->search (+1); + my $line = $self->line ($self->{row}); + $self->search (+1, $line->end + 1) + if $line->end < $self->nrow; } elsif ($keysym == 0xff08) { # backspace substr $self->{search}, -1, 1, ""; - $self->search; + $self->search (+1, $self->{row}); $self->idle; } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { return; # pass to tt_write @@ -192,7 +194,8 @@ $self->{search} =~ s/^\(\?i\)// if $self->{search} =~ /^\(.*[[:upper:]]/; - $self->search (-1); + delete $self->{found}; + $self->search (-1, $self->{row}); $self->idle; 1