#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);
# "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,
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|&;<>()] *(
(?:
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;
}
}
- $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;
}
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)
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)
{
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<selection> example extension.
warn $@;
}
}
+
+ verbose 11, "$HOOKNAME[$htype] returning <$retval>"
+ if $verbosity >= 11;
}
if ($htype == 1) { # DESTROY
=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)
=item >= 3 - script loading and management
-=item >=10 - all events received
+=item >=10 - all called hooks
+
+=item >=11 - hook reutrn values
=back