Hello I am trying to write a Python program to save Emacs' files on the loss of window focus.
For that I wrote a Python programm that creates a full gtk application and uses the wnck module:
from Pymacs import lisp
import wnck
import gtk
class AutoSaver(object):
"""This class watches if Emacs looses focus and if Emacs looses
focus saves all buffers with files
"""
def __init__(self):
"""
"""
self.screen = wnck.screen_get_default()
self.screen.force_update()
self.screen.connect("active_window_changed", self.watch_for_emacs)
def watch_for_emacs(self, screen, data=None):
screen.force_update()
win_list = screen.get_windows()
for win in win_list:
if win.get_application().get_name().startswith("emacs"):
self.save_all_buffers()
def save_all_buffers(self):
lisp.save_some_buffers(True, None)
def main(self):
"""
Starts GTK's main loop.
"""
gtk.main()
def start():
autosaver = AutoSaver()
autosaver.main()
start.interaction = ''
Unfortunately the Python programm freezes Emacs; probably because Emacs waits for the program to finish. Is there a way to let run the program in the background?
Any help really appreciated.