John Beckett wrote:
> I can't find any documentation on precisely this point but I inferred that
> "<SID>" in the mapping below should not be needed. I hoped that would be
> true from wording (at :help vim9-differences) like the following,
> admittedly for an expression mapping. If <SID> is intended as required,
> perhaps that could be mentioned in the Vim 9 doc.
>
> "When defining an expression mapping, the expression will be evaluated in
> the context of the script where it was defined."
This mentions "expression". The evaluation can be done in the right
context, because it happens before the resulting text is put in the
typeahead buffer. For a normal mapping, the RHS is put in the typeahead
buffer as-is. There is no way to attach the context of the mapping to
it, it's just text.
> vim9script
> def Toggle(): void
> echo 'TOGGLE'
> enddef
> def Init(): void
> nnoremap <buffer> <F8> :call <SID>Toggle()<CR>j
> echo 'Press F8 to toggle selection.'
> enddef
> command! Init call Init()
>
> To test, save the above in a file then enter ':so %' and ':Init'. Then
> press F8.
>
> If "<SID>" is included, pressing F8 shows "TOGGLE". Otherwise I see "E117:
> Unknown function: Toggle".
That's correct, the <SID> part is changed to <SNR>123_, the script
number is prefixed. This happens when the mapping is defined, you can
see it in the output of ":map <F8>".
--
hundred-and-one symptoms of being an internet addict:
26. You check your mail. It says "no new messages." So you check it again.
/// Bram Moolenaar -- Bram@Moolenaar.net -- 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_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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20220208110318.B72E81C03A0%40moolenaar.net.
No comments:
Post a Comment