From 71ac62ca184f919390bb545a632807201f78a0ee Mon Sep 17 00:00:00 2001 From: bmag Date: Fri, 9 Sep 2016 21:06:23 +0300 Subject: [PATCH] python: really start REPL also in emacs 25.1 Make `python-start-or-switch-repl` start a REPL when necessery also in Emacs 25.1. Previously in Emacs 25.1 it wouldn't do anything if the REPL wasn't started already. --- layers/+lang/python/packages.el | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/layers/+lang/python/packages.el b/layers/+lang/python/packages.el index 50fb5492c3d0..f134cb0c485c 100644 --- a/layers/+lang/python/packages.el +++ b/layers/+lang/python/packages.el @@ -311,8 +311,22 @@ (defun python-start-or-switch-repl () "Start and/or switch to the REPL." (interactive) - (python-shell-switch-to-shell) - (evil-insert-state)) + (let ((shell-process + (or (python-shell-get-process) + ;; `run-python' has different return values and different + ;; errors in different emacs versions. In 24.4, it throws an + ;; error when the process didn't start, but in 25.1 it + ;; doesn't throw an error, so we demote errors here and + ;; check the process later + (with-demoted-errors "Error: %S" + ;; in Emacs 24.5 and 24.4, `run-python' doesn't return the + ;; shell process + (call-interactively #'run-python) + (python-shell-get-process))))) + (unless shell-process + (error "Failed to start python shell properly")) + (pop-to-buffer (process-buffer shell-process)) + (evil-insert-state))) (defun spacemacs/python-execute-file (arg) "Execute a python script in a shell."