ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
Revision: 1.16
Committed: Sun Jan 8 01:32:38 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.15: +7 -6 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.16 # "find interetsing things"-patterns
13 root 1.15 my @mark_patterns = (
14 root 1.10 # urls, just a heuristic
15     qr{(
16 root 1.12 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
17     [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often
18 root 1.10 )}x,
19 root 1.9
20 root 1.14 # common forms of quoting
21     qr{(?:^|\s) [‘`] ([^‘`’']+) [’'] (?:\s|$)}x,
22    
23 root 1.9 # shell-like argument quoting
24 root 1.11 qr{\G [\ \t|&;<>()] *(
25 root 1.9 (?:
26 root 1.11 [^\\"'\ \t|&;<>()]+
27 root 1.9 | \\.
28 root 1.13 | " (?: [^\\"]+ | \\. )* "
29 root 1.9 | ' [^']* '
30     )+
31 root 1.14 )}x,
32 root 1.8 );
33    
34 root 1.16 # "correct obvious? crap"-patterns
35 root 1.15 my @simplify_patterns = (
36     qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple
37 root 1.16 qr{^(.*)[,\-]$}, # strip off trailing , and -
38 root 1.15 );
39 root 1.14
40 root 1.6 sub on_sel_extend {
41 root 1.7 my ($self) = @_;
42 root 1.8
43     my ($row, $col) = $self->selection_mark;
44     my $line = $self->line ($row);
45     my $offset = $line->offset_of ($row, $col);
46     my $text = $line->t;
47    
48 root 1.15 for my $regex (@mark_patterns) {
49 root 1.8 while ($text =~ /$regex/g) {
50 root 1.9 if ($-[1] <= $offset and $offset <= $+[1]) {
51 root 1.16 my $ofs = $-[1];
52 root 1.15 my $match = $1;
53    
54     for my $regex (@simplify_patterns) {
55     if ($match =~ $regex) {
56     $match = $1;
57 root 1.16 $ofs += $-[1];
58 root 1.15 }
59     }
60    
61 root 1.16 $self->selection_beg ($line->coord_of ($ofs));
62     $self->selection_end ($line->coord_of ($ofs + length $match));
63 root 1.8 return 1;
64     }
65     }
66     }
67    
68 root 1.5 ()
69     }