1
1

Factoring out the common part of do_search() and do_research()

into the new function go_looking().


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5756 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Benno Schulenberg 2016-03-20 16:57:15 +00:00
родитель b8a47f4e37
Коммит f150894d4e
3 изменённых файлов: 23 добавлений и 36 удалений

Просмотреть файл

@ -11,6 +11,8 @@
* src/search.c (do_research): Use 'return' instead of 'else'. * src/search.c (do_research): Use 'return' instead of 'else'.
* src/search.c (do_search): Don't bother setting 'answer'; just use * src/search.c (do_search): Don't bother setting 'answer'; just use
'last_search', which has been set to 'answer' in search_init(). '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> 2016-03-19 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (search_init): Always remember the last typed string, * src/search.c (search_init): Always remember the last typed string,

Просмотреть файл

@ -597,6 +597,7 @@ void do_findnext(void);
#endif #endif
#if !defined(NANO_TINY) || !defined(DISABLE_BROWSER) #if !defined(NANO_TINY) || !defined(DISABLE_BROWSER)
void do_research(void); void do_research(void);
void go_looking(void);
#endif #endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
int replace_regexp(char *string, bool create); int replace_regexp(char *string, bool create);

Просмотреть файл

@ -411,16 +411,10 @@ void findnextstr_wrap_reset(void)
search_last_line = FALSE; search_last_line = FALSE;
} }
/* Search for a string. */ /* Ask what to search for and then go looking for it. */
void do_search(void) void do_search(void)
{ {
filestruct *fileptr = openfile->current; int i = search_init(FALSE, FALSE);
size_t fileptr_x = openfile->current_x;
size_t pww_save = openfile->placewewant;
int i;
bool didfind;
i = search_init(FALSE, FALSE);
if (i == -1) /* Cancelled, or some other exit reason. */ if (i == -1) /* Cancelled, or some other exit reason. */
search_replace_abort(); search_replace_abort();
@ -431,25 +425,8 @@ void do_search(void)
do_search(); do_search();
#endif #endif
if (i != 0) if (i == 0)
return; go_looking();
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();
} }
#ifndef NANO_TINY #ifndef NANO_TINY
@ -481,11 +458,6 @@ void do_findnext(void)
/* Search for the last string without prompting. */ /* Search for the last string without prompting. */
void do_research(void) 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; focusing = TRUE;
#ifndef DISABLE_HISTORIES #ifndef DISABLE_HISTORIES
@ -508,6 +480,19 @@ void do_research(void)
/* Use the search-menu key bindings, to allow cancelling. */ /* Use the search-menu key bindings, to allow cancelling. */
currmenu = MWHEREIS; 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(); findnextstr_wrap_reset();
didfind = findnextstr( didfind = findnextstr(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
@ -517,15 +502,14 @@ void do_research(void)
/* If we found something, and we're back at the exact same spot /* If we found something, and we're back at the exact same spot
* where we started searching, then this is the only occurrence. */ * where we started searching, then this is the only occurrence. */
if (didfind && fileptr == openfile->current && if (didfind && openfile->current == was_current &&
fileptr_x == openfile->current_x) openfile->current_x == was_current_x)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
edit_redraw(fileptr, pww_save); edit_redraw(was_current, was_pww);
search_replace_abort(); search_replace_abort();
} }
#endif /* !NANO_TINY */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Calculate the size of the replacement text, taking possible /* Calculate the size of the replacement text, taking possible