diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-05-24 15:41:43 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-05-24 15:41:43 +0100 |
| commit | c4db46b58b3bd46767284afbfa370d4ef1233d0e (patch) | |
| tree | 81083bbb594971a3dda740e5b5eb571525b5336c /src | |
| parent | 074666d298666e89bd02d8dc74843050f11f0a8a (diff) | |
Rename line-flags option type to line-specs
Generalize this option type, which is a timestamped list of
<line number>|<arbitrary string>. That way this type is not strongly
coupled with the flag-lines highlighter, and can be reused for other
use cases.
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 12 | ||||
| -rw-r--r-- | src/highlighters.cc | 16 | ||||
| -rw-r--r-- | src/highlighters.hh | 2 |
3 files changed, 15 insertions, 15 deletions
diff --git a/src/commands.cc b/src/commands.cc index c32c29de..b11db6a5 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -43,9 +43,9 @@ namespace Kakoune { -StringView option_type_name(Meta::Type<TimestampedList<LineAndFlag>>) +StringView option_type_name(Meta::Type<TimestampedList<LineAndSpec>>) { - return "line-flags"; + return "line-specs"; } StringView option_type_name(Meta::Type<TimestampedList<RangeAndString>>) @@ -1334,7 +1334,7 @@ const CommandDesc declare_option_cmd = { " int-list: list of integers\n" " str-list: list of character strings\n" " completions: list of completion candidates\n" - " line-flags: list of line flags\n" + " line-specs: list of line specs\n" " range-specs: list of range specs\n", ParameterDesc{ { { "hidden", { false, "do not display option name when completing" } }, @@ -1346,7 +1346,7 @@ const CommandDesc declare_option_cmd = { make_completer( [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) -> Completions { - auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-flags", "range-specs"}; + auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs"}; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; }), [](const ParametersParser& parser, Context& context, const ShellContext&) @@ -1375,8 +1375,8 @@ const CommandDesc declare_option_cmd = { opt = ®.declare_option<Vector<String, MemoryDomain::Options>>(parser[1], docstring, {}, flags); else if (parser[0] == "completions") opt = ®.declare_option<CompletionList>(parser[1], docstring, {}, flags); - else if (parser[0] == "line-flags") - opt = ®.declare_option<TimestampedList<LineAndFlag>>(parser[1], docstring, {}, flags); + else if (parser[0] == "line-specs") + opt = ®.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags); else if (parser[0] == "range-specs") opt = ®.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags); else diff --git a/src/highlighters.cc b/src/highlighters.cc index 51758b6b..610ddffd 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1184,7 +1184,7 @@ struct FlagLinesHighlighter : Highlighter m_option_name{std::move(option_name)}, m_default_face{std::move(default_face)} {} - using LineAndFlagList = TimestampedList<LineAndFlag>; + using LineAndSpecList = TimestampedList<LineAndSpec>; static HighlighterAndId create(HighlighterParameters params) { @@ -1196,7 +1196,7 @@ struct FlagLinesHighlighter : Highlighter get_face(default_face); // validate param // throw if wrong option type - GlobalScope::instance().options()[option_name].get<LineAndFlagList>(); + GlobalScope::instance().options()[option_name].get<LineAndSpecList>(); return {"hlflags_" + params[1], make_unique<FlagLinesHighlighter>(option_name, default_face) }; } @@ -1205,7 +1205,7 @@ private: void do_highlight(const Context& context, HighlightPass, DisplayBuffer& display_buffer, BufferRange) override { - auto& line_flags = context.options()[m_option_name].get_mutable<LineAndFlagList>(); + auto& line_flags = context.options()[m_option_name].get_mutable<LineAndSpecList>(); auto& buffer = context.buffer(); update_line_flags_ifn(buffer, line_flags); @@ -1235,7 +1235,7 @@ private: { int line_num = (int)line.range().begin.line + 1; auto it = find_if(lines, - [&](const LineAndFlag& l) + [&](const LineAndSpec& l) { return std::get<0>(l) == line_num; }); if (it == lines.end()) line.insert(line.begin(), empty); @@ -1255,7 +1255,7 @@ private: void do_compute_display_setup(const Context& context, HighlightPass, DisplaySetup& setup) override { - auto& line_flags = context.options()[m_option_name].get_mutable<LineAndFlagList>(); + auto& line_flags = context.options()[m_option_name].get_mutable<LineAndSpecList>(); auto& buffer = context.buffer(); update_line_flags_ifn(buffer, line_flags); @@ -1274,7 +1274,7 @@ private: setup.window_range.column -= width; } - void update_line_flags_ifn(const Buffer& buffer, LineAndFlagList& line_flags) + void update_line_flags_ifn(const Buffer& buffer, LineAndSpecList& line_flags) { if (line_flags.prefix == buffer.timestamp()) return; @@ -1282,7 +1282,7 @@ private: auto& lines = line_flags.list; std::sort(lines.begin(), lines.end(), - [](const LineAndFlag& lhs, const LineAndFlag& rhs) + [](const LineAndSpec& lhs, const LineAndSpec& rhs) { return std::get<0>(lhs) < std::get<0>(rhs); }); auto modifs = compute_line_modifications(buffer, line_flags.prefix); @@ -1968,7 +1968,7 @@ void register_highlighters() "flag_lines", { FlagLinesHighlighter::create, "Parameters: <face> <option name>\n" - "Display flags specified in the line-flags option <option name> with <face>"} }); + "Display flags specified in the line-spec option <option name> with <face>"} }); registry.insert({ "ranges", { RangesHighlighter::create, diff --git a/src/highlighters.hh b/src/highlighters.hh index 2ea3390d..a3f1971d 100644 --- a/src/highlighters.hh +++ b/src/highlighters.hh @@ -18,7 +18,7 @@ inline bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRan String option_to_string(InclusiveBufferRange range); void option_from_string(StringView str, InclusiveBufferRange& opt); -using LineAndFlag = std::tuple<LineCount, String>; +using LineAndSpec = std::tuple<LineCount, String>; using RangeAndString = std::tuple<InclusiveBufferRange, String>; } |
