Emacs Python 模式中类似 bpython 的自动完成和参数描述?
我已经使用 bpython 一段时间来满足我所有的 Python 解释需求。这是令人愉快的,特别是当您使用不熟悉的新库或具有多种功能的库时。无论如何,有一个 bpython 解释器与我正在做的事情一起运行是很好的,但如果我同时具有类似自动完成的功能,以及以 bpython 的方式进行参数描述,那就更好了 while 我正在 Emacs 中编辑代码。我完全疯了吗?有谁知道如何做到这一点?
谢谢, 布拉德利·鲍尔斯
I've been using bpython for a while now for all of my Python interpreting needs. It's delightful, particularly when you're using unfamiliar new libraries, or libraries with a multitude of functions. In any case, it's nice to have a bpython interpreter running alongside what I'm doing, but it'd be even better if I had both the autocomplete-like feature, and the parameter description in the manner that bpython does while I'm editing code in Emacs. Am I completely crazy? Does anyone have an idea on how to do this?
Thanks,
Bradley Powers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你还没有完全疯了。
python-mode
可以与eldoc-mode
集成以显示您正在调用的函数的参数规范。只需在 Python 文件中执行Mx eldoc-mode
即可将其打开,它就会开始工作。它与较差的 python 缓冲区对话以直接检查函数,因此它应该始终相当准确。您可以使用(add-hook 'python-mode-hook '(lambda () (eldoc-mode 1)) t)
(add-hook 'python-mode-hook '(lambda () (eldoc-mode 1)) t) 自动为所有新的python-mode
缓冲区打开它code> 在你的 emacs 启动文件中。现在,在这一点上我不得不说我不做任何常规的Python编程,当我刚才尝试它时它不起作用。我花了几分钟浏览源代码,一切似乎都已就位,但它在下级进程中运行的代码只是返回一个空字符串。也许这只是我的设置,或者也许我正在阅读错误的源文件;很难说。Emacs 提供了几种不同类型的扩展/自动完成。默认情况下,您可以通过点击
M-/
访问dabbrev-expand
。这是一种相当简单的完成形式;它只是适用于您编辑的任何旧文件。更复杂的是hippie-expand
,但即便如此,它也没有做任何 Python 特有的事情。文档说它可以与 hippie-expand 集成以实现精确的完成,但这可能是一个谎言;我不明白它是如何工作的。稍微浏览一下就会发现几个相关的解决方案,所有这些解决方案似乎都依赖于pymacs
。如果我要做大量的 python 编程并且还没有设置相当复杂的 emacs,我可能会从安装 emacs-for-python。它看起来是一个相当完整的设置,甚至声称具有实时警告/错误检测功能。本着帮助别人自助的精神,我想指出我是如何得到所有这些信息的。我的第一步是在 python 模式下打开一个文件。我实际上没有任何可用的 python 代码,所以我只是转到临时缓冲区并将其设为 python 缓冲区 (
Mx python-mode
)。然后我就这个奇怪的新模式 (Ch m
) 寻求帮助,看看它能做什么。它的作者友好地简要总结了该模式的功能,其中提到了 eldoc-mode、Imenu、outline-mode、hippie-expand 、rlcompleter、缩写表和一堆其他东西。从那里我开始查看源代码。例如,为了与 eldoc-mode 集成,它定义了一个名为 python-eldoc-function 的函数,并将其提供给 eldoc 模块以在 python 缓冲区中使用。阅读该代码向我展示了它如何与下级缓冲区交互等。我希望其中一些有所帮助。
You're not completely crazy.
python-mode
can integrate witheldoc-mode
to display the arg spec of the function you're calling at point. Just doM-x eldoc-mode
while you're in a python file to turn it on and it should start working. It talks to an inferior python buffer to inspect the functions directly, so it should always be decently accurate. You can turn it on automatically for all newpython-mode
buffers with(add-hook 'python-mode-hook '(lambda () (eldoc-mode 1)) t)
in your emacs startup file. Now, at this point I have to say that I don't do any regular python programming, and that when I tried it just now it didn't work. I spent a few minutes poking around in the source code and everything seems to be in place, but the code that it runs in the inferior process is just returning an empty string. Perhaps it's just my setup, or perhaps I'm reading the wrong source files; it's hard to say.Emacs provides several different types of expansion/autocompletion. By default you have access to
dabbrev-expand
by hittingM-/
. This is a fairly simple form of completion; it's just meant to work on any old file you happen to edit. More sophisticated ishippie-expand
, but even that doesn't do anything python-specific. The documentation says that it can integrate withhippie-expand
for exact completions, but this might be a lie; I couldn't figure out how it works. A little poking around shows several related solutions for this, all of which seem to rely onpymacs
. If I were going to do a lot of python programming and didn't already have a fairly complicated emacs set up, I'd probably start by installing emacs-for-python. It looks to be a pretty complete setup, and even claims to have live warning/error detection.In the spirit of helping others to help themselves, I'd like to point out how I came upon all of this information. My first step was to open a file in
python-mode
. I didn't actually have any python code available, so I just went to my scratch buffer and made it a python buffer (M-x python-mode
). Then I asked for help about this strange new mode (C-h m
) to see what it could do. It's author has kindly put a brief summary of what the mode can do which mentionseldoc-mode
, Imenu,outline-mode
,hippie-expand
, rlcompleter, abbrev tables, and a bunch of other things. From there I started looking at the source code. For instance, to integrate with eldoc-mode, it defines a function calledpython-eldoc-function
and gives that to the eldoc module for use in python buffers. Reading that code shows me how it interacts with the inferior buffer, etc.I hope some of this helps.