From: Mario Lang <mlang@delysid.org>
Subject: Offering the differences on exit
Date: Tue, 02 Jul 2002 21:08:28 +0200 [thread overview]
Message-ID: <87k7oedk2b.fsf@lexx.delysid.org> (raw)
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
---<snip>---
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
next reply other threads:[~2002-07-02 19:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-02 19:08 Mario Lang [this message]
2002-07-02 20:47 ` Offering the differences on exit Kim F. Storm
2002-07-02 20:25 ` Mario Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k7oedk2b.fsf@lexx.delysid.org \
--to=mlang@delysid.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.