* Make a defcustom dependent on another variable
@ 2014-03-19 23:05 Joost Kremers
2014-03-20 8:17 ` Thien-Thi Nguyen
0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2014-03-19 23:05 UTC (permalink / raw
To: help-gnu-emacs
Hi all,
Defining a custom variable that can have one of (e.g.,) two values is
easy:
(defcustom some-option 'value1
"Doc string"
:group 'some-group
:type '(choice (const value1)
(const value2)))
However, what if the possible values `some-option' can take are defined
in another variable? Is it ok to do something like the following:
(defcustom some-option 'value1
"Doc string"
:group 'some-group
:type '(choice ,@(mapcar #'(lambda (x) `(const ,x))
some-option-list)))
where `some-option-list' is a variable holding a list of possible values
for `some-option'.
The code seems to work (the resulting customisation option works), but I
was wondering a) if there are any hidden problems I'm not aware of; and
b) if there is a more canonical way of doing this.
TIA
Joost
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Make a defcustom dependent on another variable
2014-03-19 23:05 Make a defcustom dependent on another variable Joost Kremers
@ 2014-03-20 8:17 ` Thien-Thi Nguyen
2014-03-20 12:19 ` Stefan
0 siblings, 1 reply; 3+ messages in thread
From: Thien-Thi Nguyen @ 2014-03-20 8:17 UTC (permalink / raw
To: Joost Kremers; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]
() Joost Kremers <joost.m.kremers@gmail.com>
() 19 Mar 2014 23:05:21 GMT
The code seems to work (the resulting customisation option works),
but I was wondering a) if there are any hidden problems I'm not
aware of; and b) if there is a more canonical way of doing this.
If you have the GNU Emacs source, you can grep for "choice.*mapcar"
and see how others do it. I see 9 hits. I choose one that is from a
fundamental library -- minibuffer.el var ‘completion--styles-type’ --
and find it in the lisp/ChangeLog.16 entry dated 2011-10-03 authored
by Stefan Monnier. I feel comfortable using this technique now.
If you do not have the GNU Emacs source, then you can question your
sanity / situation / style / subjugation, until you do... :-D
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Make a defcustom dependent on another variable
2014-03-20 8:17 ` Thien-Thi Nguyen
@ 2014-03-20 12:19 ` Stefan
0 siblings, 0 replies; 3+ messages in thread
From: Stefan @ 2014-03-20 12:19 UTC (permalink / raw
To: help-gnu-emacs
> fundamental library -- minibuffer.el var ‘completion--styles-type’ --
> and find it in the lisp/ChangeLog.16 entry dated 2011-10-03 authored
> by Stefan Monnier. I feel comfortable using this technique now.
FWIW, I'm not happy with this technique (I'd like the list of choices
to be recomputed dynamically), but it's the best I could come up with.
If someone more knowledgeable with Custom can show me how to make it
dynamic (while still making it a popup menu rather than a text field with
completion), I'd appreciate it.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-20 12:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-19 23:05 Make a defcustom dependent on another variable Joost Kremers
2014-03-20 8:17 ` Thien-Thi Nguyen
2014-03-20 12:19 ` Stefan
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.