From: Iain Patterson Date: Fri, 21 Aug 2009 14:09:30 +0000 (+0100) Subject: Window resizing fixes. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=996703df922a6431a9d621a395605f0f31329b5d;p=profile.git Window resizing fixes. Fixed not shrinking the window when list was toggled off. Use some trickery to avoid using winnr() on Vim 6. --- diff --git a/.vimrc b/.vimrc index 4057ea7..812f103 100644 --- a/.vimrc +++ b/.vimrc @@ -167,13 +167,13 @@ endfun "}}}2 " Set up our variables. fun! Iain_Vars() "{{{2 - call Prep_Var("b:iainlist", 0) + call Prep_Var("w:iainlist", 0) call Prep_Var("b:iainhex", 0) call Prep_Var("b:iainverbose", 0) " Window Flags: (F)ocused, (I)nsert mode, Cursor (H)old. call Prep_Var("b:iainstatus", "'Fih'") - call Prep_Var("g:iainextracolumnsnumber", 0) - call Prep_Var("g:iainextracolumnslist", 0) + call Prep_Var("g:iainextracolumnsnumber", "''") + call Prep_Var("g:iainextracolumnslist", "''") if has("signs") call Prep_Var("g:marksigns", 0) call Prep_Var("g:firstsign", 100) @@ -184,11 +184,11 @@ endfun "}}}2 " Show space, underscore or dollar sign depending on list mode. fun! Show_List() "{{{2 call Iain_Vars() - if b:iainlist == 0 + if w:iainlist == 0 " No list. return " " elseif Has_Unicode() - if b:iainlist == 1 + if w:iainlist == 1 " Just tabs. return "»" else @@ -196,7 +196,7 @@ fun! Show_List() "{{{2 return "¶" endif else - if b:iainlist == 1 + if w:iainlist == 1 return "_" else return "\$" @@ -309,10 +309,20 @@ endfun "}}}2 " Set extra columns depending on window status. fun! Extra_Columns(extra, var, ...) "{{{2 - if v:version < "700" + " Vim 6 doesn't have winnr("$"). Determine which windows are open + " ourselves by using :windo to incremement a counter. As Vim 5 + " doesn't have :windo we require Vim 6 for this. + if v:version < "600" return "" endif + " Remember which window we're in. + let l:winnr = winnr() + let l:num_windows = 0 + windo let l:num_windows = l:num_windows + 1 + " Switch back to the window we were in. + exe l:winnr . "wincmd w" + call Iain_Vars() if a:0 == 0 @@ -321,28 +331,34 @@ fun! Extra_Columns(extra, var, ...) "{{{2 let l:condition = a:1 endif + let l:n = 0 let l:i = 1 - let l:num_windows = 0 - while l:i <= winnr("$") + let l:windows = "" + while l:n < l:num_windows + " If window w exists then getwinvar(w, "&modified") will be 0 or 1. + if getwinvar(l:i, "&modified") =~ '^\d' + let l:n = l:n + 1 + let l:val = 0 exe "if getwinvar(" . l:i . ", '" . a:var . "') " . l:condition . " | let l:val = 1 | endif" if l:val - let l:num_windows = l:num_windows + 1 + exe "let l:windows = '" . l:windows . ":" . l:i . "'" + endif endif let l:i = l:i + 1 endwhile let l:extra = "g:iainextracolumns" . a:extra exe "let l:val = " . l:extra + exe "let " . l:extra . " = '" . l:windows . "'" - if l:num_windows == l:val + if l:windows == l:val return "" endif - exe "let " . l:extra . " = " . l:num_windows - if l:num_windows == 0 + if l:windows == "" return "-" - elseif l:val == 0 + elseif l:val == "" return "+" endif endfun "}}}2 @@ -371,7 +387,7 @@ au Mode BufLeave * if &ft == "make" | call MakeMode_unmap() | endif " Entering Make mode. fun! MakeMode_map() "{{{2 call Iain_Vars() - let b:iainlist=1 + let w:iainlist=1 call Cycle_List() set ts=8 set noexpandtab @@ -855,13 +871,13 @@ fun! Cycle_List() "{{{2 endif endif call Iain_Vars() - let b:iainlist = b:iainlist + 1 - if b:iainlist > 2 - let b:iainlist = 0 + let w:iainlist = w:iainlist + 1 + if w:iainlist > 2 + let w:iainlist = 0 endif - if b:iainlist == 0 + if w:iainlist == 0 setlocal nolist - elseif b:iainlist == 1 + elseif w:iainlist == 1 exec "setlocal lcs=" . basic setlocal list else @@ -869,7 +885,7 @@ fun! Cycle_List() "{{{2 setlocal list endif - call Resize_Columns(Extra_Columns("list", "&lcs", " =~# 'eol'"), 1) + call Resize_Columns(Extra_Columns("list", "iainlist", " == 2"), 1) endfun "}}}2 " Cycle between hex and decimal display of toolbar stuff.