]> git.eshelyaron.com Git - emacs.git/commitdiff
; cperl-mode.el: Fix fontification of flip-flop (Bug#72296)
authorHarald Jörg <haj@posteo.de>
Thu, 25 Jul 2024 20:00:10 +0000 (22:00 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 27 Jul 2024 12:03:06 +0000 (14:03 +0200)
* lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Prevent a
movement of point from bleeding into a following clause.
* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-72296):
Add a test for the flip-flop operator with code from the report.

(cherry picked from commit c27055a938aadec81e4603d00e7d0997c4d2579f)

lisp/progmodes/cperl-mode.el
test/lisp/progmodes/cperl-mode-tests.el

index cd5669ad0ce386b657fd10b98310dfa605f86438..94a84bb9bb4bf762d9b6aae4779e3e9500903ce1 100644 (file)
@@ -4651,7 +4651,7 @@ recursive calls in starting lines of here-documents."
                                    (and (eq (preceding-char) ?\})
                                         (cperl-after-block-p (point-min)))
                                    (and (eq (char-syntax (preceding-char)) ?w)
-                                        (progn
+                                        (save-excursion
                                           (forward-sexp -1)
                                            ;; After these keywords `/'
                                            ;; starts a RE.  One should
index 02230049596b994c697c3e4028de1415267486c4..7a6e0b3b64a0faa77b6a852ff515baf1c259ca74 100644 (file)
@@ -1573,6 +1573,23 @@ not appropriate."
         (should (equal (get-text-property (point) 'face)
                        font-lock-string-face))))))
 
+(ert-deftest cperl-test-bug-72296 ()
+  "Verify that the perl modes correctly handle the flip-flop operator.
+Two successive dots are an operator.  A slash immediately following them
+starts a regular expression, if there's another term between the dots
+and the slash, then we have a division."
+  :tags '(:fontification)
+  ;; Code from the bug report.  The slash is a division.  The following
+  ;; number is not a string.
+  (let ((code "for (2..$n/2) { ...; }"))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) nil)))
+  ;; This is what the test for two successive dots wants to catch: The
+  ;; flip-flop operator.  Here, the number is part of a regexp, seen as
+  ;; a string.
+  (let ((code "for (2../2/) { ...; }"))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) 9)))
+  )
+
 (ert-deftest test-indentation ()
   (ert-test-erts-file (ert-resource-file "cperl-indents.erts")))