ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
Revision: 1.15
Committed: Sun Jan 8 01:30:32 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.14: +19 -5 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.15 my @mark_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.15 my @simplify_patterns = (
34     qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple
35     qr{^(.*)[,\-]$},
36     );
37 root 1.14
38 root 1.6 sub on_sel_extend {
39 root 1.7 my ($self) = @_;
40 root 1.8
41     my ($row, $col) = $self->selection_mark;
42     my $line = $self->line ($row);
43     my $offset = $line->offset_of ($row, $col);
44     my $text = $line->t;
45    
46 root 1.15 for my $regex (@mark_patterns) {
47 root 1.8 while ($text =~ /$regex/g) {
48 root 1.9 if ($-[1] <= $offset and $offset <= $+[1]) {
49 root 1.15 my $match = $1;
50     my ($ofs1, $ofs2) = ($-[1], $+[1]);
51    
52     for my $regex (@simplify_patterns) {
53     if ($match =~ $regex) {
54     $match = $1;
55     $ofs1 += $-[1];
56     $ofs2 = $ofs1 + length $match;
57     }
58     }
59    
60     $self->selection_beg ($line->coord_of ($ofs1));
61     $self->selection_end ($line->coord_of ($ofs2));
62 root 1.8 return 1;
63     }
64     }
65     }
66    
67 root 1.5 ()
68     }