ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/eval
Revision: 1.2
Committed: Mon Jul 12 15:08:46 2021 UTC (2 years, 10 months ago) by sf-exg
Branch: MAIN
Changes since 1.1: +4 -4 lines
Log Message:
Improve eval scroll actions

eval scroll actions now scroll to the bottom when scrolling down and
there are less lines to scroll than the ones requested.

Patch by Stephen Talley.

File Contents

# Content
1 #! perl
2
3 =head1 NAME
4
5 eval - evaluate arbitrary perl code using actions
6
7 =head1 EXAMPLES
8
9 URxvt.keysym.M-c: eval:selection_to_clipboard
10 URxvt.keysym.M-v: eval:paste_clipboard
11 URxvt.keysym.M-V: eval:paste_primary
12
13 URxvt.keysym.M-Up: eval:scroll_up 1
14 URxvt.keysym.M-Down: eval:scroll_down 1
15 URxvt.keysym.M-Home: eval:scroll_to_top
16 URxvt.keysym.M-End: eval:scroll_to_bottom
17
18 =head1 DESCRIPTION
19
20 Add support for evaluating arbitrary perl code using actions in keysym
21 resources. If a keysym I<action> takes the form C<eval:STRING>, the
22 specified B<STRING> is evaluated as a Perl expression. While the full
23 urxvt API is available, the following methods are also provided for
24 users' convenience, as they implement basic actions:
25
26 =cut
27
28 our ($self);
29
30 =over 4
31
32 =item scroll_up $count
33
34 =item scroll_up_pages $count
35
36 =item scroll_down $count
37
38 =item scroll_down_pages $count
39
40 Scroll up or down by C<$count> lines or pages.
41
42 =cut
43
44 sub scroll_up ($) {
45 my $lines = $_[0];
46 $self->view_start (List::Util::min 0, $self->view_start - $lines);
47 }
48
49 sub scroll_up_pages ($) {
50 my $lines = $_[0] * ($self->nrow - 1);
51 $self->view_start (List::Util::min 0, $self->view_start - $lines);
52 }
53
54 sub scroll_down ($) {
55 my $lines = $_[0];
56 $self->view_start (List::Util::min 0, $self->view_start + $lines);
57 }
58
59 sub scroll_down_pages ($) {
60 my $lines = $_[0] * ($self->nrow - 1);
61 $self->view_start (List::Util::min 0, $self->view_start + $lines);
62 }
63
64 =item scroll_to_top
65
66 =item scroll_to_bottom
67
68 Scroll to the top or bottom of the scrollback.
69
70 =cut
71
72 sub scroll_to_top () {
73 $self->view_start ($self->top_row);
74 }
75
76 sub scroll_to_bottom () {
77 $self->view_start (0);
78 }
79
80 =item selection_to_clipboard
81
82 Copy the selection to the CLIPBOARD.
83
84 =cut
85
86 sub selection_to_clipboard () {
87 $self->selection ($self->selection, 1);
88 $self->selection_grab (urxvt::CurrentTime, 1);
89 }
90
91 =item paste_primary
92
93 =item paste_clipboard
94
95 Paste the value of the PRIMARY or CLIPBOARD selection.
96
97 =cut
98
99 sub paste_primary () {
100 $self->selection_request (urxvt::CurrentTime, 1);
101 }
102
103 sub paste_clipboard () {
104 $self->selection_request (urxvt::CurrentTime, 3);
105 }
106
107 =back
108
109 =cut
110
111 sub on_action {
112 my ($arg_self, $action) = @_;
113
114 local $self = $arg_self;
115 eval "#line 1 \"$action\"\n$action";
116 die $@ if $@;
117
118 ()
119 }