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.7 1994/01/11 22:18:46 bostic Exp $ (Berkeley) $Date: 1994/01/11 22:18:46 $";
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
);
48 F_ISSET(vp
, VC_BUFFER
) ? &vp
->buffer
: NULL
, fm
, tm
, CUT_DELETE
))
50 if (delete(sp
, ep
, fm
, tm
, 0))
54 rp
->cno
= fm
->cno
? fm
->cno
- 1 : 0;
59 * v_delete -- [buffer][count]d[count]motion
60 * Delete a range of text.
63 v_delete(sp
, ep
, vp
, fm
, tm
, rp
)
74 lmode
= F_ISSET(vp
, VC_LMODE
) ? CUT_LINEMODE
: 0;
76 F_ISSET(vp
, VC_BUFFER
) ? &vp
->buffer
: NULL
,
77 fm
, tm
, lmode
| CUT_DELETE
))
79 if (delete(sp
, ep
, fm
, tm
, lmode
))
82 /* Check for deleting the file. */
83 if (file_lline(sp
, ep
, &nlines
))
92 * If deleting lines, leave the cursor at the lowest line deleted,
93 * else, leave the cursor where it started. Always correct for EOL.
95 * The historic vi would delete the line the cursor was on (even if
96 * not in line mode) if the motion from the cursor was past the EOF
97 * and the cursor didn't originate on the last line of the file. A
98 * strange special case. We never delete the line the cursor is on.
99 * We'd have to pass a flag down to the delete() routine which would
100 * have to special case it.
103 rp
->lno
= MIN(fm
->lno
, tm
->lno
);
104 if (rp
->lno
> nlines
)
107 (void)nonblank(sp
, ep
, rp
->lno
, &rp
->cno
);
112 if (file_gline(sp
, ep
, rp
->lno
, &len
) == NULL
) {
113 GETLINE_ERR(sp
, rp
->lno
);
117 rp
->cno
= len
? len
- 1 : 0;