tweaks: merge two very similar functions into a single one

master
Benno Schulenberg 2019-05-21 12:47:22 +02:00
parent 1128a40d42
commit 20635b40f4
3 changed files with 15 additions and 11 deletions

View File

@ -498,7 +498,7 @@ bool open_buffer(const char *filename, bool new_buffer)
#ifdef ENABLE_SPELLER
/* Open the specified file, and if that succeeds, blow away the text of
* the current buffer and read the file contents into its place. */
void replace_buffer(const char *filename)
void replace_buffer(const char *filename, undo_type action, bool marked)
{
FILE *f;
int descriptor;
@ -516,21 +516,25 @@ void replace_buffer(const char *filename)
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
#endif
/* Throw away the text of the file. */
/* When nothing is marked, start at the top of the buffer. */
if (!marked) {
openfile->current = openfile->filetop;
openfile->current_x = 0;
}
/* Throw away the marked region or the whole buffer. */
cutbuffer = NULL;
openfile->current = openfile->filetop;
openfile->current_x = 0;
#ifndef NANO_TINY
add_undo(CUT_TO_EOF);
add_undo(action);
#endif
do_cut_text(FALSE, FALSE, TRUE, FALSE);
do_cut_text(FALSE, marked, !marked, FALSE);
#ifndef NANO_TINY
update_undo(CUT_TO_EOF);
update_undo(action);
#endif
free_lines(cutbuffer);
cutbuffer = was_cutbuffer;
/* Insert the processed file into its place. */
/* Insert the spell-checked file into the cleared area. */
read_file(f, descriptor, filename, TRUE);
#ifndef NANO_TINY

View File

@ -267,7 +267,7 @@ void make_new_buffer(void);
void set_modified(void);
bool open_buffer(const char *filename, bool new_buffer);
#ifdef ENABLE_SPELLER
void replace_buffer(const char *filename);
void replace_buffer(const char *filename, undo_type action, bool marked);
#ifndef NANO_TINY
void replace_marked_buffer(const char *filename);
#endif

View File

@ -2596,7 +2596,7 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark_x < openfile->current_x));
ssize_t was_mark_lineno = openfile->mark->lineno;
replace_marked_buffer(tempfile_name);
replace_buffer(tempfile_name, CUT, TRUE);
/* Adjust the end point of the marked region for any change in
* length of the region's last line. */
@ -2609,7 +2609,7 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark = fsfromline(was_mark_lineno);
} else
#endif
replace_buffer(tempfile_name);
replace_buffer(tempfile_name, CUT_TO_EOF, FALSE);
/* Go back to the old position. */
goto_line_posx(lineno_save, current_x_save);