Re: Save on losing focus in Emacs

From:

Tassilo Horn

Subject:

Re: Save on losing focus in Emacs

Date:

Mon, 02 Jul 2007 11:41:50 +0200

User-agent:

Gnus/5.110007 (No Gnus v0.7) Emacs/22.1.50 (gnu/linux)

Tim X <address@hidden> writes:
Hi Tim,
> However, two functions which may be useful are visible-frame-list and
> filtered-frame-list. To make use of these, I think you would dneed to
> use run-with -idle-timer. Yo could possibly define a function that
> looks to see if visible-frame-list returns anything. If it doesn't,
> then save any buffers with unsaved changes.
One problem might be that the timer has to run very often to save
immediately after losing focus.
> The problem with this is that if you have a big enough display, you
> may have both your emacs frame and some other application both
> 'visible', but focus is in the other application. In which case, this
> wouldn't work.
Hm, I use a tiling window manager, so most of the time all frames are
visible unless they're on another workspace.
> Alternatively, you might be able to use mouse-position to determine
> when the mouse is not in an emacs frame - the docs don't seem very
> clear on this and you may need to experiment to see what this function
> actually returns if it is called when the mouse focus is on another
> app. Its likely emacs will report the last frame the mouse was focused
> on.
I don't use a mouse frequently. Most of the time the pointer is in a
corner of the screen.
> P.S. I do find the OPs example a bit odd. I've used Emacs to develop with for
> years and often need to switch to a browser or some other app and I've never
> ever lost any work.
You got him wrong. Let's assume you edit a html-page in emacs and switch
to the browser to view you changes. But, damn, you forgot to save the
buffer, so you have to switch back to emacs, `C-x C-s' and switch back
to the browser and refresh again. If it had saved your changes
automatically when losing focus, that would not be needed.
Bye,
Tassilo
--
Chuck Norris sleeps with a pillow under his gun.