Pymacs 能夠使得emacs能和python程序進行交互,能夠讓emacs插件開發者儘可能使用python進行開發。這裏提供一個例子,在lisp中調用python的函數並將當前buffer的文件名傳遞給python,在emacs中輸出python函數的返回值python
首先安裝 python 包 Pymacs. 在 ubuntu 裏面安裝 pymacs 便可。shell
而後安裝emacs插件pymacs, el-get-install 或者 package-install 均可以ubuntu
目錄結構以下:函數
├── samplespa
│ └── __init__.py插件
└── setup.pycode
__init__.py 的內容:開發
from Pymacs import lisp interactions = {} def hello_word(filename): return 'Hello from python, file name is %s' % filename interactions[hello_word] = ''
setup.py 的內容:get
from setuptools import setup, find_packages setup( name = "sample-pymacs", version = "0.1", packages = find_packages() )
安裝這個模塊emacs
python setup.py install
若是一切正常, 在 python 中能夠 import sample
建立一個lisp文件:
(pymacs-load "sample") (message (sample-hello-word buffer-file-name))
將光標移動到每一行上並使用 C-M-x 來執行該行 lisp 代碼, 執行後會在emacs上看到輸出。