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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
23 #include "../common/common.h"
27 * ex_visual -- :[line] vi[sual] [^-.+] [window_size] [flags]
28 * Switch to visual mode.
30 * PUBLIC: int ex_visual(SCR *, EXCMD *);
33 ex_visual(SCR *sp, EXCMD *cmdp)
42 /* If open option off, disallow visual command. */
43 if (!O_ISSET(sp, O_OPEN)) {
45 "175|The visual command requires that the open option be set");
49 /* Move to the address. */
50 sp->lno = cmdp->addr1.lno == 0 ? 1 : cmdp->addr1.lno;
53 * Push a command based on the line position flags. If no
54 * flag specified, the line goes at the top of the screen.
56 switch (FL_ISSET(cmdp->iflags,
57 E_C_CARAT | E_C_DASH | E_C_DOT | E_C_PLUS)) {
71 sp->frp->lno = sp->lno;
73 (void)nonblank(sp, sp->lno, &sp->cno);
74 F_SET(sp->frp, FR_CURSORSET);
78 if (FL_ISSET(cmdp->iflags, E_C_COUNT))
79 len = snprintf(buf, sizeof(buf),
80 "%luz%c%lu", (u_long)sp->lno, pos, cmdp->count);
82 len = snprintf(buf, sizeof(buf), "%luz%c", (u_long)sp->lno, pos);
83 CHAR2INT(sp, buf, len, wp, wlen);
84 (void)v_event_push(sp, NULL, wp, wlen, CH_NOMAP | CH_QUOTED);
88 * Historically, if no line address was specified, the [p#l] flags
89 * caused the cursor to be moved to the last line of the file, which
90 * was then positioned as described above. This seems useless, so
91 * I haven't implemented it.
93 switch (FL_ISSET(cmdp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT)) {
106 * You can call the visual part of the editor from within an ex
110 * Historically, undoing a visual session was a single undo command,
111 * i.e. you could undo all of the changes you made in visual mode.
112 * We don't get this right; I'm waiting for the new logging code to
115 * It's explicit, don't have to wait for the user, unless there's
116 * already a reason to wait.
118 if (!F_ISSET(sp, SC_SCR_EXWROTE))
119 F_SET(sp, SC_EX_WAIT_NO);
121 if (F_ISSET(sp, SC_EX_GLOBAL)) {
123 * When the vi screen(s) exit, we don't want to lose our hold
124 * on this screen or this file, otherwise we're going to fail
125 * fairly spectacularly.
129 /* XXXX where is this decremented ? */
132 * Fake up a screen pointer -- vi doesn't get to change our
133 * underlying file, regardless.
141 * Historically, if the user exited the vi screen(s) using an
142 * ex quit command (e.g. :wq, :q) ex/vi exited, it was only if
143 * they exited vi using the Q command that ex continued. Some
144 * early versions of nvi continued in ex regardless, but users
145 * didn't like the semantic.
152 /* Move out of the vi screen. */
153 (void)ex_puts(sp, "\n");
155 F_CLR(sp, SC_EX | SC_SCR_EX);