Fix #13 and some cleanup.

This commit is contained in:
Chiel92 2013-12-20 20:34:38 +01:00
parent 1e20517276
commit 66995c00d1
4 changed files with 60 additions and 70 deletions

View File

@ -35,7 +35,6 @@ For using a custom formatprogram, read the text below *How can I change the beha
If the formatprogram you want to use is installed correctly, in one of the following ways, vim automatically detects it.
* It suffices to make the formatprogram globally available, which is the case if you install it via your package manager.
* Alternatively you can point vim to the the binary by explicitly putting the absolute path in `g:formatprg_<filetype>` in your .vimrc.
* A third way to make vim detect the formatprogram, is by putting its binary (or a link to it) in the `formatters/` directory within the directory of vim-autoformat.
Remember that when no formatprogram exists for a certain filetype, vim-autoformat uses vim's indent functionality as a fallback.
This will fix at least the indentation of your code, according to vim's indentfile for that filetype.
@ -62,19 +61,23 @@ It's probably in your distro's repository, so you can download it as a regular p
For Ubuntu type `sudo apt-get install astyle` in a terminal.
Otherwise, download it here: http://astyle.sourceforge.net/.
* `jsbeautify` (the python CLI version) for __Javascript__.
This one can also be installed as a vundle package, and I recommend to do so.
Put this in your .vimrc: `Bundle "einars/js-beautify"`.
Note that we're only using the python version, so `node` doesn't have to be installed.
Here is the link to the repository: https://github.com/einars/js-beautify.
* `autopep8` for __Python__.
It's probably in your distro's repository, so you can download it as a regular package.
For Ubuntu type `sudo apt-get install autopep8` in a terminal.
Here is the link to the repository: https://github.com/hhatto/autopep8.
And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2.
* `tidy` for __HTML__ ( __not HTML5__, tidy cannot handle the new tags sadly), __XHTML__ and __XML__.
* `js-beautify` for __Javascript__.
It can be installed by running `npm install -g js-beautify`.
Note that `nodejs` is needed for this to work.
Here is the link to the repository: https://github.com/einars/js-beautify.
* `html-beautify` for __HTML__.
It is shipped with `js-beautify`, which can be installed by running `npm install -g js-beautify`.
Note that `nodejs` is needed for this to work.
Here is the link to the repository: https://github.com/einars/js-beautify.
* `tidy` for __XHTML__ and __XML__.
It's probably in your distro's repository, so you can download it as a regular package.
For Ubuntu type `sudo apt-get install tidy` in a terminal.
@ -110,31 +113,27 @@ This means that the formatting style will match your current vim settings as muc
For the exact default definitions, have a look in `vim-autoformat/plugin/defaults.vim`.
Todo list
---------
Things that are not (yet) implemented
----------------------------------------------------------
* Check for windows support.
* Option for on-the-fly code-formatting, like visual studio (If ever. When you have a clever idea about how to do this, i'd be glad to hear.)
* Create a help file.
* Option for on-the-fly code-formatting, like visual studio (If ever. When you have a clever idea about how to do this, I'd be glad to hear.)
If you have any suggestions on this plugin or on this readme, if you have some nice default formatprg definition that can be added to the defaults, or if you experience problems, please contact me by creating an issue in this repository.
Pull requests are welcome.
Any feedback is welcome.
If you have any suggestions on this plugin or on this readme, if you have some nice default formatprg definition that can be added to the defaults, or if you experience problems, please contact me by creating an issue in this repository.
Change log
----------
### March 9 2013
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.
* phpCB has been removed from the defaults, due to code-breaking behaviour.
* XHTML default definition added
### December 20 2013
* `html-beautify` is now the default for HTML since it seems to be better maintained, and seems to handle inline javascript neatly.
* The `formatters/` folder is no longer supported anymore, because it is unnecessary.
* `js-beautify` can no longer be installed as a bundle, since it only makes this plugin unnecessarily complex.
### March 10 2013
* When no formatter is installed or defined, vim will now auto-indent the file instead. This uses the indentfile for that specific filetype.
### 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 27 2013
* The default behaviour of gq is enabled again by removing the fallback on auto-indenting.
Instead, the fallback is only used when running the command `:Autoformat`.
* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting.
This extends the way the formatting style will match your current vim settings.
### March 16 2013
The `dynamic_indent_width` branch has been merged into the master branch.
@ -142,8 +141,16 @@ The `dynamic_indent_width` branch has been merged into the master branch.
* This obsoletes `g:autoformat_no_default_shiftwidth`
* `g:formatprg_args_expr_<filetype>` is introduced.
### March 27 2013
* The default behaviour of gq is enabled again by removing the fallback on auto-indenting.
Instead, the fallback is only used when running the command `:Autoformat`.
* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting.
This extends the way the formatting style will match your current vim settings.
### 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 10 2013
* When no formatter is installed or defined, vim will now auto-indent the file instead. This uses the indentfile for that specific filetype.
### March 9 2013
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.
* phpCB has been removed from the defaults, due to code-breaking behaviour.
* XHTML default definition added

View File

@ -1,3 +0,0 @@
Formatprograms that are put here will be detected.
Note that globally available programs are also detected.
Read the general README.markdown file for more info on which formatprograms are supported.

View File

@ -1,6 +1,4 @@
"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("<sfile>"), ":p:h:h")."/formatters/"
"Function for finding and setting the formatter with the given name
function! s:set_formatprg()
"Get formatprg config for current filetype
let s:formatprg_var = "g:formatprg_".&filetype
@ -25,14 +23,11 @@ function! s:set_formatprg()
"Set correct formatprg path, if it is installed
if !executable(s:formatprg)
let s:formatprg = s:formatterdir.s:formatprg
if !executable(s:formatprg)
"Configured formatprg not installed
if exists("g:autoformat_verbosemode")
echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable."
endif
return 0
"Configured formatprg not installed
if exists("g:autoformat_verbosemode")
echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable."
endif
return 0
endif
let &formatprg = s:formatprg." ".s:formatprg_args

View File

@ -28,27 +28,18 @@ if !exists("g:formatprg_args_expr_xml") && !exists("g:formatprg_args_xml")
let g:formatprg_args_expr_xml = '"-q -xml --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth'
endif
if !exists("g:formatprg_html") | let g:formatprg_html = "tidy" | endif
if !exists("g:formatprg_args_expr_html") && !exists("g:formatprg_args_html")
let g:formatprg_args_expr_html = '"-q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth'
endif
if !exists("g:formatprg_xhtml") | let g:formatprg_xhtml = "tidy" | endif
if !exists("g:formatprg_args_expr_xhtml") && !exists("g:formatprg_args_xhtml")
let g:formatprg_args_expr_xhtml = '"-q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -asxhtml -wrap ".&textwidth'
endif
if !exists("g:formatprg_javascript")
let g:formatprg_javascript = "js-beautify"
if !exists("g:formatprg_html") | let g:formatprg_html = "html-beautify" | endif
if !exists("g:formatprg_args_expr_html") && !exists("g:formatprg_args_html")
let g:formatprg_args_expr_html = '"-f -"'
endif
"We allow an alternative path for js-beautify
"If js-beautify is installed as a bundle, we still want to detect it
let s:bundleDir = fnamemodify(expand("<sfile>"), ":h:h:h")
let s:jsbeautify_alternative = s:bundleDir."/js-beautify/python/".g:formatprg_javascript
if executable(s:jsbeautify_alternative)
let g:formatprg_javascript = s:jsbeautify_alternative
endif
endif
if !exists("g:formatprg_javascript") | let g:formatprg_javascript = "js-beautify" | endif
if !exists("g:formatprg_args_expr_javascript") && !exists("g:formatprg_args_javascript")
let g:formatprg_args_expr_javascript = '"-i -s".&shiftwidth'
let g:formatprg_args_expr_javascript = '"-f - -s".&shiftwidth'
endif