unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#997: perl mode blows "'" etc.
@ 2008-09-18 13:15 jidanni
  2020-02-29  2:58 ` Stefan Kangas
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: jidanni @ 2008-09-18 13:15 UTC (permalink / raw)
  To: bug-gnu-emacs

Perl mode screws up bad with this file. Cperl mode gets it better.
$ perl -c p.pl
p.pl syntax OK
$ cat p.pl
/this is a perl program to demonstrate emacs's wacky color biz/;
/this line is in the wrong color until here'/; #///
/\b.*\bpic(ture)?s\b/;
/this line is in the wrong color/;
#this comment turns back on emacs correct color: \b\b
/this line is in the right color/;
/but not this line until the end\/;/m;
$ emacs -Q p.pl
Anyway, one usually ends up having to stick in special comments with
some / ; ` ' etc. in them lest large tracts of code become the wrong
color. emacs-version "22.2.1"







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

* bug#997: perl mode blows "'" etc.
  2008-09-18 13:15 bug#997: perl mode blows "'" etc jidanni
@ 2020-02-29  2:58 ` Stefan Kangas
  2020-02-29  3:12   ` 積丹尼 Dan Jacobson
  2020-11-17 17:52 ` bug#997: perl-mode: Merging was not quite correct Harald Jörg
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-02-29  2:58 UTC (permalink / raw)
  To: jidanni; +Cc: 997

title 997 Incorrect perl-mode syntax highlighting in some cases (e.g. using "'")
tags 997 confirmed
found 997 28.0.50
thanks

jidanni@jidanni.org writes:

> Perl mode screws up bad with this file. Cperl mode gets it better.
> $ perl -c p.pl
> p.pl syntax OK
> $ cat p.pl
> /this is a perl program to demonstrate emacs's wacky color biz/;
> /this line is in the wrong color until here'/; #///

I can reproduce this on current master (28.0.50).

Open a file like this using perl-mode under emacs -Q to see the
incorrect highlighting:

/correct 'incorrect/;
/incorrect' correct/;

The problem goes away if the file looks like this instead:

$foo =~ /foobar/;
/correct 'incorrect/;
/incorrect 'correct/;

> /\b.*\bpic(ture)?s\b/;
> /this line is in the wrong color/;
> #this comment turns back on emacs correct color: \b\b
> /this line is in the right color/;
> /but not this line until the end\/;/m;

I see some incorrect highlighting in this example too.  Adding the
"$foo =~ /foobar/;" line from above seems to fix it here too.

> $ emacs -Q p.pl
> Anyway, one usually ends up having to stick in special comments with
> some / ; ` ' etc. in them lest large tracts of code become the wrong
> color. emacs-version "22.2.1"

I tried inserting the problematic lines into a larger Perl file, but I
couldn't reproduce the issue.  I'm not sure if that means that the
incorrect coloring only happens when these lines are inserted at the
very beginning of a file.

Best regards,
Stefan Kangas





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

* bug#997: perl mode blows "'" etc.
  2020-02-29  2:58 ` Stefan Kangas
@ 2020-02-29  3:12   ` 積丹尼 Dan Jacobson
  0 siblings, 0 replies; 8+ messages in thread
From: 積丹尼 Dan Jacobson @ 2020-02-29  3:12 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 997

>>>>> "SK" == Stefan Kangas <stefan@marxist.se> writes:
SK> I tried inserting the problematic lines into a larger Perl file, but I
SK> couldn't reproduce the issue.  I'm not sure if that means that the
SK> incorrect coloring only happens when these lines are inserted at the
SK> very beginning of a file.

Well I would just say 'See, reproducible!', and not test further
(e.g., beginning, end, middle of file.)





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

* bug#997: perl-mode: Merging was not quite correct
  2008-09-18 13:15 bug#997: perl mode blows "'" etc jidanni
  2020-02-29  2:58 ` Stefan Kangas
@ 2020-11-17 17:52 ` Harald Jörg
  2020-11-19 16:07   ` Noam Postavsky
  2020-11-19 17:07 ` bug#997: perl-mode: Un-merging an unrelated bug Harald Jörg
  2022-09-19 16:03 ` bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level Mauro Aranda
  3 siblings, 1 reply; 8+ messages in thread
From: Harald Jörg @ 2020-11-17 17:52 UTC (permalink / raw)
  To: 997

unmerge 997
reopen 997
thanks

So that's another attempt to exercise my super powers...

It turns out that 997, which had been merged with 26850, is actually a
different issue, and it is not fixed by the recent patch which
successfully dealt with Bug#26850 and Bug#26745 for Perl mode.
CPerl mode handles the examples correctly.

The issues are all related to each other because they all deal with the
difficulties to distinguish between a slash as a division sign and a
slash as a regex introduction.  The apostrophe "'" is a red herring - it
increases the visibility of the bug, but isn't the root cause.

Right now, Perl mode tries to detect regexes based on what's before
them.  Therefore, 26850 could be fixed by adding "return" to the stuff
which can occur before a regex.  However, the examples in this bug
demonstrate regexes with *nothing* before them: Regular expressions can
start a statement just fine, they have a return value and set some
variables as side effects.

Correctly detecting "nothing" in a regex needs some care.  So I'd like
to treat this as a separate bug which remains open for now.
-- 
Cheers,
haj





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

* bug#997: perl-mode: Merging was not quite correct
  2020-11-17 17:52 ` bug#997: perl-mode: Merging was not quite correct Harald Jörg
