From: morioka Date: Fri, 4 Jun 1999 10:06:57 +0000 (+0000) Subject: (insert-file-contents-literacy-treats-binary): New facility. X-Git-Tag: apel-9_20~34 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a1a7cda85bae45f5878d325ebd703cf0a7e3512;p=elisp%2Fapel.git (insert-file-contents-literacy-treats-binary): New facility. (insert-file-contents-literacy-treats-file-name-handler): New facility. (insert-file-contents-as-binary): Define as an alias for `insert-file-contents-literally' if it is not broken. --- diff --git a/pces-xfc.el b/pces-xfc.el index d6d03e4..c02661e 100644 --- a/pces-xfc.el +++ b/pces-xfc.el @@ -46,31 +46,72 @@ ;;; @ without code-conversion ;;; -(defun insert-file-contents-as-binary (filename - &optional visit beg end replace) - "Like `insert-file-contents', but only reads in the file literally. +(require 'broken) + +(broken-facility insert-file-contents-literacy-treats-binary + "Function `insert-file-contents-literacy' decodes text." + (let ((str "\xa1\xa3") + (coding-system-for-write 'binary) + (coding-system-for-read 'euc-jp)) + (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-literacy-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-literacy-treats-binary) + (broken-p 'insert-file-contents-literacy-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))))) + (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) + ) ;;; @ end