Nav apraksta

813gan ef292203aa Add traceback to exception message and more data to failed export message 1 mēnesi atpakaļ
.github 3958bf7a69 Add Cask 2 mēneši atpakaļ
tests 56294dd067 Rename call_function to call_py and allow it to call methods 1 mēnesi atpakaļ
.clang-format 5d7dea9308 Add clang-format configuration 2 mēneši atpakaļ
.dir-locals.el 5d7dea9308 Add clang-format configuration 2 mēneši atpakaļ
.git-blame-ignore-revs 5d7dea9308 Add clang-format configuration 2 mēneši atpakaļ
.gitignore 3958bf7a69 Add Cask 2 mēneši atpakaļ
Cask 3958bf7a69 Add Cask 2 mēneši atpakaļ
LICENSE.txt f5a48f6cf2 add LICENSE 2 gadi atpakaļ
Makefile b6f5c8ef23 Fix usage of macros 1 mēnesi atpakaļ
README.md 2cdb3bf7e2 Update README.md 1 gadu atpakaļ
console.py 8a9ae9c94d initial commit 5 gadi atpakaļ
emacs-module.h 33dc4c3686 import emacs-module header file 5 gadi atpakaļ
emacspy.el 56294dd067 Rename call_function to call_py and allow it to call methods 1 mēnesi atpakaļ
emacspy.pyx ef292203aa Add traceback to exception message and more data to failed export message 1 mēnesi atpakaļ
emacspy_threads.py fb49da1020 emacspy_threads: raise instead of deadlocking if ran from main thread 2 gadi atpakaļ
requirements.txt 8bddfe7c78 add PyErr_GetRaisedException compatibility macro 2 mēneši atpakaļ
stub.c b6f5c8ef23 Fix usage of macros 1 mēnesi atpakaļ
subinterpreter.c 0bf86b1192 Replace PyErr_GetRaisedException compatibility macro with function 1 mēnesi atpakaļ
thread_local.c 34dfd5ed85 threading improvements 4 gadi atpakaļ

README.md

emacspy

emacspy enables you to program Emacs in Python instead of ELisp. It works by using dynamic modules support introduced in Emacs 25.

Building and loading

Install Cython (pip install cython) and run make. emacspy.so will appear in the current directory. Make sure your Emacs build has loadable modules support enabled (default builds on some distributions don't!):

emacs --help | grep -q module-assertions && echo OK || echo "No loadable modules support"

You can load the module using normal load directive:

(add-to-list 'load-path "~/emacspy")
(load "~/emacspy/emacspy")

The module will expose two ELisp functions eval-python and exec-python.

(eval-python "4+4")

You can use exec-python to load you Python files:

(exec-python "import sys; sys.path.append('/home/user/my-files')")
(exec-python "import mymodule")

Python

Emacspy also exposes Python API for interacting with Emacs. To use it import emacspy module.

import emacspy

# use emacspy.v to access Emacs variables
emacspy.v.tab_width

# use emacspy.f to call Emacs functions
emacspy.f.message("hello")

# returned values are wrapped in EmacsValue
emacspy.f["+"](1, 2) # => <EmacsValue ...>

# use functions to convert to Python values
emacspy.f["+"](1, 2).int()
emacspy.v.page_delimiter.str()