jrockway / cperl-mode

cperl-mode with 5.10 fixes, mx-declare support, perl6 support, etc.
102 stars 33 forks source link

inserting newline at start of line in HERE doc breaks syntax highlighting #37

Open CeleritasCelery opened 7 years ago

CeleritasCelery commented 7 years ago

When inside a cperl HERE doc, using any function that inserts a newline at the start of a line will causes the rest of the file to highlighted with font-lock-comment-face. The only way to fix this is to make changes to the correctly highlighted part of the HERE doc which causes it to re-parse. My guess is that cperl is getting mixed up with POD highlighting and trying to apply cperl-pod-face since POD's and HERE documents are very closely related in cperl-mode code.

To reproduce: have a cperl-mode file that looks like such

#!/usr/bin/env perl

my $here_doc = <<'_HERE_';
this is here doc line
| <-- call `Eval: (insert "\n")` when cursor is here or at the start of any line
_HERE_

You will see that the rest of the file is highlighted with the comment face. Calling any function that finds the HERE doc region will be incorrect (e.g. cperl-narrow-to-here-doc). I have already confirmed that this bug exists in stock Emacs 25.1 as well.

renormalist commented 6 years ago

And is there a fix for stock Emacs you could prepare as pull request here?

CeleritasCelery commented 6 years ago

I do not have a fix. There is bug open on Emacs proper, but it has not gathered any attention

HaraldJoerg commented 4 years ago

The bug has now drawn attention but it is unlikely that it can be fixed in Emacs.

The root cause is the use of the insert function here: Use insert-and-inherit and everything works as expected.

Background: cperl-mode uses text properties to decide about the HEREiness of buffer contents. If you enter text using your keyboard, then text properties will be propagated from its surroundings. However, insert just inserts the raw text without any properties which confuses cperl-mode. insert-and-inherit, on the other hand, will apply the text properties from the surroundings to the text it inserts.

If you can't directly modify the call to insert: The command cperl-find-pods-heres, also available from the menu under Perl -> Refresh "hard" constructions, re-calculates the text properties and recovers from the situation.