ConvertToUTF8 icon indicating copy to clipboard operation
ConvertToUTF8 copied to clipboard

Use extended attributes on macOS to save/load text encoding

Open gingerbeardman opened this issue 7 years ago • 1 comments

Proposal

Use xattr (extended attributes) on macOS to save/load text encoding with file.

BBEdit is the only editor I've found that already does this.

Also you should honour any existing com.apple.TextEncoding when loading and keep it when saving.

Background

  • Text Encoding has to either be set manually, or guessed by scanning the file
  • Both of these tasks take time

Benefits

  • loading time can be reduced
  • text encoding can be more persistent
  • can still be changed and rewritten at any point

Details

debug command: xattr -p -l com.apple.TextEncoding "/path/to/file.txt"

output: file.txt com.apple.TextEncoding: Shift_JIS;2561

to set xattr (from terminal): xattr -w com.apple.TextEncoding "Shift_JIS;2561" "/path/to/file.txt"

References

these may help with implementation:

  • node: https://github.com/LinusU/fs-xattr
  • obj-c & swift: https://developer.apple.com/library/content/qa/qa1719/_index.html

gingerbeardman avatar Mar 21 '18 16:03 gingerbeardman

Any thoughts on this?

gingerbeardman avatar Jan 07 '20 14:01 gingerbeardman