]> git.eshelyaron.com Git - emacs.git/commitdiff
New :type key for defcustom
authorStefan Kangas <stefan@marxist.se>
Sun, 2 Jan 2022 15:46:02 +0000 (16:46 +0100)
committerStefan Kangas <stefan@marxist.se>
Sun, 2 Jan 2022 15:46:02 +0000 (16:46 +0100)
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
etc/NEWS
lisp/wid-edit.el

index 9508ca8620022668b568acf2010a00bc976996ad..54059d7b6ed7ff18170957074d70ba05715f66b9 100644 (file)
@@ -654,10 +654,14 @@ you can specify that the value must be @code{nil} or @code{t}, but also
 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
index 29e329edc900464fadd1fe2b8dfd6f6580b69ad0..9c892b285d1a7a8e5bc4fde55f4cf9fc856bc816 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -985,6 +985,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
index 831b2ccfca85e13dd58c24c89f28f974e0abf38c..f00a524c0c4c1b4c66c1a6b320858b082a5c3df0 100644 (file)
@@ -3460,7 +3460,7 @@ It reads a directory name from an editable text field."
     map))
 
 (define-widget 'key-sequence 'restricted-sexp
-  "A key sequence."
+  "A key sequence.  This is 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
@@ -3525,6 +3525,27 @@ It reads a directory name from an editable text field."
        (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."