From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jpw@pobox.com (John Paul Wallington) Newsgroups: gmane.emacs.help Subject: Re: diffs between a buffer and the underlying file Date: Wed, 06 Sep 2006 01:18:10 +0100 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1157503235 1007 80.91.229.2 (6 Sep 2006 00:40:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 6 Sep 2006 00:40:35 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 06 02:40:33 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GKlSq-0001sd-EC for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Sep 2006 02:40:25 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKlSp-0004sT-UL for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Sep 2006 20:40:23 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!ndsoftware.com!zen.net.uk!dedekind.zen.co.uk!news-peer-lilac.gradwell.net!not-for-mail Original-Newsgroups: gnu.emacs.help X-Mailer: Norman X-Attribution: JPW X-Face: #uahb@^mo@bA"{q'"a4y[w$n3/V:haD\; YenWcT7)kXYx3/>#[DD9ExVe}; 9FG6X`l!Dm"V peub=u!&&?}s~{TOPtGdH)KA}/qCr; d"Gr*'9_V1PE@+K'tk2/Iq@PBKtJ+]&,CP9_Fl8'*R]LCR0| 6q; Xey'`:DX+)S.]p[KP^sNe`8B\W6(Nw{o5i)y+I!h=0bU5L`Tj`~Q0!G"t(s7o7eh)J\>P>,!~/w $$jGEVa%H%8(jTv User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:a3NTqxqsA+5juPUHEGbqWc7HB8Y= Original-Lines: 38 Original-NNTP-Posting-Host: 217.169.11.183 Original-X-Trace: 1157501904 news.aaisp.net.uk 638 217.169.11.183:1428 Original-X-Complaints-To: aaispnews-abuse@gradwell.net Original-Xref: shelby.stanford.edu gnu.emacs.help:141551 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:37172 Archived-At: Urs Thuermann writes: > I sometimes get into the following situation: I open a file, make > some changes, then I want to see the changes before saving the file. The development version of Emacs has M-x diff-buffer-with-file that does what you want. If you are using a release version of Emacs then you could try putting this in your .emacs file (untested): (defun diff-buffer-with-file (&optional buffer) "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))) (if (and buffer-file-name (file-exists-p buffer-file-name)) (let ((tempfile (make-temp-file "buffer-content-"))) (unwind-protect (save-restriction (widen) (write-region (point-min) (point-max) tempfile nil 'nomessage) (diff buffer-file-name tempfile nil t) (sit-for 0)) (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) Also, the Ibuffer library, an advanced replacement for the normal buffer menu, has an `ibuffer-diff-with-file' command that you can get by pressing =. Ibuffer is included in the development version of Emacs. Alternatively, a stable version of Ibuffer is available from http://www.shootybangbang.com/software/ibuffer.el