Add indent/deindent binding (> and <)

This commit is contained in:
Maxime Coste 2012-11-19 19:22:11 +01:00
parent 1602fcf012
commit 0ca66e3bf9
2 changed files with 30 additions and 0 deletions

View File

@ -236,6 +236,32 @@ void do_join(Context& context)
editor.move_selections(-1_char); editor.move_selections(-1_char);
} }
void do_indent(Context& context)
{
const char* spaces = " ";
int width = std::min(context.option_manager()["indentwidth"].as_int(), 16);
String indent(spaces, spaces + width);
Editor& editor = context.editor();
SelectionAndCapturesList sels = editor.selections();
auto restore_sels = on_scope_end([&]{ editor.select(std::move(sels)); });
editor.select(select_whole_lines);
editor.multi_select(std::bind(select_all_matches, _1, "^[^\n]"));
editor.insert(indent, InsertMode::Insert);
}
void do_deindent(Context& context)
{
int width = context.option_manager()["indentwidth"].as_int();
Editor& editor = context.editor();
SelectionAndCapturesList sels = editor.selections();
auto restore_sels = on_scope_end([&]{ editor.select(std::move(sels)); });
editor.select(select_whole_lines);
editor.multi_select(std::bind(select_all_matches, _1,
"^\\h{1," + int_to_str(width) + "}"));
editor.erase();
}
template<bool inner> template<bool inner>
void do_select_object(Context& context) void do_select_object(Context& context)
{ {
@ -462,6 +488,9 @@ std::unordered_map<Key, std::function<void (Context& context)>> keymap =
{ { Key::Modifiers::Alt, 'j' }, do_join }, { { Key::Modifiers::Alt, 'j' }, do_join },
{ { Key::Modifiers::None, '<' }, do_deindent },
{ { Key::Modifiers::None, '>' }, do_indent },
{ { Key::Modifiers::Alt, 'x' }, [](Context& context) { context.editor().select(select_whole_lines); } }, { { Key::Modifiers::Alt, 'x' }, [](Context& context) { context.editor().select(select_whole_lines); } },
{ { Key::Modifiers::Alt, 'c' }, [](Context& context) { if (context.has_window()) context.window().center_selection(); } }, { { Key::Modifiers::Alt, 'c' }, [](Context& context) { if (context.has_window()) context.window().center_selection(); } },

View File

@ -94,6 +94,7 @@ GlobalOptionManager::GlobalOptionManager()
: OptionManager() : OptionManager()
{ {
set_option("tabstop", Option(8)); set_option("tabstop", Option(8));
set_option("indentwidth", Option(4));
set_option("eolformat", Option("lf")); set_option("eolformat", Option("lf"));
set_option("BOM", Option("no")); set_option("BOM", Option("no"));
} }