summaryrefslogtreecommitdiffstats
path: root/src/perl
diff options
context:
space:
mode:
authorsf-exg <sf-exg>2014-05-23 20:54:42 +0000
committersf-exg <sf-exg>2014-05-23 20:54:42 +0000
commit71b248801a0fd85fec5e98827303e4b83ab39182 (patch)
treea27efa11745605b86398c4d552cdf92acf0a0789 /src/perl
parent8c0b328bbc429059a2b9462c9b5dcbbeb0d173e7 (diff)
Add eval extension.
Diffstat (limited to 'src/perl')
-rw-r--r--src/perl/eval119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/perl/eval b/src/perl/eval
new file mode 100644
index 0000000..1f38c3b
--- /dev/null
+++ b/src/perl/eval
@@ -0,0 +1,119 @@
+#! perl
+
+=head1 NAME
+
+eval - evaluate arbitrary perl code using actions
+
+=head1 EXAMPLES
+
+ URxvt.keysym.M-c: eval:selection_to_clipboard
+ URxvt.keysym.M-v: eval:paste_clipboard
+ URxvt.keysym.M-V: eval:paste_primary
+
+ URxvt.keysym.M-Up: eval:scroll_up 1
+ URxvt.keysym.M-Down: eval:scroll_down 1
+ URxvt.keysym.M-Home: eval:scroll_to_top
+ URxvt.keysym.M-End: eval:scroll_to_bottom
+
+=head1 DESCRIPTION
+
+Add support for evaluating arbitrary perl code using actions in keysym
+resources. If a keysym I<action> takes the form C<eval:STRING>, the
+specified B<STRING> is evaluated as a Perl expression. While the full
+urxvt API is available, the following methods are also provided for
+users' convenience, as they implement basic actions:
+
+=cut
+
+our ($self);
+
+=over 4
+
+=item scroll_up $count
+
+=item scroll_up_pages $count
+
+=item scroll_down $count
+
+=item scroll_down_pages $count
+
+Scroll up or down by C<$count> lines or pages.
+
+=cut
+
+sub scroll_up ($) {
+ my $lines = $_[0];
+ $self->view_start ($self->view_start - $lines);
+}
+
+sub scroll_up_pages ($) {
+ my $lines = $_[0] * ($self->nrow - 1);
+ $self->view_start ($self->view_start - $lines);
+}
+
+sub scroll_down ($) {
+ my $lines = $_[0];
+ $self->view_start ($self->view_start + $lines);
+}
+
+sub scroll_down_pages ($) {
+ my $lines = $_[0] * ($self->nrow - 1);
+ $self->view_start ($self->view_start + $lines);
+}
+
+=item scroll_to_top
+
+=item scroll_to_bottom
+
+Scroll to the top or bottom of the scrollback.
+
+=cut
+
+sub scroll_to_top () {
+ $self->view_start ($self->top_row);
+}
+
+sub scroll_to_bottom () {
+ $self->view_start (0);
+}
+
+=item selection_to_clipboard
+
+Copy the selection to the CLIPBOARD.
+
+=cut
+
+sub selection_to_clipboard () {
+ $self->selection ($self->selection, 1);
+ $self->selection_grab (urxvt::CurrentTime, 1);
+}
+
+=item paste_primary
+
+=item paste_clipboard
+
+Paste the value of the PRIMARY or CLIPBOARD selection.
+
+=cut
+
+sub paste_primary () {
+ $self->selection_request (urxvt::CurrentTime, 1);
+}
+
+sub paste_clipboard () {
+ $self->selection_request (urxvt::CurrentTime, 3);
+}
+
+=back
+
+=cut
+
+sub on_action {
+ my ($arg_self, $action) = @_;
+
+ local $self = $arg_self;
+ eval "#line 1 \"$action\"\n$action";
+ die $@ if $@;
+
+ ()
+}