unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10907: 24.0.94; Updating display of Customize buffer
@ 2012-02-28 13:07 Stephen Berman
  2012-02-28 13:46 ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Stephen Berman @ 2012-02-28 13:07 UTC (permalink / raw)
  To: 10907

[-- Attachment #1: Type: text/plain, Size: 2468 bytes --]

[I posted about this problem to gnu-emacs-help last week but there
hasn't been any response, so I'm adding it to the bugtracker with a more
explicit and self-contained recipe in the hope that, if it's a real bug,
it will be fixed, or if I have made a mistake, it will be pointed out.]

1. mkdir ~/srb; cd ~/srb; touch file1 file2 file3

2. emacs -Q -l path/to/srb.el # Load the attached file.

3. M-x customize-option RET srb-selected-file RET
The Customize buffer shows this, as expected:

 Srb Selected File:
 (*) file1
 ( ) file2
 ( ) file3
     State: STANDARD.
     A selected file name from `srb-file-list'.

4. rm -rf ~/srb

5. Repeat steps 2 and 3; now the Customize buffer shows this:

 Srb Selected File: nil
     State: STANDARD. (mismatch)
     A selected file name from `srb-file-list'.

This is also expected, since srb-selected-file doesn't handle nil.

6. M-x srb-add-file RET file1 RET

7. In the Customize buffer hide and then re-show the value of
srb-selected-file; now the Customize buffer shows this:

 Srb Selected File: "file1"
     State: STANDARD. (mismatch)
     A selected file name from `srb-file-list'.

If I kill the Customize buffer and repeat step 3, it still has the
same display.  What I expected to see is this: 

 Srb Selected File:
 (*) file1
     State: STANDARD.
     A selected file name from `srb-file-list'.

But only if I exit Emacs and then restart it does the Customize buffer
look like this (after loading srb.el).  I haven't been able to get this
display after carrying out steps 4-7 without restarting Emacs.  Is it
possible?  Is there a problem with my defcustom srb-selected-file, or
with the calls to custom-reevaluate-setting and custom-set-default in
srb-add-file, or have I overlooked some other custom-* function that
correctly updates the display?  Or is this a bug in the Customize API?
I'd be grateful for any help.


In GNU Emacs 24.0.94.1 (i686-suse-linux-gnu, GTK+ Version 2.24.7)
 of 2012-02-28 on escher
Windowing system distributor `The X.Org Foundation', version 11.0.11004000
Configured using:
 `configure '--without-toolkit-scroll-bars' 'CFLAGS=-g''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=local
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test file --]
[-- Type: text/x-emacs-lisp, Size: 1144 bytes --]

(defgroup srb nil
  "srb group.")

