diff options
author | Eric Abrahamsen <eric@ericabrahamsen.net> | 2017-09-12 16:06:12 -0700 |
---|---|---|
committer | Eric Abrahamsen <eric@ericabrahamsen.net> | 2017-09-12 16:06:12 -0700 |
commit | 9b980e2691afa3a7a967011fc004d352750fe618 (patch) | |
tree | 5d5cc5e432da299eaa5ab9dfb8384b12e7101d36 /test | |
parent | d07fd34722b84ae2c407f195c82d7632a94de704 (diff) | |
download | emacs-9b980e2691afa3a7a967011fc004d352750fe618.tar.gz |
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 'test')
-rw-r--r-- | test/lisp/files-tests.el | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index b52965a02b4..c6806cdb58e 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -365,6 +365,33 @@ be invoked with the right arguments." (should-error (make-directory a/b)) (should-not (make-directory a/b t)))) +(ert-deftest files-test-no-file-write-contents () + "Test that `write-contents-functions' permits saving a file. +Usually `basic-save-buffer' will prompt for a file name if the +current buffer has none. It should first call the functions in +`write-contents-functions', and if one of them returns non-nil, +consider the buffer saved, without prompting for a file +name (Bug#28412)." + (let ((read-file-name-function + (lambda (&rest _ignore) + (error "Prompting for file name")))) + ;; With contents function, and no file. + (with-temp-buffer + (setq write-contents-functions (lambda () t)) + (set-buffer-modified-p t) + (should (null (save-buffer)))) + ;; With no contents function and no file. This should reach the + ;; `read-file-name' prompt. + (with-temp-buffer + (set-buffer-modified-p t) + (should-error (save-buffer) :type 'error)) + ;; Then a buffer visiting a file: should save normally. + (files-tests--with-temp-file temp-file-name + (with-current-buffer (find-file-noselect temp-file-name) + (setq write-contents-functions nil) + (insert "p") + (should (null (save-buffer))) + (should (eq (buffer-size) 1)))))) (provide 'files-tests) ;;; files-tests.el ends here |