+++ /dev/null
-" ZoomWin: Brief-like ability to zoom into/out-of a window
-" Author: Ron Aaron
-" modified by Charles Campbell
-" Version: 19
-" History: see :he zoomwin-history
-
-" ---------------------------------------------------------------------
-if &cp || exists("s:loaded_zoomwin")
- finish
-endif
-let s:loaded_zoomwin= 1
-
-" ---------------------------------------------------------------------
-" Public Interface:
-if !hasmapto("<Plug>ZoomWin")
- nmap <unique> <c-w>o <Plug>ZoomWin
-endif
-nnoremap <silent> <script> <Plug>ZoomWin :set lz<CR>:call ZoomWin()<CR>:set nolz<CR>
-com! ZoomWin :set lz|silent call ZoomWin()|set nolz
-
-au VimLeave * call <SID>CleanupSessionFile()
-
-" ---------------------------------------------------------------------
-
-" ZoomWin: toggles between a single-window and a multi-window layout
-" The original was by Ron Aaron and has been extensively
-" modified by Charles E. Campbell.
-fun! ZoomWin()
-" let g:decho_hide= 1 "Decho
-" call Dfunc("ZoomWin() winbufnr(2)=".winbufnr(2))
-
- let keep_hidden = &hidden
- let keep_write = &write
- if &wmh == 0 || &wmw == 0
- let keep_wmh = &wmh
- let keep_wmw = &wmw
- set wmh=1 wmw=1
- endif
- set hidden write
-
- if winbufnr(2) == -1
- " there's only one window - restore to multiple-windows mode
-
- if exists("s:sessionfile") && filereadable(s:sessionfile)
- let sponly= s:SavePosn(0)
-
- " read session file to restore window layout
- let ei_keep= &ei
- set ei=all
- exe 'silent! so '.s:sessionfile
- let v:this_session= s:sesskeep
-
- if exists("s:savedposn1")
- " restore windows' positioning and buffers
- windo call s:RestorePosn(s:savedposn{winnr()})|unlet s:savedposn{winnr()}
- call s:GotoWinNum(s:winkeep)
- unlet s:winkeep
- endif
-
- if line(".") != s:origline || virtcol(".") != s:origcol
- " If the cursor hasn't moved from the original position,
- " then let the position remain what it was in the original
- " multi-window layout.
- call s:RestorePosn(sponly)
- endif
-
- " delete session file and variable holding its name
- call delete(s:sessionfile)
- unlet s:sessionfile
- let &ei=ei_keep
- endif
-
- else " there's more than one window - go to only-one-window mode
-
- let s:winkeep = winnr()
- let s:sesskeep = v:this_session
- let s:origline = line(".")
- let s:origcol = virtcol(".")
-
- " doesn't work with the command line window (normal mode q:)
- if &bt == "nofile" && expand("%") == "command-line"
- echoerr "***error*** ZoomWin doesn't work with the command line window"
-" call Dret("ZoomWin")
- return
- endif
-
- " save window positioning commands
- let ei_keep = &ei
- set ei=all
- windo let s:savedposn{winnr()}= s:SavePosn(1)
- call s:GotoWinNum(s:winkeep)
-
- " set up name of session file
- let s:sessionfile= tempname()
-
- " save session
- let ssop_keep = &ssop
- let &ssop = 'blank,help,winsize'
- exe 'mksession! '.s:sessionfile
- set lz ei=all bh=
- exe "new! ".s:sessionfile
- v/wincmd\|split\|resize/d
- w!
- bw!
- set nolz
- let &ssop = ssop_keep
- only!
- let &ei = ei_keep
- echomsg expand("%")
- endif
-
- " restore user option settings
- let &hidden= keep_hidden
- let &write = keep_write
- if exists("keep_wmw")
- let &wmh= keep_wmh
- let &wmw= keep_wmw
- endif
-" call Dret("ZoomWin")
-endfun
-
-" ---------------------------------------------------------------------
-
-" SavePosn: this function sets up a savedposn variable that
-" has the commands necessary to restore the view
-" of the current window.
-fun! s:SavePosn(savewinhoriz)
-" call Dfunc("SavePosn(savewinhoriz=".a:savewinhoriz.") file<".expand("%").">")
- let swline = line(".")
- let swcol = col(".")
- let swwline = winline()-1
- let swwcol = virtcol(".") - wincol()
- let savedposn = "silent b ".winbufnr(0)."|".swline."|silent norm! z\<cr>"
- if swwline > 0
- let savedposn= savedposn.":silent norm! ".swwline."\<c-y>\<cr>:silent norm! zs\<cr>"
- endif
- let savedposn= savedposn.":silent call cursor(".swline.",".swcol.")\<cr>"
-
- if a:savewinhoriz
- if swwcol > 0
- let savedposn= savedposn.":silent norm! ".swwcol."zl\<cr>"
- endif
-
- " handle certain special settings for the multi-window savedposn call
- " bufhidden buftype buflisted
- let settings= ""
- if &bh != ""
- let settings="bh=".&bh
- setlocal bh=hide
- endif
- if !&bl
- let settings= settings." nobl"
- setlocal bl
- endif
- if &bt != ""
- let settings= settings." bt=".&bt
- setlocal bt=
- endif
- if settings != ""
- let savedposn= savedposn.":setlocal ".settings."\<cr>"
- endif
-
- endif
-" call Dret("SavePosn savedposn<".savedposn.">")
- return savedposn
-endfun
-
-" ---------------------------------------------------------------------
-
-" s:RestorePosn: this function restores noname and scratch windows
-fun! s:RestorePosn(savedposn)
-" call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">")
- exe a:savedposn
-" call Dret("RestorePosn")
-endfun
-
-" ---------------------------------------------------------------------
-
-" CleanupSessionFile: if you exit Vim before cleaning up the
-" supposed-to-be temporary session file
-fun! s:CleanupSessionFile()
-" call Dfunc("CleanupSessionFile()")
- if exists("s:sessionfile") && filereadable(s:sessionfile)
-" call Decho("sessionfile exists and is readable; deleting it")
- silent! call delete(s:sessionfile)
- unlet s:sessionfile
- endif
-" call Dret("CleanupSessionFile")
-endfun
-
-" ---------------------------------------------------------------------
-
-" GotoWinNum: this function puts cursor into specified window
-fun! s:GotoWinNum(winnum)
-" call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr())
- if a:winnum != winnr()
- exe a:winnum."wincmd w"
- endif
-" call Dret("GotoWinNum")
-endfun
-
-" ---------------------------------------------------------------------
-" vim: ts=4