mksession restore just deleted buffer

45 views
Skip to first unread message

niva...@gmail.com

unread,
Feb 14, 2019, 4:31:27 PM2/14/19
to vim_use
Hi,


In _vimrc sessionoptions are defined as is :

set sessionoptions=help,winsize,winpos,buffers

I have two buffers in buffers' list and after buffer deleting the second one, restarting vim, it is always in the buffers's list.


I don't understand why it appears again.

Thank you
NiVa

vim.gif

meine

unread,
Feb 15, 2019, 5:57:05 AM2/15/19
to vim...@googlegroups.com
On Thu, Feb 14, 2019 at 01:31:26PM -0800, niva...@gmail.com wrote:
> I have two buffers in buffers' list and after buffer deleting the second one, restarting vim, it is always in the buffers's list.
>
> I don't understand why it appears again.

You have to update the vim session you made by using `:mks!`

//meine

niva...@gmail.com

unread,
Feb 15, 2019, 11:57:53 AM2/15/19
to vim_use
It's done via these :


if has('autocmd')
aug Geometry
au!
au VimLeavePre * call geometry#SaveGeometry()
au VimEnter * call geometry#RestoreGeometry()
aug END
endif


fun! geometry#MkSession() "{{{
silent! execute 'mks! '.g:geometry#sessionfile
endfunction "}}}

fun! geometry#GetGeometry() "{{{
return [&columns,&lines] + getwinpos()
endfunction "}}}

