我想在我的 Emacs 包中有一个自定义变量,并且该变量的唯一有效值是正整数。有没有办法让 Mx customize 只接受这个变量的正整数并拒绝其他变量?
2 回答
            4        
        
		
我想出了如何使用自定义变量的:validate属性来做到这一点:
(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))
于 2013-09-24T00:30:43.823   回答
    
    
            1        
        
		
您可能还想使用受限性别作为 :type。
:type `(restricted-sexp
        :match-alternatives
        (,(lambda (v) (and (natnump v) (/= v 0))))))
羊皮
于 2013-09-24T20:31:14.693   回答