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

support for jinja2? #83

Open
gardar opened this issue Feb 4, 2020 · 4 comments
Open

support for jinja2? #83

gardar opened this issue Feb 4, 2020 · 4 comments

Comments

@gardar
Copy link

gardar commented Feb 4, 2020

Could we get support for jinja2?

For:
{% if %} {% else %} {% endif %}
{% for %} {% endfor %}
etc.

Related to #68 since jinja2 originates from python but imo shouldn't necessarily depend on python being supported.

@andymass
Copy link
Owner

andymass commented Feb 4, 2020

What is the file type you are using? Do you use any jinja2 plugin?

@gardar
Copy link
Author

gardar commented Feb 4, 2020

I don't believe there is an official file extension, but from what I've seen .j2 .jinja and .jinja2 are widely accepted
I'm mostly working with jinja in ansible and then It's usually with the .j2 file extension.

I do have the following set:
au BufRead,BufNewFile *.j2 setfiletype jinja

Other than that I'm currently just using a pretty minimal setup of nvim with deoplete, but I don't think deoplete or deoplete-jedi has any affect on jinja files.

@andymass
Copy link
Owner

andymass commented Feb 5, 2020

Should be possible to define a set of regexes for the jinja tags, like

au FileType jinja let b:match_words = get(b:, 'match_words', '')
    \ . ',{%-\?\s*if.\{-}-\?%}:{%-\?\s*else\s*-\?%}:{%-\?*\s*endif\s*-\?%}'
    \ . ',{%-\?\s*for.\{-}-\?%}:{%-\?\s*endfor\s*-\?%}'

Supporting this in general is hard because it depends on the underlying filetype- I guess usually it is html (e.g., https://github.com/Glench/Vim-Jinja2-Syntax/), but in your case you don't seem to have an html document filetype at all.

@buzuck
Copy link

buzuck commented Sep 9, 2020

I opened an issue for that plugin (Glench/Vim-Jinja2-Syntax#29) , but actually I it may be related to Match-up.

For the moment, Vim-Jinja2-Syntax does not match multi-line statements:

{% for very_long in dict
   if true and not false %}
[...]
{% endfor %}

I tried to fix that by just adding \_ on the last line (and I don't quite understand the other stuff, its looks quite like magic 😅 ) [Edit: I just realized the other 3 lines are just from the html file of Matchup.]

  let b:match_words = '<:>,' .
        \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
        \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
        \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>,' .
        \ '{%[-+]\? *\%(end\)\@!\(\w\+\)\>\_.\{-}%}:{%-\? *end\1\>.\{-}%}'

Here is the error I get when the cursor hits endfor:

Error detected while processing function 5[3]..6[82]..matchup#delim#get_matching[20]..<SNR>134_get_matching_delims:
line  101:
E684: list index out of range: 0

(Sorry if this should go in its own issue)

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