[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to pass messages between emacs and a Python program? (goal: tryi
Re: How to pass messages between emacs and a Python program? (goal: trying to use emacs as a UI)
Fri, 26 Aug 2016 10:05:15 +0200
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)
Brian Merchant <address@hidden> writes:
> Hi all,
> Say I have opened up a file in emacs, and I type in something like:
> `x \and \top`
> Then, a Python program reads that file, and:
> * replaces all `\and` to `∧`
> * replaces all `\top` to `T`
> * it does some thinking on the expression `x \and \top` and decides that
> that is the same as `x`, so will append an `= x`
> The final result of all the changes made by the program to the file will
> leave it like so:
> `x ∧ T = x`
> Okay, so much for what I want. For getting there though:
> I don't want the Python program to be constantly polling the file for
> changes (using a `while` loop), and I probably don't want emacs to be
> constantly polling the file for updates (which I know how to do using the
> `auto-revert` command).
> Maybe I press some key combination, and then that sends a message to a
> Python script that its time to read the file and make updates and then the
> Python script would message emacs and ask it to update what it is
> displaying in its buffer.
> Could this be done?
I have no idea about python and its features in this respect. From the
Emacs point of view, I see two possibilities:
- Use file notifications. Emacs supports file notifications for several
operating systems, like GNU/Linux, *BSD, OS X, Cygnus, MS
Windows. That is, if a file is changed in the file system, an event is
raised by the kernel, and Emacs is able to catch this event and to
run a handler (a Lisp function) bound to this event. If python could
do similar, you have it.
- Use D-Bus messages. This is a communication channel for applications
of different type to talk to each other. Emacs has D-Bus support, and
python has it also (a short web search gave me
is restricted to operating systems with D-Bus support, mainly
GNU/Linux and Cygwin. Both Emacs and your python program could send a
D-Bus message to the partner, indicating that a file has changed.
> Kind regards,
Best regards, Michael.