From 39e63cf518074564992614c117d9e40a9011c425 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 2 Nov 2017 18:05:18 +0800 Subject: [PATCH] Append '/' to highlighter group completion candidates --- src/commands.cc | 2 +- src/highlighter_group.cc | 6 +++--- src/ranges.hh | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index e4a968f8..e0da8d58 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -633,7 +633,7 @@ const CommandDesc rename_buffer_cmd = { } }; -static constexpr auto highlighter_scopes = { "global", "buffer", "window", "shared" }; +static constexpr auto highlighter_scopes = { "global/", "buffer/", "window/", "shared/" }; template Completions highlighter_cmd_completer( diff --git a/src/highlighter_group.cc b/src/highlighter_group.cc index 9768c160..d8941ea7 100644 --- a/src/highlighter_group.cc +++ b/src/highlighter_group.cc @@ -62,9 +62,9 @@ Completions HighlighterGroup::complete_child(StringView path, ByteCount cursor_p auto candidates = complete( path, cursor_pos, - m_highlighters | filter([=](const HighlighterMap::Item& hl) - { return not group or hl.value->has_children(); }) - | transform(std::mem_fn(&HighlighterMap::Item::key))); + m_highlighters | filter([=](auto& hl) { return not group or hl.value->has_children(); }) + | transform([](auto& hl) { return hl.value->has_children() ? hl.key + "/" : hl.key; }) + | gather>()); return { 0, 0, std::move(candidates) }; } diff --git a/src/ranges.hh b/src/ranges.hh index f1c11be8..fa23f180 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -328,6 +328,15 @@ Init accumulate(Range&& c, Init&& init, BinOp&& op) return std::accumulate(begin(c), end(c), init, op); } +template +auto gather() +{ + return make_view_factory([](auto&& range) { + using std::begin; using std::end; + return Container(begin(range), end(range)); + }); +} + } #endif // ranges_hh_INCLUDED