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

initial support for tree-sitter by honoring python-base-mode #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions importmagic.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ seen on https://github.com/alecthomas/importmagic."
"Get the program to run for the EPC server."
(car (split-string importmagic-python-interpreter)))

(defun importmagic--is-a-python-mode ()
"Is the buffer's major mode a python-compatible mode?"
(derived-mode-p 'python-mode 'python-base-mode))

;;;###autoload
(define-minor-mode importmagic-mode
"A mode that lets you autoimport unresolved Python symbols."
Expand All @@ -123,7 +127,7 @@ seen on https://github.com/alecthomas/importmagic."
:keymap (let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "C-c C-l") 'importmagic-fix-imports)
keymap)
(when (not (derived-mode-p 'python-mode))
(when (not (importmagic--is-a-python-mode))
(error "Importmagic only works with Python buffers"))
(if importmagic-mode
(progn
Expand All @@ -143,7 +147,7 @@ seen on https://github.com/alecthomas/importmagic."

(defun importmagic--teardown-epc ()
"Stop the EPC server for the current buffer."
(when (and (derived-mode-p 'python-mode)
(when (and (importmagic--is-a-python-mode)
importmagic-server
(symbolp 'importmagic-mode)
(symbol-value 'importmagic-mode)
Expand Down Expand Up @@ -241,7 +245,7 @@ seen on https://github.com/alecthomas/importmagic."

(defun importmagic--auto-update-index ()
"Update importmagic symbol index with current directory."
(when (and (derived-mode-p 'python-mode)
(when (and (importmagic--is-a-python-mode)
(f-this-file))
(importmagic--async-add-dir (importmagic--get-top-level))))

Expand Down