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


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2062 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2004-11-05 15:25:53 +00:00
parent 1539837fe0
commit b73c0c0b09
6 changed files with 45 additions and 15 deletions

View File

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

View File

@ -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
}

View File

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

View File

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

View File

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

View File

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