Skip to content

Commit

Permalink
Save/restore window views when shrinking/restoring
Browse files Browse the repository at this point in the history
fixes #29
  • Loading branch information
mattboehm committed Nov 29, 2013
1 parent d28cc2a commit 4bf25a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Accordion lets you set the maximum number of vsplits you want to see, and shrink

If you want to view changes to a file over time, it's got a fancy diff mode. Even if you're not big on vsplits, you may want to consider Accordion for this feature alone.

Version 0.3.1
Version 0.4.0

But I Don't Use Splits!
-----------------------
Expand Down
21 changes: 20 additions & 1 deletion autoload/accordion.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"Initialization:
"s:accordion_running: true if accordion is currently changing the layout {{{
"normally, accordion is triggered by the user changing windows
"we don't want to trigger it if accordion itself caused the change
Expand Down Expand Up @@ -92,6 +91,7 @@ function! accordion#Clear()
windo call s:UnshrinkWindow()
execute curwin "wincmd w"
wincmd =
call s:RestoreVisibleWindowViews()
let s:accordion_clearing = 0
let s:accordion_running = prev_running
endfunction
Expand Down Expand Up @@ -120,6 +120,10 @@ endfunction
"}}}
"s:ShrinkWindow() shrink a window {{{
function! s:ShrinkWindow()
"save the viewport before shrinking as shrinking can mess up window position
if !exists("w:accordion_view")
let w:accordion_view=winsaveview()
endif
setl winminwidth=0
0 wincmd |
setl winfixwidth
Expand All @@ -139,6 +143,20 @@ function! s:UnshrinkWindow()
endif
endfunction
"}}}
"s:RestoreVisibleWindowViews() restore all visible windows' dimensions
function! s:RestoreVisibleWindowViews()
windo if !s:WindowIsShrunk() | call s:RestoreCurrentWindowView() | endif
endfunction
"}}}
"s:RestoreCurrentWindowView() restore the current window's dimensions
"XXX: clears the view variable after restoring
function! s:RestoreCurrentWindowView()
if exists("w:accordion_view")
call winrestview(w:accordion_view)
unlet w:accordion_view
endif
endfunction
"}}}
"Calculate Viewport:
"s:GetMovementDirection() Get direction just moved when switching windows {{{
"hjkl: left/down/up/right
Expand Down Expand Up @@ -296,6 +314,7 @@ function! s:SetViewport(desired_viewport)
call s:SetViewportInDirection(direction, padding)
endfor
wincmd =
call s:RestoreVisibleWindowViews()
let &lazyredraw = oldlazyredraw
endfunction
"}}}
Expand Down

0 comments on commit 4bf25a0

Please sign in to comment.