Next: Explicit Encoding, Previous: Default Coding Systems, Up: Coding Systems
You can specify the coding system for a specific operation by binding
the variables coding-system-for-read
and/or
coding-system-for-write
.
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-read
when 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
let
for a specific I/O operation. Its global value is normallynil
, 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. ;; Assume crlf represents end-of-line. (let ((coding-system-for-write 'emacs-mule-dos)) (insert-file-contents filename))When its value is non-
nil
,coding-system-for-read
takes precedence over all other methods of specifying a coding system to use for input, includingfile-coding-system-alist
,process-coding-system-alist
andnetwork-coding-system-alist
.
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.When a single operation does both input and output, as do
call-process-region
andstart-process
, bothcoding-system-for-read
andcoding-system-for-write
affect it.
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).