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.