> It seems that we can use a partial in a legacy function:
> ```vim
> vim9script
> nnoremap <expr> zd <SID>ZdSetup('zd')
> function ZdSetup(cmd)
> set operatorfunc=function('s:Zd',\ [a:cmd])
> return 'g@l'
> endfunction
> def Zd(cmd: string, type: string)
> execute 'normal! ' .. cmd
> enddef
> var lines =<< trim END
> some folded lines {{{
> some folded lines
> some folded lines }}}
> END
> lines->setline(1)
> &foldmethod = 'marker'
> normal zd
> ```
> the fold is correctly deleted
>
> But not in a Vim9 function:
> ```vim
> vim9script
> nnoremap <expr> zd <SID>ZdSetup('zd')
> def ZdSetup(cmd: string): string
> set operatorfunc=function(Zd,\ [cmd])
> return 'g@l'
> enddef
> def Zd(cmd: string, type: string)
> execute 'normal! ' .. cmd
> enddef
> var lines =<< trim END
> some folded lines {{{
> some folded lines
> some folded lines }}}
> END
> lines->setline(1)
> &foldmethod = 'marker'
> normal zd
> ```
> E121: Undefined variable: cmd
>
> Am I missing something? Shouldn't Vim be able to find the `cmd`
> argument in a `:def` function:
The :def function is compiled and turns the "set" command into an EXEC
instruction. The argument is a string, when executed the function
context where "cmd" is defined is not accessible.
It might work to do (untested):
&operatorfunc = 'function(Zd, [' .. cmd .. '])'
--
f y cn rd ths thn y cn hv grt jb n cmptr prgrmmng
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20211116172004.06A341C4CB0%40moolenaar.net.