You can specify the coding system for a specific operation by binding
If this variable is non-
nil, it specifies the coding system to use for reading a file, or for input from a synchronous subprocess.
It also applies to any asynchronous subprocess or network stream, but in a different way: the value of
coding-system-for-readwhen you start the subprocess or open the network stream specifies the input decoding method for that subprocess or network stream. It remains in use for that subprocess or network stream unless and until overridden.
The right way to use this variable is to bind it with
letfor a specific I/O operation. Its global value is normally
nil, and you should not globally set it to any other value. Here is an example of the right way to use the variable:;; Read the file with no character code conversion. (let ((coding-system-for-read 'no-conversion)) (insert-file-contents filename))
When its value is non-
nil, this variable takes precedence over all other methods of specifying a coding system to use for input, including
This works much like
coding-system-for-read, except that it applies to output rather than input. It affects writing to files, as well as sending output to subprocesses and net connections. It also applies to encoding command-line arguments with which Emacs invokes subprocesses.
When a single operation does both input and output, as do
coding-system-for-writeto a non-
nilvalue prevents output primitives from calling the function specified by
select-safe-coding-system-function(see User-Chosen Coding Systems). This is because C-x RET c (
universal-coding-system-argument) works by binding
coding-system-for-write, and Emacs should obey user selection. If a Lisp program binds
coding-system-for-writeto a value that might not be safe for encoding the text to be written, it can also bind
coding-system-require-warningto a non-
nilvalue, which will force the output primitives to check the encoding by calling the value of
nil. Alternatively, call
select-safe-coding-systemexplicitly before using the specified encoding.
When this variable is non-
nil, no end-of-line conversion is done, no matter which coding system is specified. This applies to all the Emacs I/O and subprocess primitives, and to the explicit encoding and decoding functions (see Explicit Encoding).
Sometimes, you need to prefer several coding systems for some
operation, rather than fix a single one. Emacs lets you specify a
priority order for using coding systems. This ordering affects the
sorting of lists of coding systems returned by functions such as
find-coding-systems-region (see Lisp and Coding Systems).
This function returns the list of coding systems in the order of their current priorities. Optional argument highestp, if non-
nil, means return only the highest priority coding system.
This function puts coding-systems at the beginning of the priority list for coding systems, thus making their priority higher than all the rest.
This macro execute body, like
progndoes (see progn), with coding-systems at the front of the priority list for coding systems. coding-systems should be a list of coding systems to prefer during execution of body.