How to add Tooltips in VIM (Was: Tooltip problem when using UTF-8 and Chinese messages)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to add Tooltips in VIM (Was: Tooltip problem when using UTF-8 and Chinese messages)

Eric Leenman
Apperantly it is possible to add tooltips in VIM.
How do you do that?

I've tried to use Intellisense for VIM,
(http://www.vim.org/scripts/script.php?script_id=747)
without luck .

If there is something else please let me know.

Kind regards,

Eric Leenman




-----Oorspronkelijk bericht-----
Van: [hidden email] [mailto:[hidden email]]
Verzonden: woensdag 25 mei 2005 7:26
Aan: [hidden email]
Onderwerp: Tooltip problem when using UTF-8 and Chinese messages

For simplicity, I tested with the following _vimrc:

language messages zh_CN.UTF-8
set encoding=utf-8
set nocompatible
source $VIMRUNTIME/vimrc_example.vim

After adding setlocale(LC_CTYPE, "C") below setlocale(LC_ALL, "") in
main.c, Vim will start successfully with localized menus and messages
and
support for UTF-8. However, the tooltips are messed. It looks like UTF-8

strings output to a CP936 terminal.

Is this remediable within _vimrc, or is a fix to the source needed?

Best regards,

Yongwei


Disclaimer:
De informatie verzonden met deze e-mail is uitsluitend bestemd voor de geadresseerde. Gebruik van deze informatie door anderen dan de geadresseerde is verboden. Greefa accepteert, mede gezien het onveilige karakter van berichten via internet, geen enkele juridische aansprakelijkheid voor de inhoud van dit bericht.
The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. Use of this information , in whatever way, by others is strictly prohibited and may be unlawful. Greefa does not accept legal responsibility for this e-mail message due to the insecure nature of internet communications.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM (Was: Tooltip problem when using UTF-8 and Chinese messages)

A.J.Mechelynck
Eric Leenman wrote:

> Apperantly it is possible to add tooltips in VIM.
> How do you do that?
>
> I've tried to use Intellisense for VIM,
> (http://www.vim.org/scripts/script.php?script_id=747)
> without luck .
>
> If there is something else please let me know.
>
> Kind regards,
>
> Eric Leenman
[...]

See
        :help balloon-eval
        :help 'ballooneval'
        :help 'balloondelay'
        :help 'balloonexpr'


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM (Was: Tooltip problem when using UTF-8 and Chinese messages)

Eric Arnold

All the WinXP versions I have don't include the sun workshop, which seems to be
where the balloons are.  Is it true that you need to have a Unix version or
compile your own to use the balloons?

--- "A. J. Mechelynck" <[hidden email]> wrote:

> Eric Leenman wrote:
> > Apperantly it is possible to add tooltips in VIM.
> > How do you do that?
> >
> > I've tried to use Intellisense for VIM,
> > (http://www.vim.org/scripts/script.php?script_id=747)
> > without luck .
> >
> > If there is something else please let me know.
> >
> > Kind regards,
> >
> > Eric Leenman
> [...]
>
> See
> :help balloon-eval
> :help 'ballooneval'
> :help 'balloondelay'
> :help 'balloonexpr'
>
>
> Best regards,
> Tony.
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM

A.J.Mechelynck
Eric Arnold wrote:
> All the WinXP versions I have don't include the sun workshop, which seems to be
> where the balloons are.  Is it true that you need to have a Unix version or
> compile your own to use the balloons?
>
> --- "A. J. Mechelynck" <[hidden email]> wrote:

AFAIK, all you need is a version compiled with the +balloon_eval
feature, i.e.,

        :version

includes +balloon_eval ;

        :echo has("balloon_eval")

answers 1.


For Windows, see my Vim page
http://users.skynet.be/antoine.mechelynck/vim/ from which recent
versions of both gvim 6.3 and gvim 7.00aa can be downloaded. My GUI
versions (gvim.exe and gvimd.exe) but not my console versions (vim.exe
and vimd.exe) have +balloon_eval compiled-in.

Please read the accompanying text before downloading.


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

When do buffer variables become undefined?

Eric Arnold
As I understand it, buffer variables are local and persistent to each Vim
buffer in which the script is executed, so once defined, they should be
valid until the buffer is unloaded/deleted/wiped.  
I have a couple of functions like:

        function! s:Init_buffer_variables()
                if exists( 'b:initialized_RH_buf_vars' )
                        return
                endif
                let b:initialized_RH_buf_vars = 1
...
                if b:restore_cmdheight > 0
                        let &cmdheight = b:restore_cmdheight
                endif
...
        endfunction

... do lots of stuff, including setting   b:restore_cmdheight ...

        function! s:Restore_origin_window()
                call s:Init_buffer_variables()
...
                let &cmdheight = b:restore_cmdheight
        endfunction

It usually works fine, but there is some rare case I can't track down
where I get an error saying that   b:restore_cmdheight   is not defined.
When I restart the process, without quitting, the error is gone.  At first
glance, it doesn't seem possible, since the init function is called a few
lines before the variable is referenced.  I think it might have something to
do with re-"source"ing the file a few times, but I can't make it happen at
will.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: When do buffer variables become undefined?

A.J.Mechelynck
Eric Arnold wrote:

> As I understand it, buffer variables are local and persistent to each Vim
> buffer in which the script is executed, so once defined, they should be
> valid until the buffer is unloaded/deleted/wiped.  
> I have a couple of functions like:
>
> function! s:Init_buffer_variables()
> if exists( 'b:initialized_RH_buf_vars' )
> return
> endif
> let b:initialized_RH_buf_vars = 1
> ...
>        if b:restore_cmdheight > 0
>        let &cmdheight = b:restore_cmdheight
>        endif
> ...
> endfunction
>
> ... do lots of stuff, including setting   b:restore_cmdheight ...
>
> function! s:Restore_origin_window()
> call s:Init_buffer_variables()
> ...
> let &cmdheight = b:restore_cmdheight
> endfunction
>
> It usually works fine, but there is some rare case I can't track down
> where I get an error saying that   b:restore_cmdheight   is not defined.
> When I restart the process, without quitting, the error is gone.  At first
> glance, it doesn't seem possible, since the init function is called a few
> lines before the variable is referenced.  I think it might have something to
> do with re-"source"ing the file a few times, but I can't make it happen at
> will.
>
>
>
>
>

The above omits the part where b:restore_cmdheight is created; we see
s:Init_buffer_variables() called from s:Restore_origin_window() but we
don't see where s:Restore_origin_window() is called.

See ":help debug-scripts" about finding out what happens within Vim,
what is executed by sourced scripts, etc.


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM

Eric Arnold
In reply to this post by A.J.Mechelynck

Hmm.  In   :help balloon-eval   which brings up   debugger.txt   it says:
    Balloon evaluation is only available when compiled with the
    |+balloon_eval| and |+sun_workshop| features.

and   :help ballooneval   describing the option setting it also says,
        {only available when compiled with the |+balloon_eval|
                        and |+sun_workshop| or |+netbeans_intg| features}


I didn't find much about how to actually use "balloons", except in
netbeans.txt, which requires the sun compile options.  There is, however,
information on using Tooltips, via "tmenu" etc.  The tooltips seem to
be used and defined for the W32 and X11 GUI vim toolbar with tmenu
(and for other popup menus, but I haven't tried that yet).  However, the
functions from   netbeans.txt   seem to imply the ability to create
balloons in general text areas (sort of, but "not implemented"?):

showBalloon text
                Show a balloon (popup window) at the mouse pointer position,
                containing "text", a string argument.  The balloon should
                disappear when the mouse is moved more than a few pixels.


balloonEval off len type
                The mouse pointer rests on text for a short while.  When "len"
                is zero, there is no selection and the pointer is at position
                "off".  When "len" is non-zero the text from position "off" to
                "off" + "len" is selected.  
                Not implemented yet.


So, I think balloons and tooltips aren't exactly synonymous.  Even though
    has("balloon_eval")

returns "1" the actual balloon commands aren't accessible, though the
tooltips (and "tmenu") which apparently use some of the balloon
functionality are?  Is any of this correct?

What would be cool would be to create a tooltip for a text region, as with
syntax highlighting, but I don't see anything for that.  This would make
scripted applications which rely on "normal" mode (as opposed to
[tear-off]menus) much easier to provide hints and help.



--- "A. J. Mechelynck" <[hidden email]> wrote:

> Eric Arnold wrote:
> > All the WinXP versions I have don't include the sun workshop, which seems
> to be
> > where the balloons are.  Is it true that you need to have a Unix version or
> > compile your own to use the balloons?
> >
> > --- "A. J. Mechelynck" <[hidden email]> wrote:
>
> AFAIK, all you need is a version compiled with the +balloon_eval
> feature, i.e.,
>
> :version
>
> includes +balloon_eval ;
>
> :echo has("balloon_eval")
>
> answers 1.
>
>
> For Windows, see my Vim page
> http://users.skynet.be/antoine.mechelynck/vim/ from which recent
> versions of both gvim 6.3 and gvim 7.00aa can be downloaded. My GUI
> versions (gvim.exe and gvimd.exe) but not my console versions (vim.exe
> and vimd.exe) have +balloon_eval compiled-in.
>
> Please read the accompanying text before downloading.
>
>
> Best regards,
> Tony.
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM

A.J.Mechelynck
Eric Arnold wrote:

> Hmm.  In   :help balloon-eval   which brings up   debugger.txt   it says:
>     Balloon evaluation is only available when compiled with the
>     |+balloon_eval| and |+sun_workshop| features.
>
> and   :help ballooneval   describing the option setting it also says,
> {only available when compiled with the |+balloon_eval|
> and |+sun_workshop| or |+netbeans_intg| features}
>
>
> I didn't find much about how to actually use "balloons", except in
> netbeans.txt, which requires the sun compile options.  There is, however,
> information on using Tooltips, via "tmenu" etc.  The tooltips seem to
> be used and defined for the W32 and X11 GUI vim toolbar with tmenu
> (and for other popup menus, but I haven't tried that yet).  However, the
> functions from   netbeans.txt   seem to imply the ability to create
> balloons in general text areas (sort of, but "not implemented"?):
>
> showBalloon text
> Show a balloon (popup window) at the mouse pointer position,
> containing "text", a string argument.  The balloon should
> disappear when the mouse is moved more than a few pixels.
>
>
> balloonEval off len type
> The mouse pointer rests on text for a short while.  When "len"
> is zero, there is no selection and the pointer is at position
> "off".  When "len" is non-zero the text from position "off" to
> "off" + "len" is selected.  
> Not implemented yet.
>
>
> So, I think balloons and tooltips aren't exactly synonymous.  Even though
>     has("balloon_eval")
>
> returns "1" the actual balloon commands aren't accessible, though the
> tooltips (and "tmenu") which apparently use some of the balloon
> functionality are?  Is any of this correct?
>
> What would be cool would be to create a tooltip for a text region, as with
> syntax highlighting, but I don't see anything for that.  This would make
> scripted applications which rely on "normal" mode (as opposed to
> [tear-off]menus) much easier to provide hints and help.
>
>
>

*options.txt* For Vim version 6.3.  Last change: 2004 Dec 09
--- 967,981 ---
                                                *'balloondelay'* *'bdlay'*
'balloondelay' 'bdlay' number (default: 600)
                        global
                        {not in Vi}
                        {only available when compiled with the |+balloon_eval|
                        feature}
        Delay in milliseconds before a balloon may pop up.  See |balloon-eval|.

                       *'ballooneval'* *'beval'* *'noballooneval'* *'nobeval'*
'ballooneval' 'beval' boolean (default off)
                        global
                        {not in Vi}
                        {only available when compiled with the |+balloon_eval|
                        and |+sun_workshop| or |+netbeans_intg| features}
        Switch on the |balloon-eval| functionality.
---
*debugger.txt*  For Vim version 6.3.  Last change: 2001 Dec 22
--- 85,105 ---
1.5 Balloon Evaluation *balloon-eval*

This feature allows a debugger, or other external tool, to display dynamic
information based on where the mouse is pointing. The purpose of this
feature
was to allow Sun's Visual WorkShop debugger to display expression
evaluations.
However, the feature was implemented in as general a manner as possible and
could be used for displaying other information as well.

The Balloon Evaluation has some settable parameters too.  The font list and
colors can be set via X resources (XmNballoonEvalFontList,
XmNballoonEvalBackground, and XmNballoonEvalForeground).
The 'balloondelay' option sets the delay before an attempt is made to show a
balloon.
The 'ballooneval' option needs to be set to switch it on.

Balloon evaluation is only available when compiled with the |+balloon_eval|
and |+sun_workshop| features.

The Balloon evaluation functions are also used to show a tooltip for the
toolbar.  The 'ballooneval' option does not need to be set for this.
But the
other settings apply.
---

My gvim 6.3 has +balloon_eval +netbeans_intg -sun_workshop.

But things have changed between releases 6 and 7:

*options.txt* For Vim version 7.0aa.  Last change: 2005 May 31
--- 982,1027 ---
                                                *'balloondelay'* *'bdlay'*
'balloondelay' 'bdlay' number (default: 600)
                        global
                        {not in Vi}
                        {only available when compiled with the |+balloon_eval|
                        feature}
        Delay in milliseconds before a balloon may pop up.  See |balloon-eval|.

                       *'ballooneval'* *'beval'* *'noballooneval'* *'nobeval'*
'ballooneval' 'beval' boolean (default off)
                        global
                        {not in Vi}
                        {only available when compiled with the |+balloon_eval|
                        feature}
        Switch on the |balloon-eval| functionality.

                                                     *'balloonexpr'* *'bexpr'*
'balloonexpr' 'bexpr' string (default "")
                        global
                        {not in Vi}
                        {only available when compiled with the |+balloon_eval|
                        feature}
        Expression to show in evaluation balloon.  It is only used when
        'ballooneval' is on.  These variables can be used:

        v:beval_bufnr number of the buffer in which balloon is going to show
        v:beval_winnr number of the window
        v:beval_lnum line number
        v:beval_col column number (byte index)
        v:beval_text word under or after the mouse pointer

        The evaluation of the expression must not have side effects!
        Example: >
    function! MyBalloonExpr()
        return 'Cursor is at line ' . v:beval_lnum .
                \', column ' . v:beval_col .
                \ ' of file ' .  bufname(v:beval_bufnr) .
                \ ' on word "' . v:beval_text . '"'
    endfunction
    set bexpr=MyBalloonExpr()
    set ballooneval
<
        NOTE: The balloon is displayed only if the cursor is on a text
        character.  If the result of evaluating 'balloonexpr' is not empty,
        Vim does not try to send a message to an external debugger (Netbeans
        or Sun Workshop).
---
*debugger.txt*  For Vim version 7.0aa.  Last change: 2005 Mar 29
--- 85,108 ---
1.5 Balloon Evaluation *balloon-eval*

This feature allows a debugger, or other external tool, to display dynamic
information based on where the mouse is pointing.  The purpose of this
feature
was to allow Sun's Visual WorkShop debugger to display expression
evaluations.
However, the feature was implemented in as general a manner as possible and
could be used for displaying other information as well.

The Balloon Evaluation has some settable parameters too.  For Motif the font
list and colors can be set via X resources (XmNballoonEvalFontList,
XmNballoonEvalBackground, and XmNballoonEvalForeground).
The 'balloondelay' option sets the delay before an attempt is made to show a
balloon.
The 'ballooneval' option needs to be set to switch it on.

Balloon evaluation is only available when compiled with the |+balloon_eval|
feature.

The Balloon evaluation functions are also used to show a tooltip for the
toolbar.  The 'ballooneval' option does not need to be set for this.
But the
other settings apply.

Another way to use the balloon is with the 'balloonexpr' option.  This is
completely user definable.
---



Note that in version 7, features other than +balloon_eval are no more
required to make it work; and a new option, 'balloonexpr', has been
introduced.


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to add Tooltips in VIM

Eric Arnold

I just tried   balloonexpr   in Vim7, and it's almost exactly what I was
hoping it would be.  I.e. the example shows how straightforward it is:

   function! MyBalloonExpr()
        let s = 'Cursor is at line ' . v:beval_lnum .
                \', column ' . v:beval_col .
                \ ' of file ' .  bufname(v:beval_bufnr) .
                \ ' on word "' . v:beval_text . '"'
        return s
    endfunction
    set bexpr=MyBalloonExpr()
    set ballooneval


It would be nice if there were an option to have the balloon displayed
for the regular non-mouse cursor, that way hints could be assured to get
to the user whether he's using "normal" Vim commands or mousing.




--- "A. J. Mechelynck" <[hidden email]> wrote:
....
>
>
> Note that in version 7, features other than +balloon_eval are no more
> required to make it work; and a new option, 'balloonexpr', has been
> introduced.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: When do buffer variables become undefined?

Charles E Campbell Jr
In reply to this post by A.J.Mechelynck
Quoting "A. J. Mechelynck" <[hidden email]>:

> Eric Arnold wrote:
> > As I understand it, buffer variables are local and persistent to each Vim
> > buffer in which the script is executed, so once defined, they should be
> > valid until the buffer is unloaded/deleted/wiped.
...
>
> The above omits the part where b:restore_cmdheight is created; we see
> s:Init_buffer_variables() called from s:Restore_origin_window() but we
> don't see where s:Restore_origin_window() is called.
>
> See ":help debug-scripts" about finding out what happens within Vim,
> what is executed by sourced scripts, etc.

May I suggest that you check into Decho.vim --
http://vim.sourceforge.net/scripts/script.php?script_id=120

You'll need to instrument your code (ie. insert calls to Dfunc(), Decho(),
and Dret()), but then you'll get an activity trace.

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: When do buffer variables become undefined?

Hari Krishna Dara
In reply to this post by Eric Arnold

On Wed, 1 Jun 2005 at 10:03pm, Eric Arnold wrote:

> As I understand it, buffer variables are local and persistent to each Vim
> buffer in which the script is executed, so once defined, they should be
> valid until the buffer is unloaded/deleted/wiped.
> I have a couple of functions like:
>
> function! s:Init_buffer_variables()
> if exists( 'b:initialized_RH_buf_vars' )
> return
> endif
> let b:initialized_RH_buf_vars = 1
> ...
>        if b:restore_cmdheight > 0
>        let &cmdheight = b:restore_cmdheight
>        endif
> ...
> endfunction
>
> ... do lots of stuff, including setting   b:restore_cmdheight ...
>
> function! s:Restore_origin_window()
> call s:Init_buffer_variables()
> ...
> let &cmdheight = b:restore_cmdheight
> endfunction
>
> It usually works fine, but there is some rare case I can't track down
> where I get an error saying that   b:restore_cmdheight   is not defined.
> When I restart the process, without quitting, the error is gone.  At first
> glance, it doesn't seem possible, since the init function is called a few
> lines before the variable is referenced.  I think it might have something to
> do with re-"source"ing the file a few times, but I can't make it happen at
> will.

I use buffer variables too but never observed this problem. The only
reason I can think of is that your script temporarily jumps to a
different buffer in the same window or in a different window (which
doesn't have the variable defined) when the code gets executed and that
is what is causing the error. Put some :echomsg or :Decho (using
Dr.Chip's plugin) calls with the current buffer number right before
using the buffer variable in the problem area, and verify that you are
actually in the right buffer.

--
HTH,
Hari


               
__________________________________
Discover Yahoo!
Use Yahoo! to plan a weekend, have fun online and more. Check it out!
http://discover.yahoo.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: When do buffer variables become undefined?

David Fishburn
 

> -----Original Message-----
> From: Hari Krishna Dara [mailto:[hidden email]]
> Sent: Thursday, June 02, 2005 1:38 PM
> To: Eric Arnold
> Cc: [hidden email]
> Subject: Re: When do buffer variables become undefined?
>
>
> On Wed, 1 Jun 2005 at 10:03pm, Eric Arnold wrote:
>
> > As I understand it, buffer variables are local and
> persistent to each
> > Vim buffer in which the script is executed, so once defined, they
> > should be valid until the buffer is unloaded/deleted/wiped.
> > I have a couple of functions like:
> >
> > function! s:Init_buffer_variables()
> > if exists( 'b:initialized_RH_buf_vars' )
> > return
> > endif
> > let b:initialized_RH_buf_vars = 1
> > ...
> >        if b:restore_cmdheight > 0
> >        let &cmdheight = b:restore_cmdheight
> >        endif
> > ...
> > endfunction
> >
> > ... do lots of stuff, including setting   b:restore_cmdheight ...
> >
> > function! s:Restore_origin_window()
> > call s:Init_buffer_variables()
> > ...
> > let &cmdheight = b:restore_cmdheight
> > endfunction
> >
> > It usually works fine, but there is some rare case I can't
> track down
> > where I get an error saying that   b:restore_cmdheight   is
> not defined.
> > When I restart the process, without quitting, the error is
> gone.  At
> > first glance, it doesn't seem possible, since the init function is
> > called a few lines before the variable is referenced.  I think it
> > might have something to do with re-"source"ing the file a
> few times,
> > but I can't make it happen at will.
>
> I use buffer variables too but never observed this problem.
> The only reason I can think of is that your script
> temporarily jumps to a different buffer in the same window or
> in a different window (which doesn't have the variable
> defined) when the code gets executed and that is what is
> causing the error. Put some :echomsg or :Decho (using
> Dr.Chip's plugin) calls with the current buffer number right
> before using the buffer variable in the problem area, and
> verify that you are actually in the right buffer.

Yes, I had a similar issue in the past which took sometime to figure out.
Turned out one of my own autocmds was changing buffers and didn't change it
back at the end of the function.

HTH,
Dave

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: When do buffer variables become undefined?

Eric Arnold

That's something to check out.  I've got a lot of autocommands, and I'm
jumping between buffers a lot.  I'm beginning to wonder if is has something
to with the behaviour of

BufHidden Just after a buffer has become hidden.  That
                                ...
                                NOTE: When this autocommand is executed, the
                                current buffer "%" may be different from the
                                buffer being unloaded "<afile>".

which is also true for bufunload, bufdelete, etc.  I guess I need to
understand exactly when 'current buffer "%" may be different' from
what I'm expecting.




--- David Fishburn <[hidden email]> wrote:

>  
>
> > -----Original Message-----
> > From: Hari Krishna Dara [mailto:[hidden email]]
> > Sent: Thursday, June 02, 2005 1:38 PM
> > To: Eric Arnold
> > Cc: [hidden email]
> > Subject: Re: When do buffer variables become undefined?
> >
> >
> > On Wed, 1 Jun 2005 at 10:03pm, Eric Arnold wrote:
> >
> > > As I understand it, buffer variables are local and
> > persistent to each
> > > Vim buffer in which the script is executed, so once defined, they
> > > should be valid until the buffer is unloaded/deleted/wiped.
> > > I have a couple of functions like:
> > >
...

> > >
> > > It usually works fine, but there is some rare case I can't
> > track down
> > > where I get an error saying that   b:restore_cmdheight   is
> > not defined.
> > > When I restart the process, without quitting, the error is
> > gone.  At
> > > first glance, it doesn't seem possible, since the init function is
> > > called a few lines before the variable is referenced.  I think it
> > > might have something to do with re-"source"ing the file a
> > few times,
> > > but I can't make it happen at will.
> >
> > I use buffer variables too but never observed this problem.
> > The only reason I can think of is that your script
> > temporarily jumps to a different buffer in the same window or
> > in a different window (which doesn't have the variable
> > defined) when the code gets executed and that is what is
> > causing the error. Put some :echomsg or :Decho (using
> > Dr.Chip's plugin) calls with the current buffer number right
> > before using the buffer variable in the problem area, and
> > verify that you are actually in the right buffer.
>
> Yes, I had a similar issue in the past which took sometime to figure out.
> Turned out one of my own autocmds was changing buffers and didn't change it
> back at the end of the function.
>
> HTH,
> Dave
>
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: When do buffer variables become undefined?

A.J.Mechelynck
Eric Arnold wrote:

> That's something to check out.  I've got a lot of autocommands, and I'm
> jumping between buffers a lot.  I'm beginning to wonder if is has something
> to with the behaviour of
>
> BufHidden Just after a buffer has become hidden.  That
>        ...
> NOTE: When this autocommand is executed, the
> current buffer "%" may be different from the
> buffer being unloaded "<afile>".
>
> which is also true for bufunload, bufdelete, etc.  I guess I need to
> understand exactly when 'current buffer "%" may be different' from
> what I'm expecting.

I suppose that one case is if 'hidden' is set and you execute ":only".
There may be other cases. The morality is that anything invoked by an
autocommand from BufHidden, BufUnload, BufDelete, etc., shouldn't rely
of what the current buffer is. (And remember: if at that point you
switch buffers back and forth, autocommands such as WinEnter or BufEnter
won't be triggered unless "nested".)

Best regards,
Tony.

Loading...