From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Harald =?UTF-8?Q?J=C3=B6rg?= Newsgroups: gmane.emacs.bugs Subject: bug#42168: 26.1; cperl-mode: Bad interpretation of $a++ / $b Date: Thu, 2 Jul 2020 20:19:21 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7ECC07DA57C47CBF210F3B2F" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22363"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 To: 42168@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 02 21:37:11 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 1jr51D-0005is-4s for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jul 2020 21:37:11 +0200 Original-Received: from localhost ([::1]:44546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jr51C-00059d-4q for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jul 2020 15:37:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jr514-00059B-MB for bug-gnu-emacs@gnu.org; Thu, 02 Jul 2020 15:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jr514-0000GZ-D0 for bug-gnu-emacs@gnu.org; Thu, 02 Jul 2020 15:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jr514-0007yF-9d for bug-gnu-emacs@gnu.org; Thu, 02 Jul 2020 15:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Harald =?UTF-8?Q?J=C3=B6rg?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Jul 2020 19:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 42168 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.159371861330617 (code B ref -1); Thu, 02 Jul 2020 19:37:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Jul 2020 19:36:53 +0000 Original-Received: from localhost ([127.0.0.1]:55687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jr50u-0007xh-LC for submit@debbugs.gnu.org; Thu, 02 Jul 2020 15:36:53 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:52478) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jr3o4-00062x-VD for submit@debbugs.gnu.org; Thu, 02 Jul 2020 14:19:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jr3o4-0003KX-Q5 for bug-gnu-emacs@gnu.org; Thu, 02 Jul 2020 14:19:32 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jr3ny-0007Hr-Ka for bug-gnu-emacs@gnu.org; Thu, 02 Jul 2020 14:19:32 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 22F39160061 for ; Thu, 2 Jul 2020 20:19:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1593713963; bh=29I2E1dWMYgLl91oZJM//4WnhTgpzO5OcoMRFcqM8cQ=; h=To:Subject:From:Autocrypt:Date:From; b=oAaUpSSMZo4UZ26cc2ZCJahZ8OmriX2FUA5iujIgwTXKgxuLorepWKLroilOVaXux 6r1qEInLQeT3trsO068EOjxp71c2YbjYJ7kXUtOMTWHQu8haEfnIQCttsM47iTEFvO 3GK6UX94rwJDR1g7PltQXFPmpJn7gB/2TSP5AdZn7RYWNb7yDrSyEQNGcwl2IHViqx hXEO5Hfbpb3Qs1Z8cFhxjwwOtmhgsuFb6hp6lM20uCZKdsXQM4c2sF61P5ziqC35or VqHrl59BntQDVKYelJBFFhKf7RNgIdTM0HwFe/ueESw7UcNXJwA4WgJYjjNStg9rGx jQTsHXM4glYLw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49yRFQ3fq9z6tmN for ; Thu, 2 Jul 2020 20:19:22 +0200 (CEST) Autocrypt: addr=haj@posteo.de; keydata= mQINBF0DVrIBEAC7TRlIilBg/5Dx7R2rV4FBDEavbyMT2cS2wWyksh7JA8e17LNmTdakf+Bm u6C2m6+frolteYRlkreoyAg0fj/5tDw/s5dJDw3tM0b+m/pj2HcwTSRpQSEy5lBiCg11E6Mt F9UngCfkGtJzu8PBWXc1RDQVBwRn5MZbpMZZatE8NOq9AA3Yg6sY11Ez3xIvYU2R7a4OSxmc RJV2+dhdQ4oOTBIGQ2urQSU81kyRtkx+/Yh8WefMrk9nF3nzYziLS53euCAXyzklwYmD6Li3 XSu7wYp5fISky9DK6DPFK7h4RXEL4GFAhy31ehrVnNTcGRohM1Dm9BV9dwXkwlaeT3q0X+nE SXVqPDHtv748bXNIg2WVCZ0WgShcA46XVlSE9Fm+w0HI/1m1L4BaMmQ7gyK5dEchbhxohkk0 AqC3hEJ4ULRidrsCoCWGMFKiOIb9rjeC00vhrUkVJDkPWEGLXjhnRQykb6cESko0rPrSDLqX 9YqaNQ6KO9Un6uogE7YnXYg35EXJ8ORdX257IbXNbFVpgM8FFsl48WV3Pl9WNdADhnnOrz3O wzyK58i/BTsnjVX8ghbWkQcPQ2Kprt+4YR2trEi7TM5Uqzzrg0vp7Oe/9KZBxdxCE67thV7h ElW3CHb4q6o31b4cFmLbtFesSy+hnUU4UymgHgi/hvhxioBxIQARAQABtBxIYXJhbGQgSsO2 cmcgPGhhakBwb3N0ZW8uZGU+iQJOBBMBCAA4FiEEIpYEZLQynxF8Q17KN4XzzzqAcpsFAl0D VrICGwMFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQN Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=haj@posteo.de; helo=mout01.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/02 14:19:23 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Thu, 02 Jul 2020 15:36:51 -0400 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:182645 Archived-At: This is a multi-part message in MIME format. --------------7ECC07DA57C47CBF210F3B2F Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit How to reproduce: In a buffer, activate cperl-mode (M-x cperl-mode), then enter: $a++ / $b; This is supposed to be a division. However, cperl-mode interprets the slash as the start of a regular expression. Accordingly, the following text is displayed with the wrong face, and also cperl-mode might complain that it can't find the end of the regular expression. Emacs does not crash. Attached: A patch which fixes the issue for $a++ and $a--, and also includes a test to verify that the very similar text "$a+ / $b" is still correctly interpreted as a regular expression. Disclaimer: I'm rather new to elisp and even newer to ERT. Cheers, haj --------------7ECC07DA57C47CBF210F3B2F Content-Type: text/x-patch; charset=UTF-8; name="postincrement.diff" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="postincrement.diff" diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index cdbb59a5ad..2ba6921643 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -3978,6 +3978,9 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', (and (eq (preceding-char) ?.) (eq (char-after (- (point) 2)) ?.)) (bobp)) + ;; { $a++ / $b } doesn't start a regex, nor does $a-- + (not (and (memq (preceding-char) '(?+ ?-)) + (eq (preceding-char) (char-before (1- (point)))))) ;; m|blah| ? foo : bar; (not (and (eq c ?\?) diff --git a/test/lisp/progmodes/cperl-mode/cperl-fontification-tests.el b/test/lisp/progmodes/cperl-mode/cperl-fontification-tests.el new file mode 100644 index 0000000000..4148db036c --- /dev/null +++ b/test/lisp/progmodes/cperl-mode/cperl-fontification-tests.el @@ -0,0 +1,55 @@ +;;; cperl-fontification-tests.el --- Test fontification in cperl-mode -*- lexical-binding: t -*- + +;; Copyright (C) 2020-2020 ...to be decided ... + +;; Author: Harald Jörg +;; Maintainer: Harald Jörg +;; Keywords: internal +;; Human-Keywords: internal +;; Homepage: https://github.com/HaraldJoerg/cperl-mode + +;;; Commentary: + +;; This is a collection of Tests for the fontification of CPerl-mode. +;; The primary target is to verify that the refactoring we're doing +;; right now (May 2020 - ...) doesn't change any behavior, or does the +;; right thing in cases where new fontification rules are enabled. + +;; Run these tests interactively: +;; (ert-run-tests-interactively '(tag :fontification)) + +(defun cperl-test-face (text regexp) + "Returns the face of the first character matched by REGEXP in TEXT." + (interactive) + (with-temp-buffer + (let ((cperl-hairy nil) + (cperl-font-lock nil)) ;; Does this matter? + (insert text) + (cperl-mode) + (font-lock-fontify-buffer) + (goto-char (point-min)) + (re-search-forward regexp) + (message "%s" (match-string 0)) + (get-text-property (match-beginning 0) 'face)))) + +(ert-deftest jrockway-issue-45 () + "Verify that '/' is a division after ++ or --, not a regexp. +Reported in https://github.com/jrockway/cperl-mode/issues/45. +If seen as regular expression, then the slash is displayed using +font-lock-constant-face. If seen as a division, then it doesn't +have a face property." + :tags '(:fontification) + ;; The next two Perl expressions have divisions. Perl "punctuation" + ;; operators don't get a face. The comment at the end of line + ;; prevents cperl-mode from tripping over "End of ‘/ ... /’ + ;; string/RE not found" if it gets it wrong + (let ((code "{ $a++ / $b } # /")) + (should (equal (cperl-test-face code "/" ) nil))) + (let ((code "{ $a-- / $b } # /")) + (should (equal (cperl-test-face code "/" ) nil))) + ;; The next two Perl expressions have regular expressions. The + ;; delimiter of a RE is fontified with font-lock-constant-face. + (let ((code "{ $a+ / $b } # /")) + (should (equal (cperl-test-face code "/" ) font-lock-constant-face))) + (let ((code "{ $a- / $b } # /")) + (should (equal (cperl-test-face code "/" ) font-lock-constant-face)))) --------------7ECC07DA57C47CBF210F3B2F--