summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2022-07-28 21:34:31 +1000
committerMaxime Coste <mawww@kakoune.org>2022-07-28 21:34:31 +1000
commite83dbdcd2cbddb30ac63ec503c76b46b80ffe44d (patch)
tree5137a5c9cc99917821ce148baa55f6acfdcb46d3
parent79ff3c29e54387560f956cfdef3c2b7123149791 (diff)
parent3e9ca0e5c38b111bf1a68b62f6f2e44a7d12f6e9 (diff)
Merge remote-tracking branch 'krobelus/embrace-menu-2'
-rw-r--r--rc/windowing/iterm.kak2
-rw-r--r--rc/windowing/kitty.kak2
-rw-r--r--rc/windowing/new-client.kak2
-rw-r--r--rc/windowing/screen.kak2
-rw-r--r--rc/windowing/sway.kak2
-rw-r--r--rc/windowing/tmux.kak2
-rw-r--r--rc/windowing/wayland.kak2
-rw-r--r--rc/windowing/x11.kak2
-rw-r--r--src/command_manager.cc9
-rw-r--r--src/commands.cc58
-rw-r--r--src/highlighter_group.cc3
-rw-r--r--src/highlighters.cc3
12 files changed, 44 insertions, 45 deletions
diff --git a/rc/windowing/iterm.kak b/rc/windowing/iterm.kak
index acc0cae7..3db623b7 100644
--- a/rc/windowing/iterm.kak
+++ b/rc/windowing/iterm.kak
@@ -143,7 +143,7 @@ If no client is passed then the current one is used' \
fi
}
}
-complete-command iterm-focus client
+complete-command -menu iterm-focus client
alias global focus iterm-focus
alias global terminal iterm-terminal-vertical
diff --git a/rc/windowing/kitty.kak b/rc/windowing/kitty.kak
index 1e4880dc..64cc224e 100644
--- a/rc/windowing/kitty.kak
+++ b/rc/windowing/kitty.kak
@@ -72,7 +72,7 @@ If no client is passed then the current one is used' \
fi
}
}
-complete-command kitty-focus client
+complete-command -menu kitty-focus client
alias global terminal kitty-terminal
alias global terminal-tab kitty-terminal-tab
diff --git a/rc/windowing/new-client.kak b/rc/windowing/new-client.kak
index e017344e..214a18e3 100644
--- a/rc/windowing/new-client.kak
+++ b/rc/windowing/new-client.kak
@@ -6,4 +6,4 @@ The optional arguments are passed as commands to the new client' \
terminal kak -c %val{session} -e "%arg{@}"
}
-complete-command new command
+complete-command -menu new command
diff --git a/rc/windowing/screen.kak b/rc/windowing/screen.kak
index 8e4b6ee5..f9050886 100644
--- a/rc/windowing/screen.kak
+++ b/rc/windowing/screen.kak
@@ -72,7 +72,7 @@ If no client is passed then the current one is used' \
fi
}
}
-complete-command screen-focus client
+complete-command -menu screen-focus client
alias global focus screen-focus
alias global terminal screen-terminal-vertical
diff --git a/rc/windowing/sway.kak b/rc/windowing/sway.kak
index dc0c5830..4df12240 100644
--- a/rc/windowing/sway.kak
+++ b/rc/windowing/sway.kak
@@ -43,7 +43,7 @@ If no client is passed, then the current client is used' \
fi
}
}
-complete-command sway-focus client
+complete-command -menu sway-focus client
unalias global focus
alias global focus sway-focus
diff --git a/rc/windowing/tmux.kak b/rc/windowing/tmux.kak
index fe656cc2..f5a8fda3 100644
--- a/rc/windowing/tmux.kak
+++ b/rc/windowing/tmux.kak
@@ -71,7 +71,7 @@ If no client is passed then the current one is used' \
fi
}
}
-complete-command tmux-focus client
+complete-command -menu tmux-focus client
## The default behaviour for the `new` command is to open an horizontal pane in a tmux session
alias global focus tmux-focus
diff --git a/rc/windowing/wayland.kak b/rc/windowing/wayland.kak
index 1f595a33..ea8de71d 100644
--- a/rc/windowing/wayland.kak
+++ b/rc/windowing/wayland.kak
@@ -51,7 +51,7 @@ If no client is passed, then the current client is used' \
%{
fail 'Focusing specific windows in most Wayland window managers is unsupported'
}
-complete-command wayland-focus client
+complete-command -menu wayland-focus client
alias global focus wayland-focus
alias global terminal wayland-terminal
diff --git a/rc/windowing/x11.kak b/rc/windowing/x11.kak
index 4c39f7ba..a6f7da87 100644
--- a/rc/windowing/x11.kak
+++ b/rc/windowing/x11.kak
@@ -63,7 +63,7 @@ If no client is passed, then the current client is used' \
fi
}
}
-complete-command x11-focus client
+complete-command -menu x11-focus client
alias global focus x11-focus
alias global terminal x11-terminal
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 4fea1e79..48d7789e 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -811,9 +811,12 @@ Completions CommandManager::complete(const Context& context,
if (is_switch(token.content))
{
auto switches = Kakoune::complete(token.content.substr(1_byte), pos_in_token,
- command.param_desc.switches |
- transform(&SwitchMap::Item::key));
- return switches.empty() ? Completions{} : Completions{start+1, cursor_pos, std::move(switches)};
+ concatenated(command.param_desc.switches
+ | transform(&SwitchMap::Item::key),
+ ConstArrayView<String>{"-"}));
+ return switches.empty()
+ ? Completions{}
+ : Completions{start+1, cursor_pos, std::move(switches), Completions::Flags::Menu};
}
if (not command.completer)
return Completions{};
diff --git a/src/commands.cc b/src/commands.cc
index 83a7f73d..f07c768b 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -106,7 +106,7 @@ template<typename Completer>
auto add_flags(Completer completer, Completions::Flags completions_flags)
{
return [completer=std::move(completer), completions_flags]
- (const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) {
+ (const Context& context, CompletionFlags flags, StringView prefix, ByteCount cursor_pos) {
Completions res = completer(context, flags, prefix, cursor_pos);
res.flags |= completions_flags;
return res;
@@ -121,7 +121,7 @@ auto menu(Completer completer)
template<bool menu>
auto filename_completer = make_completer(
- [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos)
+ [](const Context& context, CompletionFlags flags, StringView prefix, ByteCount cursor_pos)
{ return Completions{ 0_byte, cursor_pos,
complete_filename(prefix,
context.options()["ignored_files"].get<Regex>(),
@@ -180,7 +180,7 @@ auto make_single_word_completer(Func&& func)
{
return make_completer(
[func = std::move(func)](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos) -> Completions {
+ StringView prefix, ByteCount cursor_pos) -> Completions {
auto candidate = { func(context) };
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, candidate) }; });
}
@@ -193,27 +193,19 @@ const ParameterDesc double_params{ {}, ParameterDesc::Flags::None, 2, 2 };
static constexpr auto scopes = { "global", "buffer", "window" };
static Completions complete_scope(const Context&, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
+ StringView prefix, ByteCount cursor_pos)
{
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, scopes) };
}
static Completions complete_command_name(const Context& context, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
+ StringView prefix, ByteCount cursor_pos)
{
return CommandManager::instance().complete_command_name(
context, prefix.substr(0, cursor_pos));
}
-static Completions complete_alias_name(const Context& context, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
-{
- return { 0_byte, cursor_pos, complete(prefix, cursor_pos,
- context.aliases().flatten_aliases()
- | transform(&HashItem<String, String>::key)) };
-}
-
struct ShellScriptCompleter
{
ShellScriptCompleter(String shell_script,
@@ -896,7 +888,8 @@ Completions highlighter_cmd_completer(
StringView path = params[0];
auto sep_it = find(path, '/');
if (sep_it == path.end())
- return { 0_byte, pos_in_token, complete(path, pos_in_token, highlighter_scopes) };
+ return { 0_byte, pos_in_token, complete(path, pos_in_token, highlighter_scopes),
+ Completions::Flags::Menu };
StringView scope{path.begin(), sep_it};
HighlighterGroup* root = nullptr;
@@ -913,7 +906,8 @@ Completions highlighter_cmd_completer(
else if (add and token_to_complete == 1)
{
StringView name = params[1];
- return { 0_byte, name.length(), complete(name, pos_in_token, HighlighterRegistry::instance() | transform(&HighlighterRegistry::Item::key)) };
+ return { 0_byte, name.length(), complete(name, pos_in_token, HighlighterRegistry::instance() | transform(&HighlighterRegistry::Item::key)),
+ Completions::Flags::Menu };
}
else
return {};
@@ -1064,7 +1058,7 @@ const CommandDesc remove_highlighter_cmd = {
};
static Completions complete_hooks(const Context&, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
+ StringView prefix, ByteCount cursor_pos)
{
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, enum_desc(Meta::Type<Hook>{}) | transform(&EnumDesc<Hook>::name)) };
}
@@ -1089,7 +1083,7 @@ const CommandDesc add_hook_cmd = {
CommandHelper{},
make_completer(complete_scope, complete_hooks, complete_nothing,
[](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos)
+ StringView prefix, ByteCount cursor_pos)
{ return CommandManager::instance().complete(
context, flags, prefix, cursor_pos); }),
[](const ParametersParser& parser, Context& context, const ShellContext&)
@@ -1340,6 +1334,14 @@ const CommandDesc define_command_cmd = {
define_command
};
+static Completions complete_alias_name(const Context& context, CompletionFlags,
+ StringView prefix, ByteCount cursor_pos)
+{
+ return { 0_byte, cursor_pos, complete(prefix, cursor_pos,
+ context.aliases().flatten_aliases()
+ | transform(&HashItem<String, String>::key))};
+}
+
const CommandDesc alias_cmd = {
"alias",
nullptr,
@@ -1358,14 +1360,6 @@ const CommandDesc alias_cmd = {
}
};
-static Completions complete_alias(const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos)
-{
- return {0_byte, cursor_pos,
- complete(prefix, cursor_pos, context.aliases().flatten_aliases() |
- transform([](auto& entry) -> const String& { return entry.key; }))};
-}
-
const CommandDesc unalias_cmd = {
"unalias",
nullptr,
@@ -1374,7 +1368,7 @@ const CommandDesc unalias_cmd = {
ParameterDesc{{}, ParameterDesc::Flags::None, 2, 3},
CommandFlags::None,
CommandHelper{},
- make_completer(complete_scope, complete_alias, complete_command_name),
+ make_completer(complete_scope, complete_alias_name, complete_command_name),
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
AliasRegistry& aliases = get_scope(parser[0], context).aliases();
@@ -1469,7 +1463,7 @@ const CommandDesc debug_cmd = {
CommandHelper{},
make_completer(
[](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos) -> Completions {
+ StringView prefix, ByteCount cursor_pos) -> Completions {
auto c = {"info", "buffers", "options", "memory", "shared-strings",
"profile-hash-maps", "faces", "mappings", "regex", "registers"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
@@ -1787,7 +1781,7 @@ const CommandDesc declare_option_cmd = {
CommandHelper{},
make_completer(
[](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos) -> Completions {
+ StringView prefix, ByteCount cursor_pos) -> Completions {
auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs", "str-to-str-map"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
}),
@@ -2412,7 +2406,7 @@ const CommandDesc try_catch_cmd = {
};
static Completions complete_face(const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos)
+ StringView prefix, ByteCount cursor_pos)
{
return {0_byte, cursor_pos,
complete(prefix, cursor_pos, context.faces().flatten_faces() |
@@ -2506,7 +2500,7 @@ const CommandDesc set_register_cmd = {
CommandHelper{},
make_completer(
[](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos) -> Completions {
+ StringView prefix, ByteCount cursor_pos) -> Completions {
return { 0_byte, cursor_pos,
RegisterManager::instance().complete_register_name(prefix, cursor_pos) };
}),
@@ -2555,7 +2549,7 @@ const CommandDesc change_directory_cmd = {
CommandHelper{},
make_completer(
[](const Context& context, CompletionFlags flags,
- const String& prefix, ByteCount cursor_pos) -> Completions {
+ StringView prefix, ByteCount cursor_pos) -> Completions {
return { 0_byte, cursor_pos,
complete_filename(prefix,
context.options()["ignored_files"].get<Regex>(),
@@ -2702,7 +2696,7 @@ const CommandDesc require_module_cmd = {
CommandFlags::None,
CommandHelper{},
make_completer(
- [](const Context&, CompletionFlags, const String& prefix, ByteCount cursor_pos) {
+ [](const Context&, CompletionFlags, StringView prefix, ByteCount cursor_pos) {
return CommandManager::instance().complete_module_name(prefix.substr(0, cursor_pos));
}),
[](const ParametersParser& parser, Context& context, const ShellContext&)
diff --git a/src/highlighter_group.cc b/src/highlighter_group.cc
index d5d43198..e23b5979 100644
--- a/src/highlighter_group.cc
+++ b/src/highlighter_group.cc
@@ -75,7 +75,8 @@ Completions HighlighterGroup::complete_child(StringView path, ByteCount cursor_p
| transform([](auto& hl) { return hl.value->has_children() ? hl.key + "/" : hl.key; })
| gather<Vector<String>>());
- return { 0, 0, std::move(candidates) };
+ auto completions_flags = group ? Completions::Flags::None : Completions::Flags::Menu;
+ return { 0, 0, std::move(candidates), completions_flags };
}
void Highlighters::highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range)
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 39fd28fd..cfb24f6c 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -2089,7 +2089,8 @@ public:
}
auto container = m_regions | transform(&decltype(m_regions)::Item::key);
- return { 0, 0, complete(path, cursor_pos, container) };
+ auto completions_flags = group ? Completions::Flags::None : Completions::Flags::Menu;
+ return { 0, 0, complete(path, cursor_pos, container), completions_flags };
}
static std::unique_ptr<Highlighter> create(HighlighterParameters params, Highlighter*)