Loading ...
Sorry, an error occurred while loading the content.

RE: When do buffer variables become undefined?

Expand Messages
  • David Fishburn
    ... 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
    Message 1 of 14 , Jun 3, 2005
    • 0 Attachment
      > -----Original Message-----
      > From: Hari Krishna Dara [mailto:hari_vim@...]
      > Sent: Thursday, June 02, 2005 1:38 PM
      > To: Eric Arnold
      > Cc: vim@...
      > 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
    • 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
      Message 2 of 14 , Jun 3, 2005
      • 0 Attachment
        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 <fishburn@...> wrote:

        >
        >
        > > -----Original Message-----
        > > From: Hari Krishna Dara [mailto:hari_vim@...]
        > > Sent: Thursday, June 02, 2005 1:38 PM
        > > To: Eric Arnold
        > > Cc: vim@...
        > > 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
        >
        >
      • A. J. Mechelynck
        ... 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
        Message 3 of 14 , Jun 3, 2005
        • 0 Attachment
          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.
        Your message has been successfully submitted and would be delivered to recipients shortly.