From 5bf21f29283feb363ab23be2e6d101ca7832ae33 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 6 May 2019 17:07:29 +0200 Subject: [PATCH] Penalize files ending in ~ in suggestions Fixes #985. --- src/complete.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index 392425fe1..e6b9e20fe 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -244,6 +244,9 @@ static bool compare_completions_by_duplicate_arguments(const completion_t &a, return ad < bd; } +static bool compare_completions_by_tilde(const completion_t &a, const completion_t &b) { + return a.completion.back() == L'~' < b.completion.back() == L'~'; +} /// Unique the list of completions, without perturbing their order. static void unique_completions_retaining_order(std::vector *comps) { std::unordered_set seen; @@ -285,9 +288,11 @@ void completions_sort_and_prioritize(std::vector *comps, stable_sort(comps->begin(), comps->end(), compare_completions_by_match_type); // Lastly, if this is for an autosuggestion, prefer to avoid completions that duplicate - // arguments. - if (flags & completion_request_t::autosuggestion) + // arguments, and penalize files that end in tilde - they're frequently autosave files from e.g. emacs. + if (flags & completion_request_t::autosuggestion) { stable_sort(comps->begin(), comps->end(), compare_completions_by_duplicate_arguments); + stable_sort(comps->begin(), comps->end(), compare_completions_by_tilde); + } } /// Class representing an attempt to compute completions.