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
[] = "$Id: v_at.c,v 10.10 2000/07/16 20:49:34 skimo Exp $ (Berkeley) $Date: 2000/07/16 20:49:34 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
25 #include "../common/common.h"
32 * PUBLIC: int v_at __P((SCR *, VICMD *));
50 * Historically, [@*]<carriage-return> and [@*][@*] executed the most
51 * recently executed buffer in ex mode. In vi mode, only @@ repeated
52 * the last buffer. We change historic practice and make @* work from
53 * vi mode as well, it's simpler and more consistent.
55 * My intent is that *[buffer] will, in the future, pass the buffer to
56 * whatever interpreter is loaded.
58 name
= F_ISSET(vp
, VC_BUFFER
) ? vp
->buffer
: '@';
59 if (name
== '@' || name
== '*') {
60 if (!F_ISSET(sp
, SC_AT_SET
)) {
61 ex_emsg(sp
, NULL
, EXM_NOPREVBUF
);
68 CBNAME(sp
, cbp
, name
);
70 ex_emsg(sp
, KEY_NAME(sp
, name
), EXM_EMPTYBUF
);
78 * The buffer is executed in vi mode, while in vi mode, so simply
79 * push it onto the terminal queue and continue.
82 * Historic practice is that if the buffer was cut in line mode,
83 * <newlines> were appended to each line as it was pushed onto
84 * the stack. If the buffer was cut in character mode, <newlines>
85 * were appended to all lines but the last one.
88 * Historic practice is that execution of an @ buffer could be
89 * undone by a single 'u' command, i.e. the changes were grouped
90 * together. We don't get this right; I'm waiting for the new DB
91 * logging code to be available.
93 for (tp
= cbp
->textq
.cqh_last
;
94 tp
!= (void *)&cbp
->textq
; tp
= tp
->q
.cqe_prev
) {
95 static CHAR_T nl
[] = { '\n', 0 };
96 if ((F_ISSET(cbp
, CB_LMODE
) ||
97 tp
->q
.cqe_next
!= (void *)&cbp
->textq
) &&
98 v_event_push(sp
, NULL
, nl
, 1, 0) ||
99 v_event_push(sp
, NULL
, tp
->lb
, tp
->len
, 0))
105 * If any count was supplied, it applies to the first command in the
108 if (F_ISSET(vp
, VC_C1SET
)) {
109 len
= snprintf(nbuf
, sizeof(nbuf
), "%lu", vp
->count
);
110 CHAR2INT(sp
, nbuf
, len
, wp
, wlen
);
111 MEMCPYW(wbuf
, wp
, wlen
);
112 if (v_event_push(sp
, NULL
, wp
, wlen
, 0))