all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Programmatically access all the possible values of a defcustom
@ 2014-01-29 20:28 Sebastien Vauban
  2014-01-29 22:19 ` Nicolas Richard
       [not found] ` <mailman.13125.1391033975.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastien Vauban @ 2014-01-29 20:28 UTC (permalink / raw
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

Is there a possibility to programmatically access all the values that
a defcustom can take?

The example I have in mind is `org-babel-load-languages' which can
become any list with values such as:

--8<---------------cut here---------------start------------->8---
  (choice
   (const :tag "Awk" awk)
   (const :tag "C" C)
   (const :tag "R" R)
   (const :tag "Asymptote" asymptote)
   (const :tag "Calc" calc)
   (const :tag "Clojure" clojure)
   (const :tag "CSS" css)
   (const :tag "Ditaa" ditaa)
   ...
--8<---------------cut here---------------end--------------->8---

I'd like to list them, not the default value, but the full list of
languages. Any idea how to process?

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Programmatically access all the possible values of a defcustom
  2014-01-29 20:28 Programmatically access all the possible values of a defcustom Sebastien Vauban
@ 2014-01-29 22:19 ` Nicolas Richard
       [not found] ` <mailman.13125.1391033975.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Richard @ 2014-01-29 22:19 UTC (permalink / raw
  To: Sebastien Vauban; +Cc: public-help-gnu-emacs-mXXj517/zsQ



Hi Sébastien,

"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:
> Is there a possibility to programmatically access all the values that
> a defcustom can take?

I guess it's in the plist associated to the symbol. Let's check:
(symbol-plist 'org-babel-load-languages)

Ah ha!

(get 'org-babel-load-languages 'custom-type)
=> (alist :tag "Babel Languages" :key-type (choice (const :tag "Awk" awk) (const :tag "C" C) (const :tag "R" R) (const :tag "Asymptote" asymptote) (const :tag "Calc" calc) (const :tag "Clojure" clojure) (const :tag "CSS" css) (const :tag "Ditaa" ditaa) (const :tag "Dot" dot) (const :tag "Emacs Lisp" emacs-lisp) (const :tag "Fortran" fortran) ...) :value-type (boolean :tag "Activate" :value t))

HTH,

-- 
Nico.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Programmatically access all the possible values of a defcustom
       [not found] ` <mailman.13125.1391033975.10748.help-gnu-emacs@gnu.org>
@ 2014-01-30 10:17   ` Sebastien Vauban
  2014-01-30 11:41     ` Nicolas Richard
       [not found]     ` <mailman.13179.1391082135.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastien Vauban @ 2014-01-30 10:17 UTC (permalink / raw
  To: help-gnu-emacs-mXXj517/zsQ

Hi Nicolas,

Nicolas Richard wrote:
> "Sebastien Vauban" writes:
>> Is there a possibility to programmatically access all the values that
>> a defcustom can take?
>
> I guess it's in the plist associated to the symbol. Let's check:
> (symbol-plist 'org-babel-load-languages)
>
> Ah ha!
>
> (get 'org-babel-load-languages 'custom-type)
> => (alist :tag "Babel Languages" :key-type (choice (const :tag "Awk" awk)
> (const :tag "C" C) (const :tag "R" R) (const :tag "Asymptote" asymptote)
> (const :tag "Calc" calc) (const :tag "Clojure" clojure) (const :tag "CSS" css)
> (const :tag "Ditaa" ditaa) (const :tag "Dot" dot) (const :tag "Emacs Lisp"
> emacs-lisp) (const :tag "Fortran" fortran) ...) :value-type (boolean :tag
> "Activate" :value t))

Thanks for putting me on track.

Now, I'll have to play with the list to obtain what I really want:
a string like...

   Awk, C, R, Asymptote, Calc, Clojure, CSS, Ditaa, Dot, Emacs Lisp,
   Fortran

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Programmatically access all the possible values of a defcustom
  2014-01-30 10:17   ` Sebastien Vauban
@ 2014-01-30 11:41     ` Nicolas Richard
       [not found]     ` <mailman.13179.1391082135.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Richard @ 2014-01-30 11:41 UTC (permalink / raw
  To: Sebastien Vauban; +Cc: public-help-gnu-emacs-mXXj517/zsQ



"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:
> Now, I'll have to play with the list to obtain what I really want:
> a string like...
>
>    Awk, C, R, Asymptote, Calc, Clojure, CSS, Ditaa, Dot, Emacs Lisp,
>    Fortran

The objects are "widgets", so e.g.

(widget-get (get 'org-babel-load-languages 'custom-type) :key-type)

will get you to the (choice ...) data which is documented at (info
"(widget) composite")

I'm unsure what's the best way to get rid of the [keyword value] pairs
and only map over each inner (const ...) widget ; there ought to be
something defined within the widget library but i couldn't find it. Or
maybe my whole approach is wrong, I don't know.

Anyway, this works for me :

(mapconcat (lambda (widget)
             (widget-get widget :tag))
           (cl-remove-if-not (lambda (it)
                               (and (consp it)
                                    (eq (car it) 'const)))
                             (cdr
                              (widget-get
                               (get
                                'org-babel-load-languages 'custom-type)
                               :key-type)))
           ", ")


-- 
Nico.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Programmatically access all the possible values of a defcustom
       [not found]     ` <mailman.13179.1391082135.10748.help-gnu-emacs@gnu.org>
@ 2014-01-30 12:40       ` Sebastien Vauban
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastien Vauban @ 2014-01-30 12:40 UTC (permalink / raw
  To: help-gnu-emacs-mXXj517/zsQ

Nicolas Richard wrote:
> "Sebastien Vauban" writes:
>> Now, I'll have to play with the list to obtain what I really want:
>> a string like...
>>
>>    Awk, C, R, Asymptote, Calc, Clojure, CSS, Ditaa, Dot, Emacs Lisp,
>>    Fortran
>
> The objects are "widgets", so e.g.
>
> (widget-get (get 'org-babel-load-languages 'custom-type) :key-type)
>
> will get you to the (choice ...) data which is documented at (info
> "(widget) composite")
>
> I'm unsure what's the best way to get rid of the [keyword value] pairs
> and only map over each inner (const ...) widget ; there ought to be
> something defined within the widget library but i couldn't find it. Or
> maybe my whole approach is wrong, I don't know.
>
> Anyway, this works for me :
>
> (mapconcat (lambda (widget)
>              (widget-get widget :tag))
>            (cl-remove-if-not (lambda (it)
>                                (and (consp it)
>                                     (eq (car it) 'const)))
>                              (cdr
>                               (widget-get
>                                (get
>                                 'org-babel-load-languages 'custom-type)
>                                :key-type)))
>            ", ")

You save me *a lot* of time: I'd have to "play" a lot before arriving to
such a code. Thanks!  (and it's perfectly what I was after)

Best regards,
  Seb

-- 
Sebastien Vauban


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-30 12:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-29 20:28 Programmatically access all the possible values of a defcustom Sebastien Vauban
2014-01-29 22:19 ` Nicolas Richard
     [not found] ` <mailman.13125.1391033975.10748.help-gnu-emacs@gnu.org>
2014-01-30 10:17   ` Sebastien Vauban
2014-01-30 11:41     ` Nicolas Richard
     [not found]     ` <mailman.13179.1391082135.10748.help-gnu-emacs@gnu.org>
2014-01-30 12:40       ` Sebastien Vauban

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.