fidian / hexmode

Vim plugin to edit binary files in a hex mode automatically.
146 stars 19 forks source link

Use `file` to determine if the file is binary #7

Closed rkiyanchuk closed 8 years ago

rkiyanchuk commented 8 years ago

file utility uses magic numbers to better determine if the file is binary, even if it doesn't have any extension.

The file utility is present in most distros by default, but if it isn't, the plugin falls back into old behavior (using file extension).

Also mixed tabs and spaces replaced with spaces only.

fidian commented 8 years ago

I am a little concerned about this patch. I would want the check for isBinary to be called only once when opening the file, not called again later. Let's pretend that I open a binary file and change that file so it is text on disk without replacing the buffer. How do these updates handle tricky situations like that?

I am not at a computer for a couple days otherwise I would try this out myself.

rkiyanchuk commented 8 years ago

@fidian You are right, I didn't pay much attention to how &binary was used in the original code.

How about the updated version? IsBinary is called at the beginning and the resulting value is assigned to &binary. If file executable is not present it just preserves &binary value that was already set. Later only &binary variable is used.

fidian commented 8 years ago

Looks ideal to me. I appreciate the contribution!