unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 10907@debbugs.gnu.org, Andreas Schwab <schwab@linux-m68k.org>
Subject: bug#10907: 24.0.94; Updating display of Customize buffer
Date: Sat, 03 Mar 2012 18:03:50 +0100	[thread overview]
Message-ID: <87r4x9ehvt.fsf@escher.home> (raw)
In-Reply-To: <jwvipiq2y5p.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 28 Feb 2012 21:06:59 -0500")

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

  parent reply	other threads:[~2012-03-03 17:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r4x9ehvt.fsf@escher.home \
    --to=stephen.berman@gmx.net \
    --cc=10907@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=schwab@linux-m68k.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 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).