Function: mm-insert-file-contents

mm-insert-file-contents is a byte-compiled function defined in mm-util.el.gz.

Signature

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

Documentation

Like insert-file-contents, but only reads in the file.

A buffer may be modified in several ways after reading into the buffer due to advanced Emacs features, such as file-name-handlers, format decoding, find-file-hook, etc. If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers. This function ensures that none of these modifications will take place.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/mm-util.el.gz
(defun mm-insert-file-contents (filename &optional visit beg end replace
					 inhibit)
  "Like `insert-file-contents', but only reads in the file.
A buffer may be modified in several ways after reading into the buffer due
to advanced Emacs features, such as file-name-handlers, format decoding,
`find-file-hook', etc.
If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'.
This function ensures that none of these modifications will take place."
  (cl-letf* ((format-alist nil)
             ;; FIXME: insert-file-contents doesn't look at auto-mode-alist,
             ;; nor at (default-value 'major-mode)!
             (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
             ((default-value 'major-mode) 'fundamental-mode)
             ;; FIXME: neither enable-local-variables nor enable-local-eval are
             ;; run by insert-file-contents, AFAICT?!
             (enable-local-variables nil)
             (after-insert-file-functions nil)
             (enable-local-eval nil)
             (inhibit-file-name-operation (if inhibit
                                              'insert-file-contents
                                            inhibit-file-name-operation))
             (inhibit-file-name-handlers
              (if inhibit
                  (append mm-inhibit-file-name-handlers
                          inhibit-file-name-handlers)
                inhibit-file-name-handlers))
             ;; FIXME: insert-file-contents doesn't run find-file-hook anyway!
	     (find-file-hook nil))
    (insert-file-contents filename visit beg end replace)))