2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: v_delete.c,v 8.5 1993/11/04 16:17:23 bostic Exp $ (Berkeley) $Date: 1993/11/04 16:17:23 $";
12 #include <sys/types.h>
18 * v_Delete -- [buffer][count]D
19 * Delete line command.
22 v_Delete(sp
, ep
, vp
, fm
, tm
, rp
)
31 if (file_gline(sp
, ep
, fm
->lno
, &len
) == NULL
) {
32 if (file_lline(sp
, ep
, &lno
))
36 GETLINE_ERR(sp
, fm
->lno
);
47 F_ISSET(vp
, VC_BUFFER
) ? vp
->buffer
: DEFCB
, fm
, tm
, 0))
49 if (delete(sp
, ep
, fm
, tm
, 0))
53 rp
->cno
= fm
->cno
? fm
->cno
- 1 : 0;
58 * v_delete -- [buffer][count]d[count]motion
59 * Delete a range of text.
62 v_delete(sp
, ep
, vp
, fm
, tm
, rp
)
72 lmode
= F_ISSET(vp
, VC_LMODE
);
74 F_ISSET(vp
, VC_BUFFER
) ? vp
->buffer
: DEFCB
, fm
, tm
, lmode
))
76 if (delete(sp
, ep
, fm
, tm
, lmode
))
79 /* Check for deleting the file. */
80 if (file_lline(sp
, ep
, &nlines
))
89 * If deleting lines, leave the cursor at the lowest line deleted,
90 * else, leave the cursor where it started. Always correct for EOL.
92 * The historic vi would delete the line the cursor was on (even if
93 * not in line mode) if the motion from the cursor was past the EOF
94 * and the cursor didn't originate on the last line of the file. A
95 * strange special case. We never delete the line the cursor is on.
96 * We'd have to pass a flag down to the delete() routine which would
97 * have to special case it.
100 rp
->lno
= MIN(fm
->lno
, tm
->lno
);
101 if (rp
->lno
> nlines
)
104 (void)nonblank(sp
, ep
, rp
->lno
, &rp
->cno
);
109 if (file_gline(sp
, ep
, rp
->lno
, &len
) == NULL
) {
110 GETLINE_ERR(sp
, rp
->lno
);
114 rp
->cno
= len
? len
- 1 : 0;