nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 20635b40f4a48c4cca9ba90655d12ab3d6b1c591
parent 1128a40d420290b8ecfb919a9df390add0ede980
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 21 May 2019 12:47:22 +0200

tweaks: merge two very similar functions into a single one

Diffstat:
Msrc/files.c | 20++++++++++++--------
Msrc/proto.h | 2+-
Msrc/text.c | 4++--
3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -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 diff --git a/src/proto.h b/src/proto.h @@ -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 diff --git a/src/text.c b/src/text.c @@ -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);