mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
vim-patch:7.4.785
Problem: On some systems automatically adding the missing EOL causes
problems. Setting 'binary' has too many side effects.
Solution: Add the 'fixeol' option, default on. (Pavel Samarkin)
34d72d4b6c
This commit is contained in:
@@ -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
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@@ -2191,15 +2191,16 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
'endofline' 'eol' boolean (default on)
|
'endofline' 'eol' boolean (default on)
|
||||||
local to buffer
|
local to buffer
|
||||||
When writing a file and this option is off and the 'binary' option
|
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
|
is on, or 'fixeol' option is off, no <EOL> will be written for the
|
||||||
option is automatically set when starting to edit a new file, unless
|
last line in the file. This option is automatically set or reset when
|
||||||
the file does not have an <EOL> for the last line in the file, in
|
starting to edit a new file, depending on whether file has an <EOL>
|
||||||
which case it is reset. Normally you don't have to set or reset this
|
for the last line in the file. Normally you don't have to set or
|
||||||
option. When 'binary' is off the value is not used when writing the
|
reset this option.
|
||||||
file. When 'binary' is on it is used to remember the presence of a
|
When 'binary' is off and 'fixeol' is on the value is not used when
|
||||||
<EOL> for the last line in the file, so that when you write the file
|
writing the file. When 'binary' is on or 'fixeol' is off it is used
|
||||||
the situation from the original file can be kept. But you can change
|
to remember the presence of a <EOL> for the last line in the file, so
|
||||||
it if you want to.
|
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'* *'noequalalways'* *'noea'*
|
||||||
'equalalways' 'ea' boolean (default on)
|
'equalalways' 'ea' boolean (default on)
|
||||||
@@ -2554,6 +2555,17 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
fold:c Folded |hl-Folded|
|
fold:c Folded |hl-Folded|
|
||||||
diff:c DiffDelete |hl-DiffDelete|
|
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'* *'nofkmap'* *'nofk'*
|
||||||
'fkmap' 'fk' boolean (default off) *E198*
|
'fkmap' 'fk' boolean (default off) *E198*
|
||||||
global
|
global
|
||||||
|
@@ -930,6 +930,9 @@ call <SID>BinOptionL("bin")
|
|||||||
call append("$", "endofline\tlast line in the file has an end-of-line")
|
call append("$", "endofline\tlast line in the file has an end-of-line")
|
||||||
call append("$", "\t(local to buffer)")
|
call append("$", "\t(local to buffer)")
|
||||||
call <SID>BinOptionL("eol")
|
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")
|
if has("multi_byte")
|
||||||
call append("$", "bomb\tprepend a Byte Order Mark to the file")
|
call append("$", "bomb\tprepend a Byte Order Mark to the file")
|
||||||
call append("$", "\t(local to buffer)")
|
call append("$", "\t(local to buffer)")
|
||||||
|
@@ -479,6 +479,7 @@ void buf_clear_file(buf_T *buf)
|
|||||||
buf->b_ml.ml_line_count = 1;
|
buf->b_ml.ml_line_count = 1;
|
||||||
unchanged(buf, TRUE);
|
unchanged(buf, TRUE);
|
||||||
buf->b_p_eol = TRUE;
|
buf->b_p_eol = TRUE;
|
||||||
|
buf->b_p_fixeol = true;
|
||||||
buf->b_start_eol = TRUE;
|
buf->b_start_eol = TRUE;
|
||||||
buf->b_p_bomb = FALSE;
|
buf->b_p_bomb = FALSE;
|
||||||
buf->b_start_bomb = FALSE;
|
buf->b_start_bomb = FALSE;
|
||||||
|
@@ -612,6 +612,7 @@ struct file_buffer {
|
|||||||
char_u *b_p_cfu; /* 'completefunc' */
|
char_u *b_p_cfu; /* 'completefunc' */
|
||||||
char_u *b_p_ofu; /* 'omnifunc' */
|
char_u *b_p_ofu; /* 'omnifunc' */
|
||||||
int b_p_eol; /* 'endofline' */
|
int b_p_eol; /* 'endofline' */
|
||||||
|
int b_p_fixeol; /* 'fixendofline' */
|
||||||
int b_p_et; /* 'expandtab' */
|
int b_p_et; /* 'expandtab' */
|
||||||
int b_p_et_nobin; /* b_p_et saved for binary mode */
|
int b_p_et_nobin; /* b_p_et saved for binary mode */
|
||||||
char_u *b_p_fenc; /* 'fileencoding' */
|
char_u *b_p_fenc; /* 'fileencoding' */
|
||||||
|
@@ -1934,10 +1934,10 @@ failed:
|
|||||||
check_marks_read();
|
check_marks_read();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Trick: We remember if the last line of the read didn't have
|
* 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
|
* an eol even when 'binary' is off, to support turning 'fixeol' off,
|
||||||
* 'binary' on. This is required for
|
* or writing the read again with 'binary' on. The latter is required
|
||||||
* ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
|
* for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
|
||||||
*/
|
*/
|
||||||
curbuf->b_no_eol_lnum = read_no_eol_lnum;
|
curbuf->b_no_eol_lnum = read_no_eol_lnum;
|
||||||
|
|
||||||
@@ -3322,7 +3322,7 @@ restore_backup:
|
|||||||
/* write failed or last line has no EOL: stop here */
|
/* write failed or last line has no EOL: stop here */
|
||||||
if (end == 0
|
if (end == 0
|
||||||
|| (lnum == end
|
|| (lnum == end
|
||||||
&& write_bin
|
&& (write_bin || !buf->b_p_fixeol)
|
||||||
&& (lnum == buf->b_no_eol_lnum
|
&& (lnum == buf->b_no_eol_lnum
|
||||||
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol)))) {
|
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol)))) {
|
||||||
++lnum; /* written the line, count it */
|
++lnum; /* written the line, count it */
|
||||||
|
@@ -3962,8 +3962,10 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
|
|||||||
if (ffdos)
|
if (ffdos)
|
||||||
size += lnum - 1;
|
size += lnum - 1;
|
||||||
|
|
||||||
/* Don't count the last line break if 'bin' and 'noeol'. */
|
/* Don't count the last line break if 'noeol' and ('bin' or
|
||||||
if (buf->b_p_bin && !buf->b_p_eol && buf->b_ml.ml_line_count == lnum) {
|
* 'nofixeol'). */
|
||||||
|
if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol
|
||||||
|
&& buf->b_ml.ml_line_count == lnum) {
|
||||||
size -= ffdos + 1;
|
size -= ffdos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ typedef struct memline {
|
|||||||
int ml_flags;
|
int ml_flags;
|
||||||
|
|
||||||
infoptr_T *ml_stack; /* stack of pointer blocks (array of IPTRs) */
|
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 */
|
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 */
|
linenr_T ml_line_lnum; /* line number of cached line, 0 if not valid */
|
||||||
|
@@ -4972,7 +4972,7 @@ void cursor_pos_info(void)
|
|||||||
&char_count_cursor, len, eol_size);
|
&char_count_cursor, len, eol_size);
|
||||||
if (lnum == curbuf->b_ml.ml_line_count
|
if (lnum == curbuf->b_ml.ml_line_count
|
||||||
&& !curbuf->b_p_eol
|
&& !curbuf->b_p_eol
|
||||||
&& curbuf->b_p_bin
|
&& (curbuf->b_p_bin || !curbuf->b_p_fixeol)
|
||||||
&& (long)STRLEN(s) < len)
|
&& (long)STRLEN(s) < len)
|
||||||
byte_count_cursor -= eol_size;
|
byte_count_cursor -= eol_size;
|
||||||
}
|
}
|
||||||
@@ -4993,7 +4993,7 @@ void cursor_pos_info(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Correction for when last line doesn't have an EOL. */
|
/* 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;
|
byte_count -= eol_size;
|
||||||
|
|
||||||
if (l_VIsual_active) {
|
if (l_VIsual_active) {
|
||||||
|
@@ -131,6 +131,7 @@ static char_u *p_cpt;
|
|||||||
static char_u *p_cfu;
|
static char_u *p_cfu;
|
||||||
static char_u *p_ofu;
|
static char_u *p_ofu;
|
||||||
static int p_eol;
|
static int p_eol;
|
||||||
|
static int p_fixeol;
|
||||||
static int p_et;
|
static int p_et;
|
||||||
static char_u *p_fenc;
|
static char_u *p_fenc;
|
||||||
static char_u *p_ff;
|
static char_u *p_ff;
|
||||||
@@ -3556,6 +3557,9 @@ set_bool_option (
|
|||||||
/* when 'endofline' is changed, redraw the window title */
|
/* when 'endofline' is changed, redraw the window title */
|
||||||
else if ((int *)varp == &curbuf->b_p_eol) {
|
else if ((int *)varp == &curbuf->b_p_eol) {
|
||||||
redraw_titles();
|
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 */
|
/* when 'bomb' is changed, redraw the window title and tab page text */
|
||||||
else if ((int *)varp == &curbuf->b_p_bomb) {
|
else if ((int *)varp == &curbuf->b_p_bomb) {
|
||||||
@@ -5230,6 +5234,7 @@ static char_u *get_varp(vimoption_T *p)
|
|||||||
case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
|
case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
|
||||||
case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
|
case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
|
||||||
case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
|
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_ET: return (char_u *)&(curbuf->b_p_et);
|
||||||
case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
|
case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
|
||||||
case PV_FF: return (char_u *)&(curbuf->b_p_ff);
|
case PV_FF: return (char_u *)&(curbuf->b_p_ff);
|
||||||
@@ -6409,6 +6414,7 @@ void save_file_ff(buf_T *buf)
|
|||||||
* from when editing started (save_file_ff() called).
|
* from when editing started (save_file_ff() called).
|
||||||
* Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
|
* Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
|
||||||
* changed and 'binary' is not set.
|
* 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
|
* When "ignore_empty" is true don't consider a new, empty buffer to be
|
||||||
* changed.
|
* changed.
|
||||||
*/
|
*/
|
||||||
@@ -6423,9 +6429,9 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty)
|
|||||||
&& *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
|
&& *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (buf->b_start_ffc != *buf->b_p_ff)
|
if (buf->b_start_ffc != *buf->b_p_ff)
|
||||||
return TRUE;
|
return true;
|
||||||
if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
|
if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
|
||||||
return TRUE;
|
return true;
|
||||||
if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
|
if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (buf->b_start_fenc == NULL)
|
if (buf->b_start_fenc == NULL)
|
||||||
|
@@ -665,6 +665,7 @@ enum {
|
|||||||
, BV_DEF
|
, BV_DEF
|
||||||
, BV_INC
|
, BV_INC
|
||||||
, BV_EOL
|
, BV_EOL
|
||||||
|
, BV_FIXEOL
|
||||||
, BV_EP
|
, BV_EP
|
||||||
, BV_ET
|
, BV_ET
|
||||||
, BV_FENC
|
, BV_FENC
|
||||||
|
@@ -807,6 +807,14 @@ return {
|
|||||||
varname='p_fcs',
|
varname='p_fcs',
|
||||||
defaults={if_true={vi="vert:|,fold:-"}}
|
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',
|
full_name='fkmap', abbreviation='fk',
|
||||||
type='bool', scope={'global'},
|
type='bool', scope={'global'},
|
||||||
|
@@ -418,7 +418,8 @@ static void read_input(DynamicBuffer *buf)
|
|||||||
// Finished a line, add a NL, unless this line should not have one.
|
// Finished a line, add a NL, unless this line should not have one.
|
||||||
// FIXME need to make this more readable
|
// FIXME need to make this more readable
|
||||||
if (lnum != curbuf->b_op_end.lnum
|
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_no_eol_lnum
|
||||||
&& (lnum !=
|
&& (lnum !=
|
||||||
curbuf->b_ml.ml_line_count
|
curbuf->b_ml.ml_line_count
|
||||||
|
@@ -29,6 +29,7 @@ SCRIPTS := test_eval.out \
|
|||||||
test_charsearch.out \
|
test_charsearch.out \
|
||||||
test_close_count.out \
|
test_close_count.out \
|
||||||
test_command_count.out \
|
test_command_count.out \
|
||||||
|
test_fixeol.out \
|
||||||
|
|
||||||
SCRIPTS_GUI := test16.out
|
SCRIPTS_GUI := test16.out
|
||||||
|
|
||||||
|
40
src/nvim/testdir/test_fixeol.in
Normal file
40
src/nvim/testdir/test_fixeol.in
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
Tests for 'fixeol' vim: set ft=vim :
|
||||||
|
|
||||||
|
STARTTEST
|
||||||
|
:" first write two test files – with and without trailing EOL
|
||||||
|
:" use Unix fileformat for consistency
|
||||||
|
:set ff=unix
|
||||||
|
:enew!
|
||||||
|
awith eol:w! XXEol
|
||||||
|
:enew!
|
||||||
|
:set noeol nofixeol
|
||||||
|
awithout eol:w! XXNoEol
|
||||||
|
:set eol fixeol
|
||||||
|
:bwipe XXEol XXNoEol
|
||||||
|
:"
|
||||||
|
:" try editing files with 'fixeol' disabled
|
||||||
|
:e! XXEol
|
||||||
|
ostays eol:set nofixeol
|
||||||
|
:w! XXTestEol
|
||||||
|
:e! XXNoEol
|
||||||
|
ostays without:set nofixeol
|
||||||
|
:w! XXTestNoEol
|
||||||
|
:bwipe XXEol XXNoEol XXTestEol XXTestNoEol
|
||||||
|
:set fixeol
|
||||||
|
:"
|
||||||
|
:" Append "END" to each file so that we can see what the last written char was.
|
||||||
|
ggdGaEND:w >>XXEol
|
||||||
|
:w >>XXNoEol
|
||||||
|
:w >>XXTestEol
|
||||||
|
:w >>XXTestNoEol
|
||||||
|
:"
|
||||||
|
:" Concatenate the results
|
||||||
|
:e! test.out
|
||||||
|
a0:$r XXEol
|
||||||
|
:$r XXNoEol
|
||||||
|
Go1:$r XXTestEol
|
||||||
|
:$r XXTestNoEol
|
||||||
|
:w
|
||||||
|
:qa!
|
||||||
|
ENDTEST
|
||||||
|
|
10
src/nvim/testdir/test_fixeol.ok
Normal file
10
src/nvim/testdir/test_fixeol.ok
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
0
|
||||||
|
with eol
|
||||||
|
END
|
||||||
|
without eolEND
|
||||||
|
1
|
||||||
|
with eol
|
||||||
|
stays eol
|
||||||
|
END
|
||||||
|
without eol
|
||||||
|
stays withoutEND
|
@@ -211,7 +211,7 @@ static int included_patches[] = {
|
|||||||
// 788 NA
|
// 788 NA
|
||||||
// 787,
|
// 787,
|
||||||
// 786,
|
// 786,
|
||||||
// 785,
|
785,
|
||||||
784,
|
784,
|
||||||
// 783 NA
|
// 783 NA
|
||||||
// 782,
|
// 782,
|
||||||
|
Reference in New Issue
Block a user