From 0bff4851d97436e4990df07dab15f510c256a677 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 15 Apr 2019 17:22:48 +0200 Subject: [PATCH] Support '-placement menu' switch in the info command Expose insert completion menu documentation via the info command. --- doc/pages/commands.asciidoc | 14 +++++++++-- src/commands.cc | 46 +++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/doc/pages/commands.asciidoc b/doc/pages/commands.asciidoc index 62b80818..0e4d95a3 100644 --- a/doc/pages/commands.asciidoc +++ b/doc/pages/commands.asciidoc @@ -279,8 +279,18 @@ but not really useful in that context. *-anchor* .::: print the text at the given coordinates - *-placement* {above,below}::: - set the placement relative to the anchor + *-placement* ::: + set the placement and style of the message box. + + *menu*:::: + display the info next to the displayed menu, as documentation + for the currently selected entry. + + *above*:::: + display the info above the given anchor + + *below*:::: + display the info below the given anchor *-title* ::: set the title of the message box diff --git a/src/commands.cc b/src/commands.cc index d32b9d2f..82b9175f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -2076,7 +2076,7 @@ const CommandDesc info_cmd = { "info [] : display an info box containing ", ParameterDesc{ { { "anchor", { true, "set info anchoring ." } }, - { "placement", { true, "set placement relative to anchor (above, below)" } }, + { "placement", { true, "set placement style (above, below, menu)" } }, { "title", { true, "set info title" } } }, ParameterDesc::Flags::None, 0, 1 }, @@ -2089,33 +2089,29 @@ const CommandDesc info_cmd = { return; context.client().info_hide(); - if (parser.positional_count() > 0) - { - InfoStyle style = InfoStyle::Prompt; - BufferCoord pos; - if (auto anchor = parser.get_switch("anchor")) - { - auto dot = find(*anchor, '.'); - if (dot == anchor->end()) + if (parser.positional_count() == 0) + return; + + const InfoStyle style = parser.get_switch("placement").map( + [](StringView placement) -> Optional { + if (placement == "above") return InfoStyle::InlineAbove; + if (placement == "below") return InfoStyle::InlineBelow; + if (placement == "menu") return InfoStyle::MenuDoc; + throw runtime_error(format("invalid placement: '{}'", placement)); + }).value_or(parser.get_switch("anchor") ? InfoStyle::Inline : InfoStyle::Prompt); + + const BufferCoord pos = parser.get_switch("anchor").map( + [](StringView anchor) { + auto dot = find(anchor, '.'); + if (dot == anchor.end()) throw runtime_error("expected . for anchor"); - pos = BufferCoord{str_to_int({anchor->begin(), dot})-1, - str_to_int({dot+1, anchor->end()})-1}; - style = InfoStyle::Inline; + return BufferCoord{str_to_int({anchor.begin(), dot})-1, + str_to_int({dot+1, anchor.end()})-1}; + }).value_or(BufferCoord{}); - if (auto placement = parser.get_switch("placement")) - { - if (*placement == "above") - style = InfoStyle::InlineAbove; - else if (*placement == "below") - style = InfoStyle::InlineBelow; - else - throw runtime_error(format("invalid placement: '{}'", *placement)); - } - } - auto title = parser.get_switch("title").value_or(StringView{}); - context.client().info_show(title.str(), parser[0], pos, style); - } + auto title = parser.get_switch("title").value_or(StringView{}); + context.client().info_show(title.str(), parser[0], pos, style); } };