813gan ef292203aa Add traceback to exception message and more data to failed export message | il y a 2 mois | |
---|---|---|
.github | il y a 2 mois | |
tests | il y a 2 mois | |
.clang-format | il y a 3 mois | |
.dir-locals.el | il y a 3 mois | |
.git-blame-ignore-revs | il y a 3 mois | |
.gitignore | il y a 2 mois | |
Cask | il y a 2 mois | |
LICENSE.txt | il y a 3 ans | |
Makefile | il y a 2 mois | |
README.md | il y a 1 an | |
console.py | il y a 5 ans | |
emacs-module.h | il y a 5 ans | |
emacspy.el | il y a 2 mois | |
emacspy.pyx | il y a 2 mois | |
emacspy_threads.py | il y a 3 ans | |
requirements.txt | il y a 2 mois | |
stub.c | il y a 2 mois | |
subinterpreter.c | il y a 2 mois | |
thread_local.c | il y a 5 ans |
emacspy enables you to program Emacs in Python instead of ELisp. It works by using dynamic modules support introduced in Emacs 25.
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")
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()