1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 20:41:49 +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:
Maxime Coste 2017-05-24 15:41:43 +01:00
parent 074666d298
commit c4db46b58b
6 changed files with 19 additions and 19 deletions

View File

@ -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' %{

View File

@ -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 \

View File

@ -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

View File

@ -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 = &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

View File

@ -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,

View File

@ -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>;
}