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 #ifdef ENABLE_SPELLER
/* 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 and read the file contents into its place. */ * 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; FILE *f;
int descriptor; int descriptor;
@ -516,21 +516,25 @@ void replace_buffer(const char *filename)
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction")); openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
#endif #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; cutbuffer = NULL;
openfile->current = openfile->filetop;
openfile->current_x = 0;
#ifndef NANO_TINY #ifndef NANO_TINY
add_undo(CUT_TO_EOF); add_undo(action);
#endif #endif
do_cut_text(FALSE, FALSE, TRUE, FALSE); do_cut_text(FALSE, marked, !marked, FALSE);
#ifndef NANO_TINY #ifndef NANO_TINY
update_undo(CUT_TO_EOF); update_undo(action);
#endif #endif
free_lines(cutbuffer); free_lines(cutbuffer);
cutbuffer = was_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); read_file(f, descriptor, filename, TRUE);
#ifndef NANO_TINY #ifndef NANO_TINY

View File

@ -267,7 +267,7 @@ void make_new_buffer(void);
void set_modified(void); void set_modified(void);
bool open_buffer(const char *filename, bool new_buffer); 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, undo_type action, bool marked);
#ifndef NANO_TINY #ifndef NANO_TINY
void replace_marked_buffer(const char *filename); void replace_marked_buffer(const char *filename);
#endif #endif

View File

@ -2596,7 +2596,7 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark_x < openfile->current_x)); openfile->mark_x < openfile->current_x));
ssize_t was_mark_lineno = openfile->mark->lineno; 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 /* 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. */
@ -2609,7 +2609,7 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark = fsfromline(was_mark_lineno); openfile->mark = fsfromline(was_mark_lineno);
} else } else
#endif #endif
replace_buffer(tempfile_name); replace_buffer(tempfile_name, CUT_TO_EOF, FALSE);
/* Go back to the old position. */ /* Go back to the old position. */
goto_line_posx(lineno_save, current_x_save); goto_line_posx(lineno_save, current_x_save);