mu/mu4e: implement mu4e-compose-complete-max

Allow limiting number of contacts for auto-completion to a specific number;
defaulting to 2000.
This commit is contained in:
Dirk-Jan C. Binnema
2022-05-06 21:58:51 +03:00
parent ffce3dda21
commit 836bfc9062
5 changed files with 35 additions and 12 deletions

View File

@ -304,7 +304,7 @@ using ContactSet = std::set<std::reference_wrapper<const Contact>,
ContactLessThan>;
void
ContactsCache::for_each(const EachContactFunc& each_contact) const
ContactsCache::for_each(const EachContactFunc& each_contact, size_t max_num) const
{
std::lock_guard<std::mutex> l_{priv_->mtx_};
@ -316,8 +316,13 @@ ContactsCache::for_each(const EachContactFunc& each_contact) const
for (const auto& item : priv_->contacts_)
sorted.emplace(item.second);
for (const auto& ci : sorted)
// sadly, there's no set::resize
size_t n{};
for (const auto& ci : sorted) {
if (max_num > 0 && n++ >= max_num)
break;
each_contact(ci);
}
}
bool

View File

@ -142,9 +142,10 @@ public:
/**
* Invoke some callable for each contact, in order of rank.
*
* @param each_contact
* @param each_contact function invoked for each contact
* @param max_num stop after at most so many contacts, or 0 for no limit
*/
void for_each(const EachContactFunc& each_contact) const;
void for_each(const EachContactFunc& each_contact, size_t max_num=0) const;
private:
struct Private;

View File

@ -228,7 +228,8 @@ Server::Private::make_command_map()
ArgMap{{":personal", ArgInfo{Type::Symbol, false, "only personal contacts"}},
{":after",
ArgInfo{Type::String, false, "only contacts seen after time_t string"}},
{":tstamp", ArgInfo{Type::String, false, "return changes since tstamp"}}},
{":tstamp", ArgInfo{Type::String, false, "return changes since tstamp"}},
{":maxnum", ArgInfo{Type::Number, false, "max number of contacts to return"}}},
"get contact information",
[&](const auto& params) { contacts_handler(params); }});
cmap.emplace(