Set the new user option 'diff-font-lock-prettify' to t for that, see
below under "Diff mode".
+---
+*** The 'diff' function arguments OLD and NEW may each be a buffer
+rather than a file, in non-interactive calls. This change was made in
+Emacs 24.1, but wasn't documented until now.
+
++++
+*** New command 'diff-buffers' interactively diffs two buffers.
+
** Diff mode
+++
*** Hunks are now automatically refined by font-lock.
When called interactively with a prefix argument, prompt
interactively for diff switches. Otherwise, the switches
-specified in the variable `diff-switches' are passed to the diff command."
+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
(diff-no-select old new switches no-async)))
(defun diff-file-local-copy (file-or-buf)
+ "Like `file-local-copy' but also supports a buffer as the argument.
+When FILE-OR-BUF is a buffer, return the filename of a local
+temporary file with the buffer's contents."
(if (bufferp file-or-buf)
(with-current-buffer file-or-buf
(let ((tempfile (make-temp-file "buffer-content-")))
(defun diff-no-select (old new &optional switches no-async buf)
;; Noninteractive helper for creating and reverting diff buffers
+ "Compare the OLD and NEW file/buffer, and return a diff buffer.
+
+See `diff' for the meaning of the arguments."
(unless (bufferp new) (setq new (expand-file-name new)))
(unless (bufferp old) (setq old (expand-file-name old)))
(or switches (setq switches diff-switches)) ; If not specified, use default.
(with-current-buffer (or (buffer-base-buffer buf) buf)
(diff buffer-file-name (current-buffer) nil 'noasync))))
+;;;###autoload
+(defun diff-buffers (old new &optional switches no-async)
+ "Find and display the differences between OLD and NEW buffers.
+
+When called interactively, read NEW, then OLD, using the
+minibuffer. The default for NEW is the current buffer, and the
+default for OLD is the most recently selected other buffer.
+If NO-ASYNC is non-nil, call diff synchronously.
+
+When called interactively with a prefix argument, prompt
+interactively for diff switches. Otherwise, the switches
+specified in the variable `diff-switches' are passed to the
+diff command.
+
+OLD and NEW may each be a buffer or a buffer name."
+ (interactive
+ (let ((newb (read-buffer "Diff new buffer" (current-buffer) t))
+ (oldb (read-buffer "Diff original buffer"
+ (other-buffer (current-buffer) t) t)))
+ (list oldb newb (diff-switches))))
+ (diff (get-buffer old) (get-buffer new) switches no-async))
+
(provide 'diff)
;;; diff.el ends here