emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master f5f9e10: perl-mode and cperl-mode: Recognize regex after "return"


From: Lars Ingebrigtsen
Subject: master f5f9e10: perl-mode and cperl-mode: Recognize regex after "return"
Date: Mon, 16 Nov 2020 18:21:01 -0500 (EST)

branch: master
commit f5f9e100972598b1bb9cea4c0445777db2e1131e
Author: Harald Jörg <haj@posteo.de>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    perl-mode and cperl-mode: Recognize regex after "return"
    
    * lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Add
    "return" to the keywords which start a regex.
    
    * lisp/progmodes/perl-mode.el (defconst): Add "return" to
    'perl--syntax-exp-intro-keywords' (Bug#26850).
    
    * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-28650):
    New test (bug#26850).
---
 lisp/progmodes/cperl-mode.el                             |  2 +-
 lisp/progmodes/perl-mode.el                              |  2 +-
 .../progmodes/cperl-mode-resources/cperl-bug-26850.pl    | 16 ++++++++++++++++
 test/lisp/progmodes/cperl-mode-tests.el                  | 15 +++++++++++++++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index a42ace1..0dc4551 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3959,7 +3959,7 @@ the sections using `cperl-pod-head-face', 
`cperl-pod-face',
                                              (not (memq (preceding-char)
                                                         '(?$ ?@ ?& ?%)))
                                              (looking-at
-                                              
"\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\|say\\)\\>")))))
+                                              
"\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\|say\\|return\\)\\>")))))
                                    (and (eq (preceding-char) ?.)
                                         (eq (char-after (- (point) 2)) ?.))
                                    (bobp))
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 7265aee..bb19436 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -209,7 +209,7 @@
 (eval-and-compile
   (defconst perl--syntax-exp-intro-keywords
     '("split" "if" "unless" "until" "while" "print"
-      "grep" "map" "not" "or" "and" "for" "foreach"))
+      "grep" "map" "not" "or" "and" "for" "foreach" "return"))
 
   (defconst perl--syntax-exp-intro-regexp
     (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)"
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-26850.pl 
b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-26850.pl
new file mode 100644
index 0000000..a02ea29
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-26850.pl
@@ -0,0 +1,16 @@
+sub interesting {
+    $_ = shift;
+    return
+         />Today is .+\'s birthday\.</
+      || / like[ds]? your post in </
+      || /like[ds] your new subscription\. </
+      || / likes? that you're interested in </
+      || /> likes? your comment: /
+      || /&amp;birthdays=.*birthdays?\.<\/a>/;
+}
+
+sub boring {
+    return
+         / likes? your post in </
+      || / likes? that you're interested in </
+}
diff --git a/test/lisp/progmodes/cperl-mode-tests.el 
b/test/lisp/progmodes/cperl-mode-tests.el
index a0dd391..896160bb 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -228,6 +228,21 @@ documentation it does the right thing anyway."
      (cperl-indent-command)
      (forward-line 1))))
 
+(ert-deftest cperl-test-bug-28650 ()
+  "Verify that regular expressions are recognized after 'return'.
+The test uses the syntax property \"inside a string\" for the
+text in regular expressions, which is non-nil for both cperl-mode
+and perl-mode."
+  (with-temp-buffer
+    (insert-file-contents (ert-resource-file "cperl-bug-26850.pl"))
+    (goto-char (point-min))
+    (re-search-forward "sub interesting {[^}]*}")
+    (should-not (equal (nth 3 (cperl-test-ppss (match-string 0) "Today"))
+                       nil))
+    (re-search-forward "sub boring {[^}]*}")
+    (should-not (equal (nth 3 (cperl-test-ppss (match-string 0) "likes\\?"))
+                       nil))))
+
 (ert-deftest cperl-test-bug-30393 ()
   "Verify that indentation is not disturbed by an open paren in col 0.
 Perl is not Lisp: An open paren in column 0 does not start a function."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]