1. Home
  2. Computing & Technology
  3. Linux

Specify Coding
Emacs Documentation

By Juergen Haas, About.com

Specifying a Coding System

In cases where Emacs does not automatically choose the right coding system, you can use these commands to specify one:

  • C-x <RET> f coding <RET>
    Use coding system coding for the visited file in the current buffer.
  • C-x <RET> c coding <RET>
    Specify coding system coding for the immediately following command.
  • C-x <RET> k coding <RET>
    Use coding system coding for keyboard input.
  • C-x <RET> t coding <RET>
    Use coding system coding for terminal output.
  • C-x <RET> p input-coding <RET> output-coding <RET>
    Use coding systems input-coding and output-coding for subprocess input and output in the current buffer.
  • C-x <RET> x coding <RET>
    Use coding system coding for transferring selections to and from other programs through the window system.
  • C-x <RET> X coding <RET>
    Use coding system coding for transferring one selection--the next one--to or from the window system.

The command C-x <RET> f (set-buffer-file-coding-system) specifies the file coding system for the current buffer--in other words, which coding system to use when saving or rereading the visited file. You specify which coding system using the minibuffer. Since this command applies to a file you have already visited, it affects only the way the file is saved.

Another way to specify the coding system for a file is when you visit the file. First use the command C-x <RET> c (universal-coding-system-argument this command uses the minibuffer to read a coding system name. After you exit the minibuffer, the specified coding system is used for [i]the immediately following command[/i]. [p]So if the immediately following command is [i]C-x C-f[/i], for example, it reads the file using that coding system (and records the coding system for when the file is saved). Or if the immediately following command is [i]C-x C-w[/i], it writes the file using that coding system. Other file commands affected by a specified coding system include [i]C-x C-i[/i] and [i]C-x C-v[/i], as well as the other-window variants of [i]C-x C-f[/i]. [p][i]C-x <RET> c[/i] also affects commands that start subprocesses, including [i]M-x shell[/i] (see [link url=/od/emacs_doc/a/emacsdoc479.htm]Shell[/link]). [p]However, if the immediately following command does not use the coding system, then [i]C-x <RET> c[/i] ultimately has no effect. [p]An easy way to visit a file with no conversion is with the [i]M-x find-file-literally[/i] command. See [link url=/od/emacs_doc/a/emacsdoc556.htm]Visiting[/link]. [p]The variable [b]default-buffer-file-coding-system[/b] specifies the choice of coding system to use when you create a new file. It applies when you find a new file, and when you create a buffer and then save it in a file. Selecting a language environment typically sets this variable to a good choice of default [p] * [b][link url=/od/emacs_doc/a/emacs_doc_idx.htm]Emacs Manual Index[/link][/b] _z_linux_z_);

Explore Linux
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Linux
  4. Linux Software
  5. Editors
  6. Emacs
  7. Emacs Documentation - Specify Coding

©2009 About.com, a part of The New York Times Company.

All rights reserved.