Function: info-insert-file-contents

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

Signature

(info-insert-file-contents FILENAME &optional VISIT)

Documentation

Insert the contents of an Info file in the current buffer.

Do the right thing if the file has been compressed or zipped.

Source Code

;; Defined in /usr/src/emacs/lisp/info.el.gz
(defun info-insert-file-contents (filename &optional visit)
  "Insert the contents of an Info file in the current buffer.
Do the right thing if the file has been compressed or zipped."
  (let* ((tail Info-suffix-list)
	 (jka-compr-verbose nil)
	 (lfn (if (fboundp 'msdos-long-file-names)
		  (msdos-long-file-names)
		t))
	 (check-short (and (fboundp 'msdos-long-file-names)
			   lfn))
	 fullname decoder done)
    (if (info-file-exists-p filename)
	;; FILENAME exists--see if that name contains a suffix.
	;; If so, set DECODE accordingly.
	(progn
	  (while (and tail
		      (not (string-match
			    (concat (regexp-quote (car (car tail))) "$")
			    filename)))
	    (setq tail (cdr tail)))
	  (setq fullname filename
		decoder (cdr (car tail))))
      ;; Try adding suffixes to FILENAME and see if we can find something.
      (while (and tail (not done))
	(setq fullname (info-insert-file-contents-1 filename
						    (car (car tail)) lfn))
	(if (info-file-exists-p fullname)
	    (setq done t
		  ;; If we found a file with a suffix, set DECODER
		  ;; according to the suffix.
		  decoder (cdr (car tail)))
	  ;; When the MS-DOS port runs on Windows, we need to check
	  ;; the short variant of a long file name as well.
	  (when check-short
	    (setq fullname (info-insert-file-contents-1 filename
							(car (car tail)) nil))
	    (if (info-file-exists-p fullname)
		(setq done t
		      decoder (cdr (car tail))))))
	(setq tail (cdr tail)))
      (or tail
	  (error "Can't find %s or any compressed version of it" filename)))
    ;; check for conflict with jka-compr
    (if (and (jka-compr-installed-p)
	     (jka-compr-get-compression-info fullname))
	(setq decoder nil))
    (if decoder
	(progn
	  (insert-file-contents-literally fullname visit)
	  (let ((inhibit-read-only t)
		(coding-system-for-write 'no-conversion)
		(inhibit-null-byte-detection t) ; Index nodes include null bytes
		(default-directory (or (file-name-directory fullname)
				       default-directory)))
	    (or (consp decoder)
		(setq decoder (list decoder)))
	    (apply #'call-process-region (point-min) (point-max)
		   (car decoder) t t nil (cdr decoder))))
      (let ((inhibit-null-byte-detection t)) ; Index nodes include null bytes
	(insert-file-contents fullname visit)))

    ;; Clear the caches of modified Info files.
    (let* ((attribs-old (cdr (assoc fullname Info-file-attributes)))
	   (modtime-old (and attribs-old
			     (file-attribute-modification-time attribs-old)))
	   (attribs-new (and (stringp fullname) (file-attributes fullname)))
	   (modtime-new (and attribs-new
			     (file-attribute-modification-time attribs-new))))
      (when (and modtime-old modtime-new
		 (time-less-p modtime-old modtime-new))
	(setq Info-index-nodes (remove (assoc (or Info-current-file filename)
					      Info-index-nodes)
				       Info-index-nodes))
	(setq Info-toc-nodes (remove (assoc (or Info-current-file filename)
					    Info-toc-nodes)
				     Info-toc-nodes)))
      ;; Add new modtime to `Info-file-attributes'.
      (setq Info-file-attributes
	    (cons (cons fullname attribs-new)
		  (remove (assoc fullname Info-file-attributes)
			  Info-file-attributes))))))