From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Mario Lang Newsgroups: gmane.emacs.devel Subject: [PATCH#2] View differences before saving Date: Wed, 21 Aug 2002 11:21:54 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: <874rdoy3bh.fsf@lexx.delysid.org> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1029921815 12354 127.0.0.1 (21 Aug 2002 09:23:35 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 21 Aug 2002 09:23:35 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17hRiA-0003D9-00 for ; Wed, 21 Aug 2002 11:23:34 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17hSAU-0006R3-00 for ; Wed, 21 Aug 2002 11:52:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17hRjH-0002eo-00; Wed, 21 Aug 2002 05:24:43 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17hRh1-0002av-00 for emacs-devel@gnu.org; Wed, 21 Aug 2002 05:22:23 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17hRgV-0002Ze-00 for emacs-devel@gnu.org; Wed, 21 Aug 2002 05:22:22 -0400 Original-Received: from tk212017102236.teleweb.at ([212.17.102.236] helo=lexx.delysid.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17hRgV-0002ZQ-00 for emacs-devel@gnu.org; Wed, 21 Aug 2002 05:21:51 -0400 Original-Received: from mlang by lexx.delysid.org with local (Exim 3.35 #1 (Debian)) id 17hRge-00089h-00 for ; Wed, 21 Aug 2002 11:22:00 +0200 Original-To: emacs-devel@gnu.org Original-Lines: 94 User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i386-debian-linux-gnu) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:6719 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:6719 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