Skip to content

Commit 09d2597

Browse files
committed
Updated delete-blanks to allow deleting all blank lines in the file.
1 parent 8bb7015 commit 09d2597

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

cnames.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ struct cnames Cnames[] = {
9696
{"ctrl-x", ZCTRL_X, 0,
9797
C("Command prefix.")
9898
},
99-
{"delete-blanks", ZDELETE_BLANKS, AN,
100-
C("Delete all the blank lines around the Point. The lines are not "
101-
"put in the Kill Buffer.")
99+
{"delete-blanks", ZDELETE_BLANKS, 0,
100+
C("Delete all the blank lines around the Point. With a Universal Argument "
101+
"all blanks lines in the file are deleted. The lines are NOT put in the "
102+
"Kill Buffer.")
102103
},
103104
{"delete-buffer", ZDELETE_BUFFER, 0,
104105
C("Deletes the current buffer and goes to a previous buffer. There "

delete.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,51 @@ void Zdelete_blanks(void)
202202
{
203203
struct mark *pmark = bcremark(Bbuff);
204204
struct mark *tmark = bcremark(Bbuff);
205-
if (pmark && tmark) {
206-
if (bcrsearch(Bbuff, NL)) {
207-
bmove1(Bbuff);
208-
bmrktopnt(Bbuff, tmark);
209-
movepast(isspace, BACKWARD);
210-
if (!bisstart(Bbuff))
211-
bcsearch(Bbuff, NL);
212-
if (bisbeforemrk(Bbuff, tmark))
213-
bdeltomrk(tmark);
205+
if (!pmark || !tmark) {
206+
tbell();
207+
goto done;
208+
}
209+
210+
if (Argp) {
211+
regexp_t re;
212+
Arg = 0;
213+
214+
if (re_compile(&re, "^[ \t]*\r?$", REG_EXTENDED)) {
215+
error("Internal re error.");
216+
goto done;
214217
}
215-
if (bcsearch(Bbuff, NL)) {
216-
bmrktopnt(Bbuff, tmark);
217-
movepast(isspace, FORWARD);
218-
if (bcrsearch(Bbuff, NL))
219-
bmove1(Bbuff);
220-
if (bisaftermrk(Bbuff, tmark))
221-
bdeltomrk(tmark);
218+
219+
btostart(Bbuff);
220+
while (re_step(Bbuff, &re, tmark)) {
221+
bmove1(Bbuff); /* skip over the NL */
222+
bdeltomrk(tmark);
222223
}
223-
} else
224-
tbell();
225-
bpnttomrk(Bbuff, pmark);
224+
225+
re_free(&re);
226+
goto done;
227+
}
228+
229+
if (bcrsearch(Bbuff, NL)) {
230+
bmove1(Bbuff);
231+
bmrktopnt(Bbuff, tmark);
232+
movepast(isspace, BACKWARD);
233+
if (!bisstart(Bbuff))
234+
bcsearch(Bbuff, NL);
235+
if (bisbeforemrk(Bbuff, tmark))
236+
bdeltomrk(tmark);
237+
}
238+
if (bcsearch(Bbuff, NL)) {
239+
bmrktopnt(Bbuff, tmark);
240+
movepast(isspace, FORWARD);
241+
if (bcrsearch(Bbuff, NL))
242+
bmove1(Bbuff);
243+
if (bisaftermrk(Bbuff, tmark))
244+
bdeltomrk(tmark);
245+
}
246+
247+
done:
248+
if (pmark)
249+
bpnttomrk(Bbuff, pmark);
226250
unmark(pmark);
227251
unmark(tmark);
228252
}

0 commit comments

Comments
 (0)