Function: find-buffer-file-type-coding-system
find-buffer-file-type-coding-system is a byte-compiled function
defined in dos-w32.el.gz.
This function is obsolete since 24.4.
Signature
(find-buffer-file-type-coding-system COMMAND)
Documentation
Choose a coding system for a file operation in COMMAND.
COMMAND is a list that specifies the operation, an I/O primitive, as its
CAR, and the arguments that might be given to that operation as its CDR.
If operation is insert-file-contents, the coding system is chosen based
upon the filename (the CAR of the arguments beyond the operation), the contents
of w32-untranslated-filesystem-list and file-name-buffer-file-type-alist,
and whether the file exists:
If it matches in w32-untranslated-filesystem-list:
If the file exists: undecided
If the file does not exist: undecided-unix
Otherwise:
If the file exists: undecided
If the file does not exist default value of buffer-file-coding-system
Note that the CAR of arguments to insert-file-contents operation could
be a cons cell of the form (FILENAME . BUFFER), where BUFFER is a buffer
into which the file's contents were already read, but not yet decoded.
If operation is write-region, the coding system is chosen based
upon the value of buffer-file-coding-system. If
buffer-file-coding-system is non-nil, its value is used.
Otherwise, it is undecided-dos.
The most common situation is when DOS and Unix files are read and
written, and their names do not match in w32-untranslated-filesystem-list.
In these cases, the coding system initially will be undecided.
As the file is read in the DOS case, the coding system will be
changed to undecided-dos as CR/LFs are detected. As the file
is read in the Unix case, the coding system will be changed to
undecided-unix as LFs are detected. In both cases,
buffer-file-coding-system will be set to the appropriate coding
system, and the value of buffer-file-coding-system will be used
when writing the file.
Source Code
;; Defined in /usr/src/emacs/lisp/dos-w32.el.gz
(defun find-buffer-file-type-coding-system (command)
"Choose a coding system for a file operation in COMMAND.
COMMAND is a list that specifies the operation, an I/O primitive, as its
CAR, and the arguments that might be given to that operation as its CDR.
If operation is `insert-file-contents', the coding system is chosen based
upon the filename (the CAR of the arguments beyond the operation), the contents
of `w32-untranslated-filesystem-list' and `file-name-buffer-file-type-alist',
and whether the file exists:
If it matches in `w32-untranslated-filesystem-list':
If the file exists: `undecided'
If the file does not exist: `undecided-unix'
Otherwise:
If the file exists: `undecided'
If the file does not exist default value of `buffer-file-coding-system'
Note that the CAR of arguments to `insert-file-contents' operation could
be a cons cell of the form (FILENAME . BUFFER), where BUFFER is a buffer
into which the file's contents were already read, but not yet decoded.
If operation is `write-region', the coding system is chosen based
upon the value of `buffer-file-coding-system'. If
`buffer-file-coding-system' is non-nil, its value is used.
Otherwise, it is `undecided-dos'.
The most common situation is when DOS and Unix files are read and
written, and their names do not match in `w32-untranslated-filesystem-list'.
In these cases, the coding system initially will be `undecided'.
As the file is read in the DOS case, the coding system will be
changed to `undecided-dos' as CR/LFs are detected. As the file
is read in the Unix case, the coding system will be changed to
`undecided-unix' as LFs are detected. In both cases,
`buffer-file-coding-system' will be set to the appropriate coding
system, and the value of `buffer-file-coding-system' will be used
when writing the file."
(let ((op (nth 0 command))
(undecided nil) (undecided-unix nil)
target target-buf)
(cond ((eq op 'insert-file-contents)
(setq target (nth 1 command))
;; If TARGET is a cons cell, it has the form (FILENAME . BUFFER),
;; where BUFFER is a buffer into which the file was already read,
;; but its contents were not yet decoded. (This form of the
;; arguments is used, e.g., in arc-mode.el.) This function
;; doesn't care about the contents, it only looks at the file's
;; name, which is the CAR of the cons cell.
(when (consp target)
(setq target-buf
(and (bufferp (cdr target))
(buffer-name (cdr target))))
(setq target (car target)))
(cond ((or
;; For any existing file, decide based on contents.
(file-exists-p target)
;; If TARGET does not exist as a file, replace its
;; base name with TARGET-BUF and try again. This
;; is for jka-compr's sake, which strips the
;; compression (.gz etc.) extension from the
;; FILENAME, but leaves it in the BUFFER's name.
(and (stringp target-buf)
(file-exists-p
(expand-file-name target-buf
(file-name-directory target)))))
(setq undecided t))
;; Next check for a non-DOS file system.
((w32-untranslated-file-p target)
(setq undecided-unix t)))
(cond (undecided-unix '(undecided-unix . undecided-unix))
(undecided '(undecided . undecided))
(t (cons (default-value 'buffer-file-coding-system)
(default-value 'buffer-file-coding-system)))))
((eq op 'write-region)
(if buffer-file-coding-system
(cons buffer-file-coding-system
buffer-file-coding-system)
;; Normally this is used only in a non-file-visiting
;; buffer, because normally buffer-file-coding-system is non-nil
;; in a file-visiting buffer.
'(undecided-dos . undecided-dos))))))