On Sat, 17 Sep 2022 at 13:32, Stefan Kangas wrote: > Augusto Stoffel writes: > >> I think "C-c C-n" would be a reasonable keybinding, but since I can't >> find any precedent, I didn't include a keybinding. > > `C-c C-n' is usually used to go to the next thing, so maybe we could try > to find some better key. Okay, then let's decide later (or not decide :-)). > Looks good to me (but I didn't test it), with two minor comments: > >> +(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)) > > As a minor style point, I'd prefer: > > (and (derived-mode-p 'inferior-python-mode) > (current-buffer)) > > to make it clear that we want the value. Okay >> + (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))) > > Should there be an error here if there is no running process? > No, and if fact, if the process is dead, you want to call this command to start the shell again (it happens to me and it works).