Skip to content

Commit 35b6742

Browse files
committed
Move "session is empty?" check to separate function
1 parent a5d564f commit 35b6742

File tree

3 files changed

+69
-31
lines changed

3 files changed

+69
-31
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
270270

271271
<!-- Start of generated documentation -->
272272

273-
The documentation of the 38 functions below was extracted from
274-
2 Vim scripts on March 15, 2015 at 10:15.
273+
The documentation of the 39 functions below was extracted from
274+
2 Vim scripts on March 15, 2015 at 10:22.
275275

276276
### Public API for the vim-session plug-in
277277

@@ -356,6 +356,18 @@ Normally called by the [VimEnter] [] automatic command event.
356356

357357
[VimEnter]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#VimEnter
358358

359+
#### The `xolox#session#is_empty()` function
360+
361+
Check that the user has started Vim without editing any files. Used by
362+
`xolox#session#auto_load()` to determine whether automatic session loading
363+
should be performed. Currently checks the following conditions:
364+
365+
1. That the current buffer is either empty (contains no lines and is not
366+
modified) or showing [vim-startify] [].
367+
2. That the buffer list either empty or persistent.
368+
369+
[vim-startify]: https://github.com/mhinz/vim-startify/
370+
359371
#### The `xolox#session#auto_save()` function
360372

361373
Automatically save the current editing session when Vim is closed.

autoload/xolox/session.vim

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Last Change: March 15, 2015
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.9.1'
7+
let g:xolox#session#version = '2.9.2'
88

99
" Public API for session persistence. {{{1
1010

