unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH#2] View differences before saving
@ 2002-08-21  9:21 Mario Lang
  2002-08-22  1:57 ` Richard Stallman
  2002-09-01 18:23 ` Colin Walters
  0 siblings, 2 replies; 4+ messages in thread
From: Mario Lang @ 2002-08-21  9:21 UTC (permalink / raw)


OK, I rewrote the function diff-buffer-with-file
using the function `diff' from diff.el.

Following is the patch, the same ChangeLog entry as previously
posted applies:

Index: lisp/files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.601
diff -u -r1.601 files.el
--- lisp/files.el	15 Aug 2002 20:08:24 -0000	1.601
+++ lisp/files.el	21 Aug 2002 09:18:20 -0000
@@ -2992,17 +2992,55 @@
 		 (rename-file (cdr setmodes) buffer-file-name))))))
     setmodes))
 
+(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: ")
+  (setq buffer (get-buffer (or buffer (current-buffer))))
+  (let ((buf-filename (buffer-file-name buffer)))
+    (unless buf-filename
+      (error "Buffer %s has no associated file" buffer))
+    (let ((tempfile (make-temp-file "buffer-content-")))
+      (unwind-protect
+	  (progn
+	    (with-current-buffer buffer
+	      (save-restriction
+		(widen)
+		(write-region (point-min) (point-max) tempfile nil 'nomessage)))
+	    (diff buf-filename tempfile))
+	(when (file-exists-p tempfile)
+	  (delete-file tempfile)))
+      nil)))
+
+(defvar save-some-buffers-action-alist
+  '((?\C-r
+     (lambda (buf)
+       (view-buffer buf
+		    (lambda (ignore)
+		      (exit-recursive-edit)))
+       (recursive-edit)
+       ;; Return nil to ask about BUF again.
+       nil)
+     "display the current buffer")
+    (?d diff-buffer-with-file
+	"Show difference to last saved version"))
+  "ACTION-ALIST argument used in call to `map-y-or-n-p'.")
+
 (defun save-some-buffers (&optional arg pred)
   "Save some modified file-visiting buffers.  Asks user about each one.
-You can answer `y' to save, `n' not to save, or `C-r' to look at the
-buffer in question with `view-buffer' before deciding.
+You can answer `y' to save, `n' not to save, `C-r' to look at the
+buffer in question with `view-buffer' before deciding or `d' to
+view the differences using `diff-buffer-to-file'.
 
 Optional argument (the prefix) non-nil means save all with no questions.
 Optional second argument PRED determines which buffers are considered:
 If PRED is nil, all the file-visiting buffers are considered.
 If PRED is t, then certain non-file buffers will also be considered.
 If PRED is a zero-argument function, it indicates for each buffer whether
-to consider it or not when called with that buffer current."
+to consider it or not when called with that buffer current.
+
+See `save-some-buffers-action-alist' if you want to
+change the additional actions you can take on files."
   (interactive "P")
   (save-window-excursion
     (let* ((queried nil)
@@ -3034,15 +3072,7 @@
 		(save-buffer)))
 	     (buffer-list)
 	     '("buffer" "buffers" "save")
-	     (list (list ?\C-r (lambda (buf)
-				 (view-buffer buf
-					      (function
-					       (lambda (ignore)
-						 (exit-recursive-edit))))
-				 (recursive-edit)
-				 ;; Return nil to ask about BUF again.
-				 nil)
-			 "display the current buffer"))))
+	     save-some-buffers-action-alist))
 	   (abbrevs-done
 	    (and save-abbrevs abbrevs-changed
 		 (progn

-- 
CYa,
  Mario

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

* Re: [PATCH#2] View differences before saving
  2002-08-21  9:21 [PATCH#2] View differences before saving Mario Lang
@ 2002-08-22  1:57 ` Richard Stallman
  2002-09-01 18:23 ` Colin Walters
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2002-08-22  1:57 UTC (permalink / raw)
  Cc: emacs-devel

It looks good.  When I confirm we have your papers, I will install it.

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

* Re: [PATCH#2] View differences before saving
  2002-08-21  9:21 [PATCH#2] View differences before saving Mario Lang
  2002-08-22  1:57 ` Richard Stallman
@ 2002-09-01 18:23 ` Colin Walters
  2002-09-01 18:46   ` Mario Lang
  1 sibling, 1 reply; 4+ messages in thread
From: Colin Walters @ 2002-09-01 18:23 UTC (permalink / raw)


On Wed, 2002-08-21 at 05:21, Mario Lang wrote:
> OK, I rewrote the function diff-buffer-with-file
> using the function `diff' from diff.el.

It looks really similar to the function `ibuffer-diff-with-file'.  When
this gets installed, it would be nice if you could replace the ibuffer
function with your function as well.

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

* Re: [PATCH#2] View differences before saving
  2002-09-01 18:23 ` Colin Walters
@ 2002-09-01 18:46   ` Mario Lang
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Lang @ 2002-09-01 18:46 UTC (permalink / raw)


Colin Walters <walters@verbum.org> writes:

> On Wed, 2002-08-21 at 05:21, Mario Lang wrote:
>> OK, I rewrote the function diff-buffer-with-file
>> using the function `diff' from diff.el.
>
> It looks really similar to the function `ibuffer-diff-with-file'.  When
> this gets installed, it would be nice if you could replace the ibuffer
> function with your function as well.
Or replace the calls to ibuffer-diff-with-file with calls
to diff-buffer-with-file?

Did my papers arive already? It's not some weeks that I sent them.

-- 
CYa,
  Mario

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

end of thread, other threads:[~2002-09-01 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-21  9:21 [PATCH#2] View differences before saving Mario Lang
2002-08-22  1:57 ` Richard Stallman
2002-09-01 18:23 ` Colin Walters
2002-09-01 18:46   ` Mario Lang

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).