Skip to content

Commit 4262ead

Browse files
committed
Merge branch 'release-1.3.0'
2 parents 986f7b5 + 5dff1f3 commit 4262ead

File tree

4 files changed

+85
-28
lines changed

4 files changed

+85
-28
lines changed

autoload/stay.vim

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,33 @@ endfunction
3434
" Check if {fname} is in a 'backupskip' location:
3535
" @signature: stay#istemp({fname:String})
3636
" @returns: Boolean
37-
function! stay#istemp(path) abort
38-
let l:candidates = stay#shim#globpath(&backupskip, '**/'.fnamemodify(a:path, ':t'), 1, 1)
39-
return index(l:candidates, a:path) isnot -1
40-
endfunction
37+
if exists('glob2regpat') " fastest option, Vim 7.4 with patch 668 only
38+
function! stay#istemp(path) abort
39+
for l:tempdir in split(&backupskip, '\m[^\\]\%(\\\\\)*,')
40+
if a:path =~# glob2regpat(l:tempdir)
41+
return 1
42+
endif
43+
endfor
44+
return 0
45+
endfunction
46+
elseif has('wildignore') " ~ slower by x 1.75
47+
function! stay#istemp(path) abort
48+
let l:wildignore = &wildignore
49+
try
50+
let &wildignore = &backupskip
51+
return empty(expand(a:path))
52+
finally
53+
let &wildignore = l:wildignore
54+
endtry
55+
endfunction
56+
else
57+
" assume Vim builds without |+wildignore| are performance constrained,
58+
" which makes using |globpath()| filtering on 'backupskip' a non-option
59+
" (it's about a 100 times slower than the 'wildignore' / |expand()| hack)
60+
function! stay#istemp(path) abort
61+
return -1
62+
endfunction
63+
endif
4164

4265
" Check if one of {bufnr}'s 'filetype' parts is on the {ftypes} List:
4366
" @signature: stay#isftype({bufnr:Number}, {ftypes:List<String>})

autoload/stay/view.vim

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ function! stay#view#make(winnr) abort
1919
endif
2020
unlet! b:stay_atpos
2121
call s:doautocmd('User', 'BufStaySavePre')
22+
let l:dopost = 1
2223
mkview
23-
call s:doautocmd('User', 'BufStaySavePost')
24-
call s:win.back()
2524
return 1
2625
finally
26+
if get(l:, 'dopost', 0) is 1
27+
call s:doautocmd('User', 'BufStaySavePost')
28+
endif
29+
call s:win.back()
2730
let &lazyredraw = l:lazyredraw
2831
endtry
2932
endfunction
@@ -37,20 +40,30 @@ function! stay#view#load(winnr) abort
3740
endif
3841

3942
call s:doautocmd('User', 'BufStayLoadPre')
40-
try " significantly slows down buffer loads without noautocmd
41-
noautocmd silent loadview
43+
" the `doautoall SessionLoadPost` in view session files significantly
44+
" slows down buffer load, hence we suppress it...
45+
let l:eventignore = &eventignore
46+
set eventignore+=SessionLoadPost
47+
try
48+
silent loadview
49+
" ... then fire it in a more targeted way
50+
if exists('b:stay_loaded_view')
51+
let &eventignore = l:eventignore
52+
call s:doautocmd('SessionLoadPost')
53+
endif
54+
" respect position set by other scripts / plug-ins
55+
if exists('b:stay_atpos')
56+
call cursor(b:stay_atpos[0], b:stay_atpos[1])
57+
silent! normal! zOzz
58+
endif
59+
return 1
4260
catch " silently return on errors
4361
return 0
62+
finally
63+
let &eventignore = l:eventignore
64+
call s:doautocmd('User', 'BufStayLoadPost')
65+
call s:win.back()
4466
endtry
45-
call s:doautocmd('User', 'BufStayLoadPost')
46-
call s:doautocmd('SessionLoadPost')
47-
48-
if exists('b:stay_atpos')
49-
call cursor(b:stay_atpos[0], b:stay_atpos[1])
50-
silent! normal! zOzz
51-
endif
52-
call s:win.back()
53-
return 1
5467
endfunction
5568

5669
" Private helper functions: {{{

doc/vim-stay.txt

Lines changed: 20 additions & 8 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.2.0
1+
*vim-stay.txt* For Vim version 7.0 or better version 1.3.0
22

33

