1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

cperl-mode.el: Subroutine names are fontified correctly in all places

Subroutine names are fontified as subroutine names even if the name is also
the name of a builtin (fixing an ancient unreported bug).  Subroutine name
are just comments in comment and pod (fixing a bug introduced recently)

* lisp/progmodes/cperl-mode.el (cperl-init-faces): Move
fontification of sub declarations before that of builtins.  Don't
override existing faces when fontifying subroutine declarations.
Don't fontify method calls even if the sub names match those of
builtins.

* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-fontify-sub-names):
New tests with a subroutine name in several surroundings.

* test/lisp/progmodes/cperl-mode-resources/sub-names.pl: New resource
for the new test.
This commit is contained in:
Harald Jörg 2023-08-02 23:53:42 +02:00
parent 0910230be6
commit 3c44d7a1b7
3 changed files with 121 additions and 51 deletions

View file

@ -256,6 +256,39 @@ These can occur as \"local\" aliases."
(should (equal (get-text-property (point) 'face)
'font-lock-variable-name-face))))
(ert-deftest cperl-test-fontify-sub-names ()
"Test fontification of subroutines named like builtins.
On declaration, they should look like other used defined
functions. When called, they should not be fontified. In
comments and POD they should be fontified as POD."
(let ((file (ert-resource-file "sub-names.pl")))
(with-temp-buffer
(insert-file-contents file)
(goto-char (point-min))
(funcall cperl-test-mode)
(font-lock-ensure)
;; The declaration
(search-forward-regexp "sub \\(m\\)")
(should (equal (get-text-property (match-beginning 1) 'face)
'font-lock-function-name-face))
;; calling as a method
(search-forward-regexp "C->new->\\(m\\)")
(should (equal (get-text-property (match-beginning 1) 'face)
(if (equal cperl-test-mode 'perl-mode) nil
'cperl-method-call)))
;; POD
(search-forward-regexp "\\(method\\) \\(name\\)")
(should (equal (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))
(should (equal (get-text-property (match-beginning 2) 'face)
'font-lock-comment-face))
;; comment
(search-forward-regexp "\\(method\\) \\(name\\)")
(should (equal (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))
(should (equal (get-text-property (match-beginning 2) 'face)
'font-lock-comment-face)))))
(ert-deftest cperl-test-identify-heredoc ()
"Test whether a construct containing \"<<\" followed by a
bareword is properly identified for a here-document if