NAME

Vim::X::Line - A line in a Vim buffer

VERSION

version 1.0.1

METHODS

new( buffer => $buffer, index => $i )

Creates a new Vim::X::Buffer object. Both buffer and index arguments are required.

clone

Makes a copy of the object.

content( $new_content )

Sets the content of the line to ne $new_content or, if $new_content is not given, returns the current content.

append( @lines )

Append the @lines after the current line.

Carriage returns in lines will cause them to be splitted.

dec()

Makes the object point to the previous line. Returns the object or undef if at the beginning of the buffer and can't backtrack anymore.

inc()

Makes the object point to the next line. Returns the object or, undef if at the end of the buffer and can't advance anymore.

rewind( $condition )

Move back in the buffer until $condition is met.

The condition can be a regular expression, or a coderef that will return true on success. If the condition is not met, the method returns false and the line index of the object is not modified.

ff( $condition )

Move forward in the buffer until $condition is met.

The condition can be a regular expression, or a coderef that will return true on success. If the condition is not met, the method returns false and the line index of the object is not modified.

BIG HUGE WARNING

When created, the line objects store the buffer and index of the line they correspond to, so they are more like cursors than representations of the actual lines. If lines are added or deleted in the buffer, the object will not be updated in consequence. For example, this won't do what you think:

vim_append( '1 meh', '2 meh', '3 meh' );

for my $line ( vim_lines ) {
    $line->delete if "$line" =~ /meh/;
}

vim_msg join ' ', vim_lines;   # prints '2 meh'

That's because the original line #2 become line #1 after the first delete. For things to work correctly, you can process the lines in reverse order:

vim_append( '1 meh', '2 meh', '3 meh' );

for my $line ( reverse vim_lines ) {
    $line->delete if "$line" =~ /meh/;
}

vim_msg join ' ', vim_lines;   # prints nothing!

OVERLOADING

The line object, when used as a string, will yield its content. And if used in a numerical context, it'll returns its line number.

As an additional piece of sugar is the overloading of '<<=', which sets the content of the line.

$line <<= "$line" =~ s/foo/bar/rg;

# equivalent to

$line->content(  $line->content =~ s/foo/bar/rg );

The Vim::X::Buffer the line belongs to. Read-only.

Sets or gets the line number of the object.

AUTHOR

Yanick Champoux <yanick@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yanick Champoux.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 181:

Unknown directive: =description

Around line 224:

Unknown directive: =attribute

Around line 228:

Unknown directive: =attribute