Reply to message «Re: Use and meaning of <plug>», 
sent 08:08:49 24 July 2011, Sunday
by Tony Mechelynck:

> 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.
Wrong. <SID> mappings are normally visible: check out :map <SNR>: for me it 
shows two mappings from align and one from vimrc. Same for functions: they all 
are global, even anonymous ones. s: for functions and <SID> for functions and 
mappings both only create prefix that should be unique. If you get somewhere a 
script number and substitute <SID> with <SNR>{SID}_ everything will work 
normally:
    call <SNR>107_dosurround('"')
removes surrounding '"' in my vim. Same technique works for {lhs}, but if you 
redefine script functions in this way it will be assigned that script context 
where it was defined, not that mentioned after <SNR>. You can't redefine 
anonymous functions, but you can use call() to call them without having a 
reference.

The only script-local thing is s: dictionary: I do not know how to access it 
without a debugger or without passing it somewhere.

Original message:
> 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.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to