你好,我正在尝试写一个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等待程序完成。有没有办法让程序在后台运行?
真的很感谢任何人的帮助。
发布于 2012-08-06 16:50:29
Pymacs主要是指你可以在python中编写emacs扩展。它不是IPC方法。
如果您想让两个程序同时运行,并在外部事件发生时互相发送消息,则需要IPC。
在现代Linux系统上,IPC的一种非常常见的形式是(非常没有文档记录的) dbus。Emacs支持dbus (这似乎也没有很好的文档记录)。
因此,您可能需要在emacs中创建"safe-buffer“方法,将其注册为可从dbus访问,启动程序以监视非焦点事件,并通过dbus调用"safe-buffer”方法。
发布于 2012-11-12 03:52:51
我编写了Python-EPC,这是一个用Python语言实现的EPC服务器。EPC是为Emacs Lisp设计的RPC堆栈。使用Python-EPC,您可以从Emacs调用Python函数,从Python调用Emacs Lisp函数。下面是一个与GTK集成的示例:https://github.com/tkf/python-epc/blob/master/examples/gtk/server.py
https://stackoverflow.com/questions/11708696
复制相似问题