@@ -4,7 +4,7 @@ let s:cpo = &cpo
4
4
set cpo &vim
5
5
6
6
" Make a persistent view for window {winnr}:
7
- " @signature: stay#mkview ({winnr:Number})
7
+ " @signature: stay#view#make ({winnr:Number})
8
8
" @returns: Boolean
9
9
function ! stay#view#make (winnr ) abort
10
10
if a: winnr is -1
@@ -14,41 +14,58 @@ function! stay#view#make(winnr) abort
14
14
try
15
15
let l: lazyredraw = &lazyredraw
16
16
set lazyredraw
17
- let l: curwinnr = s: gotowin (a: winnr )
17
+ if ! s: win .goto (a: winnr )
18
+ return 0
19
+ endif
18
20
unlet ! b: stay_atpos
19
21
mkview
20
- call s: gotowin ( l: curwinnr )
22
+ call s: win . back ( )
21
23
return 1
22
24
finally
23
25
let &lazyredraw = l: lazyredraw
24
26
endtry
25
27
endfunction
26
28
27
29
" Load a persistent view for window {winnr}:
28
- " @signature: stay#loadview ({winnr:Number})
30
+ " @signature: stay#view#load ({winnr:Number})
29
31
" @returns: Boolean
30
32
function ! stay#view#load (winnr ) abort
31
- if a: winnr is -1
33
+ if a: winnr is -1 || ! s: win . goto ( a: winnr )
32
34
return 0
33
35
endif
34
36
35
- let l: curwinnr = s: gotowin (a: winnr )
36
37
noautocmd silent loadview
37
38
if exists (' b:stay_atpos' )
38
39
call cursor (b: stay_atpos [0 ], b: stay_atpos [1 ])
39
40
silent ! normal ! zOzz
40
41
endif
41
- call s: gotowin ( l: curwinnr )
42
+ call s: win . back ( )
42
43
return 1
43
44
endfunction
44
45
45
46
" Private helper functions:
46
- function ! s: gotowin (winnr ) abort
47
- let l: curwinnr = winnr ()
48
- if a: winnr isnot l: curwinnr
49
- execute ' silent!' a: winnr .' wincmd w'
47
+ " - window navigation stack
48
+ let s: win = {' stack' : []}
49
+
50
+ function ! s: win .activate (winnr ) abort
51
+ if winnr () isnot a: winnr
52
+ execute ' noautocmd keepjumps keepalt silent' a: winnr .' wincmd w'
53
+ endif
54
+ endfunction
55
+
56
+ function ! s: win .goto (winnr ) abort
57
+ let l: oldwinnr = winnr ()
58
+ call self .activate (a: winnr )
59
+ call add (self .stack, l: oldwinnr )
60
+ return winnr () is a: winnr
61
+ endfunction
62
+
63
+ function ! s: win .back () abort
64
+ if len (self .stack) > 0
65
+ let l: towinnr = remove (self .stack, -1 )
66
+ call self .activate (l: towinnr )
50
67
endif
51
- return l: curwinnr
68
+ return exists ( ' l:towinnr ' ) && winnr () is l: towinnr
52
69
endfunction
53
70
54
71
let &cpo = s: cpo
0 commit comments