From c15243abdbfef8d0c6d626d6f3676f3694e13131 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Fri, 23 Sep 2016 20:58:39 -0400 Subject: [PATCH] added fix for composite filetypes 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` --- autoload/neoformat.vim | 22 ++++++++++++++-------- autoload/neoformat/cmd.vim | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/autoload/neoformat.vim b/autoload/neoformat.vim index 9d14f4ab..788a36eb 100644 --- a/autoload/neoformat.vim +++ b/autoload/neoformat.vim @@ -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 @@ -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) @@ -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') @@ -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 @@ -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 diff --git a/autoload/neoformat/cmd.vim b/autoload/neoformat/cmd.vim index 9562f392..1571bec7 100644 --- a/autoload/neoformat/cmd.vim +++ b/autoload/neoformat/cmd.vim @@ -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') @@ -51,7 +51,7 @@ function! neoformat#cmd#generate(definition) abort \ 'no_append': no_append, \ 'path': path, \ 'replace': replace, - \ 'filetype': &filetype + \ 'filetype': a:filetype \ } endfunction