* [PATCH] Save unmodified buffer when file has been deleted
@ 2011-02-11 9:19 Bastien
2011-02-11 9:29 ` Eli Zaretskii
2011-02-11 14:38 ` Stefan Monnier
0 siblings, 2 replies; 12+ messages in thread
From: Bastien @ 2011-02-11 9:19 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 253 bytes --]
If you accidently delete the file while an unmodified buffer is visiting
it, trying to save this buffer will fail because it's unmodified.
This patch fixes this problem.
Let me know if it's okay to commit it (with a proper ChangeLog entry).
Thanks,
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: basic_save_buffer.patch --]
[-- Type: text/x-patch, Size: 670 bytes --]
diff --git a/lisp/files.el b/lisp/files.el
index 8b42eaa..029c55d 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4309,7 +4309,11 @@ Before and after saving the buffer, this function runs
;; In an indirect buffer, save its base buffer instead.
(if (buffer-base-buffer)
(set-buffer (buffer-base-buffer)))
- (if (buffer-modified-p)
+ (if (or (buffer-modified-p)
+ ;; handle the case when no modification has been made but
+ ;; the file has been delete
+ (and (buffer-file-name)
+ (not (file-exists-p (buffer-file-name)))))
(let ((recent-save (recent-auto-save-p))
setmodes)
;; If buffer has no file name, ask user for one.
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
--
Bastien
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 9:19 [PATCH] Save unmodified buffer when file has been deleted Bastien
@ 2011-02-11 9:29 ` Eli Zaretskii
2011-02-11 9:48 ` Bastien
2011-02-11 14:38 ` Stefan Monnier
1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2011-02-11 9:29 UTC (permalink / raw)
To: Bastien; +Cc: emacs-devel
> From: Bastien <bastien.guerry@wikimedia.fr>
> Date: Fri, 11 Feb 2011 10:19:08 +0100
>
> + (if (or (buffer-modified-p)
> + ;; handle the case when no modification has been made but
> + ;; the file has been delete
^^^^^^^^^^^^^^^
"has been deleted". Actually, I would say "the file disappeared since
visited" or some such.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 9:29 ` Eli Zaretskii
@ 2011-02-11 9:48 ` Bastien
2011-02-11 15:13 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2011-02-11 9:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Bastien <bastien.guerry@wikimedia.fr>
>> Date: Fri, 11 Feb 2011 10:19:08 +0100
>>
>> + (if (or (buffer-modified-p)
>> + ;; handle the case when no modification has been made but
>> + ;; the file has been delete
> ^^^^^^^^^^^^^^^
> "has been deleted". Actually, I would say "the file disappeared since
> visited" or some such.
Yes, right.
Is that okay to commit this? Would be my first commit from bzr, I'm
quite nervous about it :)
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 9:19 [PATCH] Save unmodified buffer when file has been deleted Bastien
2011-02-11 9:29 ` Eli Zaretskii
@ 2011-02-11 14:38 ` Stefan Monnier
2011-02-11 14:55 ` Lennart Borgman
2011-02-11 17:37 ` Bastien
1 sibling, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2011-02-11 14:38 UTC (permalink / raw)
To: Bastien; +Cc: emacs-devel
> + (and (buffer-file-name)
> + (not (file-exists-p (buffer-file-name)))))
Please just use the buffer-file-name variable rather than the function.
Other than that, it looks like a good change (I've gotten used to
hitting SPC Backspace C-x C-s, and I also use this when I just want to
`touch' the file, so I probably won't use this feature much, tho).
Stefan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 14:38 ` Stefan Monnier
@ 2011-02-11 14:55 ` Lennart Borgman
2011-02-11 23:02 ` Stefan Monnier
2011-02-11 17:37 ` Bastien
1 sibling, 1 reply; 12+ messages in thread
From: Lennart Borgman @ 2011-02-11 14:55 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel, Bastien
On Fri, Feb 11, 2011 at 3:38 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> + (and (buffer-file-name)
>> + (not (file-exists-p (buffer-file-name)))))
>
> Please just use the buffer-file-name variable rather than the function.
> Other than that, it looks like a good change (I've gotten used to
> hitting SPC Backspace C-x C-s, and I also use this when I just want to
> `touch' the file, so I probably won't use this feature much, tho).
Why is the variable buffer-file-name preferred over the function?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 14:55 ` Lennart Borgman
@ 2011-02-11 23:02 ` Stefan Monnier
0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2011-02-11 23:02 UTC (permalink / raw)
To: Lennart Borgman; +Cc: emacs-devel, Bastien
>>> + (and (buffer-file-name)
>>> + (not (file-exists-p (buffer-file-name)))))
>>
>> Please just use the buffer-file-name variable rather than the function.
>> Other than that, it looks like a good change (I've gotten used to
>> hitting SPC Backspace C-x C-s, and I also use this when I just want to
>> `touch' the file, so I probably won't use this feature much, tho).
> Why is the variable buffer-file-name preferred over the function?
Because IMHO the function is just a historical accident.
And the variable is slightly more efficient.
Stefan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Save unmodified buffer when file has been deleted
2011-02-11 14:38 ` Stefan Monnier
2011-02-11 14:55 ` Lennart Borgman
@ 2011-02-11 17:37 ` Bastien
1 sibling, 0 replies; 12+ messages in thread
From: Bastien @ 2011-02-11 17:37 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> + (and (buffer-file-name)
>> + (not (file-exists-p (buffer-file-name)))))
>
> Please just use the buffer-file-name variable rather than the
> function.
Done, thanks.
> Other than that, it looks like a good change (I've gotten used to
> hitting SPC Backspace C-x C-s, and I also use this when I just want to
> `touch' the file, so I probably won't use this feature much, tho).
Well, we shouldn't get used to hit useless keystrokes :)
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2011-02-11 23:02 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-11 9:19 [PATCH] Save unmodified buffer when file has been deleted Bastien
2011-02-11 9:29 ` Eli Zaretskii
2011-02-11 9:48 ` Bastien
2011-02-11 15:13 ` Eli Zaretskii
2011-02-11 17:56 ` Bastien
2011-02-11 18:50 ` Eli Zaretskii
2011-02-11 19:01 ` Bastien
2011-02-11 19:29 ` Eli Zaretskii
2011-02-11 14:38 ` Stefan Monnier
2011-02-11 14:55 ` Lennart Borgman
2011-02-11 23:02 ` Stefan Monnier
2011-02-11 17:37 ` Bastien
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).