Subject: Re: bug#17174: 24.3; perl-mode highlight: unrecognized perl var $' starts a string
From: Stefan Monnier <[email-masked]>
To: "G.raud" <[email-masked]>
Cc: [email-masked]
Date: Wed, 02 Apr 2014 20:42:46 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> $ cat <<"EOF" >test.pl
> #!/usr/bin/perl
> $_ = 'truc'; /ru/;
> print "$'\n"; # this is highlighted as expected
> print $'; # this starts a string that continues to the next line
> print "\n";
> EOF
> $ emacs24 -Q test.pl

Thanks for the clear test case.  I installed the patch below in
emacs-24, which should fix it.

        Stefan

--- lisp/progmodes/perl-mode.el	2014-04-02 19:50:05 +0000
+++ lisp/progmodes/perl-mode.el	2014-04-03 00:37:11 +0000
@@ -250,7 +250,11 @@
       ;; Catch ${ so that ${var} doesn't screw up indentation.
       ;; This also catches $' to handle 'foo$', although it should really
       ;; check that it occurs inside a '..' string.
-      ("\\(\\$\\)[{']" (1 ". p"))
+      ("\\(\\$\\)[{']" (1 (unless (and (eq ?\' (char-after (match-end 1)))
+                                       (save-excursion
+                                         (not (nth 3 (syntax-ppss
+                                                      (match-beginning 0))))))
+                            (string-to-syntax ". p"))))
       ;; Handle funny names like $DB'stop.
       ("\\$ ?{?^?[_[:alpha:]][_[:alnum:]]*\\('\\)[_[:alpha:]]" (1 "_"))
       ;; format statements