DB's changes to do_delete(), and a few more minor bits


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1713 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
diff --git a/ChangeLog b/ChangeLog
index 232f58d..67858ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 CVS code -
 - General:
 	- Minor comment cleanups. (DLR)
+	- Convert more ints used as boolean values to use TRUE and
+	  FALSE. (David Benbennick)
 	- Make sure the special control keys are handled the same way
 	  after the window is resized or we come out of suspend mode.
 	  Changes to do_cont() and handle_sigwinch(). (DLR)
@@ -9,14 +11,14 @@
 	- Rearrange the NANO_SMALL #ifdef so that the code to set the
 	  MODIFIED flag in open_files->flags is included only once.
 	  (DLR)
+- nano.c:
+  do_delete()
+	- Tweak for efficiency. (David Benbennick)
 - search.c:
   not_found_msg()
 	- Convert to properly handle strings generated by
 	  display_string() that have been used in the search prompt
 	  since 1.3.0. (David Benbennick)
-  do_replace_loop()
-	- Convert more ints used as boolean values to use TRUE and
-	  FALSE. (David Benbennick)
 - utils.c:
   nstricmp(), nstrnicmp()
 	- Add extra blank lines for greater readability, and remove
diff --git a/src/nano.c b/src/nano.c
index 981912c..4a11b1b 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -943,7 +943,7 @@
 {
     size_t current_len = strlen(current->data);
 #if !defined(DISABLE_WRAPPING) || defined(ENABLE_COLOR)
-    int refresh = 0;
+    int refresh = FALSE;
 	/* Do we have to run edit_refresh(), or can we get away with
 	 * update_line()? */
 #endif
@@ -986,7 +986,7 @@
 
 #ifdef ENABLE_COLOR
     if (ISSET(COLOR_SYNTAX))
-	refresh = 1;
+	refresh = TRUE;
 #endif
 
 #if !defined(DISABLE_WRAPPING) || defined(ENABLE_COLOR)
@@ -1028,38 +1028,41 @@
 
 int do_delete(void)
 {
-    int refresh = 0;
-
-    /* blbf -> blank line before filebot (see below) */
-    int blbf = 0;
-
-    if (current->next == filebot && current->data[0] == '\0')
-	blbf = 1;
+    assert(current != NULL && current->data != NULL && current_x <=
+	strlen(current->data));
 
     placewewant = xplustabs();
 
-    if (current_x != strlen(current->data)) {
-	/* Let's get dangerous */
+    if (current->data[current_x] != '\0') {
+	size_t linelen = strlen(current->data + current_x);
+
+	assert(current_x < strlen(current->data));
+
+	/* Let's get dangerous. */
 	charmove(&current->data[current_x], &current->data[current_x + 1],
-		strlen(current->data) - current_x);
+		linelen);
 
-	align(&current->data);
-#ifdef ENABLE_COLOR
-	if (ISSET(COLOR_SYNTAX))
-	    refresh = 1;
+	null_at(&current->data, linelen + current_x - 1);
+#ifndef NANO_SMALL
+	if (current_x < mark_beginx && mark_beginbuf == current)
+	    mark_beginx--;
 #endif
-    } else if (current->next != NULL && (current->next != filebot || blbf)) {
+    } else if (current != filebot && (current->next != filebot ||
+	current->data[0] == '\0')) {
 	/* We can delete the line before filebot only if it is blank: it
-	   becomes the new magic line then. */
+	 * becomes the new magic line then. */
+	filestruct *foo = current->next;
 
-	filestruct *foo;
-
-	current->data = charealloc(current->data,
-				 strlen(current->data) +
-				 strlen(current->next->data) + 1);
-	strcat(current->data, current->next->data);
-
-	foo = current->next;
+	assert(current_x == strlen(current->data));
+	current->data = charealloc(current->data, current_x +
+		strlen(foo->data) + 1);
+	strcpy(current->data + current_x, foo->data);
+#ifndef NANO_SMALL
+	if (mark_beginbuf == current->next) {
+	    mark_beginx += current_x;
+	    mark_beginbuf = current;
+	}
+#endif
 	if (filebot == foo)
 	    filebot = current;
 
@@ -1067,15 +1070,13 @@
 	delete_node(foo);
 	renumber(current);
 	totlines--;
-	refresh = 1;
+	wrap_reset();
     } else
 	return 0;
 
     totsize--;
     set_modified();
-    update_line(current, current_x);
-    if (refresh)
-	edit_refresh();
+    edit_refresh();
     return 1;
 }