summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-01-28 11:21:22 +1100
committerMaxime Coste <mawww@kakoune.org>2024-01-30 08:20:13 +1100
commitc124c8f517c921bee2017cdf5081f3e8b98e27b9 (patch)
treef88afffc0d8eaa7886993e1a0977b6f0d9cde252 /src
parent2c944f64152c9c1a897d8deb8873ea594b084572 (diff)
Support -after switch for flag-lines highlighter
Diffstat (limited to 'src')
-rw-r--r--src/highlighters.cc32
-rw-r--r--src/main.cc1
2 files changed, 26 insertions, 7 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 7e6bd1c0..7b268bcb 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<Highlighter> 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<LineAndSpecList>();
- return std::make_unique<FlagLinesHighlighter>(option_name, default_face);
+ return std::make_unique<FlagLinesHighlighter>(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<LineAndSpecList>();
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 4d14565a..2dd4e3a6 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"