Emacs: Declare Encoding for One File (Unicode, UTF-8)

By Xah Lee. Date: . Last updated: .

Declare Encoding in a File

You can declare a file to be a specific encoding.

put this in the first line of the file:

-*- coding: utf-8 -*-

;; -*- 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.

First Line in Emacs Lisp Package

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; -*-

Reference

Emacs and Unicode

File Encoding

Unicode Font Setup

Emacs Line Ending