1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
To: vim_dev@googlegroups.com
Subject: Patch 7.3.124
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 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.
Files: src/structs.h, src/fileio.c, src/globals.h, src/os_unix.c
*** ../vim-7.3.123/src/structs.h 2010-10-20 21:22:17.000000000 +0200
--- src/structs.h 2011-02-15 17:06:34.000000000 +0100
***************
*** 1564,1569 ****
--- 1564,1572 ----
/* end of buffer options */
+ linenr_T b_no_eol_lnum; /* non-zero lnum when last line of next binary
+ * write should not have an end-of-line */
+
int b_start_eol; /* last line had eol when it was read */
int b_start_ffc; /* first char of 'ff' when edit started */
#ifdef FEAT_MBYTE
*** ../vim-7.3.123/src/fileio.c 2011-02-09 16:44:45.000000000 +0100
--- src/fileio.c 2011-02-15 17:30:54.000000000 +0100
***************
*** 317,323 ****
int using_b_fname;
#endif
! write_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.
--- 317,323 ----
int using_b_fname;
#endif
! 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,2608 ****
/*
* Trick: We remember if the last line of the read didn't have
! * an eol for when writing it again. This is required for
* ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
*/
! write_no_eol_lnum = read_no_eol_lnum;
/* When reloading a buffer put the cursor at the first line that is
* different. */
--- 2599,2609 ----
/*
* 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.
*/
! curbuf->b_no_eol_lnum = read_no_eol_lnum;
/* When reloading a buffer put the cursor at the first line that is
* different. */
***************
*** 2650,2662 ****
FALSE, NULL, eap);
if (msg_scrolled == n)
msg_scroll = m;
! #ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return FAIL;
! #endif
}
#endif
if (recoverymode && error)
return FAIL;
return OK;
--- 2651,2667 ----
FALSE, NULL, eap);
if (msg_scrolled == n)
msg_scroll = m;
! # ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return FAIL;
! # 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,4566 ****
if (end == 0
|| (lnum == end
&& write_bin
! && (lnum == write_no_eol_lnum
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
{
++lnum; /* written the line, count it */
--- 4565,4571 ----
if (end == 0
|| (lnum == end
&& write_bin
! && (lnum == buf->b_no_eol_lnum
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
{
++lnum; /* written the line, count it */
***************
*** 5086,5093 ****
{
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!
--- 5091,5096 ----
***************
*** 7256,7263 ****
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 defined(TEMPDIRNAMES) || defined(PROTO)
--- 7259,7266 ----
write_lnum_adjust(offset)
linenr_T 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)
*** ../vim-7.3.123/src/globals.h 2010-12-02 21:43:10.000000000 +0100
--- src/globals.h 2011-02-15 17:06:06.000000000 +0100
***************
*** 1057,1066 ****
;
#endif
- EXTERN linenr_T write_no_eol_lnum INIT(= 0); /* non-zero lnum when last line
- of next binary write should
- not have an end-of-line */
-
#ifdef FEAT_WINDOWS
EXTERN int postponed_split INIT(= 0); /* for CTRL-W CTRL-] command */
EXTERN int postponed_split_flags INIT(= 0); /* args for win_split() */
--- 1057,1062 ----
*** ../vim-7.3.123/src/os_unix.c 2011-02-09 18:47:36.000000000 +0100
--- src/os_unix.c 2011-02-15 17:07:22.000000000 +0100
***************
*** 4245,4251 ****
* should not have one. */
if (lnum != curbuf->b_op_end.lnum
|| !curbuf->b_p_bin
! || (lnum != write_no_eol_lnum
&& (lnum !=
curbuf->b_ml.ml_line_count
|| curbuf->b_p_eol)))
--- 4245,4251 ----
* should not have one. */
if (lnum != curbuf->b_op_end.lnum
|| !curbuf->b_p_bin
! || (lnum != curbuf->b_no_eol_lnum
&& (lnum !=
curbuf->b_ml.ml_line_count
|| curbuf->b_p_eol)))
***************
*** 4588,4597 ****
{
append_ga_line(&ga);
/* remember that the NL was missing */
! write_no_eol_lnum = curwin->w_cursor.lnum;
}
else
! write_no_eol_lnum = 0;
ga_clear(&ga);
}
--- 4588,4597 ----
{
append_ga_line(&ga);
/* remember that the NL was missing */
! curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
}
else
! curbuf->b_no_eol_lnum = 0;
ga_clear(&ga);
}
*** ../vim-7.3.123/src/version.c 2011-02-15 16:29:54.000000000 +0100
--- src/version.c 2011-02-15 17:37:38.000000000 +0100
***************
*** 716,717 ****
--- 716,719 ----
{ /* Add new patch number below this line */
+ /**/
+ 124,
/**/
--
hundred-and-one symptoms of being an internet addict:
270. You are subscribed to a mailing list for every piece of software
you use.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|