From c124c8f517c921bee2017cdf5081f3e8b98e27b9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 28 Jan 2024 11:21:22 +1100 Subject: [PATCH] Support -after switch for flag-lines highlighter --- doc/pages/changelog.asciidoc | 2 ++ src/highlighters.cc | 32 +++++++++++++++++++++++++------- src/main.cc | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 50f8d51ad..a1f0225b0 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -5,6 +5,8 @@ released versions. == Development version +* `flag-lines -after` switch to display text after the line + * `shell-script-candidates` completion now runs the script asynchronously while displaying and updating results live. diff --git a/src/highlighters.cc b/src/highlighters.cc index 7e6bd1c0c..7b268bcb9 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1368,23 +1368,26 @@ const HighlighterDesc flag_lines_desc = { }; struct FlagLinesHighlighter : Highlighter { - FlagLinesHighlighter(String option_name, String default_face) + FlagLinesHighlighter(String option_name, String default_face, bool after) : Highlighter{HighlightPass::Move}, m_option_name{std::move(option_name)}, - m_default_face{std::move(default_face)} {} + m_default_face{std::move(default_face)}, + m_after(after) {} static std::unique_ptr create(HighlighterParameters params, Highlighter*) { - if (params.size() != 2) - throw runtime_error("wrong parameter count"); + ParametersParser parser{params, { + {{"after", {{}, "display at line end" }}}, + ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 2 + }}; - const String& option_name = params[1]; - const String& default_face = params[0]; + const String& default_face = parser[0]; + const String& option_name = parser[1]; // throw if wrong option type GlobalScope::instance().options()[option_name].get(); - return std::make_unique(option_name, default_face); + return std::make_unique(option_name, default_face, (bool)parser.get_switch("after")); } private: @@ -1422,6 +1425,17 @@ private: auto it = find_if(lines, [&](const LineAndSpec& l) { return std::get<0>(l) == line_num; }); + if (m_after) + { + if (it != lines.end()) + { + DisplayLine& display_line = display_lines[it - lines.begin()]; + std::copy(std::make_move_iterator(display_line.begin()), + std::make_move_iterator(display_line.end()), + std::inserter(line, line.end())); + } + continue; + } if (it == lines.end()) line.insert(line.begin(), empty); else @@ -1440,6 +1454,9 @@ private: void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override { + if (m_after) + return; + auto& line_flags = context.context.options()[m_option_name].get_mutable(); const auto& buffer = context.context.buffer(); update_line_specs_ifn(buffer, line_flags); @@ -1461,6 +1478,7 @@ private: String m_option_name; String m_default_face; + bool m_after; }; bool is_empty(const InclusiveBufferRange& range) diff --git a/src/main.cc b/src/main.cc index 4d14565a6..2dd4e3a6b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,6 +46,7 @@ struct { StringView notes; } constexpr version_notes[] = { { 0, + "» {+u}flag-lines -after{} highlighter\n" "» asynchronous {+u}shell-script-candidates{} completion\n" "» {+b}%val\\{window_range}{} is now emitted as separate strings\n" "» {+b}+{} only duplicates identical selections a single time\n"