Emacs File/Character Encoding/Decoding FAQ

Perm url with updates: http://xahlee.org/emacs/emacs_encoding_decoding_faq.html

Emacs File/Character Encoding/Decoding FAQ

Xah Recommends:
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2009, ..., 2010-10-13

This page is a tutorial on file and character encoding/decoding in emacs. If you are not familiar with what's encoding/decoding, see: UNICODE Basics: What's Character Encoding, UTF-8, and All That?.

In a buffer, how to find out what encoding system was used to decode the file?

Check the value of the variable “buffer-file-coding-system”. You do that by typing 【Alt+x describe-variable】, then “buffer-file-coding-system”.

How to find out what's the current coding system used for opening and saving files?

Type 【Alt+x describe-coding-system】.

How to set a encoding system for a buffer?

Call “set-buffer-file-coding-system”, then type the encoding system you want. Type Tab to see a list of possible values.

How to permanently choose a encoding system in emacs for opening and saving?

Choose the menu “Options‣Mule (Multilingual Environment)‣Set Language Environment”. After that, be sure to pull the menu “Options‣Save Options” to save the setting in your emacs init file.

What encoding systems emacs support?

You can find out by calling “list-coding-systems”.

Is there a way to declare a file with a particular character encoding?

Yes. In the first line of your file, put -*- coding: utf-8 -*-. That way, each time emacs open the file, emacs will presume that the file is encoded in utf-8. The line can start with a comment character(s) of your language, such as “#”, “//”. This method is also adopted by Python.

(info "(emacs) File Variables")

Where can one read more about unicode in emacs?

(info "(emacs) International")

To learn more about Unicode, see Unicode Related Tutorials and Essays, or Wikipedia.

Emacs and Unicode Tips

xub Unicode Browser mode for Emacs

Best Fonts for Unicode

How to Quickly Switch Fonts in Emacs

Was this page useful? If so, please do donate $3, thank you donors!

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs