MEMBER FUNCTIONS
new
Create a Text::Editor::Vip::Buffer .
my $buffer = new Text::Editor::Vip::Buffer() ;
Reset
Empties the buffer from it's contents as if it was newly created. Plugins are still plugged into the buffer.
$buffer->Reset() ;
LoadAndExpandWith
Loads a perl module (plugin) and adds all it functionality to the buffer
$buffer->LoadAndExpandWith('Text::Editor::Vip::Plugins::File') ;
# we can now read files
$buffer->InsertFile(__FILE__) ;
ExpandWith
Adds a member function to the buffer.
$buffer->ExpandWith
(
'GotoBufferStart' # member function name
, \&some_sub # implementaton for GotoBufferStart
) ;
# we can now go to the buffers start
$buffer->GotoBufferStart() ;
The second argument is optional, if it is not given, Text::Editor::Vip::Buffer will take the sub from the caller namespace
sub GotoBufferStart
{
my $buffer = shift ; # remember we are a plugin to an object oriented module
$buffer->SetModificationPosition,(0, 0) ;
}
$buffer->ExpandWith( 'GotoBufferStart') ;
$buffer->GotoBufferStart() ;
Do
Let you run any perl code on the buffer. The variable $buffer is made available in your perl code.
($result, $message) = $buffer->Do("# comment\n\$buffer->Insert('bar') ;") ;
is($buffer->GetText(), "bar", 'buffer contains \'bar\'' ) ;
Returns (1) on success and (0, "error message") on failure.
GetText
Returns the buffer contents joined with "\n".
See GetTextAsArrayRef.
GetTextAsArrayRef
Returns a copy of the buffers content as an array reference.
See GetText.
MarkedBufferAsEdited
Used to mak the buffer as edited after a modification. You should not need to use this function if you access the buffer through it's interface. Which you should always do.
MarkedBufferAsUndited
Used to mak the buffer as unedited You should not need to use this function.
IsBufferMarkedAsEdited
Used to query the buffer about its state. Returns (1) if the buffer was edit. (0) otherwise.
GetNumberOfLines
Returns the number of lines in the buffer.
GetModificationPosition
Returns the position, line and character, where the next modification will occure.
SetModificationPosition
Sets the position, line and character, where the next modification will occure.
$buffer->SetModificationPosition(0, 15) ;
GetModificationLine
Returns the line where the next modification will occure.
SetModificationLine
Set the line where the next modification will occure.
GetModificationLine
Returns the character where the next modification will occure.
GetModificationLine
Sets the character where the next modification will occure.
GetLineText
Returns the text of the line passes as argument or the current modification line if no argument is passed.
my $line_12_text = $buffer->GetLineText(12) ;
my $current_line_text = $buffer->GetLineText() ;
GetLineLength
Returns the length of the text of the line passes as argument or the current modification line if no argument is passed.
my $line_12_text = $buffer->GetLineText(12) ;
my $current_line_text = $buffer->GetLineText() ;
Backspace
Deletes characters backwards. The number of characters to delete is passed as an argument. Doing a Backspace while at the begining of a line warps to the previous line.
ClearLine
Removes all text from the passed line index or the current modification line if no argument is given. The line itself is not deleted and the modification position is not modified.
$buffer->ClearLine(0) ;
Delete
Deleted, from the modification position, the number of characters passed as argument.
DeleteLine
Deleted, the line passed as argument. if no argument is passed, the current line is deleted. The selection and modification position are not modified.
InsertNewLine
Inserts a new line at the modification position. If the modification position is after the end of the current line, spaces are used to pad the current line.
InsertNewLine takes one parameter that can be set to SMART_INDENTATION or NO_SMART_INDENTATION. If SMART_INDENTATION is used (default) , IndentNewLine is called. IndentNewLine does nothing by default. This lets you define your own indentation strategy. See IndentNewLine.
$buffer->Insert("hi\nThere\nWhats\nYour\nName\n") ;
IndentNewLine
If Insert or InsertNewLine is called with a SMART_INDENTATION argument, IndentNewLine is called. This lets you define your own indentation strategy.
sub my_indenter
{
# modification position is set at the new line
my $this = shift ; # the buffer
my $line_index = shift ; # usefull if we indent depending on previous lines
$this->Insert(' ') ; # silly indentation
$this->MarkBufferAsEdited() ;
}
$buffer->ExpandWith('IndentNewLine', \&my_indenter) ;
$buffer->Insert("hi\nThere\nWhats\nYour\nName\n") ;
is($buffer->GetLineText(1), " There", "Same text") ;
Insert
Inserts a string or a list of strings, passed as an array reference, into the buffer.
$buffer->Insert("bar") ;
my @text = ("Someone\n", "wants me\nNow") ;
$buffer->Insert(\@text);
$buffer->Insert("\t something \n new") ;
Only "\n" is considered special and forces the addition of a new line in the buffer.
Insert takes a second argument . When set to SMART_INDENTATION (the default), IndentNewLine is called to indent the newly inserted line. The default IndentNewLine does nothing but you can override it to implement any indentation you please. If you want to insert raw text, pass NO_SMART_INDENTATION as a second argument.
NO_SMART_INDENTATION is defined in Text::Editor::Vip::Buffer::Constants.
NAME
Text::Editor::Vip::Buffer - Editing engine
SYNOPSIS
use Text::Editor::Vip::Buffer ;
my $buffer = new Text::Editor::Vip::Buffer() ;
DESCRIPTION
This module implements the core functionality for an editing engine. It knows about selection, undo and plugins.
USAGE
BUGS
AUTHOR
Khemir Nadim ibn Hamouda
CPAN ID: NKH
mailto:nadim@khemir.net
http:// no web site
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.