ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
Revision: 1.14
Committed: Fri Jan 6 20:50:58 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.13: +6 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.4 #! perl
2    
3 elmex 1.1 sub on_keyboard_command {
4 root 1.7 my ($self, $cmd) = @_;
5 elmex 1.2
6     $cmd eq "selection:rot13"
7 root 1.7 and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection);
8 elmex 1.3
9     ()
10 elmex 1.1 }
11 root 1.5
12 root 1.8 my @patterns = (
13 root 1.10 # urls, just a heuristic
14     qr{(
15 root 1.12 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
16     [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often
17 root 1.10 )}x,
18 root 1.9
19 root 1.14 # common forms of quoting
20     qr{(?:^|\s) [‘`] ([^‘`’']+) [’'] (?:\s|$)}x,
21    
22 root 1.9 # shell-like argument quoting
23 root 1.11 qr{\G [\ \t|&;<>()] *(
24 root 1.9 (?:
25 root 1.11 [^\\"'\ \t|&;<>()]+
26 root 1.9 | \\.
27 root 1.13 | " (?: [^\\"]+ | \\. )* "
28 root 1.9 | ' [^']* '
29     )+
30 root 1.14 )}x,
31 root 1.8 );
32    
33 root 1.14 my $x = "‘hallole’";
34    
35 root 1.6 sub on_sel_extend {
36 root 1.7 my ($self) = @_;
37 root 1.8
38     my ($row, $col) = $self->selection_mark;
39     my $line = $self->line ($row);
40     my $offset = $line->offset_of ($row, $col);
41     my $text = $line->t;
42    
43     for my $regex (@patterns) {
44     while ($text =~ /$regex/g) {
45 root 1.9 if ($-[1] <= $offset and $offset <= $+[1]) {
46     $self->selection_beg ($line->coord_of ($-[1]));
47     $self->selection_end ($line->coord_of ($+[1]));
48 root 1.8 return 1;
49     }
50     }
51     }
52    
53 root 1.5 ()
54     }