updated for version 7.3.124
Problem: When writing a file in binary mode it may be missing the final EOL
if a file previously read was missing the EOL. (Kevin Goodsell)
Solution: Move the write_no_eol_lnum into the buffer struct.
diff --git a/src/fileio.c b/src/fileio.c
index 0d4511a..a87b70b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -317,7 +317,7 @@
int using_b_fname;
#endif
- write_no_eol_lnum = 0; /* in case it was set by the previous read */
+ curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */
/*
* If there is no file name yet, use the one for the read file.
@@ -2599,10 +2599,11 @@
/*
* Trick: We remember if the last line of the read didn't have
- * an eol for when writing it again. This is required for
+ * 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.
*/
- write_no_eol_lnum = read_no_eol_lnum;
+ curbuf->b_no_eol_lnum = read_no_eol_lnum;
/* When reloading a buffer put the cursor at the first line that is
* different. */
@@ -2650,13 +2651,17 @@
FALSE, NULL, eap);
if (msg_scrolled == n)
msg_scroll = m;
-#ifdef FEAT_EVAL
+# ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return FAIL;
-#endif
+# endif
}
#endif
+ /* Reset now, following writes should not omit the EOL. Also, the line
+ * number will become invalid because of edits. */
+ curbuf->b_no_eol_lnum = 0;
+
if (recoverymode && error)
return FAIL;
return OK;
@@ -4560,7 +4565,7 @@
if (end == 0
|| (lnum == end
&& write_bin
- && (lnum == write_no_eol_lnum
+ && (lnum == buf->b_no_eol_lnum
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
{
++lnum; /* written the line, count it */
@@ -5086,8 +5091,6 @@
{
aco_save_T aco;
- write_no_eol_lnum = 0; /* in case it was set by the previous read */
-
/*
* Apply POST autocommands.
* Careful: The autocommands may call buf_write() recursively!
@@ -7256,8 +7259,8 @@
write_lnum_adjust(offset)
linenr_T offset;
{
- if (write_no_eol_lnum != 0) /* only if there is a missing eol */
- write_no_eol_lnum += offset;
+ if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */
+ curbuf->b_no_eol_lnum += offset;
}
#if defined(TEMPDIRNAMES) || defined(PROTO)