11" ZoomWin: Brief-like ability to zoom into/out-of a window
22" Author: Charles Campbell
33" original version by Ron Aaron
4- " Date: Apr 07, 2006
5- " Version: 22
4+ " Date: Jan 26, 2009
5+ " Version: 23
66" History: see :help zoomwin-history {{{1
77" GetLatestVimScripts: 508 1 :AutoInstall: ZoomWin.vim
88
1111if &cp || exists (" g:loaded_ZoomWin" )
1212 finish
1313endif
14+ if v: version < 702
15+ echohl WarningMsg
16+ echo " ***warning*** this version of ZoomWin needs vim 7.2"
17+ echohl Normal
18+ finish
19+ endif
1420let s: keepcpo = &cpo
15- let g: loaded_ZoomWin = " v22 "
21+ let g: loaded_ZoomWin = " v23 "
1622set cpo &vim
1723" DechoTabOn
1824
19- " ---------------------------------------------------------------------
20- " Public Interface: {{{1
21- if ! hasmapto (" <Plug>ZoomWin" )
22- nmap <unique> <c-w> o <Plug> ZoomWin
23- endif
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
26-
27- au VimLeave * call <SID> CleanupSessionFile ()
25+ " =====================================================================
26+ " Functions: {{{1
2827
2928" ---------------------------------------------------------------------
30- " ZoomWin: toggles between a single-window and a multi-window layout {{{1
29+ " ZoomWin#ZoomWin : toggles between a single-window and a multi-window layout {{{2
3130" The original version was by Ron Aaron.
32- fun ! ZoomWin ()
31+ fun ! ZoomWin#ZoomWin ()
3332" let g:decho_hide= 1 "Decho
34- " call Dfunc("ZoomWin() winbufnr(2)=".winbufnr(2))
33+ " call Dfunc("ZoomWin#ZoomWin () winbufnr(2)=".winbufnr(2))
3534
36- " if the vim doesn't have +mksession, only a partial zoom is available {{{2
35+ " if the vim doesn't have +mksession, only a partial zoom is available {{{3
3736 if ! has (" mksession" )
3837 if ! exists (" s:partialzoom" )
3938 echomsg " missing the +mksession feature; only a partial zoom is available"
@@ -51,14 +50,14 @@ fun! ZoomWin()
5150 let s: winrestore = winrestcmd ()
5251 res
5352 endif
54- " call Dret("ZoomWin : partialzoom=".s:partialzoom)
53+ " call Dret("ZoomWin#ZoomWin : partialzoom=".s:partialzoom)
5554 return
5655 endif
5756
58- " Close certain windows {{{2
57+ " Close certain windows {{{3
5958 call s: ZoomWinPreserve (0 )
6059
61- " save options. Force window minimum height/width to be >= 1 {{{2
60+ " save options. Force window minimum height/width to be >= 1 {{{3
6261 let keep_hidden = &hidden
6362 let keep_write = &write
6463
@@ -72,7 +71,7 @@ fun! ZoomWin()
7271 set hidden write
7372
7473 if winbufnr (2 ) == -1
75- " there's only one window - restore to multiple-windows mode {{{2
74+ " there's only one window - restore to multiple-windows mode {{{3
7675" call Decho("there's only one window - restore to multiple windows")
7776
7877 if exists (" s:sessionfile" ) && filereadable (s: sessionfile )
@@ -85,7 +84,7 @@ fun! ZoomWin()
8584 " source session file to restore window layout
8685 let ei_keep= &ei
8786 set ei = all
88- exe ' silent! so ' .s: sessionfile
87+ exe ' silent! so ' .fnameescape ( s: sessionfile)
8988" Decho("@@<".@@.">")
9089 let v: this_session= s: sesskeep
9190
@@ -112,16 +111,16 @@ fun! ZoomWin()
112111 let &ei = ei_keep
113112 endif
114113
115- else " there's more than one window - go to only-one-window mode {{{2
114+ else " there's more than one window - go to only-one-window mode {{{3
116115" call Decho("there's multiple windows - goto one-window-only")
117116
118117 let s: winkeep = winnr ()
119118 let s: sesskeep = v: this_session
120119
121120 " 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")
121+ if &bt == " nofile" && expand (" %" ) == ( v: version < 702 ? ' command-line' : ' [Command Line] ' )
122+ echoerr " ***error*** ZoomWin#ZoomWin doesn't work with the " . expand ( " % " ). " window"
123+ " call Dret("ZoomWin#ZoomWin : ".expand('%')." window error")
125124 return
126125 endif
127126" call Decho("1: @@<".@@.">")
@@ -145,9 +144,9 @@ fun! ZoomWin()
145144 " save session
146145" call Decho("save session")
147146 let ssop_keep = &ssop
148- let &ssop = ' blank,help,winsize'
147+ let &ssop = ' blank,help,winsize,folds,globals,localoptions,options '
149148" call Decho("5: @@<".@@.">")
150- exe ' mksession! ' .s: sessionfile
149+ exe ' mksession! ' .fnameescape ( s: sessionfile)
151150" call Decho("6: @@<".@@.">")
152151 let keepyy= @@
153152 let keepy0= @0
@@ -162,12 +161,20 @@ fun! ZoomWin()
162161 let keepy9= @9
163162 set lz ei = all bh =
164163 if v: version >= 700
165- exe " keepalt keepmarks new! " .s: sessionfile
164+ try
165+ exe " keepalt keepmarks new! " .fnameescape (s: sessionfile )
166+ catch /^Vim\%((\a\+)\)\=:E/
167+ echoerr " Too many windows"
168+ silent ! call delete (s: sessionfile )
169+ unlet s: sessionfile
170+ " call Dret("ZoomWin#ZoomWin : too many windows")
171+ return
172+ endtry
166173 silent ! keepjumps keepmarks v /wincmd\|split\|resize/ d
167174 keepalt w !
168175 keepalt bw !
169176 else
170- exe " new! " .s: sessionfile
177+ exe " new! " .fnameescape ( s: sessionfile)
171178 v /wincmd\|split\|resize/ d
172179 w !
173180 bw !
@@ -183,6 +190,8 @@ fun! ZoomWin()
183190 let @7 = keepy7
184191 let @8 = keepy8
185192 let @9 = keepy9
193+ call histdel (' search' , -1 )
194+ let @/ = histget (' search' , -1 )
186195" call Decho("7: @@<".@@.">")
187196
188197 " restore user's session options and restore event handling
@@ -196,7 +205,7 @@ fun! ZoomWin()
196205" call Decho("9: @@<".@@.">")
197206 endif
198207
199- " restore user option settings {{{2
208+ " restore user option settings {{{3
200209" call Decho("restore user option settings")
201210 let &hidden = keep_hidden
202211 let &write = keep_write
@@ -207,14 +216,14 @@ fun! ZoomWin()
207216 endif
208217 endif
209218
210- " Re-open certain windows {{{2
219+ " Re-open certain windows {{{3
211220 call s: ZoomWinPreserve (1 )
212221
213- " call Dret("ZoomWin")
222+ " call Dret("ZoomWin#ZoomWin ")
214223endfun
215224
216225" ---------------------------------------------------------------------
217- " SavePosn: this function sets up a savedposn variable that {{{1
226+ " SavePosn: this function sets up a savedposn variable that {{{2
218227" has the commands necessary to restore the view
219228" of the current window.
220229fun ! s: SavePosn (savewinhoriz)
@@ -265,28 +274,34 @@ fun! s:SavePosn(savewinhoriz)
265274endfun
266275
267276" ---------------------------------------------------------------------
268- " s:RestorePosn: this function restores noname and scratch windows {{{1
277+ " s:RestorePosn: this function restores noname and scratch windows {{{2
269278fun ! s: RestorePosn (savedposn)
270279" call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">")
271- exe a: savedposn
280+ if &scb
281+ setlocal noscb
282+ exe a: savedposn
283+ setlocal scb
284+ else
285+ exe a: savedposn
286+ endif
272287" call Dret("RestorePosn")
273288endfun
274289
275290" ---------------------------------------------------------------------
276- " CleanupSessionFile: if you exit Vim before cleaning up the {{{1
291+ " CleanupSessionFile: if you exit Vim before cleaning up the {{{2
277292" supposed-to-be temporary session file
278- fun ! s: CleanupSessionFile ()
279- " call Dfunc("CleanupSessionFile()")
293+ fun ! ZoomWin# CleanupSessionFile ()
294+ " call Dfunc("ZoomWin# CleanupSessionFile()")
280295 if exists (" s:sessionfile" ) && filereadable (s: sessionfile )
281296" call Decho("sessionfile exists and is readable; deleting it")
282297 silent ! call delete (s: sessionfile )
283298 unlet s: sessionfile
284299 endif
285- " call Dret("CleanupSessionFile")
300+ " call Dret("ZoomWin# CleanupSessionFile")
286301endfun
287302
288303" ---------------------------------------------------------------------
289- " GotoWinNum: this function puts cursor into specified window {{{1
304+ " GotoWinNum: this function puts cursor into specified window {{{2
290305fun ! s: GotoWinNum (winnum)
291306" call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr())
292307 if a: winnum != winnr ()
@@ -297,7 +312,7 @@ endfun
297312
298313
299314" ---------------------------------------------------------------------
300- " ZoomWinPreserve: This function, largely written by David Fishburn, {{{1
315+ " ZoomWinPreserve: This function, largely written by David Fishburn, {{{2
301316" allows ZoomWin to "preserve" certain windows:
302317"
303318" TagList, by Yegappan Lakshmanan
@@ -355,8 +370,11 @@ fun! s:ZoomWinPreserve(open)
355370" call Dret("ZoomWinPreserve")
356371endfun
357372
373+ " =====================================================================
374+ " Restore: {{{1
358375let &cpo = s: keepcpo
359376unlet s: keepcpo
377+
360378" ---------------------------------------------------------------------
361379" Modelines: {{{1
362380" vim: ts = 4 fdm = marker
0 commit comments