Function: format-insert-file

format-insert-file is an interactive and byte-compiled function defined in format.el.gz.

Signature

(format-insert-file FILENAME FORMAT &optional BEG END)

Documentation

Insert the contents of file FILENAME using data format FORMAT.

If FORMAT is nil then do not do any format conversion. The optional third and fourth arguments BEG and END specify the part (in bytes) of the file to read.

The return value is like the value of insert-file-contents: a list (ABSOLUTE-FILE-NAME SIZE).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/format.el.gz
(defun format-insert-file (filename format &optional beg end)
  "Insert the contents of file FILENAME using data format FORMAT.
If FORMAT is nil then do not do any format conversion.
The optional third and fourth arguments BEG and END specify
the part (in bytes) of the file to read.

The return value is like the value of `insert-file-contents':
a list (ABSOLUTE-FILE-NAME SIZE)."
  (interactive
   ;; Same interactive spec as write-file, plus format question.
   (let* ((file (read-file-name "Find file: "))
	  (fmt (format-read (format-message "Read file `%s' in format: "
                                            (file-name-nondirectory file)))))
     (list file fmt)))
  (let (value size old-undo)
    ;; Record only one undo entry for the insertion.  Inhibit point-motion and
    ;; modification hooks as with `insert-file-contents'.
    (let ((inhibit-point-motion-hooks t)
	  (inhibit-modification-hooks t))
      ;; Don't bind `buffer-undo-list' to t here to assert that
      ;; `insert-file-contents' may record whether the buffer was unmodified
      ;; before.
      (let ((format-alist nil))
	(setq value (insert-file-contents filename nil beg end))
	(setq size (nth 1 value)))
      (when (consp buffer-undo-list)
	(let ((head (car buffer-undo-list)))
	  (when (and (consp head)
		     (equal (car head) (point))
		     (equal (cdr head) (+ (point) size)))
	    ;; Remove first entry from `buffer-undo-list', we shall insert
	    ;; another one below.
	    (setq old-undo (cdr buffer-undo-list)))))
      (when format
	(let ((buffer-undo-list t))
	  (setq size (format-decode format size)
		value (list (car value) size)))
	(unless (eq buffer-undo-list t)
	  (setq buffer-undo-list
		(cons (cons (point) (+ (point) size)) old-undo)))))
    (unless inhibit-modification-hooks
      (run-hook-with-args 'after-change-functions (point) (+ (point) size) 0))
    value))