Go to the first, previous, next, last section, table of contents.


Encoding and I/O

The principal purpose of coding systems is for use in reading and writing files. The function insert-file-contents uses a coding system for decoding the file data, and write-region uses one to encode the buffer contents.

You can specify the coding system to use either explicitly (see section Specifying a Coding System for One Operation), or implicitly using the defaulting mechanism (see section Default Coding Systems). But these methods may not completely specify what to do. For example, they may choose a coding system such as undefined which leaves the character code conversion to be determined from the data. In these cases, the I/O operation finishes the job of choosing a coding system. Very often you will want to find out afterwards which coding system was chosen.

Variable: buffer-file-coding-system
This variable records the coding system that was used for visiting the current buffer. It is used for saving the buffer, and for writing part of the buffer with write-region. When those operations ask the user to specify a different coding system, buffer-file-coding-system is updated to the coding system specified.

Variable: save-buffer-coding-system
This variable specifies the coding system for saving the buffer--but it is not used for write-region. When saving the buffer asks the user to specify a different coding system, and save-buffer-coding-system was used, then it is updated to the coding system that was specified.

Variable: last-coding-system-used
I/O operations for files and subprocesses set this variable to the coding system name that was used. The explicit encoding and decoding functions (see section Explicit Encoding and Decoding) set it too.

Warning: Since receiving subprocess output sets this variable, it can change whenever Emacs waits; therefore, you should use copy the value shortly after the function call which stores the value you are interested in.

The variable selection-coding-system specifies how to encode selections for the window system. See section Window System Selections.


Go to the first, previous, next, last section, table of contents.