GNU Emacs
Emacs
Dashboard

22.7 Specifying a File’s Coding System

If Emacs recognizes the encoding of a file incorrectly, you can reread the file using the correct coding system with C-x RET r ( revert-buffer-with-coding-system). This command prompts for the coding system to use. To see what coding system Emacs actually used to decode the file, look at the coding system mnemonic letter near the left edge of the mode line (see The Mode Line), or type C-h C ( describe-coding-system).

You can specify the coding system for a particular file in the file itself, using the ‘ -*-…-*-’ construct at the beginning, or a local variables list at the end (see Local Variables in Files). You do this by defining a value for the “variable” named coding. Emacs does not really have a variable coding; instead of setting a variable, this uses the specified coding system for the file. For example, ‘ -*-mode: C; coding: latin-1; -*-’ specifies use of the Latin-1 coding system, as well as C mode. When you specify the coding explicitly in the file, that overrides file-coding-system-alist.