zyedidia / micro

A modern and intuitive terminal-based text editor

Home Page:https://micro-editor.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support BOM head on win , linux

kasini3000 opened this issue · comments

support BOM head on win , linux

Because both 'vi' and 'vim' under Linux supports bom headers.

Specifications

  1. Detect the three bytes in the file header.
  2. According to the encoding meaning of bytes, parse and open the text file.
  3. Save the text file according to the original encoding of the file and the BOM header.

Golang should have such a library.

Commit hash:
OS:
Terminal:

The encoding can be set when doing something like running micro -encoding utf-16 file.txt or entering setlocal encoding utf-16 and reopen in micro, but BOM is read as a character that can be edited so I think it has to be detected.

I have not used Go much before and I do not know if there are other encodings with BOM that are used a lot, but I was only able to find 1 package where BOM and encoding can be detected:
https://pkg.go.dev/github.com/dimchansky/utfbom

I think I can try adding support with detecting BOM using the package and making a pull request if detecting encodings in the list of Encoding values in the page only would be fine.