Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * cut.c * |
| 4 | * * |
| 5 | * Copyright (C) 1999 Chris Allegretta * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 1, or (at your option) * |
| 9 | * any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 19 | * * |
| 20 | **************************************************************************/ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <stdio.h> |
| 25 | #include "config.h" |
| 26 | #include "proto.h" |
| 27 | #include "nano.h" |
| 28 | |
| 29 | #ifndef NANO_SMALL |
| 30 | #include <libintl.h> |
| 31 | #define _(string) gettext(string) |
| 32 | #else |
| 33 | #define _(string) (string) |
| 34 | #endif |
| 35 | |
| 36 | static int marked_cut; /* Is the cutbuffer from a mark */ |
| 37 | static filestruct *cutbottom = NULL; /* Pointer to end of cutbuffer */ |
| 38 | |
| 39 | void add_to_cutbuffer(filestruct * inptr) |
| 40 | { |
| 41 | filestruct *tmp; |
| 42 | |
| 43 | #ifdef DEBUG |
| 44 | fprintf(stderr, _("add_to_cutbuffer called with inptr->data = %s\n"), |
| 45 | inptr->data); |
| 46 | #endif |
| 47 | |
Robert Siemborski | ea19c73 | 2000-06-09 00:52:26 +0000 | [diff] [blame] | 48 | totsize -= strlen(inptr->data); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 49 | tmp = cutbuffer; |
| 50 | if (cutbuffer == NULL) { |
| 51 | cutbuffer = inptr; |
| 52 | inptr->prev = NULL; |
| 53 | } else { |
| 54 | cutbottom->next = inptr; |
| 55 | inptr->prev = cutbottom; |
| 56 | } |
| 57 | |
| 58 | inptr->next = NULL; |
| 59 | cutbottom = inptr; |
| 60 | } |
| 61 | |
| 62 | #ifndef NANO_SMALL |
| 63 | void cut_marked_segment(filestruct * top, int top_x, filestruct * bot, |
| 64 | int bot_x) |
| 65 | { |
| 66 | filestruct *tmp, *next; |
| 67 | char *tmpstr; |
| 68 | |
| 69 | /* Set up the beginning of the cutbuffer */ |
| 70 | tmp = copy_node(top); |
| 71 | tmpstr = nmalloc(strlen(&top->data[top_x]) + 1); |
| 72 | strcpy(tmpstr, &top->data[top_x]); |
| 73 | free(tmp->data); |
| 74 | tmp->data = tmpstr; |
| 75 | |
| 76 | /* Chop off the end of the first line */ |
| 77 | tmpstr = nmalloc(top_x + 1); |
| 78 | strncpy(tmpstr, top->data, top_x); |
| 79 | free(top->data); |
| 80 | top->data = tmpstr; |
| 81 | |
| 82 | do { |
| 83 | next = tmp->next; |
| 84 | add_to_cutbuffer(tmp); |
| 85 | totlines--; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 86 | totsize--; /* newline (add_to_cutbuffer doesn't count newlines) */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 87 | tmp = next; |
| 88 | } |
| 89 | while (next != bot && next != NULL); |
| 90 | |
| 91 | dump_buffer(cutbuffer); |
| 92 | if (next == NULL) |
| 93 | return; |
| 94 | /* Now, paste bot[bot_x] into top[top_x] */ |
| 95 | tmpstr = nmalloc(strlen(top->data) + strlen(&bot->data[bot_x])); |
| 96 | strncpy(tmpstr, top->data, top_x); |
| 97 | strcpy(&tmpstr[top_x], &bot->data[bot_x]); |
| 98 | free(top->data); |
| 99 | top->data = tmpstr; |
| 100 | |
Chris Allegretta | 6925bbd | 2000-07-28 01:41:29 +0000 | [diff] [blame] | 101 | null_at(bot->data, bot_x); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 102 | next = bot->next; |
| 103 | |
| 104 | /* We explicitly don't decrement totlines here because we don't snarf |
Robert Siemborski | ea19c73 | 2000-06-09 00:52:26 +0000 | [diff] [blame] | 105 | * up a newline when we're grabbing the last line of the mark. For |
| 106 | * the same reason we don't do an extra totsize decrement */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 107 | |
| 108 | add_to_cutbuffer(bot); |
| 109 | top->next = next; |
| 110 | if (next != NULL) |
| 111 | next->prev = top; |
| 112 | |
| 113 | dump_buffer(cutbuffer); |
| 114 | renumber(top); |
| 115 | current = top; |
| 116 | current_x = top_x; |
| 117 | |
| 118 | /* If we're hitting the end of the buffer we should clean that up. */ |
| 119 | if (bot == filebot) { |
| 120 | if (next != NULL) { |
| 121 | filebot = next; |
| 122 | } else { |
| 123 | filebot = top; |
| 124 | } |
| 125 | } |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 126 | if (top->lineno < edittop->lineno) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 127 | edit_update(top, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 128 | } |
| 129 | #endif |
| 130 | |
| 131 | int do_cut_text(void) |
| 132 | { |
| 133 | filestruct *tmp, *fileptr = current; |
| 134 | #ifndef NANO_SMALL |
| 135 | char *tmpstr; |
Chris Allegretta | 45dfda9 | 2000-07-25 03:20:07 +0000 | [diff] [blame] | 136 | int newsize, cuttingtoend = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
Chris Allegretta | c86f714 | 2000-08-07 14:39:32 +0000 | [diff] [blame] | 139 | check_statblank(); |
Chris Allegretta | 0286ba4 | 2000-08-07 14:58:26 +0000 | [diff] [blame] | 140 | if (fileptr == NULL || fileptr->data == NULL) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 141 | return 0; |
| 142 | |
| 143 | tmp = fileptr->next; |
| 144 | |
Chris Allegretta | 63aa0f7 | 2000-07-27 04:09:23 +0000 | [diff] [blame] | 145 | if (!ISSET(KEEP_CUTBUFFER)) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 146 | free_filestruct(cutbuffer); |
| 147 | cutbuffer = NULL; |
Chris Allegretta | 63aa0f7 | 2000-07-27 04:09:23 +0000 | [diff] [blame] | 148 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 149 | #ifdef DEBUG |
| 150 | fprintf(stderr, _("Blew away cutbuffer =)\n")); |
| 151 | #endif |
| 152 | } |
Chris Allegretta | 0286ba4 | 2000-08-07 14:58:26 +0000 | [diff] [blame] | 153 | |
| 154 | /* Must let cutbuffer get blown away first before we do this... */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 155 | if (fileptr == filebot && !ISSET(MARK_ISSET)) |
Chris Allegretta | 0286ba4 | 2000-08-07 14:58:26 +0000 | [diff] [blame] | 156 | return 0; |
| 157 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 158 | #ifndef NANO_SMALL |
Chris Allegretta | f4e75e1 | 2000-07-24 18:28:30 +0000 | [diff] [blame] | 159 | if (ISSET(CUT_TO_END) && !ISSET(MARK_ISSET)) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 160 | if (current_x == strlen(current->data)) { |
Chris Allegretta | 45dfda9 | 2000-07-25 03:20:07 +0000 | [diff] [blame] | 161 | do_delete(); |
Chris Allegretta | 63aa0f7 | 2000-07-27 04:09:23 +0000 | [diff] [blame] | 162 | SET(KEEP_CUTBUFFER); |
Chris Allegretta | 1013e14 | 2000-07-27 04:31:52 +0000 | [diff] [blame] | 163 | marked_cut = 2; |
Chris Allegretta | 45dfda9 | 2000-07-25 03:20:07 +0000 | [diff] [blame] | 164 | return 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 165 | } else { |
Chris Allegretta | 45dfda9 | 2000-07-25 03:20:07 +0000 | [diff] [blame] | 166 | SET(MARK_ISSET); |
| 167 | SET(KEEP_CUTBUFFER); |
| 168 | |
| 169 | mark_beginx = strlen(current->data); |
| 170 | mark_beginbuf = current; |
| 171 | cuttingtoend = 1; |
| 172 | } |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 173 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 174 | if (ISSET(MARK_ISSET)) { |
| 175 | if (current->lineno == mark_beginbuf->lineno) { |
| 176 | tmp = copy_node(current); |
Chris Allegretta | 09f39cb | 2001-02-05 13:43:23 +0000 | [diff] [blame] | 177 | newsize = abs(mark_beginx - current_x) + 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 178 | |
Chris Allegretta | 09f39cb | 2001-02-05 13:43:23 +0000 | [diff] [blame] | 179 | tmpstr = nmalloc(newsize + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 180 | if (current_x < mark_beginx) { |
| 181 | strncpy(tmpstr, ¤t->data[current_x], newsize); |
| 182 | memmove(¤t->data[current_x], |
| 183 | ¤t->data[mark_beginx], |
Chris Allegretta | 09f39cb | 2001-02-05 13:43:23 +0000 | [diff] [blame] | 184 | strlen(¤t->data[mark_beginx]) + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 185 | } else { |
| 186 | strncpy(tmpstr, ¤t->data[mark_beginx], newsize); |
| 187 | memmove(¤t->data[mark_beginx], |
| 188 | ¤t->data[current_x], |
Chris Allegretta | 09f39cb | 2001-02-05 13:43:23 +0000 | [diff] [blame] | 189 | strlen(¤t->data[current_x]) + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 190 | current_x = mark_beginx; |
| 191 | update_cursor(); |
| 192 | } |
Chris Allegretta | 09f39cb | 2001-02-05 13:43:23 +0000 | [diff] [blame] | 193 | tmpstr[newsize - 1] = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 194 | tmp->data = tmpstr; |
| 195 | add_to_cutbuffer(tmp); |
| 196 | dump_buffer(cutbuffer); |
| 197 | align(¤t->data); |
| 198 | } else if (current->lineno < mark_beginbuf->lineno) |
| 199 | cut_marked_segment(current, current_x, mark_beginbuf, |
| 200 | mark_beginx); |
| 201 | else |
| 202 | cut_marked_segment(mark_beginbuf, mark_beginx, current, |
| 203 | current_x); |
| 204 | |
| 205 | placewewant = xplustabs(); |
| 206 | UNSET(MARK_ISSET); |
Chris Allegretta | 63aa0f7 | 2000-07-27 04:09:23 +0000 | [diff] [blame] | 207 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 208 | marked_cut = 1; |
| 209 | set_modified(); |
Chris Allegretta | 45dfda9 | 2000-07-25 03:20:07 +0000 | [diff] [blame] | 210 | if (cuttingtoend) |
| 211 | edit_refresh(); |
| 212 | else |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 213 | edit_update(current, CENTER); |
Chris Allegretta | 1013e14 | 2000-07-27 04:31:52 +0000 | [diff] [blame] | 214 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 215 | return 1; |
| 216 | #else |
| 217 | if (0) { |
| 218 | #endif |
| 219 | } else if (fileptr == fileage) { |
| 220 | /* we're cutting the first line */ |
| 221 | if (fileptr->next != NULL) { |
| 222 | fileptr = fileptr->next; |
| 223 | tmp = fileptr; |
| 224 | fileage = fileptr; |
| 225 | add_to_cutbuffer(fileptr->prev); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 226 | totsize--; /* get the newline */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 227 | totlines--; |
| 228 | fileptr->prev = NULL; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 229 | current = fileptr; |
Chris Allegretta | 7dc14e8 | 2000-08-05 16:03:19 +0000 | [diff] [blame] | 230 | edit_update(fileage, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 231 | } else { |
| 232 | add_to_cutbuffer(fileptr); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 233 | fileage = make_new_node(NULL); |
| 234 | fileage->data = nmalloc(1); |
Robert Siemborski | ea19c73 | 2000-06-09 00:52:26 +0000 | [diff] [blame] | 235 | fileage->data[0] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 236 | current = fileage; |
| 237 | } |
| 238 | } else { |
| 239 | if (fileptr->prev != NULL) |
| 240 | fileptr->prev->next = fileptr->next; |
| 241 | |
| 242 | if (fileptr->next != NULL) { |
| 243 | (fileptr->next)->prev = fileptr->prev; |
| 244 | current = fileptr->next; |
| 245 | totlines--; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 246 | totsize--; /* get the newline */ |
| 247 | } |
| 248 | /* No longer an else here, because we never get here anymore... |
| 249 | No need to cut the magic line, as it's empty */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 250 | add_to_cutbuffer(fileptr); |
| 251 | } |
| 252 | |
| 253 | if (fileptr == edittop) |
| 254 | edittop = current; |
| 255 | |
| 256 | edit_refresh(); |
| 257 | |
| 258 | dump_buffer(cutbuffer); |
| 259 | reset_cursor(); |
| 260 | |
| 261 | set_modified(); |
| 262 | marked_cut = 0; |
| 263 | current_x = 0; |
| 264 | placewewant = 0; |
| 265 | update_cursor(); |
| 266 | renumber(tmp); |
| 267 | SET(KEEP_CUTBUFFER); |
| 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | int do_uncut_text(void) |
| 272 | { |
Chris Allegretta | 3bc8c72 | 2000-12-10 17:03:25 +0000 | [diff] [blame] | 273 | filestruct *tmp = current, *fileptr = current, *newbuf, *newend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 274 | #ifndef NANO_SMALL |
| 275 | char *tmpstr, *tmpstr2; |
Chris Allegretta | 3bc8c72 | 2000-12-10 17:03:25 +0000 | [diff] [blame] | 276 | filestruct *hold = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 277 | #endif |
| 278 | int i; |
| 279 | |
| 280 | wrap_reset(); |
Chris Allegretta | c86f714 | 2000-08-07 14:39:32 +0000 | [diff] [blame] | 281 | check_statblank(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 282 | if (cutbuffer == NULL || fileptr == NULL) |
| 283 | return 0; /* AIEEEEEEEEEEEE */ |
| 284 | |
| 285 | newbuf = copy_filestruct(cutbuffer); |
| 286 | for (newend = newbuf; newend->next != NULL && newend != NULL; |
| 287 | newend = newend->next) { |
| 288 | totlines++; |
| 289 | } |
| 290 | |
| 291 | /* Hook newbuf into fileptr */ |
| 292 | #ifndef NANO_SMALL |
Chris Allegretta | 1013e14 | 2000-07-27 04:31:52 +0000 | [diff] [blame] | 293 | if (marked_cut) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 294 | /* If there's only one line in the cutbuffer */ |
| 295 | if (cutbuffer->next == NULL) { |
| 296 | tmpstr = |
| 297 | nmalloc(strlen(current->data) + strlen(cutbuffer->data) + |
| 298 | 1); |
| 299 | strncpy(tmpstr, current->data, current_x); |
| 300 | strcpy(&tmpstr[current_x], cutbuffer->data); |
| 301 | strcat(tmpstr, ¤t->data[current_x]); |
| 302 | free(current->data); |
| 303 | current->data = tmpstr; |
| 304 | current_x += strlen(cutbuffer->data); |
| 305 | totsize += strlen(cutbuffer->data); |
| 306 | |
| 307 | placewewant = xplustabs(); |
| 308 | update_cursor(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 309 | } else { /* yuck -- no kidding! */ |
| 310 | tmp = current->next; |
| 311 | /* New beginning */ |
| 312 | tmpstr = nmalloc(current_x + strlen(newbuf->data) + 1); |
| 313 | strncpy(tmpstr, current->data, current_x); |
| 314 | strcpy(&tmpstr[current_x], newbuf->data); |
| 315 | totsize += strlen(newbuf->data) + strlen(newend->data) + 1; |
| 316 | |
| 317 | /* New end */ |
| 318 | tmpstr2 = nmalloc(strlen(newend->data) + |
| 319 | strlen(¤t->data[current_x]) + 1); |
| 320 | strcpy(tmpstr2, newend->data); |
| 321 | strcat(tmpstr2, ¤t->data[current_x]); |
| 322 | |
| 323 | free(current->data); |
| 324 | current->data = tmpstr; |
| 325 | current->next = newbuf->next; |
| 326 | newbuf->next->prev = current; |
| 327 | delete_node(newbuf); |
| 328 | |
| 329 | current_x = strlen(newend->data); |
| 330 | placewewant = xplustabs(); |
| 331 | free(newend->data); |
| 332 | newend->data = tmpstr2; |
| 333 | |
| 334 | newend->next = tmp; |
| 335 | |
| 336 | /* If tmp isn't null, we're in the middle: update the |
| 337 | * prev pointer. If it IS null, we're at the end, update |
| 338 | * the filebot pointer */ |
| 339 | |
| 340 | if (tmp != NULL) |
| 341 | tmp->prev = newend; |
Chris Allegretta | 5146fec | 2000-12-10 05:44:02 +0000 | [diff] [blame] | 342 | else { |
| 343 | /* Fix the editbot pointer too */ |
| 344 | if (editbot == filebot) |
| 345 | editbot = newend; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 346 | filebot = newend; |
Chris Allegretta | e51c95f | 2000-12-10 05:54:27 +0000 | [diff] [blame] | 347 | new_magicline(); |
Chris Allegretta | 5146fec | 2000-12-10 05:44:02 +0000 | [diff] [blame] | 348 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 349 | |
| 350 | /* Now why don't we update the totsize also */ |
| 351 | for (tmp = current->next; tmp != newend; tmp = tmp->next) |
| 352 | totsize += strlen(tmp->data) + 1; |
| 353 | |
| 354 | i = editbot->lineno; |
| 355 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 356 | current = newend; |
| 357 | if (i <= newend->lineno) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 358 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Chris Allegretta | 293849e | 2000-07-27 05:09:22 +0000 | [diff] [blame] | 361 | /* If marked cut == 2, that means that we're doing a cut to end |
| 362 | and we don't want anything else on the line, so we have to |
| 363 | screw up all the work we just did and separate the line. There |
| 364 | must be a better way to do this, but not at 1AM on a work night. */ |
| 365 | |
| 366 | if (marked_cut == 2 && current_x != strlen(current->data)) { |
| 367 | tmp = make_new_node(current); |
Chris Allegretta | 939fdbd | 2000-07-27 13:03:31 +0000 | [diff] [blame] | 368 | tmp->data = nmalloc(strlen(¤t->data[current_x]) + 1); |
Chris Allegretta | 293849e | 2000-07-27 05:09:22 +0000 | [diff] [blame] | 369 | strcpy(tmp->data, ¤t->data[current_x]); |
Chris Allegretta | 7975ed8 | 2000-07-28 00:58:35 +0000 | [diff] [blame] | 370 | splice_node(current, tmp, current->next); |
Chris Allegretta | 6925bbd | 2000-07-28 01:41:29 +0000 | [diff] [blame] | 371 | null_at(current->data, current_x); |
Chris Allegretta | 939fdbd | 2000-07-27 13:03:31 +0000 | [diff] [blame] | 372 | current = current->next; |
| 373 | current_x = 0; |
| 374 | placewewant = 0; |
Chris Allegretta | 293849e | 2000-07-27 05:09:22 +0000 | [diff] [blame] | 375 | } |
Chris Allegretta | 5146fec | 2000-12-10 05:44:02 +0000 | [diff] [blame] | 376 | /* Renumber from BEFORE where we pasted ;) */ |
| 377 | renumber(hold); |
| 378 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 379 | dump_buffer(fileage); |
| 380 | dump_buffer(cutbuffer); |
| 381 | set_modified(); |
| 382 | edit_refresh(); |
| 383 | return 0; |
| 384 | #else |
| 385 | if (0) { |
| 386 | #endif |
| 387 | } else if (fileptr != fileage) { |
| 388 | tmp = fileptr->prev; |
| 389 | tmp->next = newbuf; |
| 390 | newbuf->prev = tmp; |
| 391 | totlines++; /* Unmarked uncuts don't split lines */ |
| 392 | } else { |
| 393 | fileage = newbuf; |
| 394 | totlines++; /* Unmarked uncuts don't split lines */ |
| 395 | } |
| 396 | |
| 397 | /* This is so uncutting at the top of the buffer will work => */ |
| 398 | if (current_y == 0) |
| 399 | edittop = newbuf; |
| 400 | |
| 401 | /* Connect the end of the buffer to the filestruct */ |
| 402 | newend->next = fileptr; |
| 403 | fileptr->prev = newend; |
| 404 | |
| 405 | /* recalculate size *sigh* */ |
| 406 | for (tmp = newbuf; tmp != fileptr; tmp = tmp->next) |
| 407 | totsize += strlen(tmp->data) + 1; |
| 408 | |
| 409 | i = editbot->lineno; |
| 410 | renumber(newbuf); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 411 | if (i < newend->lineno) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 412 | edit_update(fileptr, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 413 | |
| 414 | dump_buffer_reverse(fileptr); |
| 415 | |
| 416 | set_modified(); |
| 417 | UNSET(KEEP_CUTBUFFER); |
| 418 | edit_refresh(); |
| 419 | return 1; |
| 420 | } |