* Question: suppress ask-user-about-lock?
@ 2021-12-08 17:34 Qiantan Hong
2021-12-08 19:17 ` Michael Albinus
0 siblings, 1 reply; 10+ messages in thread
From: Qiantan Hong @ 2021-12-08 17:34 UTC (permalink / raw)
To: emacs-devel@gnu.org
Is there a standard way to cause lock-buffer immediately fail?
(let ((noninteractive t)) (lock-buffer)) is an obvious one,
but not sure if it’s good practice.
Best,
Qiantan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 17:34 Question: suppress ask-user-about-lock? Qiantan Hong
@ 2021-12-08 19:17 ` Michael Albinus
2021-12-08 19:22 ` Qiantan Hong
0 siblings, 1 reply; 10+ messages in thread
From: Michael Albinus @ 2021-12-08 19:17 UTC (permalink / raw)
To: Qiantan Hong; +Cc: emacs-devel@gnu.org
Qiantan Hong <qhong@mit.edu> writes:
Hi,
> Is there a standard way to cause lock-buffer immediately fail?
Do you mean with "fail" that lock-buffer shall do nothing?
> (let ((noninteractive t)) (lock-buffer)) is an obvious one,
> but not sure if it’s good practice.
Set or bind create-lockfiles to nil.
> Best,
> Qiantan
Best regards, Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:17 ` Michael Albinus
@ 2021-12-08 19:22 ` Qiantan Hong
2021-12-08 19:36 ` Michael Albinus
2021-12-08 20:03 ` Eli Zaretskii
0 siblings, 2 replies; 10+ messages in thread
From: Qiantan Hong @ 2021-12-08 19:22 UTC (permalink / raw)
To: Michael Albinus; +Cc: emacs-devel@gnu.org
>> Is there a standard way to cause lock-buffer immediately fail?
>
> Do you mean with "fail" that lock-buffer shall do nothing?
No, I mean it should signal ‘file-locked without asking the user
(through ask-user-about-lock).
I intended to use it as a mutex in Elisp program.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:22 ` Qiantan Hong
@ 2021-12-08 19:36 ` Michael Albinus
2021-12-08 19:43 ` Qiantan Hong
2021-12-08 20:03 ` Eli Zaretskii
1 sibling, 1 reply; 10+ messages in thread
From: Michael Albinus @ 2021-12-08 19:36 UTC (permalink / raw)
To: Qiantan Hong; +Cc: emacs-devel@gnu.org
Qiantan Hong <qhong@mit.edu> writes:
Hi,
>>> Is there a standard way to cause lock-buffer immediately fail?
>>
>> Do you mean with "fail" that lock-buffer shall do nothing?
> No, I mean it should signal ‘file-locked without asking the user
> (through ask-user-about-lock).
> I intended to use it as a mutex in Elisp program.
What about (untested)
(cl-letf (((symbol-function #'ask-user-about-lock)
(lambda (file proponent)
(signal 'file-locked (list file proponent)))))
...)
Best regards, Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:36 ` Michael Albinus
@ 2021-12-08 19:43 ` Qiantan Hong
2021-12-08 20:12 ` Michael Albinus
2021-12-08 22:03 ` Matt Armstrong
0 siblings, 2 replies; 10+ messages in thread
From: Qiantan Hong @ 2021-12-08 19:43 UTC (permalink / raw)
To: emacs-devel@gnu.org; +Cc: Michael Albinus
> What about (untested)
>
> (cl-letf (((symbol-function #'ask-user-about-lock)
> (lambda (file proponent)
> (signal 'file-locked (list file proponent)))))
>
> ...)
I guess it will break under multi-thread environment?
Because FLET, or function cells in general, are not thread local.
I also feel like the above is as hacky as my
(let ((noninteractive t)) (lock-buffer))
Does anyone have more recommendations?
Best,
Qiantan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:22 ` Qiantan Hong
2021-12-08 19:36 ` Michael Albinus
@ 2021-12-08 20:03 ` Eli Zaretskii
2021-12-08 20:12 ` Qiantan Hong
1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2021-12-08 20:03 UTC (permalink / raw)
To: Qiantan Hong; +Cc: michael.albinus, emacs-devel
> From: Qiantan Hong <qhong@mit.edu>
> Date: Wed, 8 Dec 2021 19:22:44 +0000
> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>
> No, I mean it should signal ‘file-locked without asking the user
> (through ask-user-about-lock).
> I intended to use it as a mutex in Elisp program.
But we already have mutexes in Emacs, so why not use the real thing?
What am I missing?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:43 ` Qiantan Hong
@ 2021-12-08 20:12 ` Michael Albinus
2021-12-08 22:03 ` Matt Armstrong
1 sibling, 0 replies; 10+ messages in thread
From: Michael Albinus @ 2021-12-08 20:12 UTC (permalink / raw)
To: Qiantan Hong; +Cc: emacs-devel@gnu.org
Qiantan Hong <qhong@mit.edu> writes:
> I also feel like the above is as hacky as my
> (let ((noninteractive t)) (lock-buffer))
The docstring of ask-user-about-lock encourages to redefine the
function. There should be less side effects than binding noninteractive.
> Best,
> Qiantan
Best regards, Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 20:03 ` Eli Zaretskii
@ 2021-12-08 20:12 ` Qiantan Hong
0 siblings, 0 replies; 10+ messages in thread
From: Qiantan Hong @ 2021-12-08 20:12 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Michael Albinus, emacs-devel@gnu.org
> On Dec 8, 2021, at 12:04 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Qiantan Hong <qhong@mit.edu>
>> Date: Wed, 8 Dec 2021 19:22:44 +0000
>> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>>
>> No, I mean it should signal ‘file-locked without asking the user
>> (through ask-user-about-lock).
>> I intended to use it as a mutex in Elisp program.
>
> But we already have mutexes in Emacs, so why not use the real thing?
> What am I missing?
I’m using it to lock a key value store file when writing to it,
so Emacsen have mutual exclusive write access to it.
Seems that “mutex" usually refers to a particular kind of
intraprocess mutual exclusive lock, I apologize for the confusion.
I’m referring to something similar to flock(2).
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 19:43 ` Qiantan Hong
2021-12-08 20:12 ` Michael Albinus
@ 2021-12-08 22:03 ` Matt Armstrong
2021-12-08 22:12 ` Qiantan Hong
1 sibling, 1 reply; 10+ messages in thread
From: Matt Armstrong @ 2021-12-08 22:03 UTC (permalink / raw)
To: Qiantan Hong, emacs-devel@gnu.org; +Cc: Michael Albinus
Qiantan Hong <qhong@mit.edu> writes:
>> What about (untested)
>>
>> (cl-letf (((symbol-function #'ask-user-about-lock)
>> (lambda (file proponent)
>> (signal 'file-locked (list file proponent)))))
>>
>> ...)
>
> I guess it will break under multi-thread environment? Because FLET,
> or function cells in general, are not thread local.
(info "(elisp)Threads") talks about `let' bindings being thread local.
I always took that to apply to the other let-like bindings as well. It
looks like `cl-letf' uses `let*' under the hood.
> I also feel like the above is as hacky as my (let ((noninteractive t))
> (lock-buffer)) Does anyone have more recommendations?
It think it feels hacky because `ask-user-about-lock' is a decades old
API and was probably introduced before the abnormal hook convention took
hold (info "(elisp)Standard Hooks"). I suspect that back then
redefining functions as a customization point was more common.
If the API were added today I think you'd see an
`ask-user-about-lock-function' (or functions) var that is bound to
#'ask-user-about-lock by default. The Emacs C layer would then funcall
it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Question: suppress ask-user-about-lock?
2021-12-08 22:03 ` Matt Armstrong
@ 2021-12-08 22:12 ` Qiantan Hong
0 siblings, 0 replies; 10+ messages in thread
From: Qiantan Hong @ 2021-12-08 22:12 UTC (permalink / raw)
To: Matt Armstrong; +Cc: Michael Albinus, emacs-devel@gnu.org
> (info "(elisp)Threads") talks about `let' bindings being thread local.
> I always took that to apply to the other let-like bindings as well. It
> looks like `cl-letf' uses `let*' under the hood.
For LETFing a symbol-function, it FSETs under the hood, which is not
safe. In fact it is impossible to do it using thread-safe let only,
because code outside of the CL-LETF calls the function from
the function cell, and to have your binding affect them the only
way is to set the thread-unsafe function cell.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-12-08 22:12 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-08 17:34 Question: suppress ask-user-about-lock? Qiantan Hong
2021-12-08 19:17 ` Michael Albinus
2021-12-08 19:22 ` Qiantan Hong
2021-12-08 19:36 ` Michael Albinus
2021-12-08 19:43 ` Qiantan Hong
2021-12-08 20:12 ` Michael Albinus
2021-12-08 22:03 ` Matt Armstrong
2021-12-08 22:12 ` Qiantan Hong
2021-12-08 20:03 ` Eli Zaretskii
2021-12-08 20:12 ` Qiantan Hong
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).