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

Fwd: Re: local autocommand

Expand Messages
  • Hari Krishna Dara
    I meant to send this mail to the group, hit reply instead of reply all. Thanks, Hari ... __________________________________________________ Do you Yahoo!? New
    Message 1 of 1 , Sep 27, 2002
    • 0 Attachment
      I meant to send this mail to the group, hit reply instead of reply all.

      Thanks,
      Hari

      --- Hari Krishna Dara <hari_vim@...> wrote:
      > Date: Fri, 27 Sep 2002 12:14:38 -0700 (PDT)
      > From: Hari Krishna Dara <hari_vim@...>
      > Subject: Re: local autocommand
      > To: kaminsky@...
      >
      > --- Moshe Kaminsky <kaminsky@...> wrote:
      > > Hi,
      > >
      > > I would like a certain command to be executed before I close the buffer
      > > (say, on the BufUnload au event), but only for this buffer (or actually
      > > for this file type). The problem is that if I define an autocommand,
      > > even inside the ftplugin, it is global and will take place from now on
      > > for every buffer I close (I can't identify the file by a pattern). What
      > > I need is a local autocommand. Is there something like this, or is there
      > > some other way to do this?
      > >
      > > Thanks,
      > > Moshe
      >
      > There is nothing like a local autocommand, but you can easily work-around by
      > disabling the autocommands for those buffers that you are not interested,
      > using
      > a buffer local variable.
      >
      > aug MyGroup
      > au!
      > au BufUnload <file pattern> call <SID>DoSomething()
      > aug! END
      > " Assumes that the current buffer is the buffer that you are interested in.
      > let b:doSomethingActive = 1
      >
      > function! s:DoSomething()
      > if !exists("b:doSomethingActive") || ! b:doSomethingActive
      > return
      > endif
      >
      > " Really do something.
      >
      > " If the autocommand should apply only once, optionally clear the buffer
      > local
      > " variable.
      > unlet b:doSomethingActive
      > endfunction
      >
      > HTH,
      > Hari

      __________________________________________________
      Do you Yahoo!?
      New DSL Internet Access from SBC & Yahoo!
      http://sbc.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.