From ff11ab6b66c223d3c7bcb04f6efd9f59118390ba Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 20 Jun 2020 18:40:36 +0200 Subject: [PATCH] files: list possible completions after just one instead of two This gives quicker feedback, and spares the user unnecessary beeps and typing. Also, now a beep after a means just one thing: there are NO completions. This fulfills https://savannah.gnu.org/bugs/?58627. --- src/files.c | 10 ++-------- src/prompt.c | 9 +-------- src/prototypes.h | 3 +-- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/files.c b/src/files.c index 9d0a1ca4..e9154a1e 100644 --- a/src/files.c +++ b/src/files.c @@ -2478,8 +2478,7 @@ char **filename_completion(const char *buf, size_t length, size_t *num_matches) /* 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 *lastwastab, - void (*refresh_func)(void), bool *listed) +char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *listed) { size_t num_matches = 0; char **matches = NULL; @@ -2544,9 +2543,6 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, if (num_matches == 1 && (is_dir(mzero) || is_dir(glued))) mzero[common_len++] = '/'; - if (num_matches > 1 && (common_len != *place || !*lastwastab)) - beep(); - /* If the matches have something in common, show that part. */ if (common_len != *place) { buf = charealloc(buf, common_len + 1); @@ -2555,9 +2551,7 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, *place = common_len; } - if (!*lastwastab) - *lastwastab = TRUE; - else if (num_matches > 1) { + if (num_matches > 1) { size_t longest_name = 0, ncols; int row = 0; diff --git a/src/prompt.c b/src/prompt.c index b7ba97b3..f5936834 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -409,10 +409,6 @@ functionptrtype acquire_an_answer(int *actual, bool *listed, int kbinput = ERR; bool finished; functionptrtype func; -#ifdef ENABLE_TABCOMP - bool tabbed = FALSE; - /* Whether we've pressed Tab. */ -#endif #ifdef ENABLE_HISTORIES char *history = NULL; /* The current history string. */ @@ -453,9 +449,6 @@ functionptrtype acquire_an_answer(int *actual, bool *listed, break; #ifdef ENABLE_TABCOMP - if (func != do_tab) - tabbed = FALSE; - if (func == do_tab) { #ifdef ENABLE_HISTORIES if (history_list != NULL) { @@ -472,7 +465,7 @@ functionptrtype acquire_an_answer(int *actual, bool *listed, /* 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); + answer = input_tab(answer, &typing_x, refresh_func, listed); } else #endif /* ENABLE_TABCOMP */ #ifdef ENABLE_HISTORIES diff --git a/src/prototypes.h b/src/prototypes.h index d325340f..6d91adbb 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -320,8 +320,7 @@ char *real_dir_from_tilde(const char *path); int diralphasort(const void *va, const void *vb); #endif #ifdef ENABLE_TABCOMP -char *input_tab(char *buf, size_t *place, bool *lastwastab, - void (*refresh_func)(void), bool *listed); +char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *listed); #endif /* Some functions in global.c. */