On Wed, May 16, 2012 at 2:29 AM, Marko Mahnič <marko.mah...@gmail.com> wrote:
> On May 16, 4:59 am, Michael Henry wrote:
>>
>> How does the following sound for damage control?  If Vim
>> encounters an encoding error during a write, it could
>> automatically re-try the write with utf-8 (or whatever fail-safe
>> encoding makes sense) to prevent leaving the user with an empty
>> file.

I don't like it, because a failed write will still modify the file. I
think nobody would expect that a failed write would modify the file.
I'd rather check beforehand whether the write can succeed before even
trying. I do like it better than destroying the file. I'd rather have
the file encoding change than the file contents be deleted. A warning
message should be displayed, that says, "Encoding conversion error
corrupted file contents during write. File encoding on disk is now
xxxxx."

>
> Wouldn't it be better if Vim would ask the user what to do when
> encoding
> with 'fenc' fails?  Some of the options could be:
>   - save with 'enc' encoding
>   - save with 'fenc' encoding and replace invalid characters with '?'
>   - don't save anything, I'll fix it
>
> This options should be give no matter what the value of 'writebackup'
> is.

This would be nice.

> Until the user selects an option, nothing should be written to disk.

The problem is, something IS written to disk before the conversion
error occurs. The file is truncated in preparation for writing, but
then the write fails, so we abandon the write. But the damage has
already been done.

Is there a reason we couldn't do the encoding conversion in memory,
and if it succeeds, only then open the file to write the data? That
seems like the sanest way to do things. Only open the file when you
know the write will succeed. IIUC, that's the gist of Christian's
patch, except the patch does the conversion twice to determine whether
the write will succeed. Why can't we just store off and re-use the
already converted text instead of converting again?

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to