{bug report] redir in functions

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

{bug report] redir in functions

StarWing

use redir in functions, e.g.
func! Func1()
    redir => funclist
    silent func
    redir END
    " .... other sentence ...

endfunc

funclist maybe a local-variable, but it is globle variable here, must
write
redir => l:funclist
to make funclist a local variable.

the doc only said:
:redi[r] => {var} Redirect messages to a variable.  If the variable
                        doesn't exist, then it is created.  If the variable
                        exists, then it is initialized to an empty string.
                        The variable will remain empty until redirection ends.
                        Only string variables can be used.  After the
                        redirection starts, if the variable is removed or
                        locked or the variable type is changed, then further
                        command output messages will cause errors. {not in Vi}


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

Bram Moolenaar


Weasley wrote:

> use redir in functions, e.g.
> func! Func1()
>     redir => funclist
>     silent func
>     redir END
>     " .... other sentence ...
>
> endfunc
>
> funclist maybe a local-variable, but it is globle variable here, must
> write
> redir => l:funclist
> to make funclist a local variable.
>
> the doc only said:
> :redi[r] => {var} Redirect messages to a variable.  If the variable
> doesn't exist, then it is created.  If the variable
> exists, then it is initialized to an empty string.
> The variable will remain empty until redirection ends.
> Only string variables can be used.  After the
> redirection starts, if the variable is removed or
> locked or the variable type is changed, then further
> command output messages will cause errors. {not in Vi}

It should write to the local variable.  I can change that, but it might
break some existing scripts.

It would be easier to change the documentation, but the behavior would
be quite unexpected.

--
hundred-and-one symptoms of being an internet addict:
211. Your husband leaves you...taking the computer with him and you
     call him crying, and beg him to bring the computer back.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

StarWing



On 3月16日, 上午5时21分, Bram Moolenaar <[hidden email]> wrote:

> Weasley wrote:
> > use redir in functions, e.g.
> > func! Func1()
> >     redir => funclist
> >     silent func
> >     redir END
> >     " .... other sentence ...
>
> > endfunc
>
> > funclist maybe a local-variable, but it is globle variable here, must
> > write
> > redir => l:funclist
> > to make funclist a local variable.
>
> > the doc only said:
> > :redi[r] => {var}       Redirect messages to a variable.  If the variable
> >                    doesn't exist, then it is created.  If the variable
> >                    exists, then it is initialized to an empty string.
> >                    The variable will remain empty until redirection ends.
> >                    Only string variables can be used.  After the
> >                    redirection starts, if the variable is removed or
> >                    locked or the variable type is changed, then further
> >                    command output messages will cause errors. {not in Vi}
>
> It should write to the local variable.  I can change that, but it might
> break some existing scripts.
>
> It would be easier to change the documentation, but the behavior would
> be quite unexpected.
>
> --
> hundred-and-one symptoms of being an internet addict:
> 211. Your husband leaves you...taking the computer with him and you
>      call him crying, and beg him to bring the computer back.
>
>  /// Bram Moolenaar -- [hidden email] --http://www.Moolenaar.net  \\\
> ///        sponsor Vim, vote for features --http://www.Vim.org/sponsor/\\\
> \\\        download, build and distribute --http://www.A-A-P.org       ///
>  \\\            help me help AIDS victims --http://ICCF-Holland.org   ///


thank you for attention. i think it's better to change the behavior,
but don't
change documntation, or add a flag to 'cpo' option. but i think the
best way
is just change the behavior, and point out it in documentation.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

StarWing

btw, have you seen the book "Unix-hater handbook"?  i think
the "existing script" isn't the reason to prevent correcting
mistakes.  if some script isn't work after correct, it must
be the issue/mistake of that script, not Vim, the author can
update it, or the user -- if he/she really love Vim and want
to use this script, they could change it, and upload it to
vim.org. so, i think, the compatibility is important,
especially the compatibility to Vi, but not the
compatibility to mistake/errors.

and another thing, i think in different version of Vim, just
like vim 6.x, 7.x, or 8.x, it needn't make script compatible
to the old version. i mean, sometimes we will find some way
to do things better, and we will find new, conform and
powerful interface to make script more easy to write. in
this case, we needn't save the old-way for compatibility.

the +proc feature is on the way... i'm tring another
interface, i think the +clientsever interface is good, maybe
i can change the Process-Interaction support to compatible
with +clientsever. i will implement Unix version after i
work out the best interface.

