From: Iain Patterson Date: Thu, 27 Aug 2009 12:02:40 +0000 (+0100) Subject: Perl extension to massage selections from Vim. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=ec47e959281fd4dc2dce6fad801c10abf02ef4d6;p=profile.git Perl extension to massage selections from Vim. Try to strip off marks and numbers from the start of a selection made within urxvt. It's a bit hacky and assumes that Vim will resize the terminal when displaying marks and numbers. --- diff --git a/.Xdefaults b/.Xdefaults index 2ceb3c9..a2f1c1a 100644 --- a/.Xdefaults +++ b/.Xdefaults @@ -41,7 +41,7 @@ urxvt.secondaryscroll: True urxvt.answerbackString: urxvt ! Change font size. urxvt.perl-lib: .urxvt -urxvt.perl-ext: font +urxvt.perl-ext: font,vimselection urxvt.keysym.M-minus: perl:font:smaller urxvt.keysym.M-equal: perl:font:bigger diff --git a/.urxvt/vimselection b/.urxvt/vimselection new file mode 100644 index 0000000..4a68fab --- /dev/null +++ b/.urxvt/vimselection @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +# Hide Vim stuff like marks and numbers from the selection. +sub on_sel_grab { + my ($self) = @_; + + # Assume that the terminal will have been resized. + return unless $self->{term}->ncol > 80; + + my $selection = $self->{term}->selection; + my @lines = split /\n/, $selection; + my @new; + my $n = 0; + + foreach my $line (@lines) { + # If this is the first line only do the replacement at the beginning. + # Subsequent lines are necessarily captured from the first column. + unless ($n++) { + if (($self->{term}->selection_beg)[1] > 1) { + push @new, $line; + next; + } + } + + # Strip signs, numbers (five or eight columns) and non-line squiggles. + if ($line =~ /^(. )?(~|[ \d]{5}|[ \d]{8})?/) { $line =~ s/// } + + push @new, $line; + } + + # Save the new selection. + $selection = join "\n", @new; + $self->{term}->selection($selection); +}