GNU bug report logs -
#12507
24.2.50; `bookmark-write-file': use `write-file', not `write-region', to get backups
Previous Next
Reported by: "Drew Adams" <drew.adams <at> oracle.com>
Date: Mon, 24 Sep 2012 18:44:01 UTC
Severity: wishlist
Tags: notabug
Found in version 24.2.50
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #67 received at 12507 <at> debbugs.gnu.org (full text, mbox):
"Drew Adams" <drew.adams <at> oracle.com> writes:
>> >> ;; Don't use write-file; we don't want this buffer to visit it.
>> >
>> > After write-file, the buffer is marked as visiting that file, which
>> > affects the behavior of C-x C-f and a lot more (e.g. asks the user
>> > for confirmation if the file was modified by some other process, ...).
>>
>> What about improving write-region to use backup when needed?
>> Possibly writing a new write-region-something function that handle
>> backup, or a write-file-noselect function.
>
> +1
>
> And please let us know how best to accomplish that (in the doc perhaps, but also
> in this thread).
>
> It's not clear to me how to make a backup copy of a file without visiting that
> file in some buffer, however temporarily.
>
> For example, I can imagine this as a way to append the region to a file and back
> it up:
>
> (write-region (point-min) (point-max) FILE 'append)
> (with-current-buffer (find-file-noselect FILE) (backup-buffer))
>
> But IIUC `find-file-noselect' visits the buffer (and so "asks the user for
> confirmation if the file was modified by some other process"). So that's
> apparently not the way to go. What is?
>
> Leaving the question of visiting aside for the moment, what about
> `backup-buffer' here? Should it be `save-buffer' instead, so that the modes of
> FILE get updated properly? Should it be just `basic-save-buffer-1' instead of
> `save-buffer'?
>
> And should any such code take what Juri mentioned wrt vc into account? If so,
> how?
>
> It's not clear to me how best to handle this
> write-stuff-to-a-file-and-back-it-up-when-appropriate, but I (and perhaps
> others) would like to learn. I haven't found the answer by looking at the
> manuals or perusing the source code. Can you help?
Will try to look better to this tomorrow if I find time, just for
`bookmark-write-file', what about something like this?
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1355,7 +1355,7 @@
(defun bookmark-write-file (file)
"Write `bookmark-alist' to FILE."
(bookmark-maybe-message "Saving bookmarks to file %s..." file)
- (with-current-buffer (get-buffer-create " *Bookmarks*")
+ (with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(delete-region (point-min) (point-max))
(let ((print-length nil)
@@ -1374,7 +1374,7 @@
((eq 'nospecial bookmark-version-control) version-control)
(t t))))
(condition-case nil
- (write-region (point-min) (point-max) file)
+ (save-buffer)
(file-error (message "Can't write %s" file)))
(kill-buffer (current-buffer))
(bookmark-maybe-message
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
This bug report was last modified 4 years and 176 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.