From: Drew Adams <drew.adams@oracle.com>
To: Ryan <rct@thompsonclan.org>, help-gnu-emacs@gnu.org
Subject: RE: Properly using :value-to-external and :value-to-internal?
Date: Sat, 24 Aug 2013 08:20:28 -0700 (PDT) [thread overview]
Message-ID: <4d6a1ff7-d8a8-47d4-879b-ca56e26e34ba@default> (raw)
In-Reply-To: <521850C7.3070300@thompsonclan.org>
> 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:
>
> |(defcustom myvar"" "String or regexp"
> :type'(choice(string:tag"String")
> (regexp:tag"Regexp")))|
>
>
> 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.
prev parent reply other threads:[~2013-08-24 15:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-24 6:20 Properly using :value-to-external and :value-to-internal? Ryan
2013-08-24 15:20 ` Drew Adams [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4d6a1ff7-d8a8-47d4-879b-ca56e26e34ba@default \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=rct@thompsonclan.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.