fun! geometry#SaveGeometry() "{{{
let ret = writefile(geometry#GetGeometry(), g:geometry#file, 'b')
call geometry#MkSession()
endfunction "}}}

fun! geometry#RestoreGeometry() "{{{

if filereadable(g:geometry#file)
let geom = readfile(g:geometry#file) "137*21+156+156
" if geom != ''
" let winsize = split(geom,'+')
" silent! execute 'set columns='.split(winsize[0],'*')[0]
" silent! execute 'set lines='.split(winsize[0],'*')[1]
" silent! execute "winpos ".winsize[1].' '.winsize[2]
" endif
silent! execute 'set columns='.geom[0]
silent! execute 'set lines='.geom[1]
silent! execute "winpos ".geom[2].' '.geom[3]
endif

if filereadable(g:geometry#sessionfile)
silent! execute 'source '.g:geometry#sessionfile
endif
endfunction "}}}

meine

unread,
Feb 16, 2019, 5:43:46 AM2/16/19
to vim...@googlegroups.com
On Fri, Feb 15, 2019 at 08:57:52AM -0800, niva...@gmail.com wrote:
> Le vendredi 15 février 2019 11:57:05 UTC+1, meine a écrit :
> > On Thu, Feb 14, 2019 at 01:31:26PM -0800, niva...@gmail.com wrote:
> > > I have two buffers in buffers' list and after buffer deleting the second one, restarting vim, it is always in the buffers's list.
> > >
> > > I don't understand why it appears again.
> >
> > You have to update the vim session you made by using `:mks!`
> >
> > //meine
>
> It's done via these :
>
>
> if has('autocmd')

<snip>

I'm not a coder, so I don't see the details of how you do this,

but isn't it a rather complicated way instead of a built-in vim
function?

//meine

niva...@gmail.com

unread,
Feb 16, 2019, 5:51:39 AM2/16/19
to vim_use
Nothing complicated,

your advise is coded in the function! geometry#MkSession()
silent! execute 'mks! '.g:geometry#sessionfile

And this function is called just before leaving Vim (au VimLeavePre * call geometry#SaveGeometry())

meine

unread,
Feb 16, 2019, 5:56:37 AM2/16/19
to niva...@gmail.com, vim_use
> Nothing complicated,
>
> your advise is coded in the function! geometry#MkSession()
> silent! execute 'mks! '.g:geometry#sessionfile
>
> And this function is called just before leaving Vim (au VimLeavePre * call geometry#SaveGeometry())

Merci!

//meine

niva...@gmail.com

unread,
Feb 17, 2019, 7:36:00 AM2/17/19
to vim_use
Yes but this code does not work well...

when I list buffers ":buffers", it shows me old buffer that I delete ":bd! NoBu".

Then Leave Vim (so the autocmd does its job), relaunch Vim, the buffers' list contains again previous deleted buffer and a file is create at the original buffer's folder.

So not working.

Salman Halim

unread,
Feb 17, 2019, 8:52:20 AM2/17/19
to Vim Users
After the "bd!", does listing buffers again confirm that it's gone?

Have you examined the contents and timestamp of the session file to see if it contains the details of that buffer?

How about disabling the autocommand and manually saving the session?

Anything in your session options or viminfo that might be contributing something?

Salman

niva...@gmail.com

unread,
Feb 17, 2019, 11:54:06 AM2/17/19
to vim_use
Le dimanche 17 février 2019 14:52:20 UTC+1, Salman Halim a écrit :
> On Sun, Feb 17, 2019, 07:36 <niva...@gmail.com wrote:
> Le samedi 16 février 2019 11:56:37 UTC+1, meine a écrit :
>
> > > Nothing complicated,
>
> > >
>
> > > your advise is coded in the function! geometry#MkSession()
>
> > >   silent! execute 'mks! '.g:geometry#sessionfile
>
> > >
>
> > > And this function is called just before leaving Vim (au VimLeavePre * call geometry#SaveGeometry())
>
> >
>
> > Merci!
>
> >
>
> > //meine
>
>
>
>
>
> Yes but this code does not work well...
>
>
>
> when I list buffers ":buffers", it shows me old buffer that I delete ":bd! NoBu".
>
>
>
> Then Leave Vim (so the autocmd does its job), relaunch Vim, the buffers' list contains again previous deleted buffer and a file is create at the original buffer's folder.
>
>
>
> So not working.
>
>
>
> After the "bd!", does listing buffers again confirm that it's gone?
>
no.
>
> Have you examined the contents and timestamp of the session file to see if it contains the details of that buffer?
>
timestamp is good at vim leaving and it contains infos of that buffer :

let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
argglobal
%argdel
$argadd ~/Desktop/thatbuffer.txt
winpos 278 74

>
> How about disabling the autocommand and manually saving the session?
>
I don't want to lose interest of autocmd but I can try.
>
> Anything in your session options or viminfo that might be contributing something?
>
just classical set sessionoptions=help,winsize,winpos

>
> Salman

Salman Halim

unread,
Feb 17, 2019, 12:32:04 PM2/17/19
to Vim Users



On Sun, Feb 17, 2019, 11:54 <niva...@gmail.com wrote:
Le dimanche 17 février 2019 14:52:20 UTC+1, Salman Halim a écrit :

> After the "bd!", does listing buffers again confirm that it's gone?
>
no.

Ah, so the session and autocommand aren't to blame. If you call "bd!" and the buffer is still there, then maybe bufwipe or something needs to be checked?

>
> Have you examined the contents and timestamp of the session file to see if it contains the details of that buffer?
>
timestamp is good at vim leaving and it contains infos of that buffer :

let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
argglobal
%argdel
$argadd ~/Desktop/thatbuffer.txt
winpos 278 74

It seems as if the session process isn't at fault here, but the buffer wiping is. 

The call to winpos seems to indicate that the buffer is still open in an active window? That's not consistent with a deleted buffer. 


>
> How about disabling the autocommand and manually saving the session?
>
I don't want to lose interest of autocmd but I can try.

I was trying to isolate the three different variables: buffer delete, autocommand and session making. 

>
> Anything in your session options or viminfo that might be contributing something?
>
just classical set sessionoptions=help,winsize,winpos

Yeah, that's innocuous. I was wondering whether viminfo might have something to do, but based on your session snippet above, it's clearly not viminfo. 

Salman

Ni Va

unread,
Feb 17, 2019, 12:44:44 PM2/17/19
to vim...@googlegroups.com
Sorry, for the first point: when I use ":bd! NoOfBuffer", it is not listed yet. So bd is working well.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/DuaO_Sj9hg4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

niva...@gmail.com

unread,
Feb 17, 2019, 12:45:07 PM2/17/19
to vim_use

Salman Halim

unread,
Feb 17, 2019, 2:17:17 PM2/17/19
to Vim Users
Okay, so what happens if you close all tabs and leave in just one window, wiping/deleting all buffers, verify that :buffers looks good, showing only the open window, and then save the session? Does the session file still have buffers that it shouldn't?

Basically, I'm trying to figure out whether there's a bug in buffer deletion, session creation or the autocommand mechanism, but to do that we need to create a simple example that demonstrates the problem and eliminates any potential human error. 

Salman

niva...@gmail.com

unread,
Feb 17, 2019, 2:53:10 PM2/17/19
to vim_use
Okay I've done some further tests.

:bufdo! bd! >> clear all buffers as you said.

Yesterday I had copied my session.vim file into ~/desktop so it seems it take care about history actions.

When I close Vim, no buffer is listed in buffers'list.
When I open Vim again, buffers'list contains my yesterday ~/desktop/sessions.vim which is not exsiting anymore.

... see the gif.
vim.gif

niva...@gmail.com

unread,
Feb 17, 2019, 2:53:39 PM2/17/19
to vim_use

Salman Halim

unread,
Feb 17, 2019, 3:38:38 PM2/17/19
to Vim Users
> Okay I've done some further tests.
>
> :bufdo! bd! >> clear all buffers as you said.
>
> Yesterday I had copied my session.vim file into ~/desktop so it seems it take care about history actions.
>
> When I close Vim, no buffer is listed in buffers'list.
> When I open Vim again, buffers'list contains my yesterday ~/desktop/sessions.vim which is not exsiting anymore.
>
> ... see the gif.

https://drive.google.com/open?id=1xPX4InUKhYEVrBuosfHqNk_SNRXY7PgT

1. Out of curiosity, what are the values of g:geometry#sessionfile and g:geometry#file?
2. Have you tried writing a separate session file out by hand right after doing the bufdo! bd! to see if it that session file contains anything different than the automatically generated one?
3. Have you tried using bufwipe instead of bufdelete? bufdo! bw! (That's "stronger" than deleting a buffer.)
4. The list of buffers is controlled through viminfo, not just sessions. What's the timestamp of your viminfo? Is it getting updated every time you quit? What are its contents? Could the buffer be coming back through that file?

Here's the thing: I don't have the autocommands that you do. I also cannot reproduce what you're seeing. I remove all my buffers, write out the session file with an empty Vim (by hand), quit and come back. The first thing I do is execute ':buffers' to confirm it's still empty and then load the session file. My second call to :buffers is STILL empty. I also have no buffers or args in my session file.

-- 
 
Salman

I, too, shall something make and glory in the making.

niva...@gmail.com

unread,
Feb 18, 2019, 11:50:01 AM2/18/19
to vim_use
Le dimanche 17 février 2019 21:38:38 UTC+1, Salman Halim a écrit :
> > Okay I've done some further tests.
>
> >
>
> > :bufdo! bd! >> clear all buffers as you said.
>
> >
>
> > Yesterday I had copied my session.vim file into ~/desktop so it seems it take care about history actions.
>
> >
>
> > When I close Vim, no buffer is listed in buffers'list.
>
> > When I open Vim again, buffers'list contains my yesterday ~/desktop/sessions.vim which is not exsiting anymore.
>
> >
>
> > ... see the gif.
>
>
>
> https://drive.google.com/open?id=1xPX4InUKhYEVrBuosfHqNk_SNRXY7PgT
>
>
>
> 1. Out of curiosity, what are the values of g:geometry#sessionfile and g:geometry#file?
Ok rewrite the autoload vimscript as below : now jsut one session.

> 2. Have you tried writing a separate session file out by hand right after doing the bufdo! bd! to see if it that session file contains anything different than the automatically generated one?



> 3. Have you tried using bufwipe instead of bufdelete? bufdo! bw! (That's "stronger" than deleting a buffer.)

Tried :bufdo! bw! out of :bufdo! bd! then :buffers returns only noname buffer

Then I confirm the the attached mainsession.vim is written at vim leave.

And on reload, buffers command list noname and mainsession.Vim

> 4. The list of buffers is controlled through viminfo, not just sessions. What's the timestamp of your viminfo? Is it getting updated every time you quit? What are its contents? Could the buffer be coming back through that file?
>
:rviminfo says nothing.


>
> Here's the thing: I don't have the autocommands that you do. I also cannot reproduce what you're seeing. I remove all my buffers, write out the session file with an empty Vim (by hand), quit and come back. The first thing I do is execute ':buffers' to confirm it's still empty and then load the session file. My second call to :buffers is STILL empty. I also have no buffers or args in my session file.
>
> -- 
>
>  
> Salman
>
> I, too, shall something make and glory in the making.



autoload/geometry.vim
let g:geometry#sessionfile=expand('$vimruntime/sessions/mainSession.vim')

fun! geometry#SaveGeometry() "{{{

echo 'Save'
if !filereadable(g:geometry#sessionfile)
call mkdir(expand('$vimruntime/sessions'),0700)
endif
silent! execute 'mks! '.g:geometry#sessionfile
endfunction "}}}

fun! geometry#RestoreGeometry() "{{{

echo 'Restore'
mainSession.vim

niva...@gmail.com

unread,
Feb 19, 2019, 3:49:36 AM2/19/19
to vim_use
Solved, after some tests, it appears that sessionoptions in _vimrc need to be written like this :
set sessionoptions=buffers,help,resize,winpos,winsize,
instead of
set sessionoptions=buffers,help,resize,winpos,winsize

Otherwise, there is no restoration of winsize.

Salman Halim

unread,
Feb 19, 2019, 2:55:45 PM2/19/19
to Vim Users
A trailing comma shouldn't be required. Can a Vim dev have a look, please?

--

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

niva...@gmail.com

unread,
Feb 19, 2019, 3:08:48 PM2/19/19
to vim_use
Can you confirm this first?

Salman Halim

unread,
Feb 19, 2019, 3:18:24 PM2/19/19
to Vim Users
Fair point. Unfortunately, no, I cannot: I get the exact same session file whether or not I have a trailing comma. (Diff shows no differences, the file contains nothing off and loading it doesn't add extra buffers.)

I'm on Windows, using GVim 8.1.822. You?

--

Salman

On Tue, Feb 19, 2019, 15:08 <niva...@gmail.com wrote:
Can you confirm this first?

niva...@gmail.com

unread,
Feb 20, 2019, 2:08:24 AM2/20/19
to vim_use
Windows 10 gvim 8.1.952

Salman Halim

unread,
Feb 20, 2019, 8:23:32 AM2/20/19
to Vim Users
I built 956 yesterday, but still don't see the problem you're seeing. Sorry...

I do see a problem with DLL dependencies. Will send a separate email message. 

--

Salman

On Wed, Feb 20, 2019, 02:08 <niva...@gmail.com wrote:
Windows 10 gvim 8.1.952

niva...@gmail.com

unread,
Feb 20, 2019, 1:27:08 PM2/20/19
to vim_use
Ok so there is no pb. Maybe melting pot of all plugins or _vimrc configuration.
Reply all
Reply to author
Forward
0 new messages