mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-26 13:02:01 +03:00
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.
This commit is contained in:
parent
074666d298
commit
c4db46b58b
@ -3,7 +3,7 @@ The output returned by this command is expected to comply with the following for
|
|||||||
{filename}:{line}:{column}: {kind}: {message}} \
|
{filename}:{line}:{column}: {kind}: {message}} \
|
||||||
str lintcmd
|
str lintcmd
|
||||||
|
|
||||||
decl -hidden line-flags lint_flags
|
decl -hidden line-specs lint_flags
|
||||||
decl -hidden str lint_errors
|
decl -hidden str lint_errors
|
||||||
|
|
||||||
def lint -docstring 'Parse the current buffer with a linter' %{
|
def lint -docstring 'Parse the current buffer with a linter' %{
|
||||||
|
@ -3,7 +3,7 @@ decl -docstring "options to pass to the `clang` shell command" \
|
|||||||
|
|
||||||
decl -hidden str clang_tmp_dir
|
decl -hidden str clang_tmp_dir
|
||||||
decl -hidden completions clang_completions
|
decl -hidden completions clang_completions
|
||||||
decl -hidden line-flags clang_flags
|
decl -hidden line-specs clang_flags
|
||||||
decl -hidden str clang_errors
|
decl -hidden str clang_errors
|
||||||
|
|
||||||
def -params ..1 \
|
def -params ..1 \
|
||||||
|
@ -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 }
|
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-specs git_blame_flags
|
||||||
decl -hidden line-flags git_diff_flags
|
decl -hidden line-specs git_diff_flags
|
||||||
|
|
||||||
face GitBlame default,magenta
|
face GitBlame default,magenta
|
||||||
face GitDiffFlags default,black
|
face GitDiffFlags default,black
|
||||||
|
@ -43,9 +43,9 @@
|
|||||||
namespace Kakoune
|
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>>)
|
StringView option_type_name(Meta::Type<TimestampedList<RangeAndString>>)
|
||||||
@ -1334,7 +1334,7 @@ const CommandDesc declare_option_cmd = {
|
|||||||
" int-list: list of integers\n"
|
" int-list: list of integers\n"
|
||||||
" str-list: list of character strings\n"
|
" str-list: list of character strings\n"
|
||||||
" completions: list of completion candidates\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",
|
" range-specs: list of range specs\n",
|
||||||
ParameterDesc{
|
ParameterDesc{
|
||||||
{ { "hidden", { false, "do not display option name when completing" } },
|
{ { "hidden", { false, "do not display option name when completing" } },
|
||||||
@ -1346,7 +1346,7 @@ const CommandDesc declare_option_cmd = {
|
|||||||
make_completer(
|
make_completer(
|
||||||
[](const Context& context, CompletionFlags flags,
|
[](const Context& context, CompletionFlags flags,
|
||||||
const String& prefix, ByteCount cursor_pos) -> Completions {
|
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) };
|
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
|
||||||
}),
|
}),
|
||||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
[](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);
|
opt = ®.declare_option<Vector<String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
|
||||||
else if (parser[0] == "completions")
|
else if (parser[0] == "completions")
|
||||||
opt = ®.declare_option<CompletionList>(parser[1], docstring, {}, flags);
|
opt = ®.declare_option<CompletionList>(parser[1], docstring, {}, flags);
|
||||||
else if (parser[0] == "line-flags")
|
else if (parser[0] == "line-specs")
|
||||||
opt = ®.declare_option<TimestampedList<LineAndFlag>>(parser[1], docstring, {}, flags);
|
opt = ®.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags);
|
||||||
else if (parser[0] == "range-specs")
|
else if (parser[0] == "range-specs")
|
||||||
opt = ®.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
|
opt = ®.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
|
||||||
else
|
else
|
||||||
|
@ -1184,7 +1184,7 @@ struct FlagLinesHighlighter : Highlighter
|
|||||||
m_option_name{std::move(option_name)},
|
m_option_name{std::move(option_name)},
|
||||||
m_default_face{std::move(default_face)} {}
|
m_default_face{std::move(default_face)} {}
|
||||||
|
|
||||||
using LineAndFlagList = TimestampedList<LineAndFlag>;
|
using LineAndSpecList = TimestampedList<LineAndSpec>;
|
||||||
|
|
||||||
static HighlighterAndId create(HighlighterParameters params)
|
static HighlighterAndId create(HighlighterParameters params)
|
||||||
{
|
{
|
||||||
@ -1196,7 +1196,7 @@ struct FlagLinesHighlighter : Highlighter
|
|||||||
get_face(default_face); // validate param
|
get_face(default_face); // validate param
|
||||||
|
|
||||||
// throw if wrong option type
|
// 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) };
|
return {"hlflags_" + params[1], make_unique<FlagLinesHighlighter>(option_name, default_face) };
|
||||||
}
|
}
|
||||||
@ -1205,7 +1205,7 @@ private:
|
|||||||
void do_highlight(const Context& context, HighlightPass,
|
void do_highlight(const Context& context, HighlightPass,
|
||||||
DisplayBuffer& display_buffer, BufferRange) override
|
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();
|
auto& buffer = context.buffer();
|
||||||
update_line_flags_ifn(buffer, line_flags);
|
update_line_flags_ifn(buffer, line_flags);
|
||||||
|
|
||||||
@ -1235,7 +1235,7 @@ private:
|
|||||||
{
|
{
|
||||||
int line_num = (int)line.range().begin.line + 1;
|
int line_num = (int)line.range().begin.line + 1;
|
||||||
auto it = find_if(lines,
|
auto it = find_if(lines,
|
||||||
[&](const LineAndFlag& l)
|
[&](const LineAndSpec& l)
|
||||||
{ return std::get<0>(l) == line_num; });
|
{ return std::get<0>(l) == line_num; });
|
||||||
if (it == lines.end())
|
if (it == lines.end())
|
||||||
line.insert(line.begin(), empty);
|
line.insert(line.begin(), empty);
|
||||||
@ -1255,7 +1255,7 @@ private:
|
|||||||
|
|
||||||
void do_compute_display_setup(const Context& context, HighlightPass, DisplaySetup& setup) override
|
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();
|
auto& buffer = context.buffer();
|
||||||
update_line_flags_ifn(buffer, line_flags);
|
update_line_flags_ifn(buffer, line_flags);
|
||||||
|
|
||||||
@ -1274,7 +1274,7 @@ private:
|
|||||||
setup.window_range.column -= width;
|
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())
|
if (line_flags.prefix == buffer.timestamp())
|
||||||
return;
|
return;
|
||||||
@ -1282,7 +1282,7 @@ private:
|
|||||||
auto& lines = line_flags.list;
|
auto& lines = line_flags.list;
|
||||||
|
|
||||||
std::sort(lines.begin(), lines.end(),
|
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); });
|
{ return std::get<0>(lhs) < std::get<0>(rhs); });
|
||||||
|
|
||||||
auto modifs = compute_line_modifications(buffer, line_flags.prefix);
|
auto modifs = compute_line_modifications(buffer, line_flags.prefix);
|
||||||
@ -1968,7 +1968,7 @@ void register_highlighters()
|
|||||||
"flag_lines",
|
"flag_lines",
|
||||||
{ FlagLinesHighlighter::create,
|
{ FlagLinesHighlighter::create,
|
||||||
"Parameters: <face> <option name>\n"
|
"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({
|
registry.insert({
|
||||||
"ranges",
|
"ranges",
|
||||||
{ RangesHighlighter::create,
|
{ RangesHighlighter::create,
|
||||||
|
@ -18,7 +18,7 @@ inline bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRan
|
|||||||
String option_to_string(InclusiveBufferRange range);
|
String option_to_string(InclusiveBufferRange range);
|
||||||
void option_from_string(StringView str, InclusiveBufferRange& opt);
|
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>;
|
using RangeAndString = std::tuple<InclusiveBufferRange, String>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user