From: Tomasz Konojacki Date: Sat, 7 Aug 2021 10:36:22 +0000 (+0200) Subject: perl-mode: fix variable fontification X-Git-Tag: emacs-28.0.90~1591^2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c62e805d80fc5d47325ed0ee84a7f3879e85cbd9;p=emacs.git perl-mode: fix variable fontification * lisp/progmodes/perl-mode.el: Handle variables first to avoid conflicting with keywords. This fixes cases like "$package" (bug#49906). Copyright-paperwork-exempt: yes --- diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index f49ee4cb2b5..4e14c30bc5d 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -178,6 +178,14 @@ (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 "\\<" @@ -188,15 +196,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'. diff --git a/test/lisp/progmodes/perl-mode-tests.el b/test/lisp/progmodes/perl-mode-tests.el index f63f8ad7253..3f4af5e1f61 100644 --- a/test/lisp/progmodes/perl-mode-tests.el +++ b/test/lisp/progmodes/perl-mode-tests.el @@ -21,6 +21,13 @@ (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)