Skip to content

Commit

Permalink
Rename line-flags option type to line-specs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mawww committed May 24, 2017
1 parent 074666d commit c4db46b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rc/base/lint.kak
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The output returned by this command is expected to comply with the following for
{filename}:{line}:{column}: {kind}: {message}} \
str lintcmd

decl -hidden line-flags lint_flags
decl -hidden line-specs lint_flags
decl -hidden str lint_errors

def lint -docstring 'Parse the current buffer with a linter' %{
Expand Down
2 changes: 1 addition & 1 deletion rc/extra/clang.kak
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ decl -docstring "options to pass to the `clang` shell command" \

decl -hidden str clang_tmp_dir
decl -hidden completions clang_completions
decl -hidden line-flags clang_flags
decl -hidden line-specs clang_flags
decl -hidden str clang_errors

def -params ..1 \
Expand Down
4 changes: 2 additions & 2 deletions rc/extra/git-tools.kak
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ hook -group git-status-highlight global WinSetOption filetype=git-status %{

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

decl -hidden line-flags git_blame_flags
decl -hidden line-flags git_diff_flags
decl -hidden line-specs git_blame_flags
decl -hidden line-specs git_diff_flags

face GitBlame default,magenta
face GitDiffFlags default,black
Expand Down
12 changes: 6 additions & 6 deletions src/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>>)
Expand Down Expand Up @@ -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" } },
Expand All @@ -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&)
Expand Down Expand Up @@ -1375,8 +1375,8 @@ const CommandDesc declare_option_cmd = {
opt = &reg.declare_option<Vector<String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else if (parser[0] == "completions")
opt = &reg.declare_option<CompletionList>(parser[1], docstring, {}, flags);
else if (parser[0] == "line-flags")
opt = &reg.declare_option<TimestampedList<LineAndFlag>>(parser[1], docstring, {}, flags);
else if (parser[0] == "line-specs")
opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags);
else if (parser[0] == "range-specs")
opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
else
Expand Down
16 changes: 8 additions & 8 deletions src/highlighters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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) };
}
Expand All @@ -1205,7 +1205,7 @@ struct FlagLinesHighlighter : Highlighter
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);

Expand Down Expand Up @@ -1235,7 +1235,7 @@ struct FlagLinesHighlighter : Highlighter
{
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);
Expand All @@ -1255,7 +1255,7 @@ struct FlagLinesHighlighter : Highlighter

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);

Expand All @@ -1274,15 +1274,15 @@ struct FlagLinesHighlighter : Highlighter
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;

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);
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/highlighters.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

}
Expand Down

0 comments on commit c4db46b

Please sign in to comment.