the timer functions and commands is diffcult. i can't find a
good way to implement it on Windows (it's easy in *nix).

and, last two question, how to limit user only edit text in
a region (just like emacs) ? and how to highlight a text in
byte-offset of file? i'm working on TextMate-like complete
script, i want to make user can't move cursor to other place,
and can't change text of other place when they are finishing
a tag:

 for ([i|] = 0; [i] < 10; ++[i]) // this other i...

"|" means cursor, [xx] means "xx" are highlighted, i want in
insert mode, user can't move cursor out of the region of []
(even use mouse, and autocmd, and Ctrl-O, and Ctrl-R=...).

then, how can i highlighted "i"? when you input something in
first region, the offset of second and third "i" will
changed, and change the sync-match cmd is complex (is it
expensive to change it ?), can we find any good way to work
out it?

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

Tony Mechelynck
In reply to this post by StarWing

On 15/03/09 04:18, StarWing wrote:

>
> use redir in functions, e.g.
> func! Func1()
>      redir =>  funclist
>      silent func
>      redir END
>      " .... other sentence ...
>
> endfunc
>
> funclist maybe a local-variable, but it is globle variable here, must
> write
> redir =>  l:funclist
> to make funclist a local variable.
>
> the doc only said:
> :redi[r] =>  {var} Redirect messages to a variable.  If the variable
> doesn't exist, then it is created.  If the variable
> exists, then it is initialized to an empty string.
> The variable will remain empty until redirection ends.
> Only string variables can be used.  After the
> redirection starts, if the variable is removed or
> locked or the variable type is changed, then further
> command output messages will cause errors. {not in Vi}




Here's the relavant info, from elsewhere in the docs:

> *global-variable* *g:var*
> Inside functions global variables are accessed with "g:".  Omitting this will
> access a variable local to a function.  But "g:" can also be used in any other
> place if you like.
>
> *local-variable* *l:var*
> Inside functions local variables are accessed without prepending anything.
> But you can also prepend "l:" if you like.  However, without prepending "l:"
> you may run into reserved variable names.  For example "count".  By itself it
> refers to "v:count".  Using "l:count" you can have a local variable with the
> same name.

So, _inside_ a function, funclist (with no explicit namespace) is
equivalent to l:funclist. _Outside_ all functions it is equivalent to
g:funclist.


Best regards,
Tony.
--
We apologise again for the fault in the subtitles.  Those responsible for
sacking the people who have just been sacked have been sacked.
                  "Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

StarWing



On 3月16日, 下午6时15分, Tony Mechelynck <[hidden email]>
wrote:

> On 15/03/09 04:18, StarWing wrote:
>
>
>
>
>
> > use redir in functions, e.g.
> > func! Func1()
> >      redir =>  funclist
> >      silent func
> >      redir END
> >      " .... other sentence ...
>
> > endfunc
>
> > funclist maybe a local-variable, but it is globle variable here, must
> > write
> > redir =>  l:funclist
> > to make funclist a local variable.
>
> > the doc only said:
> > :redi[r] =>  {var}      Redirect messages to a variable.  If the variable
> >                    doesn't exist, then it is created.  If the variable
> >                    exists, then it is initialized to an empty string.
> >                    The variable will remain empty until redirection ends.
> >                    Only string variables can be used.  After the
> >                    redirection starts, if the variable is removed or
> >                    locked or the variable type is changed, then further
> >                    command output messages will cause errors. {not in Vi}
>
> Here's the relavant info, from elsewhere in the docs:
>
> >                                            *global-variable* *g:var*
> > Inside functions global variables are accessed with "g:".  Omitting this will
> > access a variable local to a function.  But "g:" can also be used in any other
> > place if you like.
>
> >                                            *local-variable* *l:var*
> > Inside functions local variables are accessed without prepending anything.
> > But you can also prepend "l:" if you like.  However, without prepending "l:"
> > you may run into reserved variable names.  For example "count".  By itself it
> > refers to "v:count".  Using "l:count" you can have a local variable with the
> > same name.
>
> So, _inside_ a function, funclist (with no explicit namespace) is
> equivalent to l:funclist. _Outside_ all functions it is equivalent to
> g:funclist.

So, is it a bug?
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

iler.ml

2009/3/16 StarWing <[hidden email]>

>
>
>
> On 3月16日, 下午6时15分, Tony Mechelynck <[hidden email]>
> wrote:
> > On 15/03/09 04:18, StarWing wrote:
> >
> >
> >
> >
> >
> > > use redir in functions, e.g.
> > > func! Func1()
> > >      redir =>  funclist
> > >      silent func
> > >      redir END
> > >      " .... other sentence ...
> >
> > > endfunc
> >
> > > funclist maybe a local-variable, but it is globle variable here, must
> > > write
> > > redir =>  l:funclist
> > > to make funclist a local variable.
> >
> > > the doc only said:
> > > :redi[r] =>  {var}      Redirect messages to a variable.  If the variable
> > >                    doesn't exist, then it is created.  If the variable
> > >                    exists, then it is initialized to an empty string.
> > >                    The variable will remain empty until redirection ends.
> > >                    Only string variables can be used.  After the
> > >                    redirection starts, if the variable is removed or
> > >                    locked or the variable type is changed, then further
> > >                    command output messages will cause errors. {not in Vi}
> >
> > Here's the relavant info, from elsewhere in the docs:
> >
> > >                                            *global-variable* *g:var*
> > > Inside functions global variables are accessed with "g:".  Omitting this will
> > > access a variable local to a function.  But "g:" can also be used in any other
> > > place if you like.
> >
> > >                                            *local-variable* *l:var*
> > > Inside functions local variables are accessed without prepending anything.
> > > But you can also prepend "l:" if you like.  However, without prepending "l:"
> > > you may run into reserved variable names.  For example "count".  By itself it
> > > refers to "v:count".  Using "l:count" you can have a local variable with the
> > > same name.
> >
> > So, _inside_ a function, funclist (with no explicit namespace) is
> > equivalent to l:funclist. _Outside_ all functions it is equivalent to
> > g:funclist.
>
> So, is it a bug?

No

It is consistent with other use of g:var, l:var, var inside the function.

redir => g:var      | let g:var = 0       " (in a function) refers to global var
redir => l:var       | let l:var = 0        " (in a function) refers
to local var
redir => var         | let var = 0         " (in a function) refers to
local local var,
                                                   " it's reserved
name like 'count'
Everything is consistent. Where do you see a problem ?

Yakov

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

Benjamin Fritz



On Mar 18, 8:25 am, Yakov Lerner <[hidden email]> wrote:
> redir => var         | let var = 0         " (in a function) refers to
> local local var,
>                                                    " it's reserved
> name like 'count'
> Everything is consistent. Where do you see a problem ?
>

StarWing is saying that he does, in a function, "redir => var" and the
global var gets changed. He needs to use "redir => l:var" to make it
use the local var.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

iler.ml

On Wed, Mar 18, 2009 at 16:27, Ben Fritz <[hidden email]> wrote:

>
>
>
> On Mar 18, 8:25 am, Yakov Lerner <[hidden email]> wrote:
>> redir => var         | let var = 0         " (in a function) refers to
>> local local var,
>>                                                    " it's reserved
>> name like 'count'
>> Everything is consistent. Where do you see a problem ?
>>
>
> StarWing is saying that he does, in a function,
> "redir => var" and the
> global var gets changed.

Not for me.

If I do 'redir => var' in a function,
local virable gets changed.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: {bug report] redir in functions

Tony Mechelynck
In reply to this post by StarWing

On 16/03/09 19:25, StarWing wrote:

>
>
>
> On 3月16日, 下午6时15分, Tony Mechelynck<[hidden email]>
> wrote:
>> On 15/03/09 04:18, StarWing wrote:
>>
>>
>>
>>
>>
>>> use redir in functions, e.g.
>>> func! Func1()
>>>       redir =>   funclist
>>>       silent func
>>>       redir END
>>>       " .... other sentence ...
>>
>>> endfunc
>>
>>> funclist maybe a local-variable, but it is globle variable here, must
>>> write
>>> redir =>   l:funclist
>>> to make funclist a local variable.
>>
>>> the doc only said:
>>> :redi[r] =>   {var}      Redirect messages to a variable.  If the variable
>>>                     doesn't exist, then it is created.  If the variable
>>>                     exists, then it is initialized to an empty string.
>>>                     The variable will remain empty until redirection ends.
>>>                     Only string variables can be used.  After the
>>>                     redirection starts, if the variable is removed or
>>>                     locked or the variable type is changed, then further
>>>                     command output messages will cause errors. {not in Vi}
>>
>> Here's the relavant info, from elsewhere in the docs:
>>
>>>                                             *global-variable* *g:var*
>>> Inside functions global variables are accessed with "g:".  Omitting this will
>>> access a variable local to a function.  But "g:" can also be used in any other
>>> place if you like.
>>
>>>                                             *local-variable* *l:var*
>>> Inside functions local variables are accessed without prepending anything.
>>> But you can also prepend "l:" if you like.  However, without prepending "l:"
>>> you may run into reserved variable names.  For example "count".  By itself it
>>> refers to "v:count".  Using "l:count" you can have a local variable with the
>>> same name.
>>
>> So, _inside_ a function, funclist (with no explicit namespace) is
>> equivalent to l:funclist. _Outside_ all functions it is equivalent to
>> g:funclist.
>
> So, is it a bug?

Ah, if the actual behaviour directly contradicts the documentation, then
either the behaviour is buggy, or the documentation is in error. In this
case I agree with Bram that, in the light of the "principle of least
surprise", it's probably better (but maybe not as easy to fix) to regard
the documentation as right and fix the C code than the opposite.

Best regards,
Tony.
--
ARTHUR: The swallow may fly south with the sun, or the house martin or the
         plover seek warmer hot lands in winter, yet these are not
strangers to
         our land.
SOLDIER: Are you suggesting coconuts migrate?
                  "Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---