/*************************************************************************
* This program is copyright (C) 1985, 1986 by Jonathan Payne. It is *
* provided to you without charge for use only on a licensed Unix *
* system. You may copy JOVE provided that this notice is included with *
* the copy. You may not sell copies of this program or versions *
* modified for use on microcomputer systems, unless the copies are *
* included with a Unix system distribution and the source is provided. *
*************************************************************************/
/* Routines to perform all kinds of deletion. */
/* Assumes that either line1 or line2 is actual the current line, so it can
put its result into linebuf. */
patchup(line1
, char1
, line2
, char2
)
ChkWindows(line1
, line2
);
linecopy(linebuf
, curchar
, lcontents(line2
) + char2
);
/* The following is a redisplay optimization. */
if (line1
!= line2
&& (char1
== 0 && char2
== 0))
line1
->l_dline
= line2
->l_dline
;
DFixMarks(line1
, char1
, line2
, char2
);
/* Deletes the region by unlinking the lines in the middle,
and patching things up. The unlinked lines are still in
reg_delete(line1
, char1
, line2
, char2
)
if ((line1
== line2
&& char1
== char2
) || line2
== 0)
(void) fixorder(&line1
, &char1
, &line2
, &char2
);
retline
= nbufline(); /* New buffer line */
(void) ltobuf(line1
, genbuf
);
retline
->l_dline
= putline(&genbuf
[char1
]);
patchup(line1
, char1
, line2
, char2
);
retline
->l_next
= line1
->l_next
;
(void) ltobuf(line2
, genbuf
);
line2
->l_dline
= putline(genbuf
);
line1
->l_next
= line2
->l_next
;
line1
->l_next
->l_prev
= line1
;
Line
*next
= line1
->l_next
;
line1
->l_next
= line2
->l_next
;
line1
->l_next
->l_prev
= line1
;
lfreereg(next
, line2
); /* Put region at end of free line list. */
/* Delete character forward */
/* Delete character backward */
if (MinorMode(OverWrite
)) {
int count
= min(exp
, curchar
);
DoTimes(BackChar(), count
);
LastKeyStruck
= ' '; /* can you say gross? */
DoTimes(SelfInsert(), count
);
DoTimes(BackChar(), count
);
/* Delete some characters. If deleting `forward' then call for_char
to the final position otherwise call back_char. Then delete the
region between the two with patchup(). */
int killp
= (exp_p
&& abs(exp
) > 1);
(forward
) ? ForChar() : BackChar();
if (before
.p_line
== curline
&& before
.p_char
== curchar
)
reg_kill(before
.p_line
, before
.p_char
, 1);
(void) fixorder(&before
.p_line
, &before
.p_char
, &after
.p_line
, &after
.p_char
);
patchup(before
.p_line
, before
.p_char
, after
.p_line
, after
.p_char
);
lremove(before
.p_line
, after
.p_line
);
/* This kills a region between point, and line1/char1 and puts it on
the kill-ring. If the last command was one of the kill commands,
the region is appended (prepended if backwards) to the last entry. */
reg_kill(line2
, char2
, dot_moved
)
backwards
= !fixorder(&line1
, &char1
, &line2
, &char2
);
/* This is a kludge! But it possible for commands that don't
know which direction they are deleting in (e.g., delete
previous word could have been called with a negative argument
in which case, it wouldn't know that it really deleted
nl
= reg_delete(line1
, char1
, line2
, char2
);
if (last_cmd
!= KILLCMD
) {
killptr
= ((killptr
+ 1) % NUMKILLS
);
lfreelist(killbuf
[killptr
]);
Line
*lastln
= lastline(nl
);
(void) DoYank(nl
, 0, lastln
, length(lastln
), killbuf
[killptr
], 0, (Buffer
*) 0);
Line
*olastln
= lastline(killbuf
[killptr
]);
(void) DoYank(nl
, 0, lastln
, length(lastln
), olastln
, length(olastln
), (Buffer
*) 0);
register Mark
*mp
= CurMark();
reg_kill(mp
->m_line
, mp
->m_char
, 0);
/* Save a region. A pretend kill. */
if (mp
->m_line
== curline
&& mp
->m_char
== curchar
)
killptr
= ((killptr
+ 1) % NUMKILLS
);
lfreelist(killbuf
[killptr
]);
nl
= killbuf
[killptr
] = nbufline();
nl
->l_next
= nl
->l_prev
= 0;
status
= inorder(mp
->m_line
, mp
->m_char
, curline
, curchar
);
(void) DoYank(mp
->m_line
, mp
->m_char
, curline
, curchar
,
(void) DoYank(curline
, curchar
, mp
->m_line
, mp
->m_char
,
register char *ep
= &linebuf
[curchar
],
while (*ep
== ' ' || *ep
== '\t')
while (sp
> linebuf
&& *(sp
- 1) == ' ' || *(sp
- 1) == '\t')
DFixMarks(curline
, curchar
, curline
, curchar
+ (ep
- sp
));
if (!blnkp(&linebuf
[curchar
]))
dot
= MakeMark(curline
, curchar
, FLOATER
);
while (blnkp(linebuf
) && curline
->l_prev
)
SetLine(curline
->l_prev
);
all
|= (firstp(curline
));
while (blnkp(linebuf
) && !eobp()) {
forward
? ForWord() : BackWord();
reg_kill(savedot
.p_line
, savedot
.p_char
, 1);