]> git.eshelyaron.com Git - emacs.git/commitdiff
perl-mode: fix variable fontification
authorTomasz Konojacki <me@xenu.pl>
Sat, 7 Aug 2021 10:36:22 +0000 (12:36 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 7 Aug 2021 10:37:47 +0000 (12:37 +0200)
* lisp/progmodes/perl-mode.el: Handle variables first to avoid
conflicting with keywords. This fixes cases like "$package"
(bug#49906).
Copyright-paperwork-exempt: yes

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

index f49ee4cb2b5385f6747f9b06da7c9ad9ef6ea34f..4e14c30bc5d23bd4f18d222d3bfe0d18c737fc48 100644 (file)
 
 (defconst perl-font-lock-keywords-2
   (append
+   '(;; 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 "\\<"
      ;;
      ;; 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'.
index f63f8ad72535c81bb51b30297854dd078e2ab1f3..3f4af5e1f613a312ff0e3d2c61ae305ed8d094b8 100644 (file)
 
 (require 'perl-mode)
 
+(ert-deftest perl-test-lock ()
+  (with-temp-buffer
+    (perl-mode)
+    (insert "$package = foo;")
+    (font-lock-ensure (point-min) (point-max))
+    (should (equal (get-text-property 4 'face) 'font-lock-variable-name-face))))
+
 ;;;; Re-use cperl-mode tests
 
 (defvar cperl-test-mode)