[Top][All Lists]

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

RE: custom type `color' is not enforced

From: Drew Adams
Subject: RE: custom type `color' is not enforced
Date: Fri, 21 Dec 2007 14:03:54 -0800

I wrote:

> Trying your fix made me realize that my type test was
> insufficient. I don't understand widgets very well.

That last part is certainly true!

> Instead of testing (widget-apply type :match val), it looks like I need to
> test (and var-widget (not (widget-apply var-widget :validate))), where
> var-widget is (get var 'custom-variable).

Not quite. The code I sent didn't work. This seems to work, however:

(defun help-var-is-of-type-p (variable types)
  "Return non-nil if VARIABLE is of one of the custom types in TYPES.
Non-nil means either VARIABLE's custom type is a member of list TYPES
or VARIABLE is bound and its value satisfies a type in list TYPES."
  (or (memq (get variable 'custom-type) types)
      (and (boundp variable)
           (let ((val (symbol-value variable))
                 (var-widget (widget-convert (get variable 'custom-type))))
             (catch 'help-type-matches
               (dolist (type types)
                 (setq type (widget-convert type))
                 (plist-put (cdr type) :value val)
                 (when (and var-widget
                            (not (widget-apply type :validate)))
                   (throw 'help-type-matches t)))

[I also had to modify Lennart's `color-digits-p' to use a regexp such as
what I sent earlier: "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$".]

There may be a simpler way to do it, but this seems to work OK.

> So `C-u C-h C-o' (my `describe-option-of-type') now shows, as completion
> candidates, all options whose values are legitimate colors (and
> no others).

That was not true when I wrote it, but it seems to be true now, with the
above code.

With C-u, `describe-option-of-type' `color' includes non-`color' options
whose values are legitimate for type `color'. That means that
`help-var-is-of-type-p' must return non-nil when passed an option whose
defcustom type is `string' but whose current value is "white" (and when
passed '(color) as the TYPES arg). And the same thing, generalized for all
types. And `help-var-is-of-type-p' also returns non-nil when testing an
option of type `color' or `regexp' for type `string'.

reply via email to

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