Function: insert-file-contents-literally

insert-file-contents-literally is a byte-compiled function defined in files.el.gz.

Signature

(insert-file-contents-literally FILENAME &optional VISIT BEG END REPLACE)

Documentation

Like insert-file-contents, but only read in the file literally.

See insert-file-contents for an explanation of the parameters. A buffer may be modified in several ways after reading into the buffer, due to Emacs features such as format decoding, character code conversion, find-file-hook, automatic uncompression, etc.

This function ensures that none of these modifications will take place.

Unlike find-file-literally(var)/find-file-literally(fun), this function does not make the buffer unibyte, so if this function is used when handling binary (non-character) data, it can be convenient to make the buffer unibyte first. This isn't, strictly speaking, necessary, because multibyte buffers can also deal with raw bytes. See info node (elisp)Character Codes for details.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 19.30.

Shortdoc

;; file
(insert-file-contents-literally "/tmp/foo")
    e.g. => ("/tmp/foo" 6)

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun insert-file-contents-literally (filename &optional visit beg end replace)
  "Like `insert-file-contents', but only read in the file literally.
See `insert-file-contents' for an explanation of the parameters.
A buffer may be modified in several ways after reading into the buffer,
due to Emacs features such as format decoding, character code
conversion, `find-file-hook', automatic uncompression, etc.

This function ensures that none of these modifications will take place.

Unlike `find-file-literally', this function does not make the
buffer unibyte, so if this function is used when handling
binary (non-character) data, it can be convenient to make the
buffer unibyte first.  This isn't, strictly speaking, necessary,
because multibyte buffers can also deal with raw bytes.  See info
node `(elisp)Character Codes' for details."
  (let ((format-alist nil)
	(after-insert-file-functions nil)
	(coding-system-for-read 'no-conversion)
	(coding-system-for-write 'no-conversion)
        (inhibit-file-name-handlers
         ;; FIXME: Yuck!!  We should turn insert-file-contents-literally
         ;; into a file operation instead!
         (append '(jka-compr-handler image-file-handler epa-file-handler)
                 (and (eq inhibit-file-name-operation 'insert-file-contents)
		      inhibit-file-name-handlers)))
        (inhibit-file-name-operation 'insert-file-contents))
    (insert-file-contents filename visit beg end replace)))