From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rah Guzar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61602: [PATCH]: comint-mode redirection Date: Fri, 12 May 2023 09:11:05 +0200 Message-ID: <87h6si2erm.fsf@zohomail.eu> References: <873573ryft.fsf@zohomail.eu> <87pm763gfy.fsf@zohomail.eu> Reply-To: Rah Guzar 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="672"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.10.3; emacs 29.0.90 Cc: 61602@debbugs.gnu.org To: Ruijie Yu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 12 09:25:24 2023 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 1pxN9X-000AQQ-Qb for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 May 2023 09:25:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxN9G-0003Ip-Jf; Fri, 12 May 2023 03:25:06 -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 1pxN9C-0003IW-SS for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 03:25:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pxN9C-0007Le-J1 for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 03:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pxN9C-00009R-E3 for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 03:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Rah Guzar Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 May 2023 07:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61602 X-GNU-PR-Package: emacs Original-Received: via spool by 61602-submit@debbugs.gnu.org id=B61602.1683876295564 (code B ref 61602); Fri, 12 May 2023 07:25:02 +0000 Original-Received: (at 61602) by debbugs.gnu.org; 12 May 2023 07:24:55 +0000 Original-Received: from localhost ([127.0.0.1]:53910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxN94-000092-QY for submit@debbugs.gnu.org; Fri, 12 May 2023 03:24:55 -0400 Original-Received: from sender11-pp-o91.zoho.eu ([31.186.226.249]:25135) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxN91-00008s-UK for 61602@debbugs.gnu.org; Fri, 12 May 2023 03:24:53 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1683876288; cv=none; d=zohomail.eu; s=zohoarc; b=YPtEiHoGlKjHGIJMY7dWRmbQsCMFwr4Scg82DSxv36IHLnJr/QEQfwscfFUH9mlv2R8+eztwkAvbnFPO20SS6BpMEdIqg3Y0+Ixse69xT8IOOL2Bp+2U9hadfN/OyDdeVor3TLN92xHmpnRBWfNFVlXUdH9cfLygltXcj9NFw4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1683876288; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=3YeJv63q8r9HZ2PLFfAVDxADFTy6QajuIvy9Ww63xNc=; b=QMHNAaxk+jTv1vg+ctmQaI6OgnNZ6ISegO0/DVciOD22Dr9RDNOoKW6zzvpN+0tzZvAU/2uPDYwPZH2fTPHlZaLyYBkoRzgNLbKw6pEVZk7TS1gVFyrdYDa9zQcbxwsgjxM+y0hv80CqJJH5lBwrsXOJXzXl3fuz+NEBbJ6QBxE= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=zohomail.eu; spf=pass smtp.mailfrom=rahguzar@zohomail.eu; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1683876288; s=zoho; d=zohomail.eu; i=rahguzar@zohomail.eu; h=References:From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:In-reply-to:Message-ID:MIME-Version:Content-Type:Message-Id:Reply-To; bh=3YeJv63q8r9HZ2PLFfAVDxADFTy6QajuIvy9Ww63xNc=; b=eXyNDrgQ4mE3nQLPP1mauQqAswbffQjyZjdgukxHOTpkuCOVslmEznVmk/jZdJCR GaWlWiRPRO05RmuYv+T42PoiOnX3PiKPAlRVGsH5fz+Il9rBlG5yVTQ3DDVM/V52N/i e0R5ZmVqJ/5ajmq24wXfYRwffd2BrexDQHA1asm8= Original-Received: from localhost (81-231-79-170-no600.tbcn.telia.com [81.231.79.170]) by mx.zoho.eu with SMTPS id 1683876287326461.61554864493826; Fri, 12 May 2023 09:24:47 +0200 (CEST) In-reply-to: X-Zoho-Virus-Status: 1 X-ZohoMailClient: External 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261612 Archived-At: --=-=-= Content-Type: text/plain Hi Ruijie, Thanks for the comments. Ruijie Yu writes: > Thanks for the patch. First of all, when sending a patch(set) for > Emacs, you need to run something like this: > > $ git format-patch > > and send the generated file(s). Take a look at its manpage and ask if > you have any questions. What you have sent is a "diff" file, which > bears no commit messages. At least in Emacs contributions, patches > should usually come together with their commit messages. > > And there are guidelines on commit messages, see /CONTRIBUTE on > emacs.git. I have attached a patch which hopefully is made properly this time. > Further in-line comments below. > > Rah Guzar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > >> This variable is only used if the variable >> -`comint-use-prompt-regexp' is non-nil. >> +`comint-use-prompt-regexp' is non-nil. The exception to >> +this is redirection. Many commands including >> +`comint-redirect-send-command-to-process' use it as >> +`comint-redirect-finished-regexp'. > > This paragraph sounds a bit weird, but I don't know how to reword it. > Maybe someone else can help. > I tried some rewording. >> (defvar comint-redirect-finished-regexp nil >> "Regular expression that determines when to stop redirection in Comint. >> When the redirection filter function is given output that matches this regexp, >> -the output is inserted as usual, and redirection is completed.") >> +the output is inserted as usual, and redirection is completed. >> +This is an internal variable set by `comint-redirect-setup' and setting it >> +directly has no effect.") > > If this is indeed a private variable, why does it contain no > double-dashes in its name prior to your changes? > > Also, here and elsewhere, except for the first line, there should > generally be one empty line between paragraphs. > It is not declared as a private variable but it is in effect used as one, so documenting should prevent confusion. Some context: I wanted to use redirection to display some documentation is a separate buffer. However documentation sometimes contained the usual prompt and that messed up the comint buffer. To get around it I setup the redirected commands so that they had a custom prompt and tried to set c-r-f-r accordingly but that didn't work and I had to fish around the comint source to figure out why. >> +(defvar comint-redirect-hook nil >> + "Hook run when a redirection finishes.") > Does it make sense for a user to customize the hook? If so, you should > convert this variable into a `defcustom'. This for better discoverability. I think comint-mode is too low-level for most users to use it directly. But e.g. for those writing a derived mode it is good to be aware that this hook exists without diving into source. >> +If FINISHED-REGEXP is non-nil it is used as `comint-redirect-finished-regexp' >> +instead of `comint-prompt-regexp'." > > Please clarify what "it" is. > > If you are referring to the change below from `cominit-prompt-regexp' to > `(or finished-regexp comint-prompt-regexp)', then the current form is > ambiguous, and maybe you should say something like this: > > If F-R is non-nil, it is used as `c-r-f-r'. Otherwise `c-p-r' is > used as `c-r-f-r'. > Thanks, I incorporated your suggestion. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Bug-61602-Tweak-comint-mode-redirection.patch >From ac814964e1885d005746e98f5010a2b400293810 Mon Sep 17 00:00:00 2001 From: Rahguzar Date: Fri, 12 May 2023 09:00:34 +0200 Subject: [PATCH] (Bug#61602) Tweak comint-mode redirection * lisp/comint.el (redirection): New optional argument for 'comint-redirect-send-command-to-process' to explicitly set the regexp to end redirection. Define 'comint-redirect-hook' for easier discovery. Miscellaneous documentation fixes. --- lisp/comint.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 682b555a33c..e6ce31f231c 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -161,7 +161,10 @@ comint-prompt-regexp Defaults to \"^\", the null string at BOL. This variable is only used if the variable -`comint-use-prompt-regexp' is non-nil. +`comint-use-prompt-regexp' is non-nil. An exception to +this is redirection. Many commands including +`comint-redirect-send-command-to-process' use `comint-prompt-regexp' +to detect the end of redirection. Good choices: Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) @@ -3637,7 +3640,13 @@ comint-redirect-output-buffer (defvar comint-redirect-finished-regexp nil "Regular expression that determines when to stop redirection in Comint. When the redirection filter function is given output that matches this regexp, -the output is inserted as usual, and redirection is completed.") +the output is inserted as usual, and redirection is completed. + +This is an internal variable set by `comint-redirect-setup' and setting it +directly has no effect.") + +(defvar comint-redirect-hook nil + "Normal hook run when a redirection finishes.") (defvar comint-redirect-insert-matching-regexp nil "If non-nil, the text that ends a redirection is included in it. @@ -3833,11 +3842,14 @@ comint-redirect-send-command ;;;###autoload (defun comint-redirect-send-command-to-process - (command output-buffer process echo &optional no-display) + (command output-buffer process echo &optional no-display finished-regexp) "Send COMMAND to PROCESS, with output to OUTPUT-BUFFER. With prefix arg, echo output in process buffer. -If NO-DISPLAY is non-nil, do not show the output buffer." +If NO-DISPLAY is non-nil, do not show the output buffer. +FINISHED-REGEP is set as `comint-redirect-finished-regexp' +when it is non-nil, otherwise `comint-prompt-regexp' is used +as `comint-redirect-finished-regexp'." (interactive "sCommand: \nBOutput Buffer: \nbProcess Buffer: \nP") (let* (;; The process buffer (process-buffer (if (processp process) @@ -3857,9 +3869,9 @@ comint-redirect-send-command-to-process ;; Set up for redirection (comint-redirect-setup output-buffer - (current-buffer) ; Comint Buffer - comint-prompt-regexp ; Finished Regexp - echo) ; Echo input + (current-buffer) ; Comint Buffer + (or finished-regexp comint-prompt-regexp) ; Finished Regexp + echo) ; Echo input ;; Set the filter. (add-function :around (process-filter proc) #'comint-redirect-filter) -- 2.40.1 --=-=-=--