From: morioka Date: Mon, 7 Jun 1999 10:52:46 +0000 (+0000) Subject: (insert-file-contents-literally-treats-binary): New facility [moved X-Git-Tag: apel-9_20~30 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70999acf2e3264e250e1b3923e087f438d12d689;p=elisp%2Fapel.git (insert-file-contents-literally-treats-binary): New facility [moved from pces-xfc.el]. (insert-file-contents-literally-treats-file-name-handler): Likewise. (insert-file-contents-as-binary): Define as an alias for `insert-file-contents-literally' if it is not broken. --- diff --git a/pces-20.el b/pces-20.el index 7f57a68..51335a7 100644 --- a/pces-20.el +++ b/pces-20.el @@ -1,5 +1,5 @@ ;;; -*-byte-compile-dynamic: t;-*- -;;; pces-20.el --- pces submodule for Emacs 20 and XEmacs-mule +;;; pces-20.el --- pces submodule for Emacs 20 and XEmacs with coding-system ;; Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. @@ -30,6 +30,12 @@ ;;; Code: +;; (defun-maybe-cond multibyte-string-p (object) +;; "Return t if OBJECT is a multibyte string." +;; ((featurep 'mule) (stringp object)) +;; (t nil)) + + ;;; @ without code-conversion ;;; @@ -54,9 +60,74 @@ jka-compr-compression-info-list jam-zcat-filename-list) (write-region start end filename append visit lockname))) -;; `insert-file-contents-literally' of Emacs 20 supports -;; `file-name-handler-alist'. -(defalias 'insert-file-contents-as-binary 'insert-file-contents-literally) +(require 'broken) + +(broken-facility insert-file-contents-literally-treats-binary + "Function `insert-file-contents-literally' decodes text." + (let* ((str "\r\n") + (coding-system-for-write 'binary) + (coding-system-for-read 'raw-text-dos) + ;; (default-enable-multibyte-characters (multibyte-string-p str)) + ) + (with-temp-buffer + (insert str) + (write-region (point-min)(point-max) "literal-test-file") + ) + (string= + (with-temp-buffer + (let (file-name-handler-alist) + (insert-file-contents-literally "literal-test-file") + ) + (buffer-string) + ) + str))) + +(broken-facility insert-file-contents-literally-treats-file-name-handler + "Function `insert-file-contents' doesn't call file-name-handler." + (let (called) + (with-temp-buffer + (let ((file-name-handler-alist + '(("literal-test-file" . (lambda (operation &rest args) + (setq called t) + (let (file-name-handler-alist) + (apply operation args) + )))))) + (insert-file-contents-literally "literal-test-file") + ) + (delete-file "literal-test-file") + ) + called)) + +(static-if + (or (broken-p 'insert-file-contents-literally-treats-binary) + (broken-p 'insert-file-contents-literally-treats-file-name-handler)) + (defun insert-file-contents-as-binary (filename + &optional visit beg end replace) + "Like `insert-file-contents', but only reads in the file literally. +A buffer may be modified in several ways after reading into the buffer, +to Emacs features such as format decoding, character code +conversion, find-file-hooks, automatic uncompression, etc. + +This function ensures that none of these modifications will take place." + (let ((format-alist nil) + (after-insert-file-functions nil) + (coding-system-for-read 'binary) + (coding-system-for-write 'binary) + (jka-compr-compression-info-list nil) + (jam-zcat-filename-list nil) + (find-buffer-file-type-function + (if (fboundp 'find-buffer-file-type) + (symbol-function 'find-buffer-file-type) + nil))) + (unwind-protect + (progn + (fset 'find-buffer-file-type (lambda (filename) t)) + (insert-file-contents filename visit beg end replace)) + (if find-buffer-file-type-function + (fset 'find-buffer-file-type find-buffer-file-type-function) + (fmakunbound 'find-buffer-file-type))))) + (defalias 'insert-file-contents-as-binary 'insert-file-contents-literally) + ) (defun insert-file-contents-as-raw-text (filename &optional visit beg end replace)