Skip to content

Commit c4db46b

Browse files
committed
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.
1 parent 074666d commit c4db46b

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

rc/base/lint.kak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ The output returned by this command is expected to comply with the following for
33
{filename}:{line}:{column}: {kind}: {message}} \
44
str lintcmd
55

6-
decl -hidden line-flags lint_flags
6+
decl -hidden line-specs lint_flags
77
decl -hidden str lint_errors
88

99
def lint -docstring 'Parse the current buffer with a linter' %{

rc/extra/clang.kak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ decl -docstring "options to pass to the `clang` shell command" \
33

44
decl -hidden str clang_tmp_dir
55
decl -hidden completions clang_completions
6-
decl -hidden line-flags clang_flags
6+
decl -hidden line-specs clang_flags
77
decl -hidden str clang_errors
88

99
def -params ..1 \

rc/extra/git-tools.kak

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ hook -group git-status-highlight global WinSetOption filetype=git-status %{
1717

1818
hook -group git-status-highlight global WinSetOption filetype=(?!git-status).* %{ remove-highlighter git-status-highlight }
1919

20-
decl -hidden line-flags git_blame_flags
21-
decl -hidden line-flags git_diff_flags
20+
decl -hidden line-specs git_blame_flags
21+
decl -hidden line-specs git_diff_flags
2222

2323
face GitBlame default,magenta
2424
face GitDiffFlags default,black

src/commands.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
namespace Kakoune
4444
{
4545

46-
StringView option_type_name(Meta::Type<TimestampedList<LineAndFlag>>)
46+
StringView option_type_name(Meta::Type<TimestampedList<LineAndSpec>>)
4747
{
48-
return "line-flags";
48+
return "line-specs";
4949
}
5050

5151
StringView option_type_name(Meta::Type<TimestampedList<RangeAndString>>)
@@ -1334,7 +1334,7 @@ const CommandDesc declare_option_cmd = {
13341334
" int-list: list of integers\n"
13351335
" str-list: list of character strings\n"
13361336
" completions: list of completion candidates\n"
1337-
" line-flags: list of line flags\n"
1337+
" line-specs: list of line specs\n"
13381338
" range-specs: list of range specs\n",
13391339
ParameterDesc{
13401340
{ { "hidden", { false, "do not display option name when completing" } },
@@ -1346,7 +1346,7 @@ const CommandDesc declare_option_cmd = {
13461346
make_completer(
13471347
[](const Context& context, CompletionFlags flags,
13481348
const String& prefix, ByteCount cursor_pos) -> Completions {
1349-
auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-flags", "range-specs"};
1349+
auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs"};
13501350
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
13511351
}),
13521352
[](const ParametersParser& parser, Context& context, const ShellContext&)
@@ -1375,8 +1375,8 @@ const CommandDesc declare_option_cmd = {
13751375
opt = &reg.declare_option<Vector<String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
13761376
else if (parser[0] == "completions")
13771377
opt = &reg.declare_option<CompletionList>(parser[1], docstring, {}, flags);
1378-
else if (parser[0] == "line-flags")
1379-
opt = &reg.declare_option<TimestampedList<LineAndFlag>>(parser[1], docstring, {}, flags);
1378+
else if (parser[0] == "line-specs")
1379+
opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags);
13801380
else if (parser[0] == "range-specs")
13811381
opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
13821382
else

src/highlighters.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ struct FlagLinesHighlighter : Highlighter
11841184
m_option_name{std::move(option_name)},
11851185
m_default_face{std::move(default_face)} {}
11861186

1187-
using LineAndFlagList = TimestampedList<LineAndFlag>;
1187+
using LineAndSpecList = TimestampedList<LineAndSpec>;
11881188

11891189
static HighlighterAndId create(HighlighterParameters params)
11901190
{
@@ -1196,7 +1196,7 @@ struct FlagLinesHighlighter : Highlighter
11961196
get_face(default_face); // validate param
11971197

11981198
// throw if wrong option type
1199-
GlobalScope::instance().options()[option_name].get<LineAndFlagList>();
1199+
GlobalScope::instance().options()[option_name].get<LineAndSpecList>();
12001200

12011201
return {"hlflags_" + params[1], make_unique<FlagLinesHighlighter>(option_name, default_face) };
12021202
}
@@ -1205,7 +1205,7 @@ struct FlagLinesHighlighter : Highlighter
12051205
void do_highlight(const Context& context, HighlightPass,
12061206
DisplayBuffer& display_buffer, BufferRange) override
12071207
{
1208-
auto& line_flags = context.options()[m_option_name].get_mutable<LineAndFlagList>();
1208+
auto& line_flags = context.options()[m_option_name].get_mutable<LineAndSpecList>();
12091209
auto& buffer = context.buffer();
12101210
update_line_flags_ifn(buffer, line_flags);
12111211

@@ -1235,7 +1235,7 @@ struct FlagLinesHighlighter : Highlighter
12351235
{
12361236
int line_num = (int)line.range().begin.line + 1;
12371237
auto it = find_if(lines,
1238-
[&](const LineAndFlag& l)
1238+
[&](const LineAndSpec& l)
12391239
{ return std::get<0>(l) == line_num; });
12401240
if (it == lines.end())
12411241
line.insert(line.begin(), empty);
@@ -1255,7 +1255,7 @@ struct FlagLinesHighlighter : Highlighter
12551255

12561256
void do_compute_display_setup(const Context& context, HighlightPass, DisplaySetup& setup) override
12571257
{
1258-
auto& line_flags = context.options()[m_option_name].get_mutable<LineAndFlagList>();
1258+
auto& line_flags = context.options()[m_option_name].get_mutable<LineAndSpecList>();
12591259
auto& buffer = context.buffer();
12601260
update_line_flags_ifn(buffer, line_flags);
12611261

@@ -1274,15 +1274,15 @@ struct FlagLinesHighlighter : Highlighter
12741274
setup.window_range.column -= width;
12751275
}
12761276

1277-
void update_line_flags_ifn(const Buffer& buffer, LineAndFlagList& line_flags)
1277+
void update_line_flags_ifn(const Buffer& buffer, LineAndSpecList& line_flags)
12781278
{
12791279
if (line_flags.prefix == buffer.timestamp())
12801280
return;
12811281

12821282
auto& lines = line_flags.list;
12831283

12841284
std::sort(lines.begin(), lines.end(),
1285-
[](const LineAndFlag& lhs, const LineAndFlag& rhs)
1285+
[](const LineAndSpec& lhs, const LineAndSpec& rhs)
12861286
{ return std::get<0>(lhs) < std::get<0>(rhs); });
12871287

12881288
auto modifs = compute_line_modifications(buffer, line_flags.prefix);
@@ -1968,7 +1968,7 @@ void register_highlighters()
19681968
"flag_lines",
19691969
{ FlagLinesHighlighter::create,
19701970
"Parameters: <face> <option name>\n"
1971-
"Display flags specified in the line-flags option <option name> with <face>"} });
1971+
"Display flags specified in the line-spec option <option name> with <face>"} });
19721972
registry.insert({
19731973
"ranges",
19741974
{ RangesHighlighter::create,

src/highlighters.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inline bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRan
1818
String option_to_string(InclusiveBufferRange range);
1919
void option_from_string(StringView str, InclusiveBufferRange& opt);
2020

21-
using LineAndFlag = std::tuple<LineCount, String>;
21+
using LineAndSpec = std::tuple<LineCount, String>;
2222
using RangeAndString = std::tuple<InclusiveBufferRange, String>;
2323

2424
}

0 commit comments

Comments
 (0)