Skip to content

Commit 060dea4

Browse files
committed
Merge pull request #81: Add g:session_autosave_to (override) option
See pull request 81 on GitHub: #81
2 parents 705d726 + 46d6c02 commit 060dea4

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ By default this option is set to `'prompt'`. This means that when you start Vim
156156

157157
By default this option is set to `'prompt'`. When you've opened a session and you quit Vim, the session plug-in will ask whether you want to save the changes to your session. Set this option to `'yes'` to always automatically save open sessions when you quit Vim. To completely disable automatic saving you can set this option to `'no'`.
158158

159+
### The `g:session_autosave_to` option
160+
161+
If `g:session_autosave` is `'yes'` and this option is a nonempty string, automatic session saving always saves to the session with the name given by `g:session_autosave_to` regardless of what the current session is or any other options. In particular, `g:session_default_overwrite` does not have any effect. By default this option isn't set so none of this applies. Refer to [pull request 81] [81] for a more detailed use case.
162+
159163
### The `g:session_autosave_periodic` option
160164

161165
This option sets the interval in minutes for automatic, periodic saving of active sessions. The default is zero which disables the feature.
@@ -613,11 +617,12 @@ Here's an example session script generated by the vim-session plug-in while I wa
613617
unlet SessionLoad
614618

615619

620+
[81]: https://github.com/xolox/vim-session/pull/81
616621
[bg]: http://vimdoc.sourceforge.net/htmldoc/options.html#'background'
617622
[delcommand]: http://vimdoc.sourceforge.net/htmldoc/map.html#:delcommand
623+
[howto-install]: https://github.com/xolox/vim-session/blob/master/INSTALL.md
618624
[mksession]: http://vimdoc.sourceforge.net/htmldoc/starting.html#:mksession
619625
[sessionoptions]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27sessionoptions%27
620626
[source]: http://vimdoc.sourceforge.net/htmldoc/repeat.html#:source
621627
[tabnew]: http://vimdoc.sourceforge.net/htmldoc/tabpage.html#:tabnew
622628
[vimrc]: http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc
623-
[howto-install]: https://github.com/xolox/vim-session/blob/master/INSTALL.md

autoload/xolox/session.vim

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

7-
let g:xolox#session#version = '2.11'
7+
let g:xolox#session#version = '2.12'
88

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

