From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#19873: Ill-formed regular expression is constructed in forward-paragraph. Date: Thu, 02 Dec 2021 12:17:54 +0100 Message-ID: <87lf1345nh.fsf@gnus.org> References: <20150215103122.GA3282@acm.fritz.box> <87o9xodhq4.fsf@jane> <20170309210445.GB4046@acm> <87y25347ew.fsf@gnus.org> <87tufr476y.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7128"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Marcin Borkowski , 19873@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 02 12:20:56 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 1msk91-0001eV-Jg for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Dec 2021 12:20:55 +0100 Original-Received: from localhost ([::1]:57784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1msk90-0005OT-7n for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Dec 2021 06:20:54 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msk7E-0002yG-23 for bug-gnu-emacs@gnu.org; Thu, 02 Dec 2021 06:19:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35254) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1msk7D-0007Bl-2Z for bug-gnu-emacs@gnu.org; Thu, 02 Dec 2021 06:19:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1msk7C-0004FF-HF for bug-gnu-emacs@gnu.org; Thu, 02 Dec 2021 06:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Dec 2021 11:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19873 X-GNU-PR-Package: emacs Original-Received: via spool by 19873-submit@debbugs.gnu.org id=B19873.163844389016246 (code B ref 19873); Thu, 02 Dec 2021 11:19:02 +0000 Original-Received: (at 19873) by debbugs.gnu.org; 2 Dec 2021 11:18:10 +0000 Original-Received: from localhost ([127.0.0.1]:46800 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1msk6K-0004Dw-Hz for submit@debbugs.gnu.org; Thu, 02 Dec 2021 06:18:10 -0500 Original-Received: from quimby.gnus.org ([95.216.78.240]:38314) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1msk6G-0004DP-6e for 19873@debbugs.gnu.org; Thu, 02 Dec 2021 06:18:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=heriiMj858g2XELglxiqS4p6wLdkS89U6cEC7C4lAtI=; b=W5gCncsANPl0nSSU+trTcHQrC2 hrnW+U0XoH1cqBSBUZKfef8oV5G1RcSVTK9Yhsmsh2wvQjxu46UrHzCVHmErCFXO3ksLB+3solqb9 hw4d5EZlv0hYqX5nYIcJTn2ALm+LV6Vr+V8V7jTiSsPSylFkHRSZ+uyYysOYia5jEKgY=; Original-Received: from [84.212.220.105] (helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msk66-0000LS-PM; Thu, 02 Dec 2021 12:17:57 +0100 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAIVBMVEUQDQkwLSkiHxpC PjvR0M79/f2fnZpgXlrAv72CgHz////dq+NpAAAAAWJLR0QKaND0VgAAAAd0SU1FB+UMAgsPDonR 2zIAAAGiSURBVDjLddJLT8JAEADg6ZJQjrQmeK0biFeRGK+iKfFa7QDeECjliBgIVw2oP8Do33X2 1W5L3YTQ2S/z2G0BABwoLyeQf7UmVC/tFcsHOKnKYuHgdF2VUMf4ubLSbpBW7jPv9dpqz3Zv2aPv s2x/G+I4cL5eJPCAoPtS6/a8FtIazBH1OajUz8xN098E9ZInzzs0C9ADyOhgg0cHD47BaTIO7oeW MIfWlOb6xn4ZXJz2rpf0JG+RYQYdTNUkEzm52d/DBhcq/UbBWMESEtxjDi6OVLSl+fSED+oN9FWU wiHW8CiggXcqmoEpiiMFnyp6A4wNMAkLFb1DNriG5RE8EbAGzlXUz2EooI6J6WgD4xkMqXlogAN3 400OOmPMabmoIc5LxQJq5h7QAl9m4H9AHWXXEjjiroeHAuAlQZDc0xkSOVUB+PmW7pkmiywQpXhA 7SOC2zKIuaIr8QWUSvEzusA24sqCtYTggFFbfEw5dBUkGHUwDo5hg1EdsQC+yXBLpQzc1goQZzCh yS6sN+gZWPHQHnfkeXpcAdYBR6qU2BS/P2Yp9fsldDLvAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIx LTEyLTAyVDExOjE1OjE0KzAwOjAw0hwSHAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMS0xMi0wMlQx MToxNToxNCswMDowMKNBqqAAAAAASUVORK5CYII= X-Now-Playing: DACM's =?UTF-8?Q?=5FSt=C3=A9r=C3=A9otypie=5F:?= "Marie" In-Reply-To: <87tufr476y.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 02 Dec 2021 11:44:37 +0100") 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:221293 Archived-At: Lars Ingebrigtsen writes: > Ah, there was a reproducer in bug#19846 (and it still reproduces). > > I'll poke around here, then. The following is about 100x faster in the test case, and doesn't seem to lead to any obvious regressions. But it's kinda ugly. Any comments? An alternate approach would be to just go line by line, and see whether the regexp matches at the start of the line (either before or after skipping past any leading whitespace). But I'm not sure that's any prettier. diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index 59b15e82a8..e0d633d49b 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el @@ -238,7 +238,7 @@ forward-paragraph fill-prefix-regexp "[ \t]*$") parsep)) ;; This is used for searching. - (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)")) + (sp-parstart (concat "\\(?:" parstart "\\|" parsep "\\)")) start found-start) (while (and (< arg 0) (not (bobp))) (if (and (not (looking-at parsep)) @@ -278,7 +278,7 @@ forward-paragraph ;; multiple-lines ;; (forward-line 1)) (not (bobp))) - (while (and (re-search-backward sp-parstart nil 1) + (while (and (paragraph--line-search nil sp-parstart) (setq found-start t) ;; Found a candidate, but need to check if it is a ;; REAL parstart. @@ -328,7 +328,7 @@ forward-paragraph (not (looking-at parsep)) (looking-at fill-prefix-regexp)) (forward-line 1)) - (while (and (re-search-forward sp-parstart nil 1) + (while (and (paragraph--line-search t sp-parstart) (progn (setq start (match-beginning 0)) (goto-char start) (not (eobp))) @@ -344,6 +344,34 @@ forward-paragraph ;; Return the number of steps that could not be done. arg)) +;; We do it this way because the regexp commonly starts with optional +;; whitespace. +(defun paragraph--line-search (forward regexp) + "Look for REGEXP starting on a line. +If FORWARD, search forward. If not, go backward." + (catch 'found + (while (and (or (and forward + (not (eobp))) + (and (not forward) + (not (bobp)))) + (funcall (if forward + #'re-search-forward + #'re-search-backward) + regexp nil 1)) + (save-excursion + (goto-char (match-beginning 0)) + (beginning-of-line) + (save-restriction + (narrow-to-region + (point) (match-beginning 0)) + (when (looking-at-p "[ \t]*$") + (throw 'found t)))) + (if forward + (unless (eobp) + (forward-char 1)) + (unless (bobp) + (backward-char 1)))))) + (defun backward-paragraph (&optional arg) "Move backward to start of paragraph. With argument ARG, do it ARG times; -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no