From a847d37b24448361e70b2d2a2a147eb1cba13e8a Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey <pooka109@gmail.com> Date: Fri, 10 Feb 2017 00:17:33 -0600 Subject: [PATCH] tweaks: split the grafting code off from copy_from_buffer() Later on we're going to need the ability to graft a buffer into the current file buffer without making a copy of it first. --- src/nano.c | 16 ++++++++++++---- src/proto.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/nano.c b/src/nano.c index 542348b6..6d3d4dfb 100644 --- a/src/nano.c +++ b/src/nano.c @@ -392,9 +392,9 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot, new_magicline(); } -/* Copy all text from the given filestruct to the current filestruct +/* Meld the given buffer into the current file buffer * at the current cursor position. */ -void copy_from_buffer(filestruct *somebuffer) +void ingraft_buffer(filestruct *somebuffer) { filestruct *top_save; size_t current_x_save = openfile->current_x; @@ -427,8 +427,8 @@ void copy_from_buffer(filestruct *somebuffer) free_filestruct(openfile->fileage); /* Put the top and bottom of the current filestruct at the top and - * bottom of a copy of the passed buffer. */ - openfile->fileage = copy_filestruct(somebuffer); + * bottom of the passed buffer. */ + openfile->fileage = somebuffer; openfile->filebot = openfile->fileage; while (openfile->filebot->next != NULL) openfile->filebot = openfile->filebot->next; @@ -484,6 +484,14 @@ void copy_from_buffer(filestruct *somebuffer) new_magicline(); } +/* Meld a copy of the given buffer into the current file buffer. */ +void copy_from_buffer(filestruct *somebuffer) +{ + filestruct *the_copy = copy_filestruct(somebuffer); + + ingraft_buffer(the_copy); +} + /* Create a new openfilestruct node. */ openfilestruct *make_new_opennode(void) { diff --git a/src/proto.h b/src/proto.h index de899f04..06d278db 100644 --- a/src/proto.h +++ b/src/proto.h @@ -432,6 +432,7 @@ partition *partition_filestruct(filestruct *top, size_t top_x, void unpartition_filestruct(partition **p); void extract_buffer(filestruct **file_top, filestruct **file_bot, filestruct *top, size_t top_x, filestruct *bot, size_t bot_x); +void ingraft_buffer(filestruct *somebuffer); void copy_from_buffer(filestruct *somebuffer); openfilestruct *make_new_opennode(void); void unlink_opennode(openfilestruct *fileptr); -- GitLab