diff options
| author | Richard M. Stallman | 2002-09-02 00:11:41 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-09-02 00:11:41 +0000 |
| commit | 1eeae2a11354bf4040e28175a786df00e7651bcb (patch) | |
| tree | de71f13c32f5a15902cfc2236e150273cf40c7a8 | |
| parent | 8f96b49bc7a9eb8acc334e98ed72e771cb2868bc (diff) | |
| download | emacs-1eeae2a11354bf4040e28175a786df00e7651bcb.tar.gz emacs-1eeae2a11354bf4040e28175a786df00e7651bcb.zip | |
(save-some-buffers-action-alist): New variable.
(save-some-buffers): Use that.
(diff-buffer-with-file): New function.
| -rw-r--r-- | lisp/files.el | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/lisp/files.el b/lisp/files.el index 0983762356c..ac25232bafe 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -2993,17 +2993,56 @@ After saving the buffer, this function runs `after-save-hook'." | |||
| 2993 | (rename-file (cdr setmodes) buffer-file-name)))))) | 2993 | (rename-file (cdr setmodes) buffer-file-name)))))) |
| 2994 | setmodes)) | 2994 | setmodes)) |
| 2995 | 2995 | ||
| 2996 | (defun diff-buffer-with-file (&optional buffer) | ||
| 2997 | "View the differences between BUFFER and its associated file. | ||
| 2998 | This requires the external program \"diff\" to be in your `exec-path'." | ||
| 2999 | (interactive "bBuffer: ") | ||
| 3000 | (setq buffer (get-buffer (or buffer (current-buffer)))) | ||
| 3001 | (let ((buf-filename (buffer-file-name buffer))) | ||
| 3002 | (unless buf-filename | ||
| 3003 | (error "Buffer %s has no associated file" buffer)) | ||
| 3004 | (let ((tempfile (make-temp-file "buffer-content-"))) | ||
| 3005 | (unwind-protect | ||
| 3006 | (progn | ||
| 3007 | (with-current-buffer buffer | ||
| 3008 | (save-restriction | ||
| 3009 | (widen) | ||
| 3010 | (write-region (point-min) (point-max) tempfile nil 'nomessage))) | ||
| 3011 | (diff buf-filename tempfile)) | ||
| 3012 | (when (file-exists-p tempfile) | ||
| 3013 | (delete-file tempfile))) | ||
| 3014 | nil))) | ||
| 3015 | |||
| 3016 | (defvar save-some-buffers-action-alist | ||
| 3017 | '((?\C-r | ||
| 3018 | (lambda (buf) | ||
| 3019 | (view-buffer buf | ||
| 3020 | (lambda (ignore) | ||
| 3021 | (exit-recursive-edit))) | ||
| 3022 | (recursive-edit) | ||
| 3023 | ;; Return nil to ask about BUF again. | ||
| 3024 | nil) | ||
| 3025 | "display the current buffer") | ||
| 3026 | (?d diff-buffer-with-file | ||
| 3027 | "Show difference to last saved version")) | ||
| 3028 | "ACTION-ALIST argument used in call to `map-y-or-n-p'.") | ||
| 3029 | (put 'save-some-buffers-action-alist 'risky-local-variable t) | ||
| 3030 | |||
| 2996 | (defun save-some-buffers (&optional arg pred) | 3031 | (defun save-some-buffers (&optional arg pred) |
| 2997 | "Save some modified file-visiting buffers. Asks user about each one. | 3032 | "Save some modified file-visiting buffers. Asks user about each one. |
| 2998 | You can answer `y' to save, `n' not to save, or `C-r' to look at the | 3033 | You can answer `y' to save, `n' not to save, `C-r' to look at the |
| 2999 | buffer in question with `view-buffer' before deciding. | 3034 | buffer in question with `view-buffer' before deciding or `d' to |
| 3035 | view the differences using `diff-buffer-to-file'. | ||
| 3000 | 3036 | ||
| 3001 | Optional argument (the prefix) non-nil means save all with no questions. | 3037 | Optional argument (the prefix) non-nil means save all with no questions. |
| 3002 | Optional second argument PRED determines which buffers are considered: | 3038 | Optional second argument PRED determines which buffers are considered: |
| 3003 | If PRED is nil, all the file-visiting buffers are considered. | 3039 | If PRED is nil, all the file-visiting buffers are considered. |
| 3004 | If PRED is t, then certain non-file buffers will also be considered. | 3040 | If PRED is t, then certain non-file buffers will also be considered. |
| 3005 | If PRED is a zero-argument function, it indicates for each buffer whether | 3041 | If PRED is a zero-argument function, it indicates for each buffer whether |
| 3006 | to consider it or not when called with that buffer current." | 3042 | to consider it or not when called with that buffer current. |
| 3043 | |||
| 3044 | See `save-some-buffers-action-alist' if you want to | ||
| 3045 | change the additional actions you can take on files." | ||
| 3007 | (interactive "P") | 3046 | (interactive "P") |
| 3008 | (save-window-excursion | 3047 | (save-window-excursion |
| 3009 | (let* ((queried nil) | 3048 | (let* ((queried nil) |
| @@ -3035,15 +3074,7 @@ to consider it or not when called with that buffer current." | |||
| 3035 | (save-buffer))) | 3074 | (save-buffer))) |
| 3036 | (buffer-list) | 3075 | (buffer-list) |
| 3037 | '("buffer" "buffers" "save") | 3076 | '("buffer" "buffers" "save") |
| 3038 | (list (list ?\C-r (lambda (buf) | 3077 | save-some-buffers-action-alist)) |
| 3039 | (view-buffer buf | ||
| 3040 | (function | ||
| 3041 | (lambda (ignore) | ||
| 3042 | (exit-recursive-edit)))) | ||
| 3043 | (recursive-edit) | ||
| 3044 | ;; Return nil to ask about BUF again. | ||
| 3045 | nil) | ||
| 3046 | "display the current buffer")))) | ||
| 3047 | (abbrevs-done | 3078 | (abbrevs-done |
| 3048 | (and save-abbrevs abbrevs-changed | 3079 | (and save-abbrevs abbrevs-changed |
| 3049 | (progn | 3080 | (progn |