From 68699c3d5b36c7243b74f1661887b2210b9011b6 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 26 Sep 2018 12:28:32 -0400 Subject: [PATCH] lang/python: make repl/eval handlers respect pipenv --- modules/lang/python/autoload/python.el | 8 +++++++- modules/lang/python/config.el | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/lang/python/autoload/python.el b/modules/lang/python/autoload/python.el index 088342178..b31099b98 100644 --- a/modules/lang/python/autoload/python.el +++ b/modules/lang/python/autoload/python.el @@ -7,7 +7,13 @@ (defun +python/repl () "Open the Python REPL." (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) (when str diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index 1dc367b46..35303dce6 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -131,6 +131,15 @@ :hook (python-mode . pipenv-mode) :init (setq pipenv-with-projectile nil) :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-deactivate :after-while #'+python|update-version-in-all-buffers))