Bram Moolenaar wrote:
Tony Mechelynck wrote:

Changing a file's 'fileencoding' or 'fileformat' (or 'eol' when 'binary' is set) sets the 'modified' flag, but setting or clearing 'bomb' doesn't, even for Unicode files (e.g. &enc == "utf-8", &fenc == "" or &fenc == "utf-8"). Now with, for example, 'bomb' set, if the disk file is Unicode [i.e. ((&fenc == "" ? &enc : &fenc) =~? '^ucs\|^utf') ] and doesn't start with a BOM we cannot say that "the data on disk is the same as in memory". IMHO, if the user intentionally toggles 'bomb', then forgets to save the file, Vim should refuse to |abandon| it: if the user |:quit|s the file (or tries to |:edit| another file in the same window, etc.), then if 'autowriteall' is set Vim should write the file, if 'hidden' is set it should (IIUC) hide it, otherwise it should give the error "E37: No write since last change (add ! to override)".

I suppose this should work like 'endofline'.


There is a parallel. between 'bomb' at the beginning and 'eol' at the end, and between Unicode (i.e. the Vim expression I gave above, covering both 'enc' and 'fenc') and 'bin' as the condition for 'bomb'/'eol' to be significant.

Now how is 'eol' handled? Experimentation gives the following:

        :set eol! doesn't set 'mod' if 'nobin' is set
        :set eol! sets 'mod' if 'bin' is set
If 'eol' has been changed while 'nobin' was set, then ":set bin" will set 'mod', but after that ":set eol!" will set 'nomod'.

I'm not sure the handling of ":set eol!" while 'bin' was off (and its delayed handling when 'bin' goes on) satisfies me, but I won't delve into it here because there is one thing which makes it simpler in the case of 'bomb':

- When 'fenc' is changed explicitly, it sets 'mod' unconditionally;
- I haven't checked, but changing 'enc' should IMHO set 'mod' on those buffers where 'fenc' is empty, except those which will never be written (buftype=nofile etc.). (I.e., when 'fenc' is changed implicitly).

Therefore, I propose that ":set bomb!" on a Unicode file should set 'mod'. As a refinement, ":set bomb!" on a non-Unicode file can be ignored as far as 'mod' is concerned, since the file's 'fileencoding' cannot be changed from non-Unicode to Unicode without setting 'mod' in the process, regardless of the 'bomb' setting and its history.


Best regards,
Tony.

Reply via email to