Wednesday, April 27, 2011

Re: Where is defined?

Reply to message «Re: Where is <localleader> defined?»,
sent 22:54:22 27 April 2011, Wednesday
by Steve Litt:

> I'm not sure if I understand what you're writing, but it sounds like what
> you're doing is, instead of creating <voleader> to be used in a map
> command, at mapping time you're running a different syntax. Is that
> correct?
Different syntax? It is just another form of `eval', you can even set
g:voleader to "<localleader>" to keep old behavior untouched by default.

> If it is, it's not going to work in our application because there are tons
> of map commands that need to be changed. It's one thing to globally change
> <localleader> to <voleader>, but it's a little more troublesome (and
> requires considerable testing) to put in the execute and the g: and the
> dot.
I do not see any problems here (considering that <localleader> is used only
inside mapping commands, you are not using :execute to define them and each
command that defines a mapping takes exactly one line which is not shared with
any other command that is not a part of the mapping):
:%s/\v(\s*)(.{-})\<localleader\>(.*)/\=submatch(1).'execute
'.string(submatch(2)).'.g:voleader.'.string(submatch(3))/

> Can you think of another way to create a <voleader> right at the beginning?
I already said: it is not possible without patching vim. I personally just
define mappings only using function provided by my own framework which cares
of using some global variable as the leader and also enables user to override
any {lhs} using global and/or buffer-local variable (unless it is requested
to be unoverridable for some reason).

Original message:
> On Wednesday 27 April 2011 14:16:55 ZyX wrote:
> > Reply to message «Where is <localleader> defined?»,
> > sent 21:58:45 27 April 2011, Wednesday
> >
> > by Steve Litt:
> > > Where is <localleader> defined?
> >
> > It is surprising, but if you open `:h <localleader>' you will get desired
> > answer.
> >
> > > How would I define a similar variable
> > > called <voleader> so that it's available for use in various Vimscript
> > > programs?
> >
> > <localleader> is not a variable, it is expanded to the value of a
> > variable. You can't define a new <...> expression without patching vim.
> >
> > If you want to have a custom prefix, use `execute': instead of
> >
> > nnoremap <voleader>lhs rhs
> >
> > use
> >
> > execute 'nnoremap' g:voleader.'lhs' 'rhs'
> >
> > (note that though I use different strings for different arguments, spaces
> > in lhs and g:voleader won't be escaped: I do this only for readability).
>
> Hi ZyX,
>
> I'm not sure if I understand what you're writing, but it sounds like what
> you're doing is, instead of creating <voleader> to be used in a map
> command, at mapping time you're running a different syntax. Is that
> correct?
>
> If it is, it's not going to work in our application because there are tons
> of map commands that need to be changed. It's one thing to globally change
> <localleader> to <voleader>, but it's a little more troublesome (and
> requires considerable testing) to put in the execute and the g: and the
> dot.
>
> Can you think of another way to create a <voleader> right at the beginning?
>
> Thanks
>
> Steve
>
> Steve Litt
> Recession Relief Package
> http://www.recession-relief.US
> Twitter: http://www.twitter.com/stevelitt

No comments: