Skip to content

Commit 3300b32

Browse files
authored
Merge pull request #4 from Andrwe/master
implemented detection for mixed usage of .template
2 parents 62ef848 + e96b5c4 commit 3300b32

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ftdetect/cloudformation.vim

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function! DetectCfn(type)
1+
function! DetectCfn()
22
let likely = 0
33
let pointsRequired = 10
44

@@ -50,16 +50,20 @@ function! DetectCfn(type)
5050
\['Resources', 1],
5151
\['Outputs', 1],
5252
\]
53+
let json_type = 0
5354
for lineContents in getline(1, line('$'))
5455
for strPoints in pointMap
5556
if lineContents =~ strPoints[0]
5657
let likely += strPoints[1]
5758
endif
59+
if lineContents =~ "^\s*\{"
60+
let json_type = 1
61+
endif
5862
if likely > pointsRequired
59-
if a:type =~ "yaml"
60-
set filetype=yaml.cloudformation
61-
elseif a:type =~ "json"
63+
if json_type == 1
6264
set filetype=json.cloudformation
65+
else
66+
set filetype=yaml.cloudformation
6367
endif
6468
return
6569
endif
@@ -68,7 +72,7 @@ function! DetectCfn(type)
6872
endfunction
6973

7074
augroup filetypedetect
71-
au BufRead,BufNewFile *.yaml,*.yml call DetectCfn('yaml')
72-
au BufRead,BufNewFile *.json call DetectCfn('json')
73-
au BufNewFile,BufRead *.template setfiletype yaml.cloudformation
75+
au BufRead,BufNewFile *.yaml,*.yml call DetectCfn()
76+
au BufRead,BufNewFile *.json call DetectCfn()
77+
au BufNewFile,BufRead *.template call DetectCfn()
7478
augroup END

0 commit comments

Comments
 (0)