From 01e55b8535d97e92e79670fba123c15947a85f8b Mon Sep 17 00:00:00 2001 From: Andrew Barchuk Date: Sat, 5 Dec 2015 23:10:58 +0200 Subject: [PATCH 1/4] Add stylish-haskell prettifier --- README.md | 3 +++ plugin/defaults.vim | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 1afbd5b..985e8f8 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ Part of the Dart SDK (make sure it is on your PATH). See https://www.dartlang.or * `perltidy` for __Perl__. It can be installed from CPAN `cpanm Perl::Tidy` . See https://metacpan.org/pod/Perl::Tidy and http://perltidy.sourceforge.net/ for more info. +* `stylish-haskell` for __Haskell__ +It can be installed using [`cabal`](https://www.haskell.org/cabal/) build tool. Installation instructions are available at https://github.com/jaspervdj/stylish-haskell#installation + How can I change the behaviour of formatters, or add one myself? ---------------------------------------------------------------- If you need a formatter that is not among the defaults, or if you are not satisfied with the default formatting behaviour that is provided by vim-autoformat, you can define it yourself. diff --git a/plugin/defaults.vim b/plugin/defaults.vim index b922be4..0414afd 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -225,3 +225,12 @@ endif if !exists('g:formatters_perl') let g:formatters_perl = ['perltidy'] endif + +" Haskell +if !exists('g:formatdef_stylish_haskell') + let g:formatdef_stylish_haskell = '"stylish-haskell"' +endif + +if !exists('g:formatters_haskell') + let g:formatters_haskell = ['stylish_haskell'] +endif From b01c85e8f79e236274e52d078fb17a9f918dcd5a Mon Sep 17 00:00:00 2001 From: frtmelody Date: Sun, 13 Dec 2015 16:59:33 +0800 Subject: [PATCH 2/4] Update autoformat.vim disable gg=G --- plugin/autoformat.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index f8577fd..03607a3 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -61,7 +61,7 @@ function! s:TryAllFormatters(...) range " Make sure formatters are defined and detected if !call('find_formatters', a:000) " No formatters defined, so autoindent code - exe "normal gg=G" + " exe "normal gg=G" return 0 endif From 37a6b7f97912d8d11ff3b463ed1ed4e683cb8c1f Mon Sep 17 00:00:00 2001 From: MeLody Date: Mon, 14 Dec 2015 16:41:01 +0800 Subject: [PATCH 3/4] add swith to default gg=G --- plugin/autoformat.vim | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index 03607a3..edb9b71 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -1,5 +1,10 @@ " Function for finding the formatters for this filetype " Result is stored in b:formatters + +if !exists('g:autoformat_autoindent') + let g:autoformat_autoindent = 1 +endif + function! s:find_formatters(...) " Detect verbosity let verbose = &verbose || exists("g:autoformat_verbosemode") @@ -62,7 +67,13 @@ function! s:TryAllFormatters(...) range if !call('find_formatters', a:000) " No formatters defined, so autoindent code " exe "normal gg=G" - return 0 + if g:autoformat_autoindent == 1 + " No formatters defined, so autoindent code + exe "normal gg=G" + return 0 + else + return 0 + endif endif " Make sure index exist and is valid @@ -108,8 +119,13 @@ function! s:TryAllFormatters(...) range if s:index == b:current_formatter_index " Tried all formatters, none worked so autoindent code - exe "normal gg=G" - return 0 + if g:autoformat_autoindent == 1 + " No formatters defined, so autoindent code + exe "normal gg=G" + return 0 + else + return 0 + endif endif endwhile From 7902a12391568404eedc9b5d0b233131cb5ed444 Mon Sep 17 00:00:00 2001 From: Chiel ten Brinke Date: Tue, 15 Dec 2015 13:15:05 +0100 Subject: [PATCH 4/4] Cleanup and update README. --- README.md | 7 ++++++- plugin/autoformat.vim | 23 +++++++++-------------- plugin/defaults.vim | 12 +++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 985e8f8..3363837 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,13 @@ Or to have your code be formatted upon saving your file, you could use something au BufWrite * :Autoformat ``` +To disable the fallback to vim's indent file, set the following variable to be 0. +```vim +let g:autoformat_autoindent = 0 +``` + For each filetype, vim-autoformat has a list of applicable formatters. -If you have multiple formatters installed that are supported for some filetype, vim-autoformat just uses the first that occurs in this list of applicable formatters. +If you have multiple formatters installed that are supported for some filetype, vim-autoformat tries all formatters in this list of applicable formatters, until one succeeds. You can either set this list manually in your vimrc (see section *How can I change the behaviour of formatters, or add one myself?*, or change the formatter with the highest priority by the commands `:NextFormatter` and `:PreviousFormatter`. If you have a composite filetype with dots (like `django.python` or `php.wordpress`), vim-autoformat first tries to detect and use formatters for the exact original filetype, and then tries the same for all supertypes occuring from left to right in the original filetype separated by dots (`.`). diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index edb9b71..e6fc31c 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -7,7 +7,7 @@ endif function! s:find_formatters(...) " Detect verbosity - let verbose = &verbose || exists("g:autoformat_verbosemode") + let verbose = &verbose || g:autoformat_verbosemode == 1 " Extract filetype to be used let ftype = a:0 ? a:1 : &filetype @@ -65,15 +65,12 @@ endfunction function! s:TryAllFormatters(...) range " Make sure formatters are defined and detected if !call('find_formatters', a:000) - " No formatters defined, so autoindent code - " exe "normal gg=G" + " No formatters defined if g:autoformat_autoindent == 1 - " No formatters defined, so autoindent code + " Autoindent code exe "normal gg=G" - return 0 - else - return 0 endif + return 0 endif " Make sure index exist and is valid @@ -118,14 +115,12 @@ function! s:TryAllFormatters(...) range endif if s:index == b:current_formatter_index - " Tried all formatters, none worked so autoindent code + " Tried all formatters, none worked if g:autoformat_autoindent == 1 - " No formatters defined, so autoindent code + " Autoindent code exe "normal gg=G" - return 0 - else - return 0 endif + return 0 endif endwhile @@ -139,7 +134,7 @@ endfunction " +python version function! s:TryFormatterPython() " Detect verbosity - let verbose = &verbose || exists("g:autoformat_verbosemode") + let verbose = &verbose || g:autoformat_verbosemode == 1 python << EOF import vim, subprocess, os @@ -187,7 +182,7 @@ endfunction " +python3 version function! s:TryFormatterPython3() " Detect verbosity - let verbose = &verbose || exists("g:autoformat_verbosemode") + let verbose = &verbose || g:autoformat_verbosemode == 1 python3 << EOF import vim, subprocess, os diff --git a/plugin/defaults.vim b/plugin/defaults.vim index 0414afd..cc36fa0 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -1,8 +1,18 @@ " -" This file contains all default format program definitions and links them to filetypes +" This file contains default settings and all format program definitions and links these to filetypes " +" Vim-autoformat configuration variables +if !exists('g:autoformat_autoindent') + let g:autoformat_verbosemode = 0 +endif + +if !exists('g:autoformat_verbosemode') + let g:autoformat_verbosemode = 0 +endif + + " Python if !exists('g:formatdef_autopep8') let g:formatdef_autopep8 = '"autopep8 - --range ".a:firstline." ".a:lastline." ".(&textwidth ? "--max-line-length=".&textwidth : "")'