Function: ediff-make-temp-file

ediff-make-temp-file is a byte-compiled function defined in ediff-util.el.gz.

Signature

(ediff-make-temp-file BUFF &optional PREFIX GIVEN-FILE START END)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/ediff-util.el.gz
;; If PREFIX is given, then it is used as a prefix for the temp file
;; name.  Otherwise, `ediff' is used.  If FILE is given, use this
;; file and don't create a new one.
;; In MS-DOS, make sure the prefix isn't too long, or else
;; `make-temp-name' isn't guaranteed to return a unique filename.
;; Also, save buffer from START to END in the file.
;; START defaults to (point-min), END to (point-max)
(defun ediff-make-temp-file (buff &optional prefix given-file start end)
  (let* ((p (convert-standard-filename (or prefix "ediff")))
	 (short-p p)
	 (coding-system-for-write ediff-coding-system-for-write)
	 f short-f)
    (if (and (fboundp 'msdos-long-file-names)
	     (not (msdos-long-file-names))
	     (> (length p) 2))
	(setq short-p (substring p 0 2)))

    (setq f (concat temporary-file-directory p)
          short-f (concat temporary-file-directory short-p)
          f (cond (given-file)
		  ((find-file-name-handler f 'insert-file-contents)
		   ;; to thwart file name handlers in write-region,
		   ;; e.g., if file name ends with .Z or .gz
                   ;; This is needed so that patches produced by ediff will
		   ;; have more meaningful names
		   (ediff-make-empty-tmp-file short-f))
		  (prefix
		   ;; Prefix is most often the same as the file name for the
		   ;; variant.  Here we are trying to use the original file
		   ;; name but in the temp directory.
		   (ediff-make-empty-tmp-file f 'keep-name))
		  (t
		   ;; If don't care about name, add some random stuff
		   ;; to proposed file name.
		   (ediff-make-empty-tmp-file short-f))))

    ;; create the file
    (ediff-with-current-buffer buff
      (write-region (if start start (point-min))
		    (if end end (point-max))
		    f
		    nil          ; don't append---erase
		    'no-message)
      (set-file-modes f ediff-temp-file-mode)
      (expand-file-name f))))