mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 01:00:28 +03:00
Filters: add an expand_tabulation filter
This commit is contained in:
parent
f802a9f3be
commit
22bd9f90d5
@ -40,6 +40,7 @@ struct DisplayAtom
|
||||
Color fg_color;
|
||||
Color bg_color;
|
||||
Attribute attribute;
|
||||
BufferString replacement_text;
|
||||
|
||||
DisplayAtom(BufferIterator begin, BufferIterator end,
|
||||
Color fg_color = Color::Default,
|
||||
|
@ -52,4 +52,28 @@ void colorize_cplusplus(DisplayBuffer& display_buffer)
|
||||
colorize_regex(display_buffer, types_keywords, Color::Green);
|
||||
}
|
||||
|
||||
void expand_tabulations(DisplayBuffer& display_buffer)
|
||||
{
|
||||
const int tabstop = 8;
|
||||
for (auto atom_it = display_buffer.begin();
|
||||
atom_it != display_buffer.end(); ++atom_it)
|
||||
{
|
||||
for (BufferIterator it = atom_it->begin; it != atom_it->end; ++it)
|
||||
{
|
||||
if (*it == '\t')
|
||||
{
|
||||
if (it != atom_it->begin)
|
||||
atom_it = display_buffer.split(atom_it, it) + 1;
|
||||
|
||||
if (it+1 != atom_it->end)
|
||||
atom_it = display_buffer.split(atom_it, it+1);
|
||||
|
||||
BufferCoord pos = it.buffer().line_and_column_at(it);
|
||||
int count = tabstop - (pos.column % tabstop);
|
||||
atom_it->replacement_text = std::string(count, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ void colorize_regex(DisplayBuffer& display_buffer,
|
||||
const boost::regex& ex, Color color);
|
||||
|
||||
void colorize_cplusplus(DisplayBuffer& display_buffer);
|
||||
void colorize_cplusplus(DisplayBuffer& display_buffer);
|
||||
void expand_tabulations(DisplayBuffer& display_buffer);
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,8 @@ void draw_window(Window& window)
|
||||
WindowCoord position;
|
||||
for (const DisplayAtom& atom : window.display_buffer())
|
||||
{
|
||||
const std::string content = window.buffer().string(atom.begin, atom.end);
|
||||
const std::string content = atom.replacement_text.empty() ?
|
||||
window.buffer().string(atom.begin, atom.end) : atom.replacement_text;
|
||||
|
||||
set_attribute(A_UNDERLINE, atom.attribute & Underline);
|
||||
set_attribute(A_REVERSE, atom.attribute & Reverse);
|
||||
|
@ -112,6 +112,7 @@ Window::Window(Buffer& buffer)
|
||||
{
|
||||
m_selections.push_back(Selection(buffer.begin(), buffer.begin()));
|
||||
m_filters.push_back(colorize_cplusplus);
|
||||
m_filters.push_back(expand_tabulations);
|
||||
m_filters.push_back(HighlightSelections(*this));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user