From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Newsgroups: gmane.emacs.bugs Subject: bug#47112: Don't interpret '_' as word boundary [PATCH] Date: Sat, 13 Mar 2021 01:27:16 +0100 Message-ID: <87a6r7dhjv.fsf@hajtower> References: 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="1724"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: 47112@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 13 01:28:09 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 1lKs8X-0000JS-F2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Mar 2021 01:28:09 +0100 Original-Received: from localhost ([::1]:49446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKs8W-0005NZ-Hv for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Mar 2021 19:28:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKs8Q-0005NQ-10 for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 19:28:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47145) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lKs8P-0003fF-Pa for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 19:28:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lKs8P-00011M-Ln for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 19:28:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Mar 2021 00:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47112 X-GNU-PR-Package: emacs Original-Received: via spool by 47112-submit@debbugs.gnu.org id=B47112.16155952473876 (code B ref 47112); Sat, 13 Mar 2021 00:28:01 +0000 Original-Received: (at 47112) by debbugs.gnu.org; 13 Mar 2021 00:27:27 +0000 Original-Received: from localhost ([127.0.0.1]:58691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKs7r-00010S-5E for submit@debbugs.gnu.org; Fri, 12 Mar 2021 19:27:27 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:41171) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKs7o-00010B-9O for 47112@debbugs.gnu.org; Fri, 12 Mar 2021 19:27:25 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 711682400FB for <47112@debbugs.gnu.org>; Sat, 13 Mar 2021 01:27:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1615595237; bh=H2zhqhJfWiD4I7zxUegMjIAhIBu4J1Xwvq+se3t7uF0=; h=From:To:Subject:Date:From; b=YSoJr2fLMRptjCi/Rdeb/6b0vJg1uV/W4lRV/Bnjdzlu2snlYW6BWcVbKoLD9xAvd xzPtPdCSwHcNM2JEmJtMZvT1WkrHQVtNR/mt7QPyNt05+u1WKCajdqqJ3nOxhTliU7 XRGXHWB1l8ZZHWrjU5bjBIoPk27h0ho+LJq9nDh10Jl8++ytVkitFX6ZeXShVfFRb6 RyBMG+qiNIvxcUXsYwXavtCRtYsBM/v3ExjNP26qhxzKS+FsyrJZf6WnFFuzwcvPfe Ao8NfjGPv7eIMfKtm6NqyrUA+HdecEFcnPcSfYBBGMjZqcj836hpFcgin8joOJQBRG WeNbj4OretWHQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Dy3R85xR1z9rxK for <47112@debbugs.gnu.org>; Sat, 13 Mar 2021 01:27:16 +0100 (CET) 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:202215 Archived-At: --=-=-= Content-Type: text/plain This is a border case which affects several dark corners in CPerl mode. Per default, the '_' character is not a word character, but a symbol character in Perl. The bogus regexp in `cperl-find-pods-heres' checks the quote-like things for "ending in a word boundary". Per default there _is_ a word boundary between 'y' and '_', and from here it goes downward. It is wrong to change the search pattern to "symbol boundary" instead of "word boundary": The ':' character is also a symbol in CPerl mode and the regexp would then miss q:string: constructs. The patch is a small change to eliminate the false detection of quote constructs by yet another special case, plus some tests. -- Cheers, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-cperl-mode-Don-t-interpret-y_-as-start-of-y-function.patch Content-Description: cperl-mode: No word boundary in "y_" >From c68e15dc4bfceb6e084645f987fc401edb87f7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Sat, 13 Mar 2021 00:57:30 +0100 Subject: [PATCH] ; cperl-mode: Don't interpret y_ as start of y// function. * lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Avoid treating underscores as word-terminators. * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-47112): Test case for that bug. --- lisp/progmodes/cperl-mode.el | 33 ++++++++++++++----------- test/lisp/progmodes/cperl-mode-tests.el | 26 +++++++++++++++++++ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 734797b3ad..7e7327d986 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -3926,21 +3926,24 @@ cperl-find-pods-heres bb (char-after (1- (match-beginning b1))) ; tmp holder ;; bb == "Not a stringy" bb (if (eq b1 10) ; user variables/whatever - (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y) - (cond ((eq bb ?-) (eq c ?s)) ; -s file test - ((eq bb ?\:) ; $opt::s - (eq (char-after - (- (match-beginning b1) 2)) - ?\:)) - ((eq bb ?\>) ; $foo->s - (eq (char-after - (- (match-beginning b1) 2)) - ?\-)) - ((eq bb ?\&) - (not (eq (char-after ; &&m/blah/ - (- (match-beginning b1) 2)) - ?\&))) - (t t))) + (or + ; false positive: "y_" has no word boundary + (save-match-data (looking-at "_")) + (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y) + (cond ((eq bb ?-) (eq c ?s)) ; -s file test + ((eq bb ?\:) ; $opt::s + (eq (char-after + (- (match-beginning b1) 2)) + ?\:)) + ((eq bb ?\>) ; $foo->s + (eq (char-after + (- (match-beginning b1) 2)) + ?\-)) + ((eq bb ?\&) + (not (eq (char-after ; &&m/blah/ + (- (match-beginning b1) 2)) + ?\&))) + (t t)))) ;; or <$file> (and (eq c ?\<) ;; Do not stringify , <$fh> : diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index 61e4ece49b..f0e15022d0 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -447,4 +447,30 @@ cperl-test-bug-45255 ;; The yadda-yadda operator should not be in a string. (should (equal (nth 8 (cperl-test-ppss code "\\.")) nil)))) +(ert-deftest cperl-test-bug-47112 () + "Check that in a bareword starting with a quote-like operator +followed by an underscore is not interpreted as that quote-like +operator. Also check that a quote-like operator followed by a +colon (which is, like ?_, a symbol in CPerl mode) _is_ identified +as that quote like operator." + (with-temp-buffer + (funcall cperl-test-mode) + (insert "sub y_max { q:bar:; y _bar_foo_; }") + (goto-char (point-min)) + (cperl-update-syntaxification (point-max)) + (font-lock-fontify-buffer) + (search-forward "max") + (should (equal (get-text-property (match-beginning 0) 'face) + 'font-lock-function-name-face)) + (search-forward "bar") + (should (equal (get-text-property (match-beginning 0) 'face) + 'font-lock-string-face)) + ; perl-mode doesn't highlight + (when (eq cperl-test-mode #'cperl-mode) + (search-forward "_") + (should (equal (get-text-property (match-beginning 0) 'face) + (if (eq cperl-test-mode #'cperl-mode) + 'font-lock-constant-face + font-lock-string-face)))))) + ;;; cperl-mode-tests.el ends here -- 2.20.1 --=-=-=--