From: Mauro Aranda <maurooaranda@gmail.com>
To: 997@debbugs.gnu.org
Cc: "Harald Jörg" <haj@posteo.de>, jidanni@jidanni.org
Subject: bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level
Date: Mon, 19 Sep 2022 13:03:08 -0300 [thread overview]
Message-ID: <3a9155d8-6af5-d9d3-0d7c-2ea6c9501e0d@gmail.com> (raw)
In-Reply-To: <871vzhoasd.fsf@jidanni.org>
[-- 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
next prev parent reply other threads:[~2022-09-19 16:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Mauro Aranda [this message]
2022-09-19 18:37 ` bug#997: perl-mode: Incorrect syntax highlighting for regex at top-level Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3a9155d8-6af5-d9d3-0d7c-2ea6c9501e0d@gmail.com \
--to=maurooaranda@gmail.com \
--cc=997@debbugs.gnu.org \
--cc=haj@posteo.de \
--cc=jidanni@jidanni.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).