version 1.0
[nvi.git] / vi / v_left.c
blob5d36a60db20a9bc283de58cb2edaeeb4298c1fe0
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_left.c,v 8.3 1993/12/16 12:03:25 bostic Exp $ (Berkeley) $Date: 1993/12/16 12:03:25 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
18 * v_left -- [count]^H, [count]h
19 * Move left by columns.
21 int
22 v_left(sp, ep, vp, fm, tm, rp)
23 SCR *sp;
24 EXF *ep;
25 VICMDARG *vp;
26 MARK *fm, *tm, *rp;
28 recno_t cnt;
30 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
32 if (fm->cno == 0) {
33 msgq(sp, M_BERR, "Already in the first column.");
34 return (1);
37 rp->lno = fm->lno;
38 if (fm->cno > cnt)
39 rp->cno = fm->cno - cnt;
40 else
41 rp->cno = 0;
42 return (0);
46 * v_cfirst -- [count]_
48 * Move to the first non-blank column on a line.
50 int
51 v_cfirst(sp, ep, vp, fm, tm, rp)
52 SCR *sp;
53 EXF *ep;
54 VICMDARG *vp;
55 MARK *fm, *tm, *rp;
57 recno_t cnt;
60 * A count moves down count - 1 rows, so, "3_" is the same as "2j_".
62 * !!!
63 * Historically, if the _ is a motion, it is always a line motion,
64 * and the line motion flag is set.
66 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
67 if (cnt != 1) {
68 --vp->count;
69 if (v_down(sp, ep, vp, fm, tm, rp))
70 return (1);
71 if (F_ISSET(vp, VC_C | VC_D | VC_Y))
72 F_SET(vp, VC_LMODE);
73 } else
74 rp->lno = fm->lno;
75 rp->cno = 0;
76 if (nonblank(sp, ep, rp->lno, &rp->cno))
77 return (1);
78 return (0);
82 * v_first -- ^
83 * Move to the first non-blank column on this line.
85 int
86 v_first(sp, ep, vp, fm, tm, rp)
87 SCR *sp;
88 EXF *ep;
89 VICMDARG *vp;
90 MARK *fm, *tm, *rp;
93 * Yielding to none in our quest for compatibility with every
94 * historical blemish of vi, no matter how strange it might be,
95 * we permit the user to enter a count and then ignore it.
97 rp->cno = 0;
98 if (nonblank(sp, ep, fm->lno, &rp->cno))
99 return (1);
100 rp->lno = fm->lno;
101 return (0);
105 * v_ncol -- [count]|
106 * Move to column count or the first column on this line. If the
107 * requested column is past EOL, move to EOL. The nasty part is
108 * that we have to know character column widths to make this work.
111 v_ncol(sp, ep, vp, fm, tm, rp)
112 SCR *sp;
113 EXF *ep;
114 VICMDARG *vp;
115 MARK *fm, *tm, *rp;
117 if (F_ISSET(vp, VC_C1SET) && vp->count > 1)
118 rp->cno =
119 sp->s_chposition(sp, ep, fm->lno, (size_t)--vp->count);
120 else
121 rp->cno = 0;
122 rp->lno = fm->lno;
123 return (0);
127 * v_zero -- 0
128 * Move to the first column on this line.
131 v_zero(sp, ep, vp, fm, tm, rp)
132 SCR *sp;
133 EXF *ep;
134 VICMDARG *vp;
135 MARK *fm, *tm, *rp;
137 rp->lno = fm->lno;
138 rp->cno = 0;
139 return (0);