1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When writing a file in binary mode it may be missing the final EOL
12 if a file previously read was missing the EOL. (Kevin Goodsell)
13 Solution: Move the write_no_eol_lnum into the buffer struct.
14 Files: src/structs.h, src/fileio.c, src/globals.h, src/os_unix.c
17 *** ../vim-7.3.123/src/structs.h 2010-10-20 21:22:17.000000000 +0200
18 --- src/structs.h 2011-02-15 17:06:34.000000000 +0100
23 /* end of buffer options */
25 + linenr_T b_no_eol_lnum; /* non-zero lnum when last line of next binary
26 + * write should not have an end-of-line */
28 int b_start_eol; /* last line had eol when it was read */
29 int b_start_ffc; /* first char of 'ff' when edit started */
31 *** ../vim-7.3.123/src/fileio.c 2011-02-09 16:44:45.000000000 +0100
32 --- src/fileio.c 2011-02-15 17:30:54.000000000 +0100
38 ! write_no_eol_lnum = 0; /* in case it was set by the previous read */
41 * If there is no file name yet, use the one for the read file.
46 ! curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */
49 * If there is no file name yet, use the one for the read file.
54 * Trick: We remember if the last line of the read didn't have
55 ! * an eol for when writing it again. This is required for
56 * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
58 ! write_no_eol_lnum = read_no_eol_lnum;
60 /* When reloading a buffer put the cursor at the first line that is
65 * Trick: We remember if the last line of the read didn't have
66 ! * an eol even when 'binary' is off, for when writing it again with
67 ! * 'binary' on. This is required for
68 * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
70 ! curbuf->b_no_eol_lnum = read_no_eol_lnum;
72 /* When reloading a buffer put the cursor at the first line that is
77 if (msg_scrolled == n)
80 if (aborting()) /* autocmds may abort script processing */
86 if (recoverymode && error)
91 if (msg_scrolled == n)
94 if (aborting()) /* autocmds may abort script processing */
100 + /* Reset now, following writes should not omit the EOL. Also, the line
101 + * number will become invalid because of edits. */
102 + curbuf->b_no_eol_lnum = 0;
104 if (recoverymode && error)
112 ! && (lnum == write_no_eol_lnum
113 || (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
115 ++lnum; /* written the line, count it */
120 ! && (lnum == buf->b_no_eol_lnum
121 || (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
123 ++lnum; /* written the line, count it */
129 - write_no_eol_lnum = 0; /* in case it was set by the previous read */
132 * Apply POST autocommands.
133 * Careful: The autocommands may call buf_write() recursively!
137 write_lnum_adjust(offset)
140 ! if (write_no_eol_lnum != 0) /* only if there is a missing eol */
141 ! write_no_eol_lnum += offset;
144 #if defined(TEMPDIRNAMES) || defined(PROTO)
146 write_lnum_adjust(offset)
149 ! if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */
150 ! curbuf->b_no_eol_lnum += offset;
153 #if defined(TEMPDIRNAMES) || defined(PROTO)
154 *** ../vim-7.3.123/src/globals.h 2010-12-02 21:43:10.000000000 +0100
155 --- src/globals.h 2011-02-15 17:06:06.000000000 +0100
161 - EXTERN linenr_T write_no_eol_lnum INIT(= 0); /* non-zero lnum when last line
162 - of next binary write should
163 - not have an end-of-line */
166 EXTERN int postponed_split INIT(= 0); /* for CTRL-W CTRL-] command */
167 EXTERN int postponed_split_flags INIT(= 0); /* args for win_split() */
169 *** ../vim-7.3.123/src/os_unix.c 2011-02-09 18:47:36.000000000 +0100
170 --- src/os_unix.c 2011-02-15 17:07:22.000000000 +0100
173 * should not have one. */
174 if (lnum != curbuf->b_op_end.lnum
176 ! || (lnum != write_no_eol_lnum
178 curbuf->b_ml.ml_line_count
179 || curbuf->b_p_eol)))
181 * should not have one. */
182 if (lnum != curbuf->b_op_end.lnum
184 ! || (lnum != curbuf->b_no_eol_lnum
186 curbuf->b_ml.ml_line_count
187 || curbuf->b_p_eol)))
192 /* remember that the NL was missing */
193 ! write_no_eol_lnum = curwin->w_cursor.lnum;
196 ! write_no_eol_lnum = 0;
203 /* remember that the NL was missing */
204 ! curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
207 ! curbuf->b_no_eol_lnum = 0;
211 *** ../vim-7.3.123/src/version.c 2011-02-15 16:29:54.000000000 +0100
212 --- src/version.c 2011-02-15 17:37:38.000000000 +0100
216 { /* Add new patch number below this line */
222 hundred-and-one symptoms of being an internet addict:
223 270. You are subscribed to a mailing list for every piece of software
226 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
227 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
228 \\\ an exciting new programming language -- http://www.Zimbu.org ///
229 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///