all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* diffs between a buffer and the underlying file
@ 2006-09-05 16:39 Urs Thuermann
  2006-09-05 18:10 ` Eric Hanchrow
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Urs Thuermann @ 2006-09-05 16:39 UTC (permalink / raw)


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 best way to do this seems to be to set the region to the whole
buffer, write the region to some temporary file, and run diff on the
two files.  But I find this very unconvenient.

I'd like to have a function in emacs which can be applied to a buffer,
say buffer A, that opens a new buffer displaying all the changes
between the buffer A and the disk file, opened in buffer A.

Searching the emacs documentation I haven't found anything like this.
Only functions for diff'ing two buffers or two files.

urs

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-05 16:39 Urs Thuermann
@ 2006-09-05 18:10 ` Eric Hanchrow
  2006-09-06  0:18 ` John Paul Wallington
  2006-09-06  1:39 ` Drew Adams
  2 siblings, 0 replies; 16+ messages in thread
From: Eric Hanchrow @ 2006-09-05 18:10 UTC (permalink / raw)


I'm not sure this is quite what you're looking for, but: the NEWS for
CVS Emacs says 

*** C-x s (save-some-buffers) now offers an option `d' to diff a buffer
against its file, so you can see what changes you would be saving.

-- 
... there are any number of partisan Democrats lurking in
engineering departments and liberal moles in software-writing
offices.
        -- Molly Ivins

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-05 16:39 Urs Thuermann
  2006-09-05 18:10 ` Eric Hanchrow
@ 2006-09-06  0:18 ` John Paul Wallington
  2006-09-06  9:18   ` Romain Francoise
  2006-09-06  1:39 ` Drew Adams
  2 siblings, 1 reply; 16+ messages in thread
From: John Paul Wallington @ 2006-09-06  0:18 UTC (permalink / raw)


Urs Thuermann <urs@isnogud.escape.de> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: diffs between a buffer and the underlying file
  2006-09-05 16:39 Urs Thuermann
  2006-09-05 18:10 ` Eric Hanchrow
  2006-09-06  0:18 ` John Paul Wallington
@ 2006-09-06  1:39 ` Drew Adams
  2 siblings, 0 replies; 16+ messages in thread
From: Drew Adams @ 2006-09-06  1:39 UTC (permalink / raw)


    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 best way to do this seems to be to set the region to the whole
    buffer, write the region to some temporary file, and run diff on the
    two files.  But I find this very unconvenient.

    I'd like to have a function in emacs which can be applied to a buffer,
    say buffer A, that opens a new buffer displaying all the changes
    between the buffer A and the disk file, opened in buffer A.

    Searching the emacs documentation I haven't found anything like this.
    Only functions for diff'ing two buffers or two files.

You can always use ediff to compare any two buffers. So, with nothing extra,
you can 1) rename buffer A as foo, 2) re-read file A into buffer A, and 3)
compare buffers foo and A. The commands for this are 1) M-x rename-buffer,
2) M-x revert-buffer, and 3) M-x ediff-buffers.

Ediff  is your friend, generally.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-06  0:18 ` John Paul Wallington
@ 2006-09-06  9:18   ` Romain Francoise
  0 siblings, 0 replies; 16+ messages in thread
From: Romain Francoise @ 2006-09-06  9:18 UTC (permalink / raw)


jpw@pobox.com (John Paul Wallington) writes:

> 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 =.

Of course using Ibuffer to operate on the current buffer can be tiring
if you do it often, because you have to locate the buffer in the list.
I use the following to make point jump to the last buffer when entering
Ibuffer, I find it very convenient (e.g. C-x C-b = always works):

(add-hook 'ibuffer-hook
	  (lambda () (ibuffer-jump-to-buffer
		      (buffer-name (other-buffer (current-buffer) t)))))

-- 
Romain Francoise <romain@orebokech.com> | The sea! the sea! the open
it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the
                                        | ever free! --Bryan W. Procter

^ permalink raw reply	[flat|nested] 16+ messages in thread

