summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-09-05 00:21:42 +0200
committerMaxime Coste <frrrwww@gmail.com>2012-09-05 00:21:42 +0200
commit737ee8af249758b2999b3c03522499c404fb9c66 (patch)
tree034fe7a756a0ddf655027e0c695f6b2eac39c7a9 /src
parentb23425764edc155e16023b58afa3c42efda1d5cb (diff)
use on_next_key in do_go and do_select_object
Diffstat (limited to 'src')
-rw-r--r--src/main.cc101
1 files changed, 51 insertions, 50 deletions
diff --git a/src/main.cc b/src/main.cc
index 54bffad0..b3347da7 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -123,44 +123,43 @@ template<bool append>
void do_go(Context& context)
{
int count = context.numeric_param();
- Editor& editor = context.editor();
if (count != 0)
{
BufferIterator target =
- editor.buffer().iterator_at_line_begin(count-1);
+ context.editor().buffer().iterator_at_line_begin(count-1);
- editor.select(target);
+ context.editor().select(target);
if (context.has_window())
context.window().center_selection();
}
else
- {
- Key key = context.client().get_key();
- if (key.modifiers != Key::Modifiers::None)
- return;
+ context.client().on_next_key([](const Key& key, Context& context) {
+ if (key.modifiers != Key::Modifiers::None)
+ return;
- switch (key.key)
- {
- case 'g':
- case 't':
- editor.select(editor.buffer().begin());
- break;
- case 'l':
- case 'L':
- editor.select(select_to_eol, append);
- break;
- case 'h':
- case 'H':
- editor.select(select_to_eol_reverse, append);
- break;
- case 'b':
- {
- const Buffer& buf = editor.buffer();
- editor.select(buf.iterator_at_line_begin(buf.line_count() - 1));
- break;
- }
- }
- }
+ Editor& editor = context.editor();
+ switch (key.key)
+ {
+ case 'g':
+ case 't':
+ editor.select(editor.buffer().begin());
+ break;
+ case 'l':
+ case 'L':
+ editor.select(select_to_eol, append);
+ break;
+ case 'h':
+ case 'H':
+ editor.select(select_to_eol_reverse, append);
+ break;
+ case 'b':
+ {
+ const Buffer& buf = editor.buffer();
+ editor.select(buf.iterator_at_line_begin(buf.line_count() - 1));
+ break;
+ }
+ }
+ });
}
void do_command(Context& context)
@@ -288,27 +287,29 @@ void do_join(Context& context)
template<bool inner>
void do_select_object(Context& context)
{
- typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
- static const std::unordered_map<Key, Selector> key_to_selector =
- {
- { { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
- { { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
- { { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
- { { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
- { { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
- { { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
- { { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
- { { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
- { { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
- { { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
- { { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, inner) },
- { { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, inner) },
- };
-
- Key key = context.client().get_key();
- auto it = key_to_selector.find(key);
- if (it != key_to_selector.end())
- context.editor().select(it->second);
+ context.client().on_next_key(
+ [](const Key& key, Context& context) {
+ typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
+ static const std::unordered_map<Key, Selector> key_to_selector =
+ {
+ { { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
+ { { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
+ { { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
+ { { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
+ { { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
+ { { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
+ { { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
+ { { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
+ { { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
+ { { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
+ { { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, inner) },
+ { { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, inner) },
+ };
+
+ auto it = key_to_selector.find(key);
+ if (it != key_to_selector.end())
+ context.editor().select(it->second);
+ });
}
template<typename T>