]> git.eshelyaron.com Git - emacs.git/commitdiff
perl-mode: Fix regexps for fontification
authorHarald Jörg <haj@posteo.de>
Wed, 24 Mar 2021 16:06:21 +0000 (17:06 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 24 Mar 2021 16:06:21 +0000 (17:06 +0100)
* test/lisp/progmodes/cperl-mode-tests.el
(cperl-test-fontify-declarations): New test to ensure consistency
between perl-mode.el and cperl-mode.el (bug#47345).
* 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

lisp/progmodes/perl-mode.el
test/lisp/progmodes/cperl-mode-tests.el

index c7fa5ab84b0e87b01d32d9771e1d652980003e25..fd23683bc0a016075df00c0d8546958b87c3ea5f 100644 (file)
     ;;  (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.")
 
               "\\>")
      ;;
      ;; 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)
index 8078e9c9fa9a9a0884af9f7a97631a9a1222fb8f..14bc48b92fd963de1bf370c38453f7f82236f567 100644 (file)
@@ -135,6 +135,25 @@ point in the distant past, and is still broken in perl-mode. "
         (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)