使用 python 扩展 emacs

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

写一个 python 模块

目录结构以下:函数

├── 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中调用python 模块

建立一个lisp文件:

(pymacs-load "sample")
(message (sample-hello-word buffer-file-name))

将光标移动到每一行上并使用 C-M-x 来执行该行 lisp 代码, 执行后会在emacs上看到输出。

相关文章
相关标签/搜索