unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#26850: perl-mode: apostrophes trigger color change in wrong situation
@ 2017-05-08 22:50 積丹尼 Dan Jacobson
  2020-11-16 22:13 ` bug#26850: perl-mode and cperl-mode: Recognize regex after "return" Harald Jörg
  0 siblings, 1 reply; 3+ messages in thread
From: 積丹尼 Dan Jacobson @ 2017-05-08 22:50 UTC (permalink / raw)
  To: 26850

Apostrophes trigger color change in wrong situation:

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>/;
}





^ permalink raw reply	[flat|nested] 3+ messages in thread

* 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: /
+      || /&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 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

* bug#26850: perl-mode and cperl-mode: Recognize regex after "return"
  2020-11-16 22:13 ` bug#26850: perl-mode and cperl-mode: Recognize regex after "return" Harald Jörg
@ 2020-11-16 23:24   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2020-11-16 23:24 UTC (permalink / raw)
  To: Harald Jörg; +Cc: 26850

haj@posteo.de (Harald Jörg) writes:

> 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.

Oh, sure, I think everybody can.  Hm...  but it doesn't seem to have
gone through in this case?  When the statuses of the bugs involved
aren't the same, you have to use "forcemerge" to make it actually
happened; I did that now.

> 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.

Thanks for the patch; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-16 23:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 22:50 bug#26850: perl-mode: apostrophes trigger color change in wrong situation 積丹尼 Dan Jacobson
2020-11-16 22:13 ` bug#26850: perl-mode and cperl-mode: Recognize regex after "return" Harald Jörg
2020-11-16 23:24   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).