From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.bugs Subject: bug#38575: 27.0.50; Document that `diff' arguments OLD and NEW can be buffers Date: Sat, 14 Dec 2019 21:22:13 +1300 Message-ID: <6f1ee2d1-37ed-9e89-fb79-00be76689487@orcon.net.nz> References: <835zilaogo.fsf@gnu.org> <831rt9aiah.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FB9D129F1DE8FC3EEA9644DE" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="74138"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Cc: 38575@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 14 09:23:15 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ig2hn-000J9i-13 for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Dec 2019 09:23:15 +0100 Original-Received: from localhost ([::1]:57214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ig2hl-0007qC-QF for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Dec 2019 03:23:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46443) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ig2hd-0007q3-O0 for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2019 03:23:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ig2hb-0002RD-KS for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2019 03:23:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57195) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ig2ha-0002OR-Ec for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2019 03:23:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ig2ha-0008Bi-6A for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2019 03:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Dec 2019 08:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38575 X-GNU-PR-Package: emacs Original-Received: via spool by 38575-submit@debbugs.gnu.org id=B38575.157631173931405 (code B ref 38575); Sat, 14 Dec 2019 08:23:02 +0000 Original-Received: (at 38575) by debbugs.gnu.org; 14 Dec 2019 08:22:19 +0000 Original-Received: from localhost ([127.0.0.1]:34935 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ig2gt-0008AT-Gy for submit@debbugs.gnu.org; Sat, 14 Dec 2019 03:22:19 -0500 Original-Received: from smtp-2.orcon.net.nz ([60.234.4.43]:56051) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ig2gr-0008AI-6r for 38575@debbugs.gnu.org; Sat, 14 Dec 2019 03:22:18 -0500 Original-Received: from [116.251.203.246] (port=22727 helo=[192.168.20.103]) by smtp-2.orcon.net.nz with esmtpa (Exim 4.90_1) (envelope-from ) id 1ig2gn-0006Y3-Ae; Sat, 14 Dec 2019 21:22:13 +1300 In-Reply-To: <831rt9aiah.fsf@gnu.org> Content-Language: en-GB X-GeoIP: NZ X-Spam_score: -2.9 X-Spam_score_int: -28 X-Spam_bar: -- X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:173309 Archived-At: This is a multi-part message in MIME format. --------------FB9D129F1DE8FC3EEA9644DE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit I ended up adding a `diff-buffers' command to provide better user support for this feature. Patch attached for review. -Phil --------------FB9D129F1DE8FC3EEA9644DE Content-Type: text/x-patch; name="0001-New-command-diff-buffers.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-New-command-diff-buffers.patch" >From 3a9ce101aa9046f3f54b01b5fb37f21077a0f221 Mon Sep 17 00:00:00 2001 From: Phil Sainty Date: Sat, 14 Dec 2019 20:49:41 +1300 Subject: [PATCH] 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. --- doc/emacs/files.texi | 4 ++++ etc/NEWS | 8 ++++++++ lisp/vc/diff.el | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index c3ede18..7221edc 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1394,6 +1394,10 @@ Comparing Files buffer with its corresponding file. This shows you what changes you would make to the file if you save the buffer. +@findex diff-buffers + The command @kbd{M-x diff-buffers} compares the contents of two +specified buffers. + @findex compare-windows The command @kbd{M-x compare-windows} compares the text in the current window with that in the window that was the selected window diff --git a/etc/NEWS b/etc/NEWS index a7f3c3d..18ed8de 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1038,6 +1038,14 @@ is shown.) 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. diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el index 9ece8bc..5b055a1 100644 --- a/lisp/vc/diff.el +++ b/lisp/vc/diff.el @@ -91,7 +91,10 @@ diff 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 @@ diff (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 @@ diff-check-labels (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 @@ diff-buffer-with-file (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 -- 2.8.3 --------------FB9D129F1DE8FC3EEA9644DE--