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
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
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
(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."