1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-29 01:24:52 +03:00

Use markup for line-flags instead of a single face

This commit is contained in:
Maxime Coste 2015-12-12 23:16:07 +00:00
parent 8d7e16a8e6
commit b6105fa106
5 changed files with 34 additions and 18 deletions

View File

@ -75,8 +75,8 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe
fi
flags=$(cat ${dir}/stderr | sed -rne "
/^<stdin>:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^<stdin>:([0-9]+):.*/\1|red|█/; p }
/^<stdin>:[0-9]+:([0-9]+:)? warning/ { s/^<stdin>:([0-9]+):.*/\1|yellow|█/; p }
/^<stdin>:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^<stdin>:([0-9]+):.*/\1|{red}█/; p }
/^<stdin>:[0-9]+:([0-9]+:)? warning/ { s/^<stdin>:([0-9]+):.*/\1|{yellow}█/; p }
" | paste -s -d ':')
errors=$(cat ${dir}/stderr | sed -rne "
@ -131,7 +131,7 @@ def -allow-override -hidden clang-show-error-info %{ %sh{
} }
def clang-enable-diagnostics -docstring "Activate automatic diagnostics of the code by clang" %{
addhl flag_lines default clang_flags'
addhl flag_lines default clang_flags
hook window -group clang-diagnostics NormalIdle .* %{ clang-show-error-info }
}

View File

@ -70,12 +70,12 @@ def -params 1.. \
text=substr(sha,1,8) " " dates[sha] " " authors[sha]
gsub(":", "\\:", text)
# gsub("|", "\\|", text)
flag=line "|default|" text
flag=line "|" text
for ( i=1; i < count; i++ ) {
flag=flag ":" line+i "|default|" text
flag=flag ":" line+i "|" text
}
cmd = "kak -p " ENVIRON["kak_session"]
print "set -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{:" flag "}" | cmd
print "set -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{" flag "}" | cmd
close(cmd)
}
/^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ {
@ -108,10 +108,10 @@ def -params 1.. \
}
}
/^\+/ {
flags=flags ":" line "|green|+"
flags=flags ":" line "|{green}+"
line++
}
/^\-/ { flags=flags ":" line "|red|-" }
/^\-/ { flags=flags ":" line "|{red}-" }
END { print "set buffer git_diff_flags ", flags }
'
}

View File

@ -944,22 +944,37 @@ HighlighterAndId create_flag_lines_highlighter(HighlighterParameters params)
}
auto def_face = get_face(default_face);
Vector<DisplayLine> display_lines;
for (auto& line : lines)
{
display_lines.push_back(parse_display_line(std::get<1>(line)));
for (auto& atom : display_lines.back())
atom.face = merge_faces(def_face, atom.face);
}
CharCount width = 0;
for (auto& l : lines)
width = std::max(width, std::get<2>(l).char_length());
const String empty{' ', width};
for (auto& l : display_lines)
width = std::max(width, l.length());
const DisplayAtom empty{String{' ', width}, def_face};
for (auto& line : display_buffer.lines())
{
int line_num = (int)line.range().begin.line + 1;
auto it = find_if(lines,
[&](const LineAndFlag& l)
{ return std::get<0>(l) == line_num; });
String content = it != lines.end() ? std::get<2>(*it) : empty;
content += String(' ', width - content.char_length());
DisplayAtom atom{std::move(content)};
atom.face = it != lines.end() ? merge_faces(get_face(std::get<1>(*it)), def_face) : def_face;
line.insert(line.begin(), std::move(atom));
if (it == lines.end())
line.insert(line.begin(), empty);
else
{
DisplayLine& display_line = display_lines[it - lines.begin()];
DisplayAtom padding_atom{String(' ', width - display_line.length()), def_face};
auto it = std::copy(std::make_move_iterator(display_line.begin()),
std::make_move_iterator(display_line.end()),
std::inserter(line, line.begin()));
if (padding_atom.length() != 0)
*it++ = std::move(padding_atom);
}
}
};

View File

@ -9,7 +9,7 @@ namespace Kakoune
void register_highlighters();
using LineAndFlag = std::tuple<LineCount, String, String>;
using LineAndFlag = std::tuple<LineCount, String>;
}

View File

@ -253,7 +253,8 @@ inline void option_from_string(StringView str, TimestampedList<T>& opt)
{
auto it = find(str, ':');
opt.timestamp = str_to_int({str.begin(), it});
option_from_string({it+1, str.end()}, opt.list);
if (it != str.end())
option_from_string({it+1, str.end()}, opt.list);
}
template<typename T>