I'm really confused about this issue since it should be doable, but i fail to understand it.
I have some file with broken encoding (a pdf file, actually), which I copy some text from. When I paste this text into emacs (or anywhere else) I get sth like "íàïðèìåð", while the correct variant should be cyrillic "например". My buffer encoding is utf-8
and the broken text has something to do with cp1251
. My goal is - obviously - to repair this broken encoding and insert it in place of the broken pasted text.
I tried different combinations of encode-coding-string
and decode-coding-string
with utf-8
and cp1251
, but it gave me some other broken encodings or just a bunch of spaces (that's kinda weird)
Sorry for my messy statement, I just really don't get all this encoding stuff.
What I achieved is a (half)solution for the reverse problem: if i write (encode-coding-string "например" 'cp1251)
and press C-x C-e
, it prints "íàïðèìåð" to the messages. It's strange, but if I try to insert result of this computation into a buffer I get some nonsense yet again... Maybe I miss another aspect of this problem...
(decode-coding-string (encode-coding-string "например" 'cp1251) 'cp1251)
gives#("например" 0 8 (charset windows-1251))
. So you have kind of a round trip and you should try(decode-coding-string garbage 'cp1251)
. But if you yank in Emacs maybe you should use thecp1251
coding system for the yank command.set-clipboard-coding-system
(as suggested here) andselection-coding-system
(as described here), but this didn't help either