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:09:40 +0200 Message-ID: <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="38175"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: 57885@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 17 19:10:23 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 1oZbKg-0009ms-S9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 19:10:22 +0200 Original-Received: from localhost ([::1]:50696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZbKf-0006TI-Uj for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 13:10:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZbKN-0006Rp-HQ for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZbKM-00083d-Nc for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZbKM-0006zS-Cx for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:10: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:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57885 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166343459226847 (code B ref -1); Sat, 17 Sep 2022 17:10:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Sep 2022 17:09:52 +0000 Original-Received: from localhost ([127.0.0.1]:47076 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbKB-0006yx-M1 for submit@debbugs.gnu.org; Sat, 17 Sep 2022 13:09:51 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbK6-0006ym-GD for submit@debbugs.gnu.org; Sat, 17 Sep 2022 13:09:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZbK6-0006R0-8Z for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:09:46 -0400 Original-Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:47048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZbK4-00083D-Hp for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:09:45 -0400 Original-Received: by mail-ej1-x62f.google.com with SMTP id bj12so55759429ejb.13 for ; Sat, 17 Sep 2022 10:09:44 -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:subject:to:from:from:to:cc :subject:date; bh=khIWRwbTAzrmwo0hdCupJFojOOKuG/TdrQoqD1ud37c=; b=dp5VHZhixbOUC2aP29jieXFwLfJdO4BdWn2p4SnBoHID4X+YrB+JUEfS5S1aqFpULi 56ZSpSui21N3/PgJgfSTKBeWVAjJgKpNIlDValsODogA7x4jWLxzJiE5Xig/OHwI1Pay sMWBwRuRs4P3C1k0VU7oDTgrK41BlMjrrs0fyHayIFKwxDe+yWiGVjg8FVrjVls5elvi W1ew3/e/vWX9UX8vzz5DdguqIzhnYkb5ptn3mc0UtaiFroz1bs/g57If0gtc6UZTn1z0 y6ULeL5NtpkxQjmcjDVBvJQEmGzWVQ5x2INi8KeJTn7iipgTyvKRp+G7uuvVcFGy4r/N /tXg== 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:subject:to:from :x-gm-message-state:from:to:cc:subject:date; bh=khIWRwbTAzrmwo0hdCupJFojOOKuG/TdrQoqD1ud37c=; b=rQMr1oy9WYN+j3kMwNm7fT0ECrfPCzkToZ6UneGEHOOI+HF2v+mPW7iaWcIqo++YYC i38rldhkEHmrkQ5DzSVW6zsyxcM+jRkXKdK8Ws4iFpszh4vG2VrW24Com0XBROcLJXK1 91YpestvPcu5QyUI8LHfDMHWKbUEkHlSXsILFJmU9LfDsGeH1sGPdDGFoP1X6UbyA1+l q4dX+A6vp+hUOPGtNWf7Q1WFsd/zaq7STJqPqnrv8C1cKpHbWewziTHjUPS+crPwRsCo mxRAJSZblDW4/bPGDXx7BxDQf61S+O+o2nHDzJ7Uapze6HE50CtqSj8JVSqCaSXFFoSm ssYQ== X-Gm-Message-State: ACrzQf2DMyc4Apc0SBixnsV+QIsBxutgfHNA2MjeE0WtNzuxQ+7Net5e ufbXZ6TaLfEFzHQyiHJvBZxMr5G3nr2lqw== X-Google-Smtp-Source: AMsMyM5Hxdl2QWjDVJs18OnGwg5N439Eitkk79E+5NoznLtSN0wZj8TWURx0HTsGwmtmNFMdi3c2ww== X-Received: by 2002:a17:906:30c8:b0:73c:81a9:f8e1 with SMTP id b8-20020a17090630c800b0073c81a9f8e1mr7271678ejb.649.1663434582451; Sat, 17 Sep 2022 10:09:42 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::8510]) by smtp.gmail.com with ESMTPSA id u13-20020a056402110d00b00453852db507sm2806896edv.41.2022.09.17.10.09.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 10:09:41 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:242888 Archived-At: --=-=-= Content-Type: text/plain Tags: patch I find this pretty much essential when running "notebooks" and the like. 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. Also, in case the `string-trim' call looks hacky, I should add that the relationship between the shell buffer and process name is pretty much hardcoded in python.el, so there doesn't seem to be anything more reasonable to do that wouldn't require some major refactoring. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-lisp-progmodes-python.el-python-shell-restart-New-co.patch >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 --=-=-=--