tweaks: rename a function, to be more precise, and reshuffle some things

master
Benno Schulenberg 2020-04-07 19:19:26 +02:00
parent b70510f4be
commit 5c3a22dbd6
2 changed files with 19 additions and 25 deletions

View File

@ -478,7 +478,7 @@ void go_looking(void);
ssize_t do_replace_loop(const char *needle, bool whole_word_only, ssize_t do_replace_loop(const char *needle, bool whole_word_only,
const linestruct *real_current, size_t *real_current_x); const linestruct *real_current, size_t *real_current_x);
void do_replace(void); void do_replace(void);
void ask_for_replacement(void); void ask_for_and_do_replacements(void);
void goto_line_posx(ssize_t line, size_t pos_x); void goto_line_posx(ssize_t line, size_t pos_x);
void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
bool interactive); bool interactive);

View File

@ -125,15 +125,13 @@ void search_init(bool replacing, bool keep_the_answer)
#endif #endif
} }
/* When not doing a regular-expression search, just search; if (ISSET(USE_REGEXP) && !regexp_init(last_search))
* otherwise compile the search string, and only search when break;
* the expression is valid. */
if (!ISSET(USE_REGEXP) || regexp_init(last_search)) { if (replacing)
if (replacing) ask_for_and_do_replacements();
ask_for_replacement(); else
else go_looking();
go_looking();
}
break; break;
} }
@ -690,18 +688,20 @@ void do_replace(void)
} }
} }
/* Ask the user what the already given search string should be replaced with. */ /* Ask the user what to replace the search string with, and do the replacements. */
void ask_for_replacement(void) void ask_for_and_do_replacements(void)
{ {
linestruct *edittop_save, *begin; linestruct *was_edittop = openfile->edittop;
size_t firstcolumn_save, begin_x; size_t was_firstcolumn = openfile->firstcolumn;
linestruct *beginline = openfile->current;
size_t begin_x = openfile->current_x;
ssize_t numreplaced; ssize_t numreplaced;
int response = do_prompt(FALSE, FALSE, MREPLACEWITH, "", int response = do_prompt(FALSE, FALSE, MREPLACEWITH, "",
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */
&replace_history, edit_refresh, _("Replace with")); &replace_history, edit_refresh, _("Replace with"));
#ifdef ENABLE_HISTORIES #ifdef ENABLE_HISTORIES
/* If the replace string is not "", add it to the replace history list. */ /* When not "", add the replace string to the replace history list. */
if (response == 0) if (response == 0)
update_history(&replace_history, answer); update_history(&replace_history, answer);
#endif #endif
@ -713,18 +713,12 @@ void ask_for_replacement(void)
} else if (response > 0) } else if (response > 0)
return; return;
/* Save where we are. */ numreplaced = do_replace_loop(last_search, FALSE, beginline, &begin_x);
edittop_save = openfile->edittop;
firstcolumn_save = openfile->firstcolumn;
begin = openfile->current;
begin_x = openfile->current_x;
numreplaced = do_replace_loop(last_search, FALSE, begin, &begin_x);
/* Restore where we were. */ /* Restore where we were. */
openfile->edittop = edittop_save; openfile->edittop = was_edittop;
openfile->firstcolumn = firstcolumn_save; openfile->firstcolumn = was_firstcolumn;
openfile->current = begin; openfile->current = beginline;
openfile->current_x = begin_x; openfile->current_x = begin_x;
refresh_needed = TRUE; refresh_needed = TRUE;