If file is not on disk, use tmProperties for encoding

This happens e.g. if we do ‘ls|mate’ — here we do have content which got a charset and newline mode assigned during “load”, but from the user’s POV he is saving a new file (if he saves the buffer) so should get his configured encoding.
This commit is contained in:
Allan Odgaard
2012-08-26 17:33:26 +02:00
parent 6f45ee4a9c
commit c7678e9f67

View File

@@ -647,14 +647,17 @@ namespace document
encoding::type document_t::encoding_for_save_as_path (std::string const& path)
{
encoding::type res = disk_encoding();
if(res.charset() != kCharsetNoEncoding && res.newlines() != NULL_STR)
return res;
settings_t const& settings = settings_for_path(path);
if(res.charset() == kCharsetNoEncoding)
if(!is_on_disk() || res.charset() == kCharsetNoEncoding)
{
res.set_charset(settings.get(kSettingsEncodingKey, kCharsetUTF8));
if(res.newlines() == NULL_STR)
res.set_byte_order_mark(settings.get(kSettingsUseBOMKey, res.byte_order_mark()));
}
if(!is_on_disk() || res.newlines() == NULL_STR)
res.set_newlines(settings.get(kSettingsLineEndingsKey, "\n"));
return res;
}