reddel的python epc服务器。
reddel-server的Python项目详细描述
目录
Python EPC server component用于 reddel。 它提供了一种从emacs向服务器发送(python)源代码的简单方法, 通过Redbaron检查或转换它,并将结果发送回。
关于如何公开一个简单函数以添加参数的示例:
# file: myprovidermod.py import reddel_server class MyProvider(reddel_server.ProviderBase) @reddel_server.red_src() @reddel_server.red_validate([reddel_server.OptionalRegionValidator(), reddel_server.SingleNodeValidator(), reddel_server.TypeValidator(["def"])]) def add_arg(self, red, start, end, index, arg): red.arguments.insert(index, arg) return red
从emacs启动reddel服务器:
>>> (require 'epc) >>> (defvar my-epc (epc:start-epc "reddel" nil)) >>> ;; make sure myprovidermod is in a directory within the PYTHONPATH >>> (epc:call-sync my-epc 'add_provider '("myprovidermod.MyProvider")) >>> (message (epc:call-sync my-epc 'add_arg '("def foo(arg1, arg3): pass" nil nil 1 "arg2"))) "def foo(arg1, arg2, arg3): pass"
redbaron提供了一种无损格式,因此即使是格式和注释也会保留下来。
Usage
您可以从上面所示的emacs中启动reddel服务器,也可以从命令行启动它。 这个项目提供了一个可执行文件reddel,它应该适合大多数用例。
$ reddel --help Usage: reddel [OPTIONS] Options: --address TEXT address to bind the server to --port INTEGER address to bind the server to -p, --provider TEXT dotted path to a provider class -v, --verbosity LVL Either CRITICAL, ERROR, WARNING, INFO or DEBUG --debug Show tracebacks when erroring. --help Show this message and exit.
^{tt2}$ | Default is ^{tt3}$. Can be an IP or domain name. |
^{tt4}$ | Defaults to a random free port. |
^{tt5}$ | Example: ^{tt6}$ You can provide this multiple times. Defines additional providers that are available from the start. More providers can be added at runtime via ^{tt7}$. |
^{tt8}$ | Define the logging level. |
^{tt9}$ | By default all expected exceptions are only logged without the traceback. If this flag is set, the traceback is printed as well. |
^{tt10}$ | Show the help message and exit. |
由于epc:
>>> (progn ... (require 'epc) ... (defvar my-epc (epc:start-epc "reddel" nil)) ... ;; list all methods compatible with the given source ... (message (epc:call-sync my-epc 'list_methods '("def foo(arg1, arg3): pass"))))
(epc:start-epc "reddel" nil)通过执行不带任何参数的reddel来启动服务器(nil)。 然后,您可以通过引用从epc:start-epc返回的管理器来调用该服务器。 要执行调用,可以使用(epc:call-sync <manager> <method> <arguments>), 其中<manager>是由epc:start-epc返回的管理器,<method>是函数 而<arguments>是传递给<method>的参数列表。
文档中的“内置函数”部分提供了本包附带的所有函数的指南。 如果需要高级功能,请查看参考文档以获取有关如何编写自己的服务器的帮助。
Bugs/Requests
请使用GitHub issue tracker提交错误或请求功能。