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: Offering the differences on exit Date: Tue, 02 Jul 2002 21:08:28 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: <87k7oedk2b.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 1025637129 6707 127.0.0.1 (2 Jul 2002 19:12:09 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 2 Jul 2002 19:12:09 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 17PT4L-0001jx-00 for ; Tue, 02 Jul 2002 21:12:09 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17PT9U-0002JN-00 for ; Tue, 02 Jul 2002 21:17:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17PT4G-0004Ki-00; Tue, 02 Jul 2002 15:12:04 -0400 Original-Received: from 212186194087.graz.teleweb.at ([212.186.194.87] helo=lexx.delysid.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17PT1e-00049n-00 for ; Tue, 02 Jul 2002 15:09:22 -0400 Original-Received: from mlang by lexx.delysid.org with local (Exim 3.35 #1 (Debian)) id 17PT0n-0002Vx-00 for ; Tue, 02 Jul 2002 21:08:29 +0200 Original-To: emacs-devel@gnu.org Original-Lines: 120 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:5338 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:5338 One feature I miss since I tried out Emacs the first time is the ability to see a diff when you are asked if you want to save changed you've made. Now, there are actually two places where this could happen, when you explicitly kill a buffer (I dont really need it there), and when you exit Emacs (there I usually already forgot what I really edited, and sometimes would like to have a look at the actual differencies). The second case is handled in save-some-buffers. Now it was quite hard at first to understand whats going on there :), but I finally came up with a little patch to allow custom additions (like the diff option). It created a new variable, save-some-buffers-action-alist which holds the required values for C-r as default. This variable can then be used to insert more options there, like 'd' for diff. OK, here is the patch. Index: lisp/files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.587 diff -u -r1.587 files.el --- lisp/files.el 30 Jun 2002 14:41:43 -0000 1.587 +++ lisp/files.el 2 Jul 2002 19:00:43 -0000 @@ -2913,6 +2913,19 @@ buffer-file-name nil t buffer-file-truename))) setmodes)) +(defvar save-some-buffers-action-alist + '((?\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")) + "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. Optional argument (the prefix) non-nil means save all with no questions. @@ -2952,15 +2965,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 ------ Now, I use the following code to get my diff option: (add-to-list 'save-some-buffers-action-alist (list ?d #'diff-buffer-with-file "Show difference to last saved version")) ;; Code borrowed from ibuffer-diff-with-file (defun diff-buffer-with-file (buffer) "View the differences between BUFFER and its associated file. This requires the external program \"diff\" to be in your `exec-path'." (interactive "b") (let ((buf-filename (with-current-buffer buffer buffer-file-name))) (unless buf-filename (error "Buffer %s has no associated file" buffer)) (let ((diff-buf (get-buffer-create "*Buffer-diff*"))) (with-current-buffer diff-buf (setq buffer-read-only nil) (erase-buffer)) (let ((tempfile (make-temp-file "buffer-to-file-diff-"))) (unwind-protect (progn (with-current-buffer buffer (write-region (point-min) (point-max) tempfile nil 'nomessage)) (if (zerop (apply #'call-process "diff" nil diff-buf nil (append (when (and (boundp 'ediff-custom-diff-options) (stringp ediff-custom-diff-options)) (list ediff-custom-diff-options)) (list buf-filename tempfile)))) (message "No differences found") (progn (with-current-buffer diff-buf (goto-char (point-min)) (if (fboundp 'diff-mode) (diff-mode) (fundamental-mode))) (display-buffer diff-buf)))) (when (file-exists-p tempfile) (delete-file tempfile))))) nil)) Question: Could the patch make it into Standard Emacs? -- CYa, Mario