Function: diff

diff is an autoloaded, interactive and byte-compiled function defined in diff.el.gz.

Signature

(diff OLD NEW &optional SWITCHES NO-ASYNC)

Documentation

Find and display the differences between OLD and NEW files.

When called interactively, read NEW, then OLD, using the minibuffer. The default for NEW is the current buffer's file name, and the default for OLD is a backup file for NEW, if one exists. If NO-ASYNC is non-nil, call diff synchronously.

When called interactively with a prefix argument SWITCHES, prompt interactively for diff switches. Otherwise, the switches specified in the variable diff-switches(var)/diff-switches(fun) are passed to the diff command.

Non-interactively, OLD and NEW may each be a file or a buffer.

View in manual

Probably introduced at or before Emacs version 19.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff.el.gz
;;;###autoload
(defun diff (old new &optional switches no-async)
  "Find and display the differences between OLD and NEW files.
When called interactively, read NEW, then OLD, using the
minibuffer.  The default for NEW is the current buffer's file
name, and the default for OLD is a backup file for NEW, if one
exists.  If NO-ASYNC is non-nil, call diff synchronously.

When called interactively with a prefix argument SWITCHES, prompt
interactively for diff switches.  Otherwise, the switches
specified in the variable `diff-switches' are passed to the diff
command.

Non-interactively, OLD and NEW may each be a file or a buffer."
  (interactive
   (let* ((newf (if (and buffer-file-name (file-exists-p buffer-file-name))
		    (read-file-name
                     (format-prompt "Diff new file"
                                    (file-name-nondirectory buffer-file-name))
		     nil buffer-file-name t)
		  (read-file-name "Diff new file: " nil nil t)))
          (oldf (file-newest-backup newf)))
     (setq oldf (if (and oldf (file-exists-p oldf))
		    (read-file-name
                     (format-prompt "Diff original file"
                                    (file-name-nondirectory oldf))
		     (file-name-directory oldf) oldf t)
		  (read-file-name "Diff original file: "
				  (file-name-directory newf) nil t)))
     (list oldf newf (diff-switches))))
  (display-buffer
   (diff-no-select old new switches no-async)))