Emacs - how to avoid or replace wrong character en

2019-05-28 09:43发布

问题:

Assume that I receive a Spanish text written in MS word and saved as plain text (.txt). Unfortunately, all the Spanish accents show up like this:

Un \372ltimo an\341lisis

Can anybody tell me how I can avoid this, or at least how I can replace these characters? They are simply not found by the replace-regexp-functions, otherwise I could write a little elisp function that replaces every occurence of them by the associated Spanish accented character.

回答1:

This looks like ISO 8859-1 (Latin-1) encoding.

Visit the file with that coding system instead. If Emacs does not automatically identify the coding system, you can revisit the file with an explicit coding system with revert-buffer-with-coding-system (C-x RET r).

For example, if you are looking at the garbled file you describe,

C-x RET r
latin-1 RET
yes RET

Then you can set the coding system you want for saving (C-x RET f) and specifying something like utf-8.