Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / vi / v_left.c
blob144d61132bfe60d31752d9af363c54be2c0171f7
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 static const char sccsid[] = "Id: v_left.c,v 10.9 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <limits.h>
24 #include <stdio.h>
26 #include "../common/common.h"
27 #include "vi.h"
30 * v_left -- [count]^H, [count]h
31 * Move left by columns.
33 * PUBLIC: int v_left __P((SCR *, VICMD *));
35 int
36 v_left(SCR *sp, VICMD *vp)
38 db_recno_t cnt;
41 * !!!
42 * The ^H and h commands always failed in the first column.
44 if (vp->m_start.cno == 0) {
45 v_sol(sp);
46 return (1);
49 /* Find the end of the range. */
50 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
51 if (vp->m_start.cno > cnt)
52 vp->m_stop.cno = vp->m_start.cno - cnt;
53 else
54 vp->m_stop.cno = 0;
57 * All commands move to the end of the range. Motion commands
58 * adjust the starting point to the character before the current
59 * one.
61 if (ISMOTION(vp))
62 --vp->m_start.cno;
63 vp->m_final = vp->m_stop;
64 return (0);
68 * v_cfirst -- [count]_
69 * Move to the first non-blank character in a line.
71 * PUBLIC: int v_cfirst __P((SCR *, VICMD *));
73 int
74 v_cfirst(SCR *sp, VICMD *vp)
76 db_recno_t cnt, lno;
79 * !!!
80 * If the _ is a motion component, it makes the command a line motion
81 * e.g. "d_" deletes the line. It also means that the cursor doesn't
82 * move.
84 * The _ command never failed in the first column.
86 if (ISMOTION(vp))
87 F_SET(vp, VM_LMODE);
89 * !!!
90 * Historically a specified count makes _ move down count - 1
91 * rows, so, "3_" is the same as "2j_".
93 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
94 if (cnt != 1) {
95 --vp->count;
96 return (v_down(sp, vp));
100 * Move to the first non-blank.
102 * Can't just use RCM_SET_FNB, in case _ is used as the motion
103 * component of another command.
105 vp->m_stop.cno = 0;
106 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
107 return (1);
110 * !!!
111 * The _ command has to fail if the file is empty and we're doing
112 * a delete. If deleting line 1, and 0 is the first nonblank,
113 * make the check.
115 if (vp->m_stop.lno == 1 &&
116 vp->m_stop.cno == 0 && ISCMD(vp->rkp, 'd')) {
117 if (db_last(sp, &lno))
118 return (1);
119 if (lno == 0) {
120 v_sol(sp);
121 return (1);
126 * Delete and non-motion commands move to the end of the range,
127 * yank stays at the start. Ignore others.
129 vp->m_final =
130 ISMOTION(vp) && ISCMD(vp->rkp, 'y') ? vp->m_start : vp->m_stop;
131 return (0);
135 * v_first -- ^
136 * Move to the first non-blank character in this line.
138 * PUBLIC: int v_first __P((SCR *, VICMD *));
141 v_first(SCR *sp, VICMD *vp)
144 * !!!
145 * Yielding to none in our quest for compatibility with every
146 * historical blemish of vi, no matter how strange it might be,
147 * we permit the user to enter a count and then ignore it.
151 * Move to the first non-blank.
153 * Can't just use RCM_SET_FNB, in case ^ is used as the motion
154 * component of another command.
156 vp->m_stop.cno = 0;
157 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
158 return (1);
161 * !!!
162 * The ^ command succeeded if used as a command when the cursor was
163 * on the first non-blank in the line, but failed if used as a motion
164 * component in the same situation.
166 if (ISMOTION(vp) && vp->m_start.cno == vp->m_stop.cno) {
167 v_sol(sp);
168 return (1);
172 * If moving right, non-motion commands move to the end of the range.
173 * Delete and yank stay at the start. Motion commands adjust the
174 * ending point to the character before the current ending charcter.
176 * If moving left, all commands move to the end of the range. Motion
177 * commands adjust the starting point to the character before the
178 * current starting character.
180 if (vp->m_start.cno < vp->m_stop.cno)
181 if (ISMOTION(vp)) {
182 --vp->m_stop.cno;
183 vp->m_final = vp->m_start;
184 } else
185 vp->m_final = vp->m_stop;
186 else {
187 if (ISMOTION(vp))
188 --vp->m_start.cno;
189 vp->m_final = vp->m_stop;
191 return (0);
195 * v_ncol -- [count]|
196 * Move to column count or the first column on this line. If the
197 * requested column is past EOL, move to EOL. The nasty part is
198 * that we have to know character column widths to make this work.
200 * PUBLIC: int v_ncol __P((SCR *, VICMD *));
203 v_ncol(SCR *sp, VICMD *vp)
205 if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
206 --vp->count;
207 vp->m_stop.cno =
208 vs_colpos(sp, vp->m_start.lno, (size_t)vp->count);
210 * !!!
211 * The | command succeeded if used as a command and the cursor
212 * didn't move, but failed if used as a motion component in the
213 * same situation.
215 if (ISMOTION(vp) && vp->m_stop.cno == vp->m_start.cno) {
216 v_nomove(sp);
217 return (1);
219 } else {
221 * !!!
222 * The | command succeeded if used as a command in column 0
223 * without a count, but failed if used as a motion component
224 * in the same situation.
226 if (ISMOTION(vp) && vp->m_start.cno == 0) {
227 v_sol(sp);
228 return (1);
230 vp->m_stop.cno = 0;
234 * If moving right, non-motion commands move to the end of the range.
235 * Delete and yank stay at the start. Motion commands adjust the
236 * ending point to the character before the current ending charcter.
238 * If moving left, all commands move to the end of the range. Motion
239 * commands adjust the starting point to the character before the
240 * current starting character.
242 if (vp->m_start.cno < vp->m_stop.cno)
243 if (ISMOTION(vp)) {
244 --vp->m_stop.cno;
245 vp->m_final = vp->m_start;
246 } else
247 vp->m_final = vp->m_stop;
248 else {
249 if (ISMOTION(vp))
250 --vp->m_start.cno;
251 vp->m_final = vp->m_stop;
253 return (0);
257 * v_zero -- 0
258 * Move to the first column on this line.
260 * PUBLIC: int v_zero __P((SCR *, VICMD *));
263 v_zero(SCR *sp, VICMD *vp)
266 * !!!
267 * The 0 command succeeded if used as a command in the first column
268 * but failed if used as a motion component in the same situation.
270 if (ISMOTION(vp) && vp->m_start.cno == 0) {
271 v_sol(sp);
272 return (1);
276 * All commands move to the end of the range. Motion commands
277 * adjust the starting point to the character before the current
278 * one.
280 vp->m_stop.cno = 0;
281 if (ISMOTION(vp))
282 --vp->m_start.cno;
283 vp->m_final = vp->m_stop;
284 return (0);