diff options
| author | Eric Abrahamsen | 2017-09-12 16:06:12 -0700 |
|---|---|---|
| committer | Eric Abrahamsen | 2017-09-12 16:06:12 -0700 |
| commit | 9b980e2691afa3a7a967011fc004d352750fe618 (patch) | |
| tree | 5d5cc5e432da299eaa5ab9dfb8384b12e7101d36 /doc | |
| parent | d07fd34722b84ae2c407f195c82d7632a94de704 (diff) | |
| download | emacs-9b980e2691afa3a7a967011fc004d352750fe618.tar.gz emacs-9b980e2691afa3a7a967011fc004d352750fe618.zip | |
Allow write-contents-functions to short-circuit buffer save
Bug#28412
* lisp/files.el (basic-save-buffer): Re-arrange function so that
write-contents-functions are run earlier. If they return non-nil,
consider the buffer saved without requiring the buffer to be
visiting a file.
(save-some-buffers): This function should consider any buffer with a
buffer-local value for write-contents-functions eligible for
saving.
* test/lisp/files-tests.el (files-test-no-file-write-contents): New
test.
* doc/lispref/files.texi (Saving Buffers): Mention in docs.
* etc/NEWS: And in NEWS.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/files.texi | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 901382fe9bd..6be998f0b2e 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -457,15 +457,23 @@ Even though this is not a normal hook, you can use @code{add-hook} and | |||
| 457 | @defvar write-contents-functions | 457 | @defvar write-contents-functions |
| 458 | This works just like @code{write-file-functions}, but it is intended | 458 | This works just like @code{write-file-functions}, but it is intended |
| 459 | for hooks that pertain to the buffer's contents, not to the particular | 459 | for hooks that pertain to the buffer's contents, not to the particular |
| 460 | visited file or its location. Such hooks are usually set up by major | 460 | visited file or its location, and can be used to create arbitrary save |
| 461 | modes, as buffer-local bindings for this variable. This variable | 461 | processes for buffers that aren't visiting files at all. Such hooks |
| 462 | automatically becomes buffer-local whenever it is set; switching to a | 462 | are usually set up by major modes, as buffer-local bindings for this |
| 463 | new major mode always resets this variable, but calling | 463 | variable. This variable automatically becomes buffer-local whenever |
| 464 | @code{set-visited-file-name} does not. | 464 | it is set; switching to a new major mode always resets this variable, |
| 465 | but calling @code{set-visited-file-name} does not. | ||
| 465 | 466 | ||
| 466 | If any of the functions in this hook returns non-@code{nil}, the file | 467 | If any of the functions in this hook returns non-@code{nil}, the file |
| 467 | is considered already written and the rest are not called and neither | 468 | is considered already written and the rest are not called and neither |
| 468 | are the functions in @code{write-file-functions}. | 469 | are the functions in @code{write-file-functions}. |
| 470 | |||
| 471 | When using this hook to save buffers that are not visiting files (for | ||
| 472 | instance, special-mode buffers), keep in mind that, if the function | ||
| 473 | fails to save correctly and returns a @code{nil} value, | ||
| 474 | @code{save-buffer} will go on to prompt the user for a file to save | ||
| 475 | the buffer in. If this is undesirable, consider having the function | ||
| 476 | fail by raising an error. | ||
| 469 | @end defvar | 477 | @end defvar |
| 470 | 478 | ||
| 471 | @defopt before-save-hook | 479 | @defopt before-save-hook |