On Tuesday, May 15, 2012 2:49:38 AM UTC-5, JohnBeckett wrote: > To reproduce problem: > > 1. Create file bad.tmp by executing the following line. > :call writefile(["Very important file \x8D"], 'bad.tmp') > > 2. Start Vim editing the file and enter commands, as below. > vim -N -u NONE bad.tmp > :set fenc=cp857
What if, right here, Vim were to check the buffer contents to see if all characters in the file can actually be converted to the new fenc setting, and issue a warning if not? It's not something Vim does currently...but I don't see why it couldn't. And I'd like to know if I do something stupid *when I do it*, not when I try to write the file and end up killing my file. > :set nobackup nowritebackup > :w > > 3. Observe message which you have probably never seen before: > "bad.tmp" E513: write error, conversion failed > (make 'fenc' empty to override) > WARNING: Original file may be lost or damaged > don't quit the editor until the file is successfully written! > > 4. Panic and do what has always worked in the past: > :q! > Right, to me, :q! means "oh crap I didn't mean to do that, GET ME OUT!" > Result: > - Step 2 replaces bad.tmp with an empty file. > - The original contents have been lost. > > The "no backup" options cause Vim to overwrite the existing > file. However, the write aborts when the conversion fails, > resulting in lost data. > > While a user should not turn off backups on an important file, > it is a horrible trap that one incorrect byte can effectively > delete a file. > > A message like the following might help: > > "bad.tmp" E513: write error, conversion failed > WARNING: The file on disk has probably been corrupted. > Do not quit until the file is successfully written! > Try saving it again after entering (nothing after "="): > :set fenc= > > I haven't done more than glance at Christian Brabandt's patch > so I don't know what is achievable. Would something as simple > as checking the number of bytes in the file on disk be > sufficient to decide if corrective action is needed? > > John -- 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
