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