简体   繁体   English

使用 emacs-jedi 自动导入模块

[英]Auto import modules with emacs-jedi

With ropemacs you can do something like this:使用ropemacs,您可以执行以下操作:

M-x rope-auto-import

This analyze the code (I presume) and imports missing modules, for example if I write:这会分析代码(我假设)并导入缺少的模块,例如,如果我写:

datetime.now()

it should do the import for me by add this line:它应该通过添加以下行来为我导入:

from datetime import datetime

(it always uses the from... import... form) (它总是使用from... import...形式)

Is there a similar function in emacs-jedi? emacs-jedi中是否有类似的function?

Jedi doesn't support auto imports, yet. Jedi还不支持汽车进口。 (And therefore obviously emacs-jedi does neither) (因此显然emacs-jedi都没有)

There are discussions ongoing to implement refactorings as well (which includes auto imports). 目前正在讨论实施重构(包括汽车进口)。 However, it will probably take another year or so. 但是,它可能需要一年左右的时间。

If we ignore the jedi part and pay attention to the emacs part you could use the follow command after installing autoimport .如果我们忽略绝地部分并注意 emacs 部分,您可以在安装autoimport后使用以下命令。

(defun my-python-autoimports ()
  (interactive)
  (save-buffer)
  (shell-command (s-concat "autoimport " (shell-quote-argument (buffer-file-name))))
  (revert-buffer t t))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM