/usr/share/vile/perl/winops.pm is in vile-common 9.8s-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | # perl extension module for vile
#
# Below are a small collection of utilities which I wrote to test
# out the Vile::Window facilities after I wrote them. However, these
# do seem to be genuinely useful at times, so I collected them together
# into a single file.
#
# Also, they provide good examples of how to use the Vile::Window
# API.
#
# - Kevin, December 1999.
#
package winops;
use strict;
require Vile::Exporter;
use vars qw(@ISA %REGISTRY);
@ISA = 'Vile::Exporter';
%REGISTRY = (
'equalize-window-height' => [
\&equalize_window_height, 'make all window the same approximate size',
],
'maximize-window-height' => [
\&maximize_window_height,
'make current window as large as possible without deleting other'
. ' windows',
],
'swap-above' =>
[ \&swap_above, 'swap contents of current window and window above', ],
'swap-below' =>
[ \&swap_below, 'swap contents of current window and window below', ],
'new-window' =>
[ \&new_window, 'create a new window and make it current', ],
'delete-windows-below' =>
[ \&delete_windows_below, 'delete windows below current window', ],
'delete-windows-above' =>
[ \&delete_windows_above, 'delete windows above current window', ],
);
# Make all windows of approximately equal height
sub equalize_window_height {
my $n = Vile::window_count();
my $total_height = 0;
my $i;
# Determine total size that we have to work with
for ( $i = $n - 1 ; $i >= 0 ; $i-- ) {
$total_height += Vile::window_at($i)->size;
}
# Make top windows really small (1 line each). Don't bother
# adjusting size of the last window or the penultimate window.
# (We can't adjust the bottom window anyway. There's no need
# to adjust the penultimate window since that's the one we'll
# start with when we readjust below.)
for ( $i = 0 ; $i < $n - 2 ; $i++ ) {
Vile::window_at($i)->size(1);
}
# Now start at the penultimate window and work our way to the
# top, setting the size of each as we go.
for ( $i = $n - 2 ; $i >= 0 ; $i-- ) {
my $desired_height = int( $total_height / $n );
my $wtop = Vile::window_at($i);
my $wbot = Vile::window_at( $i + 1 );
$wtop->size( $wtop->size + $wbot->size - $desired_height );
$total_height -= $desired_height;
$n--;
}
}
# Make the current window as big as possible without deleting other
# windows
sub maximize_window_height {
my $n = Vile::window_count();
my $curwin = Vile::current_window();
my $curidx = $curwin->index;
my $i;
# Make all windows above the current window one line high
for ( $i = 0 ; $i < $curidx ; $i++ ) {
Vile::window_at($i)->size(1);
}
# Make all windows below the current window one line high
for ( $i = $n - 2 ; $i >= $curidx ; $i-- ) {
my $wtop = Vile::window_at($i);
my $wbot = Vile::window_at( $i + 1 );
$wtop->size( $wtop->size + $wbot->size - 1 );
}
}
# Helper subroutine for swapping buffers between windows
sub swap_windows {
my ( $win1, $win2 ) = @_;
# Fetch the current position (dot) and the top lines for the buffers
my @dot1 = $win1->dot;
my @dot2 = $win2->dot;
my $top1 = $win1->topline;
my $top2 = $win2->topline;
# Swap them
my $b_tmp = $win1->buffer;
$win1->buffer( $win2->buffer );
$win2->buffer($b_tmp);
# Reset dot and the top lines for the swapped buffers
$win1->dot(@dot2);
$win2->dot(@dot1);
$win1->topline($top2);
$win2->topline($top1);
}
# Swap buffer associated with current window with window above
sub swap_above {
my $w_below = Vile::current_window();
my $w_above = Vile::window_at( $w_below->index - 1 )
or die "No window above";
swap_windows( $w_above, $w_below );
}
# Swap buffer associated with current window with window below
sub swap_below {
my $w_above = Vile::current_window();
my $w_below = Vile::window_at( $w_above->index + 1 )
or die "No window below";
swap_windows( $w_above, $w_below );
}
# Create a new window a make it current
sub new_window {
my $new = Vile::Window->new or die "Can't create new window";
$new->current_window;
}
# Delete windows below current window
sub delete_windows_below {
while ( Vile::window_count() - 1 > Vile::current_window->index ) {
Vile::window_at( Vile::window_count() - 1 )->delete;
}
}
# Delete windows above current window
sub delete_windows_above {
while ( Vile::current_window->index > 0 ) {
Vile::window_at(0)->delete;
}
}
1;
__DATA__
=head1 NAME
winops - perl extension module for vile's window-operations
=head1 SYNOPSIS
In .vilerc:
perl "use winops"
In [x]vile:
:equalize-window-height
:maximize-window-height
:swap-above
:swap-below
:new-window
:delete-windows-below
:delete-windows-above
=head1 DESCRIPTION
The B<winops> modules is a small collection of utilities written to test
the Vile::Window facilities. They are both useful for scripting, as well
as demonstrating how to use the Vile::Window API.
=head2 equalize-window-height.
Make all windows the same approximate size
=head2 maximize-window-height.
Make the current window as large as possible without deleting other windows.
=head2 swap-above
Swap contents of the current window and the window above it.
=head2 swap-below
Swap contents of the current window and the window below it.
=head2 new-window
Create a new window and make it the current window.
=head2 delete-windows-below
Delete windows below the current window.
=head2 delete-windows-above
Delete windows above the current window.
=head1 AUTHOR
Kevin Buettner
=cut
|