From: Stefan Kangas <stefan@marxist.se>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 52523@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#52523: 29.0.50; defcustom :type 'key-sequence not following key-valid-p format
Date: Mon, 27 Dec 2021 19:08:42 -0800 [thread overview]
Message-ID: <CADwFkmnPEaJNquta_nQT+AoftnnMK3S4C0dVZnJw10LxQRMFfQ@mail.gmail.com> (raw)
In-Reply-To: <87pmpoerrm.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 22 Dec 2021 13:41:17 +0100")
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
tags 52523 + patch
thanks
Lars Ingebrigtsen <larsi@gnus.org> writes:
> The problem is that we don't use the name "kbd" anywhere in the new
> keymap functions, so it'd be confusing to use them in defcustom.
Having looked over the documentation to these functions, I actually
think "key" is the least confusing name here.
How does the attached patch look?
[-- Attachment #2: 0001-New-type-key-for-defcustom.patch --]
[-- Type: text/x-diff, Size: 3436 bytes --]
From c433b9c0212c1b6d25dd06ba1b6359d7dedcdedd Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Tue, 28 Dec 2021 02:59:51 +0100
Subject: [PATCH] New :type key for defcustom
As compared to the old type key-sequence that deals with raw key
sequences, this :type conforms to the format used by the new keymap-*
functions.
* lisp/wid-edit.el (key): New widget type. (Bug#52523)
(widget-key-prompt-value-history): New variable.
(widget-key-validate): New function.
(key-sequence): Doc fix.
* doc/lispref/customize.texi (Simple Types): Document above new type.
---
doc/lispref/customize.texi | 6 +++++-
etc/NEWS | 5 +++++
lisp/wid-edit.el | 23 ++++++++++++++++++++++-
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi
index 00287a7212..da5e761198 100644
--- a/doc/lispref/customize.texi
+++ b/doc/lispref/customize.texi
@@ -654,10 +654,14 @@ Simple Types
specify the text to describe each value in a way that fits the specific
meaning of the alternative.
+@item key
+The value is a valid key according to @kbd{key-valid-p}, and suitable
+for use with, for example @code{keymap-set}.
+
@item key-sequence
The value is a key sequence. The customization buffer shows the key
sequence using the same syntax as the @kbd{kbd} function. @xref{Key
-Sequences}.
+Sequences}. This is a legacy type; use @code{key} instead.
@item coding-system
The value must be a coding-system name, and you can do completion with
diff --git a/etc/NEWS b/etc/NEWS
index 01e1a8e940..ad9e61480b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -974,6 +974,11 @@ syntax.
This is like 'kbd', but only returns vectors instead of a mix of
vectors and strings.
++++
+*** New ':type' for 'defcustom' for keys.
+The new 'key' type can be used for options that should be a valid key
+according to 'key-valid-p'. The type 'key-sequence' is now obsolete.
+
+++
** New substitution in docstrings and 'substitute-command-keys'.
Use \\`KEYSEQ' to insert a literal key sequence "KEYSEQ" (for example
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index a53add7d08..754aa83d0a 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3459,7 +3459,7 @@ widget-key-sequence-map
map))
(define-widget 'key-sequence 'restricted-sexp
- "A key sequence."
+ "A key sequence. Now obsolete; use the `key' type instead."
:prompt-value 'widget-field-prompt-value
:prompt-internal 'widget-symbol-prompt-internal
; :prompt-match 'fboundp ;; What was this good for? KFS
@@ -3524,6 +3524,27 @@ widget-key-sequence-value-to-external
(read-kbd-macro value))
value))
+\f
+(defvar widget-key-prompt-value-history nil
+ "History of input to `widget-key-prompt-value'.")
+
+(define-widget 'key 'editable-field
+ "A key sequence."
+ :prompt-value 'widget-field-prompt-value
+ :match 'key-valid-p
+ :format "%{%t%}: %v"
+ :validate 'widget-key-validate
+ :keymap widget-key-sequence-map
+ :help-echo "C-q: insert KEY, EVENT, or CODE; RET: enter value"
+ :tag "Key")
+
+(defun widget-key-validate (widget)
+ (unless (and (stringp (widget-value widget))
+ (key-valid-p (widget-value widget)))
+ (widget-put widget :error (format "Invalid key: %S"
+ (widget-value widget)))
+ widget))
+
\f
(define-widget 'sexp 'editable-field
"An arbitrary Lisp expression."
--
2.30.2
next prev parent reply other threads:[~2021-12-28 3:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 20:35 bug#52523: 29.0.50; defcustom :type 'key-sequence not following key-valid-p format Stefan Kangas
2021-12-16 17:11 ` Juri Linkov
2021-12-19 12:15 ` Lars Ingebrigtsen
2021-12-19 13:43 ` Stefan Kangas
2021-12-19 13:54 ` Lars Ingebrigtsen
2021-12-19 17:08 ` Juri Linkov
2021-12-20 6:59 ` Stefan Kangas
[not found] ` <86tuf3ptcr.fsf@mail.linkov.net>
2021-12-20 10:27 ` Lars Ingebrigtsen
2021-12-21 11:19 ` Stefan Kangas
2021-12-21 18:53 ` Juri Linkov
2021-12-22 12:41 ` Lars Ingebrigtsen
2021-12-26 16:39 ` Stefan Kangas
2021-12-27 12:05 ` Lars Ingebrigtsen
2021-12-27 15:41 ` Stefan Kangas
2021-12-28 14:32 ` Lars Ingebrigtsen
2021-12-28 3:08 ` Stefan Kangas [this message]
2021-12-28 12:51 ` Eli Zaretskii
2021-12-28 14:33 ` Lars Ingebrigtsen
2021-12-28 14:34 ` Lars Ingebrigtsen
2022-01-02 16:00 ` Stefan Kangas
2021-12-22 4:16 ` 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=CADwFkmnPEaJNquta_nQT+AoftnnMK3S4C0dVZnJw10LxQRMFfQ@mail.gmail.com \
--to=stefan@marxist.se \
--cc=52523@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=larsi@gnus.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.