From 151a5880530502f6ed5c60fb12671a2a622eb0d3 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 12 Jan 2006 03:32:56 +0000 Subject: [PATCH] *** empty log message *** --- src/command.C | 2 +- src/perl/selection | 42 +++++++++++++++++++++++++++++++----------- src/screen.C | 14 +++++++++----- src/urxvt.pm | 14 +++++++++++--- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/command.C b/src/command.C index 6854f6df..2f908821 100644 --- a/src/command.C +++ b/src/command.C @@ -1922,7 +1922,7 @@ rxvt_term::button_press (XButtonEvent &ev) #endif /* allow shift+left click to extend selection */ - if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) + if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report)) { if (MEvent.button == Button1 && clickintime) selection_rotate (ev.x, ev.y); diff --git a/src/perl/selection b/src/perl/selection index e653ec10..0c968d43 100644 --- a/src/perl/selection +++ b/src/perl/selection @@ -11,11 +11,7 @@ sub on_keyboard_command { # "find interetsing things"-patterns 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) - )}x, + qr{([[:alnum:]]+)}, # common "parentheses" qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, @@ -23,6 +19,12 @@ my @mark_patterns = ( qr{ \{ ([^{}]+?) \} }x, qr{ \[ ([^{}]+?) \] }x, + # 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) + )}x, + # shell-like argument quoting, basically always matches qr{\G [\ \t|&;<>()] *( (?: @@ -45,15 +47,21 @@ sub on_sel_extend { my ($row, $col) = $self->selection_mark; my $line = $self->line ($row); - my $offset = $line->offset_of ($row, $col); my $text = $line->t; + my $markofs = $line->offset_of ($row, $col); + my $curlen = $line->offset_of ($self->selection_end) + - $line->offset_of ($self->selection_beg); + + my @matches; for my $regex (@mark_patterns) { while ($text =~ /$regex/g) { - if ($-[1] <= $offset and $offset <= $+[1]) { + if ($-[1] <= $markofs and $markofs <= $+[1]) { my $ofs = $-[1]; my $match = $1; + push @matches, [$ofs, length $match]; + for my $regex (@simplify_patterns) { if ($match =~ $regex) { $match = $1; @@ -61,12 +69,24 @@ sub on_sel_extend { } } - $self->selection_beg ($line->coord_of ($ofs)); - $self->selection_end ($line->coord_of ($ofs + length $match)); - return 1; + push @matches, [$ofs, length $match]; } } } - () + for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { + my ($ofs, $len) = @$_; + + next if $len <= $curlen; + + $self->selection_beg ($line->coord_of ($ofs)); + $self->selection_end ($line->coord_of ($ofs + $len)); + return 1; + } + + # whole line + $self->selection_beg ($line->beg, 0); + $self->selection_end ($line->end, $self->ncol); + + return 1; } diff --git a/src/screen.C b/src/screen.C index 6f10e9be..7e178f60 100644 --- a/src/screen.C +++ b/src/screen.C @@ -3047,6 +3047,13 @@ rxvt_term::selection_click (int clicks, int x, int y) clicks = ((clicks - 1) % 3) + 1; selection.clicks = clicks; /* save clicks so extend will work */ + if (clicks == 2 && !selection.rect + && HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END))) + { + MEvent.clicks = 1; // what a mess + return; + } + selection_start_colrow (Pixel2Col (x), Pixel2Row (y)); if (clicks == 2 || clicks == 3) @@ -3351,11 +3358,8 @@ rxvt_term::selection_extend_colrow (int32_t col, int32_t row, int button3, int b if (ROWCOL_IS_AFTER (selection.end, selection.beg)) selection.end.col--; - if (!HOOK_INVOKE ((this, HOOK_SEL_EXTEND, DT_END))) - { - selection_delimit_word (UP, &selection.beg, &selection.beg); - selection_delimit_word (DN, &selection.end, &selection.end); - } + selection_delimit_word (UP, &selection.beg, &selection.beg); + selection_delimit_word (DN, &selection.end, &selection.end); } else if (selection.clicks == 3) { diff --git a/src/urxvt.pm b/src/urxvt.pm index 8b994530..2b852a63 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -232,7 +232,9 @@ Returning a true value aborts selection grabbing. It will still be hilighted. Called whenever the user tries to extend the selection (e.g. with a double click) and is either supposed to return false (normal operation), or should extend the selection itelf and return true to suppress the built-in -processing. +processing. This can happen multiple times, as long as the callback +returns true, it will be called on every further click by the user and is +supposed to enlarge the selection more and more, if possible. See the F example extension. @@ -597,6 +599,9 @@ sub invoke { warn $@; } } + + verbose 11, "$HOOKNAME[$htype] returning <$retval>" + if $verbosity >= 11; } if ($htype == 1) { # DESTROY @@ -1220,7 +1225,8 @@ Return the row number of the first/last row of the line, respectively. =item $offset = $line->offset_of ($row, $col) Returns the character offset of the given row|col pair within the logical -line. +line. Works for rows outside the line, too, and returns corresponding +offsets outside the string. =item ($row, $col) = $line->coord_of ($offset) @@ -1585,7 +1591,9 @@ numbers indicate more verbose output. =item >= 3 - script loading and management -=item >=10 - all events received +=item >=10 - all called hooks + +=item >=11 - hook reutrn values =back -- 2.34.1