all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Stuart D. Herring" <herring@lanl.gov>
Cc: emacs-devel@gnu.org
Subject: Re: Missing `with' macro?
Date: Mon, 7 Aug 2006 14:38:10 -0700 (PDT)	[thread overview]
Message-ID: <48104.128.165.123.18.1154986690.squirrel@webmail.lanl.gov> (raw)
In-Reply-To: <E1G9xEu-0005xM-Ia@fencepost.gnu.org>

>     If we use REUSE nil and WRITE t, then if the user has visited the file
>     (which could easily be a file for which WRITE t makes sense, e.g.
>     ~/.emacs.d/.whatever-package-rc) and has unsaved changes in it, those
> are
>     effectively lost because they may clash with the updated file.
>
> Maybe that is correct.  It would be as if some other unrelated program
> had altered the file.  If the person tries to save his buffer, Emacs
> will report that the file has changed.
>
> To use the user's existing buffer would save the user's own unsaved
> changes without asking.  That is completely unacceptable.

Is it completely unacceptable even if the file in question is principally
"owned" by code anyway?  I can't imagine that `with-file' would ever be
invoked on someone's source code unless it was a specialized tool that
would (via confirmation or so) verify the user's intent.

> I can see one other conceivable way to handle this case: to merge the
> changes that the program makes into the user's own buffer, imitating
> the example of CVS merging remote and local changes.  But that is not
> easy to do.

I see other possibilities:
1. (and REUSE WRITE (buffer-modified-p #<buffer extant-buffer>) (error
"Attempt to co-opt user's unsaved changes")) - that is, only allow REUSE
and WRITE on an unmodified buffer.
2. Go on modifying (because of WRITE) the buffer (because of REUSE), but
don't save the changes at the end, or else ask the user whether to save
them.

Either of these could be combined with a query beforehand:
"Lisp wants to modify foobar.c.  (S)ave your changes first or (r)evert the
buffer first?  (s or r)"
(Of course, C-g would also be a useful response.)

> Unless we implement such merging, I stand by what I said:
> WRITE = t requires REUSE = nil.

I'd really like to keep the option, but if we can't find a reasonable
solution I'll do that.

> Please show me the code you're talking about; it is the only way I can
> understand this.

OK, I've done my homework now.  The querying function is
`ask-user-about-supersession-threat'; it's called from lock_file() in
filelock.c, which uses get_truename_buffer() to find the buffer whose
modification time to examine.  This means that if an existing buffer
visiting the file is out of date, and get_truename_buffer() happens to
return it instead of the up-to-date buffer created by `with-file', the
supersession query will be raised.

I don't know what the correct approach is here (without rewriting
lock_file()): should I `flet' `ask-user-about-supersession-threat', or
what?

My current version of `with-file' does avoid losing the proper file name
by destroying its filename only after entering the `unwind-protect' that
restores it, and restoring it as the first unwind action.  (This was made
much simpler by the use of `find-file-noselect-1', as it reduced the
period of time during which the file name needed to be hidden.)

> Nothing bad happens.  Don't worry about this.

OK.  Worrying halted (and `buffer-read-only' let-bound).

Davis

PS - While investigating this, I discovered the variable `buffer_count' in
buffer.c: it seems to never be used by any code anywhere.  Is it obsolete?

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

  reply	other threads:[~2006-08-07 21:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-24 10:17 Missing `with' macro? Mathias Dahl
2006-07-24 13:46 ` Stefan Monnier
2006-07-24 14:33   ` Mathias Dahl
2006-07-24 18:22 ` Richard Stallman
2006-07-24 20:55   ` Jorgen Schaefer
2006-07-25  3:09     ` Richard Stallman
2006-07-28  2:14   ` Stuart D. Herring
2006-07-28  2:23     ` Stuart D. Herring
2006-07-29 15:18     ` Richard Stallman
2006-08-01  1:06       ` Stuart D. Herring
2006-08-07  5:01         ` Richard Stallman
2006-08-07 21:38           ` Stuart D. Herring [this message]
2006-08-08 18:01             ` Richard Stallman
2006-08-08 18:32               ` Stuart D. Herring
2006-08-09  4:58                 ` Richard Stallman
2006-08-08 18:01             ` Richard Stallman
2006-08-16 19:59               ` Stuart D. Herring
2006-08-17 15:18                 ` Richard Stallman

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

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

  git send-email \
    --in-reply-to=48104.128.165.123.18.1154986690.squirrel@webmail.lanl.gov \
    --to=herring@lanl.gov \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.