]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new command python-shell-restart
authorAugusto Stoffel <arstoffel@gmail.com>
Sun, 18 Sep 2022 10:53:04 +0000 (12:53 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 18 Sep 2022 10:53:04 +0000 (12:53 +0200)
* lisp/progmodes/python.el (python-shell-restart): New command (bug#57885).

lisp/progmodes/python.el

index 9f9439aac6995080f07d0a0e266608dfb94b2304..6ef468d2cbee71e4faa492ec68d44e3c4c01afb0 100644 (file)
@@ -3217,6 +3217,26 @@ process buffer for a list of commands.)"
                   show)))
     (get-buffer-process buffer)))
 
+(defun python-shell-restart (&optional show)
+  "Restart the Python shell.
+Optional argument SHOW (interactively, the prefix argument), if
+non-nil, means also display the Python shell buffer."
+  (interactive "P")
+  (with-current-buffer
+      (or (and (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