How can I define an Elisp widget type that only accepts positive numbers?

Ryan C. Thompson

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?

Ryan C. Thompson

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I define a data type that only accepts numbers?

From Dev

How can I create a PasswordBox with an input scope that accepts only numbers?

From Java

How to make type="number" to positive numbers only

From Dev

How can ensure that a function only accepts a positive integer?

From Dev

How can ensure that a function only accepts a positive integer?

From Dev

How can I define a new data type that is a list of numbers?

From Dev

Can I define a method that only accepts primitive types?

From Dev

How can I define a widget using javascript

From Java

How do I make a textbox that only accepts numbers?

From Dev

How to generate only positive numbers (see what I mean below)

From Dev

How to know if widget accepts only numeric characters

From Dev

How can I make a TextBox accepts only numeric values?

From Java

SwiftUI - How to create TextField that only accepts numbers

From Dev

How can we define complex type for a stored procedure that accepts dynamic query as input [edmx]

From Dev

How to only allow positive numbers in an EditText

From Dev

How to add only positive numbers in shell script?

From Dev

How can I skip over symbols in elisp?

From Dev

Gradle: How do I define build type for specific flavors only?

From Dev

How do I filter and sum only negative or positive numbers in a field using an expression in SQL Reporting Services 2014

From Dev

HTML input for Positive Whole Numbers Only (Type=number)

From Dev

How Can I Define Only the Gradient for a Tensorflow Subgraph?

From Dev

how can i type only characters in jTextField?

From Dev

how can i type only characters in jTextField?

From Dev

How can I write a parser using Parsec that only accepts unique elements?

From Dev

How can I define a return type of void for a function in a Typescript interface?

From Dev

How can I define Content-type in Swift using NSURLSession

From Dev

How can I define NFData instance for recursive singleton type?

From Dev

How can I define the return type of a lodash reduce function with Typescript?

From Dev

How can I define type variant in c#?

Related Related

  1. 1

    How do I define a data type that only accepts numbers?

  2. 2

    How can I create a PasswordBox with an input scope that accepts only numbers?

  3. 3

    How to make type="number" to positive numbers only

  4. 4

    How can ensure that a function only accepts a positive integer?

  5. 5

    How can ensure that a function only accepts a positive integer?

  6. 6

    How can I define a new data type that is a list of numbers?

  7. 7

    Can I define a method that only accepts primitive types?

  8. 8

    How can I define a widget using javascript

  9. 9

    How do I make a textbox that only accepts numbers?

  10. 10

    How to generate only positive numbers (see what I mean below)

  11. 11

    How to know if widget accepts only numeric characters

  12. 12

    How can I make a TextBox accepts only numeric values?

  13. 13

    SwiftUI - How to create TextField that only accepts numbers

  14. 14

    How can we define complex type for a stored procedure that accepts dynamic query as input [edmx]

  15. 15

    How to only allow positive numbers in an EditText

  16. 16

    How to add only positive numbers in shell script?

  17. 17

    How can I skip over symbols in elisp?

  18. 18

    Gradle: How do I define build type for specific flavors only?

  19. 19

    How do I filter and sum only negative or positive numbers in a field using an expression in SQL Reporting Services 2014

  20. 20

    HTML input for Positive Whole Numbers Only (Type=number)

  21. 21

    How Can I Define Only the Gradient for a Tensorflow Subgraph?

  22. 22

    how can i type only characters in jTextField?

  23. 23

    how can i type only characters in jTextField?

  24. 24

    How can I write a parser using Parsec that only accepts unique elements?

  25. 25

    How can I define a return type of void for a function in a Typescript interface?

  26. 26

    How can I define Content-type in Swift using NSURLSession

  27. 27

    How can I define NFData instance for recursive singleton type?

  28. 28

    How can I define the return type of a lodash reduce function with Typescript?

  29. 29

    How can I define type variant in c#?

HotTag

Archive