*** empty log message ***
authorroot <root>
Thu, 12 Jan 2006 12:05:28 +0000 (12:05 +0000)
committerroot <root>
Thu, 12 Jan 2006 12:05:28 +0000 (12:05 +0000)
MANIFEST
doc/rxvtperl.3.html
doc/rxvtperl.3.man.in
doc/rxvtperl.3.txt
src/perl/selection
src/perl/selection-autotransform [new file with mode: 0644]
src/urxvt.pm

index fddf319..025d733 100644 (file)
--- 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
 
index 141b077..7ca5df4 100644 (file)
@@ -97,7 +97,32 @@ arguments, which is very convenient, too, if your <em>ls</em> supports
 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 />
@@ -143,10 +168,38 @@ additionally stores the first match in the current line into the primary
 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 />
@@ -166,6 +219,12 @@ by replacing all line-drawing characters (U+2500 .. U+259F) by a
 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>
index e1bfa50..b0ed948 100644 (file)
@@ -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
index ab963df..3b36c0a 100644 (file)
@@ -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
index 525ee86..f4a9d42 100644 (file)
@@ -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 (file)
index 0000000..db829d5
--- /dev/null
@@ -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;
+   }
+      
+   ()
+}
+
index 33000c1..6367e0c 100644 (file)
@@ -119,14 +119,15 @@ operator) that modify C<$_> as resources:
    ...
 
 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