add parameter use_answer to search_init(); when it's TRUE, only set

backupstring to answer, so that we can preserve the text of the
statusbar when switching to the search prompt from the "Go To Line"
prompt; also, set backupstring before doing anything else, add one minor
efficiency tweak, and preserve the text of the statusbar no matter what
when switching from the search prompt to the "Go To Line" prompt, since
the toggling works both ways now and non-numeric text shouldn't be lost
when going only one of those ways


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1965 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-10-04 22:37:56 +00:00
parent e663dcd6aa
commit d532f197b0
3 changed files with 41 additions and 24 deletions

View File

@ -120,6 +120,16 @@ CVS code -
debugging messages indicating when a flag is set or unset. debugging messages indicating when a flag is set or unset.
(DLR) (DLR)
- search.c: - search.c:
search_init()
- Add parameter use_answer. When it's TRUE, only set
backupstring to answer. This is needed to preserve the text
of the statusbar when switching to the search prompt from
the "Go To Line" prompt. Also, set backupstring before doing
anything else, add one minor efficiency tweak, and preserve
the text of the statusbar no matter what when switching from
the search prompt to the "Go To Line" prompt, since the
toggling works both ways now and non-numeric text shouldn't be
lost when going only one of those ways. (DLR)
findnextstr() findnextstr()
- Take the no_sameline parameter after can_display_wrap and - Take the no_sameline parameter after can_display_wrap and
wholewords, not after all other parameters. (DLR) wholewords, not after all other parameters. (DLR)

View File

@ -402,7 +402,7 @@ void regexp_cleanup(void);
void not_found_msg(const char *str); void not_found_msg(const char *str);
void search_abort(void); void search_abort(void);
void search_init_globals(void); void search_init_globals(void);
int search_init(bool replacing); int search_init(bool replacing, bool use_answer);
bool is_whole_word(int curr_pos, const char *datastr, const char bool is_whole_word(int curr_pos, const char *datastr, const char
*searchword); *searchword);
bool findnextstr(bool can_display_wrap, bool wholeword, bool bool findnextstr(bool can_display_wrap, bool wholeword, bool

View File

@ -109,32 +109,39 @@ void search_init_globals(void)
} }
} }
/* Set up the system variables for a search or replace. Return -1 if /* Set up the system variables for a search or replace. If use_answer
* the search should be canceled (due to Cancel, Go to Line, or a failed * is TRUE, only set backupstring to answer. Return -2 to run opposite
* regcomp()). Return 0 on success, and 1 on rerun calling program. * program (search -> replace, replace -> search), return -1 if the
* Return -2 to run opposite program (search -> replace, replace -> * search should be canceled (due to Cancel, Go to Line, or a failed
* search). * regcomp()), return 0 on success, and return 1 on rerun calling
* program.
* *
* replacing is TRUE if we call from do_replace(), FALSE if called from * replacing is TRUE if we call from do_replace(), and FALSE if called
* do_search(). */ * from do_search(). */
int search_init(bool replacing) int search_init(bool replacing, bool use_answer)
{ {
int i = 0; int i = 0;
char *buf; char *buf;
static char *backupstring = NULL; static char *backupstring = NULL;
/* The search string we'll be using. */
/* If backupstring doesn't exist, initialize it to "". */
if (backupstring == NULL)
backupstring = mallocstrcpy(NULL, "");
/* If use_answer is TRUE, set backupstring to answer and get out. */
if (use_answer) {
backupstring = mallocstrcpy(backupstring, answer);
return 0;
}
/* We display the search prompt below. If the user types a partial /* We display the search prompt below. If the user types a partial
* search string and then Replace or a toggle, we will return to * search string and then Replace or a toggle, we will return to
* do_search() or do_replace() and be called again. In that case, * do_search() or do_replace() and be called again. In that case,
* we should put the same search string back up. backupstring holds * we should put the same search string back up. */
* this string. */
search_init_globals(); search_init_globals();
/* If we don't already have a backupstring, set it. */
if (backupstring == NULL)
backupstring = mallocstrcpy(NULL, "");
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = (historytype *)&search_history.next; search_history.current = (historytype *)&search_history.next;
#endif #endif
@ -148,10 +155,8 @@ int search_init(bool replacing)
sprintf(buf, " [%s%s]", disp, sprintf(buf, " [%s%s]", disp,
strlenpt(last_search) > COLS / 3 ? "..." : ""); strlenpt(last_search) > COLS / 3 ? "..." : "");
free(disp); free(disp);
} else { } else
buf = charalloc(1); buf = mallocstrcpy(NULL, "");
buf[0] = '\0';
}
/* This is now one simple call. It just does a lot. */ /* This is now one simple call. It just does a lot. */
i = statusq(FALSE, replacing ? replace_list : whereis_list, i = statusq(FALSE, replacing ? replace_list : whereis_list,
@ -238,9 +243,8 @@ int search_init(bool replacing)
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = search_history.next; search_history.current = search_history.next;
#endif #endif
/* If answer parses as an integer, put it up on the /* Put answer up on the statusbar. */
* statusbar. */ do_gotoline(-1, FALSE);
do_gotoline(parse_num(answer, NULL) ? -1 : 0, FALSE);
/* Fall through. */ /* Fall through. */
default: default:
return -1; return -1;
@ -386,7 +390,7 @@ void do_search(void)
wrap_reset(); wrap_reset();
#endif #endif
i = search_init(FALSE); i = search_init(FALSE, FALSE);
if (i == -1) /* Cancel, Go to Line, blank search string, or if (i == -1) /* Cancel, Go to Line, blank search string, or
* regcomp() failed. */ * regcomp() failed. */
search_abort(); search_abort();
@ -780,7 +784,7 @@ void do_replace(void)
return; return;
} }
i = search_init(TRUE); i = search_init(TRUE, FALSE);
if (i == -1) { /* Cancel, Go to Line, blank search if (i == -1) { /* Cancel, Go to Line, blank search
* string, or regcomp() failed. */ * string, or regcomp() failed. */
replace_abort(); replace_abort();
@ -876,6 +880,9 @@ void do_gotoline(int line, bool save_pos)
} }
if (i == NANO_TOOTHERWHEREIS_KEY) { if (i == NANO_TOOTHERWHEREIS_KEY) {
/* Keep answer up on the statusbar. */
search_init(TRUE, TRUE);
do_search(); do_search();
return; return;
} }