Function: mm-find-buffer-file-coding-system

mm-find-buffer-file-coding-system is a byte-compiled function defined in mm-util.el.gz.

Signature

(mm-find-buffer-file-coding-system &optional FILENAME)

Documentation

Find coding system used to decode the contents of the current buffer.

This function looks for the coding system magic cookie or examines the coding system specified by file-coding-system-alist being associated with FILENAME which defaults to buffer-file-name(var)/buffer-file-name(fun). Data compressed by gzip, bzip2, etc. are allowed.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/mm-util.el.gz
(defun mm-find-buffer-file-coding-system (&optional filename)
  "Find coding system used to decode the contents of the current buffer.
This function looks for the coding system magic cookie or examines the
coding system specified by `file-coding-system-alist' being associated
with FILENAME which defaults to `buffer-file-name'.  Data compressed by
gzip, bzip2, etc. are allowed."
  (unless filename
    (setq filename buffer-file-name))
  (save-excursion
    (let ((decomp (unless ;; Not worth it to examine charset of tar files.
		      (and filename
			   (string-match
			    "\\.\\(?:tar\\.[^.]+\\|tbz\\|tgz\\)\\'"
			    filename))
		    (mm-decompress-buffer filename nil t))))
      (when decomp
	(set-buffer (generate-new-buffer " *temp*"))
        (mm-disable-multibyte)
	(insert decomp)
	(setq filename (file-name-sans-extension filename)))
      (goto-char (point-min))
      (unwind-protect
	  (if filename
	      (or (funcall (symbol-value 'set-auto-coding-function)
			   filename (- (point-max) (point-min)))
		  (car (find-operation-coding-system 'insert-file-contents
						     filename)))
	    (let (auto-coding-alist)
	      (condition-case nil
		  (funcall (symbol-value 'set-auto-coding-function)
			   nil (- (point-max) (point-min)))
		(error nil))))
	(when decomp
	  (kill-buffer (current-buffer)))))))