On 11/10/2016 20:06, Bram Moolenaar wrote:
Mike Williams wrote:

I imagine this is pretty obscure but I have hit it a couple of times
this last week.  If your fileformats string initial entry is different
to the fileformat default value then doing :bwipeout on the last buffer
results in the new buffer using the default fileformat and not the first
format from fileformats.  Follow?  Try the following on Windows:

 > vim -u NONE -U NONE --cmd 'set ffs=unix' -c 'set ff? | bw | set ff?'

Prefer Unix?  This shows the same effect:

$ vim -u NONE -U NONE --cmd 'set ffs=dos' -c 'set ff? | bw | set ff?'

You should see the fileformat change across the bwipeout.

Attached is a patch that sets the new buffer's fileformat from an
existing fileformats in buf_copy_options() or the global default
fileformat if ffs is not set.  It Works For Me(TM) but I don't know if
the side effects in set_fileformat() cause problems when called from

When using ":new" it does set the expected value.  This happens in
do_ecmd(), by calling set_file_options().  We could do the same in

New diff with just a call to set_file_options() added. Still working ok for me.

Can you please add a test?

New style test is included. The double bwipeout is needed to show the original issue and change in behaviour. Test should work on dos, unix, and mac - tested on linux apparently ok, tests hang on windows for me still tracking down why, and not tested on mac.


I just planted an Algebra tree. It has square roots.

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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -2081,6 +2081,7 @@ test_arglist \
 	test_farsi \
 	test_feedkeys \
 	test_file_perm \
+	test_fileformat \
 	test_filter_cmd \
 	test_filter_map \
 	test_fnameescape \
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -10735,7 +10735,7 @@ buf_copy_options(buf_T *buf, int flags)
 #ifdef FEAT_MBYTE
 		buf->b_p_fenc = vim_strsave(p_fenc);
-		buf->b_p_ff = vim_strsave(p_ff);
+		set_file_options(TRUE, NULL);
 #if defined(FEAT_QUICKFIX)
 		buf->b_p_bh = empty_option;
 		buf->b_p_bt = empty_option;
diff --git a/src/testdir/test_fileformat.vim b/src/testdir/test_fileformat.vim
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_fileformat.vim
@@ -0,0 +1,16 @@
+" Test behavior of fileformat after bwipeout of last buffer
+func Test_fileformat_after_bw()
+	bwipeout
+	set fileformat&
+	if &fileformat == 'dos'
+		let test_fileformats = 'unix'
+	elseif &fileformat == 'unix'
+		let test_fileformats = 'mac'
+	else  " must be mac
+		let test_fileformats = 'dos'
+	endif
+	exec 'set fileformats='.test_fileformats
+	bwipeout!
+	call assert_equal(test_fileformats, &fileformat)

Raspunde prin e-mail lui