[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

33.10.6 Specifying a Coding System for One Operation

You can specify the coding system for a specific operation by binding the variables coding-system-for-read and/or coding-system-for-write.

Variable: coding-system-for-read
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 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.
;; 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, including file-coding-system-alist, process-coding-system-alist and network-coding-system-alist.

Variable: coding-system-for-write
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 and start-process, both coding-system-for-read and coding-system-for-write affect it.

Variable: inhibit-eol-conversion
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 section 33.10.7 Explicit Encoding and Decoding).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May 2, 2002 using texi2html