unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* LOCK-BUFFER when two buffer visits the same buffer
@ 2021-12-11 10:00 Qiantan Hong
  2021-12-11 11:29 ` Tassilo Horn
  2021-12-11 11:39 ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Qiantan Hong @ 2021-12-11 10:00 UTC (permalink / raw)
  To: emacs-devel@gnu.org

I do lock-buffer in the first buffer, then in the second buffer,
and I killed the second buffer, the lock is gone — even it seems
that buffer one should hold the lock!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: LOCK-BUFFER when two buffer visits the same buffer
  2021-12-11 10:00 LOCK-BUFFER when two buffer visits the same buffer Qiantan Hong
@ 2021-12-11 11:29 ` Tassilo Horn
  2021-12-11 12:06   ` Qiantan Hong
  2021-12-11 11:39 ` Eli Zaretskii
  1 sibling, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2021-12-11 11:29 UTC (permalink / raw)
  To: Qiantan Hong; +Cc: emacs-devel

Qiantan Hong <qhong@mit.edu> writes:

> I do lock-buffer in the first buffer, then in the second buffer, and I
> killed the second buffer, the lock is gone — even it seems that buffer
> one should hold the lock!

More details, please.  Do you just call (lock-buffer) or (lock-buffer
"~/file")?  One emacs instance or two?

As I understand the docs, file locks are not associated with a buffer
but the emacs instance and (lock-buffer) is just a shorthand for

  (when (buffer-modified-p)
    (lock-file (buffer-file-name)))

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: LOCK-BUFFER when two buffer visits the same buffer
  2021-12-11 10:00 LOCK-BUFFER when two buffer visits the same buffer Qiantan Hong
  2021-12-11 11:29 ` Tassilo Horn
@ 2021-12-11 11:39 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2021-12-11 11:39 UTC (permalink / raw)
  To: Qiantan Hong; +Cc: emacs-devel

> From: Qiantan Hong <qhong@mit.edu>
> Date: Sat, 11 Dec 2021 10:00:00 +0000
> Accept-Language: en-US
> 
> I do lock-buffer in the first buffer, then in the second buffer,
> and I killed the second buffer, the lock is gone — even it seems
> that buffer one should hold the lock!

lock-buffer doesn't support what you are evidently trying to do.  Its
intended use is to prevent simultaneous modifications of a file by two
users, or by a single user from two separate instances of Emacs.  You
want reference counting (and probably also locking the file in the
filesystem), and that isn't supported.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: LOCK-BUFFER when two buffer visits the same buffer
  2021-12-11 11:29 ` Tassilo Horn
@ 2021-12-11 12:06   ` Qiantan Hong
  0 siblings, 0 replies; 4+ messages in thread
From: Qiantan Hong @ 2021-12-11 12:06 UTC (permalink / raw)
  To: Tassilo Horn, Eli Zaretskii; +Cc: emacs-devel@gnu.org

> lock-buffer doesn't support what you are evidently trying to do.  Its
> intended use is to prevent simultaneous modifications of a file by two
> users, or by a single user from two separate instances of Emacs.  You
> want reference counting (and probably also locking the file in the
> filesystem), and that isn't supported.
Figured that out, thanks. I could add reference counting myself,
but it probably doesn’t worth the effort at the moment.
The scenario comes up in the case of recursive transaction,
and guess I’ll just drop support for recursive transaction for now.

>> I do lock-buffer in the first buffer, then in the second buffer, and I
>> killed the second buffer, the lock is gone — even it seems that buffer
>> one should hold the lock!
> 
> More details, please.  Do you just call (lock-buffer) or (lock-buffer
> "~/file")?  One emacs instance or two?
It’s one Emacs instance.
I called (lock-buffer) after I set the buffer-file-truename of a temporary buffer.
In my case, (lock-buffer FILE) seems to make more sense, but I don’t
know how to unlock it. Therefore I just fake it with a temporary buffer
(so I can unlock it by doing (unlock-buffer) in that buffer later, or 
just kill it directly)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-11 12:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11 10:00 LOCK-BUFFER when two buffer visits the same buffer Qiantan Hong
2021-12-11 11:29 ` Tassilo Horn
2021-12-11 12:06   ` Qiantan Hong
2021-12-11 11:39 ` Eli Zaretskii

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).