Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
Nothing impossible or hard, but if I open a .yaml.jinja or .html.jinja or similar file, I currently have to run :setf yaml.jinja (or similar) to get both filetypes' syntax highlighting.
Describe the solution you'd like
I'd like file ending in .foo.jinja to be detected as both foo and jinja, at least for common combinations like yaml and html.
Describe alternatives you've considered
I could set it up in my own ~/.vim/ftdetect, but this seems like something that other users would benefit from too.
Additional context
I'm not sure what the best way to actually implement this is, and I see 3 different ways in the existing code:
setf typescript.glimmer and setf javascript.glimmer for the relevant files. This seems like the simplest way to implement it for common file types that go with .jinja?—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hm, I was looking around in the filetype detection code and thought it must be possible for the current logic to detect dotted filetypes. But apparently this is not possible right now. I am not sure if I am not missing anything here.
So either we need to add a bunch of jinja patterns for the widely used jinja filetypes, or we need to think how we can somehow generalize it.
E.g. I tried with the following approach:
diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 46650e9c4..1f397f4ed 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -51,6 +51,15 @@ func s:StarSetf(ft) endif endfunc +func s:DottedFT(ft) + let ft = split(expand("<amatch>:r"), '\.') + if len(ft) > 1 + exe ':setf ' ft[-1] .. '.' .. a:ft + return + endif + exe 'setf ' a:ft +endfunc + " Vim help file au BufNewFile,BufRead $VIMRUNTIME/doc/*.txt setf help @@ -1244,7 +1253,7 @@ au BufNewFile,BufRead *.clp setf jess au BufNewFile,BufRead *.jgr setf jgraph " Jinja -au BufNewFile,BufRead *.jinja setf jinja +au BufNewFile,BufRead *.jinja call s:DottedFT('jinja') " Jujutsu au BufNewFile,BufRead *.jjdescription setf jjdescription
This would get us a dotted filetype for foobar.baz.jinja and while it seems to work for my very simple tests, this will potentially still set the wrong filetype. E.g. at my workplace we use java properties files with jinja extensions, but foobar.properties.jinja sets the filetype to properties.jinja instead of jproperties.jinja, so it does not really help here.
But then again, I might be missing something.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
This seems like a huge hack, but would it work to create a new hidden buffer with the .jinja extension stripped off so that the autocmds in filetype.vim run on that buffer. Then get the filetype from that buffer, combine it with jinja, and close the buffer? If that works, it would work for patterns other that just .foo.jinja too. E.g., /path/to/mypy/config.jinja would get the filetype dosini.jinja, in case that's useful to anyone.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I was thinking about my hack idea more, and I think there might be a less hacky way to accomplish it. What do you think about adding a new event for filetype detection, maybe FileTypeDetect or FileTypePre? That event would be triggered whenever BufNewFile or BufRead is triggered, but could also be triggered manually for .jinja files with <amatch> set to foo.bar and <afile> set to foo.bar.jinja. That would be a pretty big change to the filetype detection code, but I think it could be done in a backwards compatible way, and enable more generic handling of multiple filetypes for templating languages.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I have been thinking to use something like this chrisbra@de8165d
So we could use: :setfiletype SECONDARY jinja and later on combine this with the real filetype when using :setfiletype html which would then result in jinja.html (from filetype.vim):
" composed/dotted filetype au BufNewFile,BufRead ?\+.jinja \ setf SECONDARY jinja | \ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
I am not sure if this is a particular good idea or not, so would like to hear from others. (in particular setting b:current_syntax in jinja.vim` currently prevents loading other syntax files nevertheless) like @dkearns @yegappan and @gpanders for the jinja filetype.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
in particular setting b:current_syntax in jinja.vim` currently prevents loading other syntax files nevertheless
If you swap the order, it seems to work. E.g., setf html.jinja shows both html and jinja syntax highlighting, but jinja.html doesn't. I think that's because of #15885.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
In general, these filetypes don't work very well without, at least, the secondary filetype explicitly targeting primary filetypes to support. I think it's acceptable to require that the supported compound filetypes be enumerated in filetype.vim.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I think it's acceptable to require that the supported compound filetypes be enumerated in filetype.vim.
How about something like this then, to avoid duplicating the detection logic for supported filetypes, but still limit which filetypes are supported?
au BufNewFile,BufRead *.{j2,jinja,jinja2}
\ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
\ if index(["html", "yaml"], &ft) >= 0 | setl ft+=.jinja | else | setl ft=jinja | endifOr maybe move most of that into a function so that jinja can do this, and other templating languages can use the same function:
au BufNewFile,BufRead *.{j2,jinja,jinja2} call s:SecondaryFt("jinja", ["html", "yaml"])
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()