* diffs between a buffer and the underlying file
@ 2006-09-14  6:19 Urs Thuermann
  2006-09-14  6:55 ` Michaël Cadilhac
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Urs Thuermann @ 2006-09-14  6:19 UTC (permalink / raw)


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 best way to do this seems to be to set the region to the whole
buffer, write the region to some temporary file, and run diff on the
two files.  But I find this very unconvenient.

I'd like to have a function in emacs which can be applied to a buffer,
say buffer A, that opens a new buffer displaying all the changes
between the buffer A and the disk file, opened in buffer A.

Searching the emacs documentation I haven't found anything like this.
Only functions for diff'ing two buffers or two files.

urs

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-14  6:19 diffs between a buffer and the underlying file Urs Thuermann
@ 2006-09-14  6:55 ` Michaël Cadilhac
  2006-09-17  8:07   ` Urs Thuermann
  2006-09-14  7:13 ` David Hansen
  2006-09-14  8:57 ` Darren
  2 siblings, 1 reply; 16+ messages in thread
From: Michaël Cadilhac @ 2006-09-14  6:55 UTC (permalink / raw)
  Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1046 bytes --]

Urs Thuermann <urs@isnogud.escape.de> 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 best way to do this seems to be to set the region to the whole
> buffer, write the region to some temporary file, and run diff on the
> two files.  But I find this very unconvenient.
>
> I'd like to have a function in emacs which can be applied to a buffer,
> say buffer A, that opens a new buffer displaying all the changes
> between the buffer A and the disk file, opened in buffer A.

I think what you want is 
M-x diff-buffer-with-file RET RET

-- 
/!\ My mail address changed, please update your files accordingly.
 |      Michaël `Micha' Cadilhac   |  Would someone please DTRT with this,  |
 |         Epita/LRDE Promo 2007   |        then ACK?                       |
 |  http://michael.cadilhac.name   |          -- Richard Stallman           |
 `--  -   JID: micha@amessage.be --'                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-14  6:19 diffs between a buffer and the underlying file Urs Thuermann
  2006-09-14  6:55 ` Michaël Cadilhac
@ 2006-09-14  7:13 ` David Hansen
  2006-09-14  8:57 ` Darren
  2 siblings, 0 replies; 16+ messages in thread
From: David Hansen @ 2006-09-14  7:13 UTC (permalink / raw)


On 14 Sep 2006 08:19:28 +0200 Urs Thuermann wrote:

> 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 best way to do this seems to be to set the region to the whole
> buffer, write the region to some temporary file, and run diff on the
> two files.  But I find this very unconvenient.
>
> I'd like to have a function in emacs which can be applied to a buffer,
> say buffer A, that opens a new buffer displaying all the changes
> between the buffer A and the disk file, opened in buffer A.
>
> Searching the emacs documentation I haven't found anything like this.
> Only functions for diff'ing two buffers or two files.

M-x apropos RET diff.*buf RET gives me (GNU Emacs 22) as the
first hit:

diff-buffer-with-file
  Command: View the differences between BUFFER and its associated file.

But maybe Emacs/20.7 is a bit old...

David

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-14  6:19 diffs between a buffer and the underlying file Urs Thuermann
  2006-09-14  6:55 ` Michaël Cadilhac
  2006-09-14  7:13 ` David Hansen
@ 2006-09-14  8:57 ` Darren
  2 siblings, 0 replies; 16+ messages in thread
From: Darren @ 2006-09-14  8:57 UTC (permalink / raw)


On 09/14/2006 at 14:19, Urs Thuermann wrote:

> 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 best way to do this seems to be to set the region to the whole
> buffer, write the region to some temporary file, and run diff on the
> two files.  But I find this very unconvenient.

How about `dired-backup-diff'?


-- 
(reply-to (concat "snlee99" "@" "tom" "." "com"))

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-14  6:55 ` Michaël Cadilhac
@ 2006-09-17  8:07   ` Urs Thuermann
  2006-09-17  8:20     ` Michaël Cadilhac
       [not found]     ` <mailman.7052.1158517019.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 16+ messages in thread
From: Urs Thuermann @ 2006-09-17  8:07 UTC (permalink / raw)
  Cc: help-gnu-emacs

michael@cadilhac.name (Michaël Cadilhac) writes:

> I think what you want is 
> M-x diff-buffer-with-file RET RET

It seems my Emacs 20.7 compiled from the sources and Emacs 21 on
Debian GNU/Linux don't know this.  Is this something new in Emacs 22
or do I have to load some Elisp file to be able to use this function?


urs


