branch: externals/compat commit 5c5bea94eff30696f71b7290f35cd070e7c64887 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
compat-29: Add support for defcustom type key --- NEWS.org | 1 + compat-29.el | 24 ++++++++++++++++++++++++ compat-tests.el | 4 ++++ compat.texi | 5 +++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/NEWS.org b/NEWS.org index 8bd2dd51b3..09697ece8f 100644 --- a/NEWS.org +++ b/NEWS.org @@ -9,6 +9,7 @@ - compat-29: Add ~with-restriction~ and ~without-restriction~. - compat-29: Add ~cl-constantly~. - compat-29: Drop ~with-narrowing~ which was renamed to ~with-restriction~. +- compat-28: Add support for ~defcustom~ type ~key~. * Release of "Compat" Version 29.1.3.4 diff --git a/compat-29.el b/compat-29.el index 81d11c15af..5cfe15450c 100644 --- a/compat-29.el +++ b/compat-29.el @@ -1521,5 +1521,29 @@ The same keyword arguments are supported as in :directory t ,@body)) +;;;; Defined in wid-edit.el + +(compat-guard (not (fboundp 'widget-key-validate)) ;; <compat-tests:widget-key> + :feature wid-edit + (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 'widget-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-valid-p (_widget value) + (key-valid-p value)) + (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))) + (provide 'compat-29) ;;; compat-29.el ends here diff --git a/compat-tests.el b/compat-tests.el index 2999a4fb06..d67365d35c 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -2967,5 +2967,9 @@ (should-error (widget-create 'compat--not-existing)) (should-equal (take 3 (widget-create 'natnum)) '(natnum :value "0")))) +(ert-deftest widget-key () + (with-temp-buffer + (should-equal (take 3 (widget-create 'key)) '(key :value "")))) + (provide 'compat-tests) ;;; compat-tests.el ends here diff --git a/compat.texi b/compat.texi index 16988a7979..f498d0156c 100644 --- a/compat.texi +++ b/compat.texi @@ -2271,6 +2271,9 @@ older than 29.1. Note that due to upstream changes, it might happen that there will be the need for changes, so use these functions with care. +The @code{defcustom} type @code{key} introduced in Emacs 28.1 is +made available by Compat. + @c based on lisp/textmodes/paragraphs.el @defun count-sentences start end Count sentences in current buffer from @var{start} to @var{end}. @@ -3246,8 +3249,6 @@ implemented in 29.1: @itemize @item -Support for the @code{key} defcustom type. -@item The function @code{imagep}. @item The function @code{image-at-point-p}.