1 " ZoomWin: Brief-like ability to zoom into/out-of a window
2 " Author: Charles Campbell
3 " original version by Ron Aaron
5 " Version: 23a ASTRO-ONLY
6 " History: see :help zoomwin-history {{{1
7 " GetLatestVimScripts: 508 1 :AutoInstall: ZoomWin.vim
9 " ---------------------------------------------------------------------
11 if &cp || exists("g:loaded_ZoomWin")
15 let g:loaded_ZoomWin = "v23a"
19 " ---------------------------------------------------------------------
20 " Public Interface: {{{1
21 if !hasmapto("<Plug>ZoomWin")
22 nmap <unique> <c-w>o <Plug>ZoomWin
24 nnoremap <silent> <script> <Plug>ZoomWin :set lz<CR>:silent call ZoomWin()<CR>:set nolz<CR>
25 com! ZoomWin :set lz|silent call ZoomWin()|set nolz
27 au VimLeave * call <SID>CleanupSessionFile()
29 " ---------------------------------------------------------------------
30 " ZoomWin: toggles between a single-window and a multi-window layout {{{1
31 " The original version was by Ron Aaron.
33 " let g:decho_hide= 1 "Decho
34 " call Dfunc("ZoomWin() winbufnr(2)=".winbufnr(2))
36 " if the vim doesn't have +mksession, only a partial zoom is available {{{2
38 if !exists("s:partialzoom")
39 echomsg "missing the +mksession feature; only a partial zoom is available"
43 echoerr "***sorry*** you need an updated vim, preferably with +mksession"
51 let s:winrestore = winrestcmd()
54 " call Dret("ZoomWin : partialzoom=".s:partialzoom)
58 " Close certain windows {{{2
59 call s:ZoomWinPreserve(0)
61 " save options. Force window minimum height/width to be >= 1 {{{2
62 let keep_hidden = &hidden
63 let keep_write = &write
66 if &wmh == 0 || &wmw == 0
69 silent! set wmh=1 wmw=1
75 " there's only one window - restore to multiple-windows mode {{{2
76 " call Decho("there's only one window - restore to multiple windows")
78 if exists("s:sessionfile") && filereadable(s:sessionfile)
79 " save position in current one-window-only
80 " call Decho("save position in current one-window-only in sponly")
81 let sponly = s:SavePosn(0)
82 let s:origline = line(".")
83 let s:origcol = virtcol(".")
85 " source session file to restore window layout
88 exe 'silent! so '.s:sessionfile
90 let v:this_session= s:sesskeep
92 if exists("s:savedposn1")
93 " restore windows' positioning and buffers
94 " call Decho("restore windows, positions, buffers")
95 windo call s:RestorePosn(s:savedposn{winnr()})|unlet s:savedposn{winnr()}
96 call s:GotoWinNum(s:winkeep)
100 if line(".") != s:origline || virtcol(".") != s:origcol
101 " If the cursor hasn't moved from the original position,
102 " then let the position remain what it was in the original
103 " multi-window layout.
104 " call Decho("restore position using sponly")
105 call s:RestorePosn(sponly)
108 " delete session file and variable holding its name
109 " call Decho("delete session file")
110 call delete(s:sessionfile)
115 else " there's more than one window - go to only-one-window mode {{{2
116 " call Decho("there's multiple windows - goto one-window-only")
118 let s:winkeep = winnr()
119 let s:sesskeep = v:this_session
121 " doesn't work with the command line window (normal mode q:)
122 if &bt == "nofile" && expand("%") == "command-line"
123 echoerr "***error*** ZoomWin doesn't work with the command line window"
124 " call Dret("ZoomWin : commandline window error")
127 " call Decho("1: @@<".@@.">")
129 " disable all events (autocmds)
130 " call Decho("disable events")
133 " call Decho("2: @@<".@@.">")
135 " save window positioning commands
136 " call Decho("save window positioning commands")
137 windo let s:savedposn{winnr()}= s:SavePosn(1)
138 call s:GotoWinNum(s:winkeep)
140 " set up name of session file
141 " call Decho("3: @@<".@@.">")
142 let s:sessionfile= tempname()
143 " call Decho("4: @@<".@@.">")
146 " call Decho("save session")
147 let ssop_keep = &ssop
148 let &ssop = 'blank,help,winsize'
149 " call Decho("5: @@<".@@.">")
150 exe 'mksession! '.s:sessionfile
151 " call Decho("6: @@<".@@.">")
165 exe "keepalt keepmarks new! ".s:sessionfile
166 silent! keepjumps keepmarks v/wincmd\|split\|resize/d
170 exe "new! ".s:sessionfile
171 v/wincmd\|split\|resize/d
186 " call Decho("7: @@<".@@.">")
188 " restore user's session options and restore event handling
189 " call Decho("restore user session options and event handling")
191 let &ssop = ssop_keep
193 " call Decho("8: @@<".@@.">")
196 " call Decho("9: @@<".@@.">")
199 " restore user option settings {{{2
200 " call Decho("restore user option settings")
201 let &hidden= keep_hidden
202 let &write = keep_write
204 if exists("keep_wmw")
210 " Re-open certain windows {{{2
211 call s:ZoomWinPreserve(1)
213 " call Dret("ZoomWin")
216 " ---------------------------------------------------------------------
217 " SavePosn: this function sets up a savedposn variable that {{{1
218 " has the commands necessary to restore the view
219 " of the current window.
220 fun! s:SavePosn(savewinhoriz)
221 " call Dfunc("SavePosn(savewinhoriz=".a:savewinhoriz.") file<".expand("%").">")
222 let swline = line(".")
223 if swline == 1 && getline(1) == ""
225 let savedposn= "silent b ".winbufnr(0)
226 " call Dret("SavePosn savedposn<".savedposn.">")
230 let swwline = winline()-1
231 let swwcol = virtcol(".") - wincol()
232 let savedposn = "silent b ".winbufnr(0)."|".swline."|silent norm! z\<cr>"
234 let savedposn= savedposn.":silent norm! ".swwline."\<c-y>\<cr>:silent norm! zs\<cr>"
236 let savedposn= savedposn.":silent call cursor(".swline.",".swcol.")\<cr>"
240 let savedposn= savedposn.":silent norm! ".swwcol."zl\<cr>"
243 " handle certain special settings for the multi-window savedposn call
244 " bufhidden buftype buflisted
247 let settings="bh=".&bh
251 let settings= settings." nobl"
255 let settings= settings." bt=".&bt
259 let savedposn= savedposn.":setlocal ".settings."\<cr>"
263 " call Dret("SavePosn savedposn<".savedposn.">")
267 " ---------------------------------------------------------------------
268 " s:RestorePosn: this function restores noname and scratch windows {{{1
269 fun! s:RestorePosn(savedposn)
270 " call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">")
278 " call Dret("RestorePosn")
281 " ---------------------------------------------------------------------
282 " CleanupSessionFile: if you exit Vim before cleaning up the {{{1
283 " supposed-to-be temporary session file
284 fun! s:CleanupSessionFile()
285 " call Dfunc("CleanupSessionFile()")
286 if exists("s:sessionfile") && filereadable(s:sessionfile)
287 " call Decho("sessionfile exists and is readable; deleting it")
288 silent! call delete(s:sessionfile)
291 " call Dret("CleanupSessionFile")
294 " ---------------------------------------------------------------------
295 " GotoWinNum: this function puts cursor into specified window {{{1
296 fun! s:GotoWinNum(winnum)
297 " call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr())
298 if a:winnum != winnr()
299 exe a:winnum."wincmd w"
301 " call Dret("GotoWinNum")
305 " ---------------------------------------------------------------------
306 " ZoomWinPreserve: This function, largely written by David Fishburn, {{{1
307 " allows ZoomWin to "preserve" certain windows:
309 " TagList, by Yegappan Lakshmanan
310 " http://vim.sourceforge.net/scripts/script.php?script_id=273
312 " WinManager, by Srinath Avadhanula
313 " http://vim.sourceforge.net/scripts/script.php?script_id=95
315 " It does so by closing the associated window upon entry to ZoomWin
316 " and re-opening it upon exit by using commands provided by the
317 " utilities themselves.
318 fun! s:ZoomWinPreserve(open)
319 " call Dfunc("ZoomWinPreserve(open=".a:open.")")
324 if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist')
325 " If taglist window is open then close it.
326 let s:taglist_winnum = bufwinnr(g:TagList_title)
327 if s:taglist_winnum != -1
334 if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager')
335 " If the winmanager window is open then close it.
336 let s:is_winmgr_vis = IsWinManagerVisible()
337 if s:is_winmgr_vis == 1
345 if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist')
346 " If taglist window was open, open it again
347 if s:taglist_winnum != -1
353 if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager')
354 " If the winmanager window is open then close it.
355 if s:is_winmgr_vis == 1
361 " call Dret("ZoomWinPreserve")
366 " ---------------------------------------------------------------------
368 " vim: ts=4 fdm=marker