1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages.
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/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
42 (eval-when-compile (require 'cl))
52 (define-widget-keywords :custom-last :custom-prefix :custom-category
53 :custom-prefixes :custom-menu
55 :custom-magic :custom-state :custom-level :custom-form
56 :custom-set :custom-save :custom-reset-current :custom-reset-saved
57 :custom-reset-standard)
59 (put 'custom-define-hook 'custom-type 'hook)
60 (put 'custom-define-hook 'standard-value '(nil))
61 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
63 ;;; Customization Groups.
66 "Customization of the One True Editor."
67 :link '(custom-manual "(emacs)Top"))
69 ;; Most of these groups are stolen from `finder.el',
71 "Basic text editing facilities."
75 "Abbreviation handling, typing shortcuts, macros."
79 (defgroup matching nil
80 "Various sorts of searching and matching."
83 (defgroup emulations nil
84 "Emulations of other editors."
91 (defgroup outlines nil
92 "Support for hierarchical outlining."
95 (defgroup external nil
96 "Interfacing to external utilities."
100 "Code related to the `bib' bibliography processor."
104 (defgroup processes nil
105 "Process, subshell, compilation, and job control support."
109 (defgroup programming nil
110 "Support for programming in other languages."
113 (defgroup languages nil
114 "Specialized modes for editing programming languages."
118 "Lisp support, including Emacs Lisp."
123 "Support for the C language and related languages."
131 "Support for object-oriented programming."
134 (defgroup applications nil
135 "Applications written in Emacs."
138 (defgroup calendar nil
139 "Calendar and time management support."
140 :group 'applications)
143 "Modes for electronic-mail handling."
144 :group 'applications)
147 "Support for netnews reading and posting."
148 :group 'applications)
151 "Games, jokes and amusements."
152 :group 'applications)
154 (defgroup development nil
155 "Support for further development of Emacs."
159 "Support for Emacs documentation."
162 (defgroup extensions nil
163 "Emacs Lisp language extensions."
166 (defgroup internal nil
167 "Code for Emacs internals, build process, defaults."
171 "Maintenance aids for the Emacs development group."
175 (defgroup environment nil
176 "Fitting Emacs with its environment."
180 "Communications, networking, remote access to files."
184 (defgroup hardware nil
185 "Support for interfacing with exotic hardware."
188 (defgroup terminals nil
189 "Support for terminal types."
193 "Front-ends/assistants for, or emulators of, UNIX features."
197 "Support code for vms."
201 "Internationalization and alternate character-set support."
206 "The X Window system."
210 "Support for Emacs frames and window systems."
214 "Support editing files of data."
218 "Support editing files."
226 "Code related to the TeX formatter."
230 "Support for multiple fonts."
233 (defgroup hypermedia nil
234 "Support for links between text or other media types."
238 "Support for on-line help systems."
242 "Code local to your site."
245 (defgroup customize '((widgets custom-group))
246 "Customization of the Customization support."
247 :link '(custom-manual "(custom)Top")
248 :link '(url-link :tag "Development Page"
249 "http://www.dina.kvl.dk/~abraham/custom/")
253 (defgroup custom-faces nil
254 "Faces used by customize."
258 (defgroup custom-browse nil
259 "Control customize browser."
263 (defgroup custom-buffer nil
264 "Control customize buffers."
268 (defgroup custom-menu nil
269 "Control customize menus."
273 (defgroup abbrev-mode nil
274 "Word abbreviations mode."
278 "Storage allocation and gc for GNU Emacs Lisp interpreter."
279 :tag "Storage Allocation"
283 "Undoing changes in buffers."
286 (defgroup modeline nil
287 "Content of the modeline."
291 "Indenting and filling text."
294 (defgroup editing-basics nil
295 "Most basic editing facilities."
298 (defgroup display nil
299 "How characters are displayed in buffers."
302 (defgroup execute nil
303 "Executing external commands."
306 (defgroup installation nil
307 "The Emacs installation."
315 "Internal Emacs limits."
319 "Debugging Emacs itself."
322 (defgroup minibuffer nil
323 "Controling the behaviour of the minibuffer."
326 (defgroup keyboard nil
327 "Input from the keyboard."
331 "Input from the mouse."
335 "Input from the menus."
338 (defgroup auto-save nil
339 "Preventing accidential loss of data."
342 (defgroup processes-basics nil
343 "Basic stuff dealing with processes."
347 "MULE Emacs internationalization."
350 (defgroup windows nil
351 "Windows within a frame."
356 (defun custom-last (x &optional n)
357 ;; Stolen from `cl.el'.
358 "Returns the last link in the list LIST.
359 With optional argument N, returns Nth-to-last link (default 1)."
362 (while (consp p) (incf m) (pop p))
364 (if (< n m) (nthcdr (- m n) x) x)))
365 (while (consp (cdr x)) (pop x))
368 (defun custom-quote (sexp)
369 "Quote SEXP iff it is not self quoting."
370 (if (or (memq sexp '(t nil))
372 (eq (aref (symbol-name sexp) 0) ?:))
374 (memq (car sexp) '(lambda)))
377 (and (fboundp 'characterp)
382 (defun custom-split-regexp-maybe (regexp)
383 "If REGEXP is a string, split it to a list at `\\|'.
384 You can get the original back with from the result with:
385 (mapconcat 'identity result \"\\|\")
387 IF REGEXP is not a string, return it unchanged."
391 (while (string-match "\\\\|" regexp start)
392 (setq all (cons (substring regexp start (match-beginning 0)) all)
393 start (match-end 0)))
394 (nreverse (cons (substring regexp start) all)))
397 (defun custom-variable-prompt ()
398 ;; Code stolen from `help.el'.
399 "Prompt for a variable, defaulting to the variable at point.
400 Return a list suitable for use in `interactive'."
401 (let ((v (variable-at-point))
402 (enable-recursive-minibuffers t)
404 (setq val (completing-read
406 (format "Customize option: (default %s) " v)
407 "Customize variable: ")
408 obarray (lambda (symbol)
410 (or (get symbol 'custom-type)
411 (user-variable-p symbol))))))
412 (list (if (equal val "")
413 (if (symbolp v) v nil)
416 (defun custom-menu-filter (menu widget)
417 "Convert MENU to the form used by `widget-choose'.
418 MENU should be in the same format as `custom-variable-menu'.
419 WIDGET is the widget to apply the filter entries of MENU on."
421 current name action filter)
423 (setq current (car menu)
425 action (nth 1 current)
426 filter (nth 2 current)
428 (if (or (null filter) (funcall filter widget))
429 (push (cons name action) result)
435 (defvar custom-prefix-list nil
436 "List of prefixes that should be ignored by `custom-unlispify'")
438 (defcustom custom-unlispify-menu-entries t
439 "Display menu entries as words instead of symbols if non nil."
443 (defcustom custom-unlispify-remove-prefixes nil
444 "Non-nil means remove group prefixes from option names in buffer."
448 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
449 "Convert symbol into a menu entry."
450 (cond ((not custom-unlispify-menu-entries)
451 (symbol-name symbol))
452 ((get symbol 'custom-tag)
454 (get symbol 'custom-tag)
455 (concat (get symbol 'custom-tag) "...")))
458 (set-buffer (get-buffer-create " *Custom-Work*"))
460 (princ symbol (current-buffer))
461 (goto-char (point-min))
462 (when (and (eq (get symbol 'custom-type) 'boolean)
463 (re-search-forward "-p\\'" nil t))
464 (replace-match "" t t)
465 (goto-char (point-min)))
466 (if custom-unlispify-remove-prefixes
467 (let ((prefixes custom-prefix-list)
470 (setq prefix (car prefixes))
471 (if (search-forward prefix (+ (point) (length prefix)) t)
474 (delete-region (point-min) (point)))
475 (setq prefixes (cdr prefixes))))))
476 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
477 (capitalize-region (point-min) (point-max))
479 (goto-char (point-max))
483 (defcustom custom-unlispify-tag-names t
484 "Display tag names as words instead of symbols if non nil."
485 :group 'custom-buffer
488 (defun custom-unlispify-tag-name (symbol)
489 "Convert symbol into a menu entry."
490 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
491 (custom-unlispify-menu-entry symbol t)))
493 (defun custom-prefix-add (symbol prefixes)
494 ;; Addd SYMBOL to list of ignored PREFIXES.
495 (cons (or (get symbol 'custom-prefix)
496 (concat (symbol-name symbol) "-"))
501 (defcustom custom-guess-name-alist
506 ("-function\\'" function)
507 ("-functions\\'" (repeat function))
508 ("-list\\'" (repeat sexp))
509 ("-alist\\'" (repeat (cons sexp sexp))))
510 "Alist of (MATCH TYPE).
512 MATCH should be a regexp matching the name of a symbol, and TYPE should
513 be a widget suitable for editing the value of that symbol. The TYPE
514 of the first entry where MATCH matches the name of the symbol will be
517 This is used for guessing the type of variables not declared with
519 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
522 (defcustom custom-guess-doc-alist
523 '(("\\`\\*?Non-nil " boolean))
524 "Alist of (MATCH TYPE).
526 MATCH should be a regexp matching a documentation string, and TYPE
527 should be a widget suitable for editing the value of a variable with
528 that documentation string. The TYPE of the first entry where MATCH
529 matches the name of the symbol will be used.
531 This is used for guessing the type of variables not declared with
533 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
536 (defun custom-guess-type (symbol)
537 "Guess a widget suitable for editing the value of SYMBOL.
538 This is done by matching SYMBOL with `custom-guess-name-alist' and
539 if that fails, the doc string with `custom-guess-doc-alist'."
540 (let ((name (symbol-name symbol))
541 (names custom-guess-name-alist)
544 (setq current (car names)
546 (when (string-match (nth 0 current) name)
547 (setq found (nth 1 current)
550 (let ((doc (documentation-property symbol 'variable-documentation))
551 (docs custom-guess-doc-alist))
554 (setq current (car docs)
556 (when (string-match (nth 0 current) doc)
557 (setq found (nth 1 current)
563 (defcustom custom-browse-sort-alphabetically nil
564 "If non-nil, sort members of each customization group alphabetically."
566 :group 'custom-browse)
568 (defcustom custom-browse-order-groups nil
569 "If non-nil, order group members within each customization group.
570 If `first', order groups before non-groups.
571 If `last', order groups after non-groups."
572 :type '(choice (const first)
574 (const :tag "none" nil))
575 :group 'custom-browse)
577 (defcustom custom-browse-only-groups nil
578 "If non-nil, show group members only within each customization group."
580 :group 'custom-browse)
582 (defcustom custom-buffer-sort-alphabetically nil
583 "If non-nil, sort members of each customization group alphabetically."
585 :group 'custom-buffer)
587 (defcustom custom-buffer-order-groups 'last
588 "If non-nil, order group members within each customization group.
589 If `first', order groups before non-groups.
590 If `last', order groups after non-groups."
591 :type '(choice (const first)
593 (const :tag "none" nil))
594 :group 'custom-buffer)
596 (defcustom custom-menu-sort-alphabetically nil
597 "If non-nil, sort members of each customization group alphabetically."
601 (defcustom custom-menu-order-groups 'first
602 "If non-nil, order group members within each customization group.
603 If `first', order groups before non-groups.
604 If `last', order groups after non-groups."
605 :type '(choice (const first)
607 (const :tag "none" nil))
610 (defun custom-sort-items (items sort-alphabetically order-groups)
611 "Return a sorted copy of ITEMS.
612 ITEMS should be a `custom-group' property.
613 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
614 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
615 groups after non-groups, if nil do not order groups at all."
616 (sort (copy-sequence items)
618 (let ((typea (nth 1 a)) (typeb (nth 1 b))
619 (namea (symbol-name (nth 0 a))) (nameb (symbol-name (nth 0 b))))
620 (cond ((not order-groups)
621 ;; Since we don't care about A and B order, maybe sort.
622 (when sort-alphabetically
623 (string-lessp namea nameb)))
624 ((eq typea 'custom-group)
625 ;; If B is also a group, maybe sort. Otherwise, order A and B.
626 (if (eq typeb 'custom-group)
627 (when sort-alphabetically
628 (string-lessp namea nameb))
629 (eq order-groups 'first)))
630 ((eq typeb 'custom-group)
631 ;; Since A cannot be a group, order A and B.
632 (eq order-groups 'last))
634 ;; Since A and B cannot be groups, sort.
635 (string-lessp namea nameb)))))))
637 ;;; Custom Mode Commands.
639 (defvar custom-options nil
640 "Customization widgets in the current buffer.")
643 "Set changes in all modified options."
645 (let ((children custom-options))
646 (mapcar (lambda (child)
647 (when (eq (widget-get child :custom-state) 'modified)
648 (widget-apply child :custom-set)))
651 (defun Custom-save ()
652 "Set all modified group members and save them."
654 (let ((children custom-options))
655 (mapcar (lambda (child)
656 (when (memq (widget-get child :custom-state) '(modified set))
657 (widget-apply child :custom-save)))
661 (defvar custom-reset-menu
662 '(("Current" . Custom-reset-current)
663 ("Saved" . Custom-reset-saved)
664 ("Standard Settings" . Custom-reset-standard))
665 "Alist of actions for the `Reset' button.
666 The key is a string containing the name of the action, the value is a
667 lisp function taking the widget as an element which will be called
668 when the action is chosen.")
670 (defun custom-reset (event)
671 "Select item from reset menu."
672 (let* ((completion-ignore-case t)
673 (answer (widget-choose "Reset to"
679 (defun Custom-reset-current (&rest ignore)
680 "Reset all modified group members to their current value."
682 (let ((children custom-options))
683 (mapcar (lambda (child)
684 (when (eq (widget-get child :custom-state) 'modified)
685 (widget-apply child :custom-reset-current)))
688 (defun Custom-reset-saved (&rest ignore)
689 "Reset all modified or set group members to their saved value."
691 (let ((children custom-options))
692 (mapcar (lambda (child)
693 (when (eq (widget-get child :custom-state) 'modified)
694 (widget-apply child :custom-reset-saved)))
697 (defun Custom-reset-standard (&rest ignore)
698 "Reset all modified, set, or saved group members to their standard settings."
700 (let ((children custom-options))
701 (mapcar (lambda (child)
702 (when (eq (widget-get child :custom-state) 'modified)
703 (widget-apply child :custom-reset-standard)))
706 ;;; The Customize Commands
708 (defun custom-prompt-variable (prompt-var prompt-val)
709 "Prompt for a variable and a value and return them as a list.
710 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
711 prompt for the value. The %s escape in PROMPT-VAL is replaced with
712 the name of the variable.
714 If the variable has a `variable-interactive' property, that is used as if
715 it were the arg to `interactive' (which see) to interactively read the value.
717 If the variable has a `custom-type' property, it must be a widget and the
718 `:prompt-value' property of that widget will be used for reading the value."
719 (let* ((var (read-variable prompt-var))
720 (minibuffer-help-form '(describe-variable var)))
722 (let ((prop (get var 'variable-interactive))
723 (type (get var 'custom-type))
724 (prompt (format prompt-val var)))
726 (setq type (list type)))
728 ;; Use VAR's `variable-interactive' property
729 ;; as an interactive spec for prompting.
730 (call-interactively (list 'lambda '(arg)
731 (list 'interactive prop)
734 (widget-prompt-value type
740 (eval-minibuffer prompt)))))))
743 (defun customize-set-value (var val)
744 "Set VARIABLE to VALUE. VALUE is a Lisp object.
746 If VARIABLE has a `variable-interactive' property, that is used as if
747 it were the arg to `interactive' (which see) to interactively read the value.
749 If VARIABLE has a `custom-type' property, it must be a widget and the
750 `:prompt-value' property of that widget will be used for reading the value."
751 (interactive (custom-prompt-variable "Set variable: "
752 "Set %s to value: "))
757 (defun customize-set-variable (var val)
758 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
760 If VARIABLE has a `custom-set' property, that is used for setting
761 VARIABLE, otherwise `set-default' is used.
763 The `customized-value' property of the VARIABLE will be set to a list
764 with a quoted VALUE as its sole list member.
766 If VARIABLE has a `variable-interactive' property, that is used as if
767 it were the arg to `interactive' (which see) to interactively read the value.
769 If VARIABLE has a `custom-type' property, it must be a widget and the
770 `:prompt-value' property of that widget will be used for reading the value. "
771 (interactive (custom-prompt-variable "Set variable: "
772 "Set customized value for %s to: "))
773 (funcall (or (get var 'custom-set) 'set-default) var val)
774 (put var 'customized-value (list (custom-quote val))))
777 (defun customize-save-variable (var val)
778 "Set the default for VARIABLE to VALUE, and save it for future sessions.
779 If VARIABLE has a `custom-set' property, that is used for setting
780 VARIABLE, otherwise `set-default' is used.
782 The `customized-value' property of the VARIABLE will be set to a list
783 with a quoted VALUE as its sole list member.
785 If VARIABLE has a `variable-interactive' property, that is used as if
786 it were the arg to `interactive' (which see) to interactively read the value.
788 If VARIABLE has a `custom-type' property, it must be a widget and the
789 `:prompt-value' property of that widget will be used for reading the value. "
790 (interactive (custom-prompt-variable "Set and ave variable: "
791 "Set and save value for %s as: "))
792 (funcall (or (get var 'custom-set) 'set-default) var val)
793 (put var 'saved-value (list (custom-quote val)))
798 "Select a customization buffer which you can use to set user options.
799 User options are structured into \"groups\".
800 Initially the top-level group `Emacs' and its immediate subgroups
801 are shown; the contents of those subgroups are initially hidden."
803 (customize-group 'emacs))
806 (defun customize-group (group)
807 "Customize GROUP, which must be a customization group."
808 (interactive (list (let ((completion-ignore-case t))
809 (completing-read "Customize group: (default emacs) "
812 (get symbol 'custom-group))
815 (when (stringp group)
816 (if (string-equal "" group)
818 (setq group (intern group))))
819 (let ((name (format "*Customize Group: %s*"
820 (custom-unlispify-tag-name group))))
821 (if (get-buffer name)
822 (switch-to-buffer name)
823 (custom-buffer-create (list (list group 'custom-group))
825 (concat " for group "
826 (custom-unlispify-tag-name group))))))
829 (defun customize-group-other-window (symbol)
830 "Customize SYMBOL, which must be a customization group."
831 (interactive (list (completing-read "Customize group: (default emacs) "
834 (get symbol 'custom-group))
837 (when (stringp symbol)
838 (if (string-equal "" symbol)
840 (setq symbol (intern symbol))))
841 (custom-buffer-create-other-window
842 (list (list symbol 'custom-group))
843 (format "*Customize Group: %s*" (custom-unlispify-tag-name symbol))))
846 (defalias 'customize-variable 'customize-option)
849 (defun customize-option (symbol)
850 "Customize SYMBOL, which must be a user option variable."
851 (interactive (custom-variable-prompt))
852 (custom-buffer-create (list (list symbol 'custom-variable))
853 (format "*Customize Option: %s*"
854 (custom-unlispify-tag-name symbol))))
857 (defalias 'customize-variable-other-window 'customize-option-other-window)
860 (defun customize-option-other-window (symbol)
861 "Customize SYMBOL, which must be a user option variable.
862 Show the buffer in another window, but don't select it."
863 (interactive (custom-variable-prompt))
864 (custom-buffer-create-other-window
865 (list (list symbol 'custom-variable))
866 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol))))
869 (defun customize-face (&optional symbol)
870 "Customize SYMBOL, which should be a face name or nil.
871 If SYMBOL is nil, customize all faces."
872 (interactive (list (completing-read "Customize face: (default all) "
873 obarray 'custom-facep)))
874 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
875 (custom-buffer-create (custom-sort-items
876 (mapcar (lambda (symbol)
877 (list symbol 'custom-face))
881 (when (stringp symbol)
882 (setq symbol (intern symbol)))
883 (unless (symbolp symbol)
884 (error "Should be a symbol %S" symbol))
885 (custom-buffer-create (list (list symbol 'custom-face))
886 (format "*Customize Face: %s*"
887 (custom-unlispify-tag-name symbol)))))
890 (defun customize-face-other-window (&optional symbol)
891 "Show customization buffer for FACE in other window."
892 (interactive (list (completing-read "Customize face: "
893 obarray 'custom-facep)))
894 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
897 (setq symbol (intern symbol)))
898 (unless (symbolp symbol)
899 (error "Should be a symbol %S" symbol))
900 (custom-buffer-create-other-window
901 (list (list symbol 'custom-face))
902 (format "*Customize Face: %s*" (custom-unlispify-tag-name symbol)))))
905 (defun customize-customized ()
906 "Customize all user options set since the last save in this session."
909 (mapatoms (lambda (symbol)
910 (and (get symbol 'customized-face)
911 (custom-facep symbol)
912 (push (list symbol 'custom-face) found))
913 (and (get symbol 'customized-value)
915 (push (list symbol 'custom-variable) found))))
917 (error "No customized user options")
918 (custom-buffer-create (custom-sort-items found t nil)
919 "*Customize Customized*"))))
922 (defun customize-saved ()
923 "Customize all already saved user options."
926 (mapatoms (lambda (symbol)
927 (and (get symbol 'saved-face)
928 (custom-facep symbol)
929 (push (list symbol 'custom-face) found))
930 (and (get symbol 'saved-value)
932 (push (list symbol 'custom-variable) found))))
934 (error "No saved user options")
935 (custom-buffer-create (custom-sort-items found t nil)
936 "*Customize Saved*"))))
939 (defun customize-apropos (regexp &optional all)
940 "Customize all user options matching REGEXP.
941 If ALL is `options', include only options.
942 If ALL is `faces', include only faces.
943 If ALL is `groups', include only groups.
944 If ALL is t (interactively, with prefix arg), include options which are not
945 user-settable, as well as faces and groups."
946 (interactive "sCustomize regexp: \nP")
948 (mapatoms (lambda (symbol)
949 (when (string-match regexp (symbol-name symbol))
950 (when (and (not (memq all '(faces options)))
951 (get symbol 'custom-group))
952 (push (list symbol 'custom-group) found))
953 (when (and (not (memq all '(options groups)))
954 (custom-facep symbol))
955 (push (list symbol 'custom-face) found))
956 (when (and (not (memq all '(groups faces)))
958 (or (get symbol 'saved-value)
959 (get symbol 'standard-value)
960 (if (memq all '(nil options))
961 (user-variable-p symbol)
962 (get symbol 'variable-documentation))))
963 (push (list symbol 'custom-variable) found)))))
966 (custom-buffer-create (custom-sort-items found t
967 custom-buffer-order-groups)
968 "*Customize Apropos*"))))
971 (defun customize-apropos-options (regexp &optional arg)
972 "Customize all user options matching REGEXP.
973 With prefix arg, include options which are not user-settable."
974 (interactive "sCustomize regexp: \nP")
975 (customize-apropos regexp (or arg 'options)))
978 (defun customize-apropos-faces (regexp)
979 "Customize all user faces matching REGEXP."
980 (interactive "sCustomize regexp: \n")
981 (customize-apropos regexp 'faces))
984 (defun customize-apropos-groups (regexp)
985 "Customize all user groups matching REGEXP."
986 (interactive "sCustomize regexp: \n")
987 (customize-apropos regexp 'groups))
991 (defcustom custom-buffer-style 'links
992 "Control the presentation style for customization buffers.
993 The value should be a symbol, one of:
995 brackets: groups nest within each other with big horizontal brackets.
996 links: groups have links to subgroups."
997 :type '(radio (const brackets)
999 :group 'custom-buffer)
1001 (defcustom custom-buffer-indent 3
1002 "Number of spaces to indent nested groups."
1004 :group 'custom-buffer)
1007 (defun custom-buffer-create (options &optional name description)
1008 "Create a buffer containing OPTIONS.
1009 Optional NAME is the name of the buffer.
1010 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1011 SYMBOL is a customization option, and WIDGET is a widget for editing
1013 (unless name (setq name "*Customization*"))
1014 (kill-buffer (get-buffer-create name))
1015 (switch-to-buffer (get-buffer-create name))
1016 (custom-buffer-create-internal options description))
1019 (defun custom-buffer-create-other-window (options &optional name description)
1020 "Create a buffer containing OPTIONS.
1021 Optional NAME is the name of the buffer.
1022 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1023 SYMBOL is a customization option, and WIDGET is a widget for editing
1025 (unless name (setq name "*Customization*"))
1026 (kill-buffer (get-buffer-create name))
1027 (let ((window (selected-window)))
1028 (switch-to-buffer-other-window (get-buffer-create name))
1029 (custom-buffer-create-internal options description)
1030 (select-window window)))
1032 (defcustom custom-reset-button-menu nil
1033 "If non-nil, only show a single reset button in customize buffers.
1034 This button will have a menu with all three reset operations."
1036 :group 'custom-buffer)
1038 (defun custom-buffer-create-internal (options &optional description)
1039 (message "Creating customization buffer...")
1041 (widget-insert "This is a customization buffer")
1043 (widget-insert description))
1045 Square brackets show active fields; type RET or click mouse-1
1046 on an active field to invoke its action. Editing an option value
1047 changes the text in the buffer; invoke the State button and
1048 choose the Set operation to set the option value.
1050 (widget-create 'info-link
1052 :help-echo "Read the online help."
1053 "(emacs)Easy Customization")
1054 (widget-insert " for more information.\n\n")
1055 (message "Creating customization buttons...")
1056 (widget-insert "Operate on everything in this buffer:\n ")
1057 (widget-create 'push-button
1058 :tag "Set for Current Session"
1060 Make your editing in this buffer take effect for this session."
1061 :action (lambda (widget &optional event)
1064 (widget-create 'push-button
1065 :tag "Save for Future Sessions"
1067 Make your editing in this buffer take effect for future Emacs sessions."
1068 :action (lambda (widget &optional event)
1070 (if custom-reset-button-menu
1073 (widget-create 'push-button
1075 :help-echo "Show a menu with reset operations."
1076 :mouse-down-action (lambda (&rest junk) t)
1077 :action (lambda (widget &optional event)
1078 (custom-reset event))))
1079 (widget-insert "\n ")
1080 (widget-create 'push-button
1083 Reset all edited text in this buffer to reflect current values."
1084 :action 'Custom-reset-current)
1086 (widget-create 'push-button
1087 :tag "Reset to Saved"
1089 Reset all values in this buffer to their saved settings."
1090 :action 'Custom-reset-saved)
1092 (widget-create 'push-button
1093 :tag "Reset to Standard"
1095 Reset all values in this buffer to their standard settings."
1096 :action 'Custom-reset-standard))
1098 (widget-create 'push-button
1100 :help-echo "Bury the buffer."
1101 :action (lambda (widget &optional event)
1103 (widget-insert "\n\n")
1104 (message "Creating customization items...")
1105 (setq custom-options
1106 (if (= (length options) 1)
1107 (mapcar (lambda (entry)
1108 (widget-create (nth 1 entry)
1109 :documentation-shown t
1110 :custom-state 'unknown
1111 :tag (custom-unlispify-tag-name
1113 :value (nth 0 entry)))
1116 (length (length options)))
1117 (mapcar (lambda (entry)
1119 (message "Creating customization items %2d%%..."
1120 (/ (* 100.0 count) length))
1121 (widget-create (nth 1 entry)
1122 :tag (custom-unlispify-tag-name
1124 :value (nth 0 entry))
1125 (setq count (1+ count))
1126 (unless (eq (preceding-char) ?\n)
1127 (widget-insert "\n"))
1128 (widget-insert "\n")))
1130 (unless (eq (preceding-char) ?\n)
1131 (widget-insert "\n"))
1132 (message "Creating customization items %2d%%...done" 100)
1133 (unless (eq custom-buffer-style 'tree)
1134 (mapcar 'custom-magic-reset custom-options))
1135 (message "Creating customization setup...")
1137 (goto-char (point-min))
1138 (message "Creating customization buffer...done"))
1140 ;;; The Tree Browser.
1143 (defun customize-browse (&optional group)
1144 "Create a tree browser for the customize hierarchy."
1147 (setq group 'emacs))
1148 (let ((name "*Customize Browser*"))
1149 (kill-buffer (get-buffer-create name))
1150 (switch-to-buffer (get-buffer-create name)))
1153 Square brackets show active fields; type RET or click mouse-1
1154 on an active field to invoke its action.
1155 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1156 (if custom-browse-only-groups
1158 Invoke the [Group] button below to edit that item in another window.\n\n")
1159 (widget-insert "Invoke the ")
1160 (widget-create 'item
1163 :tag-glyph "folder")
1164 (widget-insert ", ")
1165 (widget-create 'item
1169 (widget-insert ", and ")
1170 (widget-create 'item
1173 :tag-glyph "option")
1174 (widget-insert " buttons below to edit that
1175 item in another window.\n\n"))
1176 (let ((custom-buffer-style 'tree))
1177 (widget-create 'custom-group
1179 :custom-state 'unknown
1180 :tag (custom-unlispify-tag-name group)
1182 (goto-char (point-min)))
1184 (define-widget 'custom-browse-visibility 'item
1185 "Control visibility of of items in the customize tree browser."
1187 :action 'custom-browse-visibility-action)
1189 (defun custom-browse-visibility-action (widget &rest ignore)
1190 (let ((custom-buffer-style 'tree))
1191 (custom-toggle-parent widget)))
1193 (define-widget 'custom-browse-group-tag 'push-button
1194 "Show parent in other window when activated."
1197 :action 'custom-browse-group-tag-action)
1199 (defun custom-browse-group-tag-action (widget &rest ignore)
1200 (let ((parent (widget-get widget :parent)))
1201 (customize-group-other-window (widget-value parent))))
1203 (define-widget 'custom-browse-variable-tag 'push-button
1204 "Show parent in other window when activated."
1207 :action 'custom-browse-variable-tag-action)
1209 (defun custom-browse-variable-tag-action (widget &rest ignore)
1210 (let ((parent (widget-get widget :parent)))
1211 (customize-variable-other-window (widget-value parent))))
1213 (define-widget 'custom-browse-face-tag 'push-button
1214 "Show parent in other window when activated."
1217 :action 'custom-browse-face-tag-action)
1219 (defun custom-browse-face-tag-action (widget &rest ignore)
1220 (let ((parent (widget-get widget :parent)))
1221 (customize-face-other-window (widget-value parent))))
1223 (defconst custom-browse-alist '((" " "space")
1229 (defun custom-browse-insert-prefix (prefix)
1230 "Insert PREFIX. On XEmacs convert it to line graphics."
1231 (if nil ; (string-match "XEmacs" emacs-version)
1234 (while (not (string-equal prefix ""))
1235 (let ((entry (substring prefix 0 3)))
1236 (setq prefix (substring prefix 3))
1237 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1238 (name (nth 1 (assoc entry custom-browse-alist))))
1239 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1240 (overlay-put overlay 'start-open t)
1241 (overlay-put overlay 'end-open t)))))
1244 ;;; Modification of Basic Widgets.
1246 ;; We add extra properties to the basic widgets needed here. This is
1247 ;; fine, as long as we are careful to stay within out own namespace.
1249 ;; We want simple widgets to be displayed by default, but complex
1250 ;; widgets to be hidden.
1252 (widget-put (get 'item 'widget-type) :custom-show t)
1253 (widget-put (get 'editable-field 'widget-type)
1254 :custom-show (lambda (widget value)
1255 (let ((pp (pp-to-string value)))
1256 (cond ((string-match "\n" pp)
1261 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1263 ;;; The `custom-manual' Widget.
1265 (define-widget 'custom-manual 'info-link
1266 "Link to the manual entry for this customization option."
1267 :help-echo "Read the manual entry for this option."
1270 ;;; The `custom-magic' Widget.
1272 (defgroup custom-magic-faces nil
1273 "Faces used by the magic button."
1274 :group 'custom-faces
1275 :group 'custom-buffer)
1277 (defface custom-invalid-face '((((class color))
1278 (:foreground "yellow" :background "red"))
1280 (:bold t :italic t :underline t)))
1281 "Face used when the customize item is invalid."
1282 :group 'custom-magic-faces)
1284 (defface custom-rogue-face '((((class color))
1285 (:foreground "pink" :background "black"))
1288 "Face used when the customize item is not defined for customization."
1289 :group 'custom-magic-faces)
1291 (defface custom-modified-face '((((class color))
1292 (:foreground "white" :background "blue"))
1295 "Face used when the customize item has been modified."
1296 :group 'custom-magic-faces)
1298 (defface custom-set-face '((((class color))
1299 (:foreground "blue" :background "white"))
1302 "Face used when the customize item has been set."
1303 :group 'custom-magic-faces)
1305 (defface custom-changed-face '((((class color))
1306 (:foreground "white" :background "blue"))
1309 "Face used when the customize item has been changed."
1310 :group 'custom-magic-faces)
1312 (defface custom-saved-face '((t (:underline t)))
1313 "Face used when the customize item has been saved."
1314 :group 'custom-magic-faces)
1316 (defconst custom-magic-alist '((nil "#" underline "\
1317 uninitialized, you should not see this.")
1318 (unknown "?" italic "\
1319 unknown, you should not see this.")
1320 (hidden "-" default "\
1321 hidden, invoke \"Show\" in the previous line to show." "\
1322 group now hidden, invoke \"Show\", above, to show contents.")
1323 (invalid "x" custom-invalid-face "\
1324 the value displayed for this %c is invalid and cannot be set.")
1325 (modified "*" custom-modified-face "\
1326 you have edited the value as text, but you have not set the %c." "\
1327 you have edited something in this group, but not set it.")
1328 (set "+" custom-set-face "\
1329 you have set this %c, but not saved it for future sessions." "\
1330 something in this group has been set, but not saved.")
1331 (changed ":" custom-changed-face "\
1332 this %c has been changed outside the customize buffer." "\
1333 something in this group has been changed outside customize.")
1334 (saved "!" custom-saved-face "\
1335 this %c has been set and saved." "\
1336 something in this group has been set and saved.")
1337 (rogue "@" custom-rogue-face "\
1338 this %c has not been changed with customize." "\
1339 something in this group is not prepared for customization.")
1340 (standard " " nil "\
1341 this %c is unchanged from its standard setting." "\
1342 visible group members are all at standard settings."))
1343 "Alist of customize option states.
1344 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1346 STATE is one of the following symbols:
1349 For internal use, should never occur.
1351 For internal use, should never occur.
1353 This item is not being displayed.
1355 This item is modified, but has an invalid form.
1357 This item is modified, and has a valid form.
1359 This item has been set but not saved.
1361 The current value of this item has been changed temporarily.
1363 This item is marked for saving.
1365 This item has no customization information.
1367 This item is unchanged from the standard setting.
1369 MAGIC is a string used to present that state.
1371 FACE is a face used to present the state.
1373 ITEM-DESC is a string describing the state for options.
1375 GROUP-DESC is a string describing the state for groups. If this is
1376 left out, ITEM-DESC will be used.
1378 The string %c in either description will be replaced with the
1379 category of the item. These are `group'. `option', and `face'.
1381 The list should be sorted most significant first.")
1383 (defcustom custom-magic-show 'long
1384 "If non-nil, show textual description of the state.
1385 If `long', show a full-line description, not just one word."
1386 :type '(choice (const :tag "no" nil)
1389 :group 'custom-buffer)
1391 (defcustom custom-magic-show-hidden '(option face)
1392 "Control whether the State button is shown for hidden items.
1393 The value should be a list with the custom categories where the State
1394 button should be visible. Possible categories are `group', `option',
1396 :type '(set (const group) (const option) (const face))
1397 :group 'custom-buffer)
1399 (defcustom custom-magic-show-button nil
1400 "Show a \"magic\" button indicating the state of each customization option."
1402 :group 'custom-buffer)
1404 (define-widget 'custom-magic 'default
1405 "Show and manipulate state for a customization option."
1407 :action 'widget-parent-action
1410 :value-create 'custom-magic-value-create
1411 :value-delete 'widget-children-value-delete)
1413 (defun widget-magic-mouse-down-action (widget &optional event)
1414 ;; Non-nil unless hidden.
1415 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1419 (defun custom-magic-value-create (widget)
1420 ;; Create compact status report for WIDGET.
1421 (let* ((parent (widget-get widget :parent))
1422 (state (widget-get parent :custom-state))
1423 (hidden (eq state 'hidden))
1424 (entry (assq state custom-magic-alist))
1425 (magic (nth 1 entry))
1426 (face (nth 2 entry))
1427 (category (widget-get parent :custom-category))
1428 (text (or (and (eq category 'group)
1431 (lisp (eq (widget-get parent :custom-form) 'lisp))
1433 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1434 (setq text (concat (match-string 1 text)
1435 (symbol-name category)
1436 (match-string 2 text))))
1437 (when (and custom-magic-show
1439 (memq category custom-magic-show-hidden)))
1441 (when (and (eq category 'group)
1442 (not (and (eq custom-buffer-style 'links)
1443 (> (widget-get parent :custom-level) 1))))
1444 (insert-char ?\ (* custom-buffer-indent
1445 (widget-get parent :custom-level))))
1446 (push (widget-create-child-and-convert
1448 :help-echo "Change the state of this item."
1449 :format (if hidden "%t" "%[%t%]")
1450 :button-prefix 'widget-push-button-prefix
1451 :button-suffix 'widget-push-button-suffix
1452 :mouse-down-action 'widget-magic-mouse-down-action
1456 (let ((start (point)))
1457 (if (eq custom-magic-show 'long)
1459 (insert (symbol-name state)))
1462 (put-text-property start (point) 'face 'custom-state-face))
1464 (when (and (eq category 'group)
1465 (not (and (eq custom-buffer-style 'links)
1466 (> (widget-get parent :custom-level) 1))))
1467 (insert-char ?\ (* custom-buffer-indent
1468 (widget-get parent :custom-level))))
1469 (when custom-magic-show-button
1470 (when custom-magic-show
1471 (let ((indent (widget-get parent :indent)))
1473 (insert-char ? indent))))
1474 (push (widget-create-child-and-convert
1476 :mouse-down-action 'widget-magic-mouse-down-action
1480 :help-echo "Change the state."
1481 :format (if hidden "%t" "%[%t%]")
1483 (concat "(" magic ")")
1484 (concat "[" magic "]")))
1487 (widget-put widget :children children)))
1489 (defun custom-magic-reset (widget)
1490 "Redraw the :custom-magic property of WIDGET."
1491 (let ((magic (widget-get widget :custom-magic)))
1492 (widget-value-set magic (widget-value magic))))
1494 ;;; The `custom' Widget.
1496 (defface custom-button-face nil
1497 "Face used for buttons in customization buffers."
1498 :group 'custom-faces)
1500 (defface custom-documentation-face nil
1501 "Face used for documentation strings in customization buffers."
1502 :group 'custom-faces)
1504 (defface custom-state-face '((((class color)
1506 (:foreground "lime green"))
1509 (:foreground "dark green"))
1511 "Face used for State descriptions in the customize buffer."
1512 :group 'custom-faces)
1514 (define-widget 'custom 'default
1515 "Customize a user option."
1517 :convert-widget 'custom-convert-widget
1518 :notify 'custom-notify
1521 :custom-state 'hidden
1522 :documentation-property 'widget-subclass-responsibility
1523 :value-create 'widget-subclass-responsibility
1524 :value-delete 'widget-children-value-delete
1525 :value-get 'widget-value-value-get
1526 :validate 'widget-children-validate
1527 :match (lambda (widget value) (symbolp value)))
1529 (defun custom-convert-widget (widget)
1530 ;; Initialize :value and :tag from :args in WIDGET.
1531 (let ((args (widget-get widget :args)))
1533 (widget-put widget :value (widget-apply widget
1534 :value-to-internal (car args)))
1535 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1536 (widget-put widget :args nil)))
1539 (defun custom-notify (widget &rest args)
1540 "Keep track of changes."
1541 (let ((state (widget-get widget :custom-state)))
1542 (unless (eq state 'modified)
1543 (unless (memq state '(nil unknown hidden))
1544 (widget-put widget :custom-state 'modified))
1545 (custom-magic-reset widget)
1546 (apply 'widget-default-notify widget args))))
1548 (defun custom-redraw (widget)
1549 "Redraw WIDGET with current settings."
1550 (let ((line (count-lines (point-min) (point)))
1551 (column (current-column))
1553 (from (marker-position (widget-get widget :from)))
1554 (to (marker-position (widget-get widget :to))))
1556 (widget-value-set widget (widget-value widget))
1557 (custom-redraw-magic widget))
1558 (when (and (>= pos from) (<= pos to))
1563 (goto-line (1+ line)))
1564 (move-to-column column))
1567 (defun custom-redraw-magic (widget)
1568 "Redraw WIDGET state with current settings."
1570 (let ((magic (widget-get widget :custom-magic)))
1572 (widget-value-set magic (widget-value magic))
1573 (when (setq widget (widget-get widget :group))
1574 (custom-group-state-update widget)))
1576 (setq widget nil)))))
1579 (defun custom-show (widget value)
1580 "Non-nil if WIDGET should be shown with VALUE by default."
1581 (let ((show (widget-get widget :custom-show)))
1587 (funcall show widget value)))))
1589 (defvar custom-load-recursion nil
1590 "Hack to avoid recursive dependencies.")
1592 (defun custom-load-symbol (symbol)
1593 "Load all dependencies for SYMBOL."
1594 (unless custom-load-recursion
1595 (let ((custom-load-recursion t)
1596 (loads (get symbol 'custom-loads))
1599 (setq load (car loads)
1601 (cond ((symbolp load)
1605 ;; Don't reload a file already loaded.
1606 ((member load preloaded-file-list))
1607 ((assoc load load-history))
1608 ((assoc (locate-library load) load-history))
1611 ;; Without this, we would load cus-edit recursively.
1612 ;; We are still loading it when we call this,
1613 ;; and it is not in load-history yet.
1614 (or (equal load "cus-edit")
1615 (load-library load))
1618 (defun custom-load-widget (widget)
1619 "Load all dependencies for WIDGET."
1620 (custom-load-symbol (widget-value widget)))
1622 (defun custom-unloaded-symbol-p (symbol)
1623 "Return non-nil if the dependencies of SYMBOL has not yet been loaded."
1625 (loads (get symbol 'custom-loads))
1628 (setq load (car loads)
1630 (cond ((symbolp load)
1631 (unless (featurep load)
1633 ((assoc load load-history))
1634 ((assoc (locate-library load) load-history)
1640 (defun custom-unloaded-widget-p (widget)
1641 "Return non-nil if the dependencies of WIDGET has not yet been loaded."
1642 (custom-unloaded-symbol-p (widget-value widget)))
1644 (defun custom-toggle-hide (widget)
1645 "Toggle visibility of WIDGET."
1646 (custom-load-widget widget)
1647 (let ((state (widget-get widget :custom-state)))
1648 (cond ((memq state '(invalid modified))
1649 (error "There are unset changes"))
1651 (widget-put widget :custom-state 'unknown))
1653 (widget-put widget :documentation-shown nil)
1654 (widget-put widget :custom-state 'hidden)))
1655 (custom-redraw widget)
1658 (defun custom-toggle-parent (widget &rest ignore)
1659 "Toggle visibility of parent of WIDGET."
1660 (custom-toggle-hide (widget-get widget :parent)))
1662 (defun custom-add-see-also (widget &optional prefix)
1663 "Add `See also ...' to WIDGET if there are any links.
1664 Insert PREFIX first if non-nil."
1665 (let* ((symbol (widget-get widget :value))
1666 (links (get symbol 'custom-links))
1667 (many (> (length links) 2))
1668 (buttons (widget-get widget :buttons))
1669 (indent (widget-get widget :indent)))
1672 (insert-char ?\ indent))
1675 (insert "See also ")
1677 (push (widget-create-child-and-convert widget (car links))
1679 (setq links (cdr links))
1688 (widget-put widget :buttons buttons))))
1690 (defun custom-add-parent-links (widget &optional initial-string)
1691 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
1692 The value if non-nil if any parents were found.
1693 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
1694 (let ((name (widget-value widget))
1695 (type (widget-type widget))
1696 (buttons (widget-get widget :buttons))
1699 (insert (or initial-string "Parent groups:"))
1700 (mapatoms (lambda (symbol)
1701 (let ((entry (assq name (get symbol 'custom-group))))
1702 (when (eq (nth 1 entry) type)
1704 (push (widget-create-child-and-convert
1705 widget 'custom-group-link
1706 :tag (custom-unlispify-tag-name symbol)
1710 (widget-put widget :buttons buttons)
1713 (delete-region start (point)))
1716 ;;; The `custom-variable' Widget.
1718 (defface custom-variable-tag-face '((((class color)
1720 (:foreground "light blue" :underline t))
1723 (:foreground "blue" :underline t))
1725 "Face used for unpushable variable tags."
1726 :group 'custom-faces)
1728 (defface custom-variable-button-face '((t (:underline t :bold t)))
1729 "Face used for pushable variable tags."
1730 :group 'custom-faces)
1732 (define-widget 'custom-variable 'custom
1733 "Customize variable."
1735 :help-echo "Set or reset this variable."
1736 :documentation-property 'variable-documentation
1737 :custom-category 'option
1739 :custom-menu 'custom-variable-menu-create
1741 :value-create 'custom-variable-value-create
1742 :action 'custom-variable-action
1743 :custom-set 'custom-variable-set
1744 :custom-save 'custom-variable-save
1745 :custom-reset-current 'custom-redraw
1746 :custom-reset-saved 'custom-variable-reset-saved
1747 :custom-reset-standard 'custom-variable-reset-standard)
1749 (defun custom-variable-type (symbol)
1750 "Return a widget suitable for editing the value of SYMBOL.
1751 If SYMBOL has a `custom-type' property, use that.
1752 Otherwise, look up symbol in `custom-guess-type-alist'."
1753 (let* ((type (or (get symbol 'custom-type)
1754 (and (not (get symbol 'standard-value))
1755 (custom-guess-type symbol))
1757 (options (get symbol 'custom-options))
1758 (tmp (if (listp type)
1759 (copy-sequence type)
1762 (widget-put tmp :options options))
1765 (defun custom-variable-value-create (widget)
1766 "Here is where you edit the variables value."
1767 (custom-load-widget widget)
1768 (let* ((buttons (widget-get widget :buttons))
1769 (children (widget-get widget :children))
1770 (form (widget-get widget :custom-form))
1771 (state (widget-get widget :custom-state))
1772 (symbol (widget-get widget :value))
1773 (tag (widget-get widget :tag))
1774 (type (custom-variable-type symbol))
1775 (conv (widget-convert type))
1776 (get (or (get symbol 'custom-get) 'default-value))
1777 (prefix (widget-get widget :custom-prefix))
1778 (last (widget-get widget :custom-last))
1779 (value (if (default-boundp symbol)
1780 (funcall get symbol)
1781 (widget-get conv :value))))
1782 ;; If the widget is new, the child determine whether it is hidden.
1784 ((custom-show type value)
1785 (setq state 'unknown))
1787 (setq state 'hidden)))
1788 ;; If we don't know the state, see if we need to edit it in lisp form.
1789 (when (eq state 'unknown)
1790 (unless (widget-apply conv :match value)
1791 ;; (widget-apply (widget-convert type) :match value)
1793 ;; Now we can create the child widget.
1794 (cond ((eq custom-buffer-style 'tree)
1795 (insert prefix (if last " `--- " " |--- "))
1796 (push (widget-create-child-and-convert
1797 widget 'custom-browse-variable-tag)
1799 (insert " " tag "\n")
1800 (widget-put widget :buttons buttons))
1802 ;; Indicate hidden value.
1803 (push (widget-create-child-and-convert
1806 :sample-face 'custom-variable-tag-face
1810 (push (widget-create-child-and-convert
1812 :help-echo "Show the value of this option."
1813 :action 'custom-toggle-parent
1817 ;; In lisp mode edit the saved value when possible.
1818 (let* ((value (cond ((get symbol 'saved-value)
1819 (car (get symbol 'saved-value)))
1820 ((get symbol 'standard-value)
1821 (car (get symbol 'standard-value)))
1822 ((default-boundp symbol)
1823 (custom-quote (funcall get symbol)))
1825 (custom-quote (widget-get conv :value))))))
1826 (insert (symbol-name symbol) ": ")
1827 (push (widget-create-child-and-convert
1829 :help-echo "Hide the value of this option."
1830 :action 'custom-toggle-parent
1834 (push (widget-create-child-and-convert
1836 :button-face 'custom-variable-button-face
1838 :tag (symbol-name symbol)
1844 (let* ((format (widget-get type :format))
1845 tag-format value-format)
1846 (unless (string-match ":" format)
1847 (error "Bad format."))
1848 (setq tag-format (substring format 0 (match-end 0)))
1849 (setq value-format (substring format (match-end 0)))
1850 (push (widget-create-child-and-convert
1853 :action 'custom-tag-action
1854 :help-echo "Change value of this option."
1855 :mouse-down-action 'custom-tag-mouse-down-action
1856 :button-face 'custom-variable-button-face
1857 :sample-face 'custom-variable-tag-face
1861 (push (widget-create-child-and-convert
1863 :help-echo "Hide the value of this option."
1864 :action 'custom-toggle-parent
1867 (push (widget-create-child-and-convert
1869 :format value-format
1872 (unless (eq custom-buffer-style 'tree)
1873 ;; Now update the state.
1874 (unless (eq (preceding-char) ?\n)
1875 (widget-insert "\n"))
1876 (if (eq state 'hidden)
1877 (widget-put widget :custom-state state)
1878 (custom-variable-state-set widget))
1879 ;; Create the magic button.
1880 (let ((magic (widget-create-child-and-convert
1881 widget 'custom-magic nil)))
1882 (widget-put widget :custom-magic magic)
1883 (push magic buttons))
1884 ;; Update properties.
1885 (widget-put widget :custom-form form)
1886 (widget-put widget :buttons buttons)
1887 (widget-put widget :children children)
1888 ;; Insert documentation.
1889 (widget-default-format-handler widget ?h)
1891 (unless (eq state 'hidden)
1892 (when (eq (widget-get widget :custom-level) 1)
1893 (custom-add-parent-links widget))
1894 (custom-add-see-also widget)))))
1896 (defun custom-tag-action (widget &rest args)
1897 "Pass :action to first child of WIDGET's parent."
1898 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1901 (defun custom-tag-mouse-down-action (widget &rest args)
1902 "Pass :mouse-down-action to first child of WIDGET's parent."
1903 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
1904 :mouse-down-action args))
1906 (defun custom-variable-state-set (widget)
1907 "Set the state of WIDGET."
1908 (let* ((symbol (widget-value widget))
1909 (get (or (get symbol 'custom-get) 'default-value))
1910 (value (if (default-boundp symbol)
1911 (funcall get symbol)
1912 (widget-get widget :value)))
1914 (state (cond ((setq tmp (get symbol 'customized-value))
1915 (if (condition-case nil
1916 (equal value (eval (car tmp)))
1920 ((setq tmp (get symbol 'saved-value))
1921 (if (condition-case nil
1922 (equal value (eval (car tmp)))
1926 ((setq tmp (get symbol 'standard-value))
1927 (if (condition-case nil
1928 (equal value (eval (car tmp)))
1933 (widget-put widget :custom-state state)))
1935 (defvar custom-variable-menu
1936 '(("Set for Current Session" custom-variable-set
1938 (eq (widget-get widget :custom-state) 'modified)))
1939 ("Save for Future Sessions" custom-variable-save
1941 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
1942 ("Reset to Current" custom-redraw
1944 (and (default-boundp (widget-value widget))
1945 (memq (widget-get widget :custom-state) '(modified changed)))))
1946 ("Reset to Saved" custom-variable-reset-saved
1948 (and (get (widget-value widget) 'saved-value)
1949 (memq (widget-get widget :custom-state)
1950 '(modified set changed rogue)))))
1951 ("Reset to Standard Settings" custom-variable-reset-standard
1953 (and (get (widget-value widget) 'standard-value)
1954 (memq (widget-get widget :custom-state)
1955 '(modified set changed saved rogue)))))
1956 ("---" ignore ignore)
1957 ("Don't show as Lisp expression" custom-variable-edit
1959 (not (eq (widget-get widget :custom-form) 'edit))))
1960 ("Show as Lisp expression" custom-variable-edit-lisp
1962 (not (eq (widget-get widget :custom-form) 'lisp)))))
1963 "Alist of actions for the `custom-variable' widget.
1964 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
1965 the menu entry, ACTION is the function to call on the widget when the
1966 menu is selected, and FILTER is a predicate which takes a `custom-variable'
1967 widget as an argument, and returns non-nil if ACTION is valid on that
1968 widget. If FILTER is nil, ACTION is always valid.")
1970 (defun custom-variable-action (widget &optional event)
1971 "Show the menu for `custom-variable' WIDGET.
1972 Optional EVENT is the location for the menu."
1973 (if (eq (widget-get widget :custom-state) 'hidden)
1974 (custom-toggle-hide widget)
1975 (unless (eq (widget-get widget :custom-state) 'modified)
1976 (custom-variable-state-set widget))
1977 (custom-redraw-magic widget)
1978 (let* ((completion-ignore-case t)
1979 (answer (widget-choose (concat "Operation on "
1980 (custom-unlispify-tag-name
1981 (widget-get widget :value)))
1982 (custom-menu-filter custom-variable-menu
1986 (funcall answer widget)))))
1988 (defun custom-variable-edit (widget)
1989 "Edit value of WIDGET."
1990 (widget-put widget :custom-state 'unknown)
1991 (widget-put widget :custom-form 'edit)
1992 (custom-redraw widget))
1994 (defun custom-variable-edit-lisp (widget)
1995 "Edit the lisp representation of the value of WIDGET."
1996 (widget-put widget :custom-state 'unknown)
1997 (widget-put widget :custom-form 'lisp)
1998 (custom-redraw widget))
2000 (defun custom-variable-set (widget)
2001 "Set the current value for the variable being edited by WIDGET."
2002 (let* ((form (widget-get widget :custom-form))
2003 (state (widget-get widget :custom-state))
2004 (child (car (widget-get widget :children)))
2005 (symbol (widget-value widget))
2006 (set (or (get symbol 'custom-set) 'set-default))
2008 (cond ((eq state 'hidden)
2009 (error "Cannot set hidden variable."))
2010 ((setq val (widget-apply child :validate))
2011 (goto-char (widget-get val :from))
2012 (error "%s" (widget-get val :error)))
2014 (funcall set symbol (eval (setq val (widget-value child))))
2015 (put symbol 'customized-value (list val)))
2017 (funcall set symbol (setq val (widget-value child)))
2018 (put symbol 'customized-value (list (custom-quote val)))))
2019 (custom-variable-state-set widget)
2020 (custom-redraw-magic widget)))
2022 (defun custom-variable-save (widget)
2023 "Set the default value for the variable being edited by WIDGET."
2024 (let* ((form (widget-get widget :custom-form))
2025 (state (widget-get widget :custom-state))
2026 (child (car (widget-get widget :children)))
2027 (symbol (widget-value widget))
2028 (set (or (get symbol 'custom-set) 'set-default))
2030 (cond ((eq state 'hidden)
2031 (error "Cannot set hidden variable."))
2032 ((setq val (widget-apply child :validate))
2033 (goto-char (widget-get val :from))
2034 (error "%s" (widget-get val :error)))
2036 (put symbol 'saved-value (list (widget-value child)))
2037 (funcall set symbol (eval (widget-value child))))
2040 'saved-value (list (custom-quote (widget-value
2042 (funcall set symbol (widget-value child))))
2043 (put symbol 'customized-value nil)
2045 (custom-variable-state-set widget)
2046 (custom-redraw-magic widget)))
2048 (defun custom-variable-reset-saved (widget)
2049 "Restore the saved value for the variable being edited by WIDGET."
2050 (let* ((symbol (widget-value widget))
2051 (set (or (get symbol 'custom-set) 'set-default)))
2052 (if (get symbol 'saved-value)
2054 (funcall set symbol (eval (car (get symbol 'saved-value))))
2056 (error "No saved value for %s" symbol))
2057 (put symbol 'customized-value nil)
2058 (widget-put widget :custom-state 'unknown)
2059 (custom-redraw widget)))
2061 (defun custom-variable-reset-standard (widget)
2062 "Restore the standard setting for the variable being edited by WIDGET."
2063 (let* ((symbol (widget-value widget))
2064 (set (or (get symbol 'custom-set) 'set-default)))
2065 (if (get symbol 'standard-value)
2066 (funcall set symbol (eval (car (get symbol 'standard-value))))
2067 (error "No standard setting known for %S" symbol))
2068 (put symbol 'customized-value nil)
2069 (when (get symbol 'saved-value)
2070 (put symbol 'saved-value nil)
2072 (widget-put widget :custom-state 'unknown)
2073 (custom-redraw widget)))
2075 ;;; The `custom-face-edit' Widget.
2077 (define-widget 'custom-face-edit 'checklist
2078 "Edit face attributes."
2082 :button-args '(:help-echo "Control whether this attribute have any effect.")
2083 :args (mapcar (lambda (att)
2086 :sibling-args (widget-get (nth 1 att) :sibling-args)
2087 (list 'const :format "" :value (nth 0 att))
2089 custom-face-attributes))
2091 ;;; The `custom-display' Widget.
2093 (define-widget 'custom-display 'menu-choice
2094 "Select a display type."
2097 :help-echo "Specify frames where the face attributes should be used."
2098 :args '((const :tag "all" t)
2102 :args ((group :sibling-args (:help-echo "\
2103 Only match the specified window systems.")
2104 (const :format "Type: "
2106 (checklist :inline t
2109 :sibling-args (:help-echo "\
2110 The X11 Window System.")
2112 (const :format "PM "
2113 :sibling-args (:help-echo "\
2114 OS/2 Presentation Manager.")
2116 (const :format "Win32 "
2117 :sibling-args (:help-echo "\
2120 (const :format "DOS "
2121 :sibling-args (:help-echo "\
2124 (const :format "TTY%n"
2125 :sibling-args (:help-echo "\
2126 Plain text terminals.")
2128 (group :sibling-args (:help-echo "\
2129 Only match the frames with the specified color support.")
2130 (const :format "Class: "
2132 (checklist :inline t
2134 (const :format "Color "
2135 :sibling-args (:help-echo "\
2136 Match color frames.")
2138 (const :format "Grayscale "
2139 :sibling-args (:help-echo "\
2140 Match grayscale frames.")
2142 (const :format "Monochrome%n"
2143 :sibling-args (:help-echo "\
2144 Match frames with no color support.")
2146 (group :sibling-args (:help-echo "\
2147 Only match frames with the specified intensity.")
2149 Background brightness: "
2151 (checklist :inline t
2153 (const :format "Light "
2154 :sibling-args (:help-echo "\
2155 Match frames with light backgrounds.")
2157 (const :format "Dark\n"
2158 :sibling-args (:help-echo "\
2159 Match frames with dark backgrounds.")
2162 ;;; The `custom-face' Widget.
2164 (defface custom-face-tag-face '((t (:underline t)))
2165 "Face used for face tags."
2166 :group 'custom-faces)
2168 (define-widget 'custom-face 'custom
2170 :sample-face 'custom-face-tag-face
2171 :help-echo "Set or reset this face."
2172 :documentation-property '(lambda (face)
2173 (face-doc-string face))
2174 :value-create 'custom-face-value-create
2175 :action 'custom-face-action
2176 :custom-category 'face
2177 :custom-form 'selected
2178 :custom-set 'custom-face-set
2179 :custom-save 'custom-face-save
2180 :custom-reset-current 'custom-redraw
2181 :custom-reset-saved 'custom-face-reset-saved
2182 :custom-reset-standard 'custom-face-reset-standard
2183 :custom-menu 'custom-face-menu-create)
2185 (define-widget 'custom-face-all 'editable-list
2186 "An editable list of display specifications and attributes."
2187 :entry-format "%i %d %v"
2188 :insert-button-args '(:help-echo "Insert new display specification here.")
2189 :append-button-args '(:help-echo "Append new display specification here.")
2190 :delete-button-args '(:help-echo "Delete this display specification.")
2191 :args '((group :format "%v" custom-display custom-face-edit)))
2193 (defconst custom-face-all (widget-convert 'custom-face-all)
2194 "Converted version of the `custom-face-all' widget.")
2196 (define-widget 'custom-display-unselected 'item
2197 "A display specification that doesn't match the selected display."
2198 :match 'custom-display-unselected-match)
2200 (defun custom-display-unselected-match (widget value)
2201 "Non-nil if VALUE is an unselected display specification."
2202 (not (face-spec-set-match-display value (selected-frame))))
2204 (define-widget 'custom-face-selected 'group
2205 "Edit the attributes of the selected display in a face specification."
2206 :args '((repeat :format ""
2208 (group custom-display-unselected sexp))
2209 (group (sexp :format "") custom-face-edit)
2214 (defconst custom-face-selected (widget-convert 'custom-face-selected)
2215 "Converted version of the `custom-face-selected' widget.")
2217 (defun custom-face-value-create (widget)
2218 "Create a list of the display specifications for WIDGET."
2219 (let ((buttons (widget-get widget :buttons))
2220 (symbol (widget-get widget :value))
2221 (tag (widget-get widget :tag))
2222 (state (widget-get widget :custom-state))
2224 (is-last (widget-get widget :custom-last))
2225 (prefix (widget-get widget :custom-prefix)))
2227 (setq tag (prin1-to-string symbol)))
2228 (cond ((eq custom-buffer-style 'tree)
2229 (insert prefix (if is-last " `--- " " |--- "))
2230 (push (widget-create-child-and-convert
2231 widget 'custom-browse-face-tag)
2233 (insert " " tag "\n")
2234 (widget-put widget :buttons buttons))
2238 (if (eq custom-buffer-style 'face)
2240 (widget-specify-sample widget begin (point))
2243 (and (string-match "XEmacs" emacs-version)
2244 ;; XEmacs cannot display uninitialized faces.
2245 (not (custom-facep symbol))
2246 (copy-face 'custom-face-empty symbol))
2247 (push (widget-create-child-and-convert widget 'item
2254 (push (widget-create-child-and-convert
2256 :help-echo "Hide or show this face."
2257 :action 'custom-toggle-parent
2258 (not (eq state 'hidden)))
2262 (let ((magic (widget-create-child-and-convert
2263 widget 'custom-magic nil)))
2264 (widget-put widget :custom-magic magic)
2265 (push magic buttons))
2267 (widget-put widget :buttons buttons)
2268 ;; Insert documentation.
2269 (widget-default-format-handler widget ?h)
2271 (unless (eq state 'hidden)
2272 (when (eq (widget-get widget :custom-level) 1)
2273 (custom-add-parent-links widget))
2274 (custom-add-see-also widget))
2276 (unless (eq (preceding-char) ?\n)
2278 (unless (eq state 'hidden)
2279 (message "Creating face editor...")
2280 (custom-load-widget widget)
2281 (let* ((symbol (widget-value widget))
2282 (spec (or (get symbol 'saved-face)
2283 (get symbol 'face-defface-spec)
2284 ;; Attempt to construct it.
2285 (list (list t (custom-face-attributes-get
2286 symbol (selected-frame))))))
2287 (form (widget-get widget :custom-form))
2288 (indent (widget-get widget :indent))
2289 (edit (widget-create-child-and-convert
2291 (cond ((and (eq form 'selected)
2292 (widget-apply custom-face-selected
2294 (when indent (insert-char ?\ indent))
2295 'custom-face-selected)
2296 ((and (not (eq form 'lisp))
2297 (widget-apply custom-face-all
2301 (when indent (insert-char ?\ indent))
2304 (custom-face-state-set widget)
2305 (widget-put widget :children (list edit)))
2306 (message "Creating face editor...done"))))))
2308 (defvar custom-face-menu
2309 '(("Set for Current Session" custom-face-set)
2310 ("Save for Future Sessions" custom-face-save)
2311 ("Reset to Saved" custom-face-reset-saved
2313 (get (widget-value widget) 'saved-face)))
2314 ("Reset to Standard Setting" custom-face-reset-standard
2316 (get (widget-value widget) 'face-defface-spec)))
2317 ("---" ignore ignore)
2318 ("Show all display specs" custom-face-edit-all
2320 (not (eq (widget-get widget :custom-form) 'all))))
2321 ("Just current attributes" custom-face-edit-selected
2323 (not (eq (widget-get widget :custom-form) 'selected))))
2324 ("Show as Lisp expression" custom-face-edit-lisp
2326 (not (eq (widget-get widget :custom-form) 'lisp)))))
2327 "Alist of actions for the `custom-face' widget.
2328 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2329 the menu entry, ACTION is the function to call on the widget when the
2330 menu is selected, and FILTER is a predicate which takes a `custom-face'
2331 widget as an argument, and returns non-nil if ACTION is valid on that
2332 widget. If FILTER is nil, ACTION is always valid.")
2334 (defun custom-face-edit-selected (widget)
2335 "Edit selected attributes of the value of WIDGET."
2336 (widget-put widget :custom-state 'unknown)
2337 (widget-put widget :custom-form 'selected)
2338 (custom-redraw widget))
2340 (defun custom-face-edit-all (widget)
2341 "Edit all attributes of the value of WIDGET."
2342 (widget-put widget :custom-state 'unknown)
2343 (widget-put widget :custom-form 'all)
2344 (custom-redraw widget))
2346 (defun custom-face-edit-lisp (widget)
2347 "Edit the lisp representation of the value of WIDGET."
2348 (widget-put widget :custom-state 'unknown)
2349 (widget-put widget :custom-form 'lisp)
2350 (custom-redraw widget))
2352 (defun custom-face-state-set (widget)
2353 "Set the state of WIDGET."
2354 (let ((symbol (widget-value widget)))
2355 (widget-put widget :custom-state (cond ((get symbol 'customized-face)
2357 ((get symbol 'saved-face)
2359 ((get symbol 'face-defface-spec)
2364 (defun custom-face-action (widget &optional event)
2365 "Show the menu for `custom-face' WIDGET.
2366 Optional EVENT is the location for the menu."
2367 (if (eq (widget-get widget :custom-state) 'hidden)
2368 (custom-toggle-hide widget)
2369 (let* ((completion-ignore-case t)
2370 (symbol (widget-get widget :value))
2371 (answer (widget-choose (concat "Operation on "
2372 (custom-unlispify-tag-name symbol))
2373 (custom-menu-filter custom-face-menu
2377 (funcall answer widget)))))
2379 (defun custom-face-set (widget)
2380 "Make the face attributes in WIDGET take effect."
2381 (let* ((symbol (widget-value widget))
2382 (child (car (widget-get widget :children)))
2383 (value (widget-value child)))
2384 (put symbol 'customized-face value)
2385 (face-spec-set symbol value)
2386 (custom-face-state-set widget)
2387 (custom-redraw-magic widget)))
2389 (defun custom-face-save (widget)
2390 "Make the face attributes in WIDGET default."
2391 (let* ((symbol (widget-value widget))
2392 (child (car (widget-get widget :children)))
2393 (value (widget-value child)))
2394 (face-spec-set symbol value)
2395 (put symbol 'saved-face value)
2396 (put symbol 'customized-face nil)
2397 (custom-face-state-set widget)
2398 (custom-redraw-magic widget)))
2400 (defun custom-face-reset-saved (widget)
2401 "Restore WIDGET to the face's default attributes."
2402 (let* ((symbol (widget-value widget))
2403 (child (car (widget-get widget :children)))
2404 (value (get symbol 'saved-face)))
2406 (error "No saved value for this face"))
2407 (put symbol 'customized-face nil)
2408 (face-spec-set symbol value)
2409 (widget-value-set child value)
2410 (custom-face-state-set widget)
2411 (custom-redraw-magic widget)))
2413 (defun custom-face-reset-standard (widget)
2414 "Restore WIDGET to the face's standard settings."
2415 (let* ((symbol (widget-value widget))
2416 (child (car (widget-get widget :children)))
2417 (value (get symbol 'face-defface-spec)))
2419 (error "No standard setting for this face"))
2420 (put symbol 'customized-face nil)
2421 (when (get symbol 'saved-face)
2422 (put symbol 'saved-face nil)
2424 (face-spec-set symbol value)
2425 (widget-value-set child value)
2426 (custom-face-state-set widget)
2427 (custom-redraw-magic widget)))
2429 ;;; The `face' Widget.
2431 (define-widget 'face 'default
2432 "Select and customize a face."
2433 :convert-widget 'widget-value-convert-widget
2434 :button-prefix 'widget-push-button-prefix
2435 :button-suffix 'widget-push-button-suffix
2436 :format "%t: %[select face%] %v"
2439 :value-create 'widget-face-value-create
2440 :value-delete 'widget-face-value-delete
2441 :value-get 'widget-value-value-get
2442 :validate 'widget-children-validate
2443 :action 'widget-face-action
2444 :match '(lambda (widget value) (symbolp value)))
2446 (defun widget-face-value-create (widget)
2447 ;; Create a `custom-face' child.
2448 (let* ((symbol (widget-value widget))
2449 (custom-buffer-style 'face)
2450 (child (widget-create-child-and-convert
2454 (custom-magic-reset child)
2455 (setq custom-options (cons child custom-options))
2456 (widget-put widget :children (list child))))
2458 (defun widget-face-value-delete (widget)
2459 ;; Remove the child from the options.
2460 (let ((child (car (widget-get widget :children))))
2461 (setq custom-options (delq child custom-options))
2462 (widget-children-value-delete widget)))
2464 (defvar face-history nil
2465 "History of entered face names.")
2467 (defun widget-face-action (widget &optional event)
2468 "Prompt for a face."
2469 (let ((answer (completing-read "Face: "
2470 (mapcar (lambda (face)
2471 (list (symbol-name face)))
2475 (unless (zerop (length answer))
2476 (widget-value-set widget (intern answer))
2477 (widget-apply widget :notify widget event)
2480 ;;; The `hook' Widget.
2482 (define-widget 'hook 'list
2484 :convert-widget 'custom-hook-convert-widget
2487 (defun custom-hook-convert-widget (widget)
2488 ;; Handle `:custom-options'.
2489 (let* ((options (widget-get widget :options))
2490 (other `(editable-list :inline t
2491 :entry-format "%i %d%v"
2492 (function :format " %v")))
2494 (list `(checklist :inline t
2495 ,@(mapcar (lambda (entry)
2496 `(function-item ,entry))
2500 (widget-put widget :args args)
2503 ;;; The `custom-group-link' Widget.
2505 (define-widget 'custom-group-link 'link
2506 "Show parent in other window when activated."
2507 :help-echo "Create customization buffer for this group."
2508 :action 'custom-group-link-action)
2510 (defun custom-group-link-action (widget &rest ignore)
2511 (customize-group (widget-value widget)))
2513 ;;; The `custom-group' Widget.
2515 (defcustom custom-group-tag-faces nil
2516 ;; In XEmacs, this ought to play games with font size.
2517 "Face used for group tags.
2518 The first member is used for level 1 groups, the second for level 2,
2519 and so forth. The remaining group tags are shown with
2520 `custom-group-tag-face'."
2521 :type '(repeat face)
2522 :group 'custom-faces)
2524 (defface custom-group-tag-face-1 '((((class color)
2526 (:foreground "pink" :underline t))
2529 (:foreground "red" :underline t))
2531 "Face used for group tags.")
2533 (defface custom-group-tag-face '((((class color)
2535 (:foreground "light blue" :underline t))
2538 (:foreground "blue" :underline t))
2540 "Face used for low level group tags."
2541 :group 'custom-faces)
2543 (define-widget 'custom-group 'custom
2546 :sample-face-get 'custom-group-sample-face-get
2547 :documentation-property 'group-documentation
2548 :help-echo "Set or reset all members of this group."
2549 :value-create 'custom-group-value-create
2550 :action 'custom-group-action
2551 :custom-category 'group
2552 :custom-set 'custom-group-set
2553 :custom-save 'custom-group-save
2554 :custom-reset-current 'custom-group-reset-current
2555 :custom-reset-saved 'custom-group-reset-saved
2556 :custom-reset-standard 'custom-group-reset-standard
2557 :custom-menu 'custom-group-menu-create)
2559 (defun custom-group-sample-face-get (widget)
2560 ;; Use :sample-face.
2561 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
2562 'custom-group-tag-face))
2564 (define-widget 'custom-group-visibility 'visibility
2565 "An indicator and manipulator for hidden group contents."
2566 :create 'custom-group-visibility-create)
2568 (defun custom-group-visibility-create (widget)
2569 (let ((visible (widget-value widget)))
2571 (insert "--------")))
2572 (widget-default-create widget))
2574 (defun custom-group-members (symbol groups-only)
2575 "Return SYMBOL's custom group members.
2576 If GROUPS-ONLY non-nil, return only those members that are groups."
2577 (if (not groups-only)
2578 (get symbol 'custom-group)
2580 (dolist (entry (get symbol 'custom-group))
2581 (when (eq (nth 1 entry) 'custom-group)
2582 (push entry members)))
2583 (nreverse members))))
2585 (defun custom-group-value-create (widget)
2586 "Insert a customize group for WIDGET in the current buffer."
2587 (let* ((state (widget-get widget :custom-state))
2588 (level (widget-get widget :custom-level))
2589 (indent (widget-get widget :indent))
2590 (prefix (widget-get widget :custom-prefix))
2591 (buttons (widget-get widget :buttons))
2592 (tag (widget-get widget :tag))
2593 (symbol (widget-value widget))
2594 (members (custom-group-members symbol
2595 (and (eq custom-buffer-style 'tree)
2596 custom-browse-only-groups))))
2597 (cond ((and (eq custom-buffer-style 'tree)
2599 (or members (custom-unloaded-widget-p widget)))
2600 (custom-browse-insert-prefix prefix)
2601 (push (widget-create-child-and-convert
2602 widget 'custom-browse-visibility
2603 ;; :tag-glyph "plus"
2607 ;; (widget-glyph-insert nil "-- " "horizontal")
2608 (push (widget-create-child-and-convert
2609 widget 'custom-browse-group-tag)
2611 (insert " " tag "\n")
2612 (widget-put widget :buttons buttons))
2613 ((and (eq custom-buffer-style 'tree)
2614 (zerop (length members)))
2615 (custom-browse-insert-prefix prefix)
2617 ;; (widget-glyph-insert nil "[ ]" "empty")
2618 ;; (widget-glyph-insert nil "-- " "horizontal")
2619 (push (widget-create-child-and-convert
2620 widget 'custom-browse-group-tag)
2622 (insert " " tag "\n")
2623 (widget-put widget :buttons buttons))
2624 ((eq custom-buffer-style 'tree)
2625 (custom-browse-insert-prefix prefix)
2626 (custom-load-widget widget)
2627 (if (zerop (length members))
2629 (custom-browse-insert-prefix prefix)
2631 ;; (widget-glyph-insert nil "[ ]" "empty")
2632 ;; (widget-glyph-insert nil "-- " "horizontal")
2633 (push (widget-create-child-and-convert
2634 widget 'custom-browse-group-tag)
2636 (insert " " tag "\n")
2637 (widget-put widget :buttons buttons))
2638 (push (widget-create-child-and-convert
2639 widget 'custom-browse-visibility
2640 ;; :tag-glyph "minus"
2644 ;; (widget-glyph-insert nil "-\\ " "top")
2645 (push (widget-create-child-and-convert
2646 widget 'custom-browse-group-tag)
2648 (insert " " tag "\n")
2649 (widget-put widget :buttons buttons)
2650 (message "Creating group...")
2651 (let* ((members (custom-sort-items members
2652 custom-browse-sort-alphabetically
2653 custom-browse-order-groups))
2654 (prefixes (widget-get widget :custom-prefixes))
2655 (custom-prefix-list (custom-prefix-add symbol prefixes))
2656 (extra-prefix (if (widget-get widget :custom-last)
2659 (prefix (concat prefix extra-prefix))
2662 (setq entry (car members)
2663 members (cdr members))
2664 (push (widget-create-child-and-convert
2665 widget (nth 1 entry)
2667 :tag (custom-unlispify-tag-name (nth 0 entry))
2668 :custom-prefixes custom-prefix-list
2669 :custom-level (1+ level)
2670 :custom-last (null members)
2671 :value (nth 0 entry)
2672 :custom-prefix prefix)
2674 (widget-put widget :children (reverse children)))
2675 (message "Creating group...done")))
2678 ;; Create level indicator.
2679 (unless (eq custom-buffer-style 'links)
2680 (insert-char ?\ (* custom-buffer-indent (1- level)))
2683 (let ((begin (point)))
2685 (widget-specify-sample widget begin (point)))
2687 ;; Create link/visibility indicator.
2688 (if (eq custom-buffer-style 'links)
2689 (push (widget-create-child-and-convert
2690 widget 'custom-group-link
2694 (push (widget-create-child-and-convert
2695 widget 'group-visibility
2696 :help-echo "Show members of this group."
2697 :action 'custom-toggle-parent
2698 (not (eq state 'hidden)))
2701 ;; Create magic button.
2702 (let ((magic (widget-create-child-and-convert
2703 widget 'custom-magic nil)))
2704 (widget-put widget :custom-magic magic)
2705 (push magic buttons))
2707 (widget-put widget :buttons buttons)
2708 ;; Insert documentation.
2709 (if (and (eq custom-buffer-style 'links) (> level 1))
2710 (widget-put widget :documentation-indent 0))
2711 (widget-default-format-handler widget ?h))
2714 ;; Add parent groups references above the group.
2715 (if t ;;; This should test that the buffer
2716 ;;; was made to display a group.
2718 (if (custom-add-parent-links widget
2719 "Go to parent group:")
2721 ;; Create level indicator.
2722 (insert-char ?\ (* custom-buffer-indent (1- level)))
2725 (let ((start (point)))
2727 (widget-specify-sample widget start (point)))
2729 ;; Create visibility indicator.
2730 (unless (eq custom-buffer-style 'links)
2732 (push (widget-create-child-and-convert
2734 :help-echo "Hide members of this group."
2735 :action 'custom-toggle-parent
2736 (not (eq state 'hidden)))
2739 ;; Create more dashes.
2740 ;; Use 76 instead of 75 to compensate for the temporary "<"
2741 ;; added by `widget-insert'.
2742 (insert-char ?- (- 76 (current-column)
2743 (* custom-buffer-indent level)))
2745 ;; Create magic button.
2746 (let ((magic (widget-create-child-and-convert
2747 widget 'custom-magic
2750 (widget-put widget :custom-magic magic)
2751 (push magic buttons))
2753 (widget-put widget :buttons buttons)
2754 ;; Insert documentation.
2755 (widget-default-format-handler widget ?h)
2757 (if nil ;;; This should test that the buffer
2758 ;;; was not made to display a group.
2760 (insert-char ?\ custom-buffer-indent)
2761 (custom-add-parent-links widget)))
2762 (custom-add-see-also widget
2763 (make-string (* custom-buffer-indent level)
2766 (message "Creating group...")
2767 (custom-load-widget widget)
2768 (let* ((members (custom-sort-items members
2769 custom-buffer-sort-alphabetically
2770 custom-buffer-order-groups))
2771 (prefixes (widget-get widget :custom-prefixes))
2772 (custom-prefix-list (custom-prefix-add symbol prefixes))
2773 (length (length members))
2775 (children (mapcar (lambda (entry)
2776 (widget-insert "\n")
2778 Creating group members... %2d%%"
2779 (/ (* 100.0 count) length))
2780 (setq count (1+ count))
2782 (widget-create-child-and-convert
2783 widget (nth 1 entry)
2785 :tag (custom-unlispify-tag-name
2787 :custom-prefixes custom-prefix-list
2788 :custom-level (1+ level)
2789 :value (nth 0 entry))
2790 (unless (eq (preceding-char) ?\n)
2791 (widget-insert "\n"))))
2793 (message "Creating group magic...")
2794 (mapcar 'custom-magic-reset children)
2795 (message "Creating group state...")
2796 (widget-put widget :children children)
2797 (custom-group-state-update widget)
2798 (message "Creating group... done"))
2801 (insert-char ?\ (* custom-buffer-indent (1- level)))
2802 (insert "\\- " (widget-get widget :tag) " group end ")
2803 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
2806 (defvar custom-group-menu
2807 '(("Set for Current Session" custom-group-set
2809 (eq (widget-get widget :custom-state) 'modified)))
2810 ("Save for Future Sessions" custom-group-save
2812 (memq (widget-get widget :custom-state) '(modified set))))
2813 ("Reset to Current" custom-group-reset-current
2815 (memq (widget-get widget :custom-state) '(modified))))
2816 ("Reset to Saved" custom-group-reset-saved
2818 (memq (widget-get widget :custom-state) '(modified set))))
2819 ("Reset to standard setting" custom-group-reset-standard
2821 (memq (widget-get widget :custom-state) '(modified set saved)))))
2822 "Alist of actions for the `custom-group' widget.
2823 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2824 the menu entry, ACTION is the function to call on the widget when the
2825 menu is selected, and FILTER is a predicate which takes a `custom-group'
2826 widget as an argument, and returns non-nil if ACTION is valid on that
2827 widget. If FILTER is nil, ACTION is always valid.")
2829 (defun custom-group-action (widget &optional event)
2830 "Show the menu for `custom-group' WIDGET.
2831 Optional EVENT is the location for the menu."
2832 (if (eq (widget-get widget :custom-state) 'hidden)
2833 (custom-toggle-hide widget)
2834 (let* ((completion-ignore-case t)
2835 (answer (widget-choose (concat "Operation on "
2836 (custom-unlispify-tag-name
2837 (widget-get widget :value)))
2838 (custom-menu-filter custom-group-menu
2842 (funcall answer widget)))))
2844 (defun custom-group-set (widget)
2845 "Set changes in all modified group members."
2846 (let ((children (widget-get widget :children)))
2847 (mapcar (lambda (child)
2848 (when (eq (widget-get child :custom-state) 'modified)
2849 (widget-apply child :custom-set)))
2852 (defun custom-group-save (widget)
2853 "Save all modified group members."
2854 (let ((children (widget-get widget :children)))
2855 (mapcar (lambda (child)
2856 (when (memq (widget-get child :custom-state) '(modified set))
2857 (widget-apply child :custom-save)))
2860 (defun custom-group-reset-current (widget)
2861 "Reset all modified group members."
2862 (let ((children (widget-get widget :children)))
2863 (mapcar (lambda (child)
2864 (when (eq (widget-get child :custom-state) 'modified)
2865 (widget-apply child :custom-reset-current)))
2868 (defun custom-group-reset-saved (widget)
2869 "Reset all modified or set group members."
2870 (let ((children (widget-get widget :children)))
2871 (mapcar (lambda (child)
2872 (when (memq (widget-get child :custom-state) '(modified set))
2873 (widget-apply child :custom-reset-saved)))
2876 (defun custom-group-reset-standard (widget)
2877 "Reset all modified, set, or saved group members."
2878 (let ((children (widget-get widget :children)))
2879 (mapcar (lambda (child)
2880 (when (memq (widget-get child :custom-state)
2881 '(modified set saved))
2882 (widget-apply child :custom-reset-standard)))
2885 (defun custom-group-state-update (widget)
2887 (unless (eq (widget-get widget :custom-state) 'hidden)
2888 (let* ((children (widget-get widget :children))
2889 (states (mapcar (lambda (child)
2890 (widget-get child :custom-state))
2892 (magics custom-magic-alist)
2895 (let ((magic (car (car magics))))
2896 (if (and (not (eq magic 'hidden))
2897 (memq magic states))
2900 (setq magics (cdr magics)))))
2901 (widget-put widget :custom-state found)))
2902 (custom-magic-reset widget))
2904 ;;; The `custom-save-all' Function.
2906 (defcustom custom-file (if (boundp 'emacs-user-extension-dir)
2909 emacs-user-extension-dir
2912 "File used for storing customization information.
2913 If you change this from the default \"~/.emacs\" you need to
2914 explicitly load that file for the settings to take effect."
2918 (defun custom-save-delete (symbol)
2919 "Delete the call to SYMBOL form `custom-file'.
2920 Leave point at the location of the call, or after the last expression."
2921 (set-buffer (find-file-noselect custom-file))
2922 (goto-char (point-min))
2925 (let ((sexp (condition-case nil
2926 (read (current-buffer))
2927 (end-of-file (throw 'found nil)))))
2928 (when (and (listp sexp)
2929 (eq (car sexp) symbol))
2930 (delete-region (save-excursion
2934 (throw 'found nil))))))
2936 (defun custom-save-variables ()
2937 "Save all customized variables in `custom-file'."
2939 (custom-save-delete 'custom-set-variables)
2940 (let ((standard-output (current-buffer)))
2943 (princ "(custom-set-variables")
2944 (mapatoms (lambda (symbol)
2945 (let ((value (get symbol 'saved-value))
2946 (requests (get symbol 'custom-requests))
2947 (now (not (or (get symbol 'standard-value)
2948 (and (not (boundp symbol))
2949 (not (get symbol 'force-value)))))))
2966 (unless (looking-at "\n")
2969 (defun custom-save-faces ()
2970 "Save all customized faces in `custom-file'."
2972 (custom-save-delete 'custom-set-faces)
2973 (let ((standard-output (current-buffer)))
2976 (princ "(custom-set-faces")
2977 (let ((value (get 'default 'saved-face)))
2978 ;; The default face must be first, since it affects the others.
2980 (princ "\n '(default ")
2982 (if (or (get 'default 'face-defface-spec)
2983 (and (not (custom-facep 'default))
2984 (not (get 'default 'force-face))))
2987 (mapatoms (lambda (symbol)
2988 (let ((value (get symbol 'saved-face)))
2989 (when (and (not (eq symbol 'default))
2990 ;; Don't print default face here.
2996 (if (or (get symbol 'face-defface-spec)
2997 (and (not (custom-facep symbol))
2998 (not (get symbol 'force-face))))
3002 (unless (looking-at "\n")
3006 (defun customize-save-customized ()
3007 "Save all user options which have been set in this session."
3009 (mapatoms (lambda (symbol)
3010 (let ((face (get symbol 'customized-face))
3011 (value (get symbol 'customized-value)))
3013 (put symbol 'saved-face face)
3014 (put symbol 'customized-face nil))
3016 (put symbol 'saved-value value)
3017 (put symbol 'customized-value nil)))))
3018 ;; We really should update all custom buffers here.
3022 (defun custom-save-all ()
3023 "Save all customizations in `custom-file'."
3024 (let ((inhibit-read-only t))
3025 (custom-save-variables)
3028 (set-buffer (find-file-noselect custom-file))
3031 ;;; The Customize Menu.
3035 (defcustom custom-menu-nesting 2
3036 "Maximum nesting in custom menus."
3038 :group 'custom-menu)
3040 (defun custom-face-menu-create (widget symbol)
3041 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
3042 (vector (custom-unlispify-menu-entry symbol)
3043 `(customize-face ',symbol)
3046 (defun custom-variable-menu-create (widget symbol)
3047 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
3048 (let ((type (get symbol 'custom-type)))
3049 (unless (listp type)
3050 (setq type (list type)))
3051 (if (and type (widget-get type :custom-menu))
3052 (widget-apply type :custom-menu symbol)
3053 (vector (custom-unlispify-menu-entry symbol)
3054 `(customize-variable ',symbol)
3057 ;; Add checkboxes to boolean variable entries.
3058 (widget-put (get 'boolean 'widget-type)
3059 :custom-menu (lambda (widget symbol)
3060 (vector (custom-unlispify-menu-entry symbol)
3061 `(customize-variable ',symbol)
3063 ':selected symbol)))
3065 (if (string-match "XEmacs" emacs-version)
3066 ;; XEmacs can create menus dynamically.
3067 (defun custom-group-menu-create (widget symbol)
3068 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3069 `( ,(custom-unlispify-menu-entry symbol t)
3070 :filter (lambda (&rest junk)
3071 (cdr (custom-menu-create ',symbol)))))
3073 (defun custom-group-menu-create (widget symbol)
3074 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
3075 ;; Limit the nesting.
3076 (let ((custom-menu-nesting (1- custom-menu-nesting)))
3077 (custom-menu-create symbol))))
3080 (defun custom-menu-create (symbol)
3081 "Create menu for customization group SYMBOL.
3082 The menu is in a format applicable to `easy-menu-define'."
3083 (let* ((item (vector (custom-unlispify-menu-entry symbol)
3084 `(customize-group ',symbol)
3086 (if (and (or (not (boundp 'custom-menu-nesting))
3087 (>= custom-menu-nesting 0))
3088 (< (length (get symbol 'custom-group)) widget-menu-max-size))
3089 (let ((custom-prefix-list (custom-prefix-add symbol
3090 custom-prefix-list))
3091 (members (custom-sort-items (get symbol 'custom-group)
3092 custom-menu-sort-alphabetically
3093 custom-menu-order-groups)))
3094 (custom-load-symbol symbol)
3095 `(,(custom-unlispify-menu-entry symbol t)
3098 ,@(mapcar (lambda (entry)
3099 (widget-apply (if (listp (nth 1 entry))
3101 (list (nth 1 entry)))
3102 :custom-menu (nth 0 entry)))
3107 (defun customize-menu-create (symbol &optional name)
3108 "Return a customize menu for customization group SYMBOL.
3109 If optional NAME is given, use that as the name of the menu.
3110 Otherwise the menu will be named `Customize'.
3111 The format is suitable for use with `easy-menu-define'."
3113 (setq name "Customize"))
3114 (if (string-match "XEmacs" emacs-version)
3115 ;; We can delay it under XEmacs.
3117 :filter (lambda (&rest junk)
3118 (cdr (custom-menu-create ',symbol))))
3119 ;; But we must create it now under Emacs.
3120 (cons name (cdr (custom-menu-create symbol)))))
3122 ;;; The Custom Mode.
3124 (defvar custom-mode-map nil
3125 "Keymap for `custom-mode'.")
3127 (unless custom-mode-map
3128 (setq custom-mode-map (make-sparse-keymap))
3129 (set-keymap-parent custom-mode-map widget-keymap)
3130 (suppress-keymap custom-mode-map)
3131 (define-key custom-mode-map " " 'scroll-up)
3132 (define-key custom-mode-map "\177" 'scroll-down)
3133 (define-key custom-mode-map "q" 'bury-buffer)
3134 (define-key custom-mode-map "u" 'Custom-goto-parent)
3135 (define-key custom-mode-map "n" 'widget-forward)
3136 (define-key custom-mode-map "p" 'widget-backward)
3137 (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke))
3139 (defun Custom-move-and-invoke (event)
3140 "Move to where you click, and if it is an active field, invoke it."
3142 (mouse-set-point event)
3143 (if (widget-event-point event)
3144 (let* ((pos (widget-event-point event))
3145 (button (get-char-property pos 'button)))
3147 (widget-button-click event)))))
3149 (easy-menu-define Custom-mode-menu
3151 "Menu used in customization buffers."
3153 ,(customize-menu-create 'customize)
3154 ["Set" Custom-set t]
3155 ["Save" Custom-save t]
3156 ["Reset to Current" Custom-reset-current t]
3157 ["Reset to Saved" Custom-reset-saved t]
3158 ["Reset to Standard Settings" Custom-reset-standard t]
3159 ["Info" (Info-goto-node "(custom)The Customization Buffer") t]))
3161 (defun Custom-goto-parent ()
3162 "Go to the parent group listed at the top of this buffer.
3163 If several parents are listed, go to the first of them."
3166 (goto-char (point-min))
3167 (if (search-forward "\nGo to parent group: " nil t)
3168 (let* ((button (get-char-property (point) 'button))
3169 (parent (downcase (widget-get button :tag))))
3170 (customize-group parent)))))
3172 (defcustom custom-mode-hook nil
3173 "Hook called when entering custom-mode."
3175 :group 'custom-buffer )
3177 (defun custom-state-buffer-message (widget)
3178 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
3179 (message "To install your edits, invoke [State] and choose the Set operation")))
3181 (defun custom-mode ()
3182 "Major mode for editing customization buffers.
3184 The following commands are available:
3186 Move to next button or editable field. \\[widget-forward]
3187 Move to previous button or editable field. \\[widget-backward]
3188 \\<widget-field-keymap>\
3189 Complete content of editable text field. \\[widget-complete]
3190 \\<custom-mode-map>\
3191 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3192 Invoke button under point. \\[widget-button-press]
3193 Set all modifications. \\[Custom-set]
3194 Make all modifications default. \\[Custom-save]
3195 Reset all modified options. \\[Custom-reset-current]
3196 Reset all modified or set options. \\[Custom-reset-saved]
3197 Reset all options. \\[Custom-reset-standard]
3199 Entry to this mode calls the value of `custom-mode-hook'
3200 if that value is non-nil."
3201 (kill-all-local-variables)
3202 (setq major-mode 'custom-mode
3204 (use-local-map custom-mode-map)
3205 (easy-menu-add Custom-mode-menu)
3206 (make-local-variable 'custom-options)
3207 (make-local-variable 'widget-documentation-face)
3208 (setq widget-documentation-face 'custom-documentation-face)
3209 (make-local-variable 'widget-button-face)
3210 (setq widget-button-face 'custom-button-face)
3211 (make-local-hook 'widget-edit-functions)
3212 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3213 (run-hooks 'custom-mode-hook))
3219 ;; cus-edit.el ends here