Skip to content

Commit

Permalink
added fix for composite filetypes
Browse files Browse the repository at this point in the history
Now, instead of spitting an error message into (n)vim's messages,
the composite filetype is split and the first filetype is used.
e.g. `javascript.jsx` --> `javascript`
  • Loading branch information
sbdchd committed Sep 24, 2016
1 parent f70ea87 commit c15243a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions autoload/neoformat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ function! neoformat#Neoformat(user_formatter) abort
if !empty(a:user_formatter)
let formatter = a:user_formatter
else
let formatters = s:get_enabled_formatters(&filetype)
let filetype = s:split_filetypes(&filetype)
let formatters = s:get_enabled_formatters(filetype)
if formatters == []
call neoformat#utils#msg('formatter not defined for ' . &filetype . ' filetype')
call neoformat#utils#msg('formatter not defined for ' . filetype . ' filetype')
return neoformat#format#BasicFormat()
endif

Expand All @@ -26,10 +27,10 @@ function! neoformat#Neoformat(user_formatter) abort
let formatter = formatters[s:current_formatter_index]
endif

if exists('g:neoformat_' . &filetype . '_' . formatter)
let definition = g:neoformat_{&filetype}_{formatter}
elseif s:autoload_func_exists('neoformat#formatters#' . &filetype . '#' . formatter)
let definition = neoformat#formatters#{&filetype}#{formatter}()
if exists('g:neoformat_' . filetype . '_' . formatter)
let definition = g:neoformat_{filetype}_{formatter}
elseif s:autoload_func_exists('neoformat#formatters#' . filetype . '#' . formatter)
let definition = neoformat#formatters#{filetype}#{formatter}()
else
call neoformat#utils#log('definition not found for formatter: ' . formatter)
if !empty(a:user_formatter)
Expand All @@ -39,7 +40,7 @@ function! neoformat#Neoformat(user_formatter) abort
return neoformat#NextNeoformat()
endif

let cmd = neoformat#cmd#generate(definition)
let cmd = neoformat#cmd#generate(definition, filetype)
if cmd == {}
if !empty(a:user_formatter)
return neoformat#utils#log('user specified formatter failed')
Expand All @@ -63,7 +64,8 @@ function! neoformat#CompleteFormatters(ArgLead, CmdLine, CursorPos)
if a:ArgLead =~ '[^A-Za-z0-9]'
return []
endif
return filter(s:get_enabled_formatters(&filetype),
let filetype = s:split_filetypes(&filetype)
return filter(s:get_enabled_formatters(filetype),
\ "v:val =~? '^" . a:ArgLead ."'")
endfunction

Expand All @@ -81,3 +83,7 @@ function! s:autoload_func_exists(func_name)
endtry
return 1
endfunction

function! s:split_filetypes(filetype)
return split(a:filetype, '\.')[0]
endfunction
4 changes: 2 additions & 2 deletions autoload/neoformat/cmd.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function! neoformat#cmd#generate(definition) abort
function! neoformat#cmd#generate(definition, filetype) abort
let cmd = get(a:definition, 'exe', '')
if cmd == ''
call neoformat#utils#log('no exe field in definition')
Expand Down Expand Up @@ -51,7 +51,7 @@ function! neoformat#cmd#generate(definition) abort
\ 'no_append': no_append,
\ 'path': path,
\ 'replace': replace,
\ 'filetype': &filetype
\ 'filetype': a:filetype
\ }
endfunction

Expand Down

0 comments on commit c15243a

Please sign in to comment.