2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid[] = "@(#)ex_visual.c 10.13 (Berkeley) 6/28/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
27 #include "../common/common.h"
31 * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
32 * Switch to visual mode.
34 * PUBLIC: int ex_visual __P((SCR *, EXCMD *));
46 /* If open option off, disallow visual command. */
47 if (!O_ISSET(sp, O_OPEN)) {
49 "175|The visual command requires that the open option be set");
53 /* Move to the address. */
54 sp->lno = cmdp->addr1.lno == 0 ? 1 : cmdp->addr1.lno;
57 * Push a command based on the line position flags. If no
58 * flag specified, the line goes at the top of the screen.
60 switch (FL_ISSET(cmdp->iflags,
61 E_C_CARAT | E_C_DASH | E_C_DOT | E_C_PLUS)) {
75 sp->frp->lno = sp->lno;
77 (void)nonblank(sp, sp->lno, &sp->cno);
78 F_SET(sp->frp, FR_CURSORSET);
82 if (FL_ISSET(cmdp->iflags, E_C_COUNT))
83 len = snprintf(buf, sizeof(buf),
84 "%luz%c%lu", (u_long)sp->lno, pos, cmdp->count);
86 len = snprintf(buf, sizeof(buf), "%luz%c",
87 (u_long)sp->lno, pos);
88 (void)v_event_push(sp, NULL, buf, len, CH_NOMAP | CH_QUOTED);
92 * Historically, if no line address was specified, the [p#l] flags
93 * caused the cursor to be moved to the last line of the file, which
94 * was then positioned as described above. This seems useless, so
95 * I haven't implemented it.
97 switch (FL_ISSET(cmdp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT)) {
110 * You can call the visual part of the editor from within an ex
114 * Historically, undoing a visual session was a single undo command,
115 * i.e. you could undo all of the changes you made in visual mode.
116 * We don't get this right; I'm waiting for the new logging code to
119 * It's explicit, don't have to wait for the user, unless there's
120 * already a reason to wait.
122 if (!F_ISSET(sp, SC_SCR_EXWROTE))
123 F_SET(sp, SC_EX_WAIT_NO);
125 if (F_ISSET(sp, SC_EX_GLOBAL)) {
127 * When the vi screen(s) exit, we don't want to lose our hold
128 * on this screen or this file, otherwise we're going to fail
129 * fairly spectacularly.
135 * Fake up a screen pointer -- vi doesn't get to change our
136 * underlying file, regardless.
144 * Historically, if the user exited the vi screen(s) using an
145 * ex quit command (e.g. :wq, :q) ex/vi exited, it was only if
146 * they exited vi using the Q command that ex continued. Some
147 * early versions of nvi continued in ex regardless, but users
148 * didn't like the semantic.
155 /* Move out of the vi screen. */
156 (void)ex_puts(sp, "\n");
158 F_CLR(sp, SC_EX | SC_SCR_EX);