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
will enlarge the selection.</p>
</dd>
<dd>
-<p>It also offers the following bindable keyboard command:</p>
+<p>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:</p>
+</dd>
+<dd>
+<pre>
+ URxvt.selection.pattern-0: perl-regex
+ URxvt.selection.pattern-1: perl-regex
+ ...</pre>
+</dd>
+<dd>
+<p>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:</p>
+</dd>
+<dd>
+<pre>
+ URxvt.selection.pattern-0: \\|([^|]+)\\|</pre>
+</dd>
+<dd>
+<p>You can look at the source of the selection extension to see more
+interesting uses, such as parsing a line from beginning to end.</p>
+</dd>
+<dd>
+<p>This extension also offers the following bindable keyboard command:</p>
</dd>
<dl>
<dt><strong><a name="item_rot13">rot13</a></strong><br />
selection.</p>
</dd>
<p></p>
-<dt><strong><a name="item_digital_2dclock">digital-clock</a></strong><br />
+<dt><strong><a name="item_selection_2dautotransform">selection-autotransform</a></strong><br />
</dt>
<dd>
-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.
+</dd>
+<dd>
+<p>It works by specifying perl snippets (most useful is a single <code>s///</code>
+operator) that modify <code>$_</code> as resources:</p>
+</dd>
+<dd>
+<pre>
+ URxvt.selection-autotransform.0: transform
+ URxvt.selection-autotransform.1: transform
+ ...</pre>
+</dd>
+<dd>
+<p>For example, the following will transform selections of the form
+<code>filename:number</code>, often seen in compiler messages, into <code>vi +$filename
+$word</code>:</p>
+</dd>
+<dd>
+<pre>
+ URxvt.selection-autotransform.0: s/^(\\S+):(\\d+):?$/vi +$2 \\Q$1\\E\\x0d/</pre>
+</dd>
+<dd>
+<p>And this example matches the same,but replaces it with vi-commands you can
+paste directly into your (vi :) editor:</p>
+</dd>
+<dd>
+<pre>
+ URxvt.selection-autotransform.0: s/^(S+):(d+):?$/\\x1b:e \\Q$1\\E\\x0d:$2\\x0d/</pre>
</dd>
<p></p>
<dt><strong><a name="item_mark_2durls">mark-urls</a></strong><br />
similar-looking ascii character.
</dd>
<p></p>
+<dt><strong><a name="item_digital_2dclock">digital-clock</a></strong><br />
+</dt>
+<dd>
+Displays a digital clock using the built-in overlay.
+</dd>
+<p></p>
<dt><strong><a name="item_example_2drefresh_2dhooks">example-refresh-hooks</a></strong><br />
</dt>
<dd>
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"
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
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
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:
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
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
()
}
+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:]]+)},
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];
--- /dev/null
+#! 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;
+ }
+
+ ()
+}
+
...
For example, the following will transform selections of the form
-C<word:number> into C<vi +$number $word>:
+C<filename:number>, often seen in compiler messages, into C<vi +$filename
+$word>:
- 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