diff options
| -rw-r--r-- | lisp/files.el | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el index 0e303805d0c..a7c7902629d 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4065,6 +4065,13 @@ in such cases.") | |||
| 4065 | (make-variable-buffer-local 'save-buffer-coding-system) | 4065 | (make-variable-buffer-local 'save-buffer-coding-system) |
| 4066 | (put 'save-buffer-coding-system 'permanent-local t) | 4066 | (put 'save-buffer-coding-system 'permanent-local t) |
| 4067 | 4067 | ||
| 4068 | (defvar buffer-swapped-with nil | ||
| 4069 | "Buffer that this buffer's contents are temporarily swapped with. | ||
| 4070 | You should only set this variable in file-visiting buffers, | ||
| 4071 | because it only affects how to save the buffer in its file.") | ||
| 4072 | |||
| 4073 | (make-variable-buffer-local 'buffer-swapped-with) | ||
| 4074 | |||
| 4068 | (defun basic-save-buffer () | 4075 | (defun basic-save-buffer () |
| 4069 | "Save the current buffer in its visited file, if it has been modified. | 4076 | "Save the current buffer in its visited file, if it has been modified. |
| 4070 | The hooks `write-contents-functions' and `write-file-functions' get a chance | 4077 | The hooks `write-contents-functions' and `write-file-functions' get a chance |
| @@ -4073,6 +4080,17 @@ the visited file in the usual way. | |||
| 4073 | Before and after saving the buffer, this function runs | 4080 | Before and after saving the buffer, this function runs |
| 4074 | `before-save-hook' and `after-save-hook', respectively." | 4081 | `before-save-hook' and `after-save-hook', respectively." |
| 4075 | (interactive) | 4082 | (interactive) |
| 4083 | (if (not buffer-swapped-with) | ||
| 4084 | (basic-save-buffer-0) | ||
| 4085 | ;; If this buffer's real contents are "swapped" with some other buffer, | ||
| 4086 | ;; temporarily unswap in order to save the real contents. | ||
| 4087 | (unwind-protect | ||
| 4088 | (progn | ||
| 4089 | (buffer-swap-text buffer-swapped-with) | ||
| 4090 | (basic-save-buffer-0)) | ||
| 4091 | (buffer-swap-text buffer-swapped-with)))) | ||
| 4092 | |||
| 4093 | (defun basic-save-buffer-0 () | ||
| 4076 | (save-current-buffer | 4094 | (save-current-buffer |
| 4077 | ;; In an indirect buffer, save its base buffer instead. | 4095 | ;; In an indirect buffer, save its base buffer instead. |
| 4078 | (if (buffer-base-buffer) | 4096 | (if (buffer-base-buffer) |