--- rxvt-unicode/src/perl/searchable-scrollback 2006/01/25 15:33:43 1.21 +++ rxvt-unicode/src/perl/searchable-scrollback 2012/09/04 22:41:12 1.30 @@ -2,11 +2,40 @@ # this extension implements scrollback buffer search +#:META:X_RESOURCE:%:string:activation hotkey keysym + +=head1 NAME + +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. + +Inputting characters appends them to the regex and continues incremental +search. C removes a character from the regex, C and C +search upwards/downwards in the scrollback buffer, C jumps to the +bottom. C leaves search mode and returns to the point where search +was started, while C or C stay at the current position and +additionally stores the first match in the current line into the primary +selection if the C modifier is active. + +The regex defaults to "(?i)", resulting in a case-insensitive search. To +get a case-sensitive search you can delete this prefix using C +or simply use an uppercase character which removes the "(?i)" prefix. + +See L for more info about perl regular expression syntax. + +=cut + sub on_init { my ($self) = @_; my $hotkey = $self->{argv}[0] - || $self->x_resource ("searchable-scrollback") + || $self->x_resource ("%") || "M-s"; $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") @@ -37,8 +66,9 @@ return if $self->{overlay}; $self->{view_start} = $self->view_start; - $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EVENT_NONE); + $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EV_NONE); $self->{row} = $self->nrow - 1; + $self->{search} = "(?i)"; $self->enable ( key_press => \&key_press, @@ -81,7 +111,7 @@ no re 'eval'; # just to be sure if (my $re = eval { qr/$search/ }) { - while ($self->nrow > $row && $row > $self->top_row) { + while ($self->nrow > $row && $row >= $self->top_row) { my $line = $self->line ($row) or last; @@ -124,7 +154,7 @@ delete $self->{manpage_overlay}; if ($keysym == 0xff0d || $keysym == 0xff8d) { # enter - if ($self->{found}) { + if ($self->{found} && $event->{state} & urxvt::ShiftMask) { my ($br, $bc, $er, $ec) = @{ $self->{found}[0] }; $self->selection_beg ($br, $bc); $self->selection_end ($er, $ec); @@ -158,6 +188,10 @@ my ($self, $data) = @_; $self->{search} .= $self->locale_decode ($data); + + $self->{search} =~ s/^\(\?i\)// + if $self->{search} =~ /^\(.*[[:upper:]]/; + $self->search (-1); $self->idle;