Emacs: Declare Encoding for a File

By Xah Lee. Date: . Last updated: .

You can declare a file to be a specific encoding. [see Unicode: Character Set, Encoding, UTF-8, Codepoint]

put this in the first line of the file:

-*- coding: utf-8 -*-

The line can start with a comment character of your language, such as # , // This magic line is also adopted by Ruby, Python.

;; -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

File Variables (Emacs Manual)

in emacs lisp packages, the first line is also used for declaring the package. but you can add the encoding line after it.

;;; xah-fly-keys.el --- ergonomic modal keybinding minor mode. -*- coding: utf-8; lexical-binding: t; -*-

Emacs and Unicode

File Encoding

Unicode Font Setup

Emacs Line Ending