Friday, December 30, 2016

'maxfuncdepth' ignored

Consider the following recursive user function...

fu! Fun(count)
if a:count > 0
call Fun(a:count - 1)
endif
endfu

:h 'maxfuncdepth' describes the option's purpose as follows:

Maximum depth of function calls for user functions. This normally
catches endless recursion. When using a recursive function with
more depth, set 'maxfuncdepth' to a bigger number.

So I would expect to be able to make the following recursive call with no error:
:set maxfuncdepth=1000
:call Fun(500)

But I get the following error after slightly less than 200 recursive calls:
E169: Command too recursive

The documentation for E169 states the following:

This happens when an Ex command executes an Ex command that executes an Ex
command, etc. This is only allowed 200 times. When it's more there probably
is an endless loop. Probably a |:execute| or |:source| command is involved.

It's as though the :call (Ex command) is triggering the error long
before the number of calls to the user function Fun() has reached
'maxfuncdepth'. But if this is the way it's supposed to work, what's
the point of 'maxfuncdepth'? Don't all calls to user functions involve
an Ex command (since both `call' and `let' are Ex commands)? Is there
a way to permit more than 200 recursive calls to Fun() without
triggering the error?

Thanks,
Brett Stahlman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: