konr
konr

Reputation: 2565

How can I get the charset of a string/buffer?

I need an elisp function that guesses the charset of some html, and since Emacs already does that when opening a file, I wonder if I can reuse it somehow, perhaps by writing the string in a temporary buffer, setting the correct charset, and getting it. Are there such functions?

Thanks!

Upvotes: 5

Views: 426

Answers (2)

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56655

I don't think that Emacs has something built-in to guess a character encoding, but it can read character encoding hints in files like -- coding: utf8 -- and etc. You can take a look at this external library though. I guess that you're using some web browser for Emacs like W3M and probably it has something to deal with character encodings based on the http metainformation it receives. This article might also be of some help.

Upvotes: 0

huaiyuan
huaiyuan

Reputation: 26549

See detect-coding-string.

Upvotes: 3

Related Questions