Commit 99cde1c5 authored by HiPhish's avatar HiPhish
Browse files

Detect compound file types as well

parent a9367337
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -21,6 +21,13 @@ Jinja documentation:

.. _Jinja: http://jinja.pocoo.org/

Jinja.vim even  goes the  extra mile  and recognises file  names with  two file
types like `foo.html.jinja`  correctly as `html.jinja`. At the same  time it is
clever  enough to  know that  `foo.deprecated.jinja` is  of type  `jinja` alone
since `deprecated` is not a file type Vim knows about (unless you have a plugin
that would support  such a type of  course). This works recursively,  so if the
first file type could be a compound as well Vim will take care of it.


Installation
============
@@ -66,10 +73,6 @@ authors' attention; fixing the issue once in that plugin will forever benefit
everyone while applying a  hack to my plugin is just  shoving the problem under
the rug for the time being.

Another issue is detection of files  with compound names, such as `.html.jina`;
I don't know how to handle them and  the resulting file type will be just plain
`jinja`. Help would be greatly appreciated.


License
#######
+13 −1
Original line number Diff line number Diff line
@@ -27,4 +27,16 @@
" 'html.jinja' instead of just 'jinja'. However, we cannot simply take
" everything after the first dot as the file type because something like
" `main.macros.html.jinja` would get the wrong file type as well.
autocmd! BufRead,BufNewFile *.jinja  setfiletype jinja
autocmd! BufRead,BufNewFile *.jinja  call <SID>DetectFileExtension(expand('<afile>'))

" Detect a normal or compound file extension (like 'foo.html.jinja')
function! s:DetectFileExtension(fname)
	" This will fail setting the file type of unknown file extension like
	" 'foo.nonsense.jinja', which is what we want.
	execute 'doautocmd BufReadPost' fnamemodify(a:fname, ':r')
    if empty(&filetype)
        set filetype=jinja
    else
        set filetype+=.jinja
    endif
endfunction

test/ftdetect.vader

0 → 100644
+37 −0
Original line number Diff line number Diff line
####################################################
# Detection of Jinja files based of file extension #
####################################################

Execute (A simple file extension):
  silent file foo.jinja
  filetype detect

Then:
  AssertEqual 'jinja', &filetype


Execute (Two file extensions):
  silent file foo.html.jinja
  filetype detect

Then:
  AssertEqual 'html.jinja', &filetype


Execute (Three file extensions):
  silent file foo.tex.html.jinja
  filetype detect

Then:
  AssertEqual 'html.jinja', &filetype


# I really hope there is no 'nonsense' file format out there
Execute (Nonsense file extensions):
  silent file foo.nonsense.jinja
  filetype detect

Then:
  AssertEqual 'jinja', &filetype

+3 −3
Original line number Diff line number Diff line
##############################################################
# Test detection of various Jinja elements in a non-jinja file
##############################################################
################################################################
# Test detection of various Jinja elements in a non-jinja file #
################################################################

Given jinja (A comment):
  {# A jinja comment #}