Readme update, samples added, bugifx defaults

This commit is contained in:
Chiel92 2013-03-16 12:21:55 +01:00
parent c73d350fbb
commit cf21fe7489
5 changed files with 40 additions and 32 deletions

View File

@ -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 `<filetype>` is defined in `g:formatprg_<filetype>`.
The arguments passed to the formatprogram are defined in `g:formatprg_args_<filetype>`.
The arguments passed to the formatprogram are defined in `g:formatprg_args_expr_<filetype>` as an expression which can be evaluated, or else in `g:formatprg_args_<filetype>` 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
*

View File

@ -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

View File

@ -1 +0,0 @@
<?php mysql_connect("localhost", "root", ""); echo "foo"; mysql_select_db("mydatabase"); $query = "SELECT id, title FROM mytable ORDER BY title"; $result = mysql_query($query); echo "Total number of fields returned: " . mysql_num_fields($result) . ".<br />"; 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); } } } ?>

1
samples/xhtml.xhtml Normal file
View File

@ -0,0 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> </title></head><body> <script type="text/javascript">function bla(foo) { }</script><br /> <form> <input type="text" name="NUMBER" onkeypress= "RETURN ISnUMBERkEY(EVENT)" /> </form></body></html>

1
samples/xml.xml Normal file
View File

@ -0,0 +1 @@
<catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> <book id="bk103"> <author>Corets, Eva</author> <title>Maeve Ascendant</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-11-17</publish_date> <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description> </book> <book id="bk104"> <author>Corets, Eva</author> <title>Oberon's Legacy</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2001-03-10</publish_date> <description>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.</description> </book> <book id="bk105"> <author>Corets, Eva</author> <title>The Sundered Grail</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2001-09-10</publish_date> <description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description> </book> <book id="bk106"> <author>Randall, Cynthia</author> <title>Lover Birds</title> <genre>Romance</genre> <price>4.95</price> <publish_date>2000-09-02</publish_date> <description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description> </book> <book id="bk107"> <author>Thurman, Paula</author> <title>Splish Splash</title> <genre>Romance</genre> <price>4.95</price> <publish_date>2000-11-02</publish_date> <description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description> </book> <book id="bk108"> <author>Knorr, Stefan</author> <title>Creepy Crawlies</title> <genre>Horror</genre> <price>4.95</price> <publish_date>2000-12-06</publish_date> <description>An anthology of horror stories about roaches, centipedes, scorpions and other insects.</description> </book> <book id="bk109"> <author>Kress, Peter</author> <title>Paradox Lost</title> <genre>Science Fiction</genre> <price>6.95</price> <publish_date>2000-11-02</publish_date> <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description> </book> <book id="bk110"> <author>O'Brien, Tim</author> <title>Microsoft .NET: The Programming Bible</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-09</publish_date> <description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description> </book> <book id="bk111"> <author>O'Brien, Tim</author> <title>MSXML3: A Comprehensive Guide</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-01</publish_date> <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description> </book> <book id="bk112"> <author>Galos, Mike</author> <title>Visual Studio 7: A Comprehensive Guide</title> <genre>Computer</genre> <price>49.95</price> <publish_date>2001-04-16</publish_date> <description>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.</description> </book></catalog>