From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jack Kamm Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] python.el: Returning inferior Python output without inhibiting it Date: Sun, 01 Oct 2023 13:23:29 -0700 Message-ID: <87jzs6hz26.fsf@gmail.com> References: <87msx2ib0c.fsf@gmail.com> <83fs2u8ehy.fsf@gnu.org> 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="36342"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 01 22:24:25 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qn2zI-00090C-PP for ged-emacs-devel@m.gmane-mx.org; Sun, 01 Oct 2023 22:24:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qn2yY-000753-J4; Sun, 01 Oct 2023 16:23:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qn2yW-00074g-G5 for emacs-devel@gnu.org; Sun, 01 Oct 2023 16:23:36 -0400 Original-Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qn2yU-0003f0-Ni; Sun, 01 Oct 2023 16:23:36 -0400 Original-Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68bed2c786eso12672724b3a.0; Sun, 01 Oct 2023 13:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696191811; x=1696796611; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=mHk5B2sP7r1yn1DjKaDHrY8heo+1HsUO7gdjJflphLM=; b=Rk4rZbaJsI9LoHGb/dWVXbA6EBZ9jCAq1Jy0tMBCi7h0hrzd765JbyJ+GY1f63YFu+ rRsaHKXCvaw69SW4RrEe/eZE63JgWD3LTpgd0OkFiS2uBuSVoZC6aQr9jL+9m9CK1Wj1 3fLtgSg3O0vbTu7vRU0flcp+ZYW3ZFmx4pSLlAmi3LD+ubQ0JiaeGV/KS0qBhY5K4m+p 4U2SbetkplklVhil2aMoDWHzEXmVqQEN3hhPwi8aNw99U/y6yjBVY6Br5gf5s+0c0wVZ 4eBbzD0aEsciCDd8X2r89f/Z9zSMNs1qJCvv0DR5/5k0N/+cH0oyUnV1avlO9qh2oLny d39Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696191811; x=1696796611; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mHk5B2sP7r1yn1DjKaDHrY8heo+1HsUO7gdjJflphLM=; b=CukfY5MYCc0m1VFFjNkObXUHLXlYOIyvCRd6w2AqFEsTdjf4/umB55JxHFEsddfKUK +ov3LmWzBVueVNLdEg6zN4TCVBOfHRGgtaoozcGzPI5M0XHyPCbWGZtTQQkO34O9OgSn 8U1JpFsOHDFgBulJKtWnDhdYmnID/hsMjYSiYIKBGn+J5v6hLgqtB7+k8hToas1yM7Dt CWkFDP5845nvOS7k6eEESykr9meMqo9vEpdodgNketAI4Khj03jkowpvK9wPhnfXbT7U ey9g1fsQxbc7mP0ptQiKf6AhTnlLi0kBZezq3lUkzGgIRUxqZjuMKCEydKZuLreZM/3c BwLQ== X-Gm-Message-State: AOJu0YwIwwr0z7goGKNw6EeK8nFCfhX+4UgzWB2CFPsl7UXAwPT0rpDJ xcl6KWik+y4HFmoQSFcGp/m8Eh1pw9k= X-Google-Smtp-Source: AGHT+IHooD5TzJS+NEDA7KhQ6x27JMR6JUtNgyZfYCcrjyKzSpgJkPV+WFr3Aw2QXfaaoVe3VL7tjQ== X-Received: by 2002:a05:6a21:4983:b0:15e:9032:419a with SMTP id ax3-20020a056a21498300b0015e9032419amr7301142pzc.31.1696191811349; Sun, 01 Oct 2023 13:23:31 -0700 (PDT) Original-Received: from localhost (157-131-78-143.fiber.dynamic.sonic.net. [157.131.78.143]) by smtp.gmail.com with ESMTPSA id t18-20020a170902d21200b001c74df14e6fsm4210821ply.284.2023.10.01.13.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 13:23:30 -0700 (PDT) In-Reply-To: <83fs2u8ehy.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=jackkamm@gmail.com; helo=mail-pf1-x42a.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: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:311226 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > I think instead of renaming (which then requires us to add an obsolete > alias), it would be better to leave python-shell-send-string-no-output > available, but just make it a thin wrapper around > python-shell-send-string-return-output (which I would suggest to name > python-shell-send-string-maybe-output instead). This way, we don't > annoy Lisp programs that use python-shell-send-string-no-output with > obsolescence warnings. Thanks for the feedback -- I've updated the patch accordingly (attached). --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-python.el-Function-to-return-output-without-necessar.patch >From c071d5a531a6f17e229b0f4a9239f0f054321bc9 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sat, 30 Sep 2023 21:04:12 -0700 Subject: [PATCH] python.el: Function to return output without necessarily inhibiting * lisp/progmodes/python.el (python-shell-output-filter-inhibit-output): Variable to determine whether output currently inhibited. (python-shell-send-string): Check `python-shell-output-filter-inhibit-output' instead of `python-shell-output-filter-in-progress' to determine whether output is inhibited. (python-shell-output-filter): Set `python-shell-output-filter-inhibit-output' to nil after reaching end of output. (python-shell-send-string-no-output): Turned into a thin wrapper around `python-shell-send-string-maybe-output'. (python-shell-send-string-maybe-output): Adapted from `python-shell-send-string-no-output'. Add function argument on whether output should be inhibited, and set `python-shell-output-filter-inhibit-output' accordingly. If not inhibited, then the original filter function is run in addition to `python-shell-output-filter', and `comint-last-prompt' is not reset after evaluation (since the original output filter will set it approriately). --- lisp/progmodes/python.el | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d3cb5a77e22..30d0416d035 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2736,6 +2736,7 @@ python-shell-dedicated (defvar python-shell-output-filter-in-progress nil) (defvar python-shell-output-filter-buffer nil) +(defvar python-shell-output-filter-inhibit-output nil) (defmacro python-shell--add-to-path-with-priority (pathvar paths) "Modify PATHVAR and ensure PATHS are added only once at beginning." @@ -3750,7 +3751,7 @@ python-shell-send-string (python-shell--encode-string string) (python-shell--encode-string (or (buffer-file-name) ""))))) - (unless python-shell-output-filter-in-progress + (unless python-shell-output-filter-inhibit-output (with-current-buffer (process-buffer process) (save-excursion (goto-char (process-mark process)) @@ -3780,6 +3781,7 @@ python-shell-output-filter ;; Output ends when `python-shell-output-filter-buffer' contains ;; the prompt attached at the end of it. (setq python-shell-output-filter-in-progress nil + python-shell-output-filter-inhibit-output nil python-shell-output-filter-buffer (substring python-shell-output-filter-buffer 0 (match-beginning 0))) @@ -3795,12 +3797,21 @@ python-shell-output-filter (defun python-shell-send-string-no-output (string &optional process) "Send STRING to PROCESS and inhibit output. Return the output." + (python-shell-send-string-maybe-output string process)) + +(defun python-shell-send-string-maybe-output (string &optional process show-output) + "Send STRING to PROCESS and return the output. +Inhibit printing the output unless SHOW-OUTPUT is non-nil." (or process (setq process (python-shell-get-process-or-error))) - (cl-letf* (((process-filter process) + (cl-letf* ((original-filter-fn (process-filter process)) + ((process-filter process) (lambda (_proc str) (with-current-buffer (process-buffer process) - (python-shell-output-filter str)))) + (python-shell-output-filter str)) + (when show-output + (funcall original-filter-fn process str)))) (python-shell-output-filter-in-progress t) + (python-shell-output-filter-inhibit-output (not show-output)) (inhibit-quit t) (buffer (process-buffer process)) (last-prompt (cond ((boundp 'comint-last-prompt-overlay) @@ -3812,13 +3823,15 @@ python-shell-send-string-no-output (with-local-quit (unwind-protect (python-shell-send-string string process) - (when (not (null last-prompt)) - (with-current-buffer buffer - (set last-prompt last-prompt-value)))) + (unless show-output + (when (not (null last-prompt)) + (with-current-buffer buffer + (set last-prompt last-prompt-value))))) (while python-shell-output-filter-in-progress ;; `python-shell-output-filter' takes care of setting - ;; `python-shell-output-filter-in-progress' to NIL after it - ;; detects end of output. + ;; `python-shell-output-filter-in-progress' and + ;; `python-shell-output-filter-inhibit-output' to NIL after + ;; it detects end of output. (accept-process-output process)) (prog1 python-shell-output-filter-buffer -- 2.42.0 --=-=-=--