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.6 1994/01/09 14:21:11 bostic Exp $ (Berkeley) $Date: 1994/01/09 14:21:11 $";
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
);
46 /* The default buffer for deletes is '1'. */
47 if (!F_ISSET(vp
, VC_BUFFER
))
49 if (cut(sp
, ep
, NULL
, &vp
->buffer
, fm
, tm
, CUT_ROTATE
))
51 if (delete(sp
, ep
, fm
, tm
, 0))
55 rp
->cno
= fm
->cno
? fm
->cno
- 1 : 0;
60 * v_delete -- [buffer][count]d[count]motion
61 * Delete a range of text.
64 v_delete(sp
, ep
, vp
, fm
, tm
, rp
)
74 /* The default buffer for deletes is '1'. */
75 if (!F_ISSET(vp
, VC_BUFFER
))
78 lmode
= F_ISSET(vp
, VC_LMODE
) ? CUT_LINEMODE
: 0;
79 if (cut(sp
, ep
, NULL
, &vp
->buffer
, fm
, tm
, lmode
| CUT_ROTATE
))
81 if (delete(sp
, ep
, fm
, tm
, lmode
))
84 /* Check for deleting the file. */
85 if (file_lline(sp
, ep
, &nlines
))
94 * If deleting lines, leave the cursor at the lowest line deleted,
95 * else, leave the cursor where it started. Always correct for EOL.
97 * The historic vi would delete the line the cursor was on (even if
98 * not in line mode) if the motion from the cursor was past the EOF
99 * and the cursor didn't originate on the last line of the file. A
100 * strange special case. We never delete the line the cursor is on.
101 * We'd have to pass a flag down to the delete() routine which would
102 * have to special case it.
105 rp
->lno
= MIN(fm
->lno
, tm
->lno
);
106 if (rp
->lno
> nlines
)
109 (void)nonblank(sp
, ep
, rp
->lno
, &rp
->cno
);
114 if (file_gline(sp
, ep
, rp
->lno
, &len
) == NULL
) {
115 GETLINE_ERR(sp
, rp
->lno
);
119 rp
->cno
= len
? len
- 1 : 0;