From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Properly using :value-to-external and :value-to-internal? Date: Sat, 24 Aug 2013 08:20:28 -0700 (PDT) Message-ID: <4d6a1ff7-d8a8-47d4-879b-ca56e26e34ba@default> References: <521850C7.3070300@thompsonclan.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1377357660 16367 80.91.229.3 (24 Aug 2013 15:21:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 Aug 2013 15:21:00 +0000 (UTC) To: Ryan , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 24 17:21:01 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VDFe8-0008NV-3P for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Aug 2013 17:21:00 +0200 Original-Received: from localhost ([::1]:42005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDFe7-00023z-Li for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Aug 2013 11:20:59 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDFdo-00023J-CL for help-gnu-emacs@gnu.org; Sat, 24 Aug 2013 11:20:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDFde-00036L-MO for help-gnu-emacs@gnu.org; Sat, 24 Aug 2013 11:20:39 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:31427) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDFde-00036A-FN for help-gnu-emacs@gnu.org; Sat, 24 Aug 2013 11:20:30 -0400 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r7OFKSO4029566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 24 Aug 2013 15:20:29 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7OFKRMu001112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 24 Aug 2013 15:20:28 GMT Original-Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7OFKR7W016830; Sat, 24 Aug 2013 15:20:27 GMT In-Reply-To: <521850C7.3070300@thompsonclan.org> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6680.5000 (x86)] X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:93078 Archived-At: > I could use some help writing a special widget for use in the > "defcustom" declaration that I'm writing. I'm writing a variable that's > a list of match conditions. Each match condition is a choice between a > literal string that only matches exactly, a prefix string that matches > anything that starts with the prefix, or a regexp. The problem is that > all three of these things is internally just a string, so there's no way > to tell which one the variable has been set to. Here's a minimal example > demonstrating the problem: >=20 > |(defcustom myvar"" "String or regexp" > :type'(choice(string:tag"String") > (regexp:tag"Regexp")))| >=20 >=20 > Regardless of whether the user chooses the String or Regexp options, the > variable gets set to a string and there's no way to tell whether or not > it's supposed to be a regexp. What I'd like to do is have the variable > be set to one if either "(TYPE . VALUE)", where TYPE is one of 'string > or 'regexp and VALUE is whatever the user entered. I figured that I > could accomplish this by creating a few custom widgets with special > ":value-to-external" and ":value-to-internal" properties that handle the > conversion between bare strings and the cons cells that I want. However, > no matter what I try, i seem to run into errors, probably because the > ":match" and ":validate" properties are looking at the cons cells > instead of the bare strings and rejecting them. So can someone give me > an example of a "define-widget" call that looks and works just like a > "string" widget but actually gives "(string . VALUE)" as its value? Good question. I don't have any real help for you, unfortunately. Perhaps someone else will. It's clear that once the variable has a value that is a string you cannot tell whether the user picked `Regexp' or `String'. A regexp string is a string (and vice versa, though some strings are invalid as regexps). It is really only during customization that a difference is manifested. (This is a bit like the character/integer thing: some integers are not chars, but many are.) I do use `define-widget' in several places in my code, including in a redefinition of the `color' widget, which, like the `string' widget, is based on widget `editable-field'. I think the answer is to do what you suggested (e.g. use a cons) and to define :match, :validate, :complete-function, etc. appropriately.