From 5ca901644f98f88d9fcfd751d8d6ee580de0147d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 22 Sep 2011 18:55:45 +0000 Subject: Completion: add complete_buffername completer --- src/completion.cc | 15 +++++++++++++++ src/completion.hh | 3 +++ src/main.cc | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/completion.cc b/src/completion.cc index d4e5f04a..7e570def 100644 --- a/src/completion.cc +++ b/src/completion.cc @@ -1,5 +1,6 @@ #include "completion.hh" +#include "buffer_manager.hh" #include "utils.hh" #include @@ -33,4 +34,18 @@ CandidateList complete_filename(const std::string& prefix, return result; } +CandidateList complete_buffername(const std::string& prefix, + size_t cursor_pos) +{ + std::string real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& buffer : BufferManager::instance()) + { + if (buffer.name().substr(0, real_prefix.length()) == real_prefix) + result.push_back(buffer.name()); + } + return result; +} + + } diff --git a/src/completion.hh b/src/completion.hh index da110638..739c24ea 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -25,5 +25,8 @@ struct Completions CandidateList complete_filename(const std::string& prefix, size_t cursor_pos = std::string::npos); +CandidateList complete_buffername(const std::string& prefix, + size_t cursor_pos = std::string::npos); + } #endif // completion_hh_INCLUDED diff --git a/src/main.cc b/src/main.cc index 00fb8749..dc69b056 100644 --- a/src/main.cc +++ b/src/main.cc @@ -402,7 +402,8 @@ int main(int argc, char* argv[]) command_manager.register_command(std::vector{ "q", "quit" }, quit); command_manager.register_command(std::vector{ "w", "write" }, write_buffer, PerArgumentCommandCompleter{ complete_filename }); - command_manager.register_command(std::vector{ "b", "buffer" }, show_buffer); + command_manager.register_command(std::vector{ "b", "buffer" }, show_buffer, + PerArgumentCommandCompleter { complete_buffername }); try { -- cgit v1.2.3