From: Tomasz Konojacki <me@xenu.pl>
To: 49906@debbugs.gnu.org
Subject: bug#49906: perl-mode: variables that conflict with keywords aren't fontified properly
Date: Fri, 06 Aug 2021 08:37:19 +0200 [thread overview]
Message-ID: <20210806083716.258A.5C4F47F8@xenu.pl> (raw)
In-Reply-To: <20210806052526.2582.5C4F47F8@xenu.pl>
[-- Attachment #1: Type: text/plain, Size: 166 bytes --]
On Fri, 06 Aug 2021 05:25:30 +0200
Tomasz Konojacki <me@xenu.pl> wrote:
> For example, "$package" is fontified like a keyword.
The attached patch fixes the problem.
[-- Attachment #2: 0001-perl-mode-fix-variable-fontification.patch --]
[-- Type: application/octet-stream, Size: 2440 bytes --]
From 429f002c619b3d7efd2928dba14cd23e0f381955 Mon Sep 17 00:00:00 2001
From: Tomasz Konojacki <me@xenu.pl>
Date: Fri, 6 Aug 2021 08:34:09 +0200
Subject: [PATCH] perl-mode: fix variable fontification
* lisp/progmodes/perl-mode.el: handle variables first to avoid
conflicting with keywords. This fixes cases like "$package".
cl-lib has to be required at runtime, because cl-concatenate isn't a
macro. (bug#49906)
---
lisp/progmodes/perl-mode.el | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index f49ee4cb2b..281f106776 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -87,7 +87,7 @@
;;; Code:
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
(defgroup perl nil
"Major mode for editing Perl code."
@@ -177,7 +177,16 @@
"Subdued level highlighting for Perl mode.")
(defconst perl-font-lock-keywords-2
- (append
+ (cl-concatenate
+ 'list
+ '(;; Fontify function, variable and file name references. They have to be
+ ;; handled first because they might conflict with keywords.
+ ("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
+ ;; Additionally fontify non-scalar variables. `perl-non-scalar-variable'
+ ;; will underline them by default.
+ ("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
+ ("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
+ (2 'perl-non-scalar-variable)))
perl-font-lock-keywords-1
`( ;; Fontify keywords, except those fontified otherwise.
,(concat "\\<"
@@ -188,15 +197,6 @@
;;
;; Fontify declarators and prefixes as types.
("\\<\\(has\\|local\\|my\\|our\\|state\\)\\>" . font-lock-keyword-face) ; declarators
- ;;
- ;; Fontify function, variable and file name references.
- ("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
- ;; Additionally fontify non-scalar variables. `perl-non-scalar-variable'
- ;; will underline them by default.
- ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face)
- ("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
- ("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
- (2 'perl-non-scalar-variable))
("<\\(\\sw+\\)>" 1 font-lock-constant-face)
;;
;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'.
--
2.27.0.windows.1
next prev parent reply other threads:[~2021-08-06 6:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 3:25 bug#49906: perl-mode: variables that conflict with keywords aren't fontified properly Tomasz Konojacki
2021-08-06 6:37 ` Tomasz Konojacki [this message]
2021-08-06 11:00 ` Lars Ingebrigtsen
2021-08-06 12:06 ` Tomasz Konojacki
2021-08-06 12:10 ` Tomasz Konojacki
2021-08-07 9:10 ` Lars Ingebrigtsen
2021-08-07 9:13 ` Lars Ingebrigtsen
2021-08-07 9:33 ` Tomasz Konojacki
2021-08-07 10:37 ` Lars Ingebrigtsen
2021-08-07 11:09 ` Tomasz Konojacki
2021-08-07 11:16 ` Lars Ingebrigtsen
2021-08-07 11:33 ` Tomasz Konojacki
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=20210806083716.258A.5C4F47F8@xenu.pl \
--to=me@xenu.pl \
--cc=49906@debbugs.gnu.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).