]>
Commit | Line | Data |
---|---|---|
d57b4abe ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.1.207 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.207 | |
11 | Problem: Netbeans: "remove" cannot delete one line. | |
12 | Solution: Remove partial lines and whole lines properly. Avoid a memory | |
13 | leak. (Xavier de Gaye) | |
14 | Files: src/netbeans.c | |
15 | ||
16 | ||
17 | *** ../vim-7.1.206/src/netbeans.c Thu May 10 18:40:48 2007 | |
18 | --- src/netbeans.c Sat Jan 5 18:03:24 2008 | |
19 | *************** | |
20 | *** 1204,1209 **** | |
21 | --- 1204,1257 ---- | |
22 | return result; | |
23 | } | |
24 | ||
25 | + /* | |
26 | + * Remove from "first" byte to "last" byte (inclusive), at line "lnum" of the | |
27 | + * current buffer. Remove to end of line when "last" is MAXCOL. | |
28 | + */ | |
29 | + static void | |
30 | + nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last) | |
31 | + { | |
32 | + char_u *oldtext, *newtext; | |
33 | + int oldlen; | |
34 | + int lastbyte = last; | |
35 | + | |
36 | + oldtext = ml_get(lnum); | |
37 | + oldlen = STRLEN(oldtext); | |
38 | + if (first >= oldlen || oldlen == 0) /* just in case */ | |
39 | + return; | |
40 | + if (lastbyte >= oldlen) | |
41 | + lastbyte = oldlen - 1; | |
42 | + newtext = alloc(oldlen - (int)(lastbyte - first)); | |
43 | + if (newtext != NULL) | |
44 | + { | |
45 | + mch_memmove(newtext, oldtext, first); | |
46 | + mch_memmove(newtext + first, oldtext + lastbyte + 1, STRLEN(oldtext + lastbyte + 1) + 1); | |
47 | + nbdebug((" NEW LINE %d: %s\n", lnum, newtext)); | |
48 | + ml_replace(lnum, newtext, FALSE); | |
49 | + } | |
50 | + } | |
51 | + | |
52 | + /* | |
53 | + * Replace the "first" line with the concatenation of the "first" and | |
54 | + * the "other" line. The "other" line is not removed. | |
55 | + */ | |
56 | + static void | |
57 | + nb_joinlines(linenr_T first, linenr_T other) | |
58 | + { | |
59 | + int len_first, len_other; | |
60 | + char_u *p; | |
61 | + | |
62 | + len_first = STRLEN(ml_get(first)); | |
63 | + len_other = STRLEN(ml_get(other)); | |
64 | + p = alloc((unsigned)(len_first + len_other + 1)); | |
65 | + if (p != NULL) | |
66 | + { | |
67 | + mch_memmove(p, ml_get(first), len_first); | |
68 | + mch_memmove(p + len_first, ml_get(other), len_other + 1); | |
69 | + ml_replace(first, p, FALSE); | |
70 | + } | |
71 | + } | |
72 | + | |
73 | #define SKIP_STOP 2 | |
74 | #define streq(a,b) (strcmp(a,b) == 0) | |
75 | static int needupdate = 0; | |
76 | *************** | |
77 | *** 1371,1376 **** | |
78 | --- 1419,1426 ---- | |
79 | long count; | |
80 | pos_T first, last; | |
81 | pos_T *pos; | |
82 | + pos_T *next; | |
83 | + linenr_T del_from_lnum, del_to_lnum; /* lines to be deleted as a whole */ | |
84 | int oldFire = netbeansFireChanges; | |
85 | int oldSuppress = netbeansSuppressNoLines; | |
86 | int wasChanged; | |
87 | *************** | |
88 | *** 1420,1444 **** | |
89 | } | |
90 | last = *pos; | |
91 | nbdebug((" LAST POS: line %d, col %d\n", last.lnum, last.col)); | |
92 | ! curwin->w_cursor = first; | |
93 | doupdate = 1; | |
94 | ||
95 | ! /* keep part of first line */ | |
96 | ! if (first.lnum == last.lnum && first.col != last.col) | |
97 | { | |
98 | ! /* deletion is within one line */ | |
99 | ! char_u *p = ml_get(first.lnum); | |
100 | ! mch_memmove(p + first.col, p + last.col + 1, STRLEN(p + last.col) + 1); | |
101 | ! nbdebug((" NEW LINE %d: %s\n", first.lnum, p)); | |
102 | ! ml_replace(first.lnum, p, TRUE); | |
103 | } | |
104 | ||
105 | ! if (first.lnum < last.lnum) | |
106 | { | |
107 | int i; | |
108 | ||
109 | /* delete signs from the lines being deleted */ | |
110 | ! for (i = first.lnum; i <= last.lnum; i++) | |
111 | { | |
112 | int id = buf_findsign_id(buf->bufp, (linenr_T)i); | |
113 | if (id > 0) | |
114 | --- 1470,1544 ---- | |
115 | } | |
116 | last = *pos; | |
117 | nbdebug((" LAST POS: line %d, col %d\n", last.lnum, last.col)); | |
118 | ! del_from_lnum = first.lnum; | |
119 | ! del_to_lnum = last.lnum; | |
120 | doupdate = 1; | |
121 | ||
122 | ! /* Get the position of the first byte after the deleted | |
123 | ! * section. "next" is NULL when deleting to the end of the | |
124 | ! * file. */ | |
125 | ! next = off2pos(buf->bufp, off + count); | |
126 | ! | |
127 | ! /* Remove part of the first line. */ | |
128 | ! if (first.col != 0 || (next != NULL && first.lnum == next->lnum)) | |
129 | { | |
130 | ! if (first.lnum != last.lnum | |
131 | ! || (next != NULL && first.lnum != next->lnum)) | |
132 | ! { | |
133 | ! /* remove to the end of the first line */ | |
134 | ! nb_partialremove(first.lnum, first.col, | |
135 | ! (colnr_T)MAXCOL); | |
136 | ! if (first.lnum == last.lnum) | |
137 | ! { | |
138 | ! /* Partial line to remove includes the end of | |
139 | ! * line. Join the line with the next one, have | |
140 | ! * the next line deleted below. */ | |
141 | ! nb_joinlines(first.lnum, next->lnum); | |
142 | ! del_to_lnum = next->lnum; | |
143 | ! } | |
144 | ! } | |
145 | ! else | |
146 | ! { | |
147 | ! /* remove within one line */ | |
148 | ! nb_partialremove(first.lnum, first.col, last.col); | |
149 | ! } | |
150 | ! ++del_from_lnum; /* don't delete the first line */ | |
151 | ! } | |
152 | ! | |
153 | ! /* Remove part of the last line. */ | |
154 | ! if (first.lnum != last.lnum && next != NULL | |
155 | ! && next->col != 0 && last.lnum == next->lnum) | |
156 | ! { | |
157 | ! nb_partialremove(last.lnum, 0, last.col); | |
158 | ! if (del_from_lnum > first.lnum) | |
159 | ! { | |
160 | ! /* Join end of last line to start of first line; last | |
161 | ! * line is deleted below. */ | |
162 | ! nb_joinlines(first.lnum, last.lnum); | |
163 | ! } | |
164 | ! else | |
165 | ! /* First line is deleted as a whole, keep the last | |
166 | ! * line. */ | |
167 | ! --del_to_lnum; | |
168 | } | |
169 | ||
170 | ! /* First is partial line; last line to remove includes | |
171 | ! * the end of line; join first line to line following last | |
172 | ! * line; line following last line is deleted below. */ | |
173 | ! if (first.lnum != last.lnum && del_from_lnum > first.lnum | |
174 | ! && next != NULL && last.lnum != next->lnum) | |
175 | ! { | |
176 | ! nb_joinlines(first.lnum, next->lnum); | |
177 | ! del_to_lnum = next->lnum; | |
178 | ! } | |
179 | ! | |
180 | ! /* Delete whole lines if there are any. */ | |
181 | ! if (del_to_lnum >= del_from_lnum) | |
182 | { | |
183 | int i; | |
184 | ||
185 | /* delete signs from the lines being deleted */ | |
186 | ! for (i = del_from_lnum; i <= del_to_lnum; i++) | |
187 | { | |
188 | int id = buf_findsign_id(buf->bufp, (linenr_T)i); | |
189 | if (id > 0) | |
190 | *************** | |
191 | *** 1450,1459 **** | |
192 | nbdebug((" No sign on line %d\n", i)); | |
193 | } | |
194 | ||
195 | ! /* delete whole lines */ | |
196 | ! nbdebug((" Deleting lines %d through %d\n", first.lnum, last.lnum)); | |
197 | ! del_lines(last.lnum - first.lnum + 1, FALSE); | |
198 | } | |
199 | buf->bufp->b_changed = wasChanged; /* logically unchanged */ | |
200 | netbeansFireChanges = oldFire; | |
201 | netbeansSuppressNoLines = oldSuppress; | |
202 | --- 1550,1564 ---- | |
203 | nbdebug((" No sign on line %d\n", i)); | |
204 | } | |
205 | ||
206 | ! nbdebug((" Deleting lines %d through %d\n", del_from_lnum, del_to_lnum)); | |
207 | ! curwin->w_cursor.lnum = del_from_lnum; | |
208 | ! curwin->w_cursor.col = 0; | |
209 | ! del_lines(del_to_lnum - del_from_lnum + 1, FALSE); | |
210 | } | |
211 | + | |
212 | + /* Leave cursor at first deleted byte. */ | |
213 | + curwin->w_cursor = first; | |
214 | + check_cursor_lnum(); | |
215 | buf->bufp->b_changed = wasChanged; /* logically unchanged */ | |
216 | netbeansFireChanges = oldFire; | |
217 | netbeansSuppressNoLines = oldSuppress; | |
218 | *************** | |
219 | *** 2374,2381 **** | |
220 | * the current buffer as "buf". | |
221 | */ | |
222 | static void | |
223 | ! nb_set_curbuf(buf) | |
224 | ! buf_T *buf; | |
225 | { | |
226 | if (curbuf != buf && buf_jump_open_win(buf) == NULL) | |
227 | set_curbuf(buf, DOBUF_GOTO); | |
228 | --- 2479,2485 ---- | |
229 | * the current buffer as "buf". | |
230 | */ | |
231 | static void | |
232 | ! nb_set_curbuf(buf_T *buf) | |
233 | { | |
234 | if (curbuf != buf && buf_jump_open_win(buf) == NULL) | |
235 | set_curbuf(buf, DOBUF_GOTO); | |
236 | *** ../vim-7.1.206/src/version.c Sat Jan 5 13:58:48 2008 | |
237 | --- src/version.c Sat Jan 5 18:06:04 2008 | |
238 | *************** | |
239 | *** 668,669 **** | |
240 | --- 668,671 ---- | |
241 | { /* Add new patch number below this line */ | |
242 | + /**/ | |
243 | + 207, | |
244 | /**/ | |
245 | ||
246 | -- | |
247 | Q: How many hardware engineers does it take to change a lightbulb? | |
248 | A: None. We'll fix it in software. | |
249 | ||
250 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
251 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
252 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
253 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |