From cf21fe74895575c7127e9c6f9642fa6da5dcfd34 Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Sat, 16 Mar 2013 12:21:55 +0100 Subject: [PATCH] Readme update, samples added, bugifx defaults --- README.markdown | 33 +++++++++++---------------------- plugin/defaults.vim | 36 +++++++++++++++++++++++++++--------- samples/php.php | 1 - samples/xhtml.xhtml | 1 + samples/xml.xml | 1 + 5 files changed, 40 insertions(+), 32 deletions(-) delete mode 100644 samples/php.php create mode 100644 samples/xhtml.xhtml create mode 100644 samples/xml.xml diff --git a/README.markdown b/README.markdown index 992d8d4..e9793fa 100644 --- a/README.markdown +++ b/README.markdown @@ -62,32 +62,18 @@ How can I change the behaviour of formatters? --------------------------------------------- If you are not satisfied with the default configuration for a certain filetype, you can override it by defining it yourself. The formatprogram used for a `` is defined in `g:formatprg_`. -The arguments passed to the formatprogram are defined in `g:formatprg_args_`. +The arguments passed to the formatprogram are defined in `g:formatprg_args_expr_` as an expression which can be evaluated, or else in `g:formatprg_args_` as a plain string. The formatprogram must read the unformatted code from the standard input, and write the formatted code to the standard output. -By defining one or both of these variable in your .vimrc, you override any possible default value. +Defining any of these variable in your .vimrc, will override the default value. So, a complete definition for C# files could look like this: ```vim let g:formatprg_cs = "astyle" -let g:formatprg_args_cs = "--mode=cs --style=ansi -p -c -H" -``` - -By default vim-autoformat equals `tabstop`, `softtabstop` and `shiftwidth` to 4 and sets `expandtab`, matching the default configuration for the default formatprograms. -This overwrites these options from your .vimrc. -If you don't want vim-autoformat to set these options, put this line in your .vimrc. - -```vim -let g:autoformat_no_default_shiftwidth = 1 -``` - - -If you change the tabwidth for a certain formatprogram, I would suggest to change the indent options of vim correspondingly for that filetype. - -```vim -au filetype *.cs set tabstop=2 -au filetype *.cs set softtabstop=2 -au filetype *.cs set shiftwidth=2 +let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi -pcHs".&softtabstop' ``` +Notice that `g:formatprg_args_expr_cs` can be evaluated. +As you see, this allows us to take user defined options into account. +In this case, the indent width that astyle will use, depends on the value of `&softtabstop`. Todo list @@ -97,13 +83,13 @@ Todo list * Create a help file -If you have any suggestions on this plugin or on this readme, if you think some default formatprg definition is missing, or if you experience problems, please contact me by creating an issue in this repository. +If you have any suggestions on this plugin or on this readme, if you think some formatprg definition should be added to the defaults, or if you experience problems, please contact me by creating an issue in this repository. You can also send a message to ctje92 at gmail dot com. Change log ---------- ### March 9 2013 -The custom_config branch has been merged into the master branch. +The `custom_config` branch has been merged into the master branch. * Customization of formatprograms can be done easily now, as explained above. * I set the default tabwidth to 4 for all formatprograms as well as for vim itself. * The default parameters for astyle have been slightly modified: it will wrap spaces around operators. @@ -115,3 +101,6 @@ The custom_config branch has been merged into the master branch. ### March 13 2013 * It is now possible to prevent vim-autoformat from overwriting your settings for `tabstop`, `softtabstop`, `shiftwidth` and `expandtab` in your .vimrc. +### March 16 2013 +The `dynamic_indent_width` branch has been merged into the master branch +* diff --git a/plugin/defaults.vim b/plugin/defaults.vim index f36ff44..732f9e2 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -1,24 +1,42 @@ if !exists("g:formatprg_cs") | let g:formatprg_cs = "astyle" | endif -if !exists("g:formatprg_args_cs") | let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi -pcHs".&softtabstop' | endif +if !exists("g:formatprg_args_expr_cs") + let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi -pcHs".&softtabstop' +endif if !exists("g:formatprg_c") | let g:formatprg_c = "astyle" | endif -if !exists("g:formatprg_args_c") | let g:formatprg_args_expr_c = '"--mode=c --style=ansi -pcHs".&softtabstop' | endif +if !exists("g:formatprg_args_expr_c") + let g:formatprg_args_expr_c = '"--mode=c --style=ansi -pcHs".&softtabstop' +endif if !exists("g:formatprg_cpp") | let g:formatprg_cpp = "astyle" | endif -if !exists("g:formatprg_args_cpp") | let g:formatprg_args_expr_cpp = '"--mode=c --style=ansi -pcHs".&softtabstop' | endif +if !exists("g:formatprg_args_expr_cpp") + let g:formatprg_args_expr_cpp = '"--mode=c --style=ansi -pcHs".&softtabstop' +endif if !exists("g:formatprg_java") | let g:formatprg_java = "astyle" | endif -if !exists("g:formatprg_args_java") | let g:formatprg_args_expr_java = '"--mode=java --style=ansi -pcHs".&softtabstop' | endif +if !exists("g:formatprg_args_expr_java") + let g:formatprg_args_expr_java = '"--mode=java --style=ansi -pcHs".&softtabstop' +endif if !exists("g:formatprg_python") | let g:formatprg_python = "autopep8" | endif -if !exists("g:formatprg_args_python") | let g:formatprg_args_expr_python = '"/dev/stdin"' | endif +if !exists("g:formatprg_args_expr_python") + let g:formatprg_args_expr_python = '"/dev/stdin"' +endif if !exists("g:formatprg_xml") | let g:formatprg_xml = "tidy" | endif -if !exists("g:formatprg_args_xml") | let g:formatprg_args_expr_xml = '"-q -xml --show-errors 10 --show-warnings 10 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68"' | endif +if !exists("g:formatprg_args_expr_xml") + let g:formatprg_args_expr_xml = '"-q -xml --show-errors 10 --show-warnings 10 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68"' +endif + if !exists("g:formatprg_html") | let g:formatprg_html = "tidy" | endif -if !exists("g:formatprg_args_html") | let g:formatprg_args_expr_html = '"-q --show-errors 0 --show-warnings 0 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68"' | endif +if !exists("g:formatprg_args_expr_html") + let g:formatprg_args_expr_html = '"-q --show-errors 0 --show-warnings 0 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68"' +endif + if !exists("g:formatprg_xhtml") | let g:formatprg_xhtml = "tidy" | endif -if !exists("g:formatprg_args_xhtml") | let g:formatprg_args_expr_xhtml = '"-q --show-errors 0 --show-warnings 0 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68 -asxhtml"' | endif +if !exists("g:formatprg_args_expr_xhtml") + let g:formatprg_args_expr_xhtml = '"-q --show-errors 0 --show-warnings 0 --indent auto --indent-spaces ".&softtabstop." --vertical-space yes --tidy-mark no --wrap 68 -asxhtml"' +endif if !exists("g:formatprg_javascript") let g:formatprg_javascript = "js-beautify" @@ -31,6 +49,6 @@ if !exists("g:formatprg_javascript") let g:formatprg_javascript = s:jsbeautify_alternative endif endif -if !exists("g:formatprg_args_javascript") +if !exists("g:formatprg_args_expr_javascript") let g:formatprg_args_expr_javascript = '"-i -s".&softtabstop' endif diff --git a/samples/php.php b/samples/php.php deleted file mode 100644 index 2459170..0000000 --- a/samples/php.php +++ /dev/null @@ -1 +0,0 @@ -"; class phpVimeo { const API_REST_URL = 'http://vimeo.com/api/rest/v2'; const API_AUTH_URL = 'http://vimeo.com/oauth/authorize'; const API_ACCESS_TOKEN_URL = 'http://vimeo.com/oauth/access_token'; const API_REQUEST_TOKEN_URL = 'http://vimeo.com/oauth/request_token'; const CACHE_FILE = 'file'; private $_consumer_key = false; private $_consumer_secret = false; private $_cache_enabled = false; private $_cache_dir = false; private $_token = false; private $_token_secret = false; private $_upload_md5s = array(); public function __construct($consumer_key, $consumer_secret, $token = null, $token_secret = null){ $this -> _consumer_key = $consumer_key; $this -> _consumer_secret = $consumer_secret; if ($token && $token_secret) { $this -> setToken($token, $token_secret); } } } ?> diff --git a/samples/xhtml.xhtml b/samples/xhtml.xhtml new file mode 100644 index 0000000..9a90555 --- /dev/null +++ b/samples/xhtml.xhtml @@ -0,0 +1 @@ +
diff --git a/samples/xml.xml b/samples/xml.xml new file mode 100644 index 0000000..1e0e44f --- /dev/null +++ b/samples/xml.xml @@ -0,0 +1 @@ + Gambardella, Matthew XML Developer's Guide Computer 44.95 2000-10-01 An in-depth look at creating applications with XML. Ralls, Kim Midnight Rain Fantasy 5.95 2000-12-16 A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world. Corets, Eva Maeve Ascendant Fantasy 5.95 2000-11-17 After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society. Corets, Eva Oberon's Legacy Fantasy 5.95 2001-03-10 In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant. Corets, Eva The Sundered Grail Fantasy 5.95 2001-09-10 The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy. Randall, Cynthia Lover Birds Romance 4.95 2000-09-02 When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled. Thurman, Paula Splish Splash Romance 4.95 2000-11-02 A deep sea diver finds true love twenty thousand leagues beneath the sea. Knorr, Stefan Creepy Crawlies Horror 4.95 2000-12-06 An anthology of horror stories about roaches, centipedes, scorpions and other insects. Kress, Peter Paradox Lost Science Fiction 6.95 2000-11-02 After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum. O'Brien, Tim Microsoft .NET: The Programming Bible Computer 36.95 2000-12-09 Microsoft's .NET initiative is explored in detail in this deep programmer's reference. O'Brien, Tim MSXML3: A Comprehensive Guide Computer 36.95 2000-12-01 The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more. Galos, Mike Visual Studio 7: A Comprehensive Guide Computer 49.95 2001-04-16 Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.