in reply to [Emacs] patching cperl-mode to highlight syntax without POD newlines
Quick ugly hack known to apply to https://github.com/jrockway/cperl-mode.git, but probably applies to whatever version of cperl-mode you have as well (I don't expect most people like messing with that chunk of voodoo code). Turns off parsing of multi-line command blocks. In your example, formats the first 5 lines in pod face, and the rest as code.
Update per Laurent_R's request: (not sure what level of explanation you were wanting, so forgive me if I go on too long) POD treats all text following an =WHATEVER as part of that "Command Paragraph", so
and=head1 Heading Text Blah Blah
=head1 Heading Text Blah Blah
Both make an H1 containing "Heading Text" (it may or may not include a newline in the second case / I'm not sure and isn't important in this discussion). The Emacs syntax highlighter (cperl-mode) was highlighting LanX's subroutine as though it were an argument to the =cut. Apparently, perl itself knows that =cut doesn't take an argument and executes the line after it, thus executing the subroutine. The code below is a diff against the emacs syntax highlighter (cperl-mode.el) that comments out its parsing and highlighting of command arguments. To use it, you would need to download a copy of the cperl-mode source code, apply the diff using patch, then load the modified cperl-mode.el in your emacs configuration file. Before the patch, emacs would color =head1 red and Heading Text blue in the examples above (in my color scheme, probably different in yours). After the patch, the whole =head1 Heading Text is just red the "Heading Text" argument is not parsed, the whole line is just treated as POD. This makes the =cut span only a single line and emacs highlights the subroutine as perl code, as desired. The patch removes a feature of the cperl-mode parser so that LanX can get his work done, it isn't an improvement of cperl-mode that would be desirable generally.
diff --git a/cperl-mode.el b/cperl-mode.el index 00e6c3b..d0b23ee 100644 --- a/cperl-mode.el +++ b/cperl-mode.el @@ -3873,38 +3873,38 @@ the sections using `cperl-pod-head-face', `cpe +rl-pod-face', (put-text-property b e 'in-pod t) (put-text-property b e 'syntax-type 'in-pod) (goto-char b) - (while (re-search-forward "\n\n[ \t]" e t) - ;; We start 'pod 1 char earlier to include the pre +ceding line - (beginning-of-line) - (put-text-property (cperl-1- b) (point) 'syntax-ty +pe 'pod) - (cperl-put-do-not-fontify b (point) t) - ;; mark the non-literal parts as PODs - (if cperl-pod-here-fontify - (cperl-postpone-fontification b (point) 'face +face t)) - (re-search-forward "\n\n[^ \t\f\n]" e 'toend) - (beginning-of-line) - (setq b (point))) - (put-text-property (cperl-1- (point)) e 'syntax-type + 'pod) - (cperl-put-do-not-fontify (point) e t) - (if cperl-pod-here-fontify - (progn - ;; mark the non-literal parts as PODs - (cperl-postpone-fontification (point) e 'face +face t) - (goto-char bb) - (if (looking-at - "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\) ++\\)$") - ;; mark the headers - (cperl-postpone-fontification - (match-beginning 1) (match-end 1) - 'face head-face)) - (while (re-search-forward - ;; One paragraph - "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^ +\n]\\)+\\)$" - e 'toend) - ;; mark the headers - (cperl-postpone-fontification - (match-beginning 1) (match-end 1) - 'face head-face)))) +; (while (re-search-forward "\n\n[ \t]" e t) +; ;; We start 'pod 1 char earlier to include the pre +ceding line +; (beginning-of-line) +; (put-text-property (cperl-1- b) (point) 'syntax-ty +pe 'pod) +; (cperl-put-do-not-fontify b (point) t) +; ;; mark the non-literal parts as PODs +; (if cperl-pod-here-fontify +; (cperl-postpone-fontification b (point) 'face +face t)) +; (re-search-forward "\n\n[^ \t\f\n]" e 'toend) +; (beginning-of-line) +; (setq b (point))) +; (put-text-property (cperl-1- (point)) e 'syntax-type + 'pod) +; (cperl-put-do-not-fontify (point) e t) +; (if cperl-pod-here-fontify +; (progn +; ;; mark the non-literal parts as PODs +; (cperl-postpone-fontification (point) e 'face +face t) +; (goto-char bb) +; (if (looking-at +; "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\) ++\\)$") +; ;; mark the headers +; (cperl-postpone-fontification +; (match-beginning 1) (match-end 1) +; 'face head-face)) +; (while (re-search-forward +; ;; One paragraph +; "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^ +\n]\\)+\\)$" +; e 'toend) +; ;; mark the headers +; (cperl-postpone-fontification +; (match-beginning 1) (match-end 1) +; 'face head-face)))) (cperl-commentify bb e nil) (goto-char e) (or (eq e (point-max))
Good Day,
Dean
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Emacs] patching cperl-mode to highlight syntax without POD newlines
by Laurent_R (Canon) on Apr 22, 2015 at 20:05 UTC | |
|
Re^2: [Emacs] patching cperl-mode to highlight syntax without POD newlines
by LanX (Saint) on Apr 24, 2015 at 16:43 UTC | |
|
Re^2: [Emacs] patching cperl-mode to highlight syntax without POD newlines
by LanX (Saint) on Apr 27, 2015 at 09:57 UTC | |
by duelafn (Parson) on Apr 27, 2015 at 15:06 UTC | |
by LanX (Saint) on Apr 27, 2015 at 15:59 UTC |