all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#47345: perl-mode: Fix some regexps for fontification [PATCH]
@ 2021-03-23 14:57 Harald Jörg
  2021-03-24 16:06 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Jörg @ 2021-03-23 14:57 UTC (permalink / raw)
  To: 47345

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

Severity: minor

Following a discussion with Stefan Monnier on the developer list:

 - In "use Package;" the package name is now captured for fontifying
   as intended

 - The declarators "my" etc. now use font-lock-keyword-face for better
   consistency with other programming modes

 - As a by-catch, now all components of package names like
   "Long::Package::Name" are fontified.  This was a known issue of
   little importance, not yet reported as a bug.

 - A test is included as well.
-- 
Cheers,
haj


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Perl mode: Fix some regexps for fontification --]
[-- Type: text/x-diff, Size: 3357 bytes --]

From 8bb05c1364e59f1ad83c64c7f86735a6d6c0e0cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Tue, 23 Mar 2021 15:45:51 +0100
Subject: [PATCH] ; perl-mode: Fix regexps for fontification

* lisp/progmodes/perl-mode.el (perl-font-lock-keywords-1): pick
correct capture groups for "use Pack::Age;"
Fontify all components of "Pack::Age", not just "Pack"
(perl-font-lock-keywords-2): Use keyword-face for declarators

* test/lisp/progmodes/cperl-mode-tests.el
(cperl-test-fontify-declarations): New test to ensure consistency
between perl-mode.el and cperl-mode.el
---
 lisp/progmodes/perl-mode.el             |  6 +++---
 test/lisp/progmodes/cperl-mode-tests.el | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index c7fa5ab84b..fd23683bc0 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -170,9 +170,9 @@ perl-font-lock-keywords-1
     ;;  (1 font-lock-constant-face) (2 font-lock-variable-name-face nil t))
     ;;
     ;; Fontify function and package names in declarations.
-    ("\\<\\(package\\|sub\\)\\>[ \t]*\\(\\sw+\\)?"
+    ("\\<\\(package\\|sub\\)\\>[ \t]*\\(\\(?:\\sw\\|::\\)+\\)?"
      (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
-    ("\\(^\\|[^$@%&\\]\\)\\<\\(import\\|no\\|require\\|use\\)\\>[ \t]*\\(\\sw+\\)?"
+    ("\\(?:^\\|[^$@%&\\]\\)\\<\\(import\\|no\\|require\\|use\\)\\>[ \t]*\\(\\(?:\\sw\\|::\\)+\\)?"
      (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)))
   "Subdued level highlighting for Perl mode.")
 
@@ -187,7 +187,7 @@ perl-font-lock-keywords-2
               "\\>")
      ;;
      ;; Fontify declarators and prefixes as types.
-     ("\\<\\(has\\|local\\|my\\|our\\|state\\)\\>" . font-lock-type-face) ; declarators
+     ("\\<\\(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)
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index 8078e9c9fa..14bc48b92f 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -135,6 +135,25 @@ cperl-test-fontify-punct-vars
         (should (equal (nth 3 (syntax-ppss)) nil))
         (should (equal (nth 4 (syntax-ppss)) t))))))
 
+(ert-deftest cperl-test-fontify-declarations ()
+  "Test that declarations and package usage use consistent fontification."
+  (with-temp-buffer
+    (funcall cperl-test-mode)
+    (insert "package Foo::Bar;\n")
+    (insert "use Fee::Fie::Foe::Foo\n;")
+    (insert "my $xyzzy = 'PLUGH';\n")
+    (goto-char (point-min))
+    (font-lock-ensure)
+    (search-forward "Bar")
+    (should (equal (get-text-property (match-beginning 0) 'face)
+                   'font-lock-function-name-face))
+    (search-forward "use") ; This was buggy in perl-mode
+    (should (equal (get-text-property (match-beginning 0) 'face)
+                   'font-lock-keyword-face))
+    (search-forward "my")
+    (should (equal (get-text-property (match-beginning 0) 'face)
+                   'font-lock-keyword-face))))
+
 (defvar perl-continued-statement-offset)
 (defvar perl-indent-level)
 
-- 
2.20.1


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

end of thread, other threads:[~2021-03-24 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-23 14:57 bug#47345: perl-mode: Fix some regexps for fontification [PATCH] Harald Jörg
2021-03-24 16:06 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.