* Bill Joy UCB September 1977
if (cp
> linebuf
&& (cp
[0] == 0 || c
== '#'))
i
=+ vreopen(i
, dot
- zero
);
while (i
< vliny
[vcline
+ 1]) {
else if (*cursor
== '\t')
vgotoCL(column(cursor
- 1));
if (value(AUTOINDENT
) && indent
!= 0) {
gcursor
= genindent(indent
);
vgotoCL(qcolumn(cursor
- 1, genbuf
));
if ((vglobp
&& *vglobp
== 0) || peekbr()) {
if (!INS
[0] || INS
[0] == OVERBUF
) {
* At the beginning of the following loop which gathers appended
* lines, gcursor points to the beginning of the place for the
* appended text. Linebuf contains the line in which the operation
* is taking place, the appended text is placed starting at the
* position indicated by cursor.
* Get a line into genbuf. Gcursor indicates that we
* have possibly generated some input (e.g. autoindent).
* If the line is terminated with a newline character
* then escape will be set to the newline. The repcnt
* limits the number of characters appended, e.g. it is
* 2 to get exactly one character (i.e. for a replace)
* or 0 to get an arbitrary number of characters.
if (ch
== 'r' && repcnt
== 0)
gcursor
= vgetline(repcnt
, gcursor
, &escape
);
addtext(HADZERO
? "0" : "^");
if (!vaifirst
&& value(AUTOINDENT
)) {
* Fix up the autoindent. Fixindent gathers white
* space from the beginning of the line and turns
* it into tabs and spaces as appropriate.
* We reset the cursor to be the end of the line
* as it was when it was returned from vgetline.
gcursor
= strend(genbuf
);
* Have to cut down the count if the specified count
* would make a line which is too long.
* We save the rest of the line after the end of the
* appended material (at gcursor + 1).
* This frees up linebuf for use in saving lines, etc.
strcpy(gcursor
+ 1, cursor
);
* Catenate cnt copies of the inserted text after
* the material which precedes this insert.
cursor
=+ gcursor
- genbuf
;
* If the insert didnt terminate with a new line character
* then we want to put the whole line back together.
strcpy(cursor
, gcursor
+ 1);
* Clean up the line image on the screen.
* I is the first line after this lines image for use
* in making a new next line.
i
= vreopen(vliny
[vcline
], dot
- zero
);
* We wish to place the text we are "pushing ahead"
* in front of the append in linebuf, cursor pointing
* to the beginning of linebuf. We also wish to leave
* in genbuf the white space implied by an autoindent
* or if not ai then just start the new line at the
indent
= whitecnt(linebuf
);
* If we are generating an indent, then we
* don't want the white space of the pushed ahead
* line, preferring to generate our own. Discard
* the white space of the pushed ahead material
* and copy the remainder back to linebuf.
strcLIN(vpastwh(gcursor
+ 1));
* Generate indent white space and leave the
* cursor pointing just after it.
* Note that genindent doesn't make the generated
* white space into a string so we must do that
gcursor
= genindent(indent
);
* If the line is too long when the generated white
* space is added, then just pretend ai isn't set.
if (gcursor
+ strlen(linebuf
) > &genbuf
[510])
* Paste the first image of the line together.
strcpy(gcursor
, linebuf
);
* Without ai the first image of the new line
* is just the pushed ahead material, and there
* are no pre-inserted characters.
strcpy(genbuf
, gcursor
+ 1);
* Make a new line after dot with the material in genbuf.
* Note that this call increments dot as a side effect,
* so that dot now references the new line.
* Now open up the new line on the screen after
* Put the stuff we are pushing into linebuf
* and set the cursor to indicate that no stuff
* will preceded the inserted material on the new line.
vgotoCL(qcolumn(cursor
- 1, genbuf
));
* We ended an append with a non-newline.
* At this point the new image of the line is in linebuf
* and the cursor points at the desired cursor position.
* We have already shown this line, but must clean up the
* remainder of the screen. Note that the cursor should
* also be set to the last character appended, so
* it needs to be backed up if there was such a character.
for (cp
= genbuf
; indent
>= 8; indent
=- 8)
for (; indent
> 0; indent
--)
if (*cp
== 0 && i
== indent
&& linebuf
[0] == 0) {
strcpy(genindent(i
), cp
);
vgetline(cnt
, gcursor
, aescaped
)
iwhite
= whitecnt(genbuf
);
case DELETE
: /* interrupt */
cp
= genindent(iwhite
= backtab(c
+ value(SHIFTWIDTH
) + 1));
if (c
== iwhite
&& c
!= 0)
ogcursor
= cp
= genindent(iwhite
);
} else if (cp
+ 1 == gcursor
&&
(*cp
== '^' || *cp
== '0')) {
if (vglobp
&& vglobp
- iglobp
>= 2 &&
(vglobp
[-2] == '^' || vglobp
[-2] == '0')
&& gcursor
== ogcursor
+ 1)
case CTRL(h
): /* back character */
case CTRL(w
): /* back word */
for (cp
= gcursor
; cp
> ogcursor
&&
for (c
= wordch(cp
- 1); cp
> ogcursor
&&
while (gcursor
< cp
) putchar(*gcursor
++);
vgotoCL(qcolumn(cursor
- 1, genbuf
));
if (gcursor
> &genbuf
[510])
register int len
, replen
;
strcpy(cursor
, cursor
+ (replen
> len
? len
: replen
));
if (len
+ cnt
* replen
<= 510)
cnt
= (510 - len
) / replen
;