From 37b5e661d298cbfe51422cd515b6696a1cdaa868 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 17 Sep 2017 12:56:00 -0700 Subject: Fix recently-introduced copy-directory bug Problem reported by Andrew Christianson (Bug#28451): * lisp/files.el (copy-directory): If COPY-CONTENTS, make the destination directory if it does not exist, even if it is a directory name. Simplify, and omit unnecessary test for an already-existing non-directory target, since make-directory diagnoses that for us now. * test/lisp/files-tests.el (files-tests--copy-directory): Test for this bug. --- lisp/files.el | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index c55c8097c16..133fed90c34 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5372,7 +5372,7 @@ raised." (while (progn (setq parent (directory-file-name (file-name-directory dir))) - (condition-case err + (condition-case () (files--ensure-directory dir) (file-missing ;; Do not loop if root does not exist (Bug#2309). @@ -5544,16 +5544,14 @@ into NEWNAME instead." ;; If NEWNAME is not a directory name, create it; ;; that is where we will copy the files of DIRECTORY. (make-directory newname parents)) - ;; If NEWNAME is a directory name and COPY-CONTENTS - ;; is nil, copy into NEWNAME/[DIRECTORY-BASENAME]. - ((not copy-contents) - (setq newname (concat newname - (file-name-nondirectory directory))) - (and (file-exists-p newname) - (not (file-directory-p newname)) - (error "Cannot overwrite non-directory %s with a directory" - newname)) - (make-directory newname t))) + ;; NEWNAME is a directory name. If COPY-CONTENTS is non-nil, + ;; create NEWNAME if it is not already a directory; + ;; otherwise, create NEWNAME/[DIRECTORY-BASENAME]. + ((if copy-contents + (or parents (not (file-directory-p newname))) + (setq newname (concat newname + (file-name-nondirectory directory)))) + (make-directory (directory-file-name newname) parents))) ;; Copy recursively. (dolist (file -- cgit v1.2.1 From ee512e9a825a6dbdf438a432b75b7e18d9a983c7 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Mon, 18 Sep 2017 13:29:44 -0700 Subject: Ignore buffers whose name begins with a space in save-some-buffers * lisp/files.el (save-some-buffers): Consider these buffers "internal", and don't prompt the user to save them. * doc/lispref/files.texi: Document. --- lisp/files.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index 133fed90c34..ff0ab706338 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5188,6 +5188,7 @@ change the additional actions you can take on files." (and (buffer-live-p buffer) (buffer-modified-p buffer) (not (buffer-base-buffer buffer)) + (not (eq (aref (buffer-name buffer) 0) ?\s)) (or (buffer-file-name buffer) (and pred -- cgit v1.2.1 From 1a01423b3c75bf08c255b3bd39f44d91e509a318 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Sep 2017 01:47:39 -0700 Subject: Fix bug with make-directory on MS-Windows root * lisp/files.el (files--ensure-directory): Treat any error, not just file-already-exists, as an opportunity to check whether DIR is already a directory (Bug#28508). --- lisp/files.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index ff0ab706338..0c30d40c13b 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5337,7 +5337,7 @@ instance of such commands." "Make directory DIR if it is not already a directory. Return nil." (condition-case err (make-directory-internal dir) - (file-already-exists + (error (unless (file-directory-p dir) (signal (car err) (cdr err)))))) -- cgit v1.2.1 From 047f02f00f602b9aef63ae8938e12f3f0ab481eb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 20 Sep 2017 11:49:12 -0700 Subject: Fix new copy-directory bug with empty dirs Problem reported by Afdam Plaice (Bug#28520) and by Eli Zaretskii (Bug#28483#34). This is another bug that I introduced in my recent copy-directory changes. * lisp/files.el (copy-directory): Work with empty subdirectories, too. * test/lisp/files-tests.el (files-tests--copy-directory): Test for this bug. --- lisp/files.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index 0c30d40c13b..f0a1f2380d9 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5564,7 +5564,7 @@ into NEWNAME instead." (filetype (car (file-attributes file)))) (cond ((eq filetype t) ; Directory but not a symlink. - (copy-directory file newname keep-time parents)) + (copy-directory file target keep-time parents t)) ((stringp filetype) ; Symbolic link (make-symbolic-link filetype target t)) ((copy-file file target t keep-time))))) -- cgit v1.2.1 From 3d3778d82a87139ef50a24146f5bad2a57a82094 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 24 Sep 2017 14:01:21 -0700 Subject: Accept new `always' value for option `buffer-offer-save' Also revert ee512e9a82 * lisp/files.el (buffer-offer-save): In addition to nil and t, now allows a third symbol value, `always'. A buffer where this option is set to `always' will always be offered for save by `save-some-buffers'. (save-some-buffers): Check the exact value of this buffer-local variable. No longer check the buffer name, or the value of `write-contents-functions'. * doc/lispref/buffers.texi (Killing Buffers): Note change in manual. * doc/lispref/files.texi (Saving Buffers): Remove note about buffer names. * etc/NEWS: Mention in NEWS. --- lisp/files.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index f0a1f2380d9..211457ac7d7 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -150,8 +150,13 @@ Called with an absolute file name as argument, it returns t to enable backup.") (defcustom buffer-offer-save nil "Non-nil in a buffer means always offer to save buffer on exit. Do so even if the buffer is not visiting a file. -Automatically local in all buffers." - :type 'boolean +Automatically local in all buffers. + +Set to the symbol `always' to offer to save buffer whenever +`save-some-buffers' is called." + :type '(choice (const :tag "Never" nil) + (const :tag "On Emacs exit" t) + (const :tag "Whenever save-some-buffers is called" always)) :group 'backup) (make-variable-buffer-local 'buffer-offer-save) (put 'buffer-offer-save 'permanent-local t) @@ -5188,15 +5193,11 @@ change the additional actions you can take on files." (and (buffer-live-p buffer) (buffer-modified-p buffer) (not (buffer-base-buffer buffer)) - (not (eq (aref (buffer-name buffer) 0) ?\s)) (or (buffer-file-name buffer) - (and pred - (progn - (set-buffer buffer) - (and buffer-offer-save (> (buffer-size) 0)))) - (buffer-local-value - 'write-contents-functions buffer)) + (with-current-buffer buffer + (or (eq buffer-offer-save 'always) + (and pred buffer-offer-save (> (buffer-size) 0))))) (or (not (functionp pred)) (with-current-buffer buffer (funcall pred))) (if arg -- cgit v1.2.1