与gnu emacs的python接口。
python-emacs的Python项目详细描述
python emacs
与gnu emacs的python接口。
安装
使用pip安装:
pip install python-emacs
或者直接从存储库:
git clone https://github.com/jlumpe/python-emacs
cd python-emacs
python setup.py install
用法
使用Emacs.batch()
或Emacs.client()
创建到emacs的接口。第一个使用每个命令以批处理模式运行一个新的emacs进程,第二个使用emacsclient
与已经运行的进程通信。
>>> from emacs import Emacs >>> emacs = Emacs.batch(['-q'])
执行一些elisp代码并获得输出:
>>> src = '(princ (format "One plus two is %d" (+ 1 2)))' >>> emacs.eval(src) 'One plus two is 3'
将表达式的结果作为python值:
>>> emacs.getresult('(format "One plus two is %d" (+ 1 2))') 'One plus two is 3' >>> emacs.getresult('(cl-loop for i in \'(1 2 3 4 5) collect (* i i))') [1, 4, 9, 16, 25]
用python编写elisp程序
>>> import emacs.elisp as el >>> src = el.to_elisp((el.Symbol('format'), 'One plus two is %d', (el.Symbol('+'), 1, 2))) >>> src <el (format "One plus two is %d" (+ 1 2))> >>> emacs.getresult(src) 'One plus two is 3'
使用糟糕的DSL:
>>> from emacs.elisp import E >>> prog = E.dolist((E.i, E.number_sequence(1, 20)), E.princ(E.i), E.when(E['='](E['%'](E.i, 3), 0), E.princ("fizz")), E.when(E['='](E['%'](E.i, 5), 0), E.princ("buzz")), E.princ('\n'), ) >>> prog <el (dolist (i (number-sequence 1 20)) (princ i) (when (= (% i 3) 0) (princ "fizz")) (when (= (% i 5) 0) (princ "buzz")) (princ "\n"))> >>> print(emacs.eval(prog)) 1 2 3fizz 4 5buzz 6fizz 7 8 9fizz 10buzz 11 12fizz 13 14 15fizzbuzz 16 17 18fizz 19 20buzz