Emacs: File Encoding (Unicode, UTF-8)
What is Character Encoding
Set default encoding for read and write file, globally
Declare a file with a specific encoding
List emacs file encoding systems
- Alt+x
list-coding-systems -
Show a list of all coding systems.
emacs 29 list-coding-systems 2023-08-30
Open file with specific encoding
- Alt+x
revert-buffer-with-coding-system -
Refresh current buffer using a specific coding system to decode the file.
Press Tab to list possible ones.
Set a encoding for saving current file
- Alt+x
set-buffer-file-coding-system -
Set the file coding-system of the current buffer. (do a file save to save it with the new coding-system.)
Press Tab to see a list of possible values.
What is the encoding system used for current file
- buffer-file-coding-system
-
A Buffer Local Variable . Value is the character coding system for current buffer. 〔see Emacs: Show Variable Value and Doc〕
Set Encoding for Terminal output
This is important especially on Microsoft Windows. If you don't set this to utf-8, you may have problems with Python output of Unicode string.
Alt+x set-terminal-coding-system
put this in your Emacs Init File:
(set-terminal-coding-system 'utf-8-unix)
default-terminal-coding-system
Set Encoding for Keyboard Input
Alt+x set-keyboard-coding-system
put this in your Emacs Init File:
(set-keyboard-coding-system 'utf-8-unix)
View Current Coding System Config
Alt+xdescribe-current-coding-system
View Emacs Doc of a Specific Coding System
Alt+x describe-coding-system
Reference
Emacs and Unicode
- Emacs: Insert Unicode Character
- Emacs: Insert Emoji
- Emacs: Input Method
- Emacs: Find Character Name, Font, Position, Codepoint, Encoding, Etc
- Emacs Init: Update Unicode Data
File Encoding
- Emacs: File Encoding (Unicode, UTF-8)
- Emacs Init: Set Default File Encoding (Unicode, UTF-8)
- Emacs: Declare Encoding for One File (Unicode, UTF-8)