From 19b7a6437bd0e98befba42129957acf680611483 Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Sat, 1 Dec 2012 14:06:28 +0100 Subject: [PATCH] python support and no error into buffer when formatter not installed --- ftplugin/javascript.vim | 11 +++++++---- ftplugin/php.vim | 7 +++++-- ftplugin/python.vim | 5 +++++ plugin/autoformat.vim | 18 ++++++++++++------ 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 ftplugin/python.vim diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 5a5c7ac..0f0a9b8 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -1,7 +1,10 @@ -let s:CliOptions = "-d" let s:bundleDir = fnamemodify(expand(""), ":h:h:h") -let &formatprg=s:bundleDir."/js-beautify/python/js-beautify -i ".s:CliOptions +let s:prgpath = s:bundleDir."/js-beautify/python/js-beautify" +let s:arguments = "-i" +if executable(s:prgpath) + let &formatprg=s:prgpath." ".s:arguments +endif set expandtab -set tabstop=4 -set shiftwidth=4 +set tabstop = 4 +set shiftwidth = 4 diff --git a/ftplugin/php.vim b/ftplugin/php.vim index 39cdbdf..c635613 100644 --- a/ftplugin/php.vim +++ b/ftplugin/php.vim @@ -1,2 +1,5 @@ -let &formatprg="phpCB --space-after-if --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --one-true-brace-function-declaration --glue-amperscore --change-shell-comment-to-double-slashes-comment --force-large-php-code-tag --force-true-false-null-contant-lowercase --align-equal-statements --comment-rendering-style PEAR --equal-align-position 50 --padding-char-count 4" - +let s:prgpath-"phpCB" +let s:arguments="--space-after-if --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --one-true-brace-function-declaration --glue-amperscore --change-shell-comment-to-double-slashes-comment --force-large-php-code-tag --force-true-false-null-contant-lowercase --align-equal-statements --comment-rendering-style PEAR --equal-align-position 50 --padding-char-count 4" +if executable(s:prgpath) + let &formatprg=s:prgpath." ".s:arguments +endif diff --git a/ftplugin/python.vim b/ftplugin/python.vim new file mode 100644 index 0000000..5cc8c1c --- /dev/null +++ b/ftplugin/python.vim @@ -0,0 +1,5 @@ +let s:prgpath = "autopep8" +let s:arguments = " /dev/stdin" +if executable(s:prgpath) + let &formatprg=s:prgpath." ".s:arguments +endif diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index 37792dd..3e1b90a 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -1,9 +1,15 @@ "Function for formatting the entire buffer function! g:Autoformat() - "Save window state - let winview=winsaveview() - "Autoformat code - :silent exe "normal gggqG" - "Recall window state - call winrestview(winview) + "If a formatprg is specified + if &formatprg!="" + "echo "formatprg is: ".&formatprg + "Save window state + let winview=winsaveview() + "Autoformat code + :silent exe "normal gggqG" + "Recall window state + call winrestview(winview) + else + echo "No formatter installed for this filetype" + endif endfunction