* src/search.c (do_research): Use 'return' instead of 'else'.
* src/search.c (do_search): Don't bother setting 'answer'; just use
'last_search', which has been set to 'answer' in search_init().
+ * src/search.c (go_looking): Factor out the common part of
+ do_search() and do_research() into this new function.
2016-03-19 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (search_init): Always remember the last typed string,
search_last_line = FALSE;
}
-/* Search for a string. */
+/* Ask what to search for and then go looking for it. */
void do_search(void)
{
- filestruct *fileptr = openfile->current;
- size_t fileptr_x = openfile->current_x;
- size_t pww_save = openfile->placewewant;
- int i;
- bool didfind;
-
- i = search_init(FALSE, FALSE);
+ int i = search_init(FALSE, FALSE);
if (i == -1) /* Cancelled, or some other exit reason. */
search_replace_abort();
do_search();
#endif
- if (i != 0)
- return;
-
- findnextstr_wrap_reset();
- didfind = findnextstr(
-#ifndef DISABLE_SPELLER
- FALSE,
-#endif
- openfile->current, openfile->current_x, last_search, NULL);
-
- /* If we found something, and we're back at the exact same spot where
- * we started searching, then this is the only occurrence. */
- if (didfind && fileptr == openfile->current &&
- fileptr_x == openfile->current_x)
- statusbar(_("This is the only occurrence"));
-
- openfile->placewewant = xplustabs();
- edit_redraw(fileptr, pww_save);
- search_replace_abort();
+ if (i == 0)
+ go_looking();
}
#ifndef NANO_TINY
/* Search for the last string without prompting. */
void do_research(void)
{
- filestruct *fileptr = openfile->current;
- size_t fileptr_x = openfile->current_x;
- size_t pww_save = openfile->placewewant;
- bool didfind;
-
focusing = TRUE;
#ifndef DISABLE_HISTORIES
/* Use the search-menu key bindings, to allow cancelling. */
currmenu = MWHEREIS;
+ go_looking();
+}
+#endif /* !NANO_TINY */
+
+/* Search for the global string 'last_search'. Inform the user when
+ * the string occurs only once. */
+void go_looking(void)
+{
+ filestruct *was_current = openfile->current;
+ size_t was_current_x = openfile->current_x;
+ size_t was_pww = openfile->placewewant;
+ bool didfind;
+
findnextstr_wrap_reset();
didfind = findnextstr(
#ifndef DISABLE_SPELLER
/* If we found something, and we're back at the exact same spot
* where we started searching, then this is the only occurrence. */
- if (didfind && fileptr == openfile->current &&
- fileptr_x == openfile->current_x)
+ if (didfind && openfile->current == was_current &&
+ openfile->current_x == was_current_x)
statusbar(_("This is the only occurrence"));
openfile->placewewant = xplustabs();
- edit_redraw(fileptr, pww_save);
+ edit_redraw(was_current, was_pww);
search_replace_abort();
}
-#endif /* !NANO_TINY */
#ifdef HAVE_REGEX_H
/* Calculate the size of the replacement text, taking possible