escape whitespaces in filename or buffername completions

This commit is contained in:
Maxime Coste 2012-08-29 21:52:17 +02:00
parent 2825bc3d7b
commit f1d8d0add8
3 changed files with 8 additions and 3 deletions

View File

@ -61,7 +61,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix,
{ {
const String& name = buffer->name(); const String& name = buffer->name();
if (name.substr(0, real_prefix.length()) == real_prefix) if (name.substr(0, real_prefix.length()) == real_prefix)
result.push_back(name); result.push_back(escape(name));
} }
// no prefix completion found, check regex matching // no prefix completion found, check regex matching
if (result.empty()) if (result.empty())
@ -73,7 +73,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix,
{ {
const String& name = buffer->name(); const String& name = buffer->name();
if (boost::regex_search(name.begin(), name.end(), ex)) if (boost::regex_search(name.begin(), name.end(), ex))
result.push_back(name); result.push_back(escape(name));
} }
} }
catch (boost::regex_error& err) {} catch (boost::regex_error& err) {}

View File

@ -50,7 +50,7 @@ CandidateList complete_filename(const Context& context,
if (entry->d_type == DT_DIR) if (entry->d_type == DT_DIR)
name += '/'; name += '/';
if (fileprefix.length() != 0 or filename[0] != '.') if (fileprefix.length() != 0 or filename[0] != '.')
result.push_back(name); result.push_back(escape(name));
} }
} }
std::sort(result.begin(), result.end()); std::sort(result.begin(), result.end());

View File

@ -190,6 +190,11 @@ bool operator== (const std::unique_ptr<T>& lhs, T* rhs)
return lhs.get() == rhs; return lhs.get() == rhs;
} }
inline String escape(const String& name)
{
return name.replace("([ \\t;])", R"(\\\1)");
}
} }
#endif // utils_hh_INCLUDED #endif // utils_hh_INCLUDED