all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to pass messages between emacs and a Python program? (goal: trying to use emacs as a UI)
Date: Sun, 28 Aug 2016 19:10:25 +0200	[thread overview]
Message-ID: <874m64ddku.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: CAMt_P4=LFb6dLS=Yv4o6zX_+VMPJ-MjjVbKq8+t81d2NNOsxNA@mail.gmail.com

Brian Merchant <bhmerchant@gmail.com> 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?

Yes.


> A bit of background on my goal: I'd like to make a proof editor/"IDE", and
> while I have the programming know-how (at least in Python and C++, not in
> emacs Lisp) to code the background analyzers/proof-engines, I am horrible
> at putting pixels on a screen. I have experimented a bit with putting
> pixels on a screen, and writing my own simple editor, but suffice it to say
> that I have come to appreciate the immense amount of effort it takes to
> build something as smooth as emacs. I think it would be much better for me
> to take advantage of emacs' capabilities in terms of showing stuff on a
> screen, and manipulating/editing that stuff. I worry though that there
> might not be any easy way to do this...
>
> Anyway, would love to hear your thoughts and guidance!


1- it would be better to do it in emacs lisp, that's why emacs has emacs
   lisp!

2- there are systems to bridge lisp and python, but AFAIK, they're all
   implemented for Common Lisp.

   See for example:

      * CLAUDE - The Common Lisp Library Audience Expansion Toolkit
        http://www.european-lisp-symposium.org/editions/2014/levine.zip
        http://nicklevine.org/els2014/levine.mp3
        http://medias.ircam.fr/x31d466

      * cl-python https://common-lisp.net/project/clpython/

   So some porting work would be needed to use a similar solution with
   emacs.

   For example, cl-python which is written in Common Lisp, could run on
   emacs with emacs-cl, a CL implementation written in emacs lisp.
   Unfortunately, this emacs-cl has bit-rot since it doesn't take into
   account lexical closure introduced in emacs 24: it would need some
   work to upgrade it to emacs 24+, and some more to complete the
   conformity and coverage of the standard.  Then it would be trivial to
   use all the CL tools in emacs, such as cl-python.

3- there is slime/swank.
   https://github.com/fgallina/swank-python
   (I have no idea how complete and functional this is).
   While not directly meant for this, slime/swank can be used for RPC
   between emacs lisp and the inferior process.
   
   There are also direct emacs-python RPC such as:
   https://github.com/tkf/python-epc

4- the situation would be much easier if emacs was written in Common
   Lisp instead of C.  For this reason I've started to write a C
   compiler in Common Lisp targetting Common Lisp, with the objective to
   compile/translate the C code of emacs lisp into Common Lisp.  Then
   the solutions available in points 2 and 3 would be trivially
   available.  Unfortunately, my tax inspector requires me to work for
   money, so I couldn't complete this compiler yet. (I only have the C
   pre-processor done for now).
   
   Some people also envisionned rewritting this emacs C code manually,
   but this is as big a task, if not bigger, than to write a C compiler,
   so they didn't make any much more progress than me.

5- if python is that good, why isn't there an emacs clone written in
   python using python as scripting language instead of lisp?  It would
   be a trivial solution to your problem.
   
   

So, to make it Q&D, perhaps the easiest for you will be to use
something like https://github.com/tkf/python-epc
to call your python processing code from emacs when convenient.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk




  parent reply	other threads:[~2016-08-28 17:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 22:18 How to pass messages between emacs and a Python program? (goal: trying to use emacs as a UI) Brian Merchant
2016-08-26  8:05 ` Michael Albinus
2016-08-26  8:14 ` Thien-Thi Nguyen
2016-08-26 11:51 ` Alexis Roda
2016-08-28 17:10 ` Pascal J. Bourguignon [this message]
2016-08-28 19:50 ` Tomas Nordin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874m64ddku.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.