* Is `kbd' idempotent?
@ 2015-11-30 15:26 Michael Heerdegen
2015-11-30 15:39 ` David Kastrup
2015-11-30 16:30 ` Random832
0 siblings, 2 replies; 10+ messages in thread
From: Michael Heerdegen @ 2015-11-30 15:26 UTC (permalink / raw)
To: Emacs Development
Hello,
is `kbd' idempotent?
I want to prompt the user for a key sequence in any common format. If
he enters a string and already uses the format that `kbd' outputs, can
it be bad to call `kbd' on the input?
Thanks,
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 15:26 Is `kbd' idempotent? Michael Heerdegen
@ 2015-11-30 15:39 ` David Kastrup
2015-11-30 16:01 ` Michael Heerdegen
2015-11-30 16:30 ` Random832
1 sibling, 1 reply; 10+ messages in thread
From: David Kastrup @ 2015-11-30 15:39 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: Emacs Development
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Hello,
>
> is `kbd' idempotent?
>
> I want to prompt the user for a key sequence in any common format. If
> he enters a string and already uses the format that `kbd' outputs, can
> it be bad to call `kbd' on the input?
Uh, how is somebody going to input the format that `kbd' outputs? The
input is a string, the output often a vector.
And no, kbd does not accept such vectors as input.
--
David Kastrup
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 15:39 ` David Kastrup
@ 2015-11-30 16:01 ` Michael Heerdegen
2015-11-30 16:24 ` Random832
2015-11-30 16:24 ` Andreas Schwab
0 siblings, 2 replies; 10+ messages in thread
From: Michael Heerdegen @ 2015-11-30 16:01 UTC (permalink / raw)
To: David Kastrup; +Cc: Emacs Development
David Kastrup <dak@gnu.org> writes:
> Uh, how is somebody going to input the format that `kbd' outputs? The
> input is a string, the output often a vector.
>
> And no, kbd does not accept such vectors as input.
That part is not a problem, since I pass only strings to `kbd'.
Mmh, maybe it should better ask: if KEYS is a string that describes a
key sequence in any format that Emacs understands, or in the format that
is used for keyboard macros, and I call `kbd' on it, is the result
always a representation of same key sequence? The docstring of `kbd'
leaves open what it does with formats different from the keyboard macro
format. Or is there any test that I could use to decide whether KEYS is
in the keyboard macro format?
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 16:01 ` Michael Heerdegen
@ 2015-11-30 16:24 ` Random832
2015-12-01 14:25 ` Michael Heerdegen
2015-11-30 16:24 ` Andreas Schwab
1 sibling, 1 reply; 10+ messages in thread
From: Random832 @ 2015-11-30 16:24 UTC (permalink / raw)
To: emacs-devel
On 2015-11-30, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Mmh, maybe it should better ask: if KEYS is a string that describes a
> key sequence in any format that Emacs understands, or in the format that
> is used for keyboard macros, and I call `kbd' on it, is the result
> always a representation of same key sequence? The docstring of `kbd'
> leaves open what it does with formats different from the keyboard macro
> format. Or is there any test that I could use to decide whether KEYS is
> in the keyboard macro format?
What exactly do you define as "any format that Emacs
understands" - do you want to allow backslash-escapes (even
though no characters requiring such are used in keyboard macro
format)? Control characters typed directly with C-q? A vector
literal such as "[?\\M-x]" representing [134217848]? The string
"(kbd \"foo\")"? Emacs understands all of these.
Basically, what other formats, specifically, do you want to
accept? What formats do you think your documentation will cause
your users to be inclined to type?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 16:01 ` Michael Heerdegen
2015-11-30 16:24 ` Random832
@ 2015-11-30 16:24 ` Andreas Schwab
1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2015-11-30 16:24 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: David Kastrup, Emacs Development
Michael Heerdegen <michael_heerdegen@web.de> writes:
> David Kastrup <dak@gnu.org> writes:
>
>> Uh, how is somebody going to input the format that `kbd' outputs? The
>> input is a string, the output often a vector.
>>
>> And no, kbd does not accept such vectors as input.
>
> That part is not a problem, since I pass only strings to `kbd'.
Trivial counter example: (kbd (kbd "SPC"))
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 15:26 Is `kbd' idempotent? Michael Heerdegen
2015-11-30 15:39 ` David Kastrup
@ 2015-11-30 16:30 ` Random832
1 sibling, 0 replies; 10+ messages in thread
From: Random832 @ 2015-11-30 16:30 UTC (permalink / raw)
To: emacs-devel
On 2015-11-30, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> is `kbd' idempotent?
It occured to me after posting my previous reply, there is one
obvious case where the output of kbd is a string, which is itself a
valid string in keyboard macro format, representing a different key
sequence. Consider the following:
(kbd "C - x SPC S P C SPC C - c")
"C-x SPC C-c"
(kbd "C-x SPC C-c")
"\C-x \C-c"
(kbd "\C-x \C-c")
"\C-x\C-c"
So the answer is clearly not, even in cases where it looks like it
might be.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-11-30 16:24 ` Random832
@ 2015-12-01 14:25 ` Michael Heerdegen
2015-12-01 15:37 ` Random832
0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2015-12-01 14:25 UTC (permalink / raw)
To: emacs-devel
Random832 <random832@fastmail.com> writes:
> What exactly do you define as "any format that Emacs
> understands" - do you want to allow backslash-escapes (even
> though no characters requiring such are used in keyboard macro
> format)? Control characters typed directly with C-q? A vector
> literal such as "[?\\M-x]" representing [134217848]? The string
> "(kbd \"foo\")"? Emacs understands all of these.
> Basically, what other formats, specifically, do you want to
> accept? What formats do you think your documentation will cause
> your users to be inclined to type?
The input from the user is `read' and evaluated. Any expression that
evaluates to something that would be accepted by `define-key' should be
accepted as input.
I'm deliberating if I'm doing the user a favor if I pass any `stringp'
input implicitly to `kbd', because the keyboard macro format seems to be
quite popular. That would spare him to wrap his input into `kbd' by
himself. But if the result of `kbd' can change the "semantics" of a
string describing a key sequence - as your counterexamples demonstrate -
I can't do that.
Thanks for all answers,
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-12-01 14:25 ` Michael Heerdegen
@ 2015-12-01 15:37 ` Random832
2015-12-01 18:32 ` Michael Heerdegen
2015-12-02 18:33 ` Michael Heerdegen
0 siblings, 2 replies; 10+ messages in thread
From: Random832 @ 2015-12-01 15:37 UTC (permalink / raw)
To: emacs-devel
On 2015-12-01, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> I'm deliberating if I'm doing the user a favor if I pass any `stringp'
> input implicitly to `kbd', because the keyboard macro format seems to be
> quite popular. That would spare him to wrap his input into `kbd' by
> himself. But if the result of `kbd' can change the "semantics" of a
> string describing a key sequence - as your counterexamples demonstrate -
> I can't do that.
What about calling kbd only if the 'read' result is a string? That way
if they really want to pass a self-made string, they can do e.g.
(identity "foo"), whereas "foo" alone will be treated as (kbd "foo")
I do wonder what the use case is, though, that benefits from allowing
the entry of an arbitrary lisp expression instead of just directly
passing the user input to kbd without even a read/eval stage. Are there
key sequences that can't be represented in kbd format that the user will
want to enter as vector literals?
How about a heuristic? If the first character of input is ", it is read
and passed to kbd. If it is [, it is read. If it is (, it read and
eval'd. Otherwise, it is passed directly to kbd. That'd save them from
having to type a string literal in the (I assume most common) case they
simply want to pass a printable string to kbd.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-12-01 15:37 ` Random832
@ 2015-12-01 18:32 ` Michael Heerdegen
2015-12-02 18:33 ` Michael Heerdegen
1 sibling, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2015-12-01 18:32 UTC (permalink / raw)
To: emacs-devel
Random832 <random832@fastmail.com> writes:
> What about calling kbd only if the 'read' result is a string? That way
> if they really want to pass a self-made string, they can do e.g.
> (identity "foo"), whereas "foo" alone will be treated as (kbd "foo")
I want to avoid to introduce such a complexity for that little gain.
From what I heard, I think it's cleaner to let the user type the `kbd'
call if he prefers the `kbd' format.
> I do wonder what the use case is, though, that benefits from allowing
> the entry of an arbitrary lisp expression instead of just directly
> passing the user input to kbd without even a read/eval stage. Are there
> key sequences that can't be represented in kbd format that the user will
> want to enter as vector literals?
The input can be inserted via copy and paste or another method different
from typing literally. Also the binding of a variable or the result
of something like (my-private-version-of-kbd KEYS ...) should be
supported.
Thanks,
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Is `kbd' idempotent?
2015-12-01 15:37 ` Random832
2015-12-01 18:32 ` Michael Heerdegen
@ 2015-12-02 18:33 ` Michael Heerdegen
1 sibling, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2015-12-02 18:33 UTC (permalink / raw)
To: emacs-devel
Random832 <random832@fastmail.com> writes:
> I do wonder what the use case is, though, that benefits from allowing
> the entry of an arbitrary lisp expression instead of just directly
> passing the user input to kbd without even a read/eval stage. Are there
> key sequences that can't be represented in kbd format that the user will
> want to enter as vector literals?
Finally, I think that was a good question. It's easy enough to use C-u
M-: to insert the evaluation result of an arbitrary expression into the
minibuffer, so restricting the input to strings and vectors is fine.
But I don't want to force usage of kbd syntax, so I additionally allowed
the expression to be of the form (kbd STRING), and only in this special
case, there is an evaluation happening. The user can easily define his
own version of the thing that calls kbd in every case, so everybody
should be happy.
Thanks again,
Michael.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-12-02 18:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-30 15:26 Is `kbd' idempotent? Michael Heerdegen
2015-11-30 15:39 ` David Kastrup
2015-11-30 16:01 ` Michael Heerdegen
2015-11-30 16:24 ` Random832
2015-12-01 14:25 ` Michael Heerdegen
2015-12-01 15:37 ` Random832
2015-12-01 18:32 ` Michael Heerdegen
2015-12-02 18:33 ` Michael Heerdegen
2015-11-30 16:24 ` Andreas Schwab
2015-11-30 16:30 ` Random832
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.