diff options
-rw-r--r-- | runtime/doc/options.txt | 32 | ||||
-rw-r--r-- | runtime/optwin.vim | 3 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/fileio.c | 10 | ||||
-rw-r--r-- | src/nvim/memline.c | 6 | ||||
-rw-r--r-- | src/nvim/memline_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/ops.c | 4 | ||||
-rw-r--r-- | src/nvim/option.c | 13 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/options.lua | 8 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 3 | ||||
-rw-r--r-- | src/nvim/version.c | 6 | ||||
-rw-r--r-- | test/functional/legacy/fixeol_spec.lua | 59 |
13 files changed, 121 insertions, 27 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 70a585654e..e171c617db 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 7.4. Last change: 2014 Dec 17 +*options.txt* For Vim version 7.4. Last change: 2015 Oct 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -2178,15 +2178,16 @@ A jump table for the options with a short description can be found at |Q_op|. 'endofline' 'eol' boolean (default on) local to buffer When writing a file and this option is off and the 'binary' option - is on, no <EOL> will be written for the last line in the file. This - option is automatically set when starting to edit a new file, unless - the file does not have an <EOL> for the last line in the file, in - which case it is reset. Normally you don't have to set or reset this - option. When 'binary' is off the value is not used when writing the - file. When 'binary' is on it is used to remember the presence of a - <EOL> for the last line in the file, so that when you write the file - the situation from the original file can be kept. But you can change - it if you want to. + is on, or 'fixeol' option is off, no <EOL> will be written for the + last line in the file. This option is automatically set or reset when + starting to edit a new file, depending on whether file has an <EOL> + for the last line in the file. Normally you don't have to set or + reset this option. + When 'binary' is off and 'fixeol' is on the value is not used when + writing the file. When 'binary' is on or 'fixeol' is off it is used + to remember the presence of a <EOL> for the last line in the file, so + that when you write the file the situation from the original file can + be kept. But you can change it if you want to. *'equalalways'* *'ea'* *'noequalalways'* *'noea'* 'equalalways' 'ea' boolean (default on) @@ -2541,6 +2542,17 @@ A jump table for the options with a short description can be found at |Q_op|. fold:c Folded |hl-Folded| diff:c DiffDelete |hl-DiffDelete| + *'fixendofline'* *'fixeol'* *'nofixendofline'* *'nofixeol'* +'fixendofline' 'fixeol' boolean (default on) + local to buffer + {not in Vi} + When writing a file and this option is on, <EOL> at the end of file + will be restored if missing. Turn this option off if you want to + preserve the situation from the original file. + When the 'binary' option is set the value of this option doesn't + matter. + See the 'endofline' option. + *'fkmap'* *'fk'* *'nofkmap'* *'nofk'* 'fkmap' 'fk' boolean (default off) *E198* global diff --git a/runtime/optwin.vim b/runtime/optwin.vim index 09406f260b..dde5dd0c61 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -926,6 +926,9 @@ call <SID>BinOptionL("bin") call append("$", "endofline\tlast line in the file has an end-of-line") call append("$", "\t(local to buffer)") call <SID>BinOptionL("eol") +call append("$", "fixeol\tfixes missing end-of-line at end of text file") +call append("$", "\t(local to buffer)") +call <SID>BinOptionL("fixeol") if has("multi_byte") call append("$", "bomb\tprepend a Byte Order Mark to the file") call append("$", "\t(local to buffer)") diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 3eabb7ee43..6b5bbe3b00 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -612,6 +612,7 @@ struct file_buffer { char_u *b_p_cfu; /* 'completefunc' */ char_u *b_p_ofu; /* 'omnifunc' */ int b_p_eol; /* 'endofline' */ + int b_p_fixeol; /* 'fixendofline' */ int b_p_et; /* 'expandtab' */ int b_p_et_nobin; /* b_p_et saved for binary mode */ char_u *b_p_fenc; /* 'fileencoding' */ diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index bc5b08ef24..87fcddd3e9 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1922,10 +1922,10 @@ failed: check_marks_read(); /* - * Trick: We remember if the last line of the read didn't have - * an eol even when 'binary' is off, for when writing it again with - * 'binary' on. This is required for - * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. + * We remember if the last line of the read didn't have + * an eol even when 'binary' is off, to support turning 'fixeol' off, + * or writing the read again with 'binary' on. The latter is required + * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. */ curbuf->b_no_eol_lnum = read_no_eol_lnum; @@ -3310,7 +3310,7 @@ restore_backup: /* write failed or last line has no EOL: stop here */ if (end == 0 || (lnum == end - && write_bin + && (write_bin || !buf->b_p_fixeol) && (lnum == buf->b_no_eol_lnum || (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol)))) { ++lnum; /* written the line, count it */ diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 0ba8dd98d0..c91a25df6e 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -3954,8 +3954,10 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp) if (ffdos) size += lnum - 1; - /* Don't count the last line break if 'bin' and 'noeol'. */ - if (buf->b_p_bin && !buf->b_p_eol && buf->b_ml.ml_line_count == lnum) { + /* Don't count the last line break if 'noeol' and ('bin' or + * 'nofixeol'). */ + if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol + && buf->b_ml.ml_line_count == lnum) { size -= ffdos + 1; } } diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h index bcc1c673d2..34a002af5d 100644 --- a/src/nvim/memline_defs.h +++ b/src/nvim/memline_defs.h @@ -41,7 +41,7 @@ typedef struct memline { int ml_flags; infoptr_T *ml_stack; /* stack of pointer blocks (array of IPTRs) */ - int ml_stack_top; /* current top if ml_stack */ + int ml_stack_top; /* current top of ml_stack */ int ml_stack_size; /* total number of entries in ml_stack */ linenr_T ml_line_lnum; /* line number of cached line, 0 if not valid */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 956b9c7758..bef0ebaeed 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4964,7 +4964,7 @@ void cursor_pos_info(void) &char_count_cursor, len, eol_size); if (lnum == curbuf->b_ml.ml_line_count && !curbuf->b_p_eol - && curbuf->b_p_bin + && (curbuf->b_p_bin || !curbuf->b_p_fixeol) && (long)STRLEN(s) < len) byte_count_cursor -= eol_size; } @@ -4985,7 +4985,7 @@ void cursor_pos_info(void) } /* Correction for when last line doesn't have an EOL. */ - if (!curbuf->b_p_eol && curbuf->b_p_bin) + if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) byte_count -= eol_size; if (l_VIsual_active) { diff --git a/src/nvim/option.c b/src/nvim/option.c index dbcd230186..da74c0f288 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -122,6 +122,7 @@ static char_u *p_cpt; static char_u *p_cfu; static char_u *p_ofu; static int p_eol; +static int p_fixeol; static int p_et; static char_u *p_fenc; static char_u *p_ff; @@ -3592,6 +3593,9 @@ set_bool_option ( /* when 'endofline' is changed, redraw the window title */ else if ((int *)varp == &curbuf->b_p_eol) { redraw_titles(); + } else if ((int *)varp == &curbuf->b_p_fixeol) { + // when 'fixeol' is changed, redraw the window title + redraw_titles(); } /* when 'bomb' is changed, redraw the window title and tab page text */ else if ((int *)varp == &curbuf->b_p_bomb) { @@ -5304,6 +5308,7 @@ static char_u *get_varp(vimoption_T *p) case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); case PV_EOL: return (char_u *)&(curbuf->b_p_eol); + case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); case PV_ET: return (char_u *)&(curbuf->b_p_et); case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); case PV_FF: return (char_u *)&(curbuf->b_p_ff); @@ -5548,6 +5553,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_bin = p_bin; buf->b_p_bomb = p_bomb; buf->b_p_et = p_et; + buf->b_p_fixeol = p_fixeol; buf->b_p_et_nobin = p_et_nobin; buf->b_p_ml = p_ml; buf->b_p_ml_nobin = p_ml_nobin; @@ -6483,6 +6489,7 @@ void save_file_ff(buf_T *buf) * from when editing started (save_file_ff() called). * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was * changed and 'binary' is not set. + * Also when 'endofline' was changed and 'fixeol' is not set. * When "ignore_empty" is true don't consider a new, empty buffer to be * changed. */ @@ -6497,9 +6504,9 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty) && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL) return FALSE; if (buf->b_start_ffc != *buf->b_p_ff) - return TRUE; - if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol) - return TRUE; + return true; + if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) + return true; if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) return TRUE; if (buf->b_start_fenc == NULL) diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index d4d3410d5c..c72e1cf0bb 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -665,6 +665,7 @@ enum { , BV_DEF , BV_INC , BV_EOL + , BV_FIXEOL , BV_EP , BV_ET , BV_FENC diff --git a/src/nvim/options.lua b/src/nvim/options.lua index b22e994efe..5187340629 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -799,6 +799,14 @@ return { defaults={if_true={vi="vert:|,fold:-"}} }, { + full_name='fixendofline', abbreviation='fixeol', + type='bool', scope={'buffer'}, + vi_def=true, + redraw={'statuslines'}, + varname='p_fixeol', + defaults={if_true={vi=true}} + }, + { full_name='fkmap', abbreviation='fk', type='bool', scope={'global'}, vi_def=true, diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 57e25560de..3813c45726 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -418,7 +418,8 @@ static void read_input(DynamicBuffer *buf) // Finished a line, add a NL, unless this line should not have one. // FIXME need to make this more readable if (lnum != curbuf->b_op_end.lnum - || !curbuf->b_p_bin + || (!curbuf->b_p_bin + && curbuf->b_p_fixeol) || (lnum != curbuf->b_no_eol_lnum && (lnum != curbuf->b_ml.ml_line_count diff --git a/src/nvim/version.c b/src/nvim/version.c index 2b0d6f22f2..932ebefa8a 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -98,7 +98,7 @@ static int included_patches[] = { // 901, // 900 NA // 899 NA - // 898, + 898, // 897, // 896, // 895, @@ -201,7 +201,7 @@ static int included_patches[] = { // 798, // 797, // 796 NA - // 795, + 795, // 794 NA 793, // 792, @@ -211,7 +211,7 @@ static int included_patches[] = { // 788 NA 787, 786, - // 785, + 785, 784, // 783 NA // 782, diff --git a/test/functional/legacy/fixeol_spec.lua b/test/functional/legacy/fixeol_spec.lua new file mode 100644 index 0000000000..113d14f6ca --- /dev/null +++ b/test/functional/legacy/fixeol_spec.lua @@ -0,0 +1,59 @@ +-- Tests for 'fixeol' + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('fixeol', function() + setup(clear) + + it('is working', function() + -- First write two test files – with and without trailing EOL. + -- Use Unix fileformat for consistency. + execute('set ff=unix') + execute('enew!') + feed('awith eol<esc>:w! XXEol<cr>') + execute('enew!') + execute('set noeol nofixeol') + feed('awithout eol<esc>:w! XXNoEol<cr>') + execute('set eol fixeol') + execute('bwipe XXEol XXNoEol') + + -- Try editing files with 'fixeol' disabled. + execute('e! XXEol') + feed('ostays eol<esc>:set nofixeol<cr>') + execute('w! XXTestEol') + execute('e! XXNoEol') + feed('ostays without<esc>:set nofixeol<cr>') + execute('w! XXTestNoEol') + execute('bwipe XXEol XXNoEol XXTestEol XXTestNoEol') + execute('set fixeol') + + -- Append "END" to each file so that we can see what the last written char was. + feed('ggdGaEND<esc>:w >>XXEol<cr>') + execute('w >>XXNoEol') + execute('w >>XXTestEol') + execute('w >>XXTestNoEol') + + -- Concatenate the results. + execute('e! test.out') + feed('a0<esc>:$r XXEol<cr>') + execute('$r XXNoEol') + feed('Go1<esc>:$r XXTestEol<cr>') + execute('$r XXTestNoEol') + execute('w') + + -- Assert buffer contents. + expect([=[ + 0 + with eol + END + without eolEND + 1 + with eol + stays eol + END + without eol + stays withoutEND]=]) + end) +end) |