1 /* $NetBSD: v_yank.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
14 static const char sccsid
[] = "Id: v_yank.c,v 10.10 2001/06/25 15:19:36 skimo Exp (Berkeley) Date: 2001/06/25 15:19:36 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
21 #include <bitstring.h>
25 #include "../common/common.h"
29 * v_yank -- [buffer][count]y[count][motion]
31 * Yank text (or lines of text) into a cut buffer.
34 * Historic vi moved the cursor to the from MARK if it was before the current
35 * cursor and on a different line, e.g., "yk" moves the cursor but "yj" and
36 * "yl" do not. Unfortunately, it's too late to change this now. Matching
37 * the historic semantics isn't easy. The line number was always changed and
38 * column movement was usually relative. However, "y'a" moved the cursor to
39 * the first non-blank of the line marked by a, while "y`a" moved the cursor
40 * to the line and column marked by a. Hopefully, the motion component code
41 * got it right... Unlike delete, we make no adjustments here.
43 * PUBLIC: int v_yank __P((SCR *, VICMD *));
46 v_yank(SCR
*sp
, VICMD
*vp
)
51 F_ISSET(vp
, VC_BUFFER
) ? &vp
->buffer
: NULL
, &vp
->m_start
,
52 &vp
->m_stop
, F_ISSET(vp
, VM_LMODE
) ? CUT_LINEMODE
: 0))
54 sp
->rptlines
[L_YANKED
] += (vp
->m_stop
.lno
- vp
->m_start
.lno
) + 1;
57 * One special correction, in case we've deleted the current line or
58 * character. We check it here instead of checking in every command
59 * that can be a motion component.
61 if (db_get(sp
, vp
->m_final
.lno
, DBG_FATAL
, NULL
, &len
))
66 * Cursor movements, other than those caused by a line mode command
67 * moving to another line, historically reset the relative position.
69 * This currently matches the check made in v_delete(), I'm hoping
70 * that they should be consistent...
72 if (!F_ISSET(vp
, VM_LMODE
)) {
73 F_CLR(vp
, VM_RCM_MASK
);
74 F_SET(vp
, VM_RCM_SET
);
76 /* Make sure the set cursor position exists. */
77 if (vp
->m_final
.cno
>= len
)
78 vp
->m_final
.cno
= len
? len
- 1 : 0;