lang/python: make repl/eval handlers respect pipenv
This commit is contained in:
parent
fcd1e913c5
commit
68699c3d5b
2 changed files with 16 additions and 1 deletions
|
@ -7,7 +7,13 @@
|
||||||
(defun +python/repl ()
|
(defun +python/repl ()
|
||||||
"Open the Python REPL."
|
"Open the Python REPL."
|
||||||
(interactive)
|
(interactive)
|
||||||
(process-buffer (run-python nil t t)))
|
(process-buffer
|
||||||
|
(if-let* ((bin (executable-find "pipenv"))
|
||||||
|
(dir (pipenv-project-p)))
|
||||||
|
(let* ((default-directory dir)
|
||||||
|
(python-shell-interpreter (format "%s run %s" bin python-shell-interpreter)))
|
||||||
|
(run-python nil t t))
|
||||||
|
(run-python nil t t))))
|
||||||
|
|
||||||
(defun +python--extract-version (prefix str)
|
(defun +python--extract-version (prefix str)
|
||||||
(when str
|
(when str
|
||||||
|
|
|
@ -131,6 +131,15 @@
|
||||||
:hook (python-mode . pipenv-mode)
|
:hook (python-mode . pipenv-mode)
|
||||||
:init (setq pipenv-with-projectile nil)
|
:init (setq pipenv-with-projectile nil)
|
||||||
:config
|
:config
|
||||||
|
(set-eval-handler! 'python-mode
|
||||||
|
'((:command . "python")
|
||||||
|
(:exec (lambda ()
|
||||||
|
(if-let* ((bin (executable-find "pipenv"))
|
||||||
|
(dir (pipenv-project-p)))
|
||||||
|
(format "cd %S && %s run %%c %%o %%s %%a" dir bin)
|
||||||
|
"%c %o %s %a")))
|
||||||
|
(:description . "Run Python script")))
|
||||||
|
|
||||||
(advice-add #'pipenv-activate :after-while #'+python|update-version-in-all-buffers)
|
(advice-add #'pipenv-activate :after-while #'+python|update-version-in-all-buffers)
|
||||||
(advice-add #'pipenv-deactivate :after-while #'+python|update-version-in-all-buffers))
|
(advice-add #'pipenv-deactivate :after-while #'+python|update-version-in-all-buffers))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue