I want to have a custom variable in my Emacs package, and the only valid values for that variable are positive integers. Is there a way to make it so that M-x customize will only accept positive integers for this variable and refuse others?
I figured out how to do this with the custom variable's :validate
property:
(defun widget-positive-integer-validate (widget)
(let ((v (widget-value widget)))
(if (natnump v)
;; Valid
nil
;; Invalid
(widget-put widget :error "This field should contain a positive integer")
widget))))
(defcustom positive-integer-var 5000
"This variable must be a positive integer."
:type '(integer :value 5000
:validate widget-positive-integer-validate))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments