commit 499b926b74cba7f4461be47be9dd8a6e2386c546
parent 61dda8ff62e73f6dd058cf43f2e2ee781c1727ef
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 19 Jun 2020 10:46:45 +0200
tweaks: elide a parameter that is relevant for only one menu (Goto Dir)
Instead of burdening seven other calls of do_prompt() with a useless
parameter, just check for MGOTODIR in the appropriate place. It also
saves having to pass the parameter down through three more functions.
Diffstat:
6 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -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, FALSE, MGOTODIR, "", NULL,
+ if (do_prompt(TRUE, 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, FALSE, MWHEREISFILE, "", &search_history,
+ response = do_prompt(FALSE, MWHEREISFILE, "", &search_history,
browser_refresh, "%s%s%s", _("Search"),
/* TRANSLATORS: A modifier of the Search prompt. */
!forwards ? _(" [Backwards]") : "", thedefault);
diff --git a/src/files.c b/src/files.c
@@ -1135,7 +1135,7 @@ void do_insertfile(bool execute)
present_path = mallocstrcpy(present_path, "./");
- response = do_prompt(TRUE, TRUE,
+ response = do_prompt(TRUE,
#ifndef NANO_TINY
execute ? MEXECUTE :
#endif
@@ -2078,7 +2078,7 @@ int do_writeout(bool exiting, bool withprompt)
/* Ask for (confirmation of) the filename. Disable tab completion
* when using restricted mode and the filename isn't blank. */
response = do_prompt(!ISSET(RESTRICTED) || openfile->filename[0] == '\0',
- TRUE, MWRITEFILE, given, NULL,
+ MWRITEFILE, given, NULL,
edit_refresh, "%s%s%s", msg,
#ifndef NANO_TINY
formatstr, backupstr
@@ -2406,8 +2406,7 @@ char **username_completion(const char *buf, size_t length, size_t *num_matches)
* This code may safely be consumed by a BSD or GPL license. */
/* Try to complete the given fragment in 'buf' to a filename. */
-char **filename_completion(const char *buf, size_t length,
- bool only_folders, size_t *num_matches)
+char **filename_completion(const char *buf, size_t length, size_t *num_matches)
{
char *dirname = copy_of(buf);
char *slash, *filename;
@@ -2463,7 +2462,7 @@ char **filename_completion(const char *buf, size_t length,
continue;
}
#endif
- if (only_folders && !is_dir(fullname)) {
+ if (currmenu == MGOTODIR && !is_dir(fullname)) {
free(fullname);
continue;
}
@@ -2483,8 +2482,8 @@ char **filename_completion(const char *buf, size_t length,
/* Do tab completion. 'place' is the position of the status-bar cursor, and
* 'refresh_func' is the function to be called to refresh the edit window. */
-char *input_tab(char *buf, size_t *place, bool only_folders,
- bool *lastwastab, void (*refresh_func)(void), bool *listed)
+char *input_tab(char *buf, size_t *place, bool *lastwastab,
+ void (*refresh_func)(void), bool *listed)
{
size_t num_matches = 0;
char **matches = NULL;
@@ -2505,7 +2504,7 @@ char *input_tab(char *buf, size_t *place, bool only_folders,
/* If there are no matches yet, try matching against filenames
* in the current directory. */
if (matches == NULL)
- matches = filename_completion(buf, *place, only_folders, &num_matches);
+ matches = filename_completion(buf, *place, &num_matches);
if (num_matches == 0)
beep();
diff --git a/src/prompt.c b/src/prompt.c
@@ -404,8 +404,7 @@ void add_or_remove_pipe_symbol_from_answer(void)
/* Get a string of input at the status-bar prompt. */
functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
- bool allow_files, bool *listed, linestruct **history_list,
- void (*refresh_func)(void))
+ bool *listed, linestruct **history_list, void (*refresh_func)(void))
{
int kbinput = ERR;
bool finished;
@@ -471,8 +470,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabbing,
} else
#endif
if (allow_tabbing)
- answer = input_tab(answer, &typing_x, !allow_files,
- &tabbed, refresh_func, listed);
+ answer = input_tab(answer, &typing_x, &tabbed, refresh_func, listed);
} else
#endif /* ENABLE_TABCOMP */
#ifdef ENABLE_HISTORIES
@@ -550,15 +548,11 @@ 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,
- * and allow_files indicates whether all files (and not just directories)
- * can be tab completed. The 'provided' parameter is the default answer
- * for when simply Enter is typed. */
-int do_prompt(bool allow_tabbing, bool allow_files,
- int menu, const char *provided, linestruct **history_list,
- void (*refresh_func)(void), const char *msg, ...)
+ * 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, ...)
{
va_list ap;
int retval;
@@ -585,7 +579,7 @@ int do_prompt(bool allow_tabbing, bool allow_files,
lastmessage = VACUUM;
- func = acquire_an_answer(&retval, allow_tabbing, allow_files, &listed,
+ func = acquire_an_answer(&retval, allow_tabbing, &listed,
history_list, refresh_func);
free(prompt);
prompt = saved_prompt;
diff --git a/src/proto.h b/src/proto.h
@@ -323,8 +323,8 @@ char *real_dir_from_tilde(const char *buf);
int diralphasort(const void *va, const void *vb);
#endif
#ifdef ENABLE_TABCOMP
-char *input_tab(char *buf, size_t *place, bool only_folders,
- bool *lastwastab, void (*refresh_func)(void), bool *listed);
+char *input_tab(char *buf, size_t *place, bool *lastwastab,
+ void (*refresh_func)(void), bool *listed);
#endif
/* Some functions in global.c. */
@@ -447,9 +447,8 @@ void inject(char *burst, size_t count);
size_t get_statusbar_page_start(size_t start_col, 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_tabs, bool allow_files,
- int menu, const char *curranswer, linestruct **history_list,
- void (*refresh_func)(void), const char *msg, ...);
+int do_prompt(bool allow_tabbing, int menu, const char *curranswer,
+ linestruct **history_list, void (*refresh_func)(void), const char *msg, ...);
int do_yesno_prompt(bool all, const char *msg);
/* Most functions in rcfile.c. */
diff --git a/src/search.c b/src/search.c
@@ -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, FALSE,
+ int response = do_prompt(FALSE,
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
answer, &search_history, edit_refresh,
/* TRANSLATORS: This is the main search prompt. */
@@ -710,7 +710,7 @@ 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, FALSE, MREPLACEWITH, "",
+ int response = do_prompt(FALSE, MREPLACEWITH, "",
/* TRANSLATORS: This is a prompt. */
&replace_history, edit_refresh, _("Replace with"));
@@ -762,7 +762,7 @@ 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, FALSE, MGOTOLINE,
+ int response = do_prompt(FALSE, MGOTOLINE,
use_answer ? answer : "", NULL, edit_refresh,
/* TRANSLATORS: This is a prompt. */
_("Enter line number, column number"));
diff --git a/src/text.c b/src/text.c
@@ -2110,7 +2110,7 @@ bool fix_spello(const char *word)
put_cursor_at_end_of_answer();
/* Let the user supply a correctly spelled alternative. */
- proceed = (do_prompt(FALSE, FALSE, MSPELL, word, NULL,
+ proceed = (do_prompt(FALSE, MSPELL, word, NULL,
edit_refresh, _("Edit a replacement")) != -1);
spotlighted = FALSE;