diff --git a/ChangeLog b/ChangeLog index 45c62eff..5e9b8f25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -128,8 +128,12 @@ CVS code - cursor position at the statusbar is reset. (DLR) - Add missing #ifdefs around the wrap_reset() call so that nano compiles with wrapping disabled again. (DLR) - - When inserting a file in non-multibuffer mode, preserve - placewewant as well as current_x, for consistency. (DLR) + - If we're not inserting a file into a new buffer, partition the + current buffer so that it's effectively a new buffer just + before inserting the file, and only restore placewewant + afterwards. This is the same behavior we would get if we + opened the file, added all of it to the cutbuffer, uncut at + the current cursor position, and closed the file. (DLR) do_writeout() - Restructure if blocks for greater efficiency, using do_insertfile() as a model. (DLR) diff --git a/src/files.c b/src/files.c index 38f6c909..20e6f0d9 100644 --- a/src/files.c +++ b/src/files.c @@ -490,6 +490,7 @@ void do_insertfile( const char *msg; char *ans = mallocstrcpy(NULL, ""); /* The last answer the user typed on the statusbar. */ + filestruct *edittop_save = edittop; #ifndef DISABLE_WRAPPING wrap_reset(); @@ -535,7 +536,6 @@ void do_insertfile( statusbar(_("Cancelled")); break; } else { - size_t old_current_x = current_x; size_t old_pww = placewewant; ans = mallocstrcpy(ans, answer); @@ -575,7 +575,43 @@ void do_insertfile( else { #endif answer = mallocstrassn(answer, real_dir_from_tilde(answer)); + +#ifdef ENABLE_MULTIBUFFER + if (!ISSET(MULTIBUFFER)) { +#endif + /* If we're not inserting into a new buffer, + * partition the filestruct so that it contains no + * text and hence looks like a new buffer, and set + * edittop to the top of the partition. */ + filepart = partition_filestruct(current, current_x, + current, current_x); + edittop = fileage; +#ifdef ENABLE_MULTIBUFFER + } +#endif + load_buffer(answer); + +#ifdef ENABLE_MULTIBUFFER + if (!ISSET(MULTIBUFFER)) +#endif + { + filestruct *top_save = fileage; + + /* If we're not inserting into a new buffer, + * unpartition the filestruct so that it contains + * all the text again. Note that we've replaced the + * non-text originally in the partition with the + * text in the inserted file. */ + unpartition_filestruct(filepart); + + /* Renumber starting with the beginning line of the + * old partition. */ + renumber(top_save); + + /* Set edittop back to what it was before. */ + edittop = edittop_save; + } #ifndef NANO_SMALL } #endif @@ -592,8 +628,7 @@ void do_insertfile( /* Mark the file as modified. */ set_modified(); - /* Restore the old cursor position. */ - current_x = old_current_x; + /* Restore the old place we want. */ placewewant = old_pww; #ifdef ENABLE_MULTIBUFFER } diff --git a/src/global.c b/src/global.c index 8e539da9..9dff642a 100644 --- a/src/global.c +++ b/src/global.c @@ -61,11 +61,8 @@ filestruct *edittop = NULL; /* Pointer to the top of the edit file struct */ filestruct *filebot = NULL; /* Last node in the file struct */ filestruct *cutbuffer = NULL; /* A place to store cut text */ - -#ifndef NANO_SMALL partition *filepart = NULL; /* A place to store a portion of the file struct */ -#endif #ifdef ENABLE_MULTIBUFFER openfilestruct *open_files = NULL; /* The list of open files */ diff --git a/src/nano.c b/src/nano.c index 09c01389..1bd0094a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -615,7 +615,6 @@ void free_filestruct(filestruct *src) } } -#ifndef NANO_SMALL /* Partition a filestruct so it begins at (top, top_x) and ends at (bot, * bot_x). */ partition *partition_filestruct(filestruct *top, size_t top_x, @@ -711,7 +710,6 @@ void unpartition_filestruct(partition *p) free(p); p = NULL; } -#endif void renumber_all(void) { diff --git a/src/nano.h b/src/nano.h index 7a0b1e66..3b422ef1 100644 --- a/src/nano.h +++ b/src/nano.h @@ -206,7 +206,6 @@ typedef struct openfilestruct { } openfilestruct; #endif -#ifndef NANO_SMALL typedef struct partition { filestruct *fileage; filestruct *top_prev; @@ -215,7 +214,6 @@ typedef struct partition { filestruct *bot_next; char *bot_data; } partition; -#endif typedef struct shortcut { /* Key values that aren't used should be set to NANO_NO_KEY. */ diff --git a/src/proto.h b/src/proto.h index dd6e8e60..c3b5fca9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -86,8 +86,8 @@ extern char *alt_speller; extern struct stat fileinfo; extern filestruct *current, *fileage, *edittop, *filebot; extern filestruct *cutbuffer; -#ifndef NANO_SMALL extern partition *filepart; +#ifndef NANO_SMALL extern filestruct *mark_beginbuf; #endif @@ -302,11 +302,9 @@ void unlink_node(const filestruct *fileptr); void delete_node(filestruct *fileptr); filestruct *copy_filestruct(const filestruct *src); void free_filestruct(filestruct *src); -#ifndef NANO_SMALL partition *partition_filestruct(filestruct *top, size_t top_x, filestruct *bot, size_t bot_x); void unpartition_filestruct(partition *p); -#endif void renumber_all(void); void renumber(filestruct *fileptr); void print1opt(const char *shortflag, const char *longflag, const char