From: root Date: Thu, 12 Jan 2006 12:05:28 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=96e4164d490c62965553ff77922db2a3509bbb60;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/MANIFEST b/MANIFEST index fddf319c..025d7332 100644 --- a/MANIFEST +++ b/MANIFEST @@ -175,9 +175,10 @@ src/perl/urxvt-popup src/perl/selection src/perl/option-popup src/perl/selection-popup +src/perl/selection-autotransform src/perl/searchable-scrollback +src/perl/mark-urls src/perl/example-refresh-hooks src/perl/block-graphics-to-ascii src/perl/digital-clock -src/perl/mark-urls diff --git a/doc/rxvtperl.3.html b/doc/rxvtperl.3.html index 141b077a..7ca5df43 100644 --- a/doc/rxvtperl.3.html +++ b/doc/rxvtperl.3.html @@ -97,7 +97,32 @@ arguments, which is very convenient, too, if your ls supports will enlarge the selection.

-

It also offers the following bindable keyboard command:

+

The selection works by trying to match a number of regexes and displaying +them in increasing order of length. You can add your own regexes by +specifying resources of the form:

+
+
+
+   URxvt.selection.pattern-0: perl-regex
+   URxvt.selection.pattern-1: perl-regex
+   ...
+
+
+

The index number (0, 1...) must not have any holes, and each regex must +contain at least one pair of capturing parentheses, which will be used for +the match. For example, the followign adds a regex that matches everything +between two vertical bars:

+
+
+
+   URxvt.selection.pattern-0: \\|([^|]+)\\|
+
+
+

You can look at the source of the selection extension to see more +interesting uses, such as parsing a line from beginning to end.

+
+
+

This extension also offers the following bindable keyboard command:

rot13
@@ -143,10 +168,38 @@ additionally stores the first match in the current line into the primary selection.

-
digital-clock
+
selection-autotransform
-Displays a digital clock using the built-in overlay. +This selection allows you to do automatic transforms on a selection +whenever a selection is made. +
+
+

