Vim-Perl

 view release on metacpan or  search on metacpan

lib/Vim/Perl.pm  view on Meta::CPAN

    $res;

}

sub VimExists {
    my $expr = shift;

    ( $EvalCode, $res ) = VIM::Eval( 'exists("' . $expr . '")' );

    $res;

}

sub VimMsgPack {
    my $text = shift;

    VIM::Msg( __PACKAGE__ . "> $text" );

}

sub VimInput {
    my ( $dialog, $default ) = @_;

    unless ( defined $default ) {
        VimCmd( "let input=input(" . "'" . $dialog . "'" . ")" );
    }
    else {
        VimCmd(
            "let input=input(" . "'" . $dialog . "','" . $default . "'" . ")" );
    }

    my $inp = VimVar("input");

    return $inp;
}

=head3 VimChooseFromPrompt

=head4 Usage

	VimChooseFromPrompt($dialog,$list,$sep,@args);

=head4 Input

=over 4

=item $dialog (SCALAR) 

Input dialog message string;

=item $list   (SCALAR) 

String, containing list of values to be selected (separated by $sep);

=item $sep   (SCALAR) 

Separator of values in $list.

=back

This is perl implementation of 
vimscript function F_ChooseFromPrompt(dialog, list, sep, ...)
in funcs.vim

=cut

#function! F_ChooseFromPrompt(dialog, list, sep, ...)

sub VimChooseFromPrompt {
    my ( $dialog, $list, $sep, @args ) = @_;

    unless ( ref $list eq "" ) {
        VimMsg_PE("Input list is not SCALAR ");
        return 0;
    }

    #let inp = input(a:dialog)
    my $inp = VimInput($dialog);

    my @opts = split( "$sep", $list );

    my $empty;
    if (@args) {
        $empty = shift @args;
    }
    else {
        $empty = $list->[0];
    }

    my $result;

    unless ($inp) {
        $result = $empty;
    }
    elsif ( $inp =~ /^\s*(?<num>\d+)\s*$/ ) {
        $result = $opts[ $+{num} - 1 ];
    }
    else {
        $result = $inp;
    }

    return $result;

    #endfunction
}

sub VimCreatePrompt {
    my ( $list, $cols, $listsep ) = @_;

    my $numcommon;

    use integer;

    $numcommon = scalar @$list;

    my $promptstr = "";

    my @tableheader = split( " ", "Number Option" x $cols );
    my $table = Text::TabularDisplay->new(@tableheader);
    my @row;



( run in 1.735 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )