Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

maket the tab warning on the stl own more

  • Loading branch information...
commit 9f5a0fdcff100c405a710836e9fb7205802b03bd 1 parent e1aedaa
@scrooloose authored
Showing with 20 additions and 9 deletions.
  1. +20 −9 vimrc
View
29 vimrc
@@ -54,7 +54,7 @@ set statusline+=%r "read only flag
set statusline+=%y "filetype
set statusline+=[%{StatuslineCurrentHighlight()}]
-"display a warning if we shouldnt have &et set
+"display a warning if &et is wrong, or we have mixed-indenting
set statusline+=%#error#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*
@@ -74,18 +74,29 @@ function! StatuslineCurrentHighlight()
return name
endfunction
-"return '[&et]' if leading tabs are found and &et is set
+
+"recalculate the tab warning flag when idle and after writing
+autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
+
+"return '[&et]' if &et is set wrong
+"return '[mixed-indenting]' if spaces and tabs are used to indent
+"return an empty string if everything is fine
function! StatuslineTabWarning()
- if !exists("b:statusline_tabs_found")
- let b:statusline_tabs_found = search('^\t', 'nw') != 0
- endif
- if b:statusline_tabs_found && &expandtab
- return '[&et]'
+ if !exists("b:statusline_tab_warning")
+ let tabs = search('^\t\+[^ \t]*', 'nw') != 0
+ let spaces = search('^ \+[^ \t]*', 'nw') != 0
+
+ if tabs && spaces
+ let b:statusline_tab_warning = '[mixed-indenting]'
+ elseif (spaces && !&et) || (tabs && &et)
+ let b:statusline_tab_warning = '[&et]'
+ else
+ let b:statusline_tab_warning = ''
+ endif
endif
- return ''
+ return b:statusline_tab_warning
endfunction
-
"indent settings
set shiftwidth=4
set softtabstop=4
Please sign in to comment.
Something went wrong with that request. Please try again.