5

My problem: With my Emacs 26.1 on my 10.13.6 Mac, I have a opened a third-party text file, and it turns out I have the wrong encoding set : the text is in French , and the accentuated characters are displayed incorrectly (thus "é" is displayed as a brown \216, "î" as a brown \224, etc).

What I tried : I tried

M-x revert-buffer-with-coding-system latin-1 and M-x revert-buffer-with-coding-system utf-8 emacs and nothing changed in the display.

I also tried (and failed) to guess the encoding : it must be an encoding in which "é" is the 216th character. Now é is U+00E9 in Unicode, which gives 233 in decimal. Also é is number 130 in extended ASCII.

1
  • That \216 is in octal => 142 decimal (but I have no clue which encoding it's using). It's not cp863 either.
    – rpluim
    Oct 3, 2018 at 10:33

1 Answer 1

6

This is the MacRoman encoding, a legacy encoding from the pre-OSX days of Mac OS. It is available in Emacs as mac-roman.

C-x RET r mac-roman RET yes RET

You may need to select mac-roman-mac, mac-roman-dos or mac-roman-unix explicitly if Emacs doesn't automatically detect the representation of line endings. The mac-roman part is for the encoding of non-ASCII characters.

If you want to specify the encoding of files with a certain extension, files in a certain directory, or more generally based on a file's path, you can call modify-coding-system-alist in your init file, e.g. for all *.txt files that are in or under a directory called old-mac-files:

(modify-coding-system-alist 'file "/old-mac-files/.*\\.txt\\'" 'mac-roman-mac)
6
  • I just noticed that I have to re-execute this command every-time I re-open the file. Is there a command to put in init.el so that this particular file will always be opened with the correct encoding (leaving the others file alone) ? Oct 5, 2018 at 13:34
  • @EwanDelanoy Yes, see my edit. Oct 5, 2018 at 18:57
  • Thanks for your edit. I failed to implement it correctly on my machine, and I've asked a new question about it. Oct 8, 2018 at 11:22
  • @EwanDelanoy My bad, I forgot an argument to modify-coding-system-alist. Oct 8, 2018 at 11:46
  • I understand that the dot needs to be escaped by a backslash before it, but what is the single quote at the end of the filename for ? Oct 8, 2018 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.