From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Sharman Newsgroups: gmane.emacs.bugs Subject: bug#45950: 27.1; Certain regexps can cause comint-redirect-results-list-from-process to loop. Date: Sun, 17 Jan 2021 17:24:40 -0800 Message-ID: <1BD39C98-94C1-4814-A25B-A236AAF84027@pobox.com> Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23906"; mail-complaints-to="usenet@ciao.gmane.io" To: 45950@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 18 08:04:12 2021 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 1l1OaC-00065T-Di for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Jan 2021 08:04:12 +0100 Original-Received: from localhost ([::1]:41456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1OaB-0001jl-Ct for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Jan 2021 02:04:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Oa2-0001hr-VN for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 02:04:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1Oa2-0000uB-OS for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 02:04:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1Oa2-0004r6-Ka for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 02:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Richard Sharman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Jan 2021 07:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45950 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161095341118602 (code B ref -1); Mon, 18 Jan 2021 07:04:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Jan 2021 07:03:31 +0000 Original-Received: from localhost ([127.0.0.1]:46171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1OZV-0004pv-8a for submit@debbugs.gnu.org; Mon, 18 Jan 2021 02:03:31 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33278) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1JHm-0004zO-Pg for submit@debbugs.gnu.org; Sun, 17 Jan 2021 20:24:52 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1JHm-0002vQ-JJ for bug-gnu-emacs@gnu.org; Sun, 17 Jan 2021 20:24:50 -0500 Original-Received: from mx4.ncf.ca ([172.83.172.18]:57542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1JHj-0001Jv-1m for bug-gnu-emacs@gnu.org; Sun, 17 Jan 2021 20:24:50 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mx4.ncf.ca (Postfix) with ESMTP id B9CC316663 for ; Sun, 17 Jan 2021 20:24:44 -0500 (EST) X-Virus-Scanned: Ubuntu amavisd-new at Original-Received: from mx4.ncf.ca ([127.0.0.1]) by localhost (mx4.ncf.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bxpjDbpIcim0 for ; Sun, 17 Jan 2021 20:24:43 -0500 (EST) Original-Received: from mail.ncf.ca (mail.ncf.ca [172.83.172.45]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx4.ncf.ca (Postfix) with ESMTPS id 6998316890 for ; Sun, 17 Jan 2021 20:24:43 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 mx4.ncf.ca 6998316890 Original-Received: from [192.168.0.103] (unknown [172.103.218.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: fo019@ncf.ca) by mail.ncf.ca (Postfix) with ESMTPSA id 1626D24EDA for ; Sun, 17 Jan 2021 20:24:42 -0500 (EST) X-Mailer: Apple Mail (2.3445.9.7) Received-SPF: neutral client-ip=172.83.172.18; envelope-from=rsharman@pobox.com; helo=mx4.ncf.ca X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 18 Jan 2021 02:03:28 -0500 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:198073 Archived-At: Certain regexps can cause comint-redirect-results-list-from-process to = loop. For example, when attempting to match whole lines with the regexp "^.*$" if the output buffer contains an empty line, then the re-search-forward expression returns (point) but does not advance point, and since (eobp) is false the loop never terminates.=20 This could avoided by testing if point advances. If it doesn't, one could either exit the loop or, preferably, advance a line which would allow for further matches.=20 Function loop.el demonstrates the problem. It sends to a shell buffer a command that outputs 4 lines, the 3rd of which is empty. Trying to match all lines with "^.*$" causes it to loop.=20 (defun loop () (interactive) ;; create shell if not done (save-window-excursion (shell)) ;; send a command that outputs 4 lines, the 3rd of which is empty (let ((p (get-process "shell")) (command "(echo a; echo b ; echo ; echo d)\n") reply) (setq reply (comint-redirect-results-list-from-process p command = "^.*$" 0)) ;; we never get to here! (message (car reply)) reply )) Note: Starting from emacs -Q it is necessary to run M-x shell before invoking loop, otherwise the error "No prompt found or =E2=80=98comint-prompt-regexp=E2=80=99 not set properly" is produced. With this patch correct results are obtained: --- comint.el.orig 2021-01-17 14:22:17.000000000 -0800 +++ comint.el 2021-01-17 14:23:54.000000000 -0800 @@ -3822,7 +3822,7 @@ Return a list of expressions in the output which match REGEXP. REGEXP-GROUP is the regular expression group in REGEXP to use." (let ((output-buffer " *Comint Redirect Work Buffer*") - results) + results last-point) (with-current-buffer (get-buffer-create output-buffer) (erase-buffer) (comint-redirect-send-command-to-process command @@ -3837,13 +3837,18 @@ ;; Skip past the command, if it was echoed (and (looking-at command) (forward-line)) + (setq last-point (point)) (while (and (not (eobp)) - (re-search-forward regexp nil t)) - (push (buffer-substring-no-properties - (match-beginning regexp-group) - (match-end regexp-group)) - results)) + (re-search-forward regexp nil)) + (if (equal (point) last-point) + (forward-line 1) + (push (buffer-substring-no-properties + (match-beginning regexp-group) + (match-end regexp-group)) + results)) + (setq last-point (point))) (nreverse results)))) + ;; Converting process modes to use comint mode ;; = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= In GNU Emacs 27.1 (build 2, x86_64-apple-darwin17.7.0, NS appkit-1561.61 = Version 10.13.6 (Build 17G14033)) of 2020-12-13 built on henry.local Windowing system distributor 'Apple', version 10.3.1561 System Description: Mac OS X 10.13.6 Recent messages: For information about GNU Emacs and the GNU system, type C-h C-a. loop Quit Quit Configured features: NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS JSON PDUMPER GMP Important settings: value of $LANG: en_CA.UTF-8 locale-coding-system: utf-8-unix Major mode: Emacs-Lisp Minor modes in effect: shell-dirtrack-mode: t tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs text-property-search time-date subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils shell pcomplete comint ansi-color ring tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads kqueue cocoa ns multi-tty make-network-process emacs) Memory information: ((conses 16 49326 43672) (symbols 48 6380 11) (strings 32 17163 4847) (string-bytes 1 570096) (vectors 16 10970) (vector-slots 8 134400 67778) (floats 8 19 151) (intervals 56 211 86) (buffers 1000 14))