From e94180e2f4448c15df49d2914dfb733f5c0c879f Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Sun, 2 Dec 2012 17:12:49 +0100 Subject: [PATCH] formatter finding implemented --- ftplugin/python.vim | 12 +++++++----- plugin/autoformat.vim | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ftplugin/python.vim b/ftplugin/python.vim index 5cc8c1c..396cbff 100644 --- a/ftplugin/python.vim +++ b/ftplugin/python.vim @@ -1,5 +1,7 @@ -let s:prgpath = "autopep8" -let s:arguments = " /dev/stdin" -if executable(s:prgpath) - let &formatprg=s:prgpath." ".s:arguments -endif +"Set the formatter name and arguments for this filetype +let s:prgname = "autopep9" +let s:arguments = "/dev/stdin" + +"Set the formatprg option, if the formatter is installed +"globally or in the formatters folder +call g:FindFormatter(s:prgname, s:arguments) diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index be844ca..45a3cc5 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -2,7 +2,6 @@ function! s:Autoformat() "If a formatprg is specified if &formatprg!="" - "echo "formatprg is: ".&formatprg "Save window state let winview=winsaveview() "Autoformat code @@ -16,3 +15,21 @@ endfunction "Create a command for this command! Autoformat call s:Autoformat() + +"Function for finding and setting the formatter +"with the given name, if the formatter is installed +"globally or in the formatters folder +let s:formatterdir = fnamemodify(expand(""), ":h:h")."/formatters/" +function! s:FindFormatter(name, args) + if executable(a:name) + let s:prgpath = a:name + else + let s:bars = expand("") + let s:prgpath = s:formatterdir.a:name + endif + + if executable(s:prgpath) + let &formatprg=s:prgpath." ".a:args + endif +endfunction +