@@ -451,12 +451,16 @@ function! xolox#session#auto_save() " {{{2
451451
" We won't save the session if auto-save is explicitly disabled.
452452
return
453453
endif
454-
" Get the name of the active session (if any).
455-
let name = xolox#session#find_current_session()
456-
" If no session is active and the user doesn't have any sessions yet, help
457-
" them get started by suggesting to create the default session.
458-
if empty(name) && (empty(xolox#session#get_names(0)) || g:session_default_overwrite)
459-
let name = g:session_default_name
454+
" Get the name of the session for automatic saving.
455+
let name = xolox#misc#option#get('session_autosave_to')
456+
if empty(name)
457+
" Get the name of the active session (if any).
458+
let name = xolox#session#find_current_session()
459+
" If no session is active and the user doesn't have any sessions yet,
460+
" help them get started by suggesting to create the default session.
461+
if empty(name) && (empty(xolox#session#get_names(0)) || g:session_default_overwrite)
462+
let name = g:session_default_name
463+
endif
460464
endif
461465
" Prompt the user to save the active/first/default session?
462466
if !empty(name)

doc/session.txt

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ Contents ~
2727
7. The |g:session_extension| option
2828
8. The |g:session_autoload| option
2929
9. The |g:session_autosave| option
30-
10. The |g:session_autosave_periodic| option
31-
11. The |g:session_autosave_silent| option
32-
12. The |g:session_verbose_messages| option
33-
13. The |g:session_default_to_last| option
34-
14. The |g:session_persist_colors| option
35-
15. The |g:session_persist_globals| option
36-
16. The |g:session_restart_environment| option
37-
17. The |g:session_command_aliases| option
38-
18. The |g:session_menu| option
39-
19. The |g:session_name_suggestion_function| option
40-
20. The |g:loaded_session| option
30+
10. The |g:session_autosave_to| option
31+
11. The |g:session_autosave_periodic| option
32+
12. The |g:session_autosave_silent| option
33+
13. The |g:session_verbose_messages| option
34+
14. The |g:session_default_to_last| option
35+
15. The |g:session_persist_colors| option
36+
16. The |g:session_persist_globals| option
37+
17. The |g:session_restart_environment| option
38+
18. The |g:session_command_aliases| option
39+
19. The |g:session_menu| option
40+
20. The |g:session_name_suggestion_function| option
41+
21. The |g:loaded_session| option
4142
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
4243
6. Function reference |session-function-reference|
4344
1. Public API for the vim-session plug-in |public-api-for-vim-session-plug-in|
@@ -358,6 +359,16 @@ to your session. Set this option to "'yes'" to always automatically save open
358359
sessions when you quit Vim. To completely disable automatic saving you can set
359360
this option to "'no'".
360361

362+
-------------------------------------------------------------------------------
363+
The *g:session_autosave_to* option
364+
365+
If |g:session_autosave| is "'yes'" and this option is a nonempty string,
366+
automatic session saving always saves to the session with the name given by
367+
|g:session_autosave_to| regardless of what the current session is or any other
368+
options. In particular, |g:session_default_overwrite| does not have any effect.
369+
By default this option isn't set so none of this applies. Refer to pull request
370+
81 [6] for a more detailed use case.
371+
361372
-------------------------------------------------------------------------------
362373
The *g:session_autosave_periodic* option
363374

@@ -509,9 +520,9 @@ Vim's |:mksession| command isn't really compatible with plug-ins that create
509520
buffers with generated content and because of this the vim-session plug-in
510521
includes specific workarounds for a couple of popular plug-ins:
511522

512-
- BufExplorer [6], Conque Shell [7], NERD tree [8], Project [9] and taglist
513-
[10] windows are supported;
514-
- When shell.vim [11] is installed Vim's full-screen state is persisted;
523+
- BufExplorer [7], Conque Shell [8], NERD tree [9], Project [10] and taglist
524+
[11] windows are supported;
525+
- When shell.vim [12] is installed Vim's full-screen state is persisted;
515526
- The netrw (see |netrw-start|) plug-in supports sessions out of the box.
516527

517528
If your favorite plug-in doesn't work with the vim-session plug-in drop me a
@@ -575,7 +586,7 @@ session script.
575586
The *xolox#session#save_fullscreen()* function
576587

577588
Save the full screen state of Vim. This function provides integration between
578-
my vim-session [12] and vim-shell [13] plug-ins. The first argument is expected
589+
my vim-session [13] and vim-shell [14] plug-ins. The first argument is expected
579590
to be a list, it will be extended with the lines to be added to the session
580591
script.
581592

@@ -615,7 +626,7 @@ Check that the user has started Vim without editing any files. Used by
615626
should be performed. Currently checks the following conditions:
616627

617628
1. That the current buffer is either empty (contains no lines and is not
618-
modified) or showing vim-startify [14].
629+
modified) or showing vim-startify [15].
619630
2. That the buffer list either empty or persistent.
620631

621632
-------------------------------------------------------------------------------
@@ -776,13 +787,13 @@ Contact ~
776787
If you have questions, bug reports, suggestions, etc. the author can be
777788
contacted at peter@peterodding.com. The latest version is available at
778789
http://peterodding.com/code/vim/session/ and http://github.com/xolox/vim-
779-
session. If you like the script please vote for it on Vim Online [15].
790+
session. If you like the script please vote for it on Vim Online [16].
780791

781792
===============================================================================
782793
*session-license*
783794
License ~
784795

785-
This software is licensed under the MIT license [16]. © 2015 Peter Odding
796+
This software is licensed under the MIT license [17]. © 2015 Peter Odding
786797
<peter@peterodding.com> and Ingo Karkat.
787798

788799
Thanks go out to everyone who has helped to improve the vim-session plug-in
@@ -897,16 +908,17 @@ References ~
897908
[3] http://peterodding.com/code/vim/session/#sample_session_script
898909
[4] https://github.com/xolox/vim-session/blob/master/INSTALL.md
899910
[5] http://peterodding.com/code/vim/reload/
900-
[6] http://www.vim.org/scripts/script.php?script_id=42
901-
[7] http://www.vim.org/scripts/script.php?script_id=2771
902-
[8] http://www.vim.org/scripts/script.php?script_id=1658
903-
[9] http://www.vim.org/scripts/script.php?script_id=69
904-
[10] http://www.vim.org/scripts/script.php?script_id=273
905-
[11] http://peterodding.com/code/vim/shell/
906-
[12] http://peterodding.com/code/vim/session
907-
[13] http://peterodding.com/code/vim/shell
908-
[14] https://github.com/mhinz/vim-startify/
909-
[15] http://www.vim.org/scripts/script.php?script_id=3150
910-
[16] http://en.wikipedia.org/wiki/MIT_License
911+
[6] https://github.com/xolox/vim-session/pull/81
912+
[7] http://www.vim.org/scripts/script.php?script_id=42
913+
[8] http://www.vim.org/scripts/script.php?script_id=2771
914+
[9] http://www.vim.org/scripts/script.php?script_id=1658
915+
[10] http://www.vim.org/scripts/script.php?script_id=69
916+
[11] http://www.vim.org/scripts/script.php?script_id=273
917+
[12] http://peterodding.com/code/vim/shell/
918+
[13] http://peterodding.com/code/vim/session
919+
[14] http://peterodding.com/code/vim/shell
920+
[15] https://github.com/mhinz/vim-startify/
921+
[16] http://www.vim.org/scripts/script.php?script_id=3150
922+
[17] http://en.wikipedia.org/wiki/MIT_License
911923

912924
vim: ft=help

0 commit comments

Comments
 (0)