speller: make replace_marked_buffer() use the cutting functions directly

master
David Lawrence Ramsey 2018-07-30 15:40:03 -05:00 committed by Benno Schulenberg
parent b5f15cb574
commit bc6787826a
3 changed files with 12 additions and 13 deletions

View File

@ -535,16 +535,14 @@ void replace_buffer(const char *filename)
#ifndef NANO_TINY #ifndef NANO_TINY
/* Open the specified file, and if that succeeds, blow away the text of /* 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. */ * contents into its place. */
void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, void replace_marked_buffer(const char *filename)
filestruct *bot, size_t bot_x)
{ {
FILE *f; FILE *f;
int descriptor; int descriptor;
bool old_no_newlines = ISSET(NO_NEWLINES); bool old_no_newlines = ISSET(NO_NEWLINES);
filestruct *trash_top = NULL; filestruct *was_cutbuffer = cutbuffer;
filestruct *trash_bot = NULL;
descriptor = open_file(filename, FALSE, TRUE, &f); 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. */ /* Don't add a magicline when replacing text in the buffer. */
SET(NO_NEWLINES); SET(NO_NEWLINES);
/* Throw away the text under the mark, and insert the processed file /* Throw away the text under the mark. */
* where the marked text was. */ cutbuffer = NULL;
extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x); do_cut_text(FALSE, TRUE, FALSE);
free_filestruct(trash_top); free_filestruct(cutbuffer);
cutbuffer = was_cutbuffer;
/* Insert the processed file where the marked text was. */
read_file(f, descriptor, filename, FALSE); read_file(f, descriptor, filename, FALSE);
/* Restore the magicline behavior now that we're done fiddling. */ /* Restore the magicline behavior now that we're done fiddling. */

View File

@ -269,8 +269,7 @@ bool open_buffer(const char *filename, bool new_buffer);
#ifdef ENABLE_SPELLER #ifdef ENABLE_SPELLER
void replace_buffer(const char *filename); void replace_buffer(const char *filename);
#ifndef NANO_TINY #ifndef NANO_TINY
void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, void replace_marked_buffer(const char *filename);
filestruct *bot, size_t bot_x);
#endif #endif
#endif #endif
void prepare_for_display(void); void prepare_for_display(void);

View File

@ -2880,9 +2880,8 @@ const char *do_alt_speller(char *tempfile_name)
mark_order((const filestruct **)&top, &top_x, mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up); (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 /* Adjust the end point of the marked region for any change in
* length of the region's last line. */ * length of the region's last line. */