vim: improve indent_finder
This commit is contained in:
parent
482935d5b6
commit
87b97ee5bd
@ -8,6 +8,7 @@
|
||||
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
|
||||
help = \
|
||||
"""Usage : %s [ --vim-output ] [ --verbose ] file1 file2 ... fileN
|
||||
@ -437,20 +438,23 @@ class IndentFinder:
|
||||
def main():
|
||||
VIM_OUTPUT = 0
|
||||
|
||||
file_list = []
|
||||
for opt in sys.argv[1:]:
|
||||
if opt == "--vim-output":
|
||||
VIM_OUTPUT = 1
|
||||
elif opt == "--verbose" or opt == '-v':
|
||||
IndentFinder.VERBOSITY += 1
|
||||
elif opt == "--version":
|
||||
parser = argparse.ArgumentParser('File indent finder')
|
||||
parser.add_argument('files', metavar='FILE', nargs='+', help='file to scan')
|
||||
parser.add_argument('--vim-output', dest='vim', default=None, help='output suitable to use inside vim', action="store_true")
|
||||
parser.add_argument('--default', dest='default', default='space', help='default type of indentation for files where indentation is not meaningful: could be space or tab')
|
||||
parser.add_argument('--default-size', dest='default_size', default=8, help='default values for files where indentation is not meaningful')
|
||||
parser.add_argument('-v', '--version', dest='version', help='print version', action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.version:
|
||||
print 'IndentFinder v%s' % VERSION
|
||||
return
|
||||
elif opt[0] == "-":
|
||||
print help % sys.argv[0]
|
||||
return
|
||||
else:
|
||||
file_list.append( opt )
|
||||
if args.vim:
|
||||
VIM_OUTPUT = 1
|
||||
|
||||
DEFAULT_RESULT = (args.default, args.default_size)
|
||||
|
||||
file_list = args.files
|
||||
|
||||
fi = IndentFinder()
|
||||
|
||||
|
27
.vimrc
27
.vimrc
@ -153,14 +153,19 @@ set shiftwidth=8
|
||||
" real tabs
|
||||
" set noexpandtab
|
||||
|
||||
|
||||
"filetype specific action
|
||||
if has("autocmd")
|
||||
au Filetype markdown set tabstop=4 shiftwidth=4 softtabstop=4
|
||||
au BufRead,BufNewFile *.iris set ft=python
|
||||
au BufRead,BufNewFile *.ino set tabstop=4 shiftwidth=4 softtabstop=4
|
||||
au BufRead,BufNewFile *.asm set ft=nasm
|
||||
|
||||
" python
|
||||
" autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab
|
||||
autocmd Filetype python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
|
||||
autocmd Filetype python set tabstop=4
|
||||
autocmd Filetype python set tabstop=4 shiftwidth=4 softtabstop=4
|
||||
autocmd Filetype python set expandtab
|
||||
autocmd Filetype python set shiftwidth=4
|
||||
autocmd Filetype python set softtabstop=4
|
||||
autocmd Filetype python set modeline
|
||||
" Indentation with = for python need autopep8
|
||||
autocmd Filetype python set equalprg=autopep8\ -
|
||||
@ -169,16 +174,6 @@ if has("autocmd")
|
||||
|
||||
endif
|
||||
|
||||
if has("autocmd")
|
||||
autocmd BufRead,BufNewFile *.iris set ft=python
|
||||
autocmd BufRead,BufNewFile *.ino set tabstop=4
|
||||
autocmd BufRead,BufNewFile *.ino set softtabstop=4
|
||||
autocmd BufRead,BufNewFile *.ino set shiftwidth=4
|
||||
endif
|
||||
|
||||
if has("autocmd")
|
||||
au BufRead,BufNewFile *.asm set ft=nasm
|
||||
endif
|
||||
" vim -b : edit binary using xxd-format!
|
||||
augroup Binary
|
||||
au!
|
||||
@ -194,7 +189,11 @@ augroup END
|
||||
if has("autocmd")
|
||||
" detect indentation see http://www.freehackers.org/Indent_Finder
|
||||
if has('python')
|
||||
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output "' . expand('%') . '"' )
|
||||
if &expandtab
|
||||
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output --default space --default-size ' . &tabstop .' "' . expand('%') . '"' )
|
||||
else
|
||||
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output --default tab --default-size ' .&tabstop .' "' . expand('%') . '"' )
|
||||
endif
|
||||
endif
|
||||
else
|
||||
" auto-indent
|
||||
|
Loading…
Reference in New Issue
Block a user