summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Jörg <haj@posteo.de>2020-08-14 10:01:30 +0200
committerStefan Kangas <stefankangas@gmail.com>2020-08-14 11:03:47 +0200
commitf3ff51288fa0370a9ea33312b188565e4f2b595e (patch)
treec7779a20c6d805b717c0c469128dbcb12b11eefb
parent32cb84974faac7cecdd82e154f7cae9ac0ee8320 (diff)
downloademacs-f3ff51288fa0370a9ea33312b188565e4f2b595e.tar.gz
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.
-rw-r--r--lisp/progmodes/cperl-mode.el3
-rw-r--r--test/lisp/progmodes/cperl-mode-tests.el50
2 files changed, 53 insertions, 0 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 6122caf5189..2d2713a36ab 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3979,6 +3979,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-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
new file mode 100644
index 00000000000..f39f1ba6580
--- /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