unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: "Drew Adams" <drew.adams@oracle.com>
Cc: 12507@debbugs.gnu.org
Subject: bug#12507: [debbugs-tracker] Processed: severity 12507 wishlist
Date: Fri, 28 Sep 2012 11:04:34 +0200	[thread overview]
Message-ID: <87haqildr1.fsf@gmail.com> (raw)
In-Reply-To: <9D98A7802F07462887BCC67BE194243B@us.oracle.com> (Drew Adams's message of "Thu, 27 Sep 2012 11:37:02 -0700")

"Drew Adams" <drew.adams@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))
This is not efficient IMO, like the actual version of
`bookmark-write-file':

1) create a new buffer named "*Bookmarks*".
2) erase buffer
3) write data to it.
4) write contents of this buffer to FILE.
5) save this FILE.

instead:

1) open FILE buffer
2) erase buffer
3) write data to it
4) save 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?
What is the problem for this?
What if you open another emacs session, bookmark something in this
session, (don't save and don't quit session) switch to the initial
session, bookmark something there and save bookmarks?
It is good if it ask you for confirmation at some point, no? 

> 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'?
`save-buffer' do all the job (saving and backing up), so why writing to
buffer and then using `backup-buffer'

> And should any such code take what Juri mentioned wrt vc into account?  If so,
> how?
`save-buffer' handle that.

> 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?

I think that doing like in the patch I sent is not too bad:

(with-current-buffer (find-file-noselect file)
   write--data--here
   [...]
   (save-buffer))

No more is needed I think, but maybe I miss something?

Also, the use of `bookmark-version-control' is questionable, why
handling this file specially?
If following that, we should have a special variable for .emacs-custom.el,
desktop, history, etc... which is non--sense.

If this variable is removed, the global value of version-control will be
used and .emacs.bmk will be backed up like any other file,
like it does (or should do because it is broken with write-region) with
its default value 'nospecial.

Note that with the patch I sent, it seems a little bit faster to save,
but maybe I am wrong, need to verify. (we write one time the data and
save instead of writing two time and save)

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 





  parent reply	other threads:[~2012-09-28  9:04 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87bogubqjy.fsf@gnu.org>
     [not found] ` <handler.s.C.13485522721217.transcript@debbugs.gnu.org>
2012-09-25 13:53   ` bug#12507: [debbugs-tracker] Processed: severity 12507 wishlist Drew Adams
2012-09-26  2:53     ` Chong Yidong
2012-09-26  3:18       ` Drew Adams
2012-09-26  4:04         ` Stefan Monnier
2012-09-26 14:19           ` Drew Adams
2012-09-26 19:46             ` Stefan Monnier
2012-09-26 20:31               ` Drew Adams
2012-09-26 21:46         ` Karl Fogel
2012-09-26 22:26           ` Drew Adams
2012-09-26 23:36             ` Drew Adams
2012-09-27 15:48             ` Karl Fogel
2012-09-27 16:00               ` Drew Adams
2012-09-27 17:57                 ` Karl Fogel
2012-09-27 18:32                   ` Drew Adams
2012-09-27  3:24           ` Stefan Monnier
2012-09-24 18:41             ` bug#12507: 24.2.50; `bookmark-write-file': use `write-file', not `write-region', to get backups Drew Adams
2012-09-27  5:38               ` bug#12507: [debbugs-tracker] Processed: severity 12507 wishlist Thierry Volpiatto
2012-09-27 18:37                 ` Drew Adams
2012-09-27 21:16                   ` Thierry Volpiatto
2012-09-28  9:04                   ` Thierry Volpiatto [this message]
2012-09-28 20:00                     ` Drew Adams
2012-09-29  7:42               ` Thierry Volpiatto
2012-09-29 14:36                 ` Drew Adams
2012-09-29 15:12                   ` Thierry Volpiatto
2012-09-29 15:51                     ` Drew Adams
2012-09-29 16:20               ` Thierry Volpiatto
2012-09-29 16:50                 ` Drew Adams
2012-09-29 16:57                   ` Thierry Volpiatto
2012-10-01  3:38               ` bug#12507: Option `(bookmark-)version-control': Use :tag so doc string matches menu Karl Fogel
2012-10-01  4:06                 ` bug#12507: Option `(bookmark-)version-control': Use :tag so docstring " Drew Adams
2012-10-01  4:13               ` bug#12507: Have I mentioned how much I hate Debbugs? Karl Fogel
2012-10-01  4:50                 ` Drew Adams
2012-10-01 21:23                   ` Karl Fogel
2012-10-01 22:00                     ` Drew Adams
2012-10-02  5:31                       ` Thierry Volpiatto
2020-11-29  1:07               ` bug#12507: [debbugs-tracker] Processed: severity 12507 wishlist Karl Fogel
2012-09-27  8:36         ` bug#12507: `bookmark-write-file': use `write-file', not `write-region', to get backups Juri Linkov
2012-09-27 15:02           ` Drew Adams
2020-09-18 15:02       ` bug#12507: [debbugs-tracker] Processed: severity 12507 wishlist Lars Ingebrigtsen
2020-09-18 16:23         ` Drew Adams
2020-09-19 14:18           ` Lars Ingebrigtsen
2020-09-19 17:29             ` Drew Adams
2020-09-23  6:41               ` Karl Fogel
2020-09-23 13:34                 ` Lars Ingebrigtsen
2020-09-23 16:23                   ` Eli Zaretskii
2020-09-24 13:58                     ` Lars Ingebrigtsen
2020-09-29  5:27                       ` Karl Fogel
2020-09-29 14:29                         ` Lars Ingebrigtsen
2020-09-23 14:27                 ` Eli Zaretskii
2020-09-23 18:13                   ` Drew Adams
2020-09-23 18:14                 ` Drew Adams
2020-09-29  5:25                   ` Karl Fogel
2020-09-29 15:45                     ` Drew Adams
2020-11-29  0:28                       ` Karl Fogel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87haqildr1.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=12507@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).