Skip to content

About

EPC (RPC stack for Emacs Lisp) for Python

Resources

Stars

97 stars

Watchers

11 watching

Forks

 
 

Latest commit

 

History

257 Commits

Folders and files

Repository files navigation

EPC (RPC stack for Emacs Lisp) server for Python

Links:

Other resources:

What is this?

EPC is an RPC stack for Emacs Lisp and Python-EPC is its server side implementation in Python. Using Python-EPC, you can easily call Emacs Lisp function from Python and Python function from Emacs. For example, you can use Python GUI module to build widgets for Emacs (see examples/gtk/server.py for example).

Install

To install Python-EPC and its dependency sexpdata, run the following command.:

pip install epc

Usage

Save the following code as my-server.py. (You can find the same code at the bottom of epc/server.py):

from epc.server import EPCServer

def echo_server(address='localhost', port=0):
    server = EPCServer((address, port))
    def echo(*a):
        return a
    server.register_function(echo)
    return server

if __name__ == '__main__':
    server = echo_server()
    server.print_port()
    server.serve_forever()

And then run the following code from Emacs. This is a stripped version of examples/echo/client.el included in Python-EPC repository.:

(require 'epc)

(defvar my-epc (epc:start-epc "python" '("my-server.py")))

(deferred:$
  (epc:call-deferred my-epc 'echo '(10))
  (deferred:nextc it
    (lambda (x) (message "Return : %S" x))))

(message "Return : %S" (epc:call-sync my-epc 'echo '(10 40)))

If you have carton installed, you can run the above sample by simply typing the following commands:

make elpa        # install EPC in a separated environment
make run-sample  # run examples/echo/client.el

For example of bidirectional communication and integration with GTK, see examples/gtk/server.py. You can run this example by:

make elpa
make run-gtk-sample  # run examples/gtk/client.el

About

EPC (RPC stack for Emacs Lisp) for Python

Resources

Stars

97 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages