Function: find-operation-coding-system
find-operation-coding-system is a function defined in coding.c.
Signature
(find-operation-coding-system OPERATION ARGUMENTS...)
Documentation
Choose a coding system for an operation based on the target name.
The value names a pair of coding systems: (DECODING-SYSTEM . ENCODING-SYSTEM).
DECODING-SYSTEM is the coding system to use for decoding
(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system
for encoding (in case OPERATION does encoding).
The first argument OPERATION specifies an I/O primitive:
For file I/O, insert-file-contents or write-region.
For process I/O, call-process, call-process-region, or start-process.
For network I/O, open-network-stream.
The remaining arguments should be the same arguments that were passed to the primitive. Depending on which primitive, one of those arguments is selected as the TARGET. For example, if OPERATION does file I/O, whichever argument specifies the file name is TARGET.
TARGET has a meaning which depends on OPERATION:
For file I/O, TARGET is a file name (except for the special case below).
For process I/O, TARGET is a process name.
For network I/O, TARGET is a service name or a port number.
This function looks up what is specified for TARGET in
file-coding-system-alist, process-coding-system-alist,
or network-coding-system-alist depending on OPERATION.
They may specify a coding system, a cons of coding systems,
or a function symbol to call.
In the last case, we call the function with one argument,
which is a list of all the arguments given to this function.
If the function can't decide a coding system, it can return
undecided so that the normal code-detection is performed.
If OPERATION is insert-file-contents, the argument corresponding to
TARGET may be a cons (FILENAME . BUFFER). In that case, FILENAME is a
file name to look up, and BUFFER is a buffer that contains the file's
contents (not yet decoded). If file-coding-system-alist specifies a
function to call for FILENAME, that function should examine the
contents of BUFFER instead of reading the file.
Probably introduced at or before Emacs version 22.1.
Source Code
// Defined in /usr/src/emacs/src/coding.c
{
Lisp_Object operation, target_idx, target, val;
register Lisp_Object chain;
if (nargs < 2)
error ("Too few arguments");
operation = args[0];
if (!SYMBOLP (operation)
|| (target_idx = Fget (operation, Qtarget_idx), !FIXNATP (target_idx)))
error ("Invalid first argument");
if (nargs <= 1 + XFIXNAT (target_idx))
error ("Too few arguments for operation `%s'",
SDATA (SYMBOL_NAME (operation)));
target = args[XFIXNAT (target_idx) + 1];
if (!(STRINGP (target)
|| (EQ (operation, Qinsert_file_contents) && CONSP (target)
&& STRINGP (XCAR (target)) && BUFFERP (XCDR (target)))
|| (EQ (operation, Qopen_network_stream)
&& (FIXNUMP (target) || EQ (target, Qt)))))
error ("Invalid argument %"pI"d of operation `%s'",
XFIXNAT (target_idx) + 1, SDATA (SYMBOL_NAME (operation)));
if (CONSP (target))
target = XCAR (target);
chain = ((EQ (operation, Qinsert_file_contents)
|| EQ (operation, Qwrite_region))
? Vfile_coding_system_alist
: (EQ (operation, Qopen_network_stream)
? Vnetwork_coding_system_alist
: Vprocess_coding_system_alist));
if (NILP (chain))
return Qnil;
for (; CONSP (chain); chain = XCDR (chain))
{
Lisp_Object elt;
elt = XCAR (chain);
if (CONSP (elt)
&& ((STRINGP (target)
&& STRINGP (XCAR (elt))
&& fast_string_match (XCAR (elt), target) >= 0)
|| (FIXNUMP (target) && BASE_EQ (target, XCAR (elt)))))
{
val = XCDR (elt);
/* Here, if VAL is both a valid coding system and a valid
function symbol, we return VAL as a coding system. */
if (CONSP (val))
return val;
if (! SYMBOLP (val))
return Qnil;
if (! NILP (Fcoding_system_p (val)))
return Fcons (val, val);
if (! NILP (Ffboundp (val)))
{
/* We use calln rather than safe_calln
so as to get bug reports about functions called here
which don't handle the current interface. */
val = calln (val, Flist (nargs, args));
if (CONSP (val))
return val;
if (SYMBOLP (val) && ! NILP (Fcoding_system_p (val)))
return Fcons (val, val);
}
return Qnil;
}
}
return Qnil;
}