Auto import modules with emacs-jedi
Asked Answered
E

2

8

With ropemacs you can do something like this:

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)

Is there a similar function in emacs-jedi?

Effluent answered 10/6, 2014 at 16:56 Comment(3)
It might help if you explained what rope-auto-import does.Rhinelandpalatinate
Some info here can be useful, about python-mode or a code snippet that uses py-isort: #3839015 Nothing's perfect though.Squirearchy
How/where can I install rope-auto-import?Zoan
B
3

Jedi doesn't support auto imports, yet. (And therefore obviously emacs-jedi does neither)

There are discussions ongoing to implement refactorings as well (which includes auto imports). However, it will probably take another year or so.

Bottoms answered 10/6, 2014 at 21:54 Comment(1)
It's now 8 years later. Did this discussion go anywhere?Ker
D
1

If we ignore the jedi part and pay attention to the emacs part you could use the follow command after installing autoimport.

(defun my-python-autoimports ()
  (interactive)
  (save-buffer)
  (shell-command (s-concat "autoimport " (shell-quote-argument (buffer-file-name))))
  (revert-buffer t t))
Disenable answered 8/8, 2022 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.