[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 3a1fc816288: cperl-mode.el: Optionally treat trailing text as com
From: |
Harald Jörg |
Subject: |
master 3a1fc816288: cperl-mode.el: Optionally treat trailing text as comment |
Date: |
Fri, 13 Oct 2023 18:41:36 -0400 (EDT) |
branch: master
commit 3a1fc816288131a877345cea0f73258652cb7f57
Author: Harald Jörg <haj@posteo.de>
Commit: Harald Jörg <haj@posteo.de>
cperl-mode.el: Optionally treat trailing text as comment
* lisp/progmodes/cperl-mode.el (cperl-fontify-trailer): New
customization variable. With a value of 'comment, cperl-mode
treats trailing text after after __END__ and __DATA__ as comment,
like perl-mode does (Bug#66161).
(cperl-find-pods-heres): Treat trailing text after __END__ and
__DATA__ according to the customization variable
`cperl-fontify-trailer'.
* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-66161):
New test, verifying the changed behavior if the custom variable is
set to 'comment.
* test/lisp/progmodes/cperl-mode-resources/cperl-bug-66161.pl: New
resource file, source code from the corresponding bug report.
---
lisp/progmodes/cperl-mode.el | 17 +++++++++++++++--
.../progmodes/cperl-mode-resources/cperl-bug-66161.pl | 13 +++++++++++++
test/lisp/progmodes/cperl-mode-tests.el | 14 ++++++++++++++
3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index c2d9c0d6020..7b72e3baee5 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -550,6 +550,18 @@ This way enabling/disabling of menu items is more correct."
:version "29.1")
;;;###autoload(put 'cperl-file-style 'safe-local-variable 'stringp)
+(defcustom cperl-fontify-trailer
+ 'perl-code
+ "How to fontify text after an \"__END__\" or \"__DATA__\" token.
+If \"perl-code\", treat as Perl code for fontification, and
+examine for imenu entries. Use this setting if you have trailing
+POD documentation, or for modules which use AutoLoad or
+AutoSplit. If \"comment\", treat as comment, and do not look for
+imenu entries."
+ :type '(choice (const perl-code)
+ (const comment))
+ :group 'cperl-faces)
+
(defcustom cperl-ps-print-face-properties
'((font-lock-keyword-face nil nil bold shadow)
(font-lock-variable-name-face nil nil bold)
@@ -4913,8 +4925,9 @@ recursive calls in starting lines of here-documents."
;; 1+6+2+1+1+6+1+1=19 extra () before this:
;; "__\\(END\\|DATA\\)__"
((match-beginning 20) ; __END__, __DATA__
- (setq bb (match-end 0))
- ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
+ (if (eq cperl-fontify-trailer 'perl-code)
+ (setq bb (match-end 0))
+ (setq bb (point-max)))
(cperl-commentify b bb nil)
(setq end t))
;; "\\\\\\(['`\"($]\\)"
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-66161.pl
b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-66161.pl
new file mode 100644
index 00000000000..e39cfdd3b24
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-66161.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+print("Hello World\n");
+
+__END__
+
+TODO:
+What's happening?
+
+It's all messed up.
diff --git a/test/lisp/progmodes/cperl-mode-tests.el
b/test/lisp/progmodes/cperl-mode-tests.el
index 87d4f11280c..de7a614496f 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -1403,6 +1403,20 @@ beginning with `cperl-test-unicode`."
(cdr (assoc (match-string-no-properties 1)
faces)))))))))
+(ert-deftest cperl-test-bug-66161 ()
+ "Verify that text after \"__END__\" is fontified as comment.
+For `cperl-mode', this needs the custom variable
+`cperl-fontify-trailer' to be set to `comment'. Per default,
+cperl-mode fontifies text after the delimiter as Perl code."
+ (with-temp-buffer
+ (insert-file-contents (ert-resource-file "cperl-bug-66161.pl"))
+ (setq cperl-fontify-trailer 'comment)
+ (funcall cperl-test-mode)
+ (font-lock-ensure)
+ (search-forward "TODO") ; leaves point before the colon
+ (should (equal (get-text-property (point) 'face)
+ font-lock-comment-face))))
+
(ert-deftest test-indentation ()
(ert-test-erts-file (ert-resource-file "cperl-indents.erts")))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 3a1fc816288: cperl-mode.el: Optionally treat trailing text as comment,
Harald Jörg <=