From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Newsgroups: gmane.emacs.bugs Subject: bug#47345: perl-mode: Fix some regexps for fontification [PATCH] Date: Tue, 23 Mar 2021 15:57:36 +0100 Message-ID: <874kh1zzmn.fsf@hajtower> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37963"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: 47345@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 23 15:58:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOiU1-0009lf-Ti for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 23 Mar 2021 15:58:14 +0100 Original-Received: from localhost ([::1]:45640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOiU0-00016t-Sj for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 23 Mar 2021 10:58:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOiTq-00010f-LA for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 10:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOiTq-0006wH-Db for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 10:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lOiTq-0007Lw-C7 for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 10:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 Mar 2021 14:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47345 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161651147428246 (code B ref -1); Tue, 23 Mar 2021 14:58:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Mar 2021 14:57:54 +0000 Original-Received: from localhost ([127.0.0.1]:60953 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOiTi-0007LV-BE for submit@debbugs.gnu.org; Tue, 23 Mar 2021 10:57:54 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:46938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOiTg-0007LN-51 for submit@debbugs.gnu.org; Tue, 23 Mar 2021 10:57:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOiTf-0000oL-71 for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 10:57:51 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:34557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOiTc-0006ma-BS for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 10:57:50 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 9D93E160068 for ; Tue, 23 Mar 2021 15:57:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1616511463; bh=Zzy+w7BgQXP/QhA4RRsa6c5fiDmfiLoKodnzi3CYPX0=; h=From:To:Subject:Date:From; b=HKU70VnEoOj1D3VIrliXCO6oik66VT1zAx7rOGsI8YCqCh7HFRBo4QRi4jTjJDsKI uxX73FqVgRPDlcFCEkZujqe3RLZ6nRSphBPM4kYROpQ4mh8q40smObcX+k7Aekl88Q ggkyDLzFT36JQ70F0i5fIv+WxZ9ILLlK55glrYCwVQXNoshfRoE+LIOBMU0DQsZEme wmsqRF4F5UnrFRP93F1R5fmJljGg1OmF/dp0GxqS73pkxVjO2kM5Jc/H4Dqu8M0x5I gVCGwOIxX8DPSKyyGEDKdT4GxFBXn5sGv0RKnqJODZxt+hErpaq/JI4gv0TqsVF9ko kqVfmiYPQA3Sg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4F4ZGt1nwTz6tn4 for ; Tue, 23 Mar 2021 15:57:42 +0100 (CET) Received-SPF: pass client-ip=185.67.36.65; envelope-from=haj@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:202903 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-perl-mode-Fix-regexps-for-fontification.patch Content-Description: Perl mode: Fix some regexps for fontification >From 8bb05c1364e59f1ad83c64c7f86735a6d6c0e0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= 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 --=-=-=--