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: Sun, 18 Sep 2022 08:53:36 +0200 Message-ID: <87o7vdyxzj.fsf@gmail.com> References: <875yhmapwr.fsf@gmail.com> <87sfkpaojl.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="5961"; 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 Sun Sep 18 08:54:15 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 1oZoBy-0001M3-FJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 08:54:14 +0200 Original-Received: from localhost ([::1]:38448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZoBw-0007Lu-S3 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 02:54:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZoBn-0007Lh-Np for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 02:54:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZoBm-000728-Ks for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 02:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZoBm-0006mW-Bk for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 02:54: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: Sun, 18 Sep 2022 06:54: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.166348402926046 (code B ref 57885); Sun, 18 Sep 2022 06:54:02 +0000 Original-Received: (at 57885) by debbugs.gnu.org; 18 Sep 2022 06:53:49 +0000 Original-Received: from localhost ([127.0.0.1]:47630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZoBZ-0006m2-0M for submit@debbugs.gnu.org; Sun, 18 Sep 2022 02:53:49 -0400 Original-Received: from mail-ed1-f44.google.com ([209.85.208.44]:37806) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZoBV-0006lm-BE for 57885@debbugs.gnu.org; Sun, 18 Sep 2022 02:53:47 -0400 Original-Received: by mail-ed1-f44.google.com with SMTP id a41so25120499edf.4 for <57885@debbugs.gnu.org>; Sat, 17 Sep 2022 23:53:45 -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=y3w+yee68Pk0uLfGabrYbIhqUGt0uYQMHsvaqPLfMqI=; b=JyLwLGalnCv/8c+QtEzhpXD9OD6jTIBPCFf00eJw0ibdEmQuhOuYr6slybhJoft+gP kYnyzLicfQW1c+FfUS0c9gPIDUN4oMtnAT+LI+4jpDusEkNsfnPmD3jkXKqFte2fi/8m m9TW8om9Tm5smYtrbUuzh1LzoCh+Lm/16Gq+L/uPN885kW/Mbn3uHxptcGqpxI2tBEo+ KvJszu3HnZpizako3fc0tmfanGM1E5/Ixcmka0TcdBHPVpr0kvUJvkOAgmcqrRT3FNxC tZqKr+eMMub2obJYRdWOgBxwe6jjSPdB4/vIWjUc5HpxAUW06FRoJJkS13WHbaDo4zuA c0IQ== 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=y3w+yee68Pk0uLfGabrYbIhqUGt0uYQMHsvaqPLfMqI=; b=rOeDq/8WSGXvp1lEg8Pg0gT/t7y6BczvTDS419sRie8J7V/u69qFtwTOhv97zg6WxJ hwk/SnnAad6INvybwVGmOiELU0+3xvAKsqNyzREJ7NKkBCqm4iRcXjexzemM4ag4iPeo KhdfwwcT8DRrB0s7/A9JRjwbdXOpk9mBfh83gMm31PImsQ0SjCNF/wsk70VGx2gfDRvH ZD0etMMwO6W4oY1uD4EvMxHiiWIkWwVdkJvaBpFxLOeJbaTjYCpr4MDzY7Thhexg4t+M ZINa9oXV06l7nO9rXIadHeeYMq8MUbmKC7rCiAK4V3h8esC+zjJp7WVIjCE5hk5HWF7g n8cg== X-Gm-Message-State: ACrzQf3vXhKwU+xuOv1gonRq8MTaRFmYFlHgtUtjlVOilzNx/12i4vJ1 adxBu/+2mz1GamJPtwuVNYOvpag2CGDACA== X-Google-Smtp-Source: AMsMyM6/YXrcH+YQYeXKGpbMQb5qApwRJug0qltC9HtcgOjil2RYrDUipI29IN5JTYdaM29u4P5uEw== X-Received: by 2002:a05:6402:885:b0:452:8af6:5255 with SMTP id e5-20020a056402088500b004528af65255mr10212517edy.74.1663484018998; Sat, 17 Sep 2022 23:53:38 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::8510]) by smtp.gmail.com with ESMTPSA id p5-20020a50cd85000000b0043ba7df7a42sm17377098edi.26.2022.09.17.23.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 23:53:37 -0700 (PDT) In-Reply-To: (Stefan Kangas's message of "Sat, 17 Sep 2022 14:04:00 -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:242926 Archived-At: --=-=-= Content-Type: text/plain On Sat, 17 Sep 2022 at 14:04, Stefan Kangas wrote: > Augusto Stoffel writes: > >> Okay, then let's decide later (or not decide :-)). > > :-) > >> 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). > > Makes sense. > >> Subject: [PATCH] * lisp/progmodes/python.el (python-shell-restart): New >> command. > > BTW, maybe you want to add a first line with text like > > Add new command python-shell-restart Find attached a patch with an expanded commit message, and also an unrelated but trivial refinement for something else. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-new-command-python-shell-restart.patch >From ce69165e1050601a0ed4a9b45aca998793b468fe Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sat, 17 Sep 2022 19:01:57 +0200 Subject: [PATCH 1/2] Add new command python-shell-restart * 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Remap-up-list-in-python-mode-map.patch >From 8002e7a2ec6711b057529db082ed2f3691912004 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sun, 18 Sep 2022 08:47:01 +0200 Subject: [PATCH 2/2] Remap 'up-list' in python-mode-map The original 'up-list' command doesn't work as expected in python-mode, and its sibling 'backward-up-list' already has a remapping. * lisp/progmodes/python.el (python-mode-map): Remap 'up-list' to 'python-nav-up-list'. --- lisp/progmodes/python.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 6ef468d2cb..09f94f4b34 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -300,6 +300,7 @@ python-mode-map (define-key map [remap backward-sentence] #'python-nav-backward-block) (define-key map [remap forward-sentence] #'python-nav-forward-block) (define-key map [remap backward-up-list] #'python-nav-backward-up-list) + (define-key map [remap up-list] #'python-nav-up-list) (define-key map [remap mark-defun] #'python-mark-defun) (define-key map "\C-c\C-j" #'imenu) ;; Indent specific -- 2.37.3 --=-=-=--