summaryrefslogtreecommitdiff
path: root/src/completion.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-09-14 15:41:56 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-09-14 15:41:56 +0000
commitb59ad6a174b49a049fd6789cbeb54dc40fd85fa1 (patch)
tree71c8a6c43696e080cc3bcfbe68c89e2516b24c69 /src/completion.cc
parent4b38cd3cd0131b2ab276310cc234ab666bd99363 (diff)
Completion: dedicated completion header and basic filename completion
Diffstat (limited to 'src/completion.cc')
-rw-r--r--src/completion.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/completion.cc b/src/completion.cc
new file mode 100644
index 00000000..a1eed12a
--- /dev/null
+++ b/src/completion.cc
@@ -0,0 +1,34 @@
+#include "completion.hh"
+
+#include "utils.hh"
+
+#include <dirent.h>
+
+namespace Kakoune
+{
+
+CandidateList complete_filename(const std::string& prefix)
+{
+ size_t dir_end = prefix.find_last_of('/');
+ std::string dirname = "./";
+ std::string fileprefix = prefix;
+
+ if (dir_end != std::string::npos)
+ {
+ dirname = prefix.substr(0, dir_end + 1);
+ fileprefix = prefix.substr(dir_end + 1, std::string::npos);
+ }
+
+ 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;
+}
+
+}