1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-29 14:44:56 +03:00

Completion: add complete_buffername completer

This commit is contained in:
Maxime Coste 2011-09-22 18:55:45 +00:00
parent 429536d0f4
commit 5ca901644f
3 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "completion.hh" #include "completion.hh"
#include "buffer_manager.hh"
#include "utils.hh" #include "utils.hh"
#include <dirent.h> #include <dirent.h>
@ -33,4 +34,18 @@ CandidateList complete_filename(const std::string& prefix,
return result; 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;
}
} }

View File

@ -25,5 +25,8 @@ struct Completions
CandidateList complete_filename(const std::string& prefix, CandidateList complete_filename(const std::string& prefix,
size_t cursor_pos = std::string::npos); 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 #endif // completion_hh_INCLUDED

View File

@ -402,7 +402,8 @@ int main(int argc, char* argv[])
command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit); command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit);
command_manager.register_command(std::vector<std::string>{ "w", "write" }, write_buffer, command_manager.register_command(std::vector<std::string>{ "w", "write" }, write_buffer,
PerArgumentCommandCompleter{ complete_filename }); PerArgumentCommandCompleter{ complete_filename });
command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer); command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer,
PerArgumentCommandCompleter { complete_buffername });
try try
{ {