BTW, I am not on the mailing list but read the gnu.emacs.help
newsgroup.  But I didn't get your answer in this newsgroup from my
neesfeed.  Only your private email copy to me reached me.  Is there a
problem with the News/Email gateway?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-17  8:07   ` Urs Thuermann
@ 2006-09-17  8:20     ` Michaël Cadilhac
       [not found]     ` <mailman.7052.1158517019.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 16+ messages in thread
From: Michaël Cadilhac @ 2006-09-17  8:20 UTC (permalink / raw)
  Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1210 bytes --]

Urs Thuermann <urs@isnogud.escape.de> writes:

> michael@cadilhac.name (Michaël Cadilhac) writes:
>
>> I think what you want is 
>> M-x diff-buffer-with-file RET RET
>
> It seems my Emacs 20.7 compiled from the sources and Emacs 21 on
> Debian GNU/Linux don't know this.  Is this something new in Emacs 22
> or do I have to load some Elisp file to be able to use this function?

It has been added on 2002-09-01 by RMS, according to the ChangeLog.

You can try to

1) Use the implementation of
   http://cvs.savannah.gnu.org/viewcvs/emacs/emacs/lisp/files.el?view=markup
2) Use Emacs 22 (Best choice ;-))

> I didn't get your answer in this newsgroup from my neesfeed.

I've just changed my mail address, and help-gnu-emacs didn't know me
when I sent this mail. It should be fixed now, thanks :-)

-- 
/!\ My mail address changed, please update your files accordingly.
 |      Michaël `Micha' Cadilhac   |  Un certain Blaise Pascal              |
 |         Epita/LRDE Promo 2007   |    etc... etc...                       |
 |  http://michael.cadilhac.name   |  -- Prévert (Les paris stupides)       |
 `--  -   JID: micha@amessage.be --'                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
       [not found]     ` <mailman.7052.1158517019.9609.help-gnu-emacs@gnu.org>
@ 2006-09-18 17:30       ` Urs Thuermann
  2006-09-20 19:11         ` John Sullivan
                           ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Urs Thuermann @ 2006-09-18 17:30 UTC (permalink / raw)


michael@cadilhac.name (Michaël Cadilhac) writes:

> Urs Thuermann <urs@isnogud.escape.de> writes:
> 
> > It seems my Emacs 20.7 compiled from the sources and Emacs 21 on
> > Debian GNU/Linux don't know this.  Is this something new in Emacs 22
> > or do I have to load some Elisp file to be able to use this function?
> 
> It has been added on 2002-09-01 by RMS, according to the ChangeLog.

Shouldn't it be in emacs 21.4 then?  ftp.gnu.org says

    ftp> dir /pub/gnu/emacs/emacs-21.4a.tar.gz
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    -rw-r--r--    1 1003     65534    20403483 Feb 17  2005 emacs-21.4a.tar.gz
    226 Directory send OK.
    
> You can try to
> 
> 1) Use the implementation of
>    http://cvs.savannah.gnu.org/viewcvs/emacs/emacs/lisp/files.el?view=markup
> 2) Use Emacs 22 (Best choice ;-))

OK, thanks.  Debian doesn't have Emacs 22 yet, BTW.

urs

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-18 17:30       ` Urs Thuermann
@ 2006-09-20 19:11         ` John Sullivan
       [not found]         ` <mailman.7207.1158782592.9609.help-gnu-emacs@gnu.org>
  2006-09-21  7:43         ` Romain Francoise
  2 siblings, 0 replies; 16+ messages in thread
From: John Sullivan @ 2006-09-20 19:11 UTC (permalink / raw)


Urs Thuermann <urs@isnogud.escape.de> writes:

> OK, thanks.  Debian doesn't have Emacs 22 yet, BTW.

aptitude install emacs-snapshot

