unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefankangas@gmail.com>
To: "Harald Jörg" <haj@posteo.de>, 42168@debbugs.gnu.org
Subject: bug#42168: 26.1; cperl-mode: Bad interpretation of $a++ / $b
Date: Fri, 14 Aug 2020 02:06:46 -0700	[thread overview]
Message-ID: <CADwFkm=1caCwxOd2p_bHTfYqLWGtea1gP_Uw9AUarKPjX4rBxA@mail.gmail.com> (raw)
In-Reply-To: <d4507d95-f852-8aa0-500a-a9ef614c6a1e@posteo.de>

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

close 42168 28.1
thanks

Hi Harald,

Harald Jörg <haj@posteo.de> writes:

> Thank you for your thorough review.  I'm rather new to Emacs Lisp, and
> also to the Emacs development workflows, so this is highly
> appreciated.

Happy to help, we've all been there at one point.

>> lisp/progmodes/cperl-mode-tests.el
>
> I guess this was meant to read test/lisp/progmodes/cperl-mode-tests.el.

Indeed.

> Also, I've added a ChangeLog-style attachment, as suggested by Lars
> Ingebrigtsen in his comment to Bug#42355.

Thanks.

Your diff looks good, so I've installed the attached patch with some
minor fixes, and I'm closing the bug with this message.

Next time, could you please add the ChangeLog entry to the git commit
message and send the result of `git format-patch -1` as an attachment?
That saves time when installing the change.  Please see the attached for
an example, and you can read more in CONTRIBUTE in emacs.git.  It is
also useful to consult the git log for more examples.

Welcome again as an Emacs contributor!

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-cperl-mode-Highlight-a-b-correctly.patch --]
[-- Type: text/x-diff, Size: 3297 bytes --]

From f3ff51288fa0370a9ea33312b188565e4f2b595e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Fri, 14 Aug 2020 10:01:30 +0200
Subject: [PATCH] cperl-mode: Highlight '{$a++ / $b}' correctly

* lisp/progmodes/cperl-mode.el (cperl-find-pods-heres):
Recognize {$a++ / $b} correctly as division.  (Bug#42168)
* test/lisp/progmodes/cperl-mode-tests.el: New file with test
verifying the fix.
---
 lisp/progmodes/cperl-mode.el            |  3 ++
 test/lisp/progmodes/cperl-mode-tests.el | 50 +++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 test/lisp/progmodes/cperl-mode-tests.el

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 6122caf518..2d2713a36a 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3979,6 +3979,9 @@ cperl-find-pods-heres
 				    (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-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
new file mode 100644
index 0000000000..f39f1ba658
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -0,0 +1,50 @@
+;;; cperl-mode-tests --- Test for cperl-mode  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Harald Jörg <haj@posteo.de>
+;; Maintainer: Harald Jörg
+;; Keywords: internal
+;; Homepage: https://github.com/HaraldJoerg/cperl-mode
+
+;;; Commentary:
+
+;; This is a collection of tests for the fontification of CPerl-mode.
+
+;; Run these tests interactively:
+;; (ert-run-tests-interactively '(tag :fontification))
+
+;;; Code:
+
+(defun cperl-test-face (text regexp)
+  "Returns the face of the first character matched by REGEXP in TEXT."
+  (interactive)
+  (with-temp-buffer
+      (insert text)
+      (cperl-mode)
+      (font-lock-ensure (point-min) (point-max))
+      (goto-char (point-min))
+      (re-search-forward regexp)
+      (get-text-property (match-beginning 0) 'face)))
+
+(ert-deftest cperl-mode-test-bug-42168 ()
+  "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.
+  (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))))
+
+;;; cperl-mode-tests.el ends here
-- 
2.28.0


      reply	other threads:[~2020-08-14  9:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 18:19 bug#42168: 26.1; cperl-mode: Bad interpretation of $a++ / $b Harald Jörg
2020-07-11  9:53 ` 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 [this message]

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='CADwFkm=1caCwxOd2p_bHTfYqLWGtea1gP_Uw9AUarKPjX4rBxA@mail.gmail.com' \
    --to=stefankangas@gmail.com \
    --cc=42168@debbugs.gnu.org \
    --cc=haj@posteo.de \
    /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).