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
/* 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. */

View File

@ -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);

View File

@ -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. */