Skip to content

Commit 7a2699e

Browse files
committed
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Problem: When 'fileformats' is changed in a BufReadPre auto command, it does not take effect in readfile(). (Gary Johnson) Solution: Check the value of 'fileformats' after executing auto commands. (Christian Brabandt)
1 parent fffbf30 commit 7a2699e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/fileio.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ readfile(
274274
int msg_save = msg_scroll;
275275
linenr_T read_no_eol_lnum = 0; /* non-zero lnum when last line of
276276
* last read was missing the eol */
277-
int try_mac = (vim_strchr(p_ffs, 'm') != NULL);
278-
int try_dos = (vim_strchr(p_ffs, 'd') != NULL);
279-
int try_unix = (vim_strchr(p_ffs, 'x') != NULL);
277+
int try_mac;
278+
int try_dos;
279+
int try_unix;
280280
int file_rewind = FALSE;
281281
#ifdef FEAT_MBYTE
282282
int can_retry;
@@ -738,6 +738,10 @@ readfile(
738738
curbuf->b_op_start.lnum = ((from == 0) ? 1 : from);
739739
curbuf->b_op_start.col = 0;
740740

741+
try_mac = (vim_strchr(p_ffs, 'm') != NULL);
742+
try_dos = (vim_strchr(p_ffs, 'd') != NULL);
743+
try_unix = (vim_strchr(p_ffs, 'x') != NULL);
744+
741745
#ifdef FEAT_AUTOCMD
742746
if (!read_buffer)
743747
{
@@ -769,6 +773,11 @@ readfile(
769773
else
770774
apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname,
771775
FALSE, NULL, eap);
776+
/* autocommands may have changed it */
777+
try_mac = (vim_strchr(p_ffs, 'm') != NULL);
778+
try_dos = (vim_strchr(p_ffs, 'd') != NULL);
779+
try_unix = (vim_strchr(p_ffs, 'x') != NULL);
780+
772781
if (msg_scrolled == n)
773782
msg_scroll = m;
774783

src/testdir/test_fileformat.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ func Test_fileformat_after_bw()
1515
call assert_equal(test_fileformats, &fileformat)
1616
set fileformats&
1717
endfunc
18+
19+
func Test_fileformat_autocommand()
20+
let filecnt=['', 'foobar', 'eins', '', 'zwei', 'drei', 'vier', 'fünf', '']
21+
let ffs=&ffs
22+
call writefile(filecnt, 'Xfile', 'b')
23+
au BufReadPre Xfile set ffs=dos ff=dos
24+
new Xfile
25+
call assert_equal('dos', &l:ff)
26+
call assert_equal('dos', &ffs)
27+
" cleanup
28+
let &ffs=ffs
29+
au! BufReadPre Xfile
30+
bw!
31+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
224,
767769
/**/
768770
223,
769771
/**/

0 commit comments

Comments
 (0)