Properly detect whether a C file is using tabs or spaces for Vim.

Closes issue #5611. Thanks Kirk McDonald and Johannes Hoff.
This commit is contained in:
Brett Cannon 2009-11-08 21:35:28 +00:00
parent 002533013f
commit 813c43ab25
2 changed files with 21 additions and 18 deletions

View file

@ -1607,6 +1607,11 @@ Tests
- Issue #2389: Array objects are now pickled in a portable manner. - Issue #2389: Array objects are now pickled in a portable manner.
Misc
----
- Issue #5611: Auto-detect whether a C file uses tabs or spaces in Vim.
What's New in Python 2.6 final What's New in Python 2.6 final
============================== ==============================

View file

@ -15,31 +15,29 @@
" Only basic settings needed to enforce the style guidelines are set. " Only basic settings needed to enforce the style guidelines are set.
" Some suggested options are listed but commented out at the end of this file. " Some suggested options are listed but commented out at the end of this file.
" Number of spaces to use for an indent.
" This will affect Ctrl-T and 'autoindent'.
" Python: 4 spaces
" C: 8 spaces (pre-existing files) or 4 spaces (new files)
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead *.c,*.h set shiftwidth=8
au BufNewFile *.c,*.h set shiftwidth=4
" Number of spaces that a pre-existing tab is equal to. " Number of spaces that a pre-existing tab is equal to.
" For the amount of space used for a new tab use shiftwidth. " For the amount of space used for a new tab use shiftwidth.
" Python: 8
" C: 8
au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=8 au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=8
" Replace tabs with the equivalent number of spaces. " What to use for an indent.
" Also have an autocmd for Makefiles since they require hard tabs. " This will affect Ctrl-T and 'autoindent'.
" Python: yes " Python: 4 spaces
" C: no " C: tabs (pre-existing files) or 4 spaces (new files)
" Makefile: no au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab au BufRead,BufNewFile *.py,*.pyw set expandtab
au BufRead,BufNewFile *.c,*.h set noexpandtab fu Select_c_style()
if search('^\t', 'n', 150)
set shiftwidth=8
set noexpandtab
el
set shiftwidth=4
set expandtab
en
endf
au BufRead,BufNewFile *.c,*.h call Select_c_style()
au BufRead,BufNewFile Makefile* set noexpandtab au BufRead,BufNewFile Makefile* set noexpandtab
" Use the below highlight group when displaying bad whitespace is desired " Use the below highlight group when displaying bad whitespace is desired.
highlight BadWhitespace ctermbg=red guibg=red highlight BadWhitespace ctermbg=red guibg=red
" Display tabs at the beginning of a line in Python mode as bad. " Display tabs at the beginning of a line in Python mode as bad.