2993 |
(rename-file (cdr setmodes) buffer-file-name)))))) |
(rename-file (cdr setmodes) buffer-file-name)))))) |
2994 |
setmodes)) |
setmodes)) |
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 |
|
|
3031 |
(defun save-some-buffers (&optional arg pred) |
(defun save-some-buffers (&optional arg pred) |
3032 |
"Save some modified file-visiting buffers. Asks user about each one. |
"Save some modified file-visiting buffers. Asks user about each one. |
3033 |
You can answer `y' to save, `n' not to save, or `C-r' to look at the |
You can answer `y' to save, `n' not to save, `C-r' to look at the |
3034 |
buffer in question with `view-buffer' before deciding. |
buffer in question with `view-buffer' before deciding or `d' to |
3035 |
|
view the differences using `diff-buffer-to-file'. |
3036 |
|
|
3037 |
Optional argument (the prefix) non-nil means save all with no questions. |
Optional argument (the prefix) non-nil means save all with no questions. |
3038 |
Optional second argument PRED determines which buffers are considered: |
Optional second argument PRED determines which buffers are considered: |
3039 |
If PRED is nil, all the file-visiting buffers are considered. |
If PRED is nil, all the file-visiting buffers are considered. |
3040 |
If PRED is t, then certain non-file buffers will also be considered. |
If PRED is t, then certain non-file buffers will also be considered. |
3041 |
If PRED is a zero-argument function, it indicates for each buffer whether |
If PRED is a zero-argument function, it indicates for each buffer whether |
3042 |
to consider it or not when called with that buffer current." |
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." |
3046 |
(interactive "P") |
(interactive "P") |
3047 |
(save-window-excursion |
(save-window-excursion |
3048 |
(let* ((queried nil) |
(let* ((queried nil) |
3074 |
(save-buffer))) |
(save-buffer))) |
3075 |
(buffer-list) |
(buffer-list) |
3076 |
'("buffer" "buffers" "save") |
'("buffer" "buffers" "save") |
3077 |
(list (list ?\C-r (lambda (buf) |
save-some-buffers-action-alist)) |
|
(view-buffer buf |
|
|
(function |
|
|
(lambda (ignore) |
|
|
(exit-recursive-edit)))) |
|
|
(recursive-edit) |
|
|
;; Return nil to ask about BUF again. |
|
|
nil) |
|
|
"display the current buffer")))) |
|
3078 |
(abbrevs-done |
(abbrevs-done |
3079 |
(and save-abbrevs abbrevs-changed |
(and save-abbrevs abbrevs-changed |
3080 |
(progn |
(progn |