From 7e8212c459b285aacf2dd225c1dad5593314f094 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Fri, 10 Nov 2017 23:17:20 +0800 Subject: vim-patch:8.0.0224 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) https://github.com/vim/vim/commit/7a2699e868bca781e26b060a44fc714d87cfa4ba --- src/nvim/fileio.c | 20 +++++++++++++++----- src/nvim/testdir/test_fileformat.vim | 14 ++++++++++++++ src/nvim/version.c | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index feb16f44d4..81ac98081d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -302,11 +302,11 @@ readfile ( linenr_T skip_count = 0; linenr_T read_count = 0; int msg_save = msg_scroll; - linenr_T read_no_eol_lnum = 0; /* non-zero lnum when last line of - * last read was missing the eol */ - int try_mac = (vim_strchr(p_ffs, 'm') != NULL); - int try_dos = (vim_strchr(p_ffs, 'd') != NULL); - int try_unix = (vim_strchr(p_ffs, 'x') != NULL); + linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of + // last read was missing the eol + int try_mac; + int try_dos; + int try_unix; int file_rewind = FALSE; int can_retry; linenr_T conv_error = 0; /* line nr with conversion error */ @@ -639,6 +639,10 @@ readfile ( curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); curbuf->b_op_start.col = 0; + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); + if (!read_buffer) { int m = msg_scroll; int n = msg_scrolled; @@ -668,6 +672,12 @@ readfile ( else apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, FALSE, NULL, eap); + + // autocommands may have changed it + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); + if (msg_scrolled == n) msg_scroll = m; diff --git a/src/nvim/testdir/test_fileformat.vim b/src/nvim/testdir/test_fileformat.vim index 584f20cdfc..256a7d5b1c 100644 --- a/src/nvim/testdir/test_fileformat.vim +++ b/src/nvim/testdir/test_fileformat.vim @@ -15,3 +15,17 @@ func Test_fileformat_after_bw() call assert_equal(test_fileformats, &fileformat) set fileformats& endfunc + +func Test_fileformat_autocommand() + let filecnt=['', 'foobar', 'eins', '', 'zwei', 'drei', 'vier', 'fünf', ''] + let ffs=&ffs + call writefile(filecnt, 'Xfile', 'b') + au BufReadPre Xfile set ffs=dos ff=dos + new Xfile + call assert_equal('dos', &l:ff) + call assert_equal('dos', &ffs) + " cleanup + let &ffs=ffs + au! BufReadPre Xfile + bw! +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index a31381eddf..c57ca1e815 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -880,7 +880,7 @@ static const int included_patches[] = { // 227, // 226, // 225, - // 224, + 224, 223, // 222, // 221 NA -- cgit From 67a2207c4a4d9b848a4759a7f1e11b5ad1265648 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Fri, 10 Nov 2017 23:28:58 +0800 Subject: vim-patch:8.0.0226 Problem: The test for patch 8.0.0224 misses the CR characters and passes even without the fix. (Christian Brabandt) Solution: Use double quotes and \. https://github.com/vim/vim/commit/1695f99d08076d77ed3015f1edf09a668a4d449a --- src/nvim/testdir/test_fileformat.vim | 24 +++++++++++++----------- src/nvim/version.c | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_fileformat.vim b/src/nvim/testdir/test_fileformat.vim index 256a7d5b1c..de505d3bd0 100644 --- a/src/nvim/testdir/test_fileformat.vim +++ b/src/nvim/testdir/test_fileformat.vim @@ -17,15 +17,17 @@ func Test_fileformat_after_bw() endfunc func Test_fileformat_autocommand() - let filecnt=['', 'foobar', 'eins', '', 'zwei', 'drei', 'vier', 'fünf', ''] - let ffs=&ffs - call writefile(filecnt, 'Xfile', 'b') - au BufReadPre Xfile set ffs=dos ff=dos - new Xfile - call assert_equal('dos', &l:ff) - call assert_equal('dos', &ffs) - " cleanup - let &ffs=ffs - au! BufReadPre Xfile - bw! + let filecnt = ["\", "foobar\", "eins\", "\", "zwei\", "drei", "vier", "fünf", ""] + let ffs = &ffs + call writefile(filecnt, 'Xfile', 'b') + au BufReadPre Xfile set ffs=dos ff=dos + new Xfile + call assert_equal('dos', &l:ff) + call assert_equal('dos', &ffs) + + " cleanup + call delete('Xfile') + let &ffs = ffs + au! BufReadPre Xfile + bw! endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index c57ca1e815..ae1c85d8e2 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -878,7 +878,7 @@ static const int included_patches[] = { 229, // 228, // 227, - // 226, + 226, // 225, 224, 223, -- cgit From ea020f2e26f1e5cb89eb632c1b0ee51daf7718b4 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Sat, 11 Nov 2017 09:04:48 +0800 Subject: fix lint error --- src/nvim/fileio.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 81ac98081d..c3a0a33378 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -307,7 +307,7 @@ readfile ( int try_mac; int try_dos; int try_unix; - int file_rewind = FALSE; + int file_rewind = false; int can_retry; linenr_T conv_error = 0; /* line nr with conversion error */ linenr_T illegal_byte = 0; /* line nr with illegal byte */ @@ -647,39 +647,38 @@ readfile ( int m = msg_scroll; int n = msg_scrolled; - /* - * The file must be closed again, the autocommands may want to change - * the file before reading it. - */ - if (!read_stdin) - close(fd); /* ignore errors */ + // The file must be closed again, the autocommands may want to change + // the file before reading it. + if (!read_stdin) { + close(fd); // ignore errors + } - /* - * The output from the autocommands should not overwrite anything and - * should not be overwritten: Set msg_scroll, restore its value if no - * output was done. - */ - msg_scroll = TRUE; - if (filtering) + // The output from the autocommands should not overwrite anything and + // should not be overwritten: Set msg_scroll, restore its value if no + // output was done. + msg_scroll = true; + if (filtering) { apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else if (read_stdin) + false, curbuf, eap); + } else if (read_stdin) { apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else if (newfile) + false, curbuf, eap); + } else if (newfile) { apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else + false, curbuf, eap); + } else { apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, - FALSE, NULL, eap); + false, NULL, eap); + } - // autocommands may have changed it - try_mac = (vim_strchr(p_ffs, 'm') != NULL); - try_dos = (vim_strchr(p_ffs, 'd') != NULL); - try_unix = (vim_strchr(p_ffs, 'x') != NULL); + // autocommands may have changed it + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); - if (msg_scrolled == n) + if (msg_scrolled == n) { msg_scroll = m; + } if (aborting()) { /* autocmds may abort script processing */ --no_wait_return; -- cgit