1 ;;; cus-edit.el --- Tools for customization Emacs.
3 ;; Copyright (C) 1996, 1997 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/
20 (define-widget-keywords :custom-prefixes :custom-menu :custom-show
21 :custom-magic :custom-state :custom-level :custom-form
22 :custom-set :custom-save :custom-reset-current :custom-reset-saved
23 :custom-reset-factory)
25 ;;; Customization Groups.
28 "Customization of the One True Editor."
29 :link '(custom-manual "(emacs)Top"))
31 ;; Most of these groups are stolen from `finder.el',
33 "Basic text editing facilities."
37 "Abbreviation handling, typing shortcuts, macros."
41 (defgroup matching nil
42 "Various sorts of searching and matching."
45 (defgroup emulations nil
46 "Emulations of other editors."
53 (defgroup outlines nil
54 "Support for hierarchical outlining."
57 (defgroup external nil
58 "Interfacing to external utilities."
62 "Code related to the `bib' bibliography processor."
66 (defgroup processes nil
67 "Process, subshell, compilation, and job control support."
71 (defgroup programming nil
72 "Support for programming in other languages."
75 (defgroup languages nil
76 "Specialized modes for editing programming languages."
80 "Lisp support, including Emacs Lisp."
85 "Support for the C language and related languages."
93 "Support for object-oriented programming."
96 (defgroup applications nil
97 "Applications written in Emacs."
100 (defgroup calendar nil
101 "Calendar and time management support."
102 :group 'applications)
105 "Modes for electronic-mail handling."
106 :group 'applications)
109 "Support for netnews reading and posting."
110 :group 'applications)
113 "Games, jokes and amusements."
114 :group 'applications)
116 (defgroup development nil
117 "Support for further development of Emacs."
121 "Support for Emacs documentation."
124 (defgroup extensions nil
125 "Emacs Lisp language extensions."
128 (defgroup internal nil
129 "Code for Emacs internals, build process, defaults."
133 "Maintenance aids for the Emacs development group."
137 (defgroup environment nil
138 "Fitting Emacs with its environment."
142 "Communications, networking, remote access to files."
146 (defgroup hardware nil
147 "Support for interfacing with exotic hardware."
150 (defgroup terminals nil
151 "Support for terminal types."
155 "Front-ends/assistants for, or emulators of, UNIX features."
159 "Support code for vms."
163 "Internationalization and alternate character-set support."
168 "Support for Emacs frames and window systems."
172 "Support editing files of data."
180 "Code related to the TeX formatter."
184 "Support for multiple fonts."
187 (defgroup hypermedia nil
188 "Support for links between text or other media types."
192 "Support for on-line help systems."
196 "Code local to your site."
199 (defgroup customize '((widgets custom-group))
200 "Customization of the Customization support."
201 :link '(custom-manual "(custom)Top")
202 :link '(url-link :tag "Development Page"
203 "http://www.dina.kvl.dk/~abraham/custom/")
210 (defun custom-quote (sexp)
211 "Quote SEXP iff it is not self quoting."
212 (if (or (memq sexp '(t nil))
214 (eq (aref (symbol-name sexp) 0) ?:))
216 (memq (car sexp) '(lambda)))
219 (and (fboundp 'characterp)
224 (defun custom-split-regexp-maybe (regexp)
225 "If REGEXP is a string, split it to a list at `\\|'.
226 You can get the original back with from the result with:
227 (mapconcat 'identity result \"\\|\")
229 IF REGEXP is not a string, return it unchanged."
233 (while (string-match "\\\\|" regexp start)
234 (setq all (cons (substring regexp start (match-beginning 0)) all)
235 start (match-end 0)))
236 (nreverse (cons (substring regexp start) all)))
239 (defvar custom-prefix-list nil
240 "List of prefixes that should be ignored by `custom-unlispify'")
242 (defcustom custom-unlispify-menu-entries t
243 "Display menu entries as words instead of symbols if non nil."
247 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
248 "Convert symbol into a menu entry."
249 (cond ((not custom-unlispify-menu-entries)
250 (symbol-name symbol))
251 ((get symbol 'custom-tag)
253 (get symbol 'custom-tag)
254 (concat (get symbol 'custom-tag) "...")))
257 (set-buffer (get-buffer-create " *Custom-Work*"))
259 (princ symbol (current-buffer))
260 (goto-char (point-min))
261 (let ((prefixes custom-prefix-list)
264 (setq prefix (car prefixes))
265 (if (search-forward prefix (+ (point) (length prefix)) t)
268 (delete-region (point-min) (point)))
269 (setq prefixes (cdr prefixes)))))
270 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
271 (capitalize-region (point-min) (point-max))
273 (goto-char (point-max))
277 (defcustom custom-unlispify-tag-names t
278 "Display tag names as words instead of symbols if non nil."
282 (defun custom-unlispify-tag-name (symbol)
283 "Convert symbol into a menu entry."
284 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
285 (custom-unlispify-menu-entry symbol t)))
287 (defun custom-prefix-add (symbol prefixes)
288 ;; Addd SYMBOL to list of ignored PREFIXES.
289 (cons (or (get symbol 'custom-prefix)
290 (concat (symbol-name symbol) "-"))
295 (defvar custom-options nil
296 "Customization widgets in the current buffer.")
298 (defvar custom-mode-map nil
299 "Keymap for `custom-mode'.")
301 (unless custom-mode-map
302 (setq custom-mode-map (make-sparse-keymap))
303 (set-keymap-parent custom-mode-map widget-keymap)
304 (define-key custom-mode-map "q" 'bury-buffer))
306 (easy-menu-define custom-mode-menu
308 "Menu used in customization buffers."
311 ["Save" custom-save t]
312 ["Reset to Current" custom-reset-current t]
313 ["Reset to Saved" custom-reset-saved t]
314 ["Reset to Factory Settings" custom-reset-factory t]
315 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
317 (defcustom custom-mode-hook nil
318 "Hook called when entering custom-mode."
322 (defun custom-mode ()
323 "Major mode for editing customization buffers.
325 The following commands are available:
327 \\[widget-forward] Move to next button or editable field.
328 \\[widget-backward] Move to previous button or editable field.
329 \\[widget-button-click] Activate button under the mouse pointer.
330 \\[widget-button-press] Activate button under point.
331 \\[custom-set] Set all modifications.
332 \\[custom-save] Make all modifications default.
333 \\[custom-reset-current] Reset all modified options.
334 \\[custom-reset-saved] Reset all modified or set options.
335 \\[custom-reset-factory] Reset all options.
337 Entry to this mode calls the value of `custom-mode-hook'
338 if that value is non-nil."
339 (kill-all-local-variables)
340 (setq major-mode 'custom-mode
342 (use-local-map custom-mode-map)
343 (easy-menu-add custom-mode-menu)
344 (make-local-variable 'custom-options)
345 (run-hooks 'custom-mode-hook))
347 ;;; Custom Mode Commands.
350 "Set changes in all modified options."
352 (let ((children custom-options))
353 (mapcar (lambda (child)
354 (when (eq (widget-get child :custom-state) 'modified)
355 (widget-apply child :custom-set)))
358 (defun custom-save ()
359 "Set all modified group members and save them."
361 (let ((children custom-options))
362 (mapcar (lambda (child)
363 (when (memq (widget-get child :custom-state) '(modified set))
364 (widget-apply child :custom-save)))
368 (defvar custom-reset-menu
369 '(("Current" . custom-reset-current)
370 ("Saved" . custom-reset-saved)
371 ("Factory Settings" . custom-reset-factory))
372 "Alist of actions for the `Reset' button.
373 The key is a string containing the name of the action, the value is a
374 lisp function taking the widget as an element which will be called
375 when the action is chosen.")
377 (defun custom-reset (event)
378 "Select item from reset menu."
379 (let* ((completion-ignore-case t)
380 (answer (widget-choose "Reset to"
386 (defun custom-reset-current ()
387 "Reset all modified group members to their current value."
389 (let ((children custom-options))
390 (mapcar (lambda (child)
391 (when (eq (widget-get child :custom-state) 'modified)
392 (widget-apply child :custom-reset-current)))
395 (defun custom-reset-saved ()
396 "Reset all modified or set group members to their saved value."
398 (let ((children custom-options))
399 (mapcar (lambda (child)
400 (when (eq (widget-get child :custom-state) 'modified)
401 (widget-apply child :custom-reset-current)))
404 (defun custom-reset-factory ()
405 "Reset all modified, set, or saved group members to their factory settings."
407 (let ((children custom-options))
408 (mapcar (lambda (child)
409 (when (eq (widget-get child :custom-state) 'modified)
410 (widget-apply child :custom-reset-current)))
413 ;;; The Customize Commands
416 (defun customize (symbol)
417 "Customize SYMBOL, which must be a customization group."
418 (interactive (list (completing-read "Customize group: (default emacs) "
421 (get symbol 'custom-group))
424 (when (stringp symbol)
425 (if (string-equal "" symbol)
427 (setq symbol (intern symbol))))
428 (custom-buffer-create (list (list symbol 'custom-group))))
431 (defun customize-variable (symbol)
432 "Customize SYMBOL, which must be a variable."
434 ;; Code stolen from `help.el'.
435 (let ((v (variable-at-point))
436 (enable-recursive-minibuffers t)
438 (setq val (completing-read
440 (format "Customize variable (default %s): " v)
441 "Customize variable: ")
443 (list (if (equal val "")
445 (custom-buffer-create (list (list symbol 'custom-variable))))
448 (defun customize-face (&optional symbol)
449 "Customize SYMBOL, which should be a face name or nil.
450 If SYMBOL is nil, customize all faces."
451 (interactive (list (completing-read "Customize face: (default all) "
452 obarray 'custom-facep)))
453 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
455 (message "Looking for faces...")
456 (mapcar (lambda (symbol)
457 (setq found (cons (list symbol 'custom-face) found)))
459 (message "Creating customization buffer...")
460 (custom-buffer-create found))
462 (setq symbol (intern symbol)))
463 (unless (symbolp symbol)
464 (error "Should be a symbol %S" symbol))
465 (custom-buffer-create (list (list symbol 'custom-face)))))
468 (defun customize-customized ()
469 "Customize all already customized user options."
472 (mapatoms (lambda (symbol)
473 (and (get symbol 'saved-face)
474 (custom-facep symbol)
475 (setq found (cons (list symbol 'custom-face) found)))
476 (and (get symbol 'saved-value)
479 (cons (list symbol 'custom-variable) found)))))
481 (custom-buffer-create found)
482 (error "No customized user options"))))
485 (defun customize-apropos (regexp &optional all)
486 "Customize all user options matching REGEXP.
487 If ALL (e.g., started with a prefix key), include options which are not
489 (interactive "sCustomize regexp: \nP")
491 (mapatoms (lambda (symbol)
492 (when (string-match regexp (symbol-name symbol))
493 (when (get symbol 'custom-group)
494 (setq found (cons (list symbol 'custom-group) found)))
495 (when (custom-facep symbol)
496 (setq found (cons (list symbol 'custom-face) found)))
497 (when (and (boundp symbol)
498 (or (get symbol 'saved-value)
499 (get symbol 'factory-value)
501 (get symbol 'variable-documentation)
502 (user-variable-p symbol))))
504 (cons (list symbol 'custom-variable) found))))))
506 (custom-buffer-create found)
507 (error "No matches"))))
510 (defun custom-buffer-create (options)
511 "Create a buffer containing OPTIONS.
512 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
513 SYMBOL is a customization option, and WIDGET is a widget for editing
515 (kill-buffer (get-buffer-create "*Customization*"))
516 (switch-to-buffer (get-buffer-create "*Customization*"))
518 (widget-insert "This is a customization buffer.
519 Push RET or click mouse-2 on the word ")
520 (widget-create 'info-link
522 :help-echo "Push me for help."
523 "(custom)The Customization Buffer")
524 (widget-insert " for more information.\n\n")
526 (mapcar (lambda (entry)
528 (if (> (length options) 1)
529 (widget-create (nth 1 entry)
530 :tag (custom-unlispify-tag-name
532 :value (nth 0 entry))
533 ;; If there is only one entry, don't hide it!
534 (widget-create (nth 1 entry)
535 :custom-state 'unknown
536 :tag (custom-unlispify-tag-name
538 :value (nth 0 entry)))
539 (unless (eq (preceding-char) ?\n)
540 (widget-insert "\n"))
541 (widget-insert "\n")))
543 (mapcar 'custom-magic-reset custom-options)
544 (widget-create 'push-button
546 :help-echo "Push me to set all modifications."
547 :action (lambda (widget &optional event)
550 (widget-create 'push-button
552 :help-echo "Push me to make the modifications default."
553 :action (lambda (widget &optional event)
556 (widget-create 'push-button
558 :help-echo "Push me to undo all modifications."
559 :action (lambda (widget &optional event)
560 (custom-reset event)))
562 (widget-create 'push-button
564 :help-echo "Push me to bury the buffer."
565 :action (lambda (widget &optional event)
567 ;; Steal button release event.
568 (if (and (fboundp 'button-press-event-p)
569 (fboundp 'next-command-event))
572 (button-press-event-p event)
573 (next-command-event))
575 (when (memq 'down (event-modifiers event))
580 ;;; Modification of Basic Widgets.
582 ;; We add extra properties to the basic widgets needed here. This is
583 ;; fine, as long as we are careful to stay within out own namespace.
585 ;; We want simple widgets to be displayed by default, but complex
586 ;; widgets to be hidden.
588 (widget-put (get 'item 'widget-type) :custom-show t)
589 (widget-put (get 'editable-field 'widget-type)
590 :custom-show (lambda (widget value)
591 (let ((pp (pp-to-string value)))
592 (cond ((string-match "\n" pp)
597 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
599 ;;; The `custom-manual' Widget.
601 (define-widget 'custom-manual 'info-link
602 "Link to the manual entry for this customization option."
603 :help-echo "Push me to read the manual."
606 ;;; The `custom-magic' Widget.
608 (defface custom-invalid-face '((((class color))
609 (:foreground "yellow" :background "red"))
611 (:bold t :italic t :underline t)))
612 "Face used when the customize item is invalid.")
614 (defface custom-rogue-face '((((class color))
615 (:foreground "pink" :background "black"))
618 "Face used when the customize item is not defined for customization.")
620 (defface custom-modified-face '((((class color))
621 (:foreground "white" :background "blue"))
624 "Face used when the customize item has been modified.")
626 (defface custom-set-face '((((class color))
627 (:foreground "blue" :background "white"))
630 "Face used when the customize item has been set.")
632 (defface custom-changed-face '((((class color))
633 (:foreground "white" :background "blue"))
636 "Face used when the customize item has been changed.")
638 (defface custom-saved-face '((t (:underline t)))
639 "Face used when the customize item has been saved.")
641 (defcustom custom-magic-alist '((nil "#" underline "\
642 uninitialized, you should not see this.")
643 (unknown "?" italic "\
644 unknown, you should not see this.")
645 (hidden "-" default "\
646 hidden, press the state button to show.")
647 (invalid "x" custom-invalid-face "\
648 the value displayed for this item is invalid and cannot be set.")
649 (modified "*" custom-modified-face "\
650 you have edited the item, and can now set it.")
651 (set "+" custom-set-face "\
652 you have set this item, but not saved it.")
653 (changed ":" custom-changed-face "\
654 this item has been changed outside customize.")
655 (saved "!" custom-saved-face "\
656 this item has been saved.")
657 (rogue "@" custom-rogue-face "\
658 this item is not prepared for customization.")
660 this item is unchanged from its factory setting."))
661 "Alist of customize option states.
662 Each entry is of the form (STATE MAGIC FACE DESCRIPTION), where
664 STATE is one of the following symbols:
667 For internal use, should never occur.
669 For internal use, should never occur.
671 This item is not being displayed.
673 This item is modified, but has an invalid form.
675 This item is modified, and has a valid form.
677 This item has been set but not saved.
679 The current value of this item has been changed temporarily.
681 This item is marked for saving.
683 This item has no customization information.
685 This item is unchanged from the factory default.
687 MAGIC is a string used to present that state.
689 FACE is a face used to present the state.
691 DESCRIPTION is a string describing the state.
693 The list should be sorted most significant first."
694 :type '(list (checklist :inline t
696 (string :tag "Magic")
698 (string :tag "Description"))
699 (group (const unknown)
700 (string :tag "Magic")
702 (string :tag "Description"))
703 (group (const hidden)
704 (string :tag "Magic")
706 (string :tag "Description"))
707 (group (const invalid)
708 (string :tag "Magic")
710 (string :tag "Description"))
711 (group (const modified)
712 (string :tag "Magic")
714 (string :tag "Description"))
716 (string :tag "Magic")
718 (string :tag "Description"))
719 (group (const changed)
720 (string :tag "Magic")
722 (string :tag "Description"))
724 (string :tag "Magic")
726 (string :tag "Description"))
728 (string :tag "Magic")
730 (string :tag "Description"))
731 (group (const factory)
732 (string :tag "Magic")
734 (string :tag "Description")))
735 (editable-list :inline t
737 (string :tag "Magic")
739 (string :tag "Description"))))
742 (defcustom custom-magic-show 'long
743 "Show long description of the state of each customization option."
744 :type '(choice (const :tag "no" nil)
749 (defcustom custom-magic-show-button t
750 "Show a magic button indicating the state of each customization option."
754 (define-widget 'custom-magic 'default
755 "Show and manipulate state for a customization option."
757 :action 'widget-choice-item-action
759 :value-create 'custom-magic-value-create
760 :value-delete 'widget-children-value-delete)
762 (defun custom-magic-value-create (widget)
763 ;; Create compact status report for WIDGET.
764 (let* ((parent (widget-get widget :parent))
765 (state (widget-get parent :custom-state))
766 (entry (assq state custom-magic-alist))
767 (magic (nth 1 entry))
770 (lisp (eq (widget-get parent :custom-form) 'lisp))
772 (when custom-magic-show
773 (push (widget-create-child-and-convert widget 'choice-item
775 Push me to change the state of this item."
780 (if (eq custom-magic-show 'long)
782 (insert (symbol-name state)))
786 (when custom-magic-show-button
787 (when custom-magic-show
788 (let ((indent (widget-get parent :indent)))
790 (insert-char ? indent))))
791 (push (widget-create-child-and-convert widget 'choice-item
794 Push me to change the state."
797 (concat "(" magic ")")
798 (concat "[" magic "]")))
801 (widget-put widget :children children)))
803 (defun custom-magic-reset (widget)
804 "Redraw the :custom-magic property of WIDGET."
805 (let ((magic (widget-get widget :custom-magic)))
806 (widget-value-set magic (widget-value magic))))
808 ;;; The `custom-level' Widget.
810 (define-widget 'custom-level 'item
811 "The custom level buttons."
813 :help-echo "Push me to expand or collapse this item."
814 :action 'custom-level-action)
816 (defun custom-level-action (widget &optional event)
817 "Toggle visibility for parent to WIDGET."
818 (let* ((parent (widget-get widget :parent))
819 (state (widget-get parent :custom-state)))
820 (cond ((memq state '(invalid modified))
821 (error "There are unset changes"))
823 (widget-put parent :custom-state 'unknown))
825 (widget-put parent :custom-state 'hidden)))
826 (custom-redraw parent)))
828 ;;; The `custom' Widget.
830 (define-widget 'custom 'default
831 "Customize a user option."
832 :convert-widget 'custom-convert-widget
833 :format "%l%[%t%]: %v%m%h%a"
834 :format-handler 'custom-format-handler
835 :notify 'custom-notify
837 :custom-state 'hidden
838 :documentation-property 'widget-subclass-responsibility
839 :value-create 'widget-subclass-responsibility
840 :value-delete 'widget-children-value-delete
841 :value-get 'widget-item-value-get
842 :validate 'widget-editable-list-validate
843 :match (lambda (widget value) (symbolp value)))
845 (defun custom-convert-widget (widget)
846 ;; Initialize :value and :tag from :args in WIDGET.
847 (let ((args (widget-get widget :args)))
849 (widget-put widget :value (widget-apply widget
850 :value-to-internal (car args)))
851 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
852 (widget-put widget :args nil)))
855 (defun custom-format-handler (widget escape)
856 ;; We recognize extra escape sequences.
857 (let* ((buttons (widget-get widget :buttons))
858 (state (widget-get widget :custom-state))
859 (level (widget-get widget :custom-level)))
860 (cond ((eq escape ?l)
862 (push (widget-create-child-and-convert
863 widget 'custom-level (make-string level ?*))
866 (widget-put widget :buttons buttons)))
868 (when (eq state 'hidden)
869 (widget-insert " ...")))
871 (and (eq (preceding-char) ?\n)
872 (widget-get widget :indent)
873 (insert-char ? (widget-get widget :indent)))
874 (let ((magic (widget-create-child-and-convert
875 widget 'custom-magic nil)))
876 (widget-put widget :custom-magic magic)
878 (widget-put widget :buttons buttons)))
880 (let* ((symbol (widget-get widget :value))
881 (links (get symbol 'custom-links))
882 (many (> (length links) 2)))
884 (and (eq (preceding-char) ?\n)
885 (widget-get widget :indent)
886 (insert-char ? (widget-get widget :indent)))
889 (push (widget-create-child-and-convert widget (car links))
891 (setq links (cdr links))
900 (widget-put widget :buttons buttons))))
902 (widget-default-format-handler widget escape)))))
904 (defun custom-notify (widget &rest args)
905 "Keep track of changes."
906 (widget-put widget :custom-state 'modified)
907 (let ((buffer-undo-list t))
908 (custom-magic-reset widget))
909 (apply 'widget-default-notify widget args))
911 (defun custom-redraw (widget)
912 "Redraw WIDGET with current settings."
914 (from (marker-position (widget-get widget :from)))
915 (to (marker-position (widget-get widget :to))))
917 (widget-value-set widget (widget-value widget))
918 (custom-redraw-magic widget))
919 (when (and (>= pos from) (<= pos to))
922 (defun custom-redraw-magic (widget)
923 "Redraw WIDGET state with current settings."
925 (let ((magic (widget-get widget :custom-magic)))
928 (widget-value-set magic (widget-value magic))
929 (when (setq widget (widget-get widget :group))
930 (custom-group-state-update widget))))
933 (defun custom-show (widget value)
934 "Non-nil if WIDGET should be shown with VALUE by default."
935 (let ((show (widget-get widget :custom-show)))
941 (funcall show widget value)))))
943 (defun custom-load-symbol (symbol)
944 "Load all dependencies for SYMBOL."
945 (let ((loads (get symbol 'custom-loads))
948 (setq load (car loads)
950 (cond ((symbolp load)
954 ((assoc load load-history))
960 (defun custom-load-widget (widget)
961 "Load all dependencies for WIDGET."
962 (custom-load-symbol (widget-value widget)))
964 ;;; The `custom-variable' Widget.
966 (defface custom-variable-sample-face '((t (:underline t)))
967 "Face used for unpushable variable tags."
970 (defface custom-variable-button-face '((t (:underline t :bold t)))
971 "Face used for pushable variable tags."
974 (define-widget 'custom-variable 'custom
975 "Customize variable."
977 :help-echo "Push me to set or reset this variable."
978 :documentation-property 'variable-documentation
980 :custom-menu 'custom-variable-menu-create
982 :value-create 'custom-variable-value-create
983 :action 'custom-variable-action
984 :custom-set 'custom-variable-set
985 :custom-save 'custom-variable-save
986 :custom-reset-current 'custom-redraw
987 :custom-reset-saved 'custom-variable-reset-saved
988 :custom-reset-factory 'custom-variable-reset-factory)
990 (defun custom-variable-value-create (widget)
991 "Here is where you edit the variables value."
992 (custom-load-widget widget)
993 (let* ((buttons (widget-get widget :buttons))
994 (children (widget-get widget :children))
995 (form (widget-get widget :custom-form))
996 (state (widget-get widget :custom-state))
997 (symbol (widget-get widget :value))
998 (options (get symbol 'custom-options))
999 (child-type (or (get symbol 'custom-type) 'sexp))
1000 (tag (widget-get widget :tag))
1001 (type (let ((tmp (if (listp child-type)
1002 (copy-list child-type)
1003 (list child-type))))
1005 (widget-put tmp :options options))
1007 (conv (widget-convert type))
1008 (value (if (default-boundp symbol)
1009 (default-value symbol)
1010 (widget-get conv :value))))
1011 ;; If the widget is new, the child determine whether it is hidden.
1013 ((custom-show type value)
1014 (setq state 'unknown))
1016 (setq state 'hidden)))
1017 ;; If we don't know the state, see if we need to edit it in lisp form.
1018 (when (eq state 'unknown)
1019 (unless (widget-apply conv :match value)
1020 ;; (widget-apply (widget-convert type) :match value)
1022 ;; Now we can create the child widget.
1023 (cond ((eq state 'hidden)
1024 ;; Indicate hidden value.
1025 (push (widget-create-child-and-convert
1027 :format "%{%t%}: ..."
1028 :sample-face 'custom-variable-sample-face
1033 ;; In lisp mode edit the saved value when possible.
1034 (let* ((value (cond ((get symbol 'saved-value)
1035 (car (get symbol 'saved-value)))
1036 ((get symbol 'factory-value)
1037 (car (get symbol 'factory-value)))
1038 ((default-boundp symbol)
1039 (custom-quote (default-value symbol)))
1041 (custom-quote (widget-get conv :value))))))
1042 (push (widget-create-child-and-convert
1044 :button-face 'custom-variable-button-face
1045 :tag (symbol-name symbol)
1051 (push (widget-create-child-and-convert
1054 :button-face 'custom-variable-button-face
1055 :sample-face 'custom-variable-sample-face
1058 ;; Now update the state.
1059 (unless (eq (preceding-char) ?\n)
1060 (widget-insert "\n"))
1061 (if (eq state 'hidden)
1062 (widget-put widget :custom-state state)
1063 (custom-variable-state-set widget))
1064 (widget-put widget :custom-form form)
1065 (widget-put widget :buttons buttons)
1066 (widget-put widget :children children)))
1068 (defun custom-variable-state-set (widget)
1069 "Set the state of WIDGET."
1070 (let* ((symbol (widget-value widget))
1071 (value (if (default-boundp symbol)
1072 (default-value symbol)
1073 (widget-get widget :value)))
1075 (state (cond ((setq tmp (get symbol 'customized-value))
1076 (if (condition-case nil
1077 (equal value (eval (car tmp)))
1081 ((setq tmp (get symbol 'saved-value))
1082 (if (condition-case nil
1083 (equal value (eval (car tmp)))
1087 ((setq tmp (get symbol 'factory-value))
1088 (if (condition-case nil
1089 (equal value (eval (car tmp)))
1094 (widget-put widget :custom-state state)))
1096 (defvar custom-variable-menu
1097 '(("Edit" . custom-variable-edit)
1098 ("Edit Lisp" . custom-variable-edit-lisp)
1099 ("Set" . custom-variable-set)
1100 ("Save" . custom-variable-save)
1101 ("Reset to Current" . custom-redraw)
1102 ("Reset to Saved" . custom-variable-reset-saved)
1103 ("Reset to Factory Settings" . custom-variable-reset-factory))
1104 "Alist of actions for the `custom-variable' widget.
1105 The key is a string containing the name of the action, the value is a
1106 lisp function taking the widget as an element which will be called
1107 when the action is chosen.")
1109 (defun custom-variable-action (widget &optional event)
1110 "Show the menu for `custom-variable' WIDGET.
1111 Optional EVENT is the location for the menu."
1112 (if (eq (widget-get widget :custom-state) 'hidden)
1114 (widget-put widget :custom-state 'unknown)
1115 (custom-redraw widget))
1116 (let* ((completion-ignore-case t)
1117 (answer (widget-choose (custom-unlispify-tag-name
1118 (widget-get widget :value))
1119 custom-variable-menu
1122 (funcall answer widget)))))
1124 (defun custom-variable-edit (widget)
1125 "Edit value of WIDGET."
1126 (widget-put widget :custom-state 'unknown)
1127 (widget-put widget :custom-form 'edit)
1128 (custom-redraw widget))
1130 (defun custom-variable-edit-lisp (widget)
1131 "Edit the lisp representation of the value of WIDGET."
1132 (widget-put widget :custom-state 'unknown)
1133 (widget-put widget :custom-form 'lisp)
1134 (custom-redraw widget))
1136 (defun custom-variable-set (widget)
1137 "Set the current value for the variable being edited by WIDGET."
1138 (let ((form (widget-get widget :custom-form))
1139 (state (widget-get widget :custom-state))
1140 (child (car (widget-get widget :children)))
1141 (symbol (widget-value widget))
1143 (cond ((eq state 'hidden)
1144 (error "Cannot set hidden variable."))
1145 ((setq val (widget-apply child :validate))
1146 (goto-char (widget-get val :from))
1147 (error "%s" (widget-get val :error)))
1149 (set symbol (eval (setq val (widget-value child))))
1150 (put symbol 'customized-value (list val)))
1152 (set symbol (setq val (widget-value child)))
1153 (put symbol 'customized-value (list (custom-quote val)))))
1154 (custom-variable-state-set widget)
1155 (custom-redraw-magic widget)))
1157 (defun custom-variable-save (widget)
1158 "Set the default value for the variable being edited by WIDGET."
1159 (let ((form (widget-get widget :custom-form))
1160 (state (widget-get widget :custom-state))
1161 (child (car (widget-get widget :children)))
1162 (symbol (widget-value widget))
1164 (cond ((eq state 'hidden)
1165 (error "Cannot set hidden variable."))
1166 ((setq val (widget-apply child :validate))
1167 (goto-char (widget-get val :from))
1168 (error "%s" (widget-get val :error)))
1170 (put symbol 'saved-value (list (widget-value child)))
1171 (set symbol (eval (widget-value child))))
1174 'saved-value (list (custom-quote (widget-value
1176 (set symbol (widget-value child))))
1177 (put symbol 'customized-value nil)
1179 (custom-variable-state-set widget)
1180 (custom-redraw-magic widget)))
1182 (defun custom-variable-reset-saved (widget)
1183 "Restore the saved value for the variable being edited by WIDGET."
1184 (let ((symbol (widget-value widget)))
1185 (if (get symbol 'saved-value)
1187 (set symbol (eval (car (get symbol 'saved-value))))
1189 (error "No saved value for %s" symbol))
1190 (put symbol 'customized-value nil)
1191 (widget-put widget :custom-state 'unknown)
1192 (custom-redraw widget)))
1194 (defun custom-variable-reset-factory (widget)
1195 "Restore the factory setting for the variable being edited by WIDGET."
1196 (let ((symbol (widget-value widget)))
1197 (if (get symbol 'factory-value)
1198 (set symbol (eval (car (get symbol 'factory-value))))
1199 (error "No factory default for %S" symbol))
1200 (put symbol 'customized-value nil)
1201 (when (get symbol 'saved-value)
1202 (put symbol 'saved-value nil)
1204 (widget-put widget :custom-state 'unknown)
1205 (custom-redraw widget)))
1207 ;;; The `custom-face-edit' Widget.
1209 (defvar custom-face-edit-args
1210 (mapcar (lambda (att)
1213 (list 'const :format "" :value (nth 0 att))
1215 custom-face-attributes))
1217 (define-widget 'custom-face-edit 'checklist
1218 "Edit face attributes."
1222 :args (mapcar (lambda (att)
1225 (list 'const :format "" :value (nth 0 att))
1227 custom-face-attributes))
1229 ;;; The `custom-display' Widget.
1231 (define-widget 'custom-display 'menu-choice
1232 "Select a display type."
1235 :args '((const :tag "all" t)
1236 (checklist :offset 0
1238 :args ((group (const :format "Type: " type)
1239 (checklist :inline t
1243 (const :format "PM "
1245 (const :format "Win32 "
1247 (const :format "DOS "
1249 (const :format "TTY%n"
1251 (group (const :format "Class: " class)
1252 (checklist :inline t
1254 (const :format "Color "
1259 (const :format "Monochrome%n"
1261 (group (const :format "Background: " background)
1262 (checklist :inline t
1264 (const :format "Light "
1266 (const :format "Dark\n"
1269 ;;; The `custom-face' Widget.
1271 (defface custom-face-tag-face '((t (:underline t)))
1272 "Face used for face tags."
1275 (define-widget 'custom-face 'custom
1277 :format "%l%{%t%}: %s%m%h%a%v"
1278 :format-handler 'custom-face-format-handler
1279 :sample-face 'custom-face-tag-face
1280 :help-echo "Push me to set or reset this face."
1281 :documentation-property '(lambda (face)
1282 (face-doc-string face))
1283 :value-create 'custom-face-value-create
1284 :action 'custom-face-action
1285 :custom-set 'custom-face-set
1286 :custom-save 'custom-face-save
1287 :custom-reset-current 'custom-redraw
1288 :custom-reset-saved 'custom-face-reset-saved
1289 :custom-reset-factory 'custom-face-reset-factory
1290 :custom-menu 'custom-face-menu-create)
1292 (defun custom-face-format-handler (widget escape)
1293 ;; We recognize extra escape sequences.
1295 (symbol (widget-get widget :value)))
1296 (cond ((eq escape ?s)
1297 (and (string-match "XEmacs" emacs-version)
1298 ;; XEmacs cannot display initialized faces.
1299 (not (custom-facep symbol))
1300 (copy-face 'custom-face-empty symbol))
1301 (setq child (widget-create-child-and-convert
1303 :format "(%{%t%})\n"
1307 (custom-format-handler widget escape)))
1310 :buttons (cons child (widget-get widget :buttons))))))
1312 (defun custom-face-value-create (widget)
1313 ;; Create a list of the display specifications.
1314 (unless (eq (preceding-char) ?\n)
1316 (when (not (eq (widget-get widget :custom-state) 'hidden))
1317 (custom-load-widget widget)
1318 (let* ((symbol (widget-value widget))
1319 (edit (widget-create-child-and-convert
1320 widget 'editable-list
1321 :entry-format "%i %d %v"
1322 :value (or (get symbol 'saved-face)
1323 (get symbol 'factory-face))
1324 '(group :format "%v"
1325 custom-display custom-face-edit))))
1326 (custom-face-state-set widget)
1327 (widget-put widget :children (list edit)))))
1329 (defvar custom-face-menu
1330 '(("Set" . custom-face-set)
1331 ("Save" . custom-face-save)
1332 ("Reset to Saved" . custom-face-reset-saved)
1333 ("Reset to Factory Setting" . custom-face-reset-factory))
1334 "Alist of actions for the `custom-face' widget.
1335 The key is a string containing the name of the action, the value is a
1336 lisp function taking the widget as an element which will be called
1337 when the action is chosen.")
1339 (defun custom-face-state-set (widget)
1340 "Set the state of WIDGET."
1341 (let ((symbol (widget-value widget)))
1342 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
1344 ((get symbol 'saved-face)
1346 ((get symbol 'factory-face)
1351 (defun custom-face-action (widget &optional event)
1352 "Show the menu for `custom-face' WIDGET.
1353 Optional EVENT is the location for the menu."
1354 (if (eq (widget-get widget :custom-state) 'hidden)
1356 (widget-put widget :custom-state 'unknown)
1357 (custom-redraw widget))
1358 (let* ((completion-ignore-case t)
1359 (symbol (widget-get widget :value))
1360 (answer (widget-choose (custom-unlispify-tag-name symbol)
1361 custom-face-menu event)))
1363 (funcall answer widget)))))
1365 (defun custom-face-set (widget)
1366 "Make the face attributes in WIDGET take effect."
1367 (let* ((symbol (widget-value widget))
1368 (child (car (widget-get widget :children)))
1369 (value (widget-value child)))
1370 (put symbol 'customized-face value)
1371 (when (fboundp 'copy-face)
1372 (copy-face 'custom-face-empty symbol))
1373 (custom-face-display-set symbol value)
1374 (custom-face-state-set widget)
1375 (custom-redraw-magic widget)))
1377 (defun custom-face-save (widget)
1378 "Make the face attributes in WIDGET default."
1379 (let* ((symbol (widget-value widget))
1380 (child (car (widget-get widget :children)))
1381 (value (widget-value child)))
1382 (when (fboundp 'copy-face)
1383 (copy-face 'custom-face-empty symbol))
1384 (custom-face-display-set symbol value)
1385 (put symbol 'saved-face value)
1386 (put symbol 'customized-face nil)
1387 (custom-face-state-set widget)
1388 (custom-redraw-magic widget)))
1390 (defun custom-face-reset-saved (widget)
1391 "Restore WIDGET to the face's default attributes."
1392 (let* ((symbol (widget-value widget))
1393 (child (car (widget-get widget :children)))
1394 (value (get symbol 'saved-face)))
1396 (error "No saved value for this face"))
1397 (put symbol 'customized-face nil)
1398 (when (fboundp 'copy-face)
1399 (copy-face 'custom-face-empty symbol))
1400 (custom-face-display-set symbol value)
1401 (widget-value-set child value)
1402 (custom-face-state-set widget)
1403 (custom-redraw-magic widget)))
1405 (defun custom-face-reset-factory (widget)
1406 "Restore WIDGET to the face's factory settings."
1407 (let* ((symbol (widget-value widget))
1408 (child (car (widget-get widget :children)))
1409 (value (get symbol 'factory-face)))
1411 (error "No factory default for this face"))
1412 (put symbol 'customized-face nil)
1413 (when (get symbol 'saved-face)
1414 (put symbol 'saved-face nil)
1416 (when (fboundp 'copy-face)
1417 (copy-face 'custom-face-empty symbol))
1418 (custom-face-display-set symbol value)
1419 (widget-value-set child value)
1420 (custom-face-state-set widget)
1421 (custom-redraw-magic widget)))
1423 ;;; The `face' Widget.
1425 (define-widget 'face 'default
1426 "Select and customize a face."
1427 :convert-widget 'widget-item-convert-widget
1428 :format "%[%t%]: %v"
1431 :value-create 'widget-face-value-create
1432 :value-delete 'widget-face-value-delete
1433 :value-get 'widget-item-value-get
1434 :validate 'widget-editable-list-validate
1435 :action 'widget-face-action
1436 :match '(lambda (widget value) (symbolp value)))
1438 (defun widget-face-value-create (widget)
1439 ;; Create a `custom-face' child.
1440 (let* ((symbol (widget-value widget))
1441 (child (widget-create-child-and-convert
1443 :format "%t %s%m%h%v"
1446 (custom-magic-reset child)
1447 (setq custom-options (cons child custom-options))
1448 (widget-put widget :children (list child))))
1450 (defun widget-face-value-delete (widget)
1451 ;; Remove the child from the options.
1452 (let ((child (car (widget-get widget :children))))
1453 (setq custom-options (delq child custom-options))
1454 (widget-children-value-delete widget)))
1456 (defvar face-history nil
1457 "History of entered face names.")
1459 (defun widget-face-action (widget &optional event)
1460 "Prompt for a face."
1461 (let ((answer (completing-read "Face: "
1462 (mapcar (lambda (face)
1463 (list (symbol-name face)))
1467 (unless (zerop (length answer))
1468 (widget-value-set widget (intern answer))
1469 (widget-apply widget :notify widget event)
1472 ;;; The `hook' Widget.
1474 (define-widget 'hook 'list
1476 :convert-widget 'custom-hook-convert-widget
1479 (defun custom-hook-convert-widget (widget)
1480 ;; Handle `:custom-options'.
1481 (let* ((options (widget-get widget :options))
1482 (other `(editable-list :inline t
1483 :entry-format "%i %d%v"
1484 (function :format " %v")))
1486 (list `(checklist :inline t
1487 ,@(mapcar (lambda (entry)
1488 `(function-item ,entry))
1492 (widget-put widget :args args)
1495 ;;; The `custom-group' Widget.
1497 (defcustom custom-group-tag-faces '(custom-group-tag-face-1)
1498 ;; In XEmacs, this ought to play games with font size.
1499 "Face used for group tags.
1500 The first member is used for level 1 groups, the second for level 2,
1501 and so forth. The remaining group tags are shown with
1502 `custom-group-tag-face'."
1503 :type '(repeat face)
1506 (defface custom-group-tag-face-1 '((((class color)
1508 (:foreground "pink" :underline t))
1511 (:foreground "red" :underline t))
1513 "Face used for group tags.")
1515 (defface custom-group-tag-face '((((class color)
1517 (:foreground "light blue" :underline t))
1520 (:foreground "blue" :underline t))
1522 "Face used for low level group tags."
1525 (define-widget 'custom-group 'custom
1527 :format "%l%{%t%}:%L\n%m%h%a%v"
1528 :sample-face-get 'custom-group-sample-face-get
1529 :documentation-property 'group-documentation
1530 :help-echo "Push me to set or reset all members of this group."
1531 :value-create 'custom-group-value-create
1532 :action 'custom-group-action
1533 :custom-set 'custom-group-set
1534 :custom-save 'custom-group-save
1535 :custom-reset-current 'custom-group-reset-current
1536 :custom-reset-saved 'custom-group-reset-saved
1537 :custom-reset-factory 'custom-group-reset-factory
1538 :custom-menu 'custom-group-menu-create)
1540 (defun custom-group-sample-face-get (widget)
1541 ;; Use :sample-face.
1542 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
1543 'custom-group-tag-face))
1545 (defun custom-group-value-create (widget)
1546 (let ((state (widget-get widget :custom-state)))
1547 (unless (eq state 'hidden)
1548 (custom-load-widget widget)
1549 (let* ((level (widget-get widget :custom-level))
1550 (symbol (widget-value widget))
1551 (members (get symbol 'custom-group))
1552 (prefixes (widget-get widget :custom-prefixes))
1553 (custom-prefix-list (custom-prefix-add symbol prefixes))
1554 (children (mapcar (lambda (entry)
1555 (widget-insert "\n")
1557 (widget-create-child-and-convert
1558 widget (nth 1 entry)
1560 :tag (custom-unlispify-tag-name
1562 :custom-prefixes custom-prefix-list
1563 :custom-level (1+ level)
1564 :value (nth 0 entry))
1565 (unless (eq (preceding-char) ?\n)
1566 (widget-insert "\n"))))
1568 (mapcar 'custom-magic-reset children)
1569 (widget-put widget :children children)
1570 (custom-group-state-update widget)))))
1572 (defvar custom-group-menu
1573 '(("Set" . custom-group-set)
1574 ("Save" . custom-group-save)
1575 ("Reset to Current" . custom-group-reset-current)
1576 ("Reset to Saved" . custom-group-reset-saved)
1577 ("Reset to Factory" . custom-group-reset-factory))
1578 "Alist of actions for the `custom-group' widget.
1579 The key is a string containing the name of the action, the value is a
1580 lisp function taking the widget as an element which will be called
1581 when the action is chosen.")
1583 (defun custom-group-action (widget &optional event)
1584 "Show the menu for `custom-group' WIDGET.
1585 Optional EVENT is the location for the menu."
1586 (if (eq (widget-get widget :custom-state) 'hidden)
1588 (widget-put widget :custom-state 'unknown)
1589 (custom-redraw widget))
1590 (let* ((completion-ignore-case t)
1591 (answer (widget-choose (custom-unlispify-tag-name
1592 (widget-get widget :value))
1596 (funcall answer widget)))))
1598 (defun custom-group-set (widget)
1599 "Set changes in all modified group members."
1600 (let ((children (widget-get widget :children)))
1601 (mapcar (lambda (child)
1602 (when (eq (widget-get child :custom-state) 'modified)
1603 (widget-apply child :custom-set)))
1606 (defun custom-group-save (widget)
1607 "Save all modified group members."
1608 (let ((children (widget-get widget :children)))
1609 (mapcar (lambda (child)
1610 (when (memq (widget-get child :custom-state) '(modified set))
1611 (widget-apply child :custom-save)))
1614 (defun custom-group-reset-current (widget)
1615 "Reset all modified group members."
1616 (let ((children (widget-get widget :children)))
1617 (mapcar (lambda (child)
1618 (when (eq (widget-get child :custom-state) 'modified)
1619 (widget-apply child :custom-reset-current)))
1622 (defun custom-group-reset-saved (widget)
1623 "Reset all modified or set group members."
1624 (let ((children (widget-get widget :children)))
1625 (mapcar (lambda (child)
1626 (when (memq (widget-get child :custom-state) '(modified set))
1627 (widget-apply child :custom-reset-saved)))
1630 (defun custom-group-reset-factory (widget)
1631 "Reset all modified, set, or saved group members."
1632 (let ((children (widget-get widget :children)))
1633 (mapcar (lambda (child)
1634 (when (memq (widget-get child :custom-state)
1635 '(modified set saved))
1636 (widget-apply child :custom-reset-factory)))
1639 (defun custom-group-state-update (widget)
1641 (unless (eq (widget-get widget :custom-state) 'hidden)
1642 (let* ((children (widget-get widget :children))
1643 (states (mapcar (lambda (child)
1644 (widget-get child :custom-state))
1646 (magics custom-magic-alist)
1649 (let ((magic (car (car magics))))
1650 (if (and (not (eq magic 'hidden))
1651 (memq magic states))
1654 (setq magics (cdr magics)))))
1655 (widget-put widget :custom-state found)))
1656 (custom-magic-reset widget))
1658 ;;; The `custom-save-all' Function.
1660 (defcustom custom-file "~/.emacs"
1661 "File used for storing customization information.
1662 If you change this from the default \"~/.emacs\" you need to
1663 explicitly load that file for the settings to take effect."
1667 (defun custom-save-delete (symbol)
1668 "Delete the call to SYMBOL form `custom-file'.
1669 Leave point at the location of the call, or after the last expression."
1670 (set-buffer (find-file-noselect custom-file))
1671 (goto-char (point-min))
1674 (let ((sexp (condition-case nil
1675 (read (current-buffer))
1676 (end-of-file (throw 'found nil)))))
1677 (when (and (listp sexp)
1678 (eq (car sexp) symbol))
1679 (delete-region (save-excursion
1683 (throw 'found nil))))))
1685 (defun custom-save-variables ()
1686 "Save all customized variables in `custom-file'."
1688 (custom-save-delete 'custom-set-variables)
1689 (let ((standard-output (current-buffer)))
1692 (princ "(custom-set-variables")
1693 (mapatoms (lambda (symbol)
1694 (let ((value (get symbol 'saved-value)))
1700 (if (or (get symbol 'factory-value)
1701 (and (not (boundp symbol))
1702 (not (get symbol 'force-value))))
1709 (defun custom-save-faces ()
1710 "Save all customized faces in `custom-file'."
1712 (custom-save-delete 'custom-set-faces)
1713 (let ((standard-output (current-buffer)))
1716 (princ "(custom-set-faces")
1717 (mapatoms (lambda (symbol)
1718 (let ((value (get symbol 'saved-face)))
1724 (if (or (get symbol 'factory-face)
1725 (and (not (custom-facep symbol))
1726 (not (get symbol 'force-face))))
1733 (defun custom-save-all ()
1734 "Save all customizations in `custom-file'."
1735 (custom-save-variables)
1738 (set-buffer (find-file-noselect custom-file))
1741 ;;; The Customize Menu.
1743 (defcustom custom-menu-nesting 2
1744 "Maximum nesting in custom menus."
1748 (defun custom-face-menu-create (widget symbol)
1749 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
1750 (vector (custom-unlispify-menu-entry symbol)
1751 `(custom-buffer-create '((,symbol custom-face)))
1754 (defun custom-variable-menu-create (widget symbol)
1755 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
1756 (let ((type (get symbol 'custom-type)))
1757 (unless (listp type)
1758 (setq type (list type)))
1759 (if (and type (widget-get type :custom-menu))
1760 (widget-apply type :custom-menu symbol)
1761 (vector (custom-unlispify-menu-entry symbol)
1762 `(custom-buffer-create '((,symbol custom-variable)))
1765 (widget-put (get 'boolean 'widget-type)
1766 :custom-menu (lambda (widget symbol)
1767 (vector (custom-unlispify-menu-entry symbol)
1768 `(custom-buffer-create
1769 '((,symbol custom-variable)))
1771 ':selected symbol)))
1773 (defun custom-group-menu-create (widget symbol)
1774 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
1775 (custom-menu-create symbol))
1777 (defun custom-menu-create (symbol &optional name)
1778 "Create menu for customization group SYMBOL.
1779 If optional NAME is given, use that as the name of the menu.
1780 Otherwise make up a name from SYMBOL.
1781 The menu is in a format applicable to `easy-menu-define'."
1783 (setq name (custom-unlispify-menu-entry symbol)))
1784 (let ((item (vector name
1785 `(custom-buffer-create '((,symbol custom-group)))
1787 (if (and (> custom-menu-nesting 0)
1788 (< (length (get symbol 'custom-group)) widget-menu-max-size))
1789 (let ((custom-menu-nesting (1- custom-menu-nesting))
1790 (custom-prefix-list (custom-prefix-add symbol
1791 custom-prefix-list)))
1792 (custom-load-symbol symbol)
1793 `(,(custom-unlispify-menu-entry symbol t)
1796 ,@(mapcar (lambda (entry)
1797 (widget-apply (if (listp (nth 1 entry))
1799 (list (nth 1 entry)))
1800 :custom-menu (nth 0 entry)))
1801 (get symbol 'custom-group))))
1805 (defun custom-menu-update ()
1806 "Update customize menu."
1808 (add-hook 'custom-define-hook 'custom-menu-reset)
1809 (let ((menu `(,(car custom-help-menu)
1810 ,(widget-apply '(custom-group) :custom-menu 'emacs)
1811 ,@(cdr (cdr custom-help-menu)))))
1812 (if (fboundp 'add-submenu)
1813 (add-submenu '("Help") menu)
1814 (define-key global-map [menu-bar help-menu customize-menu]
1815 (cons (car menu) (easy-menu-create-keymaps (car menu) (cdr menu)))))))
1820 (defun custom-make-dependencies ()
1821 "Batch function to extract custom dependencies from .el files.
1822 Usage: emacs -batch *.el -f custom-make-dependencies > deps.el"
1823 (let ((buffers (buffer-list)))
1825 (set-buffer (car buffers))
1826 (setq buffers (cdr buffers))
1827 (let ((file (buffer-file-name)))
1828 (when (and file (string-match "\\`\\(.*\\)\\.el\\'" file))
1829 (goto-char (point-min))
1831 (let ((name (file-name-nondirectory (match-string 1 file))))
1833 (let ((expr (read (current-buffer))))
1834 (when (and (listp expr)
1835 (memq (car expr) '(defcustom defface defgroup)))
1837 (put (nth 1 expr) 'custom-where name)))))
1839 (mapatoms (lambda (symbol)
1840 (let ((members (get symbol 'custom-group))
1845 (princ " 'custom-loads '(")
1847 (setq item (car (car members))
1848 members (cdr members)
1849 where (get item 'custom-where))
1850 (unless (or (null where)
1851 (member where found))
1855 (push where found)))
1862 ;; cus-edit.el ends here