From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#57885: [PATCH] Add a command to restart the Python shell Date: Sat, 17 Sep 2022 13:32:53 -0400 Message-ID: References: <875yhmapwr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26124"; mail-complaints-to="usenet@ciao.gmane.io" To: Augusto Stoffel , 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:34:13 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 1oZbhj-0006c2-CQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 19:34:11 +0200 Original-Received: from localhost ([::1]:50522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZbhi-0002an-AD for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Sep 2022 13:34:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZbha-0002af-Av for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oZbha-0002vV-2c for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oZbhZ-0007cW-UR for bug-gnu-emacs@gnu.org; Sat, 17 Sep 2022 13:34:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Sep 2022 17:34:01 +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.166343598229211 (code B ref 57885); Sat, 17 Sep 2022 17:34:01 +0000 Original-Received: (at 57885) by debbugs.gnu.org; 17 Sep 2022 17:33:02 +0000 Original-Received: from localhost ([127.0.0.1]:47117 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbgc-0007ay-Cq for submit@debbugs.gnu.org; Sat, 17 Sep 2022 13:33:02 -0400 Original-Received: from mail-oi1-f180.google.com ([209.85.167.180]:46003) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oZbga-0007aS-8T for 57885@debbugs.gnu.org; Sat, 17 Sep 2022 13:33:01 -0400 Original-Received: by mail-oi1-f180.google.com with SMTP id o204so9828735oia.12 for <57885@debbugs.gnu.org>; Sat, 17 Sep 2022 10:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date; bh=I1tDTpqphBr924/F19IRNuSZSF5SZ1DyQzzzGLT7AlY=; b=i+rJbts+P7AncmPyVF9QlmfCWQplaLrsCtlNAg7udOxKVmXenRMMpCNdFG6lrBtVyJ +4D/cRNX+3vcL8m+Kh20WoYBsUL4olaBuqCE/wYBZpOOoow4oRcvu/8A5LPNsLkaLgpk d4Jhzl1N6IF311sHNKTLXZEa/zrLqvUw1GLUX4Q9P2TuH50arFkPv5ZSjcCjo0pZfkBo JE+tPzzj4cHD02Zm4o2Ey6NIS6nD2fXVZei28lHzCnvSZ3kqT6dlqax7+GWBYOMyclE7 OP+C4gc1tkN5+4jHaFJzI5Z+4JWIjeK0wC1I9SMmEzBH+5ww3TqdYkVaRQ3h0IDtOGD1 yDsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-message-state:from:to:cc:subject:date; bh=I1tDTpqphBr924/F19IRNuSZSF5SZ1DyQzzzGLT7AlY=; b=7YlUQfM5mj8pwDht4DAEaRH6gVh9OaPKfZUcN8We9YVQWT+hjWb1zW5VmSDjwKCTn2 trcPO/wiGGGEdJOCh5UsBu2GKoPgzC2fxxxXCMMu9aCZ8QZzNpqo9A1isSp3XCS7aZTQ 7IyPfLGA06bRACZtEi46ZiYg6Mfhb1OWJ8m76bLnX4vA0/srNPU7/TqddDE76S0c0x7f JtrzCK4wA8vGf59xi+ynXw9+6yPXmUP48WZg8P9LkZ5Uxh1tv0mFRSgnnPj7swTNqJRe h+PkfqiKNPpz+x4fUUJ0FK8kPM27VOhm8oseuI39BYaRZENXCkxVLjFI+/epMzuCT2YV URWw== X-Gm-Message-State: ACgBeo38an47rhqMkCOOqEqLbErSCQZsjLmDxUOo9QBd/2PVQHmomVP3 A8g17dofSI6ePb9Hj8LHknYkkLbzWPEEt5ztAnI= X-Google-Smtp-Source: AA6agR47eki+9iaX4ZEzuSaM9PhoWrN9ZFSVzW+qD9caU8PUPAQqbT1ErGR+zutufoJsx0SwoxoWEldYtYaV0xxnzdM= X-Received: by 2002:a05:6808:1688:b0:345:ea9a:2954 with SMTP id bb8-20020a056808168800b00345ea9a2954mr9115593oib.199.1663435974545; Sat, 17 Sep 2022 10:32:54 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 17 Sep 2022 13:32:53 -0400 In-Reply-To: <875yhmapwr.fsf@gmail.com> X-Hashcash: 1:20:220917:arstoffel@gmail.com::Eoh41wFc2kRHZjcd:3H0D 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:242892 Archived-At: 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. 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. > + (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? > + (python-shell-make-comint (python-shell-calculate-command) > + (string-trim (buffer-name) "\\*" "\\*") > + show)))