Skip to content

Commit 6a09675

Browse files
committed
Merge branch 'release-1.0.1'
2 parents 8d0df10 + 32e5317 commit 6a09675

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

autoload/stay/view.vim

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let s:cpo = &cpo
44
set cpo&vim
55

66
" Make a persistent view for window {winnr}:
7-
" @signature: stay#mkview({winnr:Number})
7+
" @signature: stay#view#make({winnr:Number})
88
" @returns: Boolean
99
function! stay#view#make(winnr) abort
1010
if a:winnr is -1
@@ -14,41 +14,58 @@ function! stay#view#make(winnr) abort
1414
try
1515
let l:lazyredraw = &lazyredraw
1616
set lazyredraw
17-
let l:curwinnr = s:gotowin(a:winnr)
17+
if !s:win.goto(a:winnr)
18+
return 0
19+
endif
1820
unlet! b:stay_atpos
1921
mkview
20-
call s:gotowin(l:curwinnr)
22+
call s:win.back()
2123
return 1
2224
finally
2325
let &lazyredraw = l:lazyredraw
2426
endtry
2527
endfunction
2628

2729
" Load a persistent view for window {winnr}:
28-
" @signature: stay#loadview({winnr:Number})
30+
" @signature: stay#view#load({winnr:Number})
2931
" @returns: Boolean
3032
function! stay#view#load(winnr) abort
31-
if a:winnr is -1
33+
if a:winnr is -1 || !s:win.goto(a:winnr)
3234
return 0
3335
endif
3436

35-
let l:curwinnr = s:gotowin(a:winnr)
3637
noautocmd silent loadview
3738
if exists('b:stay_atpos')
3839
call cursor(b:stay_atpos[0], b:stay_atpos[1])
3940
silent! normal! zOzz
4041
endif
41-
call s:gotowin(l:curwinnr)
42+
call s:win.back()
4243
return 1
4344
endfunction
4445

4546
" 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)
5067
endif
51-
return l:curwinnr
68+
return exists('l:towinnr') && winnr() is l:towinnr
5269
endfunction
5370

5471
let &cpo = s:cpo

doc/vim-stay.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim-stay.txt* For Vim version 7.0 or better version 1.0.0
1+
*vim-stay.txt* For Vim version 7.0 or better version 1.0.1
22

33

44
VIM REFERENCE for the Stay plug-in
@@ -36,17 +36,17 @@ The following, non-standard 'viewoptions' settings are recommended:
3636

3737
IGNORED FILE TYPES: *g:volatile_ftypes*
3838

39-
vim-stay applies heuristics to detect volatile file types, but certain file
40-
types escape these and need to be expressly marked as volatile (meaning
41-
buffers of this file type will never be persisted).
42-
43-
Volatile file types are stored in the `volatile_ftypes` global List. To
44-
overwrite this list, do
45-
>
46-
let g:volatile_ftypes = ['foo', 'bar']
47-
<
48-
any time before or after the plug-in has loaded. To add to this list without
49-
overwriting the defaults, make sure the plug-in has loaded, then do
39+
vim-stay applies heuristics to detect buffers that should not be persisted,
40+
but in some cases non-persistent buffers slip through. Some of them are
41+
regular files that are not persistent by their very nature (like git commit
42+
messages), a few are buffers created by plug-ins that miss all indication
43+
that they are not files. These can be expressly marked as volatile (meaning
44+
buffers of this type will never be persisted) by adding their 'filetype' to
45+
the `volatile_ftypes` global |List|.
46+
47+
Note this list is meant as a safety net for the case heuristics fail; it
48+
usually should not be necessary to modify vim-stay's defaults. If you find
49+
you need to add file types to it, make sure the plug-in has loaded, then do
5050
>
5151
let g:volatile_ftypes += ['foo', 'bar']
5252
<
@@ -58,10 +58,10 @@ INTEGRATION WITH 3RD PARTY PLUG-INS:
5858

5959
Out of the box, vim-stay integrates with the following plug-ins:
6060

61-
1. vim-stay http://www.vim.org/scripts/script.php?script_id=5089
61+
1. vim-fetch http://www.vim.org/scripts/script.php?script_id=5089
6262

63-
If you'd like vim-stay to integrate with other position-setting plug-ins, open
64-
an issue or a PR at
63+
If you'd like vim-stay to integrate with other position-setting or view
64+
management plug-ins, open an issue or a PR at
6565

6666
https://github.com/kopischke/vim-stay/issues
6767

plugin/stay.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" A LESS SIMPLISTIC TAKE ON RESTORE_VIEW.VIM
22
" Maintainer: Martin Kopischke <[email protected]>
33
" License: MIT (see LICENSE.md)
4-
" Version: 1.0.0
4+
" Version: 1.0.1
55
if &compatible || !has('autocmd') || !has('mksession') || v:version < 700
66
finish
77
endif

0 commit comments

Comments
 (0)