Skip to content

Instantly share code, notes, and snippets.

@bennofs
Created November 2, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennofs/1eaf99a9338b84ad2066c2c0a197db0d to your computer and use it in GitHub Desktop.
Save bennofs/1eaf99a9338b84ad2066c2c0a197db0d to your computer and use it in GitHub Desktop.
; enable python version switching
(defvar +python-interpreter-executable-history nil
"History list for recently selected python interpreters.")
(defun +set-python-interpreter-executable (command)
"Set the python interpreter for the current buffer to the given executable."
(interactive
(list
(read-shell-command
"Python interpreter: " nil '+python-interpreter-executable-history "python"
)))
(setq-local python-shell-interpreter command)
(setq-local flycheck-python-pycompile-executable command)
(setq-local lsp-python-ms-python-executable-cmd command)
(when (= (length lsp--buffer-workspaces) 1)
(lsp-workspace-restart (nth 0 lsp--buffer-workspaces)))
(flycheck-buffer)
(let
((process (python-shell-get-process)))
(when (and process (y-or-n-p "Python interpreter already running. Kill currently running process?"))
(kill-process process))))
(after! python
(map! :map python-mode-map
:localleader
"p" #'+set-python-interpreter-executable))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment