unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* defcustom - help
@ 2011-08-03 14:57 Jambunathan K
  2011-08-04  3:39 ` Katsumi Yamaoka
  0 siblings, 1 reply; 3+ messages in thread
From: Jambunathan K @ 2011-08-03 14:57 UTC (permalink / raw)
  To: emacs-devel


There are two defcustoms - one for configuring a list of items and one
for choosing the preferred among those. Read ahead ...

1. Copy these two to scratch buffer and install them using C-x C-e.

(defcustom kjn--list-items
  '("a" "b" "c")
  "A list of items."
  :group 'kjn
  :type '(repeat (string :tag "Output format")))

(defcustom kjn--preferred-list-item "a"
  "Preferred item in the list."
  :group 'kjn
  :type `(choice (const :tag "None" nil)
		 ,@(mapcar (lambda (c)
		 	     `(const :tag ,c ,c))
		 	   kjn--list-items)))

2. M-x customize-variable RET kjn--preferred-list-item RET

   - Note that all the items "a", "b" and "c" are offered as a choice in
     drop-down list.

3. M-x customize-variable RET kjn--list-items RET
   
   and add an item "d" to the list. Save it for current session.

4. Now repeat step 2. Note that the newly added item doesn't show up in
   the dropdown list.

Can someone help me with achieving the desired behaviour in step 4. 

Jambunathan K.

-- 



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

* Re: defcustom - help
  2011-08-03 14:57 defcustom - help Jambunathan K
@ 2011-08-04  3:39 ` Katsumi Yamaoka
  2011-08-04  3:46   ` Katsumi Yamaoka
  0 siblings, 1 reply; 3+ messages in thread
From: Katsumi Yamaoka @ 2011-08-04  3:39 UTC (permalink / raw)
  To: emacs-devel

Jambunathan K wrote:
> There are two defcustoms - one for configuring a list of items and one
> for choosing the preferred among those. Read ahead ...
[...]
> Can someone help me with achieving the desired behaviour in step 4.

You can use :convert-widget to generate a custom type dynamically.

(defun kjn--widget-type-convert-widget (widget)
  "Convert the car of `:args' as a widget type in WIDGET."
  (apply 'widget-convert (widget-type widget)
	 (eval (car (widget-get widget :args)))))

(defcustom kjn--preferred-list-item "a"
  "Preferred item in the list."
  :group 'kjn
  :type `(choice :convert-widget kjn--widget-type-convert-widget
		 `((const :tag "None" nil)
		   ,@(mapcar (lambda (c)
			       `(const :tag ,c ,c))
			     kjn--list-items))))

I'm not a custom expert so please don't ask me how/why it works. ;-)



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

* Re: defcustom - help
  2011-08-04  3:39 ` Katsumi Yamaoka
@ 2011-08-04  3:46   ` Katsumi Yamaoka
  0 siblings, 0 replies; 3+ messages in thread
From: Katsumi Yamaoka @ 2011-08-04  3:46 UTC (permalink / raw)
  To: emacs-devel

Katsumi Yamaoka wrote:
> You can use :convert-widget to generate a custom type dynamically.
[...]
> (defcustom kjn--preferred-list-item "a"
>   "Preferred item in the list."
>   :group 'kjn
>   :type `(choice :convert-widget kjn--widget-type-convert-widget
          ^
Replace it with ', ` is unnecessary in this case.



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

end of thread, other threads:[~2011-08-04  3:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-03 14:57 defcustom - help Jambunathan K
2011-08-04  3:39 ` Katsumi Yamaoka
2011-08-04  3:46   ` Katsumi Yamaoka

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).