NAME
Text::Editor::Vip::Buffer::Plugins::FindReplace- Find and replace functionality plugin for Vip::Buffer
SYNOPSIS
is_deeply([$buffer->FindOccurence('1', 0, 0)], [0, 5, '1'], 'Found occurence 1') ;
is($buffer->GetText(), $text, 'Text still the same') ;
is($buffer->GetSelectionText(), '', 'GetSelectionText empty') ;
#FindNextOccurence
$buffer->SetModificationPosition(0, 0) ;
is_deeply([$buffer->FindNextOccurence()], [0, 5, '1'], 'FindNextOccurence') ;
$buffer->SetModificationPosition(0, 5) ;
is_deeply([$buffer->FindNextOccurence()], [0, 9, '1'], 'FindNextOccurence') ;
# FindNextOccurenceForCurrentWord
$buffer->SetModificationPosition(0, 0) ;
is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [1, 0, 'line'], 'FindNextOccurenceForCurrentWord') ;
$buffer->SetModificationPosition(1, 0) ;
is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [2, 0, 'line'], 'FindNextOccurenceForCurrentWord') ;
$buffer->SetModificationPosition(4, 0) ;
is_deeply([$buffer->FindNextOccurenceForCurrentWord()], [undef, undef, undef], 'FindNextOccurenceForCurrentWord') ;
# Regex search
is_deeply([$buffer->FindOccurence(qr/..n[a-z]/, 0, 0)], [0, 0, 'line'], 'Found occurence with regex') ;
DESCRIPTION
Find and replace functionality plugin for Vip::Buffer
FUNCTIONS
FindOccurence
Finds the text matching the regex argument starting at the line and character arguments. If no line argument is passed, the modification position is used.
This sub returns an array containing: ($match_line, $match_position, $match_word)
The Selection is not modified by this sub. To set the modification at the match position:
my ($match_line, $match_position, $match_word) = $buffer->FindOccurence($regex, $line, $character) ;
if(defined $match_line)
{
$buffer->SetModificationPosition($match_line, $match_position + length($match_word)) ;
$buffer->{SELECTION}->Set($match_line, $match_position,$match_line, $match_position + length($match_word)) ;
}
FindOccurenceWithinBoundaries
Finds the text matching the regex argument within tha passed boundaries starting at the line and character arguments. If no line argument is passed, the modification position is used.
Arguments:
search regex, a perl qr or a string
start_line (boundary)
start_character (boundary)
end_line (boundary)
end_character (boundary)
line, where to start looking
character, where to start looking
This sub returns an array containing: ($match_line, $match_character, $match_word)
The Selection an the current modification position are not modified by this sub.
$buffer->FindOccurenceWithinBoundaries('line', @boundaries) ;
FindNextOccurence
Find the next occurence matching the search regex.
FindNextOccurenceForCurrentWord
Finds the next occurence for the word at the modification position.
FindOccurenceBackwards
Searches for the regex going backwards in the buffer. Intricate regexes might not work.
FindPreviousOccurence
Searches for the next occurence going backwards in the buffer
FindPreviousOccurenceForCurrentWord
Finds the previous occurence for the word at the modification position.
ReplaceOccurenceWithinBoundaries
Finds a match for the search_regex argument and replaces it with the replacement.
Arguments:
search regex, a perl qr or a string
replacement, a regex, a string or a sub reference (see bellow)
start_line (boundary)
start_character (boundary)
end_line (boundary)
end_character (boundary)
line, where to start looking, optional
character, where to start looking, optional
If line or character are undefined or invalid, the current modification position is used.
Valid boudaries must be passed to this sub or it will return undef. No replacement is done if the searched regex doesn't match within the boudaries.
This sub returns an array containing: ($match_line, $match_position, $match_word, $replacement)
String replacement
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'replacement') ;
Regex replacement
if the replacement is a regex, parenthesis can be be used to assign $1, $2, ..
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'xx$1', @boundaries) ;
Sub replacement
Arguments:
the buffer
matching line
matching character
the match
the sub returns a string which will be be inserted at the matching position.
sub replacement_sub
{
my($buffer, $match_line, $match_character, $match_word) = @_ ;
join(', ', ref($buffer), $match_line, $match_character, $match_word, "\n") ;
}
$buffer->ReplaceOccurenceWithinBoundaries('match_this', \&sub_reference, @boundaries)
ReplaceOccurence
Finds a match for the search_regex argument and replaces it with the replacement.
Arguments:
search regex, a perl qr or a string
replacement, a regex, string or sub reference
line, where to start looking, optional
character, where to start looking, optional
If line or character are undefined or invalid, the current modification position is used.
This sub returns an array containing: ($match_line, $match_position, $match_word, $replacement)
String replacement
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'replacement') ;
Regex replacement
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'xx$1') ;
if the replacement is a regex, parenthesis can be be used to assign $1, $2, ..
$buffer->ReplaceOccurence(qr/..(n[a-z])/, 'xx$1') ;
Sub replacement
Arguments:
the buffer
matching line
matching character
the match
the sub returns a string which will be be inserted at the matching position.
sub replacement_sub
{
my($buffer, $match_line, $match_character, $match_word) = @_ ;
join(', ', ref($buffer), $match_line, $match_character, $match_word, "\n") ;
}
$buffer->ReplaceOccurenceWithinBoundaries('match_this', \&sub_reference)
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.