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
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)
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();
statusbar(_("Cancelled"));
break;
} else {
- size_t old_current_x = current_x;
size_t old_pww = placewewant;
ans = mallocstrcpy(ans, answer);
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
/* 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
}
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 */
}
}
-#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,
free(p);
p = NULL;
}
-#endif
void renumber_all(void)
{
} openfilestruct;
#endif
-#ifndef NANO_SMALL
typedef struct partition {
filestruct *fileage;
filestruct *top_prev;
filestruct *bot_next;
char *bot_data;
} partition;
-#endif
typedef struct shortcut {
/* Key values that aren't used should be set to NANO_NO_KEY. */
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
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