Tuesday, November 29, 2016

What is gained by the extra level of map indirection recommended in help?

The 'write-plugin' section of the help recommends the following
3-level map approach:

map ,c <Plug>TypecorrAdd
noremap <unique> <script> <Plug>TypecorrAdd <SID>Add
noremap <SID>Add :call <SID>Add(expand("<cword>"), 1)<CR>

I understand how it works, but it wasn't immediately clear to me what
was being gained by the middle level of indirection: specifically the
map to <SID>Add. What is the advantage of this strategy over the
following 2-level approach?

map ,c <Plug>TypecorrAdd
noremap <unique> <script> <Plug>TypecorrAdd
\ :call <SID>Add(expand("<cword>"), 1)<CR>

The help says...
"If another script would also map <SID>Add, it would get another
script ID and thus define another mapping."

While this is true, isn't this sort of script-uniqueness already
guaranteed by the use of <SID> in the rhs of the 3rd mapping? I.e.,
:call <SID>Add(...)<CR>

Thanks,
Brett S.

--
--
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: