Hangs when opening files with jinja string concatenation
wwentland opened this issue · comments
Dear Maintainer,
unfortunately emacs seems to hang if you open the following file:
baz:
bar: {{ 'boo' ~ 'foo' }}
This seems to be only triggered if string literals are present as the following does not cause emacs to hang:
{% set boo = 'boo' %}
{% set foo = 'foo' %}
baz:
bar: {{ boo ~ foo }}
Thank you!
Thanks for the report, I can reproduce this. It completely locks emacs...
I'll try and get some time soon to look into this. In the meantime, if you're able to reproduce this with any other code, please post it here.
I believe this crash is caused by python-mode syntax highlighting (which is the mode used inside jinja {{ }}
tags).
Can you try the following?
- Open an empty file with python-mode enabled
- Insert
'foo' ~ 'bar'
- Then (try to) insert a space at the start of the line. Emacs hangs immediately for me, then proceeds to blast the CPU, even after the buffer is closed.
See also dgutov/mmm-mode#66, where python-mode also hangs emacs due to malformed syntax.
I suppose fixing this bug in python-mode isn't going to be straightforward. I propose we try one of the following:
- Switch the mode used inside
{{ }}
and{% %}
tags to something simple like text-mode. We will lose some syntax highlighting and any specific python mode niceties. - Leave things as they are, since python-mode used in any way will hang on this kind of syntax, not just in salt-mode.
- Create some kind of hook in salt mode that scans the buffer for bad regexes and attempts to change them, else disables the python submode. For example, I think
{{ 'foo' ~ 'bar' }}
could be changed to{{'foo' ~ 'bar'}}
and python-mode won't explode. This of course has the downside of salt-mode changing your code in unexpected ways. I also suspect there are more of these python-mode syntax bugs that salt-mode would need to look for.
What do you think?
I believe this crash
Is it a crash or a freeze?
@dgutov a freeze I think?
It's an infinite loop in python-mode font locking according to your comment here dgutov/mmm-mode#66 (comment)
However I am unable to use C-g to recover from this, I have to kill emacs.
It's an infinite loop in python-mode font locking according to your comment here
The relevant bug seems fixed (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24856#8). You might want to try to build Emacs from master, to double-check.
@dgutov thank you for finding that out for me.
I just ran emacs from master and it doesn't have this bug, so I guess it's just a matter of time until this issue is fixed naturally. Thank you.
I can confirm that the bug has been fixed in emacs master and 25.2. Thank you for looking into this!