[Reversing the top-posting]
On Thu, 17 May 2012, Alessandro Antonello wrote:
Em 17/05/2012 08:09, "Benjamin R. Haskell" escreveu:
On Thu, 17 May 2012, Christian Brabandt wrote:
Hi Benjamin!
On Mi, 16 Mai 2012, Benjamin Fritz wrote:
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.
Well, I wouldn't rather not have 2 copies of the buffer in memory.
Surely there's a way to "do the encoding conversion in memory"
without creating a full copy of the buffer. Just running through the
buffer character-by-character, or line-wise, and ensuring that all
characters can be encoded using &fenc should work.
But, this way, how can Vim rollback if the conversion fails? Undoing
everything in reverse order?
Sorry for the imprecision: there's nothing to rollback... It's a test
conversion. More fully:
If encoding conversion is necessary for the write, there are two passes
through the buffer:
First pass: for every character in the buffer, ensure that it can be
converted to the target encoding. (This is in memory, so it's not as
time-consuming as a full "practice write" to disk.)
Second pass: write the file to disk, using the target encoding
(converting on-the-fly, or however the current process works).
Not sure how this would work for BufWriteCmd hackery. (But I'm not sure
how any of the proposals would work w.r.t. BufWriteCmd)
IMHO, the 'writebackup' option should be ignored when a character
encoding conversion is needed. Warning the user when that fails.
IMHO, the 'writebackup' option should be kept to whatever the user sets
it.
Vim simply shouldn't destroy the user's data due to a failed character
conversion. Despite its rarity, it's a completely-preventable condition
that Vim can detect before the original file is truncated.
--
Best,
Ben H
--
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