[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] View Differences before saving
From: |
Mario Lang |
Subject: |
[PATCH] View Differences before saving |
Date: |
Tue, 20 Aug 2002 15:25:15 +0200 |
User-agent: |
Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i386-debian-linux-gnu) |
Hello Emacsers :)
I've just received the confirmation that my
past and future changes assigment arrived
at the FSF. So I prepared a slightly
improved version of my previos patch (thanks Kim)
for submittion. I don't have CVS access, so if
the patch looks OK and is accepted that way, I'd like
to ask someone with CVS access to install it.
Here's the ChangeLog entry:
2002-08-20 Mario Lang <address@hidden>
* files.el: (diff-buffer-with-file): New function.
Intended for save-some-buffers-action-alist, but
useful in general.
* (save-some-buffers): Removed static
data in call to map-y-or-n-p and moved into
save-some-buffers-action-alist.
* save-some-buffers-action-alist: New variable.
Added option `d' using diff-buffer-to-file.
And here is the patch:
Index: files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.601
diff -u -r1.601 files.el
--- files.el 15 Aug 2002 20:08:24 -0000 1.601
+++ files.el 20 Aug 2002 13:15:01 -0000
@@ -2992,17 +2992,64 @@
(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 ((diff-buf (get-buffer-create "*Buffer-diff*")))
+ (with-current-buffer buffer
+ (save-restriction
+ (widen)
+ (if (zerop
+ (shell-command-on-region (point-min) (point-max)
+ (concat "diff "
+ (when (and (boundp 'ediff-custom-diff-options)
+ (stringp ediff-custom-diff-options))
+ ediff-custom-diff-options)
+ " " buf-filename " -") diff-buf))
+ (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))))))
+ 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 +3081,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
- [PATCH] View Differences before saving,
Mario Lang <=