Next: Lisp and Coding Systems, Previous: Coding System Basics, Up: Coding Systems
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 Specifying Coding Systems), or implicitly using the defaulting
mechanism (see 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.
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.However,
buffer-file-coding-system
does not affect sending text to a subprocess.
This variable specifies the coding system for saving the buffer (by overriding
buffer-file-coding-system
). Note that it is not used forwrite-region
.When a command to save the buffer starts out to use
buffer-file-coding-system
(orsave-buffer-coding-system
), and that coding system cannot handle the actual text in the buffer, the command asks the user to choose another coding system. After that happens, the command also updatesbuffer-file-coding-system
to represent the coding system that the user specified.
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 Explicit Encoding) set it too.
Warning: Since receiving subprocess output sets this variable, it can change whenever Emacs waits; therefore, you should copy the value shortly after the function call that stores the value you are interested in.
The variable selection-coding-system
specifies how to encode
selections for the window system. See Window System Selections.