2011-09-14 17:41:56 +02:00
|
|
|
#include "completion.hh"
|
|
|
|
|
2011-09-22 20:55:45 +02:00
|
|
|
#include "buffer_manager.hh"
|
2011-09-14 17:41:56 +02:00
|
|
|
#include "utils.hh"
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2011-09-16 11:17:55 +02:00
|
|
|
CandidateList complete_filename(const std::string& prefix,
|
|
|
|
size_t cursor_pos)
|
2011-09-14 17:41:56 +02:00
|
|
|
{
|
2011-09-16 11:17:55 +02:00
|
|
|
std::string real_prefix = prefix.substr(0, cursor_pos);
|
|
|
|
size_t dir_end = real_prefix.find_last_of('/');
|
2011-09-14 17:41:56 +02:00
|
|
|
std::string dirname = "./";
|
2011-09-16 11:17:55 +02:00
|
|
|
std::string fileprefix = real_prefix;
|
2011-09-14 17:41:56 +02:00
|
|
|
|
|
|
|
if (dir_end != std::string::npos)
|
|
|
|
{
|
2011-09-16 11:17:55 +02:00
|
|
|
dirname = real_prefix.substr(0, dir_end + 1);
|
|
|
|
fileprefix = real_prefix.substr(dir_end + 1, std::string::npos);
|
2011-09-14 17:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto dir = auto_raii(opendir(dirname.c_str()), closedir);
|
|
|
|
|
|
|
|
CandidateList result;
|
|
|
|
while (dirent* entry = readdir(dir))
|
|
|
|
{
|
|
|
|
std::string filename = entry->d_name;
|
|
|
|
if (filename.substr(0, fileprefix.length()) == fileprefix)
|
|
|
|
result.push_back(filename);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|