1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.pattern-0:string:first selection pattern |
3 | #:META:RESOURCE:%.pattern-0:string:first selection pattern |
|
|
4 | |
|
|
5 | =head1 NAME |
|
|
6 | |
|
|
7 | selection - more intelligent selection (enabled by default) |
|
|
8 | |
|
|
9 | =head1 DESCRIPTION |
|
|
10 | |
|
|
11 | This extension tries to be more intelligent when the user extends |
|
|
12 | selections (double-click and further clicks). Right now, it tries to |
|
|
13 | select words, urls and complete shell-quoted arguments, which is very |
|
|
14 | convenient, too, if your F<ls> supports C<--quoting-style=shell>. |
|
|
15 | |
|
|
16 | A double-click usually selects the word under the cursor, further clicks |
|
|
17 | will enlarge the selection. |
|
|
18 | |
|
|
19 | The selection works by trying to match a number of regexes and displaying |
|
|
20 | them in increasing order of length. You can add your own regexes by |
|
|
21 | specifying resources of the form: |
|
|
22 | |
|
|
23 | URxvt.selection.pattern-0: perl-regex |
|
|
24 | URxvt.selection.pattern-1: perl-regex |
|
|
25 | ... |
|
|
26 | |
|
|
27 | The index number (0, 1...) must not have any holes, and each regex must |
|
|
28 | contain at least one pair of capturing parentheses, which will be used for |
|
|
29 | the match. For example, the following adds a regex that matches everything |
|
|
30 | between two vertical bars: |
|
|
31 | |
|
|
32 | URxvt.selection.pattern-0: \\|([^|]+)\\| |
|
|
33 | |
|
|
34 | Another example: Programs I use often output "absolute path: " at the |
|
|
35 | beginning of a line when they process multiple files. The following |
|
|
36 | pattern matches the filename (note, there is a single space at the very |
|
|
37 | end): |
|
|
38 | |
|
|
39 | URxvt.selection.pattern-0: ^(/[^:]+):\ |
|
|
40 | |
|
|
41 | You can look at the source of the selection extension to see more |
|
|
42 | interesting uses, such as parsing a line from beginning to end. |
|
|
43 | |
|
|
44 | This extension also offers the following actions: |
|
|
45 | |
|
|
46 | =over 4 |
|
|
47 | |
|
|
48 | =item rot13 |
|
|
49 | |
|
|
50 | Rot-13 the selection when activated. |
|
|
51 | |
|
|
52 | Example: |
|
|
53 | |
|
|
54 | URxvt.keysym.C-M-r: selection:rot13 |
|
|
55 | |
|
|
56 | =back |
|
|
57 | |
|
|
58 | =cut |
4 | |
59 | |
5 | sub on_user_command { |
60 | sub on_user_command { |
6 | my ($self, $cmd) = @_; |
61 | my ($self, $cmd) = @_; |
7 | |
62 | |
8 | $cmd eq "selection:rot13" |
63 | $cmd eq "selection:rot13" |
|
|
64 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
|
|
65 | |
|
|
66 | () |
|
|
67 | } |
|
|
68 | |
|
|
69 | sub on_action { |
|
|
70 | my ($self, $action) = @_; |
|
|
71 | |
|
|
72 | $action eq "rot13" |
9 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
73 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
10 | |
74 | |
11 | () |
75 | () |
12 | } |
76 | } |
13 | |
77 | |