Penalize files ending in ~ in suggestions

Fixes #985.
This commit is contained in:
Fabian Homborg 2019-05-06 17:07:29 +02:00
parent cc205a134b
commit 5bf21f2928

View file

@ -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<completion_t> *comps) {
std::unordered_set<wcstring> seen;
@ -285,9 +288,11 @@ void completions_sort_and_prioritize(std::vector<completion_t> *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.