Skip to content

Commit e7ee18e

Browse files
Charles Campbellvim-scripts
authored andcommitted
Version 23
ZoomWin has been split into a plugin + autoload portion for faster vim startup. Bug fixes (scrollbind caused the restore to have an incorrect cursor position, retains the search pattern present before zooming, more files than screen rows problem)
1 parent 682e7ce commit e7ee18e

File tree

3 files changed

+119
-44
lines changed

3 files changed

+119
-44
lines changed
Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

@@ -11,29 +11,28 @@
1111
if &cp || exists("g:loaded_ZoomWin")
1212
finish
1313
endif
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
1420
let s:keepcpo = &cpo
15-
let g:loaded_ZoomWin = "v22"
21+
let g:loaded_ZoomWin = "v23"
1622
set 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")
214223
endfun
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.
220229
fun! s:SavePosn(savewinhoriz)
@@ -265,28 +274,34 @@ fun! s:SavePosn(savewinhoriz)
265274
endfun
266275

267276
" ---------------------------------------------------------------------
268-
" s:RestorePosn: this function restores noname and scratch windows {{{1
277+
" s:RestorePosn: this function restores noname and scratch windows {{{2
269278
fun! 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")
273288
endfun
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")
286301
endfun
287302

288303
" ---------------------------------------------------------------------
289-
" GotoWinNum: this function puts cursor into specified window {{{1
304+
" GotoWinNum: this function puts cursor into specified window {{{2
290305
fun! 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")
356371
endfun
357372

373+
" =====================================================================
374+
" Restore: {{{1
358375
let &cpo= s:keepcpo
359376
unlet s:keepcpo
377+
360378
" ---------------------------------------------------------------------
361379
" Modelines: {{{1
362380
" vim: ts=4 fdm=marker

doc/ZoomWin.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
*ZoomWin.txt* Zoom into/out-of a window Apr 10, 2006
1+
*ZoomWin.txt* Zoom into/out-of a window Jan 26, 2009
22
Authors: Charles E. Campbell, Jr. *zoomwin*
33
Ron Aaron
4-
Version: 21
5-
Copyright: (c) 2004-2005 by Charles E. Campbell, Jr. *zoomwin-copyright*
4+
Copyright: (c) 2004-2008 by Charles E. Campbell, Jr. *zoomwin-copyright*
65
The VIM LICENSE applies to ZoomWin.vim and ZoomWin.txt
76
(see |copyright|) except use "ZoomWin" instead of "Vim"
87
No warranty, express or implied. Use At-Your-Own-Risk.
@@ -30,6 +29,15 @@ Copyright: (c) 2004-2005 by Charles E. Campbell, Jr. *zoomwin-copyright*
3029
==============================================================================
3130
3. History *zoomwin-history*
3231

32+
v23 Apr 24, 2008 : * when |'scrollbind'| was activated: when ZoomWin
33+
attempted to restore multiple-windows, the cursor
34+
position was incorrect. Fixed.
35+
Jan 02, 2009 * included some more things in the session file
36+
* broke ZoomWin into an plugin + autoload pair
37+
* (Ingo Karkat) contributed a patch to retain the
38+
the search pattern before zooming
39+
* (Ingo Karkat) contributed a patch to detect the
40+
vim 7.2 name for the command line window
3341
v22 Apr 10, 2006 : * "only" was occasionally issuing an "Already one
3442
window" message, which is now prevented
3543
* SavePosn() issued error message when handling an

plugin/ZoomWinPlugin.vim

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
" ZoomWin: Brief-like ability to zoom into/out-of a window
2+
" Author: Charles Campbell
3+
" original version by Ron Aaron
4+
" Date: Jan 16, 2009
5+
" Version: 23e ASTRO-ONLY
6+
" History: see :help zoomwin-history {{{1
7+
" GetLatestVimScripts: 508 1 :AutoInstall: ZoomWin.vim
8+
9+
" ---------------------------------------------------------------------
10+
" Load Once: {{{1
11+
if &cp || exists("g:loaded_ZoomWinPlugin")
12+
finish
13+
endif
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
20+
let s:keepcpo = &cpo
21+
let g:loaded_ZoomWinPlugin = "v23"
22+
set cpo&vim
23+
"DechoTabOn
24+
25+
" ---------------------------------------------------------------------
26+
" Public Interface: {{{1
27+
if !hasmapto("<Plug>ZoomWin")
28+
nmap <unique> <c-w>o <Plug>ZoomWin
29+
endif
30+
nnoremap <silent> <script> <Plug>ZoomWin :set lz<CR>:silent call ZoomWin#ZoomWin()<CR>:set nolz<CR>
31+
com! ZoomWin :set lz|silent call ZoomWin#ZoomWin()|set nolz
32+
33+
au VimLeave * call ZoomWin#CleanupSessionFile()
34+
35+
" ---------------------------------------------------------------------
36+
" ZoomWin: toggles between a single-window and a multi-window layout {{{1
37+
" The original version was by Ron Aaron.
38+
" This function provides compatibility with previous versions.
39+
fun! ZoomWin()
40+
call ZoomWin#ZoomWin()
41+
endfun
42+
43+
" ---------------------------------------------------------------------
44+
" Restore: {{{1
45+
let &cpo= s:keepcpo
46+
unlet s:keepcpo
47+
" ---------------------------------------------------------------------
48+
" Modelines: {{{1
49+
" vim: ts=4 fdm=marker

0 commit comments

Comments
 (0)