rework cut buffers to match historic practice
[nvi.git] / vi / v_yank.c
blobb555d0da7d549d978c23fb48205f41777df86b84
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: v_yank.c,v 8.11 1994/01/09 14:21:17 bostic Exp $ (Berkeley) $Date: 1994/01/09 14:21:17 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
18 * v_Yank -- [buffer][count]Y
19 * Yank lines of text into a cut buffer.
21 int
22 v_Yank(sp, ep, vp, fm, tm, rp)
23 SCR *sp;
24 EXF *ep;
25 VICMDARG *vp;
26 MARK *fm, *tm, *rp;
28 if (file_gline(sp, ep, tm->lno, NULL) == NULL) {
29 v_eof(sp, ep, fm);
30 return (1);
32 if (cut(sp, ep, NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
33 fm, tm, CUT_LINEMODE))
34 return (1);
36 sp->rptlines[L_YANKED] += (tm->lno - fm->lno) + 1;
37 return (0);
41 * v_yank -- [buffer][count]y[count][motion]
42 * Yank text (or lines of text) into a cut buffer.
44 int
45 v_yank(sp, ep, vp, fm, tm, rp)
46 SCR *sp;
47 EXF *ep;
48 VICMDARG *vp;
49 MARK *fm, *tm, *rp;
51 if (F_ISSET(vp, VC_LMODE)) {
52 if (file_gline(sp, ep, tm->lno, NULL) == NULL) {
53 v_eof(sp, ep, fm);
54 return (1);
56 if (cut(sp, ep,
57 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
58 fm, tm, CUT_LINEMODE))
59 return (1);
60 } else if (cut(sp, ep,
61 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, tm, 0))
62 return (1);
65 * !!!
66 * Historic vi moved the cursor to the from MARK if it was before the
67 * current cursor. This makes no sense. For example, "yj" moves the
68 * cursor but "yk" does not. Unfortunately, it's too late to change
69 * this now. Matching the historic semantics isn't easy. The line
70 * number was always changed and column movement was usually relative.
71 * However, "y'a" moved the cursor to the first non-blank of the line
72 * marked by a, while "y`a" moved the cursor to the line and column
73 * marked by a.
75 if (F_ISSET(vp, VC_REVMOVE)) {
76 rp->lno = fm->lno;
77 if (vp->mkp == &vikeys['\'']) {
78 rp->cno = 0;
79 (void)nonblank(sp, ep, rp->lno, &rp->cno);
80 } else if (vp->mkp == &vikeys['`'])
81 rp->cno = fm->cno;
82 else
83 rp->cno = sp->s_relative(sp, ep, rp->lno);
86 sp->rptlines[L_YANKED] += (tm->lno - fm->lno) + 1;
87 return (0);