Cómo cargar un programa GTK en Pymacs

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?

Cualquier ayuda muy apreciada.

preguntado el 29 de julio de 12 a las 12:07

2 Respuestas

Pymacs mainly just means that you can programm emacs extension in python. It is not an IPC method.

If you want to have two programs running at the same time and sending each other messages when external events occur, you need IPC.

A very common form of IPC on modern Linux systems is (the horribly undocumented) dbus. Emacs has support for dbus (which seems also not well documented).

Sin embargo, here (the answer by rakete) is a very nice example on how to provide a dbus interface to an emacs function.

So, what you probably want to do is create a "safe-buffer" method in emacs, register it to be accessible from dbus, start your program to watch for unfocus events and call that "safe-buffer" method via dbus.

contestado el 23 de mayo de 17 a las 13:05

Thanks a lot, I will try your recommendations. - Rockiger

hice Python-EPC, an EPC server implementation in Python. EPC is an RPC stack, which is designed for Emacs Lisp. Using Python-EPC, you can call Python functions from Emacs and Emacs Lisp functions from Python. Here is an example for integration with GTK: https://github.com/tkf/python-epc/blob/master/examples/gtk/server.py

respondido 11 nov., 12:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.