Patch to set fileformat from ffs having done bw on last buffer

28 views
Skip to first unread message

Mike Williams

unread,
Oct 11, 2016, 12:32:19 PM10/11/16
to vim_dev
Hi,

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
buf_copy_options().

HTH - TTFN

Mike
--
I don't worry about tomorrow's problems - I'm not even acquainted with
yesterdays.
option.c.diff

Bram Moolenaar

unread,
Oct 11, 2016, 3:07:05 PM10/11/16
to Mike Williams, vim_dev

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
> buf_copy_options().

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
buf_copy_options().

Can you please add a test?


--
A hamburger walks into a bar, and the bartender says: "I'm sorry,
but we don't serve food here."

/// Bram Moolenaar -- Br...@Moolenaar.net -- 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 ///

Mike Williams

unread,
Oct 12, 2016, 8:33:13 AM10/12/16
to Bram Moolenaar, vim_dev
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
>> buf_copy_options().
>
> 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
> buf_copy_options().

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.

HTH - TTFN

Mike
--
I just planted an Algebra tree. It has square roots.
fileformat.diff

Bram Moolenaar

unread,
Oct 12, 2016, 10:59:38 AM10/12/16
to Mike Williams, vim_dev
Thanks. I'll include it.

I'll add the test to test_alot, it's a bit more efficient.

I see several tests fail. I can fix it this way:

if (*p_ffs == NUL)
buf->b_p_ff = vim_strsave(p_ff);
else
set_file_options(TRUE, NULL);
buf->b_start_ffc = *buf->b_p_ff;

Hmm, test67 still hangs, other tests fail. Ah, the test input was
changed by a previous failure. I'll fix that in another patch.

--
I wonder, do vegetarians eat fruit bats?
Reply all
Reply to author
Forward
0 new messages