From: "Harald Jörg" <haj@posteo.de>
To: 42168@debbugs.gnu.org
Subject: bug#42168: 26.1; cperl-mode: Bad interpretation of $a++ / $b
Date: Thu, 2 Jul 2020 20:19:21 +0200 [thread overview]
Message-ID: <da546d18-f862-ba5f-aa0d-22e8fa8e9581@posteo.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 651 bytes --]
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
[-- Attachment #2: postincrement.diff --]
[-- Type: text/x-patch, Size: 3201 bytes --]
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 <haj@posteo.de>
+;; 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))))
next reply other threads:[~2020-07-02 18:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 18:19 Harald Jörg [this message]
2020-07-11 9:53 ` bug#42168: 26.1; cperl-mode: Bad interpretation of $a++ / $b Eli Zaretskii
2020-08-13 0:40 ` Stefan Kangas
2020-08-13 7:30 ` Harald Jörg
2020-08-13 7:55 ` Stefan Kangas
2020-08-13 8:17 ` Stefan Kangas
2020-08-13 20:40 ` Harald Jörg
2020-08-14 9:06 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=da546d18-f862-ba5f-aa0d-22e8fa8e9581@posteo.de \
--to=haj@posteo.de \
--cc=42168@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).