dhruvasagar / vim-table-mode

VIM Table Mode for instant table creation.
2.11k stars 96 forks source link

"E866: (NFA regexp) Misplaced {" on toggles, realign #162

Closed oeuftete closed 4 years ago

oeuftete commented 4 years ago

I've been seeing this in recent versions (currently, 0af25d72ebc0271648c8f91c0ce5c59174d2761b) in a couple of my environments. I suspect this may be an interaction with some other plugin since no one else seems to be seeing it, but at a loss into how I might fix it. I've tried some manual bisection with this plugin and the presence of other plugins, but not able to pin this down.

Enabling:

Error detected while processing function tablemode#Toggle[6]..<SNR>318_SetActive[2]..<SNR>318_ToggleSyntax:
line    4:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
E475: Invalid argument: Table /^\s*\(\{\#\)\?\s*\zs|.\+|\ze\s*\(\s\+\#\}\)\?\s*$/ contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL
Table Mode Enabled

Realigning:

Error detected while processing function tablemode#table#Realign[8]..tablemode#table#IsTable[1]..tablemode#table#IsRow[1]..tablemode#table#IsBorder:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
Error detected while processing function tablemode#table#Realign[8]..tablemode#table#IsTable[1]..tablemode#table#IsRow:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
Error detected while processing function tablemode#table#Realign[8]..tablemode#table#IsTable[1]..tablemode#table#IsBorder:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
Error detected while processing function tablemode#table#Realign[19]..tablemode#table#IsTable[1]..tablemode#table#IsRow[1]..tablemode#table#IsBorder:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
Error detected while processing function tablemode#table#Realign[19]..tablemode#table#IsTable[1]..tablemode#table#IsRow:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing
Error detected while processing function tablemode#table#Realign[19]..tablemode#table#IsTable[1]..tablemode#table#IsBorder:
line    1:
E866: (NFA regexp) Misplaced {
E64: \{ follows nothing

vi:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)
Included patches: 1-1453
idvorkin commented 4 years ago

I can repro with:

---
  - emotional intelligence
---

- Second Table
| -------- | -------------------------------- |
| T1       | T2                               |

I suspect the problem is the liquid plugin, as when I set ft=markdown before enabling it works.

oeuftete commented 4 years ago

Found it. The vim-markdown plugin supports fenced languages to format inside code blocks. I had jinja2 as a supported language there. The Vim-Jinja2-Syntax plugin does this in its syntax file:

setlocal commentstring={#%s#}

And that's what commentstring was set to in my buffer. That gets read by tablemode#table#GetCommentStart(), and ends up in a format in the syntax match that is not valid.

Not sure what the right fix is in this plugin, if any. The workaround for me was to do setlocal commentstring=<!--%s-->, and things work again. And/or remove jinja2 from g:markdown_fenced_languages.

dhruvasagar commented 4 years ago

@oeuftete Interesting, thanks for looking into this. Is setlocal commentstring={#%s#} valid and / or is setlocal commentstring=<!--%s--> a valid alternative for jinja2 ? As a work around it is also possible to just alter that within the markdown ftplugin perhaps. If however, the former commentstring is the right one to be used, then it would require a bit of escaping within the regex builder that uses the comment string.

oeuftete commented 4 years ago

@dhruvasagar I believe {#%s#} is the appropriate commentstring for jinja2. <!--%s--> is not appropriate for jinja2, but is of course perfectly sensible for markdown.

I think (?) the real problem here is that the syntax file for jinja2 is setting commentstring, and this should not be set in a syntax file, but in an ftplugin file. Because it is in the syntax file, it gets sets when the markdown plugin reads it to format its fenced code blocks, overwriting the markdown setting in the buffer.

Anyway, I have opened the PR https://github.com/pallets/jinja/pull/1164 to fix the jinja2 syntax file in its project, which should eventually percolate down to the Vim-Jinja2-Syntax plugin, which should make this go away for me.

dhruvasagar commented 4 years ago

@oeuftete Thanks a lot, I am going to close this issue for the time being, feel free to reopen this if you think otherwise and if there's something we'll need to do additionally in vim-table-mode