From 612b41615bbee97bfb46045bdbf170616fa6d64f Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sat, 2 Jul 2005 17:56:29 +0000
Subject: [PATCH] clean up the search code a bit

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2809 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    |  7 +++++++
 src/search.c | 22 ++++++++--------------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e7bfc4af..3692779f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,13 @@ CVS code -
 	  cursor position if there are no keys waiting in the buffer.
 	  (DLR)
 - search.c:
+  search_init()
+	- Don't blank out last_replace anymore when we get a new string,
+	  as it'll be blanked out in do_replace().  Also, consolidate
+	  the cases for blank and new search strings, as they now differ
+	  only in which string they pass to regexp_init(). (DLR)
+  replace_abort()
+	- Remove unnecessary update of placewewant. (DLR)
   do_replace()
 	- Blank out last_replace properly again just before displaying
 	  the "Replace" prompt. (DLR, found by Mike Frysinger)
diff --git a/src/search.c b/src/search.c
index 6687975d..fd7acf18 100644
--- a/src/search.c
+++ b/src/search.c
@@ -215,17 +215,14 @@ int search_init(bool replacing, bool use_answer)
 	return -1;
     } else {
 	switch (i) {
-	    case -2:		/* It's the same string. */
+	    case -2:		/* It's an empty string. */
+	    case 0:		/* It's a new string. */
 #ifdef HAVE_REGEX_H
-		/* Since answer is "", use last_search! */
-		if (ISSET(USE_REGEXP) && regexp_init(last_search) == 0)
-		    return -1;
-#endif
-		break;
-	    case 0:		/* They entered something new. */
-		last_replace[0] = '\0';
-#ifdef HAVE_REGEX_H
-		if (ISSET(USE_REGEXP) && regexp_init(answer) == 0)
+		/* Use last_search if answer is an empty string, or
+		 * answer if it isn't. */
+		if (ISSET(USE_REGEXP) &&
+			regexp_init((i == -2) ? last_search :
+			answer) == 0)
 		    return -1;
 #endif
 		break;
@@ -570,11 +567,8 @@ void do_research(void)
 
 void replace_abort(void)
 {
-    /* Identical to search_abort(), so we'll call it here.  If it does
-     * something different later, we can change it back.  For now, it's
-     * just a waste to duplicate code. */
+    /* For now, we do the same thing as search_abort(). */
     search_abort();
-    placewewant = xplustabs();
 }
 
 #ifdef HAVE_REGEX_H
-- 
GitLab