From 034a78c419f463e81c254de08040e1a94feb1a88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Harald=20J=C3=B6rg?= Date: Thu, 25 Jul 2024 22:00:10 +0200 Subject: [PATCH] ; cperl-mode.el: Fix fontification of flip-flop (Bug#72296) * 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 | 2 +- test/lisp/progmodes/cperl-mode-tests.el | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index cd5669ad0ce..94a84bb9bb4 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -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 diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index 02230049596..7a6e0b3b64a 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -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"))) -- 2.39.5