2015-03-08 16:49 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> ZyX wrote:
>
>> >> Consider the following code:
>> >>
>> >>     % vim -u NONE -i NONE --cmd 'autocmd BufReadCmd edit://foo :call 
>> >> setline(".", "foo")|setlocal buftype=nofile' -c 'edit edit://foo' -c 
>> >> 'mksession ses.vim' -c qall!
>> >>     % vim -u NONE -i NONE --cmd 'autocmd BufReadCmd edit://foo :call 
>> >> setline(".", "foo")|setlocal buftype=nofile' -S ses.vim
>> >>
>> >> . This will show you the empty buffer in the second Vim instance with an 
>> >> empty name. But the following code:
>> >>
>> >>     % vim -u NONE -i NONE --cmd 'autocmd BufReadCmd edit://foo :call 
>> >> setline(".", "foo")|setlocal buftype=nofile' -c 'edit edit://foo' -c 
>> >> 'edit bar' -c 'mksession ses.vim' -c qall!
>> >>     % vim -u NONE -i NONE --cmd 'autocmd BufReadCmd edit://foo :call 
>> >> setline(".", "foo")|setlocal buftype=nofile' -S ses.vim -c bnext
>> >>
>> >> (additions: `-c 'edit bar'` in first command, `-c bnext` in the second) 
>> >> will show you buffer with `foo` on the first line.
>> >
>> > I find it a bit difficult to see what the problem is without actually
>> > executing the commands.  Perhaps you can point to the lines in the
>> > session file that are not correct?
>>
>> With `buftype=nofile` Vim will execute `badd +0 edit://foo`, then some
>> stuff, then `file edit://foo`. Neither of these commands launches
>> BufReadCmd event. With other &buftype it will execute `badd +0
>> edit://foo`, then `edit edit://foo` which launches BufReadCmd.
>>
>> Note: `nofile` was preferred over `nowrite` because with `nofile`
>> buffer name is not handled like a file name. Actual buffer name is
>> something like `aurum://diff:…`.
>
> OK, so we have a "nofile" buffer for which we would want to use the
> ":edit" command, so that the BufReadCmd gets triggered.  But "nofile"
> basically means that one can't use ":edit".  So how about using
> ":doauto BufReadCmd {fname}"?  Can you put that in the session file to
> check if it works?  Once we know the right command it should be easy to
> add it to the session file writing.

The problem is actually worse then that:

1. BufReadCmd command is not launched in first case. Fixed by adding
`:doautocmd BufReadCmd` just after `file` call (adding file name is
not needed because current file name is the default for :doautocmd).
2. The edit://foo buffer replaces empty buffer, so it is wiped out,
effectively making `doautocmd` call useless.

I.e. I have to make these changes:

==================================================
--- ses.old.vim 2015-03-08 17:06:56.996446157 +0300
+++ ses.new.vim 2015-03-08 17:07:16.087336270 +0300
@@ -23,6 +23,7 @@
 argglobal
 enew
 file edit://foo
+doautocmd BufReadCmd
 setlocal keymap=
 setlocal noarabic
 setlocal noautoindent
@@ -129,7 +130,7 @@
 setlocal wrapmargin=0
 tabnext 1
 if exists('s:wipebuf')
-  silent exe 'bwipe ' . s:wipebuf
+  " silent exe 'bwipe ' . s:wipebuf
 endif
 unlet! s:wipebuf
 set winheight=1 winwidth=20 shortmess=
==================================================

, both files attached. I think that this :bwipe call is there for a
reason, though I do not understand why it looks like it looks: I would
use

==================================================
--- ses.old.vim 2015-03-08 17:06:56.996446157 +0300
+++ ses.new2.vim 2015-03-08 17:14:06.786228799 +0300
@@ -8,9 +8,7 @@
 let v:this_session=expand("<sfile>:p")
 silent only
 cd ~/tmp/image/raiagent
-if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
-  let s:wipebuf = bufnr('%')
-endif
+let s:initbuf = bufnr('%')
 set shortmess=aoO
 badd +0 edit://foo
 argglobal
@@ -128,10 +127,10 @@
 setlocal wrap
 setlocal wrapmargin=0
 tabnext 1
-if exists('s:wipebuf')
-  silent exe 'bwipe ' . s:wipebuf
+if empty(bufname(s:initbuf)) && !getbufvar(s:initbuf, '&modified') &&
getbufline(s:initbuf, 1, '$') ==# ['']
+    silent execute 'bwipeout' s:initbuf
 endif
-unlet! s:wipebuf
+unlet s:initbuf
 set winheight=1 winwidth=20 shortmess=
 let s:sx = expand("<sfile>:p:r")."x.vim"
 if file_readable(s:sx)
==================================================

: i.e. check whether initial buffer needs to be removed *after* adding
new buffers because as you see as the result of sourcing ses.old.vim
it may appear that initial empty buffer may be reused by some of the
buffers created by the session file code.

I.e. the best session code I came up with

==================================================
--- ses.old.vim 2015-03-08 17:06:56.996446157 +0300
+++ ses.new3.vim 2015-03-08 17:18:16.835930335 +0300
@@ -10,5 +10,3 @@
 cd ~/tmp/image/raiagent
-if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
-  let s:wipebuf = bufnr('%')
-endif
+let s:initbuf = bufnr('%')
 set shortmess=aoO
@@ -25,2 +23,3 @@
 file edit://foo
+doautocmd BufReadCmd
 setlocal keymap=
@@ -130,6 +129,6 @@
 tabnext 1
-if exists('s:wipebuf')
-  silent exe 'bwipe ' . s:wipebuf
+if empty(bufname(s:initbuf)) && !getbufvar(s:initbuf, '&modified') &&
getbufline(s:initbuf, 1, '$') ==# ['']
+    silent execute 'bwipeout' s:initbuf
 endif
-unlet! s:wipebuf
+unlet s:initbuf
 set winheight=1 winwidth=20 shortmess=
==================================================

>
> --
> Q:  Why do ducks have flat feet?
> A:  To stamp out forest fires.
>
> Q:  Why do elephants have flat feet?
> A:  To stamp out flaming ducks.
>
>  /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
> ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\  an exciting new programming language -- http://www.Zimbu.org        ///
>  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: ses.new.vim
Description: Binary data

Attachment: ses.old.vim
Description: Binary data

Attachment: ses.new2.vim
Description: Binary data

Attachment: ses.new3.vim
Description: Binary data

Raspunde prin e-mail lui