Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Import parent module instead of submodule #17

Open
Yevgnen opened this issue Apr 2, 2019 · 2 comments
Open

Feature request: Import parent module instead of submodule #17

Yevgnen opened this issue Apr 2, 2019 · 2 comments

Comments

@Yevgnen
Copy link

Yevgnen commented Apr 2, 2019

Hi, thanks for the awesome package.

Currently for os.path.join* (where * is the cursor), importmagic-fix-symbol-at-point will ask imports for os.path which give candidates like

Screen Shot 2019-04-02 at 22 36 48

It would be nice to have an option to ask imports for os even the cursor is right after os.path.join like

Screen Shot 2019-04-02 at 22 32 48

for one who prefers usages like os.path.join() and datetime.datetime.now() instead of join() and now().

Also, if the cursor is right after os.path*, importmagic-fix-symbol-at-point, candidates is now given as

Screen Shot 2019-04-02 at 22 31 25

which (importing path while using as os.path) is probably not what the user want in this situation.

How do you think about it? I found this because I saw the gif of the importmagic repo and noticed that it imports os in this situation.

@anachronic
Copy link
Owner

On a quick read it sounds very reasonable. However, at this point I'm not sure that's something importmagic.el can control. I think it's up to the parent python project to decide what they decide to query, but I could very well be wrong here.

Let me take a look at this over the weekend and I'll see what I can do.

@Yevgnen
Copy link
Author

Yevgnen commented Apr 4, 2019

Thanks for the reply. I think it all depends on what importmagic.el asks importmagic for. For example, a possible naive implementation would likely be

(defun importmagic-fix-symbol-at-point ()
  "Fix imports for symbol at point."
  (interactive)
  (let ((start (save-excursion
                 (re-search-backward "[^.a-zA-Z0-9]" (line-beginning-position) t))))
    (if start
        (importmagic-fix-symbol (car (split-string (buffer-substring-no-properties (1+ start) (point)) "\\.")))
      (importmagic-fix-symbol (thing-at-point 'symbol t)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants