* bug#26850: perl-mode and cperl-mode: Recognize regex after "return"
2017-05-08 22:50 bug#26850: perl-mode: apostrophes trigger color change in wrong situation 積丹尼 Dan Jacobson
@ 2020-11-16 22:13 ` Harald Jörg
2020-11-16 23:24 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Harald Jörg @ 2020-11-16 22:13 UTC (permalink / raw)
To: 26850
[-- Attachment #1: Type: text/plain, Size: 935 bytes --]
merge 26850 26745
thanks
I don't know whether I have the authority to merge bugs, but they
clearly are the same issue, so I'll just give it a try.
The apostrophe, as mentioned in the subject of Bug#26850, is irrelevant:
The actual problem in both reports is the failure to recognize a regular
expression after the keyword "return". The apostrophe just changes the
interpretation of the text which follows.
There are several workarounds: You could, for example, explicitly write
the regexes as $_ =~ /.../; ... but of course, why would you do that,
since $_ is superfluous. Alternatively, you could just omit the
"return", which is also superfluous in the examples provided.
Nevertheless, the patch fixes the issue, which happens in both perl-mode
and cperl-mode. I guess that in neither mode the list of keywords which
precede a regex is actually complete, but "return" is a use case
relevant enough to be fixed.
--
Cheers,
haj
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Recognize regex after "return" --]
[-- Type: text/x-diff, Size: 4039 bytes --]
From bab7a88cb14d9b464f2d976094f46eae46500c0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Mon, 16 Nov 2020 22:47:31 +0100
Subject: [PATCH] ; cperl-mode, perl-mode: Recognize a regular expression after
"return"
* lisp/progmodes/perl-mode.el (defconst): Add "return" to
'perl--syntax-exp-intro-keywords' (Bug#26850).
* lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Add
"return" to the keywords which start a regex.
* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-28650):
New test.
---
lisp/progmodes/cperl-mode.el | 2 +-
lisp/progmodes/perl-mode.el | 2 +-
.../cperl-mode-resources/cperl-bug-26850.pl | 16 ++++++++++++++++
test/lisp/progmodes/cperl-mode-tests.el | 15 +++++++++++++++
4 files changed, 33 insertions(+), 2 deletions(-)
create mode 100644 test/lisp/progmodes/cperl-mode-resources/cperl-bug-26850.pl
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index a42ace105a..0dc45515d4 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3959,7 +3959,7 @@ cperl-find-pods-heres
(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 7265aeee45..bb19436cda 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -209,7 +209,7 @@ perl-quote-like-pairs
(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 0000000000..a02ea29fe9
--- /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: /
+ || /&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 a0dd391840..896160bb88 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -228,6 +228,21 @@ cperl-test-bug-19709
(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."
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread