From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rogers-emacs@rgrjr.dyndns.org Newsgroups: gmane.emacs.bugs Subject: bug#7277: 24.0.50; Can't revert diff-buffer-with-file Date: Sun, 24 Oct 2010 16:30:17 -0400 Message-ID: <19652.38745.217242.560815@rgr.rgrjr.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OZLX+CkR23" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1287953227 12571 80.91.229.12 (24 Oct 2010 20:47:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 24 Oct 2010 20:47:07 +0000 (UTC) To: 7277@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 24 22:47:06 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PA7T7-0001mK-2h for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Oct 2010 22:47:06 +0200 Original-Received: from localhost ([127.0.0.1]:37275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PA7T6-000351-DP for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Oct 2010 16:47:04 -0400 Original-Received: from [140.186.70.92] (port=44856 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PA7Sy-0002zK-WA for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:46:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PA7P3-00027N-6e for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:42:54 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PA7P3-00027H-0i for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:42:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PA79i-0007Oo-11; Sun, 24 Oct 2010 16:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: rogers-emacs@rgrjr.dyndns.org Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Oct 2010 20:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 7277 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.128795198728434 (code B ref -1); Sun, 24 Oct 2010 20:27:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Oct 2010 20:26:27 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PA798-0007OZ-Tk for submit@debbugs.gnu.org; Sun, 24 Oct 2010 16:26:27 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PA796-0007OT-Ck for submit@debbugs.gnu.org; Sun, 24 Oct 2010 16:26:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PA7Cw-0008Q8-R0 for submit@debbugs.gnu.org; Sun, 24 Oct 2010 16:30:24 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:50946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PA7Cw-0008Q4-Nk for submit@debbugs.gnu.org; Sun, 24 Oct 2010 16:30:22 -0400 Original-Received: from [140.186.70.92] (port=45983 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PA7Cv-0000TA-I3 for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:30:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PA7Cu-0008Pt-6J for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:30:21 -0400 Original-Received: from rgrjr.com ([216.146.47.5]:42387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PA7Cu-0008Pm-2o for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2010 16:30:20 -0400 Original-Received: from rgrjr.dyndns.org (c-66-30-196-77.hsd1.ma.comcast.net [66.30.196.77]) by rgrjr.com (Postfix on CentOS) with ESMTP id 0081E1600FB for ; Sun, 24 Oct 2010 20:30:18 +0000 (UTC) Original-Received: (qmail 27303 invoked by uid 89); 24 Oct 2010 20:30:18 -0000 Original-Received: from unknown (HELO rgr.rgrjr.com) (192.168.57.1) by home with SMTP; 24 Oct 2010 20:30:18 -0000 Original-Received: by rgr.rgrjr.com (Postfix, from userid 500) id C14DDA4E03; Sun, 24 Oct 2010 16:30:17 -0400 (EDT) X-Mailer: VM 7.19 under Emacs 24.0.50.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 24 Oct 2010 16:27:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:41119 Archived-At: --OZLX+CkR23 Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit The problem, of course, is that the temp file is deleted shortly after "diff" exits, so the default revert-buffer function installed by "diff" fails. The simplest solution seems to be to install a new revert-buffer function that redoes the whole process of checking for a file buffer and writing the temp file. The attached patch does a minimal refactoring of "diff" and "diff-buffer-with-file" to do just that, while trying to DTRT if the user renames the diff buffer or kills the original buffer. -- Bob Rogers http://www.rgrjr.com/ --OZLX+CkR23 Content-Type: text/plain Content-Description: Content-Disposition: inline; filename="diff-buffer-revert-1.patch" Content-Transfer-Encoding: 7bit diff --git a/lisp/files.el b/lisp/files.el index d5f60b7..603c014 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4512,24 +4512,42 @@ Before and after saving the buffer, this function runs "View the differences between BUFFER and its associated file. This requires the external program `diff' to be in your `exec-path'." (interactive "bBuffer: ") - (with-current-buffer (get-buffer (or buffer (current-buffer))) + (diff-buffer-internal (get-buffer (or buffer (current-buffer))) + (get-buffer-create "*Diff*")) + ;; return always nil, so that save-buffers-kill-emacs will not move + ;; over to the next unsaved buffer when calling `d'. + nil) + +(defvar diff-buffer-buffer) ;; suppress compiler warnings. + +(defun diff-buffer-internal (buffer result-buffer) + (if (not (and buffer (buffer-name buffer))) + (error "Original buffer deleted.")) + (with-current-buffer buffer (if (and buffer-file-name (file-exists-p buffer-file-name)) (let ((tempfile (make-temp-file "buffer-content-"))) (unwind-protect (progn (write-region nil nil tempfile nil 'nomessage) - (diff buffer-file-name tempfile nil t) - (sit-for 0)) + ;; No asynch so we don't delete the temp file prematurely. + (diff-into-buffer result-buffer buffer-file-name tempfile + nil t) + (sit-for 0) + ;; Now revise the revert-buffer-function, since the + ;; default will not be able to find the temp file. + (with-current-buffer result-buffer + (set (make-local-variable 'diff-buffer-buffer) buffer) + (setq revert-buffer-function + (lambda (ignore-auto noconfirm) + (diff-buffer-internal diff-buffer-buffer + (current-buffer)))))) (when (file-exists-p tempfile) (delete-file tempfile)))) (message "Buffer %s has no associated file on disc" (buffer-name)) ;; Display that message for 1 second so that user can read it ;; in the minibuffer. - (sit-for 1))) - ;; return always nil, so that save-buffers-kill-emacs will not move - ;; over to the next unsaved buffer when calling `d'. - nil) + (sit-for 1)))) (defvar save-some-buffers-action-alist `((?\C-r diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el index e79e72c..1a835b5 100644 --- a/lisp/vc/diff.el +++ b/lisp/vc/diff.el @@ -108,11 +108,16 @@ specified in `diff-switches' are passed to the diff command." (read-file-name "Diff original file: " (file-name-directory newf) nil t))) (list oldf newf (diff-switches)))) + (diff-into-buffer nil old new switches no-async)) + +(defun diff-into-buffer (buf old new &optional switches no-async) + ;; Noninteractive helper for creating and reverting diff buffers. (setq new (expand-file-name new) old (expand-file-name old)) (or switches (setq switches diff-switches)) ; If not specified, use default. + (or buf (setq buf (get-buffer-create "*Diff*"))) (let* ((old-alt (file-local-copy old)) - (new-alt (file-local-copy new)) + (new-alt (file-local-copy new)) (command (mapconcat 'identity `(,diff-command @@ -123,7 +128,6 @@ specified in `diff-switches' are passed to the diff command." ,(shell-quote-argument (or old-alt old)) ,(shell-quote-argument (or new-alt new))) " ")) - (buf (get-buffer-create "*Diff*")) (thisdir default-directory) proc) (save-excursion --OZLX+CkR23--