From bc6787826a93abfe2207b8d9c4cf390e9a7e3aa7 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 30 Jul 2018 15:40:03 -0500 Subject: [PATCH] speller: make replace_marked_buffer() use the cutting functions directly --- src/files.c | 19 ++++++++++--------- src/proto.h | 3 +-- src/text.c | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/files.c b/src/files.c index 22e89e82..4fe315df 100644 --- a/src/files.c +++ b/src/files.c @@ -535,16 +535,14 @@ void replace_buffer(const char *filename) #ifndef NANO_TINY /* Open the specified file, and if that succeeds, blow away the text of - * the current buffer at the given coordinates and read the file + * the current buffer covered by the mark and read the file * contents into its place. */ -void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, - filestruct *bot, size_t bot_x) +void replace_marked_buffer(const char *filename) { FILE *f; int descriptor; bool old_no_newlines = ISSET(NO_NEWLINES); - filestruct *trash_top = NULL; - filestruct *trash_bot = NULL; + filestruct *was_cutbuffer = cutbuffer; descriptor = open_file(filename, FALSE, TRUE, &f); @@ -554,10 +552,13 @@ void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, /* Don't add a magicline when replacing text in the buffer. */ SET(NO_NEWLINES); - /* Throw away the text under the mark, and insert the processed file - * where the marked text was. */ - extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x); - free_filestruct(trash_top); + /* Throw away the text under the mark. */ + cutbuffer = NULL; + do_cut_text(FALSE, TRUE, FALSE); + free_filestruct(cutbuffer); + cutbuffer = was_cutbuffer; + + /* Insert the processed file where the marked text was. */ read_file(f, descriptor, filename, FALSE); /* Restore the magicline behavior now that we're done fiddling. */ diff --git a/src/proto.h b/src/proto.h index 6734ce04..d30afa34 100644 --- a/src/proto.h +++ b/src/proto.h @@ -269,8 +269,7 @@ bool open_buffer(const char *filename, bool new_buffer); #ifdef ENABLE_SPELLER void replace_buffer(const char *filename); #ifndef NANO_TINY -void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, - filestruct *bot, size_t bot_x); +void replace_marked_buffer(const char *filename); #endif #endif void prepare_for_display(void); diff --git a/src/text.c b/src/text.c index 99eaa512..9e7ff5ad 100644 --- a/src/text.c +++ b/src/text.c @@ -2880,9 +2880,8 @@ const char *do_alt_speller(char *tempfile_name) mark_order((const filestruct **)&top, &top_x, (const filestruct **)&bot, &bot_x, &right_side_up); - openfile->mark = NULL; - replace_marked_buffer(tempfile_name, top, top_x, bot, bot_x); + replace_marked_buffer(tempfile_name); /* Adjust the end point of the marked region for any change in * length of the region's last line. */