(defcustom srb-dir "~/srb/"
  "Directory of files whose names are members of `srb-file-list'."
  :type 'directory
  :group 'srb)

(defvar srb-file-list (if (file-exists-p srb-dir)
			  (directory-files srb-dir nil
					   "^[^.]+")) ; Don't include "." or ".."
  "List of names of files in `srb-dir'.")

(defcustom srb-selected-file (car srb-file-list)
  "A selected file name from `srb-file-list'."
  :type `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))
  :group 'srb)

(defun srb-add-file ()
  "Add a file name to `srb-file-list' and update `srb-selected-file'."
  (interactive)
  (unless (file-exists-p srb-dir)
    (make-directory srb-dir))
  (let ((file (read-from-minibuffer "Enter a file name: ")))
    (with-current-buffer (get-buffer-create file)
      (erase-buffer)
      (write-region (point-min) (point-max)
		    (concat srb-dir file) nil 'nomessage nil t)
      (kill-buffer file)))
  (setq srb-file-list (directory-files srb-dir nil "^[^.]+"))
  (custom-reevaluate-setting 'srb-selected-file)
  (custom-set-default 'srb-file (symbol-value 'srb-selected-file)))

(provide 'srb)

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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 13:07 bug#10907: 24.0.94; Updating display of Customize buffer Stephen Berman
@ 2012-02-28 13:46 ` Andreas Schwab
  2012-02-28 15:19   ` Stephen Berman
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2012-02-28 13:46 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907

Stephen Berman <stephen.berman@gmx.net> writes:

> 7. In the Customize buffer hide and then re-show the value of
> srb-selected-file; now the Customize buffer shows this:
>
>  Srb Selected File: "file1"
>      State: STANDARD. (mismatch)
>      A selected file name from `srb-file-list'.

The current value does not match any of the empty set of choices.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 13:46 ` Andreas Schwab
@ 2012-02-28 15:19   ` Stephen Berman
  2012-02-28 17:23     ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Stephen Berman @ 2012-02-28 15:19 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10907

On Tue, 28 Feb 2012 14:46:47 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>> 7. In the Customize buffer hide and then re-show the value of
>> srb-selected-file; now the Customize buffer shows this:
>>
>>  Srb Selected File: "file1"
>>      State: STANDARD. (mismatch)
>>      A selected file name from `srb-file-list'.
>
> The current value does not match any of the empty set of choices.

Do you mean that Custom thinks srb-file-list is still empty?  If so, and
if I add a check, that fixes the mismatch, but not the display.
Specifically, if I change the definition of srb-selected-file to this:

(defcustom srb-selected-file (car srb-file-list)
  "A selected file name from `srb-file-list'."
  :type (if srb-file-list
	    `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))) 
  :group 'srb)

then when srb-dir is empty or nonexistant, the Custom buffer shows this:

 Srb Selected File: nil
     State: STANDARD.
     A selected file name from `srb-file-list'.

and after I add a file and refresh the display by hiding and unhiding
the value, it shows this:

 Srb Selected File: "file1"
     State: STANDARD.
     A selected file name from `srb-file-list'.

I still see the list of radio buttons only after restarting Emacs.  So I
guess the defcustom is still wrong; do you know how to fix it?

Steve Berman





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 15:19   ` Stephen Berman
@ 2012-02-28 17:23     ` Andreas Schwab
  2012-02-28 17:50       ` Stephen Berman
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2012-02-28 17:23 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907

Stephen Berman <stephen.berman@gmx.net> writes:

> On Tue, 28 Feb 2012 14:46:47 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:
>
>> Stephen Berman <stephen.berman@gmx.net> writes:
>>
>>> 7. In the Customize buffer hide and then re-show the value of
>>> srb-selected-file; now the Customize buffer shows this:
>>>
>>>  Srb Selected File: "file1"
>>>      State: STANDARD. (mismatch)
>>>      A selected file name from `srb-file-list'.
>>
>> The current value does not match any of the empty set of choices.
>
> Do you mean that Custom thinks srb-file-list is still empty?

Its :type hasn't changed at all.

> (defcustom srb-selected-file (car srb-file-list)
>   "A selected file name from `srb-file-list'."
>   :type (if srb-file-list
> 	    `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))) 
>   :group 'srb)
>
> then when srb-dir is empty or nonexistant, the Custom buffer shows this:
>
>  Srb Selected File: nil
>      State: STANDARD.
>      A selected file name from `srb-file-list'.

:type is nil (ie. no type).

> and after I add a file and refresh the display by hiding and unhiding
> the value, it shows this:
>
>  Srb Selected File: "file1"
>      State: STANDARD.
>      A selected file name from `srb-file-list'.

:type is still nil.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 17:23     ` Andreas Schwab
@ 2012-02-28 17:50       ` Stephen Berman
  2012-02-28 18:00         ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Stephen Berman @ 2012-02-28 17:50 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10907

On Tue, 28 Feb 2012 18:23:11 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>> On Tue, 28 Feb 2012 14:46:47 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>>> Stephen Berman <stephen.berman@gmx.net> writes:
>>>
>>>> 7. In the Customize buffer hide and then re-show the value of
>>>> srb-selected-file; now the Customize buffer shows this:
>>>>
>>>>  Srb Selected File: "file1"
>>>>      State: STANDARD. (mismatch)
>>>>      A selected file name from `srb-file-list'.
>>>
>>> The current value does not match any of the empty set of choices.
>>
>> Do you mean that Custom thinks srb-file-list is still empty?
>
> Its :type hasn't changed at all.
>
>> (defcustom srb-selected-file (car srb-file-list)
>>   "A selected file name from `srb-file-list'."
>>   :type (if srb-file-list
>> 	    `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))) 
>>   :group 'srb)
>>
>> then when srb-dir is empty or nonexistant, the Custom buffer shows this:
>>
>>  Srb Selected File: nil
>>      State: STANDARD.
>>      A selected file name from `srb-file-list'.
>
> :type is nil (ie. no type).
>
>> and after I add a file and refresh the display by hiding and unhiding
>> the value, it shows this:
>>
>>  Srb Selected File: "file1"
>>      State: STANDARD.
>>      A selected file name from `srb-file-list'.
>
> :type is still nil.

I don't follow you; can (or someone else who gets it) you please
elaborate?  Thanks.

Steve Berman





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 17:50       ` Stephen Berman
@ 2012-02-28 18:00         ` Andreas Schwab
  2012-02-28 18:33           ` Stephen Berman
  2012-02-28 22:11           ` Drew Adams
  0 siblings, 2 replies; 19+ messages in thread
From: Andreas Schwab @ 2012-02-28 18:00 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907

*Note (elisp) Customization Types::

       You specify the customization type in `defcustom' with the `:type'
    keyword.  The argument of `:type' is evaluated, but only once when the
    `defcustom' is executed, so it isn't useful for the value to vary.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 18:00         ` Andreas Schwab
@ 2012-02-28 18:33           ` Stephen Berman
  2012-02-29  2:06             ` Stefan Monnier
  2012-02-29  4:00             ` Eli Zaretskii
  2012-02-28 22:11           ` Drew Adams
  1 sibling, 2 replies; 19+ messages in thread
From: Stephen Berman @ 2012-02-28 18:33 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10907

On Tue, 28 Feb 2012 19:00:15 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:

> *Note (elisp) Customization Types::
>
>        You specify the customization type in `defcustom' with the `:type'
>     keyword.  The argument of `:type' is evaluated, but only once when the
>     `defcustom' is executed, so it isn't useful for the value to vary.

Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
defcustom in a running Emacs?  It would be very useful.

Steve Berman





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 18:00         ` Andreas Schwab
  2012-02-28 18:33           ` Stephen Berman
@ 2012-02-28 22:11           ` Drew Adams
  2012-02-28 23:11             ` Andreas Schwab
  1 sibling, 1 reply; 19+ messages in thread
From: Drew Adams @ 2012-02-28 22:11 UTC (permalink / raw)
  To: 'Andreas Schwab', 'Stephen Berman'; +Cc: 10907

> *Note (elisp) Customization Types::
> You specify the customization type in `defcustom' with 
> the `:type' keyword.  The argument of `:type' is evaluated,
> but only once when the `defcustom' is executed, so it isn't
> useful for the value to vary.

Having this in the Elisp manual helps developers, but it is not all that helpful
for a Customize user trying to understand the behavior.

Stephen described a purely end-user interaction.  And yes, the behavior is not
obvious.  We obviously felt it sufficiently non-obvious to add that paragraph to
the Elisp manual.  End users deserve some info that helps them too understand a
bit.

At the least there seems to be an Emacs-manual doc bug here. Let's please add
something to help users navigate the labyrinth.






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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 22:11           ` Drew Adams
@ 2012-02-28 23:11             ` Andreas Schwab
  2012-02-29  1:01               ` Drew Adams
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2012-02-28 23:11 UTC (permalink / raw)
  To: Drew Adams; +Cc: 10907, 'Stephen Berman'

"Drew Adams" <drew.adams@oracle.com> writes:

> At the least there seems to be an Emacs-manual doc bug here.

Rubbish.  This is about defcustom, which is not a user-level command.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 23:11             ` Andreas Schwab
@ 2012-02-29  1:01               ` Drew Adams
  0 siblings, 0 replies; 19+ messages in thread
From: Drew Adams @ 2012-02-29  1:01 UTC (permalink / raw)
  To: 'Andreas Schwab'; +Cc: 10907, 'Stephen Berman'

> This is about defcustom, which is not a user-level command.

My bad.






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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 18:33           ` Stephen Berman
@ 2012-02-29  2:06             ` Stefan Monnier
  2012-02-29  9:05               ` Andreas Schwab
                                 ` (2 more replies)
  2012-02-29  4:00             ` Eli Zaretskii
  1 sibling, 3 replies; 19+ messages in thread
From: Stefan Monnier @ 2012-02-29  2:06 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907, Andreas Schwab

> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
> defcustom in a running Emacs?

Agreed that there should be some way to have a defcustom type that is
a bit more dynamic: no need to completely reevaluate the whole
expression, but being able to have a dynamic set of `choice's would
be helpful.
I don't know Custom enough to be sure that it doesn't exist, so if it
does, please someone change the :type of completion-styles to make use
of it.  If it doesn't, well, patches welcome,


        Stefan






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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-28 18:33           ` Stephen Berman
  2012-02-29  2:06             ` Stefan Monnier
@ 2012-02-29  4:00             ` Eli Zaretskii
  2012-02-29 12:20               ` Stephen Berman
  1 sibling, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2012-02-29  4:00 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907, schwab

> From: Stephen Berman <stephen.berman@gmx.net>
> Date: Tue, 28 Feb 2012 19:33:16 +0100
> Cc: 10907@debbugs.gnu.org
> 
> On Tue, 28 Feb 2012 19:00:15 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:
> 
> > *Note (elisp) Customization Types::
> >
> >        You specify the customization type in `defcustom' with the `:type'
> >     keyword.  The argument of `:type' is evaluated, but only once when the
> >     `defcustom' is executed, so it isn't useful for the value to vary.
> 
> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
> defcustom in a running Emacs?  It would be very useful.

There's custom-reevaluate-setting, but I'm not sure it will do what
you want.





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29  2:06             ` Stefan Monnier
@ 2012-02-29  9:05               ` Andreas Schwab
  2012-02-29 12:26                 ` Stephen Berman
  2012-02-29 19:45               ` Glenn Morris
  2012-03-03 17:03               ` Stephen Berman
  2 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2012-02-29  9:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10907, Stephen Berman

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
>> defcustom in a running Emacs?
>
> Agreed that there should be some way to have a defcustom type that is
> a bit more dynamic: no need to completely reevaluate the whole
> expression, but being able to have a dynamic set of `choice's would
> be helpful.

Define a widget derived from menu-choice with custom :match and
:validate methods.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29  4:00             ` Eli Zaretskii
@ 2012-02-29 12:20               ` Stephen Berman
  0 siblings, 0 replies; 19+ messages in thread
From: Stephen Berman @ 2012-02-29 12:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 10907, schwab

On Wed, 29 Feb 2012 06:00:23 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Date: Tue, 28 Feb 2012 19:33:16 +0100
>> Cc: 10907@debbugs.gnu.org
>> 
>> On Tue, 28 Feb 2012 19:00:15 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:
>> 
>> > *Note (elisp) Customization Types::
>> >
>> >        You specify the customization type in `defcustom' with the `:type'
>> >     keyword.  The argument of `:type' is evaluated, but only once when the
>> >     `defcustom' is executed, so it isn't useful for the value to vary.
>> 
>> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
>> defcustom in a running Emacs?  It would be very useful.
>
> There's custom-reevaluate-setting, but I'm not sure it will do what
> you want.

Unfortunately it doesn't (I pointed that out in my OP, assuming I was
using it properly).

Steve Berman





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29  9:05               ` Andreas Schwab
@ 2012-02-29 12:26                 ` Stephen Berman
  0 siblings, 0 replies; 19+ messages in thread
From: Stephen Berman @ 2012-02-29 12:26 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10907

On Wed, 29 Feb 2012 10:05:15 +0100 Andreas Schwab <schwab@linux-m68k.org> wrote:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
>>> defcustom in a running Emacs?
>>
>> Agreed that there should be some way to have a defcustom type that is
>> a bit more dynamic: no need to completely reevaluate the whole
>> expression, but being able to have a dynamic set of `choice's would
>> be helpful.
>
> Define a widget derived from menu-choice with custom :match and
> :validate methods.

Thanks for the suggestion; I'll try taking a stab at it, but with my
level of competence and available time, it may take a while, if I
succeed at all (if anyone else beats me to the punch, please let know).

Steve Berman





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29  2:06             ` Stefan Monnier
  2012-02-29  9:05               ` Andreas Schwab
@ 2012-02-29 19:45               ` Glenn Morris
  2012-03-01  2:42                 ` Stefan Monnier
  2012-03-03 17:03               ` Stephen Berman
  2 siblings, 1 reply; 19+ messages in thread
From: Glenn Morris @ 2012-02-29 19:45 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10907, Stephen Berman, Andreas Schwab

Stefan Monnier wrote:

> but being able to have a dynamic set of `choice's would be helpful.

When might you want to use such a thing, as opposed to having :type a
static list that encompasses all possible valid settings?

I can only see it being harmful. Eg if you want to compute the :type
based on whether some external utility is installed on the system, you
could end up with saved settings in ~/.emacs that suddenly become
invalid (wrong type) if said utility gets removed from the system.





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29 19:45               ` Glenn Morris
@ 2012-03-01  2:42                 ` Stefan Monnier
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Monnier @ 2012-03-01  2:42 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 10907, Stephen Berman, Andreas Schwab

>> but being able to have a dynamic set of `choice's would be helpful.
> When might you want to use such a thing, as opposed to having :type a
> static list that encompasses all possible valid settings?

In the email to which you respond, I mention completion-styles, since
these can refer to styles that are provided by external packages.

> I can only see it being harmful.  Eg if you want to compute the :type
> based on whether some external utility is installed on the system, you
> could end up with saved settings in ~/.emacs that suddenly become
> invalid (wrong type) if said utility gets removed from the system.

Just because there are scenarios where you can bump into bugs doesn't
mean it can't be very useful.  E.g. types such as `function' also accept
a set of values that depends on what's installed, yet it hasn't proved
to be a problem.


        Stefan





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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-02-29  2:06             ` Stefan Monnier
  2012-02-29  9:05               ` Andreas Schwab
  2012-02-29 19:45               ` Glenn Morris
@ 2012-03-03 17:03               ` Stephen Berman
  2022-04-21 13:49                 ` Lars Ingebrigtsen
  2 siblings, 1 reply; 19+ messages in thread
From: Stephen Berman @ 2012-03-03 17:03 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 10907, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

On Tue, 28 Feb 2012 21:06:59 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> Ah, thanks.  I feared as much.  Is there really no way to reevaluate a
>> defcustom in a running Emacs?
>
> Agreed that there should be some way to have a defcustom type that is
> a bit more dynamic: no need to completely reevaluate the whole
> expression, but being able to have a dynamic set of `choice's would
> be helpful.

It turns out that, at least for my use case, completely reevaluating the
whole expression in fact DTRT -- see the attached file.  Admittedly,
elegant it isn't, and AFAIK this is virtually never done (I guess that's
why it didn't occur to me when I asked the above question) -- but other
than inelegance, is there a problem with doing this?

Steve Berman


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test updating defcustom --]
[-- Type: text/x-emacs-lisp, Size: 2053 bytes --]

(defgroup srb nil
  "srb group.")

(defcustom srb-dir "~/srb/"
  "Directory of files whose names are members of `srb-file-list'."
  :type 'directory
  :group 'srb)

(defvar srb-file-list (if (file-exists-p srb-dir)
			  (directory-files srb-dir nil
					   "^[^.]+")) ; Don't include "." or ".."
  "List of names of files in `srb-dir'.")

(defcustom srb-selected-file (car srb-file-list)
  "A selected file name from `srb-file-list'."
  :type `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))
  :group 'srb)

(defun srb-reevaluate-defcustom ()
  "Reevaluate defcustom `srb-selected-file'."
  (eval (defcustom srb-selected-file (car srb-file-list)
	  "A selected file name from `srb-file-list'."
	  :type `(radio ,@(mapcar (lambda (x) (list 'const x)) srb-file-list))
	  :group 'srb)))

(defun srb-add-file ()
  "Add a file to `srb-dir' and update variables."
  (interactive)
  (unless (file-exists-p srb-dir)
    (make-directory srb-dir))
  (let ((file (read-from-minibuffer "Enter a file name: ")))
    (with-current-buffer (get-buffer-create file)
      (erase-buffer)
      (write-region (point-min) (point-max)
		    (concat srb-dir file) nil 'nomessage nil t)
      (kill-buffer file)))
  (setq srb-file-list (directory-files srb-dir nil "^[^.]+"))
  (custom-set-default 'srb-selected-file (symbol-value 'srb-selected-file))
  (srb-reevaluate-defcustom))

(defun srb-delete-file ()
  "Delete a file from `srb-dir' and update variables."
  (interactive)
  (let ((files (directory-files srb-dir nil "^[^.]+")))
    (if (and (file-exists-p srb-dir) (> (length files) 0))
	(let ((file (completing-read "Enter a file name: " files nil t)))
	  (when (yes-or-no-p (format "Confirm you want to delete file %s " file))
	    (delete-file (concat srb-dir file))
	    (setq srb-file-list (directory-files srb-dir nil "^[^.]+"))
	    (custom-set-default 'srb-selected-file
				(symbol-value 'srb-selected-file))
	    (srb-reevaluate-defcustom)
	    (message "File %s deleted" file)))
      (error "There are no files to delete"))))

(provide 'srb)

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

* bug#10907: 24.0.94; Updating display of Customize buffer
  2012-03-03 17:03               ` Stephen Berman
@ 2022-04-21 13:49                 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 19+ messages in thread
From: Lars Ingebrigtsen @ 2022-04-21 13:49 UTC (permalink / raw)
  To: Stephen Berman; +Cc: 10907, Andreas Schwab, Stefan Monnier

Stephen Berman <stephen.berman@gmx.net> writes:

> It turns out that, at least for my use case, completely reevaluating the
> whole expression in fact DTRT -- see the attached file.  Admittedly,
> elegant it isn't, and AFAIK this is virtually never done (I guess that's
> why it didn't occur to me when I asked the above question) -- but other
> than inelegance, is there a problem with doing this?

No, doing that's fine, but rather unusual.

Andreas pointed out that the traditional way to do more dynamic types is
to use a menu-choice with :match and stuff, so I don't think there's
anything much to fix here, really, and I'm therefore closing this bug
report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2022-04-21 13:49 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28 13:07 bug#10907: 24.0.94; Updating display of Customize buffer Stephen Berman
2012-02-28 13:46 ` Andreas Schwab
2012-02-28 15:19   ` Stephen Berman
2012-02-28 17:23     ` Andreas Schwab
2012-02-28 17:50       ` Stephen Berman
2012-02-28 18:00         ` Andreas Schwab
2012-02-28 18:33           ` Stephen Berman
2012-02-29  2:06             ` Stefan Monnier
2012-02-29  9:05               ` Andreas Schwab
2012-02-29 12:26                 ` Stephen Berman
2012-02-29 19:45               ` Glenn Morris
2012-03-01  2:42                 ` Stefan Monnier
2012-03-03 17:03               ` Stephen Berman
2022-04-21 13:49                 ` Lars Ingebrigtsen
2012-02-29  4:00             ` Eli Zaretskii
2012-02-29 12:20               ` Stephen Berman
2012-02-28 22:11           ` Drew Adams
2012-02-28 23:11             ` Andreas Schwab
2012-02-29  1:01               ` Drew Adams

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).