Completion: add complete_buffername completer
This commit is contained in:
parent
429536d0f4
commit
5ca901644f
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user