(at least I know it's in unstable, not sure about testing)

-- 
-John Sullivan
-http://www.wjsullivan.net
-GPG Key: AE8600B6

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
       [not found]         ` <mailman.7207.1158782592.9609.help-gnu-emacs@gnu.org>
@ 2006-09-21  4:14           ` Tim X
  2006-10-14 19:56             ` David Combs
  0 siblings, 1 reply; 16+ messages in thread
From: Tim X @ 2006-09-21  4:14 UTC (permalink / raw)


John Sullivan <john@wjsullivan.net> writes:

> Urs Thuermann <urs@isnogud.escape.de> writes:
>
>> OK, thanks.  Debian doesn't have Emacs 22 yet, BTW.
>
> aptitude install emacs-snapshot
>
> (at least I know it's in unstable, not sure about testing)
>
> -- 
> -John Sullivan
> -http://www.wjsullivan.net
> -GPG Key: AE8600B6
>
>
>

Its not in testing, but it is in unstable. So, to get emacs-snapshot
(aka emacs 22 CVS) on a Debian testing system, put the following in
your /etc/apt/conf.d directory (call it something appropriate like
05local, so that it is loaded at an appropriate time)

APT::Default-Release "testing";

this will ensure aptitude (or apt) will give preference to packages
from testing rather than unstable and stop heaps of packages from
getting updated from the unstable repository. 

Then you need to add an unstable repository to your
/etc/apt/sources.list

then, to install emacs 22 from unstable, but keep everything else from
testing, all you need to do is an 

aptitude update
aptitude install emacs-snapshot

and your away. You will then get updated emacs snapshots every week or
so as they are updated from CVS. I've been running it for months now
and it is very stable - you can even try emacs-snapshot-gtk to get the
one built with the gtk widgets (though I don't think it is quite as
stable).

HTH

Tim
-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-18 17:30       ` Urs Thuermann
  2006-09-20 19:11         ` John Sullivan
       [not found]         ` <mailman.7207.1158782592.9609.help-gnu-emacs@gnu.org>
@ 2006-09-21  7:43         ` Romain Francoise
  2 siblings, 0 replies; 16+ messages in thread
From: Romain Francoise @ 2006-09-21  7:43 UTC (permalink / raw)


Urs Thuermann <urs@isnogud.escape.de> writes:

> Debian doesn't have Emacs 22 yet, BTW.

<URL: http://www.emacswiki.org/cgi-bin/wiki/EmacsCvsAndDebian>

-- 
Romain Francoise <romain@orebokech.com> | The sea! the sea! the open
it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the
                                        | ever free! --Bryan W. Procter

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: diffs between a buffer and the underlying file
  2006-09-21  4:14           ` Tim X
@ 2006-10-14 19:56             ` David Combs
  0 siblings, 0 replies; 16+ messages in thread
From: David Combs @ 2006-10-14 19:56 UTC (permalink / raw)


In article <87bqp9hn48.fsf@lion.rapttech.com.au>,
Tim X  <timx@nospam.dev.null> wrote:
>John Sullivan <john@wjsullivan.net> writes:
>
>> Urs Thuermann <urs@isnogud.escape.de> writes:
>>
>>> OK, thanks.  Debian doesn't have Emacs 22 yet, BTW.
>>
>> aptitude install emacs-snapshot
>>
>> (at least I know it's in unstable, not sure about testing)
>>
>> -- 
>> -John Sullivan
>> -http://www.wjsullivan.net
>> -GPG Key: AE8600B6
>>
>>
>>
>
>Its not in testing, but it is in unstable. So, to get emacs-snapshot
>(aka emacs 22 CVS) on a Debian testing system, put the following in
>your /etc/apt/conf.d directory (call it something appropriate like
>05local, so that it is loaded at an appropriate time)
>
>APT::Default-Release "testing";
>
>this will ensure aptitude (or apt) will give preference to packages
>from testing rather than unstable and stop heaps of packages from
>getting updated from the unstable repository. 
>
>Then you need to add an unstable repository to your
>/etc/apt/sources.list
>
>then, to install emacs 22 from unstable, but keep everything else from
>testing, all you need to do is an 
>
>aptitude update
>aptitude install emacs-snapshot
>
>and your away. You will then get updated emacs snapshots every week or
>so as they are updated from CVS. I've been running it for months now
>and it is very stable - you can even try emacs-snapshot-gtk to get the
>one built with the gtk widgets (though I don't think it is quite as
>stable).
>
>HTH
>
>Tim
>-- 
>tcross (at) rapttech dot com dot au



And what if you want to use it for solaris/sparc?

What adjustments to the above need to be made?

Plus, an exact "cut-n-paste" cvs-cmd (line, switches, etc)
for downloading a newest-hottest-experimental-emacs.tar.gz --
ie, cvs command-line that's usable -- WITHOUT HAVING TO
KNOW ANYTHING ABOUT CVS (or whatever).

THANKS

David

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2006-10-14 19:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-14  6:19 diffs between a buffer and the underlying file Urs Thuermann
2006-09-14  6:55 ` Michaël Cadilhac
2006-09-17  8:07   ` Urs Thuermann
2006-09-17  8:20     ` Michaël Cadilhac
     [not found]     ` <mailman.7052.1158517019.9609.help-gnu-emacs@gnu.org>
2006-09-18 17:30       ` Urs Thuermann
2006-09-20 19:11         ` John Sullivan
     [not found]         ` <mailman.7207.1158782592.9609.help-gnu-emacs@gnu.org>
2006-09-21  4:14           ` Tim X
2006-10-14 19:56             ` David Combs
2006-09-21  7:43         ` Romain Francoise
2006-09-14  7:13 ` David Hansen
2006-09-14  8:57 ` Darren
  -- strict thread matches above, loose matches on Subject: below --
2006-09-05 16:39 Urs Thuermann
2006-09-05 18:10 ` Eric Hanchrow
2006-09-06  0:18 ` John Paul Wallington
2006-09-06  9:18   ` Romain Francoise
2006-09-06  1:39 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.