@@ -386,11 +386,7 @@ function! xolox#session#auto_load() " {{{2
386386
return
387387
endif
388388
" Check that the user has started Vim without editing any files.
389-
let current_buffer_is_empty = (&modified == 0 && getline(1, '$') == [''])
390-
let current_buffer_is_startify = (&filetype == 'startify')
391-
let buffer_list_is_empty = (bufname('%') == '' && empty(filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != ' . bufnr(''))))
392-
let buffer_list_is_persistent = (index(xolox#misc#option#split(&viminfo), '%') >= 0)
393-
if (current_buffer_is_empty || current_buffer_is_startify) && (buffer_list_is_empty || buffer_list_is_persistent)
389+
if xolox#session#is_empty()
394390
" Check whether a session matching the user-specified server name exists.
395391
if v:servername !~ '^\cgvim\d*$'
396392
for session in xolox#session#get_names(0)
@@ -425,6 +421,23 @@ function! xolox#session#auto_load() " {{{2
425421
endif
426422
endfunction
427423

424+
function! xolox#session#is_empty() " {{{2
425+
" Check that the user has started Vim without editing any files. Used by
426+
" `xolox#session#auto_load()` to determine whether automatic session loading
427+
" should be performed. Currently checks the following conditions:
428+
"
429+
" 1. That the current buffer is either empty (contains no lines and is not
430+
" modified) or showing [vim-startify] [].
431+
" 2. That the buffer list either empty or persistent.
432+
"
433+
" [vim-startify]: https://github.com/mhinz/vim-startify/
434+
let current_buffer_is_empty = (&modified == 0 && getline(1, '$') == [''])
435+
let current_buffer_is_startify = (&filetype == 'startify')
436+
let buffer_list_is_empty = (bufname('%') == '' && empty(filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != ' . bufnr(''))))
437+
let buffer_list_is_persistent = (index(xolox#misc#option#split(&viminfo), '%') >= 0)
438+
return (current_buffer_is_empty || current_buffer_is_startify) && (buffer_list_is_empty || buffer_list_is_persistent)
439+
endfunction
440+
428441
function! xolox#session#auto_save() " {{{2
429442
" Automatically save the current editing session when Vim is closed.
430443
" Normally called by the [VimLeavePre] [] automatic command event.

doc/session.txt

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,24 @@ Contents ~
5050
7. The |xolox#session#save_state()| function
5151
8. The |xolox#session#save_special_windows()| function
5252
9. The |xolox#session#auto_load()| function
53-
10. The |xolox#session#auto_save()| function
54-
11. The |xolox#session#auto_save_periodic()| function
55-
12. The |xolox#session#auto_unlock()| function
56-
13. The |xolox#session#prompt_for_name()| function
57-
14. The |xolox#session#name_to_path()| function
58-
15. The |xolox#session#path_to_name()| function
59-
16. The |xolox#session#get_names()| function
60-
17. The |xolox#session#complete_names()| function
61-
18. The |xolox#session#complete_names_with_suggestions()| function
62-
19. The |xolox#session#is_tab_scoped()| function
63-
20. The |xolox#session#find_current_session()| function
64-
21. The |xolox#session#get_label()| function
65-
22. The |xolox#session#options_include()| function
66-
23. The |xolox#session#include_tabs()| function
67-
24. The |xolox#session#change_tab_options()| function
68-
25. The |xolox#session#restore_tab_options()| function
69-
26. The |xolox#session#locking_enabled()| function
53+
10. The |xolox#session#is_empty()| function
54+
11. The |xolox#session#auto_save()| function
55+
12. The |xolox#session#auto_save_periodic()| function
56+
13. The |xolox#session#auto_unlock()| function
57+
14. The |xolox#session#prompt_for_name()| function
58+
15. The |xolox#session#name_to_path()| function
59+
16. The |xolox#session#path_to_name()| function
60+
17. The |xolox#session#get_names()| function
61+
18. The |xolox#session#complete_names()| function
62+
19. The |xolox#session#complete_names_with_suggestions()| function
63+
20. The |xolox#session#is_tab_scoped()| function
64+
21. The |xolox#session#find_current_session()| function
65+
22. The |xolox#session#get_label()| function
66+
23. The |xolox#session#options_include()| function
67+
24. The |xolox#session#include_tabs()| function
68+
25. The |xolox#session#change_tab_options()| function
69+
26. The |xolox#session#restore_tab_options()| function
70+
27. The |xolox#session#locking_enabled()| function
7071
2. Example function for session name suggestions |example-function-for-session-name-suggestions|
7172
1. The |xolox#session#suggestions#vcs_feature_branch()| function
7273
8. Contact |session-contact|
@@ -542,8 +543,8 @@ might take a while...)
542543
*session-function-reference*
543544
Function reference ~
544545

545-
The documentation of the 38 functions below was extracted from 2 Vim scripts on
546-
March 15, 2015 at 10:15.
546+
The documentation of the 39 functions below was extracted from 2 Vim scripts on
547+
March 15, 2015 at 10:22.
547548

548549
-------------------------------------------------------------------------------
549550
*public-api-for-vim-session-plug-in*
@@ -627,6 +628,17 @@ The *xolox#session#auto_load()* function
627628
Automatically load the default or last used session when Vim starts. Normally
628629
called by the |VimEnter| automatic command event.
629630

631+
-------------------------------------------------------------------------------
632+
The *xolox#session#is_empty()* function
633+
634+
Check that the user has started Vim without editing any files. Used by
635+
|xolox#session#auto_load()| to determine whether automatic session loading
636+
should be performed. Currently checks the following conditions:
637+
638+
1. That the current buffer is either empty (contains no lines and is not
639+
modified) or showing vim-startify [19].
640+
2. That the buffer list either empty or persistent.
641+
630642
-------------------------------------------------------------------------------
631643
The *xolox#session#auto_save()* function
632644

@@ -785,13 +797,13 @@ Contact ~
785797
If you have questions, bug reports, suggestions, etc. the author can be
786798
contacted at peter@peterodding.com. The latest version is available at
787799
http://peterodding.com/code/vim/session/ and http://github.com/xolox/vim-
788-
session. If you like the script please vote for it on Vim Online [19].
800+
session. If you like the script please vote for it on Vim Online [20].
789801

790802
===============================================================================
791803
*session-license*
792804
License ~
793805

794-
This software is licensed under the MIT license [20]. © 2015 Peter Odding
806+
This software is licensed under the MIT license [21]. © 2015 Peter Odding
795807
<peter@peterodding.com> and Ingo Karkat.
796808

797809
Thanks go out to everyone who has helped to improve the vim-session plug-in
@@ -919,7 +931,8 @@ References ~
919931
[16] http://peterodding.com/code/vim/shell/
920932
[17] http://peterodding.com/code/vim/session
921933
[18] http://peterodding.com/code/vim/shell
922-
[19] http://www.vim.org/scripts/script.php?script_id=3150
923-
[20] http://en.wikipedia.org/wiki/MIT_License
934+
[19] https://github.com/mhinz/vim-startify/
935+
[20] http://www.vim.org/scripts/script.php?script_id=3150
936+
[21] http://en.wikipedia.org/wiki/MIT_License
924937

925938
vim: ft=help

0 commit comments

Comments
 (0)