1 ;;; custom-edit.el --- Tools for customization Emacs.
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
17 (require 'widget-edit)
19 (define-widget-keywords :custom-show :custom-magic
20 :custom-state :custom-level :custom-form
21 :custom-apply :custom-set-default :custom-reset)
25 (defun custom-quote (sexp)
26 "Quote SEXP iff it is not self quoting."
27 (if (or (memq sexp '(t nil))
29 (eq (aref (symbol-name sexp) 0) ?:))
31 (memq (car sexp) '(lambda)))
37 (defun custom-unimplemented (&rest ignore)
38 "Apologize for my laziness."
39 (error "Sorry, not implemented"))
41 ;;; Modification of Basic Widgets.
43 ;; We add extra properties to the basic widgets needed here. This is
44 ;; fine, as long as we are careful to stay within out own namespace.
46 ;; We want simple widgets to be displayed by default, but complex
47 ;; widgets to be hidden.
49 (widget-put (get 'item 'widget-type) :custom-show t)
50 (widget-put (get 'editable-field 'widget-type)
51 :custom-show (lambda (widget value)
52 (let ((pp (pp-to-string value)))
53 (cond ((string-match "\n" pp)
58 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
60 ;;; The `custom-magic' Widget
62 (define-widget 'custom-magic 'item
63 "Status feedback for customization option."
65 :action 'widget-choice-item-action
66 :value-create 'custom-magic-value-create)
68 (defface custom-invalid-face '((((class color))
69 (:foreground "yellow" :background "red"))
71 (:bold t :italic t :underline t)))
72 "Face used when the customize item is invalid."
75 (defface custom-rogue-face '((((class color))
76 (:foreground "pink" :background "black"))
79 "Face used when the customize item is not defined for customization."
82 (defface custom-modified-face '((((class color))
83 (:foreground "white" :background "blue"))
86 "Face used when the customize item has been modified."
89 (defface custom-applied-face '((((class color))
90 (:foreground "blue" :background "white"))
93 "Face used when the customize item has been applied."
96 (defface custom-saved-face '((t (:underline t)))
97 "Face used when the customize item has been saved."
100 (defcustom custom-magic-alist '((nil "#" underline)
103 (invalid "x" custom-invalid-face)
104 (modified "*" custom-modified-face)
105 (applied "+" custom-applied-face)
106 (saved "!" custom-saved-face)
107 (rogue "@" custom-rogue-face)
109 "Alist of magic representing a customize items status.
110 Each entry is of the form (STATE MAGIC FACE), where
112 STATE is one of the following symbols:
115 For internal use, should never occur.
117 For internal use, should never occur.
119 This item is not being displayed.
121 This item is modified, but has an invalid form.
123 This item is modified, and has a valid form.
125 This items current value has been changed temporarily.
127 This item is marked for saving.
129 This item has no customization information.
131 This item is unchanged from the factory default.
133 MAGIC is a string used to present that state.
135 FACE is a face used to present the state.
137 The list should be sorted most significant first."
138 :type '(repeat (list (choice (item nil)
150 (defun custom-magic-value-create (widget)
151 ;; Create compact status report for WIDGET.
152 (let* ((parent (widget-get widget :parent))
153 (state (widget-get parent :custom-state))
154 (entry (assq state custom-magic-alist))
155 (magic (nth 1 entry))
156 (face (nth 2 entry)))
157 (if (eq (widget-get parent :custom-form) 'lisp)
158 (widget-insert "(" magic ")")
159 (widget-insert "[" magic "]"))
160 (widget-put widget :button-face face)))
162 (defun custom-magic-reset (widget)
163 "Redraw the :custom-magic property of WIDGET."
164 (let ((magic (widget-get widget :custom-magic)))
165 (widget-value-set magic (widget-value magic))))
167 ;;; The `custom-level' Widget.
169 (define-widget 'custom-level 'item
170 "The custom level buttons."
172 :help-echo "Push me to expand or collapse this item."
173 :action 'custom-level-action)
175 (defun custom-level-action (widget &optional event)
176 "Toggle visibility for parent to WIDGET."
177 (let* ((parent (widget-get widget :parent))
178 (state (widget-get parent :custom-state)))
179 (cond ((memq state '(invalid modified))
180 (error "There are unapplied changes"))
182 (widget-put parent :custom-state 'unknown))
184 (widget-put parent :custom-state 'hidden)))
185 (custom-redraw parent)))
187 ;;; The `custom' Widget.
189 (define-widget 'custom 'default
190 "Customize a user option."
191 :convert-widget 'widget-item-convert-widget
192 :format "%l%[%t%]: %v%m %h"
193 :format-handler 'custom-format-handler
194 :notify 'custom-notify
196 :custom-state 'hidden
197 :documentation-property 'widget-subclass-responsibility
198 :value-create 'widget-subclass-responsibility
199 :value-delete 'widget-radio-value-delete
200 :value-get 'widget-item-value-get
201 :validate 'widget-editable-list-validate
202 :match (lambda (widget value) (symbolp value)))
204 (defun custom-format-handler (widget escape)
205 ;; We recognize extra escape sequences.
206 (let* ((symbol (widget-get widget :value))
207 (buttons (widget-get widget :buttons))
208 (level (widget-get widget :custom-level)))
209 (cond ((eq escape ?l)
211 (push (widget-create-child-and-convert
212 widget 'custom-level (make-string level ?*))
215 (widget-put widget :buttons buttons)))
217 (and (eq (preceding-char) ?\n)
218 (widget-get widget :indent)
219 (insert-char ? (widget-get widget :indent)))
220 (let ((magic (widget-create-child-and-convert
221 widget 'custom-magic nil)))
222 (widget-put widget :custom-magic magic)
224 (widget-put widget :buttons buttons)))
226 (widget-default-format-handler widget escape)))))
228 (defun custom-notify (widget &rest args)
229 "Keep track of changes."
230 (widget-put widget :custom-state 'modified)
231 (let ((buffer-undo-list t))
232 (custom-magic-reset widget))
233 (apply 'widget-default-notify widget args))
235 (defun custom-redraw (widget)
236 "Redraw WIDGET with current settings."
237 (widget-value-set widget (widget-value widget))
238 (custom-redraw-magic widget))
240 (defun custom-redraw-magic (widget)
241 "Redraw WIDGET state with current settings."
243 (let ((magic (widget-get widget :custom-magic)))
246 (widget-value-set magic (widget-value magic))
247 (when (setq widget (widget-get widget :group))
248 (custom-group-state-update widget))))
251 (defun custom-show (widget value)
252 "Non-nil if WIDGET should be shown with VALUE by default."
253 (let ((show (widget-get widget :custom-show)))
259 (funcall show widget value)))))
261 ;;; The `custom-variable' Widget.
263 (define-widget 'custom-variable 'custom
264 "Customize variable."
266 :help-echo "Push me to set or reset this variable."
267 :documentation-property 'variable-documentation
270 :value-create 'custom-variable-value-create
271 :action 'custom-variable-action
272 :custom-apply 'custom-variable-apply
273 :custom-set-default 'custom-variable-set-default
274 :custom-reset 'custom-redraw)
276 (defun custom-variable-value-create (widget)
277 "Here is where you edit the variables value."
278 (let* ((buttons (widget-get widget :buttons))
279 (children (widget-get widget :children))
280 (form (widget-get widget :custom-form))
281 (state (widget-get widget :custom-state))
282 (symbol (widget-get widget :value))
283 (child-type (or (get symbol 'custom-type) 'sexp))
284 (type (if (listp child-type)
287 (conv (widget-convert type))
288 (value (if (boundp symbol)
289 (symbol-value symbol)
290 (widget-get conv :value))))
291 ;; If the widget is new, the child determine whether it is hidden.
293 ((custom-show type value)
294 (setq state 'unknown))
296 (setq state 'hidden)))
297 ;; If we don't know the state, see if we need to edit it in lisp form.
298 (when (eq state 'unknown)
299 (unless (widget-apply (widget-convert type) :match value)
301 ;; Now we can create the child widget.
302 (cond ((eq state 'hidden)
303 ;; Make hidden value easy to show.
304 (push (widget-create-child-and-convert
306 :tag (symbol-name symbol)
307 :format "%t: %[show%]")
310 ;; In lisp mode edit the saved value when possible.
311 (let* ((value (cond ((get symbol 'saved-value)
312 (car (get symbol 'saved-value)))
313 ((get symbol 'factory-value)
314 (car (get symbol 'factory-value)))
316 (custom-quote (symbol-value symbol)))
318 (custom-quote (widget-get conv :value))))))
319 (push (widget-create-child-and-convert widget 'sexp
320 :tag (symbol-name symbol)
326 (push (widget-create-child-and-convert widget type
327 :tag (symbol-name symbol)
330 ;; Now update the state.
331 (unless (eq (preceding-char) ?\n)
332 (widget-insert "\n"))
333 (if (eq state 'hidden)
334 (widget-put widget :custom-state state)
335 (custom-variable-state-set widget))
336 (widget-put widget :custom-form form)
337 (widget-put widget :buttons buttons)
338 (widget-put widget :children children)))
340 (defun custom-variable-state-set (widget)
341 "Set the state of WIDGET."
342 (let* ((symbol (widget-value widget))
343 (value (symbol-value symbol))
344 (state (if (get symbol 'saved-value)
345 (if (condition-case nil
347 (eval (car (get symbol 'saved-value))))
351 (if (get symbol 'factory-value)
352 (if (condition-case nil
354 (eval (car (get symbol 'factory-value))))
359 (widget-put widget :custom-state state)))
361 (defvar custom-variable-menu
362 '(("Edit" . custom-variable-edit)
363 ("Edit Default" . custom-variable-edit-lisp)
364 ("Apply" . custom-variable-apply)
365 ("Set Default" . custom-variable-set-default)
366 ("Reset" . custom-redraw)
367 ("Reset to Default" . custom-variable-default)
368 ("Reset to Factory Settings" . custom-variable-factory))
369 "Alist of actions for the `custom-variable' widget.
370 The key is a string containing the name of the action, the value is a
371 lisp function taking the widget as an element which will be called
372 when the action is chosen.")
374 (defun custom-variable-action (widget &optional event)
375 "Show the menu for `custom-variable' WIDGET.
376 Optional EVENT is the location for the menu."
377 (let* ((completion-ignore-case t)
378 (answer (widget-choose (symbol-name (widget-get widget :value))
382 (funcall answer widget))))
384 (defun custom-variable-edit (widget)
385 "Edit value of WIDGET."
386 (widget-put widget :custom-state 'unknown)
387 (widget-put widget :custom-form 'edit)
388 (custom-redraw widget))
390 (defun custom-variable-edit-lisp (widget)
391 "Edit the lisp representation of the value of WIDGET."
392 (widget-put widget :custom-state 'unknown)
393 (widget-put widget :custom-form 'lisp)
394 (custom-redraw widget))
396 (defun custom-variable-apply (widget)
397 "Set the current value for the variable being edited by WIDGET."
398 (let ((form (widget-get widget :custom-form))
399 (state (widget-get widget :custom-state))
400 (child (car (widget-get widget :children)))
401 (symbol (widget-value widget))
403 (cond ((eq state 'hidden)
404 (error "Cannot apply hidden variable."))
405 ((setq val (widget-apply child :validate))
406 (error "Invalid %S"))
408 (set symbol (eval (widget-value child))))
410 (set symbol (widget-value child))))
411 (custom-variable-state-set widget)
412 (custom-redraw-magic widget)))
414 (defun custom-variable-set-default (widget)
415 "Set the default value for the variable being edited by WIDGET."
416 (let ((form (widget-get widget :custom-form))
417 (state (widget-get widget :custom-state))
418 (child (car (widget-get widget :children)))
419 (symbol (widget-value widget))
421 (cond ((eq state 'hidden)
422 (error "Cannot apply hidden variable."))
423 ((setq val (widget-apply child :validate))
424 (error "Invalid %S"))
426 (put symbol 'saved-value (list (widget-value child)))
427 (set symbol (eval (widget-value child))))
430 'saved-value (list (custom-quote (widget-value
432 (set symbol (widget-value child))))
433 (custom-variable-state-set widget)
434 (custom-redraw-magic widget)))
436 (defun custom-variable-default (widget)
437 "Restore the default value for the variable being edited by WIDGET."
438 (let ((symbol (widget-value widget)))
439 (if (get symbol 'saved-value)
440 (set symbol (car (get symbol 'saved-value)))
441 (error "No default value for %s" symbol))
442 (widget-put widget :custom-state 'unknown)
443 (custom-redraw widget)))
445 (defun custom-variable-factory (widget)
446 "Restore the factory setting for the variable being edited by WIDGET."
447 (let ((symbol (widget-value widget)))
448 (if (get symbol 'factory-value)
449 (set symbol (car (get symbol 'factory-value)))
450 (error "No factory default for %S" symbol))
451 (when (get symbol 'saved-value)
452 (put symbol 'saved-value nil))
453 (widget-put widget :custom-state 'unknown)
454 (custom-redraw widget)))
456 ;;; The `custom-face-edit' Widget.
458 (defvar custom-face-edit-args
459 (mapcar (lambda (att)
462 (list 'const :format "" :value (nth 0 att))
464 custom-face-attributes))
466 (define-widget 'custom-face-edit 'checklist
467 "Edit face attributes."
471 :args (mapcar (lambda (att)
474 (list 'const :format "" :value (nth 0 att))
476 custom-face-attributes))
478 ;;; The `custom-display' Widget.
480 (define-widget 'custom-display 'menu-choice
481 "Select a display type."
484 :args '((const :tag "all" t)
487 :args ((group (const :format "Type: " type)
492 (const :format "TTY%n"
494 (group (const :format "Class: " class)
497 (const :format "Color "
502 (const :format "Monochrome%n"
504 (group (const :format "Background: " background)
507 (const :format "Light "
509 (const :format "Dark\n"
512 ;;; The `custom-face' Widget.
514 (define-widget 'custom-face 'custom
516 :format "%l%[%t%]: %s%m %h%v"
517 :format-handler 'custom-face-format-handler
518 :help-echo "Push me to set or reset this face."
519 :documentation-property 'face-documentation
520 :value-create 'custom-face-value-create
521 :action 'custom-face-action
522 :custom-apply 'custom-face-apply
523 :custom-set-default 'custom-face-set-default
524 :custom-reset 'custom-redraw)
526 (defun custom-face-format-handler (widget escape)
527 ;; We recognize extra escape sequences.
529 (symbol (widget-get widget :value)))
530 (cond ((eq escape ?s)
531 (setq child (widget-create-child-and-convert
533 :format "(%[sample%])\n"
534 :button-face symbol)))
536 (custom-format-handler widget escape)))
539 :buttons (cons child (widget-get widget :buttons))))))
541 (defun custom-face-value-create (widget)
542 ;; Create a list of the display specifications.
543 (unless (eq (preceding-char) ?\n)
545 (when (not (eq (widget-get widget :custom-state) 'hidden))
546 (let* ((symbol (widget-value widget))
547 (edit (widget-create-child-and-convert
548 widget 'editable-list
549 :entry-format "%i %d %v"
550 :value (or (get symbol 'saved-face)
551 (get symbol 'factory-face))
553 custom-display custom-face-edit))))
554 (custom-face-state-set widget)
555 (widget-put widget :children (list edit)))))
557 (defvar custom-face-menu
558 '(("Apply" . custom-face-apply)
559 ("Set Default" . custom-face-set-default)
560 ("Reset to Default" . custom-face-default)
561 ("Reset to Factory Setting" . custom-face-factory))
562 "Alist of actions for the `custom-face' widget.
563 The key is a string containing the name of the action, the value is a
564 lisp function taking the widget as an element which will be called
565 when the action is chosen.")
567 (defun custom-face-state-set (widget)
568 "Set the state of WIDGET."
569 (let ((symbol (widget-value widget)))
570 (widget-put widget :custom-state (cond ((get symbol 'saved-face)
572 ((get symbol 'factory-face)
577 (defun custom-face-action (widget &optional event)
578 "Show the menu for `custom-face' WIDGET.
579 Optional EVENT is the location for the menu."
580 (when (eq (widget-get widget :custom-state) 'hidden)
581 (error "You cannot edit a hidden face"))
582 (let* ((completion-ignore-case t)
583 (symbol (widget-get widget :value))
584 (answer (widget-choose (symbol-name symbol) custom-face-menu event)))
586 (funcall answer widget))
587 (custom-face-state-set widget)
588 (custom-redraw-magic widget)))
590 (defun custom-face-apply (widget)
591 "Make the face attributes in WIDGET take effect."
592 (let* ((symbol (widget-value widget))
593 (child (car (widget-get widget :children)))
594 (value (widget-value child)))
595 (custom-face-display-set symbol value)))
597 (defun custom-face-set-default (widget)
598 "Make the face attributes in WIDGET default."
599 (let* ((symbol (widget-value widget))
600 (child (car (widget-get widget :children)))
601 (value (widget-value child)))
602 (put symbol 'saved-face value)))
604 (defun custom-face-default (widget)
605 "Restore WIDGET to the face's default attributes."
606 (let* ((symbol (widget-value widget))
607 (child (car (widget-get widget :children))))
608 (unless (get symbol 'saved-face)
609 (error "No saved value for this face")
610 (widget-value-set child (get symbol 'saved-face)))))
612 (defun custom-face-factory (widget)
613 "Restore WIDGET to the face's factory settings."
614 (let* ((symbol (widget-value widget))
615 (child (car (widget-get widget :children))))
616 (unless (get symbol 'factory-face)
617 (error "No factory default for this face"))
618 (when (get symbol 'saved-face)
619 (put symbol 'saved-face nil))
620 (widget-value-set child (get symbol 'factory-face))))
622 ;;; The `face' Widget.
624 (define-widget 'face 'default
625 "Select and customize a face."
626 :convert-widget 'widget-item-convert-widget
629 :value-create 'widget-face-value-create
630 :value-delete 'widget-radio-value-delete
631 :value-get 'widget-item-value-get
632 :validate 'widget-editable-list-validate
633 :action 'widget-face-action
634 :match '(lambda (widget value) (symbolp value)))
636 (defun widget-face-value-create (widget)
637 ;; Create a `custom-face' child.
638 (let* ((symbol (widget-value widget))
639 (child (widget-create-child-and-convert
644 (custom-magic-reset child)
645 (widget-put widget :children (list child))))
647 (defvar face-history nil
648 "History of entered face names.")
650 (defun widget-face-action (widget &optional event)
652 (let ((answer (completing-read "Face: "
653 (mapcar (lambda (face)
654 (list (symbol-name face)))
658 (unless (zerop (length answer))
659 (widget-value-set widget (intern answer))
662 ;;; The `custom-group' Widget.
664 (define-widget 'custom-group 'custom
666 :format "%l%[%t%]:\n%m %h%v"
667 :documentation-property 'group-documentation
668 :help-echo "Push me to set or reset all members of this group."
669 :value-create 'custom-group-value-create
670 :action 'custom-group-action
671 :custom-apply 'custom-group-apply
672 :custom-set-default 'custom-group-set-default
673 :custom-reset 'custom-group-reset)
675 (defun custom-group-value-create (widget)
676 (let* ((state (widget-get widget :custom-state))
677 (level (widget-get widget :custom-level))
678 (symbol (widget-value widget))
679 (members (get symbol 'custom-group)))
680 (unless (eq state 'hidden)
681 (let* ((children (mapcar (lambda (entry)
684 (widget-create-child-and-convert
687 :custom-level (1+ level)
688 :value (nth 0 entry))
689 (unless (eq (preceding-char) ?\n)
690 (widget-insert "\n"))))
692 (mapcar 'custom-magic-reset children)
693 (widget-put widget :children children)
694 (custom-group-state-update widget)))))
696 (defvar custom-group-menu
697 '(("Apply" . custom-group-apply)
698 ("Set Default" . custom-group-set-default)
699 ("Reset" . custom-group-reset))
700 "Alist of actions for the `custom-group' widget.
701 The key is a string containing the name of the action, the value is a
702 lisp function taking the widget as an element which will be called
703 when the action is chosen.")
705 (defun custom-group-action (widget &optional event)
706 "Show the menu for `custom-group' WIDGET.
707 Optional EVENT is the location for the menu."
708 (let* ((completion-ignore-case t)
709 (answer (widget-choose (symbol-name (widget-get widget :value))
713 (funcall answer widget))))
715 (defun custom-group-apply (widget)
716 "Apply changes in all modified group members."
717 (let ((children (widget-get widget :children)))
718 (mapcar (lambda (child)
719 (when (eq (widget-get child :custom-state) 'modified)
720 (widget-apply child :custom-apply)))
723 (defun custom-group-set-default (widget)
724 "Set default in all modified group members."
725 (let ((children (widget-get widget :children)))
726 (mapcar (lambda (child)
727 (when (eq (widget-get child :custom-state) 'modified)
728 (widget-apply child :custom-set-default)))
731 (defun custom-group-reset (widget)
732 "Reset all modified group members."
733 (let ((children (widget-get widget :children)))
734 (mapcar (lambda (child)
735 (when (eq (widget-get child :custom-state) 'modified)
736 (widget-apply child :custom-reset)))
739 (defun custom-group-state-update (widget)
741 (unless (eq (widget-get widget :custom-state) 'hidden)
742 (let* ((children (widget-get widget :children))
743 (states (mapcar (lambda (child)
744 (widget-get child :custom-state))
746 (magics custom-magic-alist)
749 (let ((magic (car (car magics))))
750 (if (and (not (eq magic 'hidden))
754 (setq magics (cdr magics)))))
755 (widget-put widget :custom-state found)))
756 (custom-magic-reset widget))
758 ;;; The `custom-save' Command.
760 (defcustom custom-file "~/.emacs"
761 "File used for storing customization information.
762 If you change this from the default \"~/.emacs\" you need to
763 explicitly load that file for the settings to take effect."
767 (defun custom-save-delete (symbol)
768 "Delete the call to SYMBOL form `custom-file'.
769 Leave point at the location of the call, or after the last expression."
770 (set-buffer (find-file-noselect custom-file))
771 (goto-char (point-min))
774 (let ((sexp (condition-case nil
775 (read (current-buffer))
776 (end-of-file (throw 'found nil)))))
777 (when (and (listp sexp)
778 (eq (car sexp) symbol))
779 (delete-region (save-excursion
783 (throw 'found nil))))))
785 (defun custom-save-variables ()
786 "Save all customized variables in `custom-file'."
788 (custom-save-delete 'custom-set-variables)
789 (let ((standard-output (current-buffer)))
792 (princ "(custom-set-variables")
793 (mapatoms (lambda (symbol)
794 (let ((value (get symbol 'saved-value)))
799 (prin1 (car value))))))
804 (defun custom-save-faces ()
805 "Save all customized faces in `custom-file'."
807 (custom-save-delete 'custom-set-faces)
808 (let ((standard-output (current-buffer)))
811 (princ "(custom-set-faces")
812 (mapatoms (lambda (symbol)
813 (let ((value (get symbol 'saved-face)))
823 (defun custom-save ()
824 "Save all customizations in `custom-file'."
826 (custom-save-variables)
829 (set-buffer (find-file-noselect custom-file))
834 (defvar custom-options nil
835 "Customization widgets in the current buffer.")
837 (defvar custom-mode-map nil
838 "Keymap for `custom-mode'.")
840 (unless custom-mode-map
841 (setq custom-mode-map (make-sparse-keymap))
842 (set-keymap-parent custom-mode-map widget-keymap))
844 (easy-menu-define custom-mode-menu
846 "Menu used in customization buffers."
848 ["Apply" custom-apply t]
849 ["Set Default" custom-set-default t]
850 ["Reset" custom-reset t]
851 ["Save" custom-save t]))
853 (defun custom-mode ()
854 "Major mode for editing customization buffers.
856 The following commands are available:
858 \\[widget-forward] Move to next button or editable field.
859 \\[widget-backward] Move to previous button or editable field.
860 \\[widget-button-click] Activate button under the mouse pointer.
861 \\[widget-button-press] Activate button under point.
862 \\[custom-apply] Apply all modifications.
863 \\[custom-set-default] Make all modifications default.
864 \\[custom-reset] Undo all modifications.
865 \\[custom-save] Save defaults for future emacs sessions.
867 Entry to this mode calls the value of `custom-mode-hook'
868 if that value is non-nil."
869 (kill-all-local-variables)
870 (setq major-mode 'custom-mode
872 (use-local-map custom-mode-map)
873 (make-local-variable 'custom-options)
874 (run-hooks 'custom-mode-hook))
876 ;;; Custom Mode Commands.
878 (defun custom-apply ()
879 "Apply changes in all modified options."
881 (let ((children custom-options))
882 (mapcar (lambda (child)
883 (when (eq (widget-get child :custom-state) 'modified)
884 (widget-apply child :custom-apply)))
887 (defun custom-set-default ()
888 "Set default in all modified group members."
890 (let ((children custom-options))
891 (mapcar (lambda (child)
892 (when (eq (widget-get child :custom-state) 'modified)
893 (widget-apply child :custom-set-default)))
896 (defun custom-reset ()
897 "Reset all modified group members."
899 (let ((children custom-options))
900 (mapcar (lambda (child)
901 (when (eq (widget-get child :custom-state) 'modified)
902 (widget-apply child :custom-reset)))
905 ;;; The Customize Commands
908 (defun customize (symbol)
909 "Customize SYMBOL, which must be a customization group."
910 (interactive (list (completing-read "Customize group: (default emacs) "
913 (get symbol 'custom-group))
916 (when (stringp symbol)
917 (if (string-equal "" symbol)
919 (setq symbol (intern symbol))))
920 (custom-buffer-create (list (list symbol 'custom-group))))
923 (defun customize-variable (symbol)
924 "Customize SYMBOL, which must be a variable."
926 ;; Code stolen from `help.el'.
927 (let ((v (variable-at-point))
928 (enable-recursive-minibuffers t)
930 (setq val (completing-read
932 (format "Customize variable (default %s): " v)
933 "Customize variable: ")
935 (list (if (equal val "")
937 (custom-buffer-create (list (list symbol 'custom-variable))))
940 (defun customize-face (symbol)
942 (interactive (list (completing-read "Customize face: " obarray 'facep)))
943 (unless (symbolp symbol)
944 (error "Should be a symbol %S" symbol))
945 (custom-buffer-create (list (list symbol 'custom-face))))
948 (defun customize-apropos (regexp &optional all)
949 "Customize all user options matching REGEXP.
950 If ALL (e.g., started with a prefix key), include options which are not
952 (interactive "sCustomize regexp: \nP")
954 (mapatoms (lambda (symbol)
955 (when (string-match regexp (symbol-name symbol))
956 (when (get symbol 'custom-group)
957 (setq found (cons (list symbol 'custom-group) found)))
959 (setq found (cons (list symbol 'custom-face) found)))
960 (when (and (boundp symbol)
961 (or (get symbol 'default-value)
962 (get symbol 'factory-value)
964 (get symbol 'variable-documentation)
965 (user-variable-p symbol))))
967 (cons (list symbol 'custom-variable) found))))))
969 (custom-buffer-create found)
970 (error "No matches"))))
972 (defun custom-buffer-create (options)
973 "Create a buffer containing OPTIONS.
974 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
975 SYMBOL is a customization option, and WIDGET is a widget for editing
977 (kill-buffer (get-buffer-create "*Customization*"))
978 (switch-to-buffer (get-buffer-create "*Customization*"))
980 (widget-insert "This is a customization buffer.
981 Push RET or click mouse-2 on the word ")
982 (widget-create 'info-link
984 :help-echo "Push me for help."
985 "(custom)The Customization Buffer")
986 (widget-insert " for more information.\n\n")
988 (mapcar (lambda (entry)
990 (widget-create (nth 1 entry)
991 :value (nth 0 entry))
992 (unless (eq (preceding-char) ?\n)
993 (widget-insert "\n"))
994 (widget-insert "\n")))
996 (widget-create 'push-button
998 :help-echo "Push me to apply all modifications."
999 :action (lambda (widget &optional event)
1002 (widget-create 'push-button
1004 :help-echo "Push me to make the modifications default."
1005 :action (lambda (widget &optional event)
1006 (custom-set-default)))
1008 (widget-create 'push-button
1010 :help-echo "Push me to undo all modifications.."
1011 :action (lambda (widget &optional event)
1014 (widget-create 'push-button
1016 :help-echo "Push me to store the new defaults permanently."
1017 :action (lambda (widget &optional event)
1019 (widget-insert "\n")
1024 (provide 'custom-edit)
1026 ;; custom-edit.el ends here