v_yank.c revision 1.3 1 1.3 christos /* $NetBSD: v_yank.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 1.1 christos /*-
3 1.1 christos * Copyright (c) 1992, 1993, 1994
4 1.1 christos * The Regents of the University of California. All rights reserved.
5 1.1 christos * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 1.1 christos * Keith Bostic. All rights reserved.
7 1.1 christos *
8 1.1 christos * See the LICENSE file for redistribution information.
9 1.1 christos */
10 1.1 christos
11 1.1 christos #include "config.h"
12 1.1 christos
13 1.3 christos #include <sys/cdefs.h>
14 1.3 christos #if 0
15 1.1 christos #ifndef lint
16 1.1 christos 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 1.1 christos #endif /* not lint */
18 1.3 christos #else
19 1.3 christos __RCSID("$NetBSD: v_yank.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 1.3 christos #endif
21 1.1 christos
22 1.1 christos #include <sys/types.h>
23 1.1 christos #include <sys/queue.h>
24 1.1 christos #include <sys/time.h>
25 1.1 christos
26 1.1 christos #include <bitstring.h>
27 1.1 christos #include <limits.h>
28 1.1 christos #include <stdio.h>
29 1.1 christos
30 1.1 christos #include "../common/common.h"
31 1.1 christos #include "vi.h"
32 1.1 christos
33 1.1 christos /*
34 1.1 christos * v_yank -- [buffer][count]y[count][motion]
35 1.1 christos * [buffer][count]Y
36 1.1 christos * Yank text (or lines of text) into a cut buffer.
37 1.1 christos *
38 1.1 christos * !!!
39 1.1 christos * Historic vi moved the cursor to the from MARK if it was before the current
40 1.1 christos * cursor and on a different line, e.g., "yk" moves the cursor but "yj" and
41 1.1 christos * "yl" do not. Unfortunately, it's too late to change this now. Matching
42 1.1 christos * the historic semantics isn't easy. The line number was always changed and
43 1.1 christos * column movement was usually relative. However, "y'a" moved the cursor to
44 1.1 christos * the first non-blank of the line marked by a, while "y`a" moved the cursor
45 1.1 christos * to the line and column marked by a. Hopefully, the motion component code
46 1.1 christos * got it right... Unlike delete, we make no adjustments here.
47 1.1 christos *
48 1.1 christos * PUBLIC: int v_yank __P((SCR *, VICMD *));
49 1.1 christos */
50 1.1 christos int
51 1.1 christos v_yank(SCR *sp, VICMD *vp)
52 1.1 christos {
53 1.1 christos size_t len;
54 1.1 christos
55 1.1 christos if (cut(sp,
56 1.1 christos F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, &vp->m_start,
57 1.1 christos &vp->m_stop, F_ISSET(vp, VM_LMODE) ? CUT_LINEMODE : 0))
58 1.1 christos return (1);
59 1.1 christos sp->rptlines[L_YANKED] += (vp->m_stop.lno - vp->m_start.lno) + 1;
60 1.1 christos
61 1.1 christos /*
62 1.1 christos * One special correction, in case we've deleted the current line or
63 1.1 christos * character. We check it here instead of checking in every command
64 1.1 christos * that can be a motion component.
65 1.1 christos */
66 1.1 christos if (db_get(sp, vp->m_final.lno, DBG_FATAL, NULL, &len))
67 1.1 christos return (1);
68 1.1 christos
69 1.1 christos /*
70 1.1 christos * !!!
71 1.1 christos * Cursor movements, other than those caused by a line mode command
72 1.1 christos * moving to another line, historically reset the relative position.
73 1.1 christos *
74 1.1 christos * This currently matches the check made in v_delete(), I'm hoping
75 1.1 christos * that they should be consistent...
76 1.1 christos */
77 1.1 christos if (!F_ISSET(vp, VM_LMODE)) {
78 1.1 christos F_CLR(vp, VM_RCM_MASK);
79 1.1 christos F_SET(vp, VM_RCM_SET);
80 1.1 christos
81 1.1 christos /* Make sure the set cursor position exists. */
82 1.1 christos if (vp->m_final.cno >= len)
83 1.1 christos vp->m_final.cno = len ? len - 1 : 0;
84 1.1 christos }
85 1.1 christos return (0);
86 1.1 christos }
87