Skip to content

Commit d5c3b6a

Browse files
committed
Bug fix: Re-implement Vim's special handling of initial, empty buffer
See issue #60 on GitHub: #60 This is a follow up to my recent changes for issue #28: Bug fix: Disable Vim's special handling of initial, empty buffer #28
1 parent 74e5034 commit d5c3b6a

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
236236
<!-- Start of generated documentation -->
237237

238238
The documentation of the 34 functions below was extracted from
239-
2 Vim scripts on June 24, 2013 at 22:49.
239+
1 Vim scripts on June 24, 2013 at 23:47.
240240

241-
### Public API for vim-notes plug-in
241+
### Public API for the vim-notes plug-in
242242

243243
#### The `xolox#session#save_session()` function
244244

autoload/xolox/session.vim

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
" Public API for vim-notes plug-in.
1+
" Public API for the vim-notes plug-in.
22
"
33
" Author: Peter Odding
44
" Last Change: June 24, 2013
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.4.3'
7+
let g:xolox#session#version = '2.4.4'
88

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

11-
" The functions in this fold take a single list argument in which the Vim
12-
" script lines are stored that should be executed to restore the (relevant
13-
" parts of the) current Vim editing session. The only exception to this is
14-
" xolox#session#save_session() which expects the target filename as 2nd
15-
" argument:
16-
1711
function! xolox#session#save_session(commands, filename) " {{{2
1812
" Save the current Vim editing session to a Vim script using the
1913
" [:mksession] [] command and some additional Vim magic provided by the
@@ -193,6 +187,15 @@ function! xolox#session#save_state(commands) " {{{2
193187
call map(lines, 's:tabpage_filter(buffers, v:val)')
194188
endif
195189
call extend(a:commands, map(lines, 's:state_filter(v:val)'))
190+
" Re-implement Vim's special handling of the initial, empty buffer.
191+
call add(a:commands, "if exists('s:wipebuf')")
192+
call add(a:commands, " if empty(bufname(s:wipebuf)) && !getbufvar(s:wipebuf, '&modified')")
193+
call add(a:commands, " let s:wipebuflines = getbufline(s:wipebuf, 1, '$')")
194+
call add(a:commands, " if len(s:wipebuflines) <= 1 && empty(get(s:wipebuflines, 0, ''))")
195+
call add(a:commands, " silent exe 'bwipe ' . s:wipebuf")
196+
call add(a:commands, " endif")
197+
call add(a:commands, " endif")
198+
call add(a:commands, "endif")
196199
return 1
197200
finally
198201
let &sessionoptions = ssop_save
@@ -252,7 +255,7 @@ function! s:state_filter(line) " {{{3
252255
" when :mksession adds corresponding :argglobal and/or :argument commands
253256
" to the session script.
254257
return '" ' . a:line
255-
elseif a:line =~ "^\\s*silent exe 'bwipe ' \\. s:wipebuf$"
258+
elseif a:line =~ "^\\s*silent exe 'bwipe ' \\. s:wipebuf$" || a:line =~ '^unlet! s:wipebuf$'
256259
" Disable Vim's special handling of the initial, empty buffer because it
257260
" breaks restoring of special windows with content generated by a Vim
258261
" plug-in. The :mksession command doesn't have this problem because it

doc/session.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Contents ~
3434
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
3535
6. Known issues |session-known-issues|
3636
7. Function reference |session-function-reference|
37-
1. Public API for vim-notes plug-in |session-public-api-for-vim-notes-plug-in|
37+
1. Public API for the vim-notes plug-in |session-public-api-for-vim-notes-plug-in|
3838
1. The |xolox#session#save_session()| function
3939
2. The |xolox#session#save_globals()| function
4040
3. The |xolox#session#save_features()| function
@@ -476,12 +476,12 @@ might take a while...)
476476
*session-function-reference*
477477
Function reference ~
478478

479-
The documentation of the 34 functions below was extracted from 2 Vim scripts on
480-
June 24, 2013 at 22:49.
479+
The documentation of the 34 functions below was extracted from 1 Vim scripts on
480+
June 24, 2013 at 23:47.
481481

482482
-------------------------------------------------------------------------------
483483
*session-public-api-for-vim-notes-plug-in*
484-
Public API for vim-notes plug-in ~
484+
Public API for the vim-notes plug-in ~
485485

486486
-------------------------------------------------------------------------------
487487
The *xolox#session#save_session()* function

0 commit comments

Comments
 (0)