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

Re: Fwd: FocusLost, FocusGained, and system() calls

Expand Messages
  • Benjamin Fritz
    ... This works : augroup TEST au! autocmd FocusLost * echomsg focus lost autocmd FocusGained * echomsg focus gained augroup END set ei=all echomsg
    Message 1 of 5 , Oct 26, 2011
    • 0 Attachment
      On Wed, Oct 26, 2011 at 3:26 PM, Bram Moolenaar <Bram@...> wrote:
      >> > The script contains:
      >> >
      >> >        set ei=all
      >> >        echomsg system("xterm -e 'echo system command; exit'")
      >> >        set ei&
      >> >
      >> > The problem is that the autocommands trigger later.  The focus events
      >> > are put in the type ahead buffer.  That's to avoid asynchronous
      >> > autocommands causing trouble.
      >> >
      >>
      >> OK. So, how would one temporarily ignore Focus\(Lost\|Gained\) autocommands?
      >
      > Somehow read a character.  Haven't tried what would work.

      This "works":

      augroup TEST
      au!
      autocmd FocusLost * echomsg "focus lost"
      autocmd FocusGained * echomsg "focus gained"
      augroup END

      set ei=all
      echomsg system("echo system command")
      echo "press any key to continue"
      call getchar()
      set ei&

      By "works" I mean that I do not see a "focus gained" message. It
      appears your diagnosis is on the right track.

      >
      >> And, why don't we get FocusLost? I would expect never to get one
      >> without the other.
      >
      > I get both.  I'm on Unbutu with GTK.  Perhaps MS-Windows is different?

      Yeah Gary Johnson tried on Fedora 11 and got neither the FocusGained
      nor the FocusLost events either with or without the eventignore
      setting. It certainly looks like Windows acts differently.

      With this on Windows XP 64-bit (eventignore removed):

      autocmd FocusLost * echomsg "focus lost"
      autocmd FocusGained * echomsg "focus gained"

      "set ei=all
      echomsg system("echo system command")
      "set ei&

      I get only FocusGained...no FocusLost.

      I get the same thing with the commands in there (uncommented).

      > These are Windows messages WM_KILLFOCUS and WM_SETFOCUS, thus it's not
      > under control of Vim.
      >

      That's not a good sign. Is there some way to make sure Vim notices it
      lost focus when using system()?

      As a workaround, maybe using feedkeys() somehow can reset the
      eventignore to allow ignoring of FocusGained? This seems VERY kludgy
      though, even if it works.

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.