From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: custom type `color' is not enforced Date: Fri, 21 Dec 2007 14:03:54 -0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1198274792 6160 80.91.229.12 (21 Dec 2007 22:06:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Dec 2007 22:06:32 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Lennart Borgman \(gmail\)" , Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 21 23:06:43 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J5q0F-0003hJ-T5 for ged-emacs-devel@m.gmane.org; Fri, 21 Dec 2007 23:06:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J5pzw-0001Pc-1f for ged-emacs-devel@m.gmane.org; Fri, 21 Dec 2007 17:05:40 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J5pzs-0001NF-0m for emacs-devel@gnu.org; Fri, 21 Dec 2007 17:05:36 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J5pzq-0001Ld-1c for emacs-devel@gnu.org; Fri, 21 Dec 2007 17:05:35 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J5pzp-0001LO-Sp for emacs-devel@gnu.org; Fri, 21 Dec 2007 17:05:33 -0500 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1J5pzm-0005cq-Ay; Fri, 21 Dec 2007 17:05:30 -0500 Original-Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id lBLM5FIE009586; Fri, 21 Dec 2007 16:05:17 -0600 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id lBLAFTMR008482; Fri, 21 Dec 2007 15:05:15 -0700 Original-Received: from dhcp-amer-csvpn-gw1-141-144-66-79.vpn.oracle.com by acsmt351.oracle.com with ESMTP id 3459800391198274624; Fri, 21 Dec 2007 14:03:44 -0800 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:85360 Archived-At: 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))) nil))))) [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'.