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

59609Re: When do buffer variables become undefined?

Expand Messages
  • Hari Krishna Dara
    Jun 2, 2005
      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.


      Discover Yahoo!
      Use Yahoo! to plan a weekend, have fun online and more. Check it out!
    • Show all 14 messages in this topic