From 7aa533c04904a8be36354e5896891f672ba3a40f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 29 Jun 2012 13:25:34 +0200 Subject: [PATCH] simplify Register interface --- src/commands.cc | 8 +++++--- src/main.cc | 8 ++++---- src/ncurses.cc | 2 +- src/register.cc | 17 +---------------- src/register.hh | 6 +----- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 0d42b060..fc3afe5f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -659,9 +659,11 @@ class RegisterRestorer { public: RegisterRestorer(char name) - : m_name(name), - m_save(RegisterManager::instance()[name].content()) - {} + : m_name(name) + { + memoryview save = RegisterManager::instance()[name]; + m_save = std::vector(save.begin(), save.end()); + } ~RegisterRestorer() { RegisterManager::instance()[m_name] = m_save; } diff --git a/src/main.cc b/src/main.cc index 9a9c2008..ba6eaccc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -210,7 +210,7 @@ void do_search(Editor& editor) { String ex = prompt("/"); if (ex.empty()) - ex = RegisterManager::instance()['/'].get(); + ex = RegisterManager::instance()['/'][0]; else RegisterManager::instance()['/'] = ex; @@ -222,7 +222,7 @@ void do_search(Editor& editor) template void do_search_next(Editor& editor) { - const String& ex = RegisterManager::instance()['/'].get(); + const String& ex = RegisterManager::instance()['/'][0]; if (not ex.empty()) editor.select(std::bind(select_next_match, _1, ex), append); else @@ -260,9 +260,9 @@ void do_paste(Editor& editor, int count) else { if (append) - editor.append(reg.get(count-1)); + editor.append(reg[count-1]); else - editor.insert(reg.get(count-1)); + editor.insert(reg[count-1]); } } diff --git a/src/ncurses.cc b/src/ncurses.cc index 0daaabe9..adf2a8f5 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -265,7 +265,7 @@ String NCursesClient::prompt(const String& text, Completer completer) case CTRL('r'): { c = getch(); - String reg = RegisterManager::instance()[c].get(); + String reg = RegisterManager::instance()[c][0]; current_completion = -1; result = result.substr(0, cursor_pos) + reg + result.substr(cursor_pos, String::npos); cursor_pos += reg.length(); diff --git a/src/register.cc b/src/register.cc index d8c48704..af0852ea 100644 --- a/src/register.cc +++ b/src/register.cc @@ -5,28 +5,13 @@ namespace Kakoune const String Register::ms_empty; -Register& Register::operator=(const String& value) -{ - m_content.clear(); - m_content.push_back(value); - return *this; -} - Register& Register::operator=(const memoryview& values) { m_content = std::vector(values.begin(), values.end()); return *this; } -const String& Register::get() const -{ - if (m_content.size() != 0) - return m_content.front(); - else - return ms_empty; -} - -const String& Register::get(size_t index) const +const String& Register::operator[](size_t index) const { if (m_content.size() > index) return m_content[index]; diff --git a/src/register.hh b/src/register.hh index 0dc072f7..fc50e44f 100644 --- a/src/register.hh +++ b/src/register.hh @@ -12,16 +12,12 @@ namespace Kakoune class Register { public: - Register& operator=(const String& value); Register& operator=(const memoryview& values); - const String& get() const; - const String& get(size_t index) const; + const String& operator[](size_t index) const; operator memoryview() const { return memoryview(m_content); } - - const std::vector& content() const { return m_content; } private: std::vector m_content;