emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 29.0.60; keymap-local-set and keymap-global-set became less strict


From: Daniel Mendler
Subject: Re: 29.0.60; keymap-local-set and keymap-global-set became less strict
Date: Wed, 1 Feb 2023 21:22:21 +0100

On 2/1/23 19:54, Stefan Monnier wrote:
>> I think call-interactively-p would be better for this use case, but
>> that's my opinion versus yours.
> 
> Have you ever looked at the implementation of `called-interactively-p`?

I guess there is no doubt that we all agree that the implementation is
not great. But I would not consider it prohibitively bad, such that it
should never ever be used in new code. If that is the case why is the
function not officially deprecated?

To be clear, I was aware of the recommendation to avoid
`called-interactively-p' and iirc I have not used it in any of my
packages. It is a kludge to use it, but using "hidden arguments" and
"advertised calling convention" seems as much a kludge in my eyes. Is it
commonly agreed upon that advertised calling conventions are the lesser
evil? I've usually understood advertised calling convention as a means
for deprecation - did I misunderstand that? I wonder if
`called-interactively-p' would lead to actual problems in this
particular use case?

The problem with the hidden INTERACTIVE (or ALLOW-VECTOR) argument is
that it is still somewhat exposed to non-interactive callers. For
example, in the context of the Compat library, should this argument be
made available, since non-interactive callers may want to use it? What
if callers start to use it if they want to pass vector arguments?

An example where INTERACTIVE arguments seems more justified to me are
the `completion-at-point-functions' provided by my Cape package. The
Capf `cape-line', which also happens to be a command, completes full
lines in a buffer. If called interactively or with a non-nil interactive
argument, it will use `completion-in-region'. The nice property is that
the equivalence `(call-interactively #'cape-line) == (cape-line t)` holds.

To come back to `keymap-local-set' - the good thing is that we can avoid
both kludges, advertised calling conventions and `call-interactively-p'.
All we have to do is move the key reading entirely to the interactive
form, which also seems to be semantically most correct. If I would rate
the possible solutions:

1. Just allow vector arguments for all the functions. Simplest solution,
least amount of code.

2. Use `(interactive (list (keymap--read-key) ...))`. Unfortunately this
solution lead to technical difficulties in the `keymap--read-key' function.

3. Use the `call-interactively-p' kludge.

4. Use the hidden INTERACTIVE argument kludge.

Unfortunately none of the solutions 1 to 3 seems to be good enough.

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]