emacs-diffs
[Top][All Lists]
Advanced

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

master 984391a9dc: New :type key for defcustom


From: Stefan Kangas
Subject: master 984391a9dc: New :type key for defcustom
Date: Sun, 2 Jan 2022 10:47:07 -0500 (EST)

branch: master
commit 984391a9dc384627533758f6fced219b5381c91f
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    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 9508ca8620..54059d7b6e 100644
--- a/doc/lispref/customize.texi
+++ b/doc/lispref/customize.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 29e329edc9..9c892b285d 100644
--- 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
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 831b2ccfca..f00a524c0c 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -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
@@ -3526,6 +3526,27 @@ It reads a directory name from an editable text field."
     value))
 
 
+(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))
+
+
 (define-widget 'sexp 'editable-field
   "An arbitrary Lisp expression."
   :tag "Lisp expression"



reply via email to

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