>From 3ccd5651604bd0e90b6504148e8c770355b2e3e4 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sat, 17 Sep 2022 19:01:57 +0200 Subject: [PATCH] * lisp/progmodes/python.el (python-shell-restart): New command. --- lisp/progmodes/python.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9f9439aac6..4965d436a0 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3217,6 +3217,25 @@ run-python show))) (get-buffer-process buffer))) +(defun python-shell-restart (&optional show) + "Restart the Python shell. +With a prefix argument, also SHOW the buffer." + (interactive "P") + (with-current-buffer + (or (when (derived-mode-p 'inferior-python-mode) + (current-buffer)) + (seq-some (lambda (dedicated) + (get-buffer (format "*%s*" (python-shell-get-process-name + dedicated)))) + '(buffer project nil)) + (user-error "No Python shell")) + (when-let ((proc (get-buffer-process (current-buffer)))) + (kill-process proc) + (while (accept-process-output proc))) + (python-shell-make-comint (python-shell-calculate-command) + (string-trim (buffer-name) "\\*" "\\*") + show))) + (defun run-python-internal () "Run an inferior Internal Python process. Input and output via buffer named after -- 2.37.3