From a36b726bdecf898d4a390367ef72a0e049c49a87 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 8 Aug 2022 08:56:11 +0200 Subject: [PATCH] completion: search through all open buffers for possible completions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows one to complete also words that are present in other files (when these are open in other buffers). This fulfills https://savannah.gnu.org/bugs/?61691. Requested-by: Tasos Papastylianou Original-patch-by: Marco Diego Aurélio Mesquita --- src/text.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/text.c b/src/text.c index 38041add..2222a5b4 100644 --- a/src/text.c +++ b/src/text.c @@ -3061,12 +3061,14 @@ char *copy_completion(char *text) return word; } -/* Look at the fragment the user has typed, then search the current buffer for +/* Look at the fragment the user has typed, then search all buffers for * the first word that starts with this fragment, and tentatively complete the * fragment. If the user types 'Complete' again, search and paste the next * possible completion. */ void complete_a_word(void) { + static openfilestruct *scouring = NULL; + /* The buffer that is being searched for possible completions. */ char *shard, *completion = NULL; size_t start_of_shard, shard_length = 0; size_t i = 0, j = 0; @@ -3089,6 +3091,7 @@ void complete_a_word(void) openfile->last_action = OTHER; /* Initialize the starting point for searching. */ + scouring = openfile; pletion_line = openfile->filetop; pletion_x = 0; @@ -3200,9 +3203,17 @@ void complete_a_word(void) pletion_line = pletion_line->next; pletion_x = 0; + +#ifdef ENABLE_MULTIBUFFER + /* When at end of buffer and there is another, search that one. */ + if (pletion_line == NULL && scouring->next != openfile) { + scouring = scouring->next; + pletion_line = scouring->filetop; + } +#endif } - /* The search has reached the end of the file. */ + /* The search has gone through all buffers. */ if (list_of_completions != NULL) { edit_refresh(); statusline(AHEM, _("No further matches"));