Ingo Karkat wrote: > On 13-Aug-2013 11:15 +0200, Bram Moolenaar wrote: > > > Einar Lielmanis wrote: > > > >> Encrypted file contents are destroyed, if something (e.g autocmd) > >> triggers write event, while user is being asked for password. > >> > >> To repro: > >> 1. have an encrypted.txt ready (:X) > >> 2. gvim, :au focuslost * w > >> 3. :e encrypted.txt, don't type in the password yet, > >> 4. lose window focus, e.g via switching to another window, to trigger > >> the focuslost event, > >> > >> Expected: > >> The file hasn't changed, so it should stay unmodified, > >> > >> Actual behavior: > >> encrypted.txt is truncated to a zero size. > > > > Doing a ":write" on FocusLost is a bad idea. > > This is a common idiom to auto-save, e.g. see > http://vim.wikia.com/wiki/Auto_save_files_when_focus_is_lost > > > Perhaps ":update" would be acceptable, but generally a FocusLost event > > should not do something like this, because it can happen at any time. > > Doesn't "at any time" imply more multithreading than is actually > available in Vim(script)?!
It's not multi-threading, it is like handling an interrupt. And yes, autocommands have the danger of doing something bad. There is a warning in the documentation about that. > I had naively assumed that the FocusLost event would only be processed > after the blocking password query has been concluded. Not only would that require queueing events, it would also cause the FocusLost to be executed when focus has been regained (how else would one type the password?). > Isn't that (blocking, or maybe just ignoring autocmd events if that's > simpler to implement) a proper way to fix the problem? No, because Vim does not know what the autocommand will do. It won't guess what the user actually wanted. It could result in making the event not working while the user did want to do something useful. You can use the mode() function to find out what state Vim is in. While typing the encryption key it's "c". -- >From "know your smileys": :~) A man with a tape recorder up his nose /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- You received this message from the "vim_dev" 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 --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.