Maxim Kim wrote:
> Is there a way to use vim9 autoloaded function in expression register?
>
> The old way works:
>
> vim9script
> import autoload 'misc.vim'
> iab <buffer> p! println!()<left><c-r>=misc#Eatchar('\s')<cr>
>
> the dotted call doesn't:
>
> vim9script
> import autoload 'misc.vim'
> iab <buffer> p! println!()<left><c-r>=misc.Eatchar('\s')<cr>
>
> E121: Undefined variable: misc
When using a mapping or abbreviation the context of where it was defined
is not used. That is why you need to use <SID> for a script-local
function. This is different from user commands, where the context is
used.
Your "old way" example most likely works because "misc#" finds the
misc.vim script file in an autoload directory. The "import" line
doesn't matter (I haven't tried this though).
When using "misc.Eatchar()" it cannot find "misc" in the current
context. The script context where the abbreviation was defined is not
used.
I can't think of a good way to make this work. Being able to access
"misc", which is script-local in one specific script, from any other
context, means script-local isn't really "local" any more.
The best I can think of is to add a script-local function and use that:
vim9script
import autoload 'misc.vim'
def Eatchar(arg: string): string
return misc.Eatchar(arg)
enddef
iab <buffer> p! println!()<left><c-r>=<SID>Eatchar('\s')<cr>
Disclaimer: I haven't tried this.
--
MAN: Fetchez la vache!
GUARD: Quoi?
MAN: Fetchez la vache!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// 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/20230316122726.868681C0C56%40moolenaar.net.