Skip to content

Instantly share code, notes, and snippets.

@oppara
Created October 6, 2011 14:25
Show Gist options
  • Save oppara/1267520 to your computer and use it in GitHub Desktop.
Save oppara/1267520 to your computer and use it in GitHub Desktop.
phptidy(phpStylist)
command! -range=0 PhpTidy call s:php_tidy(<count>, <line1>, <line2>)
function! s:php_tidy(has_range, line1, line2)
if !exists('g:php_tidy_tmp')
let g:php_tidy_tmp = '/path/to/php_tidy'
endif
if !exists('g:php_tidy_cmd')
let g:php_tidy_cmd = '/path/to/tools/phpStylist.sh '
endif
if a:has_range
call writefile(getline(a:line1, a:line2), g:php_tidy_tmp)
let l:res = system(g:php_tidy_cmd . g:php_tidy_tmp)
let l:res = substitute(l:res, '<?php\s*', '', "")
let l:res = substitute(l:res, '\s*?>$', '', "")
let l:lines = split(l:res, "\n")
" call delete(tmp)
execute ':silent ' . a:line1 . ',' . a:line2 . 'delete'
call append(a:line1 - 1, l:lines)
let l:cnt = len(l:lines) - 1
execute ':normal! kV' . (l:cnt) .'k'
execute ':normal! ='
else
execute ':normal mx'
execute ':%:!' . g:php_tidy_cmd . '%'
execute ':normal `x'
execute ':delmarks x'
endif
endfunction
#!/bin/sh
# http://sourceforge.net/projects/phpstylist/
php=`which php`
stylist="/path/to/phpStylist.php"
$php $stylist "$@" \
--indent_size 4 \
--line_before_comment_multi \
--keep_redundant_lines \
--space_after_comma \
--space_around_assignment \
--align_var_assignment \
--space_around_comparison \
--space_around_arithmetic \
--space_around_logical \
--space_around_colon_question \
--line_before_function \
--space_after_if \
--add_missing_braces \
--space_inside_for \
--indent_case \
--line_after_break \
--space_around_double_arrow \
--space_around_concat \
--vertical_array \
--align_array_assignment
@zeroasterisk
Copy link

@oppara
this looks exactly like what I've been looking for -- can you provide a bit more documentation or "how to install" for me, i'm newish to vim and uncertain how to implement... thought about releasing as a bundle?

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment