SublimeText / TrailingSpaces

Highlight trailing spaces and delete them in a flash.
MIT License
897 stars 94 forks source link

Added support for non UTF-8 encoded files. #90

Closed davidolrik closed 4 years ago

davidolrik commented 9 years ago

TrailingSpaces fails to run on non UTF-8 files.

This small fix extracts the encoding from the view(current file), and uses that encoding for opening the file.

FichteFoll commented 4 years ago

Sublime Text's encoding names are very different from Python's. sublime_lib has a bidirectional mapping for those, but I believe the "read file from disk" solution to be very fragile in the first place. I don't see why getting the text from view.substr isn't an option.

rchl commented 4 years ago

@FichteFoll reading file from disk is used for the "show only trailing spaces in modified lines" feature. Do you see any other way of implementing it? I don't immediately see any API we could use for that.

FichteFoll commented 4 years ago

I was thinking of loading the file into memory using view.substr when the file is loaded or first activated, but I just realized that this assumption fails when recovering a hot-exited session. I presume reading from the file is still necessary in that case, but using the encoding mapping provided by sublime_lib instead.