diff --git a/ChangeLog b/ChangeLog index 8df3898d..b2ec89a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ * 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 * src/search.c (search_init): Always remember the last typed string, diff --git a/src/proto.h b/src/proto.h index 8af1bebb..6fc07f93 100644 --- a/src/proto.h +++ b/src/proto.h @@ -597,6 +597,7 @@ void do_findnext(void); #endif #if !defined(NANO_TINY) || !defined(DISABLE_BROWSER) void do_research(void); +void go_looking(void); #endif #ifdef HAVE_REGEX_H int replace_regexp(char *string, bool create); diff --git a/src/search.c b/src/search.c index 32b00e99..8a408a24 100644 --- a/src/search.c +++ b/src/search.c @@ -411,16 +411,10 @@ void findnextstr_wrap_reset(void) 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(); @@ -431,25 +425,8 @@ void do_search(void) 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 @@ -481,11 +458,6 @@ void do_findnext(void) /* 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 @@ -508,6 +480,19 @@ void do_research(void) /* 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 @@ -517,15 +502,14 @@ void do_research(void) /* 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