It works by specifying perl snippets (most useful is a single s/// +operator) that modify $_ as resources:

+
+
+
+   URxvt.selection-autotransform.0: transform
+   URxvt.selection-autotransform.1: transform
+   ...
+
+
+

For example, the following will transform selections of the form +filename:number, often seen in compiler messages, into vi +$filename +$word:

+
+
+
+   URxvt.selection-autotransform.0: s/^(\\S+):(\\d+):?$/vi +$2 \\Q$1\\E\\x0d/
+
+
+

And this example matches the same,but replaces it with vi-commands you can +paste directly into your (vi :) editor:

+
+
+
+   URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\\x1b:e \\Q$1\\E\\x0d:$2\\x0d/

mark-urls
@@ -166,6 +219,12 @@ by replacing all line-drawing characters (U+2500 .. U+259F) by a similar-looking ascii character.

+
digital-clock
+
+
+Displays a digital clock using the built-in overlay. +
+

example-refresh-hooks
diff --git a/doc/rxvtperl.3.man.in b/doc/rxvtperl.3.man.in index e1bfa50f..b0ed9488 100644 --- a/doc/rxvtperl.3.man.in +++ b/doc/rxvtperl.3.man.in @@ -183,7 +183,29 @@ arguments, which is very convenient, too, if your \fIls\fR supports A double-click usually selects the word under the cursor, further clicks will enlarge the selection. .Sp -It also offers the following bindable keyboard command: +The selection works by trying to match a number of regexes and displaying +them in increasing order of length. You can add your own regexes by +specifying resources of the form: +.Sp +.Vb 3 +\& URxvt.selection.pattern-0: perl-regex +\& URxvt.selection.pattern-1: perl-regex +\& ... +.Ve +.Sp +The index number (0, 1...) must not have any holes, and each regex must +contain at least one pair of capturing parentheses, which will be used for +the match. For example, the followign adds a regex that matches everything +between two vertical bars: +.Sp +.Vb 1 +\& URxvt.selection.pattern-0: \e\e|([^|]+)\e\e| +.Ve +.Sp +You can look at the source of the selection extension to see more +interesting uses, such as parsing a line from beginning to end. +.Sp +This extension also offers the following bindable keyboard command: .RS 4 .IP "rot13" 4 .IX Item "rot13" @@ -218,9 +240,34 @@ bottom. \f(CW\*(C`Escape\*(C'\fR leaves search mode and returns to the point whe was started, while \f(CW\*(C`Enter\*(C'\fR or \f(CW\*(C`Return\*(C'\fR stay at the current position and additionally stores the first match in the current line into the primary selection. -.IP "digital-clock" 4 -.IX Item "digital-clock" -Displays a digital clock using the built-in overlay. +.IP "selection-autotransform" 4 +.IX Item "selection-autotransform" +This selection allows you to do automatic transforms on a selection +whenever a selection is made. +.Sp +It works by specifying perl snippets (most useful is a single \f(CW\*(C`s///\*(C'\fR +operator) that modify \f(CW$_\fR as resources: +.Sp +.Vb 3 +\& URxvt.selection-autotransform.0: transform +\& URxvt.selection-autotransform.1: transform +\& ... +.Ve +.Sp +For example, the following will transform selections of the form +\&\f(CW\*(C`filename:number\*(C'\fR, often seen in compiler messages, into \f(CW\*(C`vi +$filename +$word\*(C'\fR: +.Sp +.Vb 1 +\& URxvt.selection-autotransform.0: s/^(\e\eS+):(\e\ed+):?$/vi +$2 \e\eQ$1\e\eE\e\ex0d/ +.Ve +.Sp +And this example matches the same,but replaces it with vi-commands you can +paste directly into your (vi :) editor: +.Sp +.Vb 1 +\& URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\e\ex1b:e \e\eQ$1\e\eE\e\ex0d:$2\e\ex0d/ +.Ve .IP "mark-urls" 4 .IX Item "mark-urls" Uses per-line display filtering (\f(CW\*(C`on_line_update\*(C'\fR) to underline urls and @@ -232,6 +279,9 @@ the \s-1URL\s0 as first argument. A not very useful example of filtering all text output to the terminal, by replacing all line-drawing characters (U+2500 .. U+259F) by a similar-looking ascii character. +.IP "digital-clock" 4 +.IX Item "digital-clock" +Displays a digital clock using the built-in overlay. .IP "example-refresh-hooks" 4 .IX Item "example-refresh-hooks" Displays a very simple digital clock in the upper right corner of the diff --git a/doc/rxvtperl.3.txt b/doc/rxvtperl.3.txt index ab963dfc..3b36c0a2 100644 --- a/doc/rxvtperl.3.txt +++ b/doc/rxvtperl.3.txt @@ -41,7 +41,25 @@ PREPACKAGED EXTENSIONS A double-click usually selects the word under the cursor, further clicks will enlarge the selection. - It also offers the following bindable keyboard command: + The selection works by trying to match a number of regexes and + displaying them in increasing order of length. You can add your own + regexes by specifying resources of the form: + + URxvt.selection.pattern-0: perl-regex + URxvt.selection.pattern-1: perl-regex + ... + + The index number (0, 1...) must not have any holes, and each regex + must contain at least one pair of capturing parentheses, which will + be used for the match. For example, the followign adds a regex that + matches everything between two vertical bars: + + URxvt.selection.pattern-0: \\|([^|]+)\\| + + You can look at the source of the selection extension to see more + interesting uses, such as parsing a line from beginning to end. + + This extension also offers the following bindable keyboard command: rot13 Rot-13 the selection when activated. Used via keyboard trigger: @@ -72,8 +90,27 @@ PREPACKAGED EXTENSIONS stay at the current position and additionally stores the first match in the current line into the primary selection. - digital-clock - Displays a digital clock using the built-in overlay. + selection-autotransform + This selection allows you to do automatic transforms on a selection + whenever a selection is made. + + It works by specifying perl snippets (most useful is a single "s///" + operator) that modify $_ as resources: + + URxvt.selection-autotransform.0: transform + URxvt.selection-autotransform.1: transform + ... + + For example, the following will transform selections of the form + "filename:number", often seen in compiler messages, into "vi + +$filename $word": + + URxvt.selection-autotransform.0: s/^(\\S+):(\\d+):?$/vi +$2 \\Q$1\\E\\x0d/ + + And this example matches the same,but replaces it with vi-commands + you can paste directly into your (vi :) editor: + + URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\\x1b:e \\Q$1\\E\\x0d:$2\\x0d/ mark-urls Uses per-line display filtering ("on_line_update") to underline urls @@ -86,6 +123,9 @@ PREPACKAGED EXTENSIONS terminal, by replacing all line-drawing characters (U+2500 .. U+259F) by a similar-looking ascii character. + digital-clock + Displays a digital clock using the built-in overlay. + example-refresh-hooks Displays a very simple digital clock in the upper right corner of the window. Illustrates overwriting the refresh callbacks to create diff --git a/src/perl/selection b/src/perl/selection index 525ee86f..f4a9d424 100644 --- a/src/perl/selection +++ b/src/perl/selection @@ -9,6 +9,17 @@ sub on_keyboard_command { () } +sub on_init { + my ($self) = @_; + + for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) { + no re 'eval'; # just to be sure + push @{ $self->{patterns} }, qr/$res/; + } + + () +} + # "find interetsing things"-patterns my @mark_patterns = ( qr{([[:word:]]+)}, @@ -55,7 +66,7 @@ sub on_sel_extend { my @matches; - for my $regex (@mark_patterns) { + for my $regex (@mark_patterns, @{ $self->{patterns} }) { while ($text =~ /$regex/g) { if ($-[1] <= $markofs and $markofs <= $+[1]) { my $ofs = $-[1]; diff --git a/src/perl/selection-autotransform b/src/perl/selection-autotransform new file mode 100644 index 00000000..db829d51 --- /dev/null +++ b/src/perl/selection-autotransform @@ -0,0 +1,54 @@ +#! perl + +sub msg { + my ($self, $msg) = @_; + + my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); + $overlay->set (0, 0, $msg); + my $iow; $iow = urxvt::timer->new->start (urxvt::NOW + 2)->cb (sub { + undef $overlay; + undef $iow; + }); +} + +sub on_init { + my ($self) = @_; + + unless (urxvt::safe) { + warn "running with elevated privileges, ignoring selection-autotransform patterns"; + return; + } + + for (my $idx = 0; defined (my $res = urxvt::untaint $self->x_resource ("selection-autotransform.$idx")); $idx++) { + my $transform = eval "sub { $res }"; + + if ($transform) { + push @{ $self->{transforms} }, $transform; + } else { + warn "$res: $@"; + } + } + + () +} + +sub on_sel_grab { + my ($self) = @_; + + my $text = $self->selection; + local $_ = $text; + + for my $transform (@{ $self->{transforms} }) { + $transform->(); + if ($text ne $_) { + $self->selection ($_); + s/[\x00-\x1f\x80-\x9f]/·/g; + $self->msg ($self->special_encode ("auto-transformed to $_")); + } + + last; + } + + () +} + diff --git a/src/urxvt.pm b/src/urxvt.pm index 33000c18..6367e0ce 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -119,14 +119,15 @@ operator) that modify C<$_> as resources: ... For example, the following will transform selections of the form -C into C: +C, often seen in compiler messages, into C: - URxvt.selection-autotransform.0: s/^(S+):(d+):?$/vi +$2 $1\\x0d/ + URxvt.selection-autotransform.0: s/^(\\S+):(\\d+):?$/vi +$2 \\Q$1\\E\\x0d/ And this example matches the same,but replaces it with vi-commands you can -paste directory into your (vi :) editor: +paste directly into your (vi :) editor: - URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\\x1b:e $1\\x0d:$2\\x0d/ + URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\\x1b:e \\Q$1\\E\\x0d:$2\\x0d/ =item mark-urls