From f1071bf08e246d0820edfb66163acb65e90d9482 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 25 Sep 2021 01:15:49 +0200 Subject: [PATCH] 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 bc35982c172..b93b8bc015a 100644 --- a/doc/lispref/customize.texi +++ b/doc/lispref/customize.texi @@ -594,6 +594,9 @@ want to take the time to work out a more specific type to use. @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 31b09dad242..84a6b3f10a1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3737,6 +3737,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 ab358da7e3f..72353b91909 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -3644,6 +3644,13 @@ match-alternatives: %S" :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.39.2