44
VIM REFERENCE for the Stay plug-in
@@ -9,9 +9,10 @@ Never lose your place in a buffer again *vim-stay*
99
1. Introduction |vim-stay-introduction|
1010
2. Configuration |vim-stay-configuration|
1111
3. Commands |vim-stay-commands|
12-
4. Position specifications |vim-stay-integration|
13-
5. Troubleshooting |vim-stay-troubleshooting|
14-
6. Credits and license |vim-stay-credits-license|
12+
4. Variables |vim-stay-variables|
13+
5. Position specifications |vim-stay-integration|
14+
6. Troubleshooting |vim-stay-troubleshooting|
15+
7. Credits and license |vim-stay-credits-license|
1516

1617
{not available when |'compatible'| is set, or when Vim is compiled without
1718
|+autocmd| or without |+mksession|}
@@ -73,7 +74,15 @@ you need to add file types to it, make sure the plug-in has loaded, then do
7374
|g:volatile_ftypes|) to the plug-in defaults.
7475

7576
==============================================================================
76-
4. Integration *vim-stay-integration*
77+
4. Variables *vim-stay-variables*
78+
79+
80+
b:stay_loaded_view
81+
Full path to the view session file last loaded for the current
82+
buffer by vim-stay.
83+
84+
==============================================================================
85+
5. Integration *vim-stay-integration*
7786

7887

7988
INTEGRATION WITH 3RD PARTY PLUG-INS:
@@ -139,7 +148,7 @@ The advantage over hard-wiring support for vim-stay in your plug-in is that
139148
- the integration code will only be active if your user actually uses vim-stay.
140149

141150
==============================================================================
142-
5. Troubleshooting *vim-stay-troubleshooting*
151+
6. Troubleshooting *vim-stay-troubleshooting*
143152

144153

145154
MY CURSOR POSITION IS NOT PERSISTED
@@ -178,12 +187,15 @@ recommended setting under |vim-stay-viewoptions|.
178187
VIM-STAY TRIES TO PERSIST STATE FOR TEMPORARY FILES
179188

180189
- If the files are in a standard system temporary location, you should check
181-
if it listed in 'backupskip' - vim-stray will ignore files in the hierarchy
190+
if it listed in 'backupskip' - vim-stay will ignore files in the hierarchy
182191
of directories listed there.
183192
- Files in a temporary or cache directory not listed in 'backupskip' are not
184193
recognized as volatile, unless their 'buftype' is set to a non-file type.
185194
You can alleviate the issue by setting |b:stay_ignore| in affected buffers.
186195

196+
Note: for performance reasons, 'backupskip' checking is skipped if Vim is
197+
compiled without |+wildignore| and |glob2regpat()| is not available.
198+
187199

188200
VIM-STAY TRIES TO PERSIST STATE FOR OTHER VOLATILE FILES
189201

@@ -211,7 +223,7 @@ Please do not forget to list the steps to reproduce the issue as well as your
211223
Vim version and platform.
212224

213225
==============================================================================
214-
6. Credits and License *vim-stay-credits-license*
226+
7. Credits and License *vim-stay-credits-license*
215227

216228
vim-stay is maintained by Martin Kopischke
217229

plugin/stay.vim

Lines changed: 12 additions & 3 deletions
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.2.0
4+
" Version: 1.3.0
55
if &compatible || !has('autocmd') || !has('mksession') || v:version < 700
66
finish
77
endif
@@ -49,12 +49,21 @@ function! s:setup(defaults) abort
4949
" - 'stay' autocommand group (also used by integrations)
5050
augroup stay
5151
autocmd!
52+
53+
" |v:this_session| is not set for view sessions, so we roll our own (ignored
54+
" when 'viewdir' is empty or set to the current directory hierarchy, as that
55+
" would catch every filed sourced from there, not just view session files)
56+
autocmd SourcePre ?*
57+
\ if &viewdir !~? '\v^$|^\.' && stridx(expand('<afile>'), &viewdir) is 0 |
58+
\ let b:stay_loaded_view = expand('<afile>') |
59+
\ endif
60+
5261
" default buffer handling
53-
autocmd BufLeave,BufWinLeave ?*
62+
autocmd BufLeave,BufWinLeave ?* nested
5463
\ if stay#ispersistent(str2nr(expand('<abuf>')), g:volatile_ftypes) |
5564
\ call stay#view#make(bufwinnr(str2nr(expand('<abuf>')))) |
5665
\ endif
57-
autocmd BufWinEnter ?*
66+
autocmd BufWinEnter ?* nested
5867
\ if stay#ispersistent(str2nr(expand('<abuf>')), g:volatile_ftypes) |
5968
\ call stay#view#load(bufwinnr(str2nr(expand('<abuf>')))) |
6069
\ endif

0 commit comments

Comments
 (0)