ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-autotransform
(Generate patch)

Comparing rxvt-unicode/src/perl/selection-autotransform (file contents):
Revision 1.9 by root, Wed Jun 6 15:06:41 2012 UTC vs.
Revision 1.11 by root, Sun Jun 10 17:31:53 2012 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:%.:string:autotransform expression 3#:META:X_RESOURCE:%.:string:autotransform expression
4
5=head1 NAME
6
7 selection-autotransform - automatically transform select text
8
9=head1 DESCRPIPTION
10
11This selection allows you to do automatic transforms on a selection
12whenever a selection is made.
13
14It works by specifying perl snippets (most useful is a single C<s///>
15operator) that modify C<$_> as resources:
16
17 URxvt.selection-autotransform.0: transform
18 URxvt.selection-autotransform.1: transform
19 ...
20
21For example, the following will transform selections of the form
22C<filename:number>, often seen in compiler messages, into C<vi +$filename
23$word>:
24
25 URxvt.selection-autotransform.0: s/^([^:[:space:]]+):(\\d+):?$/vi +$2 \\Q$1\\E\\x0d/
26
27And this example matches the same,but replaces it with vi-commands you can
28paste directly into your (vi :) editor:
29
30 URxvt.selection-autotransform.0: s/^([^:[:space:]]+(\\d+):?$/:e \\Q$1\\E\\x0d:$2\\x0d/
31
32Of course, this can be modified to suit your needs and your editor :)
33
34To expand the example above to typical perl error messages ("XXX at
35FILENAME line YYY."), you need a slightly more elaborate solution:
36
37 URxvt.selection.pattern-0: ( at .*? line \\d+[,.])
38 URxvt.selection-autotransform.0: s/^ at (.*?) line (\\d+)[,.]$/:e \\Q$1\E\\x0d:$2\\x0d/
39
40The first line tells the selection code to treat the unchanging part of
41every error message as a selection pattern, and the second line transforms
42the message into vi commands to load the file.
43
44=cut
4 45
5sub msg { 46sub msg {
6 my ($self, $msg) = @_; 47 my ($self, $msg) = @_;
7 48
8 my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); 49 my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1);
14} 55}
15 56
16sub on_init { 57sub on_init {
17 my ($self) = @_; 58 my ($self) = @_;
18 59
19 for (my $idx = 0; defined (my $res = $self->x_resource ("selection-autotransform.$idx")); $idx++) { 60 for (my $idx = 0; defined (my $res = $self->x_resource ("%.$idx")); $idx++) {
20 $res = $self->locale_decode ($res); 61 $res = $self->locale_decode ($res);
21 my $transform = eval "sub { $res }"; 62 my $transform = eval "sub { $res }";
22 63
23 if ($transform) { 64 if ($transform) {
24 push @{ $self->{transforms} }, $transform; 65 push @{ $self->{transforms} }, $transform;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines