On 24/07/11 01:02, esquifit wrote:
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)?

The whole <SID> thing is meant to allow creating mappings and functions which are only visible from within the script where they were created (i.e., not in other scripts, not at the command-line, but can be used in autocommands defined in that script). <SID> can also be used in the {rhs} of a mapping created in the same script, to allow some kind of restricted access to script-local functions.

<SID> is guaranteed to be different for every script: in the first script sourced it means <SNR>1_ then in the second script <SNR>2_ etc.

<Plug> is global, meant for mappings etc. that can be seen outside the script.

See also ":help using-<Plug>" for a discussion of the difference between <SID> and <Plug>. Also see the preceding page or so of help text for an example similar to what you quoted above, and how to use it.


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


In the end, you will only see the light if enlightenment comes to you from within. All we can do is try to help.


Best regards,
Tony.
--
Question:
Man Invented Alcohol,
God Invented Grass.
Who do you trust?

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

Reply via email to