- // complete or increment the command
- string s = lyxaction.getApproxFuncName(fl_get_input(ob));
- if (!s.empty())
- fl_set_input(ob, s.c_str());
+ // Completion handling.
+
+ vector<string> comp;
+ lyx::copy_if(completion_.begin(),
+ completion_.end(),
+ std::back_inserter(comp), prefix(input));
+
+ if (comp.empty()) {
+ // No matches
+ string const tmp = input + _(" [no match]");
+ stored_set(input);
+ fl_set_input(ob, tmp.c_str());
+ } else if (comp.size() == 1) {
+ // Perfect match
+ string const tmp =
+ comp[0] + _(" [sole completion]");
+ stored_set(comp[0]);
+ fl_set_input(ob, tmp.c_str());
+ } else {
+ // More that one match
+ // Find maximal avaliable prefix
+ string const tmp = comp[0];
+ string test(input);
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ lyx::copy_if(comp.begin(),
+ comp.end(),
+ std::back_inserter(vtmp),
+ prefix(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+ fl_set_input(ob, test.c_str());
+
+ // How should the possible matches
+ // be visualized?
+ std::copy(comp.begin(), comp.end(),
+ std::ostream_iterator<string>(std::cerr, "\n"));
+ }