tweaks: elide another parameter, relevant in just three menus

The parameter was referenced in just one place.  So, simply check for
the three relevant menus (and unrestricted mode) and be done with it.

This also has the pleasant effect that the menu name is now the first
parameter of do_prompt(), thus clearly indicating what prompt it is,
instead of having an opaque TRUE or FALSE value at the beginning.
master
Benno Schulenberg 2020-06-20 17:15:40 +02:00
parent a13b0bc854
commit b086d0bad0
6 changed files with 24 additions and 25 deletions

View File

@ -233,7 +233,7 @@ char *do_browser(char *path)
selected = filelist_len - 1;
} else if (func == goto_dir) {
/* Ask for the directory to go to. */
if (do_prompt(TRUE, MGOTODIR, "", NULL,
if (do_prompt(MGOTODIR, "", NULL,
/* TRANSLATORS: This is a prompt. */
browser_refresh, _("Go To Directory")) < 0) {
statusbar(_("Cancelled"));
@ -639,7 +639,7 @@ int filesearch_init(bool forwards)
thedefault = copy_of("");
/* Now ask what to search for. */
response = do_prompt(FALSE, MWHEREISFILE, "", &search_history,
response = do_prompt(MWHEREISFILE, "", &search_history,
browser_refresh, "%s%s%s", _("Search"),
/* TRANSLATORS: A modifier of the Search prompt. */
!forwards ? _(" [Backwards]") : "", thedefault);

View File

@ -1135,7 +1135,7 @@ void do_insertfile(bool execute)
present_path = mallocstrcpy(present_path, "./");
response = do_prompt(TRUE,
response = do_prompt(
#ifndef NANO_TINY
execute ? MEXECUTE :
#endif
@ -2077,8 +2077,7 @@ int do_writeout(bool exiting, bool withprompt)
else {
/* Ask for (confirmation of) the filename. Disable tab completion
* when in restricted mode. */
response = do_prompt(!ISSET(RESTRICTED),
MWRITEFILE, given, NULL,
response = do_prompt(MWRITEFILE, given, NULL,
edit_refresh, "%s%s%s", msg,
#ifndef NANO_TINY
formatstr, backupstr

View File

@ -403,8 +403,8 @@ void add_or_remove_pipe_symbol_from_answer(void)
#endif
/* Get a string of input at the status-bar prompt. */
functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
bool *listed, linestruct **history_list, void (*refresh_func)(void))
functionptrtype acquire_an_answer(int *actual, bool *listed,
linestruct **history_list, void (*refresh_func)(void))
{
int kbinput = ERR;
bool finished;
@ -469,7 +469,9 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
}
} else
#endif
if (allow_tabbing)
/* Allow tab completion of filenames, but not in restricted mode. */
if ((currmenu == MINSERTFILE || currmenu == MWRITEFILE ||
currmenu == MGOTODIR) && !ISSET(RESTRICTED))
answer = input_tab(answer, &typing_x, &tabbed, refresh_func, listed);
} else
#endif /* ENABLE_TABCOMP */
@ -548,11 +550,10 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
/* Ask a question on the status bar. Return 0 when text was entered,
* -1 for a cancelled entry, -2 for a blank string, and the relevant
* keycode when a valid shortcut key was pressed. The allow_tabbing
* parameter indicates whether tab completion is allowed; 'provided'
* is the default answer for when simply Enter is typed. */
int do_prompt(bool allow_tabbing, int menu, const char *provided,
linestruct **history_list, void (*refresh_func)(void), const char *msg, ...)
* keycode when a valid shortcut key was pressed. The 'provided'
* parameter is the default answer for when simply Enter is typed. */
int do_prompt(int menu, const char *provided, linestruct **history_list,
void (*refresh_func)(void), const char *msg, ...)
{
va_list ap;
int retval;
@ -579,8 +580,7 @@ int do_prompt(bool allow_tabbing, int menu, const char *provided,
lastmessage = VACUUM;
func = acquire_an_answer(&retval, allow_tabbing, &listed,
history_list, refresh_func);
func = acquire_an_answer(&retval, &listed, history_list, refresh_func);
free(prompt);
prompt = saved_prompt;

View File

@ -443,8 +443,8 @@ void inject(char *burst, size_t count);
size_t get_statusbar_page_start(size_t base, size_t column);
void put_cursor_at_end_of_answer(void);
void add_or_remove_pipe_symbol_from_answer(void);
int do_prompt(bool allow_tabbing, int menu, const char *provided,
linestruct **history_list, void (*refresh_func)(void), const char *msg, ...);
int do_prompt(int menu, const char *provided, linestruct **history_list,
void (*refresh_func)(void), const char *msg, ...);
int do_yesno_prompt(bool all, const char *msg);
/* Most functions in rcfile.c. */

View File

@ -93,7 +93,7 @@ void search_init(bool replacing, bool keep_the_answer)
while (TRUE) {
functionptrtype func;
/* Ask the user what to search for (or replace). */
int response = do_prompt(FALSE,
int response = do_prompt(
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
answer, &search_history, edit_refresh,
/* TRANSLATORS: This is the main search prompt. */
@ -710,9 +710,9 @@ void ask_for_and_do_replacements(void)
linestruct *beginline = openfile->current;
size_t begin_x = openfile->current_x;
ssize_t numreplaced;
int response = do_prompt(FALSE, MREPLACEWITH, "",
int response = do_prompt(MREPLACEWITH, "", &replace_history,
/* TRANSLATORS: This is a prompt. */
&replace_history, edit_refresh, _("Replace with"));
edit_refresh, _("Replace with"));
#ifdef ENABLE_HISTORIES
/* When not "", add the replace string to the replace history list. */
@ -762,10 +762,9 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
{
if (interactive) {
/* Ask for the line and column. */
int response = do_prompt(FALSE, MGOTOLINE,
use_answer ? answer : "", NULL, edit_refresh,
int response = do_prompt(MGOTOLINE, use_answer ? answer : "", NULL,
/* TRANSLATORS: This is a prompt. */
_("Enter line number, column number"));
edit_refresh, _("Enter line number, column number"));
/* If the user cancelled or gave a blank answer, get out. */
if (response < 0) {

View File

@ -2110,8 +2110,9 @@ bool fix_spello(const char *word)
put_cursor_at_end_of_answer();
/* Let the user supply a correctly spelled alternative. */
proceed = (do_prompt(FALSE, MSPELL, word, NULL,
edit_refresh, _("Edit a replacement")) != -1);
proceed = (do_prompt(MSPELL, word, NULL, edit_refresh,
/* TRANSLATORS: This is a prompt. */
_("Edit a replacement")) != -1);
spotlighted = FALSE;