aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--complete.cpp24
-rw-r--r--complete.h12
-rw-r--r--expand.cpp2
-rw-r--r--path.cpp1
-rw-r--r--reader.cpp15
5 files changed, 23 insertions, 31 deletions
diff --git a/complete.cpp b/complete.cpp
index 8fbcb1d3..ad2bbb14 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -312,20 +312,6 @@ completion_t &completion_t::operator=(const completion_t &him)
return *this;
}
-bool completion_t::operator < (const completion_t& rhs) const
-{
- return this->completion < rhs.completion;
-}
-
-bool completion_t::operator == (const completion_t& rhs) const
-{
- return this->completion == rhs.completion;
-}
-
-bool completion_t::operator != (const completion_t& rhs) const
-{
- return !(*this == rhs);
-}
wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &list)
{
@@ -338,11 +324,17 @@ wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &li
return strings;
}
-void sort_completions(std::vector<completion_t> &completions)
+bool completion_t::is_alphabetically_less_than(const completion_t &a, const completion_t &b)
+{
+ return a.completion < b.completion;
+}
+
+bool completion_t::is_alphabetically_equal_to(const completion_t &a, const completion_t &b)
{
- std::sort(completions.begin(), completions.end());
+ return a.completion == b.completion;
}
+
/** Class representing an attempt to compute completions */
class completer_t
{
diff --git a/complete.h b/complete.h
index da94bacd..85208d69 100644
--- a/complete.h
+++ b/complete.h
@@ -127,11 +127,10 @@ public:
completion_t(const wcstring &comp, const wcstring &desc = L"", string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), int flags_val = 0);
completion_t(const completion_t &);
completion_t &operator=(const completion_t &);
-
- /* The following are needed for sorting and uniquing completions */
- bool operator < (const completion_t& rhs) const;
- bool operator == (const completion_t& rhs) const;
- bool operator != (const completion_t& rhs) const;
+
+ /* Compare two completions. No operating overlaoding to make this always explicit (there's potentially multiple ways to complare completions). */
+ static bool is_alphabetically_less_than(const completion_t &a, const completion_t &b);
+ static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
};
enum
@@ -146,9 +145,6 @@ typedef uint32_t completion_request_flags_t;
/** Given a list of completions, returns a list of their completion fields */
wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &completions);
-/** Sorts a list of completions */
-void sort_completions(std::vector<completion_t> &completions);
-
/**
Add a completion.
diff --git a/expand.cpp b/expand.cpp
index dc83c385..9dfe5026 100644
--- a/expand.cpp
+++ b/expand.cpp
@@ -1766,7 +1766,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
case 1:
{
res = EXPAND_WILDCARD_MATCH;
- sort_completions(expanded);
+ std::sort(expanded.begin(), expanded.end(), completion_t::is_alphabetically_less_than);
out->insert(out->end(), expanded.begin(), expanded.end());
break;
}
diff --git a/path.cpp b/path.cpp
index 27aadbd3..3a0b9c83 100644
--- a/path.cpp
+++ b/path.cpp
@@ -367,6 +367,7 @@ bool path_get_config(wcstring &path)
return ! result.empty();
}
+__attribute__((unused))
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)
{
size_t needle_len = wcslen(needle);
diff --git a/reader.cpp b/reader.cpp
index 11b45e9d..cd9d9e45 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -802,8 +802,8 @@ bool reader_data_t::expand_abbreviation_as_necessary(size_t cursor_backtrack)
/** Sorts and remove any duplicate completions in the list. */
static void sort_and_make_unique(std::vector<completion_t> &l)
{
- sort(l.begin(), l.end());
- l.erase(std::unique(l.begin(), l.end()), l.end());
+ sort(l.begin(), l.end(), completion_t::is_alphabetically_less_than);
+ l.erase(std::unique(l.begin(), l.end(), completion_t::is_alphabetically_equal_to), l.end());
}
@@ -1642,11 +1642,14 @@ static bool reader_can_replace(const wcstring &in, int flags)
/* Compare two completions, ordering completions with better match types first */
bool compare_completions_by_match_type(const completion_t &a, const completion_t &b)
{
- /* Compare match types */
- int match_compare = a.match.compare(b.match);
- if (match_compare != 0)
+ /* Compare match types, unless both completions are prefix (#923) in which case we always want to compare them alphabetically */
+ if (a.match.type != fuzzy_match_prefix || b.match.type != fuzzy_match_prefix)
{
- return match_compare < 0;
+ int match_compare = a.match.compare(b.match);
+ if (match_compare != 0)
+ {
+ return match_compare < 0;
+ }
}
/* Compare using file comparison */