您好我正在尝试编写一个 Python 程序来保存 Emacs 的文件,以防止失去窗口焦点。
为此,我编写了一个 Python 程序,它创建了一个完整的 gtk 应用程序并使用了 wnck 模块:
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 = ''
不幸的是,Python 程序冻结了 Emacs;可能是因为 Emacs 等待程序完成。有没有办法让程序在后台运行?
任何帮助都非常感谢。