]> git.eshelyaron.com Git - emacs.git/commitdiff
perl-mode and cperl-mode: Recognize regex after "return"
authorHarald Jörg <haj@posteo.de>
Mon, 16 Nov 2020 23:20:26 +0000 (00:20 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 16 Nov 2020 23:20:26 +0000 (00:20 +0100)
* 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
lisp/progmodes/perl-mode.el
test/lisp/progmodes/cperl-mode-resources/cperl-bug-26850.pl [new file with mode: 0644]
test/lisp/progmodes/cperl-mode-tests.el

index a42ace105aa60e1c96b5938192eed5e9b20cc4a3..0dc45515d410958b3b52fd15f6f3834e2a74f959 100644 (file)
@@ -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))
index 7265aeee45ddc23d08b92c491c38f55aa4cc03a8..bb19436cdad81b62ac8308911f3474c9afe81c52 100644 (file)
 (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 (file)
index 0000000..a02ea29
--- /dev/null
@@ -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 </
+}
index a0dd391840f752c44da96bb9c40626fb8c1384d2..896160bb88359a2119a135f13e9eae019c7b901d 100644 (file)
@@ -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."