[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom type `color' is not enforced

From: Lennart Borgman (gmail)
Subject: Re: custom type `color' is not enforced
Date: Fri, 21 Dec 2007 10:36:50 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071031 Thunderbird/ Mnenhy/

Richard Stallman wrote:
    >     `C-h M-o color RET TAB' correctly gives all options defined with :type
    >     `color' (rigid equality test). However, since Emacs currently does not
    >     distinguish type `color' from type `string' (= this bug),
    > That statement surprises me.  The two types have different names, and
    > don't behave the same, so in what sense does Emacs not distinguish
    > them?

    Please reread what I said:

You said Emacs does not distinguish type `color' from type `string'.
That's mistaken; it does distinguish them.  They behave differently.

I agree it would be good to make `color' check for a valid color.
I hope someone will do that.

Something like this?

(defun color-digits-p (color)
    (string-match (rx bos
                      (or (repeat 3 3 hex-digit)
                          (repeat 6 6 hex-digit))

(defun widget-color-validate (widget)
  (let ((val (widget-value widget)))
    (unless (or
             ;;(color-defined-p val)
             (member val x-colors)
             (and (stringp val)
                  (color-digits-p val)))
      (widget-put widget :error (format "Invalid color: %S"
                                        (widget-value widget)))

(define-widget 'color 'editable-field
  "Choose a color name (with sample)."
  :format "%{%t%}: %v (%{sample%})\n"
  :size 10
  :tag "Color"
  :validate 'widget-color-validate
  :value "black"
  :complete 'widget-color-complete
  :sample-face-get 'widget-color-sample-face-get
  :notify 'widget-color-notify
  :action 'widget-color-action)

(defcustom test-color "black"
  "color test"
  :type 'color)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]