commit a847d37b24448361e70b2d2a2a147eb1cba13e8a
parent 1cb945fe8e51b0c935b5d409b323c595983badc2
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 10 Feb 2017 00:17:33 -0600
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.
Diffstat:
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git 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
@@ -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);