@ 2020-11-19 16:07   ` Noam Postavsky
  0 siblings, 0 replies; 8+ messages in thread
From: Noam Postavsky @ 2020-11-19 16:07 UTC (permalink / raw)
  To: Harald Jörg; +Cc: 997

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

> unmerge 997
> reopen 997
> thanks
>
> So that's another attempt to exercise my super powers...

You have to send that text to control@debbugs.gnu.org in order for it to
take effect (generally if you do this as part of a public bug message,
you should use Bcc for that to avoid follow-ups from also going to
control; which is why you don't see that destination address when other
people do it).





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

* bug#997: perl-mode: Un-merging an unrelated bug
  2008-09-18 13:15 bug#997: perl mode blows "'" etc jidanni
  2020-02-29  2:58 ` Stefan Kangas
  2020-11-17 17:52 ` bug#997: perl-mode: Merging was not quite correct Harald Jörg
@ 2020-11-19 17:07 ` Harald Jörg
  2022-09-19 16:03 ` bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level Mauro Aranda
  3 siblings, 0 replies; 8+ messages in thread
From: Harald Jörg @ 2020-11-19 17:07 UTC (permalink / raw)
  To: 997; +Cc: Noam Postavsky

unmerge 997
reopen 997
thanks

See my previous message for an explanation why I want to unmerge, and
Noam Postavsky's clarification (thank you!) why I'm sending this again,
now Bcc'ed to control@debbugs.gnu.org.

One day I'll be familiar enough with these procedures... I hope.
-- 
Cheers,
haj





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

* bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level
  2008-09-18 13:15 bug#997: perl mode blows "'" etc jidanni
                   ` (2 preceding siblings ...)
  2020-11-19 17:07 ` bug#997: perl-mode: Un-merging an unrelated bug Harald Jörg
@ 2022-09-19 16:03 ` Mauro Aranda
  2022-09-19 18:37   ` Lars Ingebrigtsen
  3 siblings, 1 reply; 8+ messages in thread
From: Mauro Aranda @ 2022-09-19 16:03 UTC (permalink / raw)
  To: 997; +Cc: Harald Jörg, jidanni

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

tags 997 patch
quit


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

 > Correctly detecting "nothing" in a regex needs some care.  So I'd like
 > to treat this as a separate bug which remains open for now.

I attach a patch to fix this bug, by detecting that we moved to the
beginning of buffer when searching for something before the "/".

[-- Attachment #2: 0001-perl-mode-is-a-regexp-match-if-there-s-nothing-befor.patch --]
[-- Type: text/x-patch, Size: 2199 bytes --]

From e339176f338d8603c8671d27b3f116ca1b988364 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Mon, 19 Sep 2022 12:58:44 -0300
Subject: [PATCH] perl-mode: / is a regexp match if there's nothing before it

* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function):
A "/" that starts the first statement is a regexp match.  (Bug#997)
* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-997): New
test.
---
 lisp/progmodes/perl-mode.el             |  1 +
 test/lisp/progmodes/cperl-mode-tests.el | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 70cb460568..bd8f4ecd1c 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -280,6 +280,7 @@ perl-syntax-propertize-function
                                       (backward-sexp 1)
                                       (member (buffer-substring (point) end)
                                               perl--syntax-exp-intro-keywords)))
+                               (bobp)
                                (memq (char-before)
                                      '(?? ?: ?. ?, ?\; ?= ?! ?~ ?\( ?\[))))))
                nil ;; A division sign instead of a regexp-match.
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index db3feec93a..66039d6fc7 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -723,6 +723,18 @@ cperl-test-imenu-index
 
 ;;; Tests for issues reported in the Bug Tracker
 
+(ert-deftest cperl-test-bug-997 ()
+  "Test that we distinguish a regexp match when there's nothing before it."
+  (let ((code "# some comment\n\n/fontify me/;\n"))
+    (with-temp-buffer
+      (funcall cperl-test-mode)
+      (insert code)
+      (font-lock-ensure)
+      (goto-char (point-min))
+      (search-forward "/f")
+      (should (equal (get-text-property (point) 'face)
+                     'font-lock-string-face)))))
+
 (defun cperl-test--run-bug-10483 ()
   "Runs a short program, intended to be under timer scrutiny.
 This function is intended to be used by an Emacs subprocess in
-- 
2.34.1


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

* bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level
  2022-09-19 16:03 ` bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level Mauro Aranda
@ 2022-09-19 18:37   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-19 18:37 UTC (permalink / raw)
  To: Mauro Aranda; +Cc: 997, Harald Jörg, jidanni

Mauro Aranda <maurooaranda@gmail.com> writes:

> I attach a patch to fix this bug, by detecting that we moved to the
> beginning of buffer when searching for something before the "/".

Thanks; pushed to Emacs 29.





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

end of thread, other threads:[~2022-09-19 18:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-18 13:15 bug#997: perl mode blows "'" etc jidanni
2020-02-29  2:58 ` Stefan Kangas
2020-02-29  3:12   ` 積丹尼 Dan Jacobson
2020-11-17 17:52 ` bug#997: perl-mode: Merging was not quite correct Harald Jörg
2020-11-19 16:07   ` Noam Postavsky
2020-11-19 17:07 ` bug#997: perl-mode: Un-merging an unrelated bug Harald Jörg
2022-09-19 16:03 ` bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level Mauro Aranda
2022-09-19 18:37   ` 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).