Emacs - 局部 Python 变量的制表符补全
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/750267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Emacs - tab-completion of local Python variables
提问by zak23
Is there a good emacs mode that will allow tab-completion of local python variables? I set up ipython.el but it will only tab-complete things in the scope of the interpreter. I'm looking for something that will let me tab-complete tokens in the local namespace of a function or file.
是否有一个好的 emacs 模式可以让本地 python 变量的制表符完成?我设置了 ipython.el 但它只会在解释器的范围内完成选项卡。我正在寻找可以让我在函数或文件的本地命名空间中使用制表符完成标记的东西。
回答by Amol Gawai
M-/ runs the command dabbrev-expand . This will complete local names in any mode. Also I bind meta f1 to hippie expand from all open buffers. This is very useful for me.
M-/ 运行命令 dabbrev-expand 。这将在任何模式下完成本地名称。此外,我将 meta f1 绑定到所有打开的缓冲区中的嬉皮扩展。这对我来说非常有用。
;; Bind hippie-expand
(global-set-key [(meta f1)] (make-hippie-expand-function
'(try-expand-dabbrev-visible
try-expand-dabbrev
try-expand-dabbrev-all-buffers) t))
Hope this is useful.
希望这是有用的。
回答by dermatthias
I use emacs-autocomplete.el (version 0.2.0) together with yasnippet. Works ok for me, although it isn't a complete auto-completion environment like eclipse+java is. But enough for a common emacs hacker like me :)
我将 emacs-autocomplete.el(版本 0.2.0)与 yasnippet 一起使用。对我来说没问题,虽然它不像 eclipse+java 那样是一个完整的自动完成环境。但对于像我这样的普通 emacs 黑客来说已经足够了:)
1) Download autocomplete from here(first link) and put it in your load-path directory. Also download the extensions you want to use (Attention: Ruby and etags extensions need additional stuff). Put them also in yout load-path dir.
1)从这里下载自动完成(第一个链接)并将其放在您的加载路径目录中。同时下载你想使用的扩展(注意:Ruby 和 etags 扩展需要额外的东西)。将它们也放在你的加载路径目录中。
2) Download yasnippetand install it like the instruction on that page says (including the (require ...) part).
2)下载yasnippet并按照该页面上的说明进行安装(包括(需要...)部分)。
3) Put these lines in your .emacs file and edit them for your needs (like all the extensions you want to use):
3) 将这些行放在您的 .emacs 文件中并根据您的需要进行编辑(如您要使用的所有扩展名):
(require 'auto-complete)
(global-auto-complete-mode t)
(when (require 'auto-complete nil t)
(require 'auto-complete-yasnippet)
(require 'auto-complete-python)
(require 'auto-complete-css)
(require 'auto-complete-cpp)
(require 'auto-complete-emacs-lisp)
(require 'auto-complete-semantic)
(require 'auto-complete-gtags)
(global-auto-complete-mode t)
(setq ac-auto-start 3)
(setq ac-dwim t)
(set-default 'ac-sources '(ac-source-yasnippet ac-source-abbrev ac-source-words-in-buffer ac-source-files-in-current-dir ac-source-symbols))
For more informations on options see the auto-complete.el file.
有关选项的更多信息,请参阅 auto-complete.el 文件。
4) Restart emacs or do a M-x load-file with your .emacs file. Write some code and press TAB for auto completion.
4) 重新启动 emacs 或使用 .emacs 文件执行 Mx 加载文件。编写一些代码并按 TAB 键自动完成。
回答by boskom
The blog post describing kind of tab completion you want can be found at Python code completion in Emacs. There is a bit of installing packages, pymacs, AutoComplete, rope, ropemacs, rope mode, yasnippet and setting up, but in the end I hope it will pay off.
可以在 Emacs 中的 Python 代码完成中找到描述您想要的选项卡完成类型的博客文章 。有一些安装包、pymacs、AutoComplete、rope、ropemacs、rope mode、yasnippet 和设置,但最终我希望它会有所回报。
回答by Dave Halter
Use Jedi!
使用绝地!
It really understands Python better than any other autocompletion library:
它比任何其他自动完成库都更了解 Python:
- builtins
- multiple returns or yields
- tuple assignments / array indexing / dictionary indexing
- with-statement / exception handling
- *args / **kwargs
- decorators / lambdas / closures
- generators / iterators
- some descriptors: property / staticmethod / classmethod
- some magic methods:
__call__
,__iter__
,__next__
,__get__
,__getitem__
,__init__
- list.append(), set.add(), list.extend(), etc.
- (nested) list comprehensions / ternary expressions
- relative imports
- getattr() /
__getattr__
/__getattribute__
- simple/usual sys.path modifications
- isinstance checks for if/while/assert
- 内置函数
- 多重回报或收益
- 元组分配/数组索引/字典索引
- with 语句/异常处理
- *args / **kwargs
- 装饰器 / lambdas / 闭包
- 生成器/迭代器
- 一些描述符:属性/静态方法/类方法
- 一些神奇的方法:
__call__
,__iter__
,__next__
,__get__
,__getitem__
,__init__
- list.append()、set.add()、list.extend() 等。
- (嵌套)列表推导式/三元表达式
- 相对进口
- getattr()
__getattr__
//__getattribute__
- 简单/通常的 sys.path 修改
- isinstance 检查 if/while/assert
回答by Shane C. Mason
I think that you may be looking for something like this. It uses Pymacsand python-modeto do just what you are looking for.
我想你可能正在寻找这样的东西。它使用Pymacs和python-mode来做你正在寻找的事情。
Let us know how it works out for you?
让我们知道它对您的效果如何?
回答by Lester Cheung
If you just want to get it up and running with minimal fuss, try the emacs-for-pythonpackage.
如果您只想轻松地启动并运行它,请尝试使用emacs-for-python包。
Happy coding!
快乐编码!