summaryrefslogtreecommitdiff
path: root/lisp/vc/diff.el
diff options
context:
space:
mode:
authorPhil Sainty <psainty@orcon.net.nz>2019-12-14 20:49:41 +1300
committerPhil Sainty <psainty@orcon.net.nz>2019-12-16 10:55:24 +1300
commit9b7f0de639e024dd7e546d6cd3148deb1067bd1b (patch)
treeec3f92797b619de1b4a34209fca473efe05688dd /lisp/vc/diff.el
parent9ee5af315098245d9f58eb5562dca6997cab4426 (diff)
downloademacs-9b7f0de639e024dd7e546d6cd3148deb1067bd1b.tar.gz
New command 'diff-buffers'
* lisp/vc/diff.el (diff-buffers): New command. (diff, diff-no-select, diff-file-local-copy): Improve docstrings. * doc/emacs/files.texi: * etc/NEWS: Document new command, and the previously-undocumented ability for 'diff' to compare buffers.
Diffstat (limited to 'lisp/vc/diff.el')
-rw-r--r--lisp/vc/diff.el33
1 files changed, 32 insertions, 1 deletions
diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el
index 9ece8bc1fb4..5b055a1620f 100644
--- a/lisp/vc/diff.el
+++ b/lisp/vc/diff.el
@@ -91,7 +91,10 @@ exists. 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."
+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
@@ -112,6 +115,9 @@ specified in the variable `diff-switches' are passed to the diff command."
(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-")))
@@ -139,6 +145,9 @@ Possible values are:
(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.
@@ -243,6 +252,28 @@ This requires the external program `diff' to be in your `exec-path'."
(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