From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#37127: [PATCH] cperl-mode: Suppress a misleading message Date: Fri, 30 Oct 2020 18:12:13 -0400 Message-ID: References: <87ftlu67cy.fsf@vinc17.net> <87eelg3ffl.fsf@hajtower> <87zh43cvqa.fsf@hajtower> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21750"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 37127@debbugs.gnu.org To: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 30 23:13:10 2020 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 1kYcdy-0005We-4F for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Oct 2020 23:13:10 +0100 Original-Received: from localhost ([::1]:52446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYcdw-0005bY-IP for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Oct 2020 18:13:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYcdq-0005bS-4u for bug-gnu-emacs@gnu.org; Fri, 30 Oct 2020 18:13:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYcdp-0004ex-RW for bug-gnu-emacs@gnu.org; Fri, 30 Oct 2020 18:13:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kYcdp-00039P-Me for bug-gnu-emacs@gnu.org; Fri, 30 Oct 2020 18:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Oct 2020 22:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37127 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed fixed Original-Received: via spool by 37127-submit@debbugs.gnu.org id=B37127.160409594412065 (code B ref 37127); Fri, 30 Oct 2020 22:13:01 +0000 Original-Received: (at 37127) by debbugs.gnu.org; 30 Oct 2020 22:12:24 +0000 Original-Received: from localhost ([127.0.0.1]:60051 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kYcdD-00038W-Pv for submit@debbugs.gnu.org; Fri, 30 Oct 2020 18:12:24 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64874) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kYcdC-00038F-8l for 37127@debbugs.gnu.org; Fri, 30 Oct 2020 18:12:22 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C8DF21002FA; Fri, 30 Oct 2020 18:12:16 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 045F610025D; Fri, 30 Oct 2020 18:12:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1604095935; bh=76p442ZfTQKaaIcY8tJGUGAuqBm9BgTqIDzUk9d/EMY=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=ELDDerZC5/04Ia7Orax5XfHdFhzBaGSyykjqZ2wIgXfaiHbM+2RKjp7UP7F3mHUIH CAxIDUlAOlQv8PqNMaCzygU6N1i4jtler2bbDmY47zae3S3NzRtWvGX18RdpYUlM/Z xlV+SSgw/aKMWZWlWh3odrWkGJqxvCypu5ytW6bSEWJdhXkNrpT2Yf9C4lhjfUh0ge zHtVn5ixLnPBJUEIvgM9uv3TLFSWLT9qiX82TMsxvVEXRTPbLap4Mnbt7TFW57mS/u irkAJcqlTtk0vBb3yVD0AHKvCq51YQ4jXKp1PfyGRp7f8I/oets+JO/LHQ+v+iCED4 DunUxiA9xhvtA== Original-Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C8A9E120380; Fri, 30 Oct 2020 18:12:14 -0400 (EDT) In-Reply-To: <87zh43cvqa.fsf@hajtower> ("Harald =?UTF-8?Q?J=C3=B6rg?="'s message of "Fri, 30 Oct 2020 21:19:41 +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:192213 Archived-At: >> I mean, I don't necessarily mind it, but as a user I find it odd that >> typing a `)` which has a matching `(` nearby (which can be found without >> crossing any string/RE boundary) should emit a warning about some >> "unrelated" surrounding entity like the RE in which it is located. > In an unterminated RE, the message will appear for every single > character you type, until the RE is terminated. I'd find it odd if the > `)` was the only character where the message didn't appear :) I agree that `)` should be no different. And while as a user I find such messages more annoying than helpful (I much prefer to be warned by some font-lock highlighting (e.g. by "bleeding" past what I expected to be the end) or something like a tooltip), I'm OK with the current behavior. I just don't think that not emitting the message should trigger a test failure. > In Perl, almost any non-whitespace character can be used as > a delimiter, including letters, quotes, comment starters, and colons. Yes, I remember that from when I wrote the corresponding syntax-propertize code for `perl-mode` ;-) > I see now that at least this test should be skipped in Perl mode, which > I failed to do. Again. Sorry for that. No problem. BTW, I just noticed that if I revert your patch to cperl-mode.el, the test still succeeds :-( > In general, handling of REs with non-standard delimiters is one of the > areas where Perl mode has significant deficiencies. Hmm... I thought I had managed to make it cover most cases back then. I'd be interested to know which cases I missed (or which new cases were introduced since then: after all it was quite some years ago). In any case, along the way I decided that this bug was in large part to blame on blink-matching-open because it calls `syntax-propertize` from within narrowing. So I changed it which made your `cperl-mode` patch unnecessary. I also tweaked your test so that it does fail in the old code (and passes with the new code) and so it also works in `perl-mode` (except for the second part which I kept but which would fail in `perl-mode`). The patch I installed can be found below. Stefan diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 94f42cb2bc..ebbea6bed9 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -3225,13 +3225,6 @@ cperl-forward-re (and cperl-brace-recursing (or (eq ostart ?\{) (eq starter ?\{))) - ;; If we are at the end of a narrowed buffer, then a - ;; scan error should not be reported to the user. - ;; This situation actually happens when a closing - ;; paren is entered in a regular expression. - ;; Reported in Bug#37127. - (and (eobp) (buffer-narrowed-p) - (equal (car bb) 'scan-error)) (message "End of `%s%s%c ... %c' string/RE not found: %s" argument diff --git a/lisp/simple.el b/lisp/simple.el index 2e40e3261c..b1b9c88b32 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8014,6 +8014,7 @@ blink-matching-open (blinkpos (save-excursion (save-restriction + (syntax-propertize (point)) (if blink-matching-paren-distance (narrow-to-region (max (minibuffer-prompt-end) ;(point-min) unless minibuf. @@ -8024,7 +8025,7 @@ blink-matching-open (not blink-matching-paren-dont-ignore-comments)))) (condition-case () (progn - (syntax-propertize (point)) + ;; (syntax-propertize (point)) ;?? (forward-sexp -1) ;; backward-sexp skips backward over prefix chars, ;; so move back to the matching paren. diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index 75010f7d0f..33ebcccde8 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -224,28 +224,33 @@ cperl-bug37127 "Verify that closing a paren in a regex goes without a message. Also check that the message is issued if the regex terminator is missing." - (let (collected-messages) - ;; Part one: Regex is ok, no messages - (ert-with-message-capture collected-messages - (with-temp-buffer - (insert "$_ =~ /(./;") - (cperl-mode) - (goto-char (point-min)) - (search-forward ".") - (let ((last-command-event ?\))) - (cperl-electric-rparen 1) - (cperl-find-pods-heres (point-min) (point-max) t))) - (should (string-equal collected-messages ""))) - ;; part two: Regex terminator missing -> message + ;; Part one: Regex is ok, no messages + (ert-with-message-capture collected-messages + (with-temp-buffer + (insert "$_ =~ /(./;") + (funcall cperl-test-mode) + (goto-char (point-min)) + (search-forward ".") + (let ((last-command-event ?\)) + ;; Don't emit "Matches ..." even if not visible (e.g. in batch). + (blink-matching-paren 'jump-offscreen)) + (self-insert-command 1) + (blink-matching-open)) + (syntax-propertize (point-max))) + (should (string-equal collected-messages ""))) + ;; part two: Regex terminator missing -> message + (when (eq cperl-test-mode #'cperl-mode) + ;; This test is only run in `cperl-mode' because only cperl-mode + ;; emits a message to warn about such unclosed REs. (ert-with-message-capture collected-messages (with-temp-buffer (insert "$_ =~ /(..;") (goto-char (point-min)) - (cperl-mode) + (funcall cperl-test-mode) (search-forward ".") (let ((last-command-event ?\))) - (cperl-electric-rparen 1) - (cperl-find-pods-heres (point-min) (point-max) t))) + (self-insert-command 1)) + (syntax-propertize (point-max))) (should (string-match "^End of .* string/RE" collected-messages)))))