Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture return value from function in vim?

Example:

function! MyFunction()
  exe 'call Include("'.mykeyw.'")'
  Return value???
endfunction

function! Include(keyw)
   if condition == ""
     return 0
   endif
endfunction

If return in Include() is invoked I want to stop executing MyFunction() as well.

It seems that there is no way other then checking the return value from the return statement from Include() in MyFunction.

But how do I check the return value from Include() in MyFunction()??

P.e. In this case, how do I capture the return value '0' from Include() in MyFunction()?

like image 691
Reman Avatar asked Jan 18 '16 15:01

Reman


1 Answers

Functions can be used as expressions; so you can simply store the return value of Include() in a variable or use it in a conditional:

function! MyFunction()
  let value = Include(mykeyw)    " stored as a variable
                                 " or
  if Include(mykeyw) == 1        " used in a conditional
    echo "Yay!"
  else
    echo "Nay!"
  endif
endfunction

function! Include(keyw)
  if condition == ""
    return 0
  endif
endfunction
like image 165
romainl Avatar answered Nov 15 '22 05:11

romainl