Skip to content

Commit e9b892e

Browse files
committed
patch 7.4.1125
Problem: There is no perleval(). Solution: Add perleval(). (Damien)
1 parent 25b2b94 commit e9b892e

File tree

8 files changed

+413
-19
lines changed

8 files changed

+413
-19
lines changed

runtime/doc/eval.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Jan 16
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Jan 17
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1950,6 +1950,7 @@ nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum}
19501950
nr2char( {expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr}
19511951
or( {expr}, {expr}) Number bitwise OR
19521952
pathshorten( {expr}) String shorten directory names in a path
1953+
perleval( {expr}) any evaluate |Perl| expression
19531954
pow( {x}, {y}) Float {x} to the power of {y}
19541955
prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum}
19551956
printf( {fmt}, {expr1}...) String format text
@@ -4778,6 +4779,17 @@ pathshorten({expr}) *pathshorten()*
47784779
< ~/.v/a/myfile.vim ~
47794780
It doesn't matter if the path exists or not.
47804781

4782+
perleval({expr}) *perleval()*
4783+
Evaluate Perl expression {expr} in scalar context and return
4784+
its result converted to Vim data structures. If value can't be
4785+
converted, it returned as string Perl representation.
4786+
Note: If you want a array or hash, {expr} must returns an
4787+
reference of it.
4788+
Example: >
4789+
:echo perleval('[1 .. 4]')
4790+
< [1, 2, 3, 4]
4791+
{only available when compiled with the |+perl| feature}
4792+
47814793
pow({x}, {y}) *pow()*
47824794
Return the power of {x} to the exponent {y} as a |Float|.
47834795
{x} and {y} must evaluate to a |Float| or a |Number|.

runtime/doc/usr_41.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ Various: *various-functions*
921921

922922
luaeval() evaluate Lua expression
923923
mzeval() evaluate |MzScheme| expression
924+
perleval() evaluate Perl expression (|+perl|)
924925
py3eval() evaluate Python expression (|+python3|)
925926
pyeval() evaluate Python expression (|+python|)
926927
wordcount() get byte/word/char count of buffer

src/eval.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv));
657657
static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv));
658658
static void f_or __ARGS((typval_T *argvars, typval_T *rettv));
659659
static void f_pathshorten __ARGS((typval_T *argvars, typval_T *rettv));
660+
#ifdef FEAT_PERL
661+
static void f_perleval __ARGS((typval_T *argvars, typval_T *rettv));
662+
#endif
660663
#ifdef FEAT_FLOAT
661664
static void f_pow __ARGS((typval_T *argvars, typval_T *rettv));
662665
#endif
@@ -8270,6 +8273,9 @@ static struct fst
82708273
{"nr2char", 1, 2, f_nr2char},
82718274
{"or", 2, 2, f_or},
82728275
{"pathshorten", 1, 1, f_pathshorten},
8276+
#ifdef FEAT_PERL
8277+
{"perleval", 1, 1, f_perleval},
8278+
#endif
82738279
#ifdef FEAT_FLOAT
82748280
{"pow", 2, 2, f_pow},
82758281
#endif
@@ -15480,6 +15486,23 @@ f_pathshorten(argvars, rettv)
1548015486
}
1548115487
}
1548215488

15489+
#ifdef FEAT_PERL
15490+
/*
15491+
* "perleval()" function
15492+
*/
15493+
static void
15494+
f_perleval(argvars, rettv)
15495+
typval_T *argvars;
15496+
typval_T *rettv;
15497+
{
15498+
char_u *str;
15499+
char_u buf[NUMBUFLEN];
15500+
15501+
str = get_tv_string_buf(&argvars[0], buf);
15502+
do_perleval(str, rettv);
15503+
}
15504+
#endif
15505+
1548315506
#ifdef FEAT_FLOAT
1548415507
/*
1548515508
* "pow()" function

0 commit comments

Comments
 (0)