1 /* $NetBSD: ex_visual.c,v 1.1.1.2 2008/05/18 14:31:21 aymeric Exp $ */
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.
15 static const char sccsid
[] = "Id: ex_visual.c,v 10.16 2001/08/29 11:04:13 skimo Exp (Berkeley) Date: 2001/08/29 11:04:13";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
29 #include "../common/common.h"
33 * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
34 * Switch to visual mode.
36 * PUBLIC: int ex_visual __P((SCR *, EXCMD *));
39 ex_visual(SCR
*sp
, EXCMD
*cmdp
)
48 /* If open option off, disallow visual command. */
49 if (!O_ISSET(sp
, O_OPEN
)) {
51 "175|The visual command requires that the open option be set");
55 /* Move to the address. */
56 sp
->lno
= cmdp
->addr1
.lno
== 0 ? 1 : cmdp
->addr1
.lno
;
59 * Push a command based on the line position flags. If no
60 * flag specified, the line goes at the top of the screen.
62 switch (FL_ISSET(cmdp
->iflags
,
63 E_C_CARAT
| E_C_DASH
| E_C_DOT
| E_C_PLUS
)) {
77 sp
->frp
->lno
= sp
->lno
;
79 (void)nonblank(sp
, sp
->lno
, &sp
->cno
);
80 F_SET(sp
->frp
, FR_CURSORSET
);
84 if (FL_ISSET(cmdp
->iflags
, E_C_COUNT
))
85 len
= snprintf(buf
, sizeof(buf
),
86 "%luz%c%lu", (unsigned long)sp
->lno
, pos
, cmdp
->count
);
88 len
= snprintf(buf
, sizeof(buf
),
89 "%luz%c", (unsigned long)sp
->lno
, pos
);
90 CHAR2INT(sp
, buf
, len
, wp
, wlen
);
91 (void)v_event_push(sp
, NULL
, wp
, wlen
, CH_NOMAP
| CH_QUOTED
);
95 * Historically, if no line address was specified, the [p#l] flags
96 * caused the cursor to be moved to the last line of the file, which
97 * was then positioned as described above. This seems useless, so
98 * I haven't implemented it.
100 switch (FL_ISSET(cmdp
->iflags
, E_C_HASH
| E_C_LIST
| E_C_PRINT
)) {
113 * You can call the visual part of the editor from within an ex
117 * Historically, undoing a visual session was a single undo command,
118 * i.e. you could undo all of the changes you made in visual mode.
119 * We don't get this right; I'm waiting for the new logging code to
122 * It's explicit, don't have to wait for the user, unless there's
123 * already a reason to wait.
125 if (!F_ISSET(sp
, SC_SCR_EXWROTE
))
126 F_SET(sp
, SC_EX_WAIT_NO
);
128 if (F_ISSET(sp
, SC_EX_GLOBAL
)) {
130 * When the vi screen(s) exit, we don't want to lose our hold
131 * on this screen or this file, otherwise we're going to fail
132 * fairly spectacularly.
136 /* XXXX where is this decremented ? */
139 * Fake up a screen pointer -- vi doesn't get to change our
140 * underlying file, regardless.
148 * Historically, if the user exited the vi screen(s) using an
149 * ex quit command (e.g. :wq, :q) ex/vi exited, it was only if
150 * they exited vi using the Q command that ex continued. Some
151 * early versions of nvi continued in ex regardless, but users
152 * didn't like the semantic.
159 /* Move out of the vi screen. */
160 (void)ex_puts(sp
, "\n");
162 F_CLR(sp
, SC_EX
| SC_SCR_EX
);