Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CeleritasCelery opened this issue Mar 1, 2017 · 3 comments

Comments

@CeleritasCelery
Copy link

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
Copy link
Collaborator

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

@CeleritasCelery
Copy link
Author

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

@HaraldJoerg
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants