Reply to message «Use and meaning of <plug>», sent 03:02:27 24 July 2011, Sunday by esquifit:
> map <unique> <Leader>XY <Plug>MyscriptMyfunction
> noremap <unique> <script> <Plug>MyscriptMyfunction <SID>Myfunction
> noremap <SID>Myfunction :call <SID>Myfunction()<CR>
Where have you seen such code? Most of time it is
if !hasmapto('<Plug>MyscriptMyfunction')
map <leader>XY <Plug>MyscriptMyfunction
endif
noremap <Plug>MyscriptMyfunction :call <SID>Myfunction()
It does make sense as it allows user to customize the mappings.
> Wouldn't the following line solve the problem given the same
> assumptions (instead of the three above)?
>
> map <unique> <Leader>YX :call MyscriptMyfunction()<CR>
Never write this:
1. User may have exchanged meanings of `:' and `;' or did something else which
will break the above. User is unlikely to remap <Plug>MyscriptMyfunction though
and in
:noremap <Plug>MyscriptMyfunction :call <SID>Myfunction()
it is safe due to `nore'.
2. It does not allow user to customize plugin.
Original message:
> What is the actual value of using <plug>? I've always seen the same
> pattern:
>
> map <unique> <Leader>XY <Plug>MyscriptMyfunction
> noremap <unique> <script> <Plug>MyscriptMyfunction <SID>Myfunction
> noremap <SID>Myfunction :call <SID>Myfunction()<CR>
>
> As far as I understand, <plug> allows users of a (third party) plugin
> to define their own mappings to symbols defined in the plugin as
> <SID>Something. This is apparently necessary because the actual value
> of <SID> is not known in advance and it could change in the course of
> time. However, in order to make use of <plug>, the plugin author is
> expected to craft a name which is globally unique, for instance by
> following the convention '<Plug> scriptname mapname', so that this
> name does not clash with other from other plugins. In the example
> above, this would correspond to '<plug>MyscriptMyfunction'. But then,
> what good is the whole <SID> thing, if the plugin author is still
> expected to use unique global identifiers (here MyscriptMyfunction)?
> Wouldn't the following line solve the problem given the same
> assumptions (instead of the three above)?
>
> map <unique> <Leader>YX :call MyscriptMyfunction()<CR>
>
> I'm evidently missing the main point and I'd be most grateful if
> somebody could show me the light :-)
signature.asc
Description: This is a digitally signed message part.
