2000-08-06 21:13:45 +00:00
|
|
|
/* $Id$ */
|
2000-06-06 05:53:49 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* cut.c *
|
|
|
|
* *
|
2002-01-04 17:57:40 +00:00
|
|
|
* Copyright (C) 1999-2002 Chris Allegretta *
|
2000-06-06 05:53:49 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2001-10-24 11:33:54 +00:00
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2000-06-06 05:53:49 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2001-04-28 18:03:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2002-07-19 01:08:59 +00:00
|
|
|
#include <assert.h>
|
2000-06-06 05:53:49 +00:00
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
static int marked_cut; /* Is the cutbuffer from a mark? */
|
2002-12-22 16:30:00 +00:00
|
|
|
static filestruct *cutbottom = NULL;
|
|
|
|
/* Pointer to end of cutbuffer */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
filestruct *get_cutbottom(void)
|
|
|
|
{
|
|
|
|
return cutbottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_to_cutbuffer(filestruct *inptr)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2002-12-22 16:30:00 +00:00
|
|
|
fprintf(stderr, _("add_to_cutbuffer() called with inptr->data = %s\n"),
|
2000-06-06 05:53:49 +00:00
|
|
|
inptr->data);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cutbuffer == NULL) {
|
|
|
|
cutbuffer = inptr;
|
|
|
|
inptr->prev = NULL;
|
|
|
|
} else {
|
|
|
|
cutbottom->next = inptr;
|
|
|
|
inptr->prev = cutbottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
inptr->next = NULL;
|
|
|
|
cutbottom = inptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Cut a marked segment instead of a whole line.
|
2002-12-22 16:30:00 +00:00
|
|
|
*
|
2002-07-19 01:08:59 +00:00
|
|
|
* The first cut character is top->data[top_x]. Unless top == bot, the
|
|
|
|
* last cut line has length bot_x. That is, if bot_x > 0 then we cut to
|
|
|
|
* bot->data[bot_x - 1].
|
|
|
|
*
|
|
|
|
* destructive is whether to actually modify the file structure, if not
|
|
|
|
* then just copy the buffer into cutbuffer and don't pull it from the
|
|
|
|
* file.
|
|
|
|
*
|
|
|
|
* If destructive, then we maintain totsize, totlines, filebot, the
|
|
|
|
* magic line, and line numbers. Also, we set current and current_x so
|
|
|
|
* the cursor will be on the first character after what was cut. We do
|
|
|
|
* not do any screen updates. */
|
|
|
|
void cut_marked_segment(filestruct *top, size_t top_x, filestruct *bot,
|
|
|
|
size_t bot_x, int destructive)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2002-07-19 01:08:59 +00:00
|
|
|
filestruct *tmp, *next;
|
|
|
|
size_t newsize;
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
if (top == bot && top_x == bot_x)
|
|
|
|
return;
|
|
|
|
assert(top != NULL && bot != NULL);
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Make top be no later than bot. */
|
|
|
|
if (top->lineno > bot->lineno) {
|
|
|
|
filestruct *swap = top;
|
|
|
|
int swap2 = top_x;
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
top = bot;
|
|
|
|
bot = swap;
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
top_x = bot_x;
|
|
|
|
bot_x = swap2;
|
|
|
|
} else if (top == bot && top_x > bot_x) {
|
|
|
|
/* And bot_x can't be an earlier character than top_x. */
|
|
|
|
int swap = top_x;
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
top_x = bot_x;
|
|
|
|
bot_x = swap;
|
2001-06-21 23:58:47 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Make the first cut line manually. */
|
2000-06-06 05:53:49 +00:00
|
|
|
tmp = copy_node(top);
|
2002-07-19 01:08:59 +00:00
|
|
|
newsize = (top == bot ? bot_x - top_x : strlen(top->data + top_x));
|
|
|
|
memmove(tmp->data, top->data + top_x, newsize);
|
|
|
|
null_at(&tmp->data, newsize);
|
|
|
|
add_to_cutbuffer(tmp);
|
2001-05-29 04:21:44 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* And make the remainder line manually too. */
|
2001-05-29 04:21:44 +00:00
|
|
|
if (destructive) {
|
2002-07-19 01:08:59 +00:00
|
|
|
current_x = top_x;
|
|
|
|
totsize -= newsize;
|
|
|
|
totlines -= bot->lineno - top->lineno;
|
|
|
|
|
|
|
|
newsize = top_x + strlen(bot->data + bot_x) + 1;
|
|
|
|
if (top == bot) {
|
|
|
|
/* In this case, the remainder line is shorter, so we must
|
|
|
|
move text from the end forward first. */
|
|
|
|
memmove(top->data + top_x, bot->data + bot_x,
|
|
|
|
newsize - top_x);
|
|
|
|
top->data = (char *)nrealloc(top->data,
|
|
|
|
sizeof(char) * newsize);
|
|
|
|
} else {
|
2002-07-20 13:57:41 +00:00
|
|
|
totsize -= bot_x + 1;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2002-12-22 16:30:00 +00:00
|
|
|
/* Here, the remainder line might get longer, so we
|
|
|
|
realloc() it first. */
|
2002-07-19 01:08:59 +00:00
|
|
|
top->data = (char *)nrealloc(top->data,
|
|
|
|
sizeof(char) * newsize);
|
|
|
|
memmove(top->data + top_x, bot->data + bot_x,
|
|
|
|
newsize - top_x);
|
2001-05-29 04:21:44 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
if (top == bot) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
return;
|
2001-05-29 04:21:44 +00:00
|
|
|
}
|
2001-05-17 03:41:00 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
tmp = top->next;
|
|
|
|
while (tmp != bot) {
|
|
|
|
next = tmp->next;
|
|
|
|
if (!destructive)
|
|
|
|
tmp = copy_node(tmp);
|
|
|
|
else
|
2002-07-20 13:57:41 +00:00
|
|
|
totsize -= strlen(tmp->data) + 1;
|
2002-07-19 01:08:59 +00:00
|
|
|
add_to_cutbuffer(tmp);
|
|
|
|
tmp = next;
|
|
|
|
}
|
2001-05-17 03:41:00 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Make the last cut line manually. */
|
|
|
|
tmp = copy_node(bot);
|
|
|
|
null_at(&tmp->data, bot_x);
|
|
|
|
add_to_cutbuffer(tmp);
|
|
|
|
#ifdef DEBUG
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2001-05-29 04:21:44 +00:00
|
|
|
if (destructive) {
|
2002-07-19 01:08:59 +00:00
|
|
|
top->next = bot->next;
|
|
|
|
if (top->next != NULL)
|
|
|
|
top->next->prev = top;
|
|
|
|
delete_node(bot);
|
2001-05-29 04:21:44 +00:00
|
|
|
renumber(top);
|
|
|
|
current = top;
|
|
|
|
if (bot == filebot) {
|
2002-07-19 01:08:59 +00:00
|
|
|
filebot = top;
|
|
|
|
assert(bot_x == 0);
|
|
|
|
if (top_x > 0)
|
|
|
|
new_magicline();
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int do_cut_text(void)
|
|
|
|
{
|
2002-07-19 01:08:59 +00:00
|
|
|
filestruct *fileptr;
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifndef NANO_SMALL
|
2001-10-22 03:15:31 +00:00
|
|
|
int dontupdate = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
assert(current != NULL && current->data != NULL);
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2000-08-07 14:39:32 +00:00
|
|
|
check_statblank();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2000-07-27 04:09:23 +00:00
|
|
|
if (!ISSET(KEEP_CUTBUFFER)) {
|
2000-06-06 05:53:49 +00:00
|
|
|
free_filestruct(cutbuffer);
|
|
|
|
cutbuffer = NULL;
|
2001-06-21 15:07:40 +00:00
|
|
|
marked_cut = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, _("Blew away cutbuffer =)\n"));
|
|
|
|
#endif
|
|
|
|
}
|
2000-08-07 14:58:26 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* You can't cut the magic line except with the mark. But
|
|
|
|
trying does clear the cutbuffer if KEEP_CUTBUFFER is not set. */
|
|
|
|
if (current == filebot
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
&& !ISSET(MARK_ISSET)
|
|
|
|
#endif
|
|
|
|
)
|
2000-08-07 14:58:26 +00:00
|
|
|
return 0;
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifndef NANO_SMALL
|
2000-07-24 18:28:30 +00:00
|
|
|
if (ISSET(CUT_TO_END) && !ISSET(MARK_ISSET)) {
|
2002-07-19 01:08:59 +00:00
|
|
|
assert(current_x >= 0 && current_x <= strlen(current->data));
|
2001-06-10 20:41:20 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
if (current->data[current_x] == '\0') {
|
|
|
|
/* If the line is empty and we didn't just cut a non-blank
|
|
|
|
line, create a dummy line and add it to the cutbuffer */
|
2001-06-22 21:47:23 +00:00
|
|
|
if (marked_cut != 1 && current->next != filebot) {
|
2002-07-19 01:08:59 +00:00
|
|
|
filestruct *junk = make_new_node(current);
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2002-02-15 19:17:02 +00:00
|
|
|
junk->data = charalloc(1);
|
2002-06-13 00:40:19 +00:00
|
|
|
junk->data[0] = '\0';
|
2001-06-10 20:41:20 +00:00
|
|
|
add_to_cutbuffer(junk);
|
2002-07-19 01:08:59 +00:00
|
|
|
#ifdef DEBUG
|
2001-06-21 15:07:40 +00:00
|
|
|
dump_buffer(cutbuffer);
|
2002-07-19 01:08:59 +00:00
|
|
|
#endif
|
2001-06-10 20:41:20 +00:00
|
|
|
}
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2000-07-25 03:20:07 +00:00
|
|
|
do_delete();
|
2000-07-27 04:09:23 +00:00
|
|
|
SET(KEEP_CUTBUFFER);
|
2000-07-27 04:31:52 +00:00
|
|
|
marked_cut = 2;
|
2000-07-25 03:20:07 +00:00
|
|
|
return 1;
|
2000-10-26 01:44:42 +00:00
|
|
|
} else {
|
2000-07-25 03:20:07 +00:00
|
|
|
SET(MARK_ISSET);
|
|
|
|
SET(KEEP_CUTBUFFER);
|
|
|
|
|
|
|
|
mark_beginx = strlen(current->data);
|
|
|
|
mark_beginbuf = current;
|
2002-07-19 01:08:59 +00:00
|
|
|
dontupdate = 1;
|
2000-07-25 03:20:07 +00:00
|
|
|
}
|
2000-07-12 02:09:17 +00:00
|
|
|
}
|
2001-10-22 03:15:31 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
if (ISSET(MARK_ISSET)) {
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Don't do_update() and move the screen position if the marked
|
|
|
|
area lies entirely within the screen buffer */
|
|
|
|
dontupdate |= current->lineno >= edittop->lineno &&
|
|
|
|
current->lineno <= editbot->lineno &&
|
|
|
|
mark_beginbuf->lineno >= edittop->lineno &&
|
|
|
|
mark_beginbuf->lineno <= editbot->lineno;
|
|
|
|
cut_marked_segment(current, current_x, mark_beginbuf,
|
|
|
|
mark_beginx, 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
placewewant = xplustabs();
|
|
|
|
UNSET(MARK_ISSET);
|
2000-07-27 04:09:23 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
marked_cut = 1;
|
2002-12-22 16:30:00 +00:00
|
|
|
if (dontupdate)
|
2000-07-25 03:20:07 +00:00
|
|
|
edit_refresh();
|
2002-12-22 16:30:00 +00:00
|
|
|
else
|
2000-07-29 04:33:38 +00:00
|
|
|
edit_update(current, CENTER);
|
2002-12-22 16:30:00 +00:00
|
|
|
set_modified();
|
2000-07-27 04:31:52 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
#endif /* !NANO_SMALL */
|
|
|
|
|
|
|
|
totlines--;
|
|
|
|
totsize -= strlen(current->data) + 1;
|
|
|
|
fileptr = current;
|
|
|
|
current = current->next;
|
|
|
|
current->prev = fileptr->prev;
|
|
|
|
add_to_cutbuffer(fileptr);
|
|
|
|
#ifdef DEBUG
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
#endif
|
2002-11-04 16:05:42 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
if (fileptr == fileage)
|
|
|
|
fileage = current;
|
|
|
|
else
|
|
|
|
current->prev->next = current;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
if (fileptr == edittop)
|
|
|
|
edittop = current;
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
renumber(current);
|
2000-06-06 05:53:49 +00:00
|
|
|
edit_refresh();
|
|
|
|
set_modified();
|
|
|
|
marked_cut = 0;
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
2002-07-19 01:08:59 +00:00
|
|
|
reset_cursor();
|
2000-06-06 05:53:49 +00:00
|
|
|
SET(KEEP_CUTBUFFER);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_uncut_text(void)
|
|
|
|
{
|
2002-07-19 01:08:59 +00:00
|
|
|
filestruct *tmp = current, *fileptr = current;
|
2002-12-22 16:30:00 +00:00
|
|
|
filestruct *newbuf = NULL, *newend = NULL;
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
char *tmpstr, *tmpstr2;
|
2000-12-10 17:03:25 +00:00
|
|
|
filestruct *hold = current;
|
2000-06-06 05:53:49 +00:00
|
|
|
#endif
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wrap_reset();
|
2000-08-07 14:39:32 +00:00
|
|
|
check_statblank();
|
2000-06-06 05:53:49 +00:00
|
|
|
if (cutbuffer == NULL || fileptr == NULL)
|
|
|
|
return 0; /* AIEEEEEEEEEEEE */
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
#ifndef NANO_SMALL
|
2002-12-22 16:30:00 +00:00
|
|
|
if (marked_cut == 0 || cutbuffer->next != NULL)
|
2002-07-19 01:08:59 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
newbuf = copy_filestruct(cutbuffer);
|
|
|
|
for (newend = newbuf; newend->next != NULL && newend != NULL;
|
|
|
|
newend = newend->next)
|
|
|
|
totlines++;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hook newbuf into fileptr */
|
|
|
|
#ifndef NANO_SMALL
|
2002-12-22 16:30:00 +00:00
|
|
|
if (marked_cut != 0) {
|
2002-07-19 01:08:59 +00:00
|
|
|
int recenter_me = 0;
|
|
|
|
/* Should we eventually use edit_update(CENTER)? */
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
/* If there's only one line in the cutbuffer */
|
|
|
|
if (cutbuffer->next == NULL) {
|
2002-07-19 01:08:59 +00:00
|
|
|
size_t buf_len = strlen(cutbuffer->data);
|
|
|
|
size_t cur_len = strlen(current->data);
|
|
|
|
|
|
|
|
current->data = nrealloc(current->data, cur_len + buf_len + 1);
|
|
|
|
memmove(current->data + current_x + buf_len,
|
|
|
|
current->data + current_x, cur_len - current_x + 1);
|
|
|
|
strncpy(current->data + current_x, cutbuffer->data, buf_len);
|
2002-12-22 16:30:00 +00:00
|
|
|
/* Use strncpy() to not copy the terminal '\0'. */
|
2002-07-19 01:08:59 +00:00
|
|
|
|
|
|
|
current_x += buf_len;
|
|
|
|
totsize += buf_len;
|
2002-03-28 01:59:34 +00:00
|
|
|
/* If we've uncut a line, make sure there's a magicline after
|
|
|
|
it */
|
|
|
|
if (current->next == NULL)
|
|
|
|
new_magicline();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_cursor();
|
|
|
|
} else { /* yuck -- no kidding! */
|
|
|
|
tmp = current->next;
|
|
|
|
/* New beginning */
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr = charalloc(current_x + strlen(newbuf->data) + 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
strncpy(tmpstr, current->data, current_x);
|
|
|
|
strcpy(&tmpstr[current_x], newbuf->data);
|
|
|
|
totsize += strlen(newbuf->data) + strlen(newend->data) + 1;
|
|
|
|
|
|
|
|
/* New end */
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr2 = charalloc(strlen(newend->data) +
|
2000-06-06 05:53:49 +00:00
|
|
|
strlen(¤t->data[current_x]) + 1);
|
|
|
|
strcpy(tmpstr2, newend->data);
|
|
|
|
strcat(tmpstr2, ¤t->data[current_x]);
|
|
|
|
|
|
|
|
free(current->data);
|
|
|
|
current->data = tmpstr;
|
|
|
|
current->next = newbuf->next;
|
|
|
|
newbuf->next->prev = current;
|
|
|
|
delete_node(newbuf);
|
|
|
|
|
|
|
|
current_x = strlen(newend->data);
|
|
|
|
placewewant = xplustabs();
|
|
|
|
free(newend->data);
|
|
|
|
newend->data = tmpstr2;
|
|
|
|
|
|
|
|
newend->next = tmp;
|
|
|
|
|
|
|
|
/* If tmp isn't null, we're in the middle: update the
|
2002-07-19 01:08:59 +00:00
|
|
|
prev pointer. If it IS null, we're at the end; update
|
|
|
|
the filebot pointer */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
if (tmp != NULL)
|
|
|
|
tmp->prev = newend;
|
2000-12-10 05:44:02 +00:00
|
|
|
else {
|
|
|
|
/* Fix the editbot pointer too */
|
|
|
|
if (editbot == filebot)
|
|
|
|
editbot = newend;
|
2000-06-06 05:53:49 +00:00
|
|
|
filebot = newend;
|
2000-12-10 05:54:27 +00:00
|
|
|
new_magicline();
|
2000-12-10 05:44:02 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
/* Now why don't we update the totsize also */
|
|
|
|
for (tmp = current->next; tmp != newend; tmp = tmp->next)
|
|
|
|
totsize += strlen(tmp->data) + 1;
|
|
|
|
|
|
|
|
current = newend;
|
2002-07-19 01:08:59 +00:00
|
|
|
if (editbot->lineno < newend->lineno)
|
|
|
|
recenter_me = 1;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2000-07-27 05:09:22 +00:00
|
|
|
/* If marked cut == 2, that means that we're doing a cut to end
|
|
|
|
and we don't want anything else on the line, so we have to
|
2002-07-19 01:08:59 +00:00
|
|
|
screw up all the work we just did and separate the line.
|
|
|
|
There must be a better way to do this, but not at 1AM on a
|
|
|
|
work night. */
|
2000-07-27 05:09:22 +00:00
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
if (marked_cut == 2) {
|
2000-07-27 05:09:22 +00:00
|
|
|
tmp = make_new_node(current);
|
2002-12-22 16:30:00 +00:00
|
|
|
tmp->data = mallocstrcpy(NULL, current->data + current_x);
|
2000-07-28 00:58:35 +00:00
|
|
|
splice_node(current, tmp, current->next);
|
2001-10-22 23:22:19 +00:00
|
|
|
null_at(¤t->data, current_x);
|
2000-07-27 13:03:31 +00:00
|
|
|
current = current->next;
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
2001-06-21 15:07:40 +00:00
|
|
|
|
|
|
|
/* Extra line added, update stuff */
|
|
|
|
totlines++;
|
|
|
|
totsize++;
|
2000-07-27 05:09:22 +00:00
|
|
|
}
|
2000-12-10 05:44:02 +00:00
|
|
|
/* Renumber from BEFORE where we pasted ;) */
|
|
|
|
renumber(hold);
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-06 05:53:49 +00:00
|
|
|
dump_buffer(fileage);
|
|
|
|
dump_buffer(cutbuffer);
|
2002-07-19 01:08:59 +00:00
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
set_modified();
|
2002-07-19 01:08:59 +00:00
|
|
|
if (recenter_me)
|
|
|
|
edit_update(current, CENTER);
|
|
|
|
else
|
|
|
|
edit_refresh();
|
2001-06-21 15:07:40 +00:00
|
|
|
UNSET(KEEP_CUTBUFFER);
|
2000-06-06 05:53:49 +00:00
|
|
|
return 0;
|
2002-07-19 01:08:59 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
#endif
|
2002-07-19 01:08:59 +00:00
|
|
|
|
|
|
|
if (fileptr != fileage) {
|
2000-06-06 05:53:49 +00:00
|
|
|
tmp = fileptr->prev;
|
|
|
|
tmp->next = newbuf;
|
|
|
|
newbuf->prev = tmp;
|
2002-07-19 01:08:59 +00:00
|
|
|
} else
|
2000-06-06 05:53:49 +00:00
|
|
|
fileage = newbuf;
|
2002-07-19 01:08:59 +00:00
|
|
|
totlines++; /* Unmarked uncuts don't split lines */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
/* This is so uncutting at the top of the buffer will work => */
|
|
|
|
if (current_y == 0)
|
|
|
|
edittop = newbuf;
|
|
|
|
|
|
|
|
/* Connect the end of the buffer to the filestruct */
|
|
|
|
newend->next = fileptr;
|
|
|
|
fileptr->prev = newend;
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
/* Recalculate size *sigh* */
|
2000-06-06 05:53:49 +00:00
|
|
|
for (tmp = newbuf; tmp != fileptr; tmp = tmp->next)
|
|
|
|
totsize += strlen(tmp->data) + 1;
|
|
|
|
|
|
|
|
i = editbot->lineno;
|
|
|
|
renumber(newbuf);
|
2002-12-22 16:30:00 +00:00
|
|
|
/* Center the screen if we've moved beyond the line numbers of both
|
|
|
|
the old and new editbots */
|
|
|
|
if (i < newend->lineno && editbot->lineno < newend->lineno)
|
2000-07-29 04:33:38 +00:00
|
|
|
edit_update(fileptr, CENTER);
|
2002-07-19 01:08:59 +00:00
|
|
|
else
|
2001-10-22 03:15:31 +00:00
|
|
|
edit_refresh();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
dump_buffer_reverse();
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
set_modified();
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
return 1;
|
|
|
|
}
|