Subject: Re: bug#15809: 24.3.50; wrong defcustom type for `suggest-key-bindings'

From: Stefan Kangas <[email-masked]>
Date: Fri, 24 Sep 2021 16:34:38 -0700

tags 15809 + patch
thanks

Lars Ingebrigtsen <[email-masked]> writes:

> Stefan Kangas <[email-masked]> writes:
>
>>> Or to be more general, perhaps there should be a custom interval type?  Like
>>>
>>> (integer :minimum 1)
>>>
>>> ?
>>>
>>> Or just `natnum'?
>>
>> natnum sounds like it could be generally useful, yes.  We have plenty of
>> customizable things that should never be negative.
>
> Yeah, that's the most common numerical restriction (by far), and the few
> variables that are numbers with other ranges can be done with a
> defcustom predicate.

How about the attached?
From 7313d60a163b66af039efc69046e4df4dff21457 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sat, 25 Sep 2021 01:15:49 +0200
Subject: [PATCH 1/2] New :type natnum for defcustom

* lisp/wid-edit.el (natnum): New widget type.  (Bug#15809)
* doc/lispref/customize.texi (Simple Types): Document it.
---
 doc/lispref/customize.texi | 3 +++
 etc/NEWS                   | 5 +++++
 lisp/wid-edit.el           | 7 +++++++
 3 files changed, 15 insertions(+)

diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi
index bc35982c17..b93b8bc015 100644
--- a/doc/lispref/customize.texi
+++ b/doc/lispref/customize.texi
@@ -594,6 +594,9 @@ Simple Types
 @item integer
 The value must be an integer.
 
+@item natnum
+The value must be a nonnegative integer.
+
 @item number
 The value must be a number (floating point or integer).
 
diff --git a/etc/NEWS b/etc/NEWS
index c266dddafa..b2e7331517 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3724,6 +3724,11 @@ instead of only becoming available after doing (for instance)
 ---
 ** ':safe' settings in 'defcustom' are now propagated to the loaddefs files.
 
++++
+** New ':type' for 'defcustom' for nonnegative integers.
+The new 'natnum' type can be used for options that should be
+nonnegative integers.
+
 +++
 ** ERT can now output more verbose test failure reports.
 If the 'EMACS_TEST_VERBOSE' environment variable is set, failure
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index ab358da7e3..72353b9190 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3644,6 +3644,13 @@ 'integer
   :type-error "This field should contain an integer"
   :match-alternatives '(integerp))
 
+(define-widget 'natnum 'restricted-sexp
+  "A nonnegative integer."
+  :tag "Integer (positive)"
+  :value 0
+  :type-error "This field should contain a nonnegative integer"
+  :match-alternatives '(natnump))
+
 (define-widget 'number 'restricted-sexp
   "A number (floating point or integer)."
   :tag "Number"
-- 
2.30.2

From 95127f0d7441999c78e4c4e9ab8217757148e5c9 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sat, 25 Sep 2021 01:25:47 +0200
Subject: [PATCH 2/2] Set :type of suggest-key-bindings to natnum

* lisp/simple.el (suggest-key-bindings): Set :type to
natnum.  (Bug#15809)
---
 lisp/simple.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 298e3ea5ee..dd480396f6 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2144,7 +2144,7 @@ suggest-key-bindings
 \\[execute-extended-command] for all commands that have them."
   :group 'keyboard
   :type '(choice (const :tag "off" nil)
-                 (integer :tag "time" 2)
+                 (natnum :tag "time" 2)
                  (other :tag "on")))
 
 (defcustom extended-command-suggest-shorter t
-- 
2.30.2