From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#57885: [PATCH] Add a command to restart the Python shell Date: Sat, 17 Sep 2022 19:39:10 +0200 Message-ID: <87sfkpaojl.fsf@gmail.com> References: <875yhmapwr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15579"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 57885@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 17 19:40:16 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oZbnc-0003vR-1P for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 19:40:16 +0200 Original-Received: from localhost ([::1]:38852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZbna-0005LC-Hi for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 13:40:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZbnO-0005Jf-RD for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZbnO-0003xu-Go for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZbnO-0007lu-44 for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Sep 2022 17:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57885 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57885-submit@debbugs.gnu.org id=B57885.166343635929813 (code B ref 57885); Sat, 17 Sep 2022 17:40:02 +0000 Original-Received: (at 57885) by debbugs.gnu.org; 17 Sep 2022 17:39:19 +0000 Original-Received: from localhost ([127.0.0.1]:47126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbmh-0007kn-HK for submit@debbugs.gnu.org; Sat, 17 Sep 2022 13:39:19 -0400 Original-Received: from mail-ej1-f42.google.com ([209.85.218.42]:36731) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbmf-0007kb-Og for 57885@debbugs.gnu.org; Sat, 17 Sep 2022 13:39:18 -0400 Original-Received: by mail-ej1-f42.google.com with SMTP id 13so26943701ejn.3 for <57885@debbugs.gnu.org>; Sat, 17 Sep 2022 10:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date; bh=bd+Ihb8QtPxjkREpDFAytnL51bALc7spLGse5ghpFs8=; b=F9v5x5HL8SM+EbQ0mmjRV4a32pR9mORUyByeyVwrxowsqXsrYjrfrEerl9ncn52asn VZI9vQ1TBUn2HSuh1IG4HoD7avxqIvc+i0obVwrmLF0zdS67xPNYC6dTaXon6NkCGbhY 90h9IDjHzS+ar2wo/wpseVlZ9JKBiCi9+vfwpwJZ09G7cqLDHMD4Cdgw2N6Ewdd9RASV bsyqlcZg7xyrDRY3vsNvfuKO3alIOMxKHcZrou45RtzMhuqWXU/IXA3cR+TOyaS8PaFj +1rjze4Mis77bfvaPYDtqOqh5Mw4+n0CQXpu2hfhgOmjLWMIE2xlajbZ6ZqhdYTZYr/v 0Lpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=bd+Ihb8QtPxjkREpDFAytnL51bALc7spLGse5ghpFs8=; b=Yv0j50+mUbdX4eNGXxk6VeKZTTsX5ZrJH5ORpKOZqDt2LyloLpDZ5pFzQon2cc4F+Z eD7EeI6PBBgmLHqpy1rqsAKWW0SBzrLLDuQ9VlefMEId+HLjn3DX8NfedKicW5JnYQp3 GJatJlQBTyC/m7a/pgCYyzdQJowUoLrcCOZBMYwu0V4BC+DkrMBykoSBDz0MVt9FXDu6 oGt0MJxKa/FZGdEYEC7DfskaERhPwvZOZWQVpylyrubF2K7nmVtADSQ9S8BTHHsPwI6n SnVIc/TDukv/ilTeyPfoUnLm3G+YFOx9UUtvU5OU220OcNTRWUCCu4VN/UeodHffqpMc lO2w== X-Gm-Message-State: ACrzQf0VlVuEb3NIKxkVngM0R9NnrEd9YtoAjH0QP/ZupAbOyQhVBrZs +YSlH203wJBRh6ApAuuFQdsLFulyg2uJJA== X-Google-Smtp-Source: AMsMyM5Av8aaftJSOJWvSItBBsnI+xByWG9Q4sB4wVfIaRNN8ff/V3tS8F1imhcp94cYb8jv7z9gzQ== X-Received: by 2002:a17:906:9b8a:b0:780:da07:9df5 with SMTP id dd10-20020a1709069b8a00b00780da079df5mr2956387ejc.273.1663436351755; Sat, 17 Sep 2022 10:39:11 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::8510]) by smtp.gmail.com with ESMTPSA id pw17-20020a17090720b100b00780348931e7sm5663519ejb.75.2022.09.17.10.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 10:39:11 -0700 (PDT) In-Reply-To: (Stefan Kangas's message of "Sat, 17 Sep 2022 13:32:53 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242894 Archived-At: --=-=-= Content-Type: text/plain 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). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-progmodes-python.el-python-shell-restart-New-co.patch >From e0b1d4cb08a57e2170efb92b74c2ce60e4ea7113 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9f9439aac6..6ef468d2cb 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3217,6 +3217,26 @@ run-python 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 -- 2.37.3 --=-=-=--