1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, 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.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist) ; from cus-load
146 (defvar recentf-exclude)) ; from recentf.el
156 (put 'custom-define-hook 'custom-type 'hook)
157 (put 'custom-define-hook 'standard-value '(nil))
158 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link '(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link '(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
221 "Support for the C language and related languages."
222 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
223 :link '(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group 'applications)
243 "Modes for electronic-mail handling."
244 :group 'applications)
247 "Support for netnews reading and posting."
248 :link '(custom-manual "(gnus)")
249 :group 'applications)
252 "Games, jokes and amusements."
253 :group 'applications)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link '(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize '((widgets custom-group))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link '(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag "Storage Allocation"
388 "Undoing changes in buffers."
389 :link '(custom-manual "(emacs)Undo")
392 (defgroup modeline nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controling the behavior of the minibuffer."
426 :link '(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidential loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link '(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link '(custom-manual "(emacs)Mac OS")
471 (defun custom-quote (sexp)
472 "Quote SEXP iff it is not self quoting."
473 (if (or (memq sexp '(t nil))
476 (memq (car sexp) '(lambda)))
480 ;;; (and (fboundp 'characterp)
481 ;;; (characterp sexp))
486 (defun custom-split-regexp-maybe (regexp)
487 "If REGEXP is a string, split it to a list at `\\|'.
488 You can get the original back with from the result with:
489 (mapconcat 'identity result \"\\|\")
491 IF REGEXP is not a string, return it unchanged."
495 (while (string-match "\\\\|" regexp start)
496 (setq all (cons (substring regexp start (match-beginning 0)) all)
497 start (match-end 0)))
498 (nreverse (cons (substring regexp start) all)))
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
506 (enable-recursive-minibuffers t)
508 (setq val (completing-read
509 (if default (format "Customize variable (default %s): " default)
510 "Customize variable: ")
511 obarray 'custom-variable-p t nil nil default))
512 (list (if (equal val "")
513 (if (symbolp v) v nil)
516 (defun custom-menu-filter (menu widget)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
521 current name action filter)
523 (setq current (car menu)
525 action (nth 1 current)
526 filter (nth 2 current)
528 (if (or (null filter) (funcall filter widget))
529 (push (cons name action) result)
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non nil."
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
546 :group 'custom-buffer
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries)
552 (symbol-name symbol))
553 ((get symbol 'custom-tag)
555 (get symbol 'custom-tag)
556 (concat (get symbol 'custom-tag) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
560 (princ symbol (current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list)
572 (setq prefix (car prefixes))
573 (if (search-forward prefix (+ (point) (length prefix)) t)
576 (delete-region (point-min) (point)))
577 (setq prefixes (cdr prefixes))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
579 (capitalize-region (point-min) (point-max))
581 (goto-char (point-max))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non nil."
587 :group 'custom-buffer
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
593 (custom-unlispify-menu-entry symbol t)))
595 (defun custom-prefix-add (symbol prefixes)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol 'custom-prefix)
598 (concat (symbol-name symbol) "-"))
603 (defcustom custom-guess-name-alist
608 ("-function\\'" function)
609 ("-functions\\'" (repeat function))
610 ("-list\\'" (repeat sexp))
611 ("-alist\\'" (repeat (cons sexp sexp))))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching the name of a symbol, and TYPE should
615 be a widget suitable for editing the value of that symbol. The TYPE
616 of the first entry where MATCH matches the name of the symbol will be
619 This is used for guessing the type of variables not declared with
621 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
624 (defcustom custom-guess-doc-alist
625 '(("\\`\\*?Non-nil " boolean))
626 "Alist of (MATCH TYPE).
628 MATCH should be a regexp matching a documentation string, and TYPE
629 should be a widget suitable for editing the value of a variable with
630 that documentation string. The TYPE of the first entry where MATCH
631 matches the name of the symbol will be used.
633 This is used for guessing the type of variables not declared with
635 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
638 (defun custom-guess-type (symbol)
639 "Guess a widget suitable for editing the value of SYMBOL.
640 This is done by matching SYMBOL with `custom-guess-name-alist' and
641 if that fails, the doc string with `custom-guess-doc-alist'."
642 (let ((name (symbol-name symbol))
643 (names custom-guess-name-alist)
646 (setq current (car names)
648 (when (string-match (nth 0 current) name)
649 (setq found (nth 1 current)
652 (let ((doc (documentation-property symbol 'variable-documentation))
653 (docs custom-guess-doc-alist))
656 (setq current (car docs)
658 (when (string-match (nth 0 current) doc)
659 (setq found (nth 1 current)
665 (defcustom custom-browse-sort-alphabetically nil
666 "If non-nil, sort members of each customization group alphabetically."
668 :group 'custom-browse)
670 (defcustom custom-browse-order-groups nil
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type '(choice (const first)
676 (const :tag "none" nil))
677 :group 'custom-browse)
679 (defcustom custom-browse-only-groups nil
680 "If non-nil, show group members only within each customization group."
682 :group 'custom-browse)
684 (defcustom custom-buffer-sort-alphabetically nil
685 "If non-nil, sort members of each customization group alphabetically."
687 :group 'custom-buffer)
689 (defcustom custom-buffer-order-groups 'last
690 "If non-nil, order group members within each customization group.
691 If `first', order groups before non-groups.
692 If `last', order groups after non-groups."
693 :type '(choice (const first)
695 (const :tag "none" nil))
696 :group 'custom-buffer)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort members of each customization group alphabetically."
703 (defcustom custom-menu-order-groups 'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type '(choice (const first)
709 (const :tag "none" nil))
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items)
722 (let ((typea (nth 1 a)) (typeb (nth 1 b))
723 (namea (nth 0 a)) (nameb (nth 0 b)))
724 (cond ((not order-groups)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb)))
728 ((eq typea 'custom-group)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb 'custom-group)
731 (when sort-alphabetically
732 (string-lessp namea nameb))
733 (eq order-groups 'first)))
734 ((eq typeb 'custom-group)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups 'last))
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb)))))))
741 ;;; Custom Mode Commands.
743 (defvar custom-options nil
744 "Customization widgets in the current buffer.")
747 "Set changes in all modified options."
749 (let ((children custom-options))
750 (mapc (lambda (child)
751 (when (eq (widget-get child :custom-state) 'modified)
752 (widget-apply child :custom-set)))
755 (defun Custom-save ()
756 "Set all modified group members and save them."
758 (let ((children custom-options))
759 (mapc (lambda (child)
760 (when (memq (widget-get child :custom-state)
761 '(modified set changed rogue))
762 (widget-apply child :custom-save)))
766 (defvar custom-reset-menu
767 '(("Current" . Custom-reset-current)
768 ("Saved" . Custom-reset-saved)
769 ("Erase Customization (use standard values)" . Custom-reset-standard))
770 "Alist of actions for the `Reset' button.
771 The key is a string containing the name of the action, the value is a
772 Lisp function taking the widget as an element which will be called
773 when the action is chosen.")
775 (defun custom-reset (event)
776 "Select item from reset menu."
777 (let* ((completion-ignore-case t)
778 (answer (widget-choose "Reset to"
784 (defun Custom-reset-current (&rest ignore)
785 "Reset all modified group members to their current value."
787 (let ((children custom-options))
788 (mapc (lambda (widget)
789 (if (memq (widget-get widget :custom-state)
791 (widget-apply widget :custom-reset-current)))
794 (defun Custom-reset-saved (&rest ignore)
795 "Reset all modified or set group members to their saved value."
797 (let ((children custom-options))
798 (mapc (lambda (widget)
799 (if (memq (widget-get widget :custom-state)
800 '(modified set changed rogue))
801 (widget-apply widget :custom-reset-saved)))
804 (defun Custom-reset-standard (&rest ignore)
805 "Erase all customization (either current or saved) for the group members.
806 The immediate result is to restore them to their standard values.
807 This operation eliminates any saved values for the group members,
808 making them as if they had never been customized at all."
810 (let ((children custom-options))
811 (when (or (and (= 1 (length children))
812 (memq (widget-type (car children))
813 '(custom-variable custom-face)))
814 (yes-or-no-p "Really erase all customizations in this buffer? "))
815 (mapc (lambda (widget)
816 (and (if (widget-get widget :custom-standard-value)
817 (widget-apply widget :custom-standard-value)
819 (memq (widget-get widget :custom-state)
820 '(modified set changed saved rogue))
821 (widget-apply widget :custom-reset-standard)))
824 ;;; The Customize Commands
826 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
827 "Prompt for a variable and a value and return them as a list.
828 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
829 prompt for the value. The %s escape in PROMPT-VAL is replaced with
830 the name of the variable.
832 If the variable has a `variable-interactive' property, that is used as if
833 it were the arg to `interactive' (which see) to interactively read the value.
835 If the variable has a `custom-type' property, it must be a widget and the
836 `:prompt-value' property of that widget will be used for reading the value.
838 If optional COMMENT argument is non nil, also prompt for a comment and return
839 it as the third element in the list."
840 (let* ((var (read-variable prompt-var))
841 (minibuffer-help-form '(describe-variable var))
843 (let ((prop (get var 'variable-interactive))
844 (type (get var 'custom-type))
845 (prompt (format prompt-val var)))
847 (setq type (list type)))
849 ;; Use VAR's `variable-interactive' property
850 ;; as an interactive spec for prompting.
851 (call-interactively (list 'lambda '(arg)
852 (list 'interactive prop)
855 (widget-prompt-value type
861 (eval-minibuffer prompt))))))
864 (read-string "Comment: " (get var 'variable-comment)))
868 (defun customize-set-value (variable value &optional comment)
869 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
871 If VARIABLE has a `variable-interactive' property, that is used as if
872 it were the arg to `interactive' (which see) to interactively read the value.
874 If VARIABLE has a `custom-type' property, it must be a widget and the
875 `:prompt-value' property of that widget will be used for reading the value.
877 If given a prefix (or a COMMENT argument), also prompt for a comment."
878 (interactive (custom-prompt-variable "Set variable: "
882 (cond ((string= comment "")
883 (put variable 'variable-comment nil))
885 (put variable 'variable-comment comment)))
886 (set variable value))
889 (defun customize-set-variable (variable value &optional comment)
890 "Set the default for VARIABLE to VALUE, and return VALUE.
891 VALUE is a Lisp object.
893 If VARIABLE has a `custom-set' property, that is used for setting
894 VARIABLE, otherwise `set-default' is used.
896 The `customized-value' property of the VARIABLE will be set to a list
897 with a quoted VALUE as its sole list member.
899 If VARIABLE has a `variable-interactive' property, that is used as if
900 it were the arg to `interactive' (which see) to interactively read the value.
902 If VARIABLE has a `custom-type' property, it must be a widget and the
903 `:prompt-value' property of that widget will be used for reading the value.
905 If given a prefix (or a COMMENT argument), also prompt for a comment."
906 (interactive (custom-prompt-variable "Set variable: "
907 "Set customized value for %s to: "
909 (custom-load-symbol variable)
910 (funcall (or (get variable 'custom-set) 'set-default) variable value)
911 (put variable 'customized-value (list (custom-quote value)))
912 (cond ((string= comment "")
913 (put variable 'variable-comment nil)
914 (put variable 'customized-variable-comment nil))
916 (put variable 'variable-comment comment)
917 (put variable 'customized-variable-comment comment)))
921 (defun customize-save-variable (variable value &optional comment)
922 "Set the default for VARIABLE to VALUE, and save it for future sessions.
925 If VARIABLE has a `custom-set' property, that is used for setting
926 VARIABLE, otherwise `set-default' is used.
928 The `customized-value' property of the VARIABLE will be set to a list
929 with a quoted VALUE as its sole list member.
931 If VARIABLE has a `variable-interactive' property, that is used as if
932 it were the arg to `interactive' (which see) to interactively read the value.
934 If VARIABLE has a `custom-type' property, it must be a widget and the
935 `:prompt-value' property of that widget will be used for reading the value.
937 If given a prefix (or a COMMENT argument), also prompt for a comment."
938 (interactive (custom-prompt-variable "Set and save variable: "
939 "Set and save value for %s as: "
941 (funcall (or (get variable 'custom-set) 'set-default) variable value)
942 (put variable 'saved-value (list (custom-quote value)))
943 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
944 (cond ((string= comment "")
945 (put variable 'variable-comment nil)
946 (put variable 'saved-variable-comment nil))
948 (put variable 'variable-comment comment)
949 (put variable 'saved-variable-comment comment)))
955 "Select a customization buffer which you can use to set user options.
956 User options are structured into \"groups\".
957 Initially the top-level group `Emacs' and its immediate subgroups
958 are shown; the contents of those subgroups are initially hidden."
960 (customize-group 'emacs))
963 (defun customize-mode (mode)
964 "Customize options related to the current major mode.
965 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
966 then prompt for the MODE to customize."
969 (let ((completion-regexp-list '("-mode\\'"))
970 (group (custom-group-of-mode major-mode)))
971 (if (and group (not current-prefix-arg))
974 (completing-read (if group
975 (format "Major mode (default %s): " major-mode)
978 'custom-group-of-mode
979 t nil nil (if group (symbol-name major-mode))))))))
980 (customize-group (custom-group-of-mode mode)))
984 (defun customize-group (group)
985 "Customize GROUP, which must be a customization group."
987 (list (let ((completion-ignore-case t))
988 (completing-read "Customize group (default emacs): "
991 (or (and (get symbol 'custom-loads)
992 (not (get symbol 'custom-autoload)))
993 (get symbol 'custom-group)))
995 (when (stringp group)
996 (if (string-equal "" group)
998 (setq group (intern group))))
999 (let ((name (format "*Customize Group: %s*"
1000 (custom-unlispify-tag-name group))))
1001 (if (get-buffer name)
1002 (pop-to-buffer name)
1003 (custom-buffer-create (list (list group 'custom-group))
1005 (concat " for group "
1006 (custom-unlispify-tag-name group))))))
1009 (defun customize-group-other-window (group)
1010 "Customize GROUP, which must be a customization group."
1012 (list (let ((completion-ignore-case t))
1013 (completing-read "Customize group (default emacs): "
1016 (or (and (get symbol 'custom-loads)
1017 (not (get symbol 'custom-autoload)))
1018 (get symbol 'custom-group)))
1020 (when (stringp group)
1021 (if (string-equal "" group)
1023 (setq group (intern group))))
1024 (let ((name (format "*Customize Group: %s*"
1025 (custom-unlispify-tag-name group))))
1026 (if (get-buffer name)
1028 ;; Copied from `custom-buffer-create-other-window'.
1030 (same-window-buffer-names nil)
1031 (same-window-regexps nil))
1032 (pop-to-buffer name))
1033 (custom-buffer-create-other-window
1034 (list (list group 'custom-group))
1036 (concat " for group "
1037 (custom-unlispify-tag-name group))))))
1040 (defalias 'customize-variable 'customize-option)
1043 (defun customize-option (symbol)
1044 "Customize SYMBOL, which must be a user option variable."
1045 (interactive (custom-variable-prompt))
1046 (let ((basevar (indirect-variable symbol)))
1047 (custom-buffer-create (list (list basevar 'custom-variable))
1048 (format "*Customize Option: %s*"
1049 (custom-unlispify-tag-name basevar)))
1050 (unless (eq symbol basevar)
1051 (message "`%s' is an alias for `%s'" symbol basevar))))
1054 (defalias 'customize-variable-other-window 'customize-option-other-window)
1057 (defun customize-option-other-window (symbol)
1058 "Customize SYMBOL, which must be a user option variable.
1059 Show the buffer in another window, but don't select it."
1060 (interactive (custom-variable-prompt))
1061 (let ((basevar (indirect-variable symbol)))
1062 (custom-buffer-create-other-window
1063 (list (list basevar 'custom-variable))
1064 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1065 (unless (eq symbol basevar)
1066 (message "`%s' is an alias for `%s'" symbol basevar))))
1068 (defvar customize-changed-options-previous-release "21.1"
1069 "Version for `customize-changed-options' to refer back to by default.")
1072 (defalias 'customize-changed 'customize-changed-options)
1075 (defun customize-changed-options (since-version)
1076 "Customize all settings whose meanings have changed in Emacs itself.
1077 This includes new user option variables and faces, and new
1078 customization groups, as well as older options and faces whose meanings
1079 or default values have changed since the previous major Emacs release.
1081 With argument SINCE-VERSION (a string), customize all settings
1082 that were added or redefined since that version."
1084 (interactive "sCustomize options changed, since version (default all versions): ")
1085 (if (equal since-version "")
1086 (setq since-version nil)
1087 (unless (condition-case nil
1088 (numberp (read since-version))
1090 (signal 'wrong-type-argument (list 'numberp since-version))))
1091 (unless since-version
1092 (setq since-version customize-changed-options-previous-release))
1094 ;; Load the information for versions since since-version. We use
1095 ;; custom-load-symbol for this.
1096 (put 'custom-versions-load-alist 'custom-loads nil)
1097 (dolist (elt custom-versions-load-alist)
1098 (if (customize-version-lessp since-version (car elt))
1099 (dolist (load (cdr elt))
1100 (custom-add-load 'custom-versions-load-alist load))))
1101 (custom-load-symbol 'custom-versions-load-alist)
1102 (put 'custom-versions-load-alist 'custom-loads nil)
1107 (let ((version (get symbol 'custom-version)))
1109 (when (customize-version-lessp since-version version)
1110 (if (or (get symbol 'custom-group)
1111 (get symbol 'group-documentation))
1112 (push (list symbol 'custom-group) found))
1113 (if (custom-variable-p symbol)
1114 (push (list symbol 'custom-variable) found))
1115 (if (custom-facep symbol)
1116 (push (list symbol 'custom-face) found)))))))
1118 (custom-buffer-create (custom-sort-items found t 'first)
1119 "*Customize Changed Options*")
1120 (error "No user option defaults have been changed since Emacs %s"
1123 (defun customize-version-lessp (version1 version2)
1124 ;; Why are the versions strings, and given that they are, why aren't
1125 ;; they converted to numbers and compared as such here? -- fx
1127 ;; In case someone made a mistake and left out the quotes
1128 ;; in the :version value.
1129 (if (numberp version2)
1130 (setq version2 (prin1-to-string version2)))
1131 (let (major1 major2 minor1 minor2)
1132 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1133 (setq major1 (read (or (match-string 1 version1)
1135 (setq minor1 (read (or (match-string 3 version1)
1137 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1138 (setq major2 (read (or (match-string 1 version2)
1140 (setq minor2 (read (or (match-string 3 version2)
1142 (or (< major1 major2)
1143 (and (= major1 major2)
1144 (< minor1 minor2)))))
1147 (defun customize-face (&optional face)
1148 "Customize FACE, which should be a face name or nil.
1149 If FACE is nil, customize all faces. If FACE is actually a
1150 face-alias, customize the face it is aliased to.
1152 Interactively, when point is on text which has a face specified,
1153 suggest to customize that face, if it's customizable."
1155 (list (read-face-name "Customize face" "all faces" t)))
1156 (if (member face '(nil ""))
1157 (setq face (face-list)))
1158 (if (and (listp face) (null (cdr face)))
1159 (setq face (car face)))
1161 (custom-buffer-create (custom-sort-items
1163 (list s 'custom-face))
1166 "*Customize Faces*")
1167 ;; If FACE is actually an alias, customize the face it is aliased to.
1168 (if (get face 'face-alias)
1169 (setq face (get face 'face-alias)))
1170 (unless (facep face)
1171 (error "Invalid face %S" face))
1172 (custom-buffer-create (list (list face 'custom-face))
1173 (format "*Customize Face: %s*"
1174 (custom-unlispify-tag-name face)))))
1177 (defun customize-face-other-window (&optional face)
1178 "Show customization buffer for face FACE in other window.
1179 If FACE is actually a face-alias, customize the face it is aliased to.
1181 Interactively, when point is on text which has a face specified,
1182 suggest to customize that face, if it's customizable."
1184 (list (read-face-name "Customize face" "all faces" t)))
1185 (if (member face '(nil ""))
1186 (setq face (face-list)))
1187 (if (and (listp face) (null (cdr face)))
1188 (setq face (car face)))
1190 (custom-buffer-create-other-window
1193 (list s 'custom-face))
1196 "*Customize Faces*")
1197 (if (get face 'face-alias)
1198 (setq face (get face 'face-alias)))
1199 (unless (facep face)
1200 (error "Invalid face %S" face))
1201 (custom-buffer-create-other-window
1202 (list (list face 'custom-face))
1203 (format "*Customize Face: %s*"
1204 (custom-unlispify-tag-name face)))))
1207 (defun customize-customized ()
1208 "Customize all user options set since the last save in this session."
1211 (mapatoms (lambda (symbol)
1212 (and (or (get symbol 'customized-face)
1213 (get symbol 'customized-face-comment))
1214 (custom-facep symbol)
1215 (push (list symbol 'custom-face) found))
1216 (and (or (get symbol 'customized-value)
1217 (get symbol 'customized-variable-comment))
1219 (push (list symbol 'custom-variable) found))))
1221 (error "No customized user options")
1222 (custom-buffer-create (custom-sort-items found t nil)
1223 "*Customize Customized*"))))
1226 (defun customize-rogue ()
1227 "Customize all user variable modified outside customize."
1230 (mapatoms (lambda (symbol)
1231 (let ((cval (or (get symbol 'customized-value)
1232 (get symbol 'saved-value)
1233 (get symbol 'standard-value))))
1234 (when (and cval ;Declared with defcustom.
1235 (default-boundp symbol) ;Has a value.
1236 (not (equal (eval (car cval))
1237 ;; Which does not match customize.
1238 (default-value symbol))))
1239 (push (list symbol 'custom-variable) found)))))
1241 (error "No rogue user options")
1242 (custom-buffer-create (custom-sort-items found t nil)
1243 "*Customize Rogue*"))))
1245 (defun customize-saved ()
1246 "Customize all already saved user options."
1249 (mapatoms (lambda (symbol)
1250 (and (or (get symbol 'saved-face)
1251 (get symbol 'saved-face-comment))
1252 (custom-facep symbol)
1253 (push (list symbol 'custom-face) found))
1254 (and (or (get symbol 'saved-value)
1255 (get symbol 'saved-variable-comment))
1257 (push (list symbol 'custom-variable) found))))
1259 (error "No saved user options")
1260 (custom-buffer-create (custom-sort-items found t nil)
1261 "*Customize Saved*"))))
1264 (defun customize-apropos (regexp &optional all)
1265 "Customize all loaded options, faces and groups matching REGEXP.
1266 If ALL is `options', include only options.
1267 If ALL is `faces', include only faces.
1268 If ALL is `groups', include only groups.
1269 If ALL is t (interactively, with prefix arg), include variables
1270 that are not customizable options, as well as faces and groups
1271 \(but we recommend using `apropos-variable' instead)."
1272 (interactive "sCustomize regexp: \nP")
1274 (mapatoms (lambda (symbol)
1275 (when (string-match regexp (symbol-name symbol))
1276 (when (and (not (memq all '(faces options)))
1277 (get symbol 'custom-group))
1278 (push (list symbol 'custom-group) found))
1279 (when (and (not (memq all '(options groups)))
1280 (custom-facep symbol))
1281 (push (list symbol 'custom-face) found))
1282 (when (and (not (memq all '(groups faces)))
1284 (eq (indirect-variable symbol) symbol)
1285 (or (get symbol 'saved-value)
1286 (custom-variable-p symbol)
1287 (and (not (memq all '(nil options)))
1288 (get symbol 'variable-documentation))))
1289 (push (list symbol 'custom-variable) found)))))
1291 (error "No matches")
1292 (custom-buffer-create (custom-sort-items found t
1293 custom-buffer-order-groups)
1294 "*Customize Apropos*"))))
1297 (defun customize-apropos-options (regexp &optional arg)
1298 "Customize all loaded customizable options matching REGEXP.
1299 With prefix arg, include variables that are not customizable options
1300 \(but we recommend using `apropos-variable' instead)."
1301 (interactive "sCustomize regexp: \nP")
1302 (customize-apropos regexp (or arg 'options)))
1305 (defun customize-apropos-faces (regexp)
1306 "Customize all loaded faces matching REGEXP."
1307 (interactive "sCustomize regexp: \n")
1308 (customize-apropos regexp 'faces))
1311 (defun customize-apropos-groups (regexp)
1312 "Customize all loaded groups matching REGEXP."
1313 (interactive "sCustomize regexp: \n")
1314 (customize-apropos regexp 'groups))
1318 (defcustom custom-buffer-style 'links
1319 "Control the presentation style for customization buffers.
1320 The value should be a symbol, one of:
1322 brackets: groups nest within each other with big horizontal brackets.
1323 links: groups have links to subgroups."
1324 :type '(radio (const brackets)
1326 :group 'custom-buffer)
1328 (defcustom custom-buffer-done-kill nil
1329 "*Non-nil means exiting a Custom buffer should kill it."
1332 :group 'custom-buffer)
1334 (defcustom custom-buffer-indent 3
1335 "Number of spaces to indent nested groups."
1337 :group 'custom-buffer)
1339 (defun custom-get-fresh-buffer (name)
1340 "Get a fresh new buffer with name NAME.
1341 If the buffer already exist, clean it up to be like new.
1342 Beware: it's not quite like new. Good enough for custom, but maybe
1344 ;; To be more complete, we should also kill all permanent-local variables,
1345 ;; but it's not needed for custom.
1346 (let ((buf (get-buffer name)))
1347 (when (and buf (buffer-local-value 'buffer-file-name buf))
1348 ;; This will check if the file is not saved.
1352 (get-buffer-create name)
1353 (with-current-buffer buf
1354 (kill-all-local-variables)
1355 (run-hooks 'kill-buffer-hook)
1356 ;; Delete overlays before erasing the buffer so the overlay hooks
1357 ;; don't get run spuriously when we erase the buffer.
1358 (let ((ols (overlay-lists)))
1359 (dolist (ol (nconc (car ols) (cdr ols)))
1360 (delete-overlay ol)))
1365 (defun custom-buffer-create (options &optional name description)
1366 "Create a buffer containing OPTIONS.
1367 Optional NAME is the name of the buffer.
1368 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1369 SYMBOL is a customization option, and WIDGET is a widget for editing
1371 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1372 (custom-buffer-create-internal options description))
1375 (defun custom-buffer-create-other-window (options &optional name description)
1376 "Create a buffer containing OPTIONS, and display it in another window.
1377 The result includes selecting that window.
1378 Optional NAME is the name of the buffer.
1379 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1380 SYMBOL is a customization option, and WIDGET is a widget for editing
1382 (unless name (setq name "*Customization*"))
1383 (let ((pop-up-windows t)
1384 (same-window-buffer-names nil)
1385 (same-window-regexps nil))
1386 (pop-to-buffer (custom-get-fresh-buffer name))
1387 (custom-buffer-create-internal options description)))
1389 (defcustom custom-reset-button-menu nil
1390 "If non-nil, only show a single reset button in customize buffers.
1391 This button will have a menu with all three reset operations."
1393 :group 'custom-buffer)
1395 (defcustom custom-buffer-verbose-help t
1396 "If non-nil, include explanatory text in the customization buffer."
1398 :group 'custom-buffer)
1400 (defun Custom-buffer-done (&rest ignore)
1401 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1403 (quit-window custom-buffer-done-kill))
1405 (defvar custom-button nil
1406 "Face used for buttons in customization buffers.")
1408 (defvar custom-button-pressed nil
1409 "Face used for pressed buttons in customization buffers.")
1411 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1412 '(("unspecified" . unspecified))))
1413 "If non-nil, indicate active buttons in a `raised-button' style.
1414 Otherwise use brackets."
1417 :group 'custom-buffer
1418 :set (lambda (variable value)
1419 (custom-set-default variable value)
1421 (if value 'custom-button 'custom-button-unraised))
1422 (setq custom-button-pressed
1424 'custom-button-pressed
1425 'custom-button-pressed-unraised))))
1427 (defun custom-buffer-create-internal (options &optional description)
1429 (if custom-buffer-verbose-help
1431 (widget-insert "This is a customization buffer")
1433 (widget-insert description))
1434 (widget-insert (format ".
1435 %s buttons; type RET or click mouse-1 to actuate one.
1436 Editing a setting changes only the text in the buffer.
1437 Use the setting's State button to set it or save changes in it.
1438 Saving a change normally works by editing your Emacs init file.
1440 (if custom-raised-buttons
1441 "`Raised' text indicates"
1442 "Square brackets indicate")))
1443 (widget-create 'info-link
1445 "(emacs)Saving Customizations")
1447 " for information on how to save in a different file.\n
1449 (widget-create 'info-link
1451 :help-echo "Read the online help."
1452 "(emacs)Easy Customization")
1453 (widget-insert " for more information.\n\n")
1454 (widget-insert "Operate on everything in this buffer:\n "))
1455 (widget-insert " "))
1456 (widget-create 'push-button
1457 :tag "Set for Current Session"
1459 Make your editing in this buffer take effect for this session."
1460 :action (lambda (widget &optional event)
1462 (when (or custom-file user-init-file)
1464 (widget-create 'push-button
1465 :tag "Save for Future Sessions"
1467 Make your editing in this buffer take effect for future Emacs sessions.
1468 This updates your Emacs initialization file or creates a new one."
1469 :action (lambda (widget &optional event)
1471 (if custom-reset-button-menu
1474 (widget-create 'push-button
1476 :help-echo "Show a menu with reset operations."
1477 :mouse-down-action (lambda (&rest junk) t)
1478 :action (lambda (widget &optional event)
1479 (custom-reset event))))
1481 (when (or custom-file user-init-file)
1482 (widget-create 'push-button
1483 :tag "Erase Customization"
1485 Un-customize all settings in this buffer--save them with standard values."
1486 :action 'Custom-reset-standard)))
1487 (widget-insert "\n ")
1488 (widget-create 'push-button
1489 :tag "Reset to Current"
1491 Reset all edited text in this buffer to reflect current values."
1492 :action 'Custom-reset-current)
1494 (widget-create 'push-button
1495 :tag "Reset to Saved"
1497 Reset all settings in this buffer to their saved values."
1498 :action 'Custom-reset-saved)
1499 (if (not custom-buffer-verbose-help)
1502 (widget-create 'info-link
1504 :help-echo "Read the online help."
1505 "(emacs)Easy Customization")))
1507 (widget-create 'push-button
1510 (lambda (&rest ignore)
1511 (if custom-buffer-done-kill
1513 "Bury this buffer"))
1514 :action #'Custom-buffer-done)
1515 (widget-insert "\n\n")
1516 (message "Creating customization items...")
1517 (buffer-disable-undo)
1518 (setq custom-options
1519 (if (= (length options) 1)
1520 (mapcar (lambda (entry)
1521 (widget-create (nth 1 entry)
1522 :documentation-shown t
1523 :custom-state 'unknown
1524 :tag (custom-unlispify-tag-name
1526 :value (nth 0 entry)))
1529 (length (length options)))
1530 (mapcar (lambda (entry)
1532 (message "Creating customization items ...%2d%%"
1533 (/ (* 100.0 count) length))
1534 (widget-create (nth 1 entry)
1535 :tag (custom-unlispify-tag-name
1537 :value (nth 0 entry))
1538 (setq count (1+ count))
1539 (unless (eq (preceding-char) ?\n)
1540 (widget-insert "\n"))
1541 (widget-insert "\n")))
1543 (unless (eq (preceding-char) ?\n)
1544 (widget-insert "\n"))
1545 (message "Creating customization items ...done")
1546 (message "Resetting customization items...")
1547 (unless (eq custom-buffer-style 'tree)
1548 (mapc 'custom-magic-reset custom-options))
1549 (message "Resetting customization items...done")
1550 (message "Creating customization setup...")
1552 (buffer-enable-undo)
1553 (goto-char (point-min))
1554 (message "Creating customization setup...done"))
1556 ;;; The Tree Browser.
1559 (defun customize-browse (&optional group)
1560 "Create a tree browser for the customize hierarchy."
1563 (setq group 'emacs))
1564 (let ((name "*Customize Browser*"))
1565 (pop-to-buffer (custom-get-fresh-buffer name)))
1567 (widget-insert (format "\
1568 %s buttons; type RET or click mouse-1
1569 on a button to invoke its action.
1570 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1571 (if custom-raised-buttons
1572 "`Raised' text indicates"
1573 "Square brackets indicate")))
1576 (if custom-browse-only-groups
1578 Invoke the [Group] button below to edit that item in another window.\n\n")
1579 (widget-insert "Invoke the ")
1580 (widget-create 'item
1583 :tag-glyph "folder")
1584 (widget-insert ", ")
1585 (widget-create 'item
1589 (widget-insert ", and ")
1590 (widget-create 'item
1593 :tag-glyph "option")
1594 (widget-insert " buttons below to edit that
1595 item in another window.\n\n"))
1596 (let ((custom-buffer-style 'tree))
1597 (widget-create 'custom-group
1599 :custom-state 'unknown
1600 :tag (custom-unlispify-tag-name group)
1603 (goto-char (point-min)))
1605 (define-widget 'custom-browse-visibility 'item
1606 "Control visibility of items in the customize tree browser."
1608 :action 'custom-browse-visibility-action)
1610 (defun custom-browse-visibility-action (widget &rest ignore)
1611 (let ((custom-buffer-style 'tree))
1612 (custom-toggle-parent widget)))
1614 (define-widget 'custom-browse-group-tag 'push-button
1615 "Show parent in other window when activated."
1618 :action 'custom-browse-group-tag-action)
1620 (defun custom-browse-group-tag-action (widget &rest ignore)
1621 (let ((parent (widget-get widget :parent)))
1622 (customize-group-other-window (widget-value parent))))
1624 (define-widget 'custom-browse-variable-tag 'push-button
1625 "Show parent in other window when activated."
1628 :action 'custom-browse-variable-tag-action)
1630 (defun custom-browse-variable-tag-action (widget &rest ignore)
1631 (let ((parent (widget-get widget :parent)))
1632 (customize-variable-other-window (widget-value parent))))
1634 (define-widget 'custom-browse-face-tag 'push-button
1635 "Show parent in other window when activated."
1638 :action 'custom-browse-face-tag-action)
1640 (defun custom-browse-face-tag-action (widget &rest ignore)
1641 (let ((parent (widget-get widget :parent)))
1642 (customize-face-other-window (widget-value parent))))
1644 (defconst custom-browse-alist '((" " "space")
1650 (defun custom-browse-insert-prefix (prefix)
1651 "Insert PREFIX. On XEmacs convert it to line graphics."
1652 ;; Fixme: do graphics.
1653 (if nil ; (string-match "XEmacs" emacs-version)
1656 (while (not (string-equal prefix ""))
1657 (let ((entry (substring prefix 0 3)))
1658 (setq prefix (substring prefix 3))
1659 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1660 (name (nth 1 (assoc entry custom-browse-alist))))
1661 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1662 (overlay-put overlay 'start-open t)
1663 (overlay-put overlay 'end-open t)))))
1666 ;;; Modification of Basic Widgets.
1668 ;; We add extra properties to the basic widgets needed here. This is
1669 ;; fine, as long as we are careful to stay within out own namespace.
1671 ;; We want simple widgets to be displayed by default, but complex
1672 ;; widgets to be hidden.
1674 (widget-put (get 'item 'widget-type) :custom-show t)
1675 (widget-put (get 'editable-field 'widget-type)
1676 :custom-show (lambda (widget value)
1677 (let ((pp (pp-to-string value)))
1678 (cond ((string-match "\n" pp)
1683 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1685 ;;; The `custom-manual' Widget.
1687 (define-widget 'custom-manual 'info-link
1688 "Link to the manual entry for this customization option."
1689 :help-echo "Read the manual entry for this option."
1692 ;;; The `custom-magic' Widget.
1694 (defgroup custom-magic-faces nil
1695 "Faces used by the magic button."
1696 :group 'custom-faces
1697 :group 'custom-buffer)
1699 (defface custom-invalid '((((class color))
1700 (:foreground "yellow1" :background "red1"))
1702 (:weight bold :slant italic :underline t)))
1703 "Face used when the customize item is invalid."
1704 :group 'custom-magic-faces)
1705 ;; backward-compatibility alias
1706 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1708 (defface custom-rogue '((((class color))
1709 (:foreground "pink" :background "black"))
1712 "Face used when the customize item is not defined for customization."
1713 :group 'custom-magic-faces)
1714 ;; backward-compatibility alias
1715 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1717 (defface custom-modified '((((min-colors 88) (class color))
1718 (:foreground "white" :background "blue1"))
1720 (:foreground "white" :background "blue"))
1722 (:slant italic :bold)))
1723 "Face used when the customize item has been modified."
1724 :group 'custom-magic-faces)
1725 ;; backward-compatibility alias
1726 (put 'custom-modified-face 'face-alias 'custom-modified)
1728 (defface custom-set '((((min-colors 88) (class color))
1729 (:foreground "blue1" :background "white"))
1731 (:foreground "blue" :background "white"))
1734 "Face used when the customize item has been set."
1735 :group 'custom-magic-faces)
1736 ;; backward-compatibility alias
1737 (put 'custom-set-face 'face-alias 'custom-set)
1739 (defface custom-changed '((((min-colors 88) (class color))
1740 (:foreground "white" :background "blue1"))
1742 (:foreground "white" :background "blue"))
1745 "Face used when the customize item has been changed."
1746 :group 'custom-magic-faces)
1747 ;; backward-compatibility alias
1748 (put 'custom-changed-face 'face-alias 'custom-changed)
1750 (defface custom-themed '((((min-colors 88) (class color))
1751 (:foreground "white" :background "blue1"))
1753 (:foreground "white" :background "blue"))
1756 "Face used when the customize item has been set by a theme."
1757 :group 'custom-magic-faces)
1759 (defface custom-saved '((t (:underline t)))
1760 "Face used when the customize item has been saved."
1761 :group 'custom-magic-faces)
1762 ;; backward-compatibility alias
1763 (put 'custom-saved-face 'face-alias 'custom-saved)
1765 (defconst custom-magic-alist
1766 '((nil "#" underline "\
1767 UNINITIALIZED, you should not see this.")
1768 (unknown "?" italic "\
1769 UNKNOWN, you should not see this.")
1770 (hidden "-" default "\
1771 HIDDEN, invoke \"Show\" in the previous line to show." "\
1772 group now hidden, invoke \"Show\", above, to show contents.")
1773 (invalid "x" custom-invalid "\
1774 INVALID, the displayed value cannot be set.")
1775 (modified "*" custom-modified "\
1776 EDITED, shown value does not take effect until you set or save it." "\
1777 something in this group has been edited but not set.")
1778 (set "+" custom-set "\
1779 SET for current session only." "\
1780 something in this group has been set but not saved.")
1781 (changed ":" custom-changed "\
1782 CHANGED outside Customize; operating on it here may be unreliable." "\
1783 something in this group has been changed outside customize.")
1784 (saved "!" custom-saved "\
1786 something in this group has been set and saved.")
1787 (themed "o" custom-themed "\
1789 visible group members are all at standard values.")
1790 (rogue "@" custom-rogue "\
1791 NO CUSTOMIZATION DATA; not intended to be customized." "\
1792 something in this group is not prepared for customization.")
1793 (standard " " nil "\
1795 visible group members are all at standard values."))
1796 "Alist of customize option states.
1797 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1799 STATE is one of the following symbols:
1802 For internal use, should never occur.
1804 For internal use, should never occur.
1806 This item is not being displayed.
1808 This item is modified, but has an invalid form.
1810 This item is modified, and has a valid form.
1812 This item has been set but not saved.
1814 The current value of this item has been changed outside Customize.
1816 This item is marked for saving.
1818 This item has no customization information.
1820 This item is unchanged from the standard setting.
1822 MAGIC is a string used to present that state.
1824 FACE is a face used to present the state.
1826 ITEM-DESC is a string describing the state for options.
1828 GROUP-DESC is a string describing the state for groups. If this is
1829 left out, ITEM-DESC will be used.
1831 The string %c in either description will be replaced with the
1832 category of the item. These are `group'. `option', and `face'.
1834 The list should be sorted most significant first.")
1836 (defcustom custom-magic-show 'long
1837 "If non-nil, show textual description of the state.
1838 If `long', show a full-line description, not just one word."
1839 :type '(choice (const :tag "no" nil)
1841 (other :tag "short" short))
1842 :group 'custom-buffer)
1844 (defcustom custom-magic-show-hidden '(option face)
1845 "Control whether the State button is shown for hidden items.
1846 The value should be a list with the custom categories where the State
1847 button should be visible. Possible categories are `group', `option',
1849 :type '(set (const group) (const option) (const face))
1850 :group 'custom-buffer)
1852 (defcustom custom-magic-show-button nil
1853 "Show a \"magic\" button indicating the state of each customization option."
1855 :group 'custom-buffer)
1857 (define-widget 'custom-magic 'default
1858 "Show and manipulate state for a customization option."
1860 :action 'widget-parent-action
1863 :value-create 'custom-magic-value-create
1864 :value-delete 'widget-children-value-delete)
1866 (defun widget-magic-mouse-down-action (widget &optional event)
1867 ;; Non-nil unless hidden.
1868 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1872 (defun custom-magic-value-create (widget)
1873 "Create compact status report for WIDGET."
1874 (let* ((parent (widget-get widget :parent))
1875 (state (widget-get parent :custom-state))
1876 (hidden (eq state 'hidden))
1877 (entry (assq state custom-magic-alist))
1878 (magic (nth 1 entry))
1879 (face (nth 2 entry))
1880 (category (widget-get parent :custom-category))
1881 (text (or (and (eq category 'group)
1884 (form (widget-get parent :custom-form))
1886 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1887 (setq text (concat (match-string 1 text)
1888 (symbol-name category)
1889 (match-string 2 text))))
1890 (when (and custom-magic-show
1892 (memq category custom-magic-show-hidden)))
1894 (when (and (eq category 'group)
1895 (not (and (eq custom-buffer-style 'links)
1896 (> (widget-get parent :custom-level) 1))))
1897 (insert-char ?\ (* custom-buffer-indent
1898 (widget-get parent :custom-level))))
1899 (push (widget-create-child-and-convert
1901 :help-echo "Change the state of this item."
1902 :format (if hidden "%t" "%[%t%]")
1903 :button-prefix 'widget-push-button-prefix
1904 :button-suffix 'widget-push-button-suffix
1905 :mouse-down-action 'widget-magic-mouse-down-action
1909 (let ((start (point)))
1910 (if (eq custom-magic-show 'long)
1912 (insert (symbol-name state)))
1913 (cond ((eq form 'lisp)
1915 ((eq form 'mismatch)
1916 (insert " (mismatch)")))
1917 (put-text-property start (point) 'face 'custom-state))
1919 (when (and (eq category 'group)
1920 (not (and (eq custom-buffer-style 'links)
1921 (> (widget-get parent :custom-level) 1))))
1922 (insert-char ?\ (* custom-buffer-indent
1923 (widget-get parent :custom-level))))
1924 (when custom-magic-show-button
1925 (when custom-magic-show
1926 (let ((indent (widget-get parent :indent)))
1928 (insert-char ? indent))))
1929 (push (widget-create-child-and-convert
1931 :mouse-down-action 'widget-magic-mouse-down-action
1935 :help-echo "Change the state."
1936 :format (if hidden "%t" "%[%t%]")
1937 :tag (if (memq form '(lisp mismatch))
1938 (concat "(" magic ")")
1939 (concat "[" magic "]")))
1942 (widget-put widget :children children)))
1944 (defun custom-magic-reset (widget)
1945 "Redraw the :custom-magic property of WIDGET."
1946 (let ((magic (widget-get widget :custom-magic)))
1947 (widget-value-set magic (widget-value magic))))
1949 ;;; The `custom' Widget.
1951 (defface custom-button
1952 '((((type x w32 mac) (class color)) ; Like default modeline
1953 (:box (:line-width 2 :style released-button)
1954 :background "lightgrey" :foreground "black"))
1957 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1959 :group 'custom-faces)
1960 ;; backward-compatibility alias
1961 (put 'custom-button-face 'face-alias 'custom-button)
1963 (defface custom-button-unraised
1965 (class color) (background light)) :foreground "blue1" :underline t)
1966 (((class color) (background light)) :foreground "blue" :underline t)
1968 (class color) (background dark)) :foreground "cyan1" :underline t)
1969 (((class color) (background dark)) :foreground "cyan" :underline t)
1971 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1973 :group 'custom-faces)
1976 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
1978 (defface custom-button-pressed
1979 '((((type x w32 mac) (class color))
1980 (:box (:line-width 2 :style pressed-button)
1981 :background "lightgrey" :foreground "black"))
1983 (:inverse-video t)))
1984 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1986 :group 'custom-faces)
1987 ;; backward-compatibility alias
1988 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
1990 (defface custom-button-pressed-unraised
1991 '((default :inherit custom-button-unraised)
1992 (((class color) (background light)) :foreground "magenta4")
1993 (((class color) (background dark)) :foreground "violet"))
1994 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1996 :group 'custom-faces)
1998 (setq custom-button-pressed
1999 (if custom-raised-buttons
2000 'custom-button-pressed
2001 'custom-button-pressed-unraised))
2003 (defface custom-documentation nil
2004 "Face used for documentation strings in customization buffers."
2005 :group 'custom-faces)
2006 ;; backward-compatibility alias
2007 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2009 (defface custom-state '((((class color)
2011 (:foreground "lime green"))
2014 (:foreground "dark green"))
2016 "Face used for State descriptions in the customize buffer."
2017 :group 'custom-faces)
2018 ;; backward-compatibility alias
2019 (put 'custom-state-face 'face-alias 'custom-state)
2021 (define-widget 'custom 'default
2022 "Customize a user option."
2024 :convert-widget 'custom-convert-widget
2025 :notify 'custom-notify
2028 :custom-state 'hidden
2029 :documentation-property 'widget-subclass-responsibility
2030 :value-create 'widget-subclass-responsibility
2031 :value-delete 'widget-children-value-delete
2032 :value-get 'widget-value-value-get
2033 :validate 'widget-children-validate
2034 :match (lambda (widget value) (symbolp value)))
2036 (defun custom-convert-widget (widget)
2037 "Initialize :value and :tag from :args in WIDGET."
2038 (let ((args (widget-get widget :args)))
2040 (widget-put widget :value (widget-apply widget
2041 :value-to-internal (car args)))
2042 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2043 (widget-put widget :args nil)))
2046 (defun custom-notify (widget &rest args)
2047 "Keep track of changes."
2048 (let ((state (widget-get widget :custom-state)))
2049 (unless (eq state 'modified)
2050 (unless (memq state '(nil unknown hidden))
2051 (widget-put widget :custom-state 'modified))
2052 (custom-magic-reset widget)
2053 (apply 'widget-default-notify widget args))))
2055 (defun custom-redraw (widget)
2056 "Redraw WIDGET with current settings."
2057 (let ((line (count-lines (point-min) (point)))
2058 (column (current-column))
2060 (from (marker-position (widget-get widget :from)))
2061 (to (marker-position (widget-get widget :to))))
2063 (widget-value-set widget (widget-value widget))
2064 (custom-redraw-magic widget))
2065 (when (and (>= pos from) (<= pos to))
2070 (goto-line (1+ line)))
2071 (move-to-column column))
2074 (defun custom-redraw-magic (widget)
2075 "Redraw WIDGET state with current settings."
2077 (let ((magic (widget-get widget :custom-magic)))
2079 (widget-value-set magic (widget-value magic))
2080 (when (setq widget (widget-get widget :group))
2081 (custom-group-state-update widget)))
2083 (setq widget nil)))))
2086 (defun custom-show (widget value)
2087 "Non-nil if WIDGET should be shown with VALUE by default."
2088 (let ((show (widget-get widget :custom-show)))
2094 (funcall show widget value)))))
2096 (defun custom-load-widget (widget)
2097 "Load all dependencies for WIDGET."
2098 (custom-load-symbol (widget-value widget)))
2100 (defun custom-unloaded-symbol-p (symbol)
2101 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2103 (loads (get symbol 'custom-loads))
2106 (setq load (car loads)
2108 (cond ((symbolp load)
2109 (unless (featurep load)
2111 ((assoc load load-history))
2112 ((assoc (locate-library load) load-history)
2118 (defun custom-unloaded-widget-p (widget)
2119 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2120 (custom-unloaded-symbol-p (widget-value widget)))
2122 (defun custom-toggle-hide (widget)
2123 "Toggle visibility of WIDGET."
2124 (custom-load-widget widget)
2125 (let ((state (widget-get widget :custom-state)))
2126 (cond ((memq state '(invalid modified))
2127 (error "There are unset changes"))
2129 (widget-put widget :custom-state 'unknown))
2131 (widget-put widget :documentation-shown nil)
2132 (widget-put widget :custom-state 'hidden)))
2133 (custom-redraw widget)
2136 (defun custom-toggle-parent (widget &rest ignore)
2137 "Toggle visibility of parent of WIDGET."
2138 (custom-toggle-hide (widget-get widget :parent)))
2140 (defun custom-add-see-also (widget &optional prefix)
2141 "Add `See also ...' to WIDGET if there are any links.
2142 Insert PREFIX first if non-nil."
2143 (let* ((symbol (widget-get widget :value))
2144 (links (get symbol 'custom-links))
2145 (many (> (length links) 2))
2146 (buttons (widget-get widget :buttons))
2147 (indent (widget-get widget :indent)))
2150 (insert-char ?\ indent))
2153 (insert "See also ")
2155 (push (widget-create-child-and-convert widget (car links))
2157 (setq links (cdr links))
2166 (widget-put widget :buttons buttons))))
2168 (defun custom-add-parent-links (widget &optional initial-string)
2169 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2170 The value is non-nil if any parents were found.
2171 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2172 (let ((name (widget-value widget))
2173 (type (widget-type widget))
2174 (buttons (widget-get widget :buttons))
2177 (insert (or initial-string "Parent groups:"))
2178 (mapatoms (lambda (symbol)
2179 (when (member (list name type) (get symbol 'custom-group))
2181 (push (widget-create-child-and-convert
2182 widget 'custom-group-link
2183 :tag (custom-unlispify-tag-name symbol)
2186 (setq parents (cons symbol parents)))))
2187 (and (null (get name 'custom-links)) ;No links of its own.
2188 (= (length parents) 1) ;A single parent.
2189 (let* ((links (delq nil (mapcar (lambda (w)
2190 (unless (eq (widget-type w)
2193 (get (car parents) 'custom-links))))
2194 (many (> (length links) 2)))
2196 (insert "\nParent documentation: ")
2198 (push (widget-create-child-and-convert widget (car links))
2200 (setq links (cdr links))
2211 (delete-region start (point)))
2212 (widget-put widget :buttons buttons)
2215 ;;; The `custom-comment' Widget.
2217 ;; like the editable field
2218 (defface custom-comment '((((class grayscale color)
2220 (:background "gray85"))
2221 (((class grayscale color)
2223 (:background "dim gray"))
2226 "Face used for comments on variables or faces"
2228 :group 'custom-faces)
2229 ;; backward-compatibility alias
2230 (put 'custom-comment-face 'face-alias 'custom-comment)
2232 ;; like font-lock-comment-face
2233 (defface custom-comment-tag
2234 '((((class color) (background dark)) (:foreground "gray80"))
2235 (((class color) (background light)) (:foreground "blue4"))
2236 (((class grayscale) (background light))
2237 (:foreground "DimGray" :weight bold :slant italic))
2238 (((class grayscale) (background dark))
2239 (:foreground "LightGray" :weight bold :slant italic))
2241 "Face used for variables or faces comment tags"
2242 :group 'custom-faces)
2243 ;; backward-compatibility alias
2244 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2246 (define-widget 'custom-comment 'string
2249 :help-echo "Edit a comment here."
2250 :sample-face 'custom-comment-tag-face
2251 :value-face 'custom-comment-face
2253 :create 'custom-comment-create)
2255 (defun custom-comment-create (widget)
2256 (let* ((null-comment (equal "" (widget-value widget))))
2257 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2259 (widget-default-create widget)
2260 ;; `widget-default-delete' expects markers in these slots --
2261 ;; maybe it shouldn't.
2262 (widget-put widget :from (point-marker))
2263 (widget-put widget :to (point-marker)))))
2265 (defun custom-comment-hide (widget)
2266 (widget-put (widget-get widget :parent) :comment-shown nil))
2268 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2269 ;; the global custom one
2270 (defun custom-comment-show (widget)
2271 (widget-put widget :comment-shown t)
2272 (custom-redraw widget)
2275 (defun custom-comment-invisible-p (widget)
2276 (let ((val (widget-value (widget-get widget :comment-widget))))
2278 (not (widget-get widget :comment-shown)))))
2280 ;;; The `custom-variable' Widget.
2282 ;; When this was underlined blue, users confused it with a
2283 ;; Mosaic-style hyperlink...
2284 (defface custom-variable-tag
2287 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2288 (((min-colors 88) (class color)
2290 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2293 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2295 "Face used for unpushable variable tags."
2296 :group 'custom-faces)
2297 ;; backward-compatibility alias
2298 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2300 (defface custom-variable-button '((t (:underline t :weight bold)))
2301 "Face used for pushable variable tags."
2302 :group 'custom-faces)
2303 ;; backward-compatibility alias
2304 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2306 (defcustom custom-variable-default-form 'edit
2307 "Default form of displaying variable values."
2308 :type '(choice (const edit)
2310 :group 'custom-buffer
2313 (defun custom-variable-documentation (variable)
2314 "Return documentation of VARIABLE for use in Custom buffer.
2315 Normally just return the docstring. But if VARIABLE automatically
2316 becomes buffer local when set, append a message to that effect."
2317 (if (and (local-variable-if-set-p variable)
2318 (or (not (local-variable-p variable))
2320 (local-variable-if-set-p variable))))
2321 (concat (documentation-property variable 'variable-documentation)
2323 This variable automatically becomes buffer-local when set outside Custom.
2324 However, setting it through Custom sets the default value.")
2325 (documentation-property variable 'variable-documentation)))
2327 (define-widget 'custom-variable 'custom
2328 "Customize variable."
2330 :help-echo "Set or reset this variable."
2331 :documentation-property #'custom-variable-documentation
2332 :custom-category 'option
2334 :custom-menu 'custom-variable-menu-create
2335 :custom-form nil ; defaults to value of `custom-variable-default-form'
2336 :value-create 'custom-variable-value-create
2337 :action 'custom-variable-action
2338 :custom-set 'custom-variable-set
2339 :custom-save 'custom-variable-save
2340 :custom-reset-current 'custom-redraw
2341 :custom-reset-saved 'custom-variable-reset-saved
2342 :custom-reset-standard 'custom-variable-reset-standard
2343 :custom-standard-value 'custom-variable-standard-value)
2345 (defun custom-variable-type (symbol)
2346 "Return a widget suitable for editing the value of SYMBOL.
2347 If SYMBOL has a `custom-type' property, use that.
2348 Otherwise, look up symbol in `custom-guess-type-alist'."
2349 (let* ((type (or (get symbol 'custom-type)
2350 (and (not (get symbol 'standard-value))
2351 (custom-guess-type symbol))
2353 (options (get symbol 'custom-options))
2354 (tmp (if (listp type)
2355 (copy-sequence type)
2358 (widget-put tmp :options options))
2361 (defun custom-variable-value-create (widget)
2362 "Here is where you edit the variable's value."
2363 (custom-load-widget widget)
2364 (unless (widget-get widget :custom-form)
2365 (widget-put widget :custom-form custom-variable-default-form))
2366 (let* ((buttons (widget-get widget :buttons))
2367 (children (widget-get widget :children))
2368 (form (widget-get widget :custom-form))
2369 (state (widget-get widget :custom-state))
2370 (symbol (widget-get widget :value))
2371 (tag (widget-get widget :tag))
2372 (type (custom-variable-type symbol))
2373 (conv (widget-convert type))
2374 (get (or (get symbol 'custom-get) 'default-value))
2375 (prefix (widget-get widget :custom-prefix))
2376 (last (widget-get widget :custom-last))
2377 (value (if (default-boundp symbol)
2378 (funcall get symbol)
2379 (widget-get conv :value))))
2380 ;; If the widget is new, the child determines whether it is hidden.
2382 ((custom-show type value)
2383 (setq state 'unknown))
2385 (setq state 'hidden)))
2386 ;; If we don't know the state, see if we need to edit it in lisp form.
2387 (when (eq state 'unknown)
2388 (unless (widget-apply conv :match value)
2389 ;; (widget-apply (widget-convert type) :match value)
2390 (setq form 'mismatch)))
2391 ;; Now we can create the child widget.
2392 (cond ((eq custom-buffer-style 'tree)
2393 (insert prefix (if last " `--- " " |--- "))
2394 (push (widget-create-child-and-convert
2395 widget 'custom-browse-variable-tag)
2397 (insert " " tag "\n")
2398 (widget-put widget :buttons buttons))
2400 ;; Indicate hidden value.
2401 (push (widget-create-child-and-convert
2404 :sample-face 'custom-variable-tag-face
2408 (push (widget-create-child-and-convert
2410 :help-echo "Show the value of this option."
2412 :action 'custom-toggle-parent
2415 ((memq form '(lisp mismatch))
2416 ;; In lisp mode edit the saved value when possible.
2417 (let* ((value (cond ((get symbol 'saved-value)
2418 (car (get symbol 'saved-value)))
2419 ((get symbol 'standard-value)
2420 (car (get symbol 'standard-value)))
2421 ((default-boundp symbol)
2422 (custom-quote (funcall get symbol)))
2424 (custom-quote (widget-get conv :value))))))
2425 (insert (symbol-name symbol) ": ")
2426 (push (widget-create-child-and-convert
2428 :help-echo "Hide the value of this option."
2431 :action 'custom-toggle-parent
2435 (push (widget-create-child-and-convert
2437 :button-face 'custom-variable-button-face
2439 :tag (symbol-name symbol)
2445 (let* ((format (widget-get type :format))
2446 tag-format value-format)
2447 (unless (string-match ":" format)
2448 (error "Bad format"))
2449 (setq tag-format (substring format 0 (match-end 0)))
2450 (setq value-format (substring format (match-end 0)))
2451 (push (widget-create-child-and-convert
2454 :action 'custom-tag-action
2455 :help-echo "Change value of this option."
2456 :mouse-down-action 'custom-tag-mouse-down-action
2457 :button-face 'custom-variable-button-face
2458 :sample-face 'custom-variable-tag-face
2462 (push (widget-create-child-and-convert
2464 :help-echo "Hide the value of this option."
2467 :action 'custom-toggle-parent
2470 (push (widget-create-child-and-convert
2472 :format value-format
2475 (unless (eq custom-buffer-style 'tree)
2476 (unless (eq (preceding-char) ?\n)
2477 (widget-insert "\n"))
2478 ;; Create the magic button.
2479 (let ((magic (widget-create-child-and-convert
2480 widget 'custom-magic nil)))
2481 (widget-put widget :custom-magic magic)
2482 (push magic buttons))
2483 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2484 ;; before the call to `widget-default-format-handler'. Otherwise, I
2485 ;; loose my current `buttons'. This function shouldn't be called like
2486 ;; this anyway. The doc string widget should be added like the others.
2488 (widget-put widget :buttons buttons)
2490 ;; Insert documentation.
2491 (widget-default-format-handler widget ?h)
2493 ;; The comment field
2494 (unless (eq state 'hidden)
2495 (let* ((comment (get symbol 'variable-comment))
2497 (widget-create-child-and-convert
2498 widget 'custom-comment
2500 :value (or comment ""))))
2501 (widget-put widget :comment-widget comment-widget)
2502 ;; Don't push it !!! Custom assumes that the first child is the
2504 (setq children (append children (list comment-widget)))))
2505 ;; Update the rest of the properties properties.
2506 (widget-put widget :custom-form form)
2507 (widget-put widget :children children)
2508 ;; Now update the state.
2509 (if (eq state 'hidden)
2510 (widget-put widget :custom-state state)
2511 (custom-variable-state-set widget))
2513 (unless (eq state 'hidden)
2514 (when (eq (widget-get widget :custom-level) 1)
2515 (custom-add-parent-links widget))
2516 (custom-add-see-also widget)))))
2518 (defun custom-tag-action (widget &rest args)
2519 "Pass :action to first child of WIDGET's parent."
2520 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2523 (defun custom-tag-mouse-down-action (widget &rest args)
2524 "Pass :mouse-down-action to first child of WIDGET's parent."
2525 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2526 :mouse-down-action args))
2528 (defun custom-variable-state-set (widget)
2529 "Set the state of WIDGET."
2530 (let* ((symbol (widget-value widget))
2531 (get (or (get symbol 'custom-get) 'default-value))
2532 (value (if (default-boundp symbol)
2533 (funcall get symbol)
2534 (widget-get widget :value)))
2535 (comment (get symbol 'variable-comment))
2538 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2540 (get symbol 'customized-variable-comment))
2542 (if (condition-case nil
2543 (and (equal value (eval (car tmp)))
2544 (equal comment temp))
2548 ((progn (setq tmp (get symbol 'theme-value))
2549 (setq temp (get symbol 'saved-variable-comment))
2551 (if (condition-case nil
2552 (and (equal comment temp)
2559 ((eq 'user (caar (get symbol 'theme-value)))
2561 ((eq 'standard (caar (get symbol 'theme-value)))
2565 ((setq tmp (get symbol 'standard-value))
2566 (if (condition-case nil
2567 (and (equal value (eval (car tmp)))
2568 (equal comment nil))
2573 (widget-put widget :custom-state state)))
2575 (defun custom-variable-standard-value (widget)
2576 (get (widget-value widget) 'standard-value))
2578 (defvar custom-variable-menu
2579 `(("Set for Current Session" custom-variable-set
2581 (eq (widget-get widget :custom-state) 'modified)))
2582 ,@(when (or custom-file user-init-file)
2583 '(("Save for Future Sessions" custom-variable-save
2585 (memq (widget-get widget :custom-state) '(modified set changed rogue))))))
2586 ("Reset to Current" custom-redraw
2588 (and (default-boundp (widget-value widget))
2589 (memq (widget-get widget :custom-state) '(modified changed)))))
2590 ("Reset to Saved" custom-variable-reset-saved
2592 (and (or (get (widget-value widget) 'saved-value)
2593 (get (widget-value widget) 'saved-variable-comment))
2594 (memq (widget-get widget :custom-state)
2595 '(modified set changed rogue)))))
2596 ,@(when (or custom-file user-init-file)
2597 '(("Erase Customization" custom-variable-reset-standard
2599 (and (get (widget-value widget) 'standard-value)
2600 (memq (widget-get widget :custom-state)
2601 '(modified set changed saved rogue)))))))
2602 ("Use Backup Value" custom-variable-reset-backup
2604 (get (widget-value widget) 'backup-value)))
2605 ("---" ignore ignore)
2606 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2607 ("---" ignore ignore)
2608 ("Don't show as Lisp expression" custom-variable-edit
2610 (eq (widget-get widget :custom-form) 'lisp)))
2611 ("Show initial Lisp expression" custom-variable-edit-lisp
2613 (eq (widget-get widget :custom-form) 'edit))))
2614 "Alist of actions for the `custom-variable' widget.
2615 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2616 the menu entry, ACTION is the function to call on the widget when the
2617 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2618 widget as an argument, and returns non-nil if ACTION is valid on that
2619 widget. If FILTER is nil, ACTION is always valid.")
2621 (defun custom-variable-action (widget &optional event)
2622 "Show the menu for `custom-variable' WIDGET.
2623 Optional EVENT is the location for the menu."
2624 (if (eq (widget-get widget :custom-state) 'hidden)
2625 (custom-toggle-hide widget)
2626 (unless (eq (widget-get widget :custom-state) 'modified)
2627 (custom-variable-state-set widget))
2628 (custom-redraw-magic widget)
2629 (let* ((completion-ignore-case t)
2630 (answer (widget-choose (concat "Operation on "
2631 (custom-unlispify-tag-name
2632 (widget-get widget :value)))
2633 (custom-menu-filter custom-variable-menu
2637 (funcall answer widget)))))
2639 (defun custom-variable-edit (widget)
2640 "Edit value of WIDGET."
2641 (widget-put widget :custom-state 'unknown)
2642 (widget-put widget :custom-form 'edit)
2643 (custom-redraw widget))
2645 (defun custom-variable-edit-lisp (widget)
2646 "Edit the Lisp representation of the value of WIDGET."
2647 (widget-put widget :custom-state 'unknown)
2648 (widget-put widget :custom-form 'lisp)
2649 (custom-redraw widget))
2651 (defun custom-variable-set (widget)
2652 "Set the current value for the variable being edited by WIDGET."
2653 (let* ((form (widget-get widget :custom-form))
2654 (state (widget-get widget :custom-state))
2655 (child (car (widget-get widget :children)))
2656 (symbol (widget-value widget))
2657 (set (or (get symbol 'custom-set) 'set-default))
2658 (comment-widget (widget-get widget :comment-widget))
2659 (comment (widget-value comment-widget))
2661 (cond ((eq state 'hidden)
2662 (error "Cannot set hidden variable"))
2663 ((setq val (widget-apply child :validate))
2664 (goto-char (widget-get val :from))
2665 (error "%s" (widget-get val :error)))
2666 ((memq form '(lisp mismatch))
2667 (when (equal comment "")
2669 ;; Make the comment invisible by hand if it's empty
2670 (custom-comment-hide comment-widget))
2671 (custom-variable-backup-value widget)
2672 (custom-push-theme 'theme-value symbol 'user
2673 'set (custom-quote (widget-value child)))
2674 (funcall set symbol (eval (setq val (widget-value child))))
2675 (put symbol 'customized-value (list val))
2676 (put symbol 'variable-comment comment)
2677 (put symbol 'customized-variable-comment comment))
2679 (when (equal comment "")
2681 ;; Make the comment invisible by hand if it's empty
2682 (custom-comment-hide comment-widget))
2683 (custom-variable-backup-value widget)
2684 (custom-push-theme 'theme-value symbol 'user
2685 'set (custom-quote (widget-value child)))
2686 (funcall set symbol (setq val (widget-value child)))
2687 (put symbol 'customized-value (list (custom-quote val)))
2688 (put symbol 'variable-comment comment)
2689 (put symbol 'customized-variable-comment comment)))
2690 (custom-variable-state-set widget)
2691 (custom-redraw-magic widget)))
2693 (defun custom-variable-save (widget)
2694 "Set and save the value for the variable being edited by WIDGET."
2695 (let* ((form (widget-get widget :custom-form))
2696 (state (widget-get widget :custom-state))
2697 (child (car (widget-get widget :children)))
2698 (symbol (widget-value widget))
2699 (set (or (get symbol 'custom-set) 'set-default))
2700 (comment-widget (widget-get widget :comment-widget))
2701 (comment (widget-value comment-widget))
2703 (cond ((eq state 'hidden)
2704 (error "Cannot set hidden variable"))
2705 ((setq val (widget-apply child :validate))
2706 (goto-char (widget-get val :from))
2707 (error "Saving %s: %s" symbol (widget-get val :error)))
2708 ((memq form '(lisp mismatch))
2709 (when (equal comment "")
2711 ;; Make the comment invisible by hand if it's empty
2712 (custom-comment-hide comment-widget))
2713 (put symbol 'saved-value (list (widget-value child)))
2714 (custom-push-theme 'theme-value symbol 'user
2715 'set (custom-quote (widget-value child)))
2716 (funcall set symbol (eval (widget-value child)))
2717 (put symbol 'variable-comment comment)
2718 (put symbol 'saved-variable-comment comment))
2720 (when (equal comment "")
2722 ;; Make the comment invisible by hand if it's empty
2723 (custom-comment-hide comment-widget))
2724 (put symbol 'saved-value
2725 (list (custom-quote (widget-value child))))
2726 (custom-push-theme 'theme-value symbol 'user
2727 'set (custom-quote (widget-value child)))
2728 (funcall set symbol (widget-value child))
2729 (put symbol 'variable-comment comment)
2730 (put symbol 'saved-variable-comment comment)))
2731 (put symbol 'customized-value nil)
2732 (put symbol 'customized-variable-comment nil)
2734 (custom-variable-state-set widget)
2735 (custom-redraw-magic widget)))
2737 (defun custom-variable-reset-saved (widget)
2738 "Restore the saved value for the variable being edited by WIDGET.
2739 The value that was current before this operation
2740 becomes the backup value, so you can get it again."
2741 (let* ((symbol (widget-value widget))
2742 (set (or (get symbol 'custom-set) 'set-default))
2743 (value (get symbol 'saved-value))
2744 (comment (get symbol 'saved-variable-comment)))
2745 (cond ((or value comment)
2746 (put symbol 'variable-comment comment)
2747 (custom-variable-backup-value widget)
2748 (custom-push-theme 'theme-value symbol 'user 'set value)
2750 (funcall set symbol (eval (car value)))
2753 (error "No saved value for %s" symbol)))
2754 (put symbol 'customized-value nil)
2755 (put symbol 'customized-variable-comment nil)
2756 (widget-put widget :custom-state 'unknown)
2757 ;; This call will possibly make the comment invisible
2758 (custom-redraw widget)))
2760 (defun custom-variable-reset-standard (widget)
2761 "Restore the standard setting for the variable being edited by WIDGET.
2762 This operation eliminates any saved setting for the variable,
2763 restoring it to the state of a variable that has never been customized.
2764 The value that was current before this operation
2765 becomes the backup value, so you can get it again."
2766 (let* ((symbol (widget-value widget))
2767 (set (or (get symbol 'custom-set) 'set-default)))
2768 (if (get symbol 'standard-value)
2769 (custom-variable-backup-value widget)
2770 (error "No standard setting known for %S" symbol))
2771 (put symbol 'variable-comment nil)
2772 (put symbol 'customized-value nil)
2773 (put symbol 'customized-variable-comment nil)
2774 (custom-push-theme 'theme-value symbol 'user 'reset nil)
2775 (custom-theme-recalc-variable symbol)
2776 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2777 (put symbol 'saved-value nil)
2778 (put symbol 'saved-variable-comment nil)
2780 (widget-put widget :custom-state 'unknown)
2781 ;; This call will possibly make the comment invisible
2782 (custom-redraw widget)))
2784 (defun custom-variable-backup-value (widget)
2785 "Back up the current value for WIDGET's variable.
2786 The backup value is kept in the car of the `backup-value' property."
2787 (let* ((symbol (widget-value widget))
2788 (get (or (get symbol 'custom-get) 'default-value))
2789 (type (custom-variable-type symbol))
2790 (conv (widget-convert type))
2791 (value (if (default-boundp symbol)
2792 (funcall get symbol)
2793 (widget-get conv :value))))
2794 (put symbol 'backup-value (list value))))
2796 (defun custom-variable-reset-backup (widget)
2797 "Restore the backup value for the variable being edited by WIDGET.
2798 The value that was current before this operation
2799 becomes the backup value, so you can use this operation repeatedly
2800 to switch between two values."
2801 (let* ((symbol (widget-value widget))
2802 (set (or (get symbol 'custom-set) 'set-default))
2803 (value (get symbol 'backup-value))
2804 (comment-widget (widget-get widget :comment-widget))
2805 (comment (widget-value comment-widget)))
2808 (custom-variable-backup-value widget)
2809 (custom-push-theme 'theme-value symbol 'user 'set value)
2811 (funcall set symbol (car value))
2813 (error "No backup value for %s" symbol))
2814 (put symbol 'customized-value (list (car value)))
2815 (put symbol 'variable-comment comment)
2816 (put symbol 'customized-variable-comment comment)
2817 (custom-variable-state-set widget)
2818 ;; This call will possibly make the comment invisible
2819 (custom-redraw widget)))
2821 ;;; The `custom-face-edit' Widget.
2823 (define-widget 'custom-face-edit 'checklist
2824 "Edit face attributes."
2828 :button-args '(:help-echo "Control whether this attribute has any effect.")
2829 :value-to-internal 'custom-face-edit-fix-value
2830 :match (lambda (widget value)
2831 (widget-checklist-match widget
2832 (custom-face-edit-fix-value widget value)))
2833 :convert-widget 'custom-face-edit-convert-widget
2834 :args (mapcar (lambda (att)
2837 :sibling-args (widget-get (nth 1 att) :sibling-args)
2838 (list 'const :format "" :value (nth 0 att))
2840 custom-face-attributes))
2842 (defun custom-face-edit-fix-value (widget value)
2843 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2844 Also change :reverse-video to :inverse-video."
2848 (let ((key (car value))
2849 (val (car (cdr value))))
2850 (cond ((eq key :italic)
2851 (push :slant result)
2852 (push (if val 'italic 'normal) result))
2854 (push :weight result)
2855 (push (if val 'bold 'normal) result))
2856 ((eq key :reverse-video)
2857 (push :inverse-video result)
2861 (push val result))))
2862 (setq value (cdr (cdr value))))
2863 (setq result (nreverse result))
2867 (defun custom-face-edit-convert-widget (widget)
2868 "Convert :args as widget types in WIDGET."
2871 :args (mapcar (lambda (arg)
2873 :deactivate 'custom-face-edit-deactivate
2874 :activate 'custom-face-edit-activate
2875 :delete 'custom-face-edit-delete))
2876 (widget-get widget :args)))
2879 (defun custom-face-edit-deactivate (widget)
2880 "Make face widget WIDGET inactive for user modifications."
2881 (unless (widget-get widget :inactive)
2882 (let ((tag (custom-face-edit-attribute-tag widget))
2883 (from (copy-marker (widget-get widget :from)))
2884 (value (widget-value widget))
2885 (inhibit-read-only t)
2886 (inhibit-modification-hooks t))
2889 (widget-default-delete widget)
2890 (insert tag ": *\n")
2891 (widget-put widget :inactive
2892 (cons value (cons from (- (point) from))))))))
2894 (defun custom-face-edit-activate (widget)
2895 "Make face widget WIDGET inactive for user modifications."
2896 (let ((inactive (widget-get widget :inactive))
2897 (inhibit-read-only t)
2898 (inhibit-modification-hooks t))
2899 (when (consp inactive)
2901 (goto-char (car (cdr inactive)))
2902 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2903 (widget-put widget :inactive nil)
2904 (widget-apply widget :create)
2905 (widget-value-set widget (car inactive))
2908 (defun custom-face-edit-delete (widget)
2909 "Remove WIDGET from the buffer."
2910 (let ((inactive (widget-get widget :inactive))
2911 (inhibit-read-only t)
2912 (inhibit-modification-hooks t))
2914 ;; Widget is alive, we don't have to do anything special
2915 (widget-default-delete widget)
2916 ;; WIDGET is already deleted because we did so to inactivate it;
2917 ;; now just get rid of the label we put in its place.
2918 (delete-region (car (cdr inactive))
2919 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2920 (widget-put widget :inactive nil))))
2923 (defun custom-face-edit-attribute-tag (widget)
2924 "Returns the first :tag property in WIDGET or one of its children."
2925 (let ((tag (widget-get widget :tag)))
2926 (or (and (not (equal tag "")) tag)
2927 (let ((children (widget-get widget :children)))
2928 (while (and (null tag) children)
2929 (setq tag (custom-face-edit-attribute-tag (pop children))))
2932 ;;; The `custom-display' Widget.
2934 (define-widget 'custom-display 'menu-choice
2935 "Select a display type."
2938 :help-echo "Specify frames where the face attributes should be used."
2939 :args '((const :tag "all" t)
2940 (const :tag "defaults" default)
2944 :args ((group :sibling-args (:help-echo "\
2945 Only match the specified window systems.")
2946 (const :format "Type: "
2948 (checklist :inline t
2951 :sibling-args (:help-echo "\
2952 The X11 Window System.")
2954 (const :format "PM "
2955 :sibling-args (:help-echo "\
2956 OS/2 Presentation Manager.")
2958 (const :format "W32 "
2959 :sibling-args (:help-echo "\
2962 (const :format "MAC "
2963 :sibling-args (:help-echo "\
2966 (const :format "DOS "
2967 :sibling-args (:help-echo "\
2970 (const :format "TTY%n"
2971 :sibling-args (:help-echo "\
2972 Plain text terminals.")
2974 (group :sibling-args (:help-echo "\
2975 Only match the frames with the specified color support.")
2976 (const :format "Class: "
2978 (checklist :inline t
2980 (const :format "Color "
2981 :sibling-args (:help-echo "\
2982 Match color frames.")
2984 (const :format "Grayscale "
2985 :sibling-args (:help-echo "\
2986 Match grayscale frames.")
2988 (const :format "Monochrome%n"
2989 :sibling-args (:help-echo "\
2990 Match frames with no color support.")
2992 (group :sibling-args (:help-echo "\
2993 The minimum number of colors the frame should support.")
2994 (const :format "" min-colors)
2995 (integer :tag "Minimum number of colors" ))
2996 (group :sibling-args (:help-echo "\
2997 Only match frames with the specified intensity.")
2999 Background brightness: "
3001 (checklist :inline t
3003 (const :format "Light "
3004 :sibling-args (:help-echo "\
3005 Match frames with light backgrounds.")
3007 (const :format "Dark\n"
3008 :sibling-args (:help-echo "\
3009 Match frames with dark backgrounds.")
3011 (group :sibling-args (:help-echo "\
3012 Only match frames that support the specified face attributes.")
3013 (const :format "Supports attributes:" supports)
3014 (custom-face-edit :inline t :format "%n%v"))))))
3016 ;;; The `custom-face' Widget.
3018 (defface custom-face-tag
3019 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3020 "Face used for face tags."
3021 :group 'custom-faces)
3022 ;; backward-compatibility alias
3023 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3025 (defcustom custom-face-default-form 'selected
3026 "Default form of displaying face definition."
3027 :type '(choice (const all)
3030 :group 'custom-buffer
3033 (define-widget 'custom-face 'custom
3035 :sample-face 'custom-face-tag-face
3036 :help-echo "Set or reset this face."
3037 :documentation-property #'face-doc-string
3038 :value-create 'custom-face-value-create
3039 :action 'custom-face-action
3040 :custom-category 'face
3041 :custom-form nil ; defaults to value of `custom-face-default-form'
3042 :custom-set 'custom-face-set
3043 :custom-save 'custom-face-save
3044 :custom-reset-current 'custom-redraw
3045 :custom-reset-saved 'custom-face-reset-saved
3046 :custom-reset-standard 'custom-face-reset-standard
3047 :custom-standard-value 'custom-face-standard-value
3048 :custom-menu 'custom-face-menu-create)
3050 (define-widget 'custom-face-all 'editable-list
3051 "An editable list of display specifications and attributes."
3052 :entry-format "%i %d %v"
3053 :insert-button-args '(:help-echo "Insert new display specification here.")
3054 :append-button-args '(:help-echo "Append new display specification here.")
3055 :delete-button-args '(:help-echo "Delete this display specification.")
3056 :args '((group :format "%v" custom-display custom-face-edit)))
3058 (defconst custom-face-all (widget-convert 'custom-face-all)
3059 "Converted version of the `custom-face-all' widget.")
3061 (define-widget 'custom-display-unselected 'item
3062 "A display specification that doesn't match the selected display."
3063 :match 'custom-display-unselected-match)
3065 (defun custom-display-unselected-match (widget value)
3066 "Non-nil if VALUE is an unselected display specification."
3067 (not (face-spec-set-match-display value (selected-frame))))
3069 (define-widget 'custom-face-selected 'group
3070 "Edit the attributes of the selected display in a face specification."
3071 :args '((choice :inline t
3072 (group :tag "With Defaults" :inline t
3073 (group (const :tag "" default)
3074 (custom-face-edit :tag " Default\n Attributes"))
3077 (group custom-display-unselected sexp))
3078 (group (sexp :format "")
3079 (custom-face-edit :tag " Overriding\n Attributes"))
3083 (group :tag "No Defaults" :inline t
3086 (group custom-display-unselected sexp))
3087 (group (sexp :format "")
3088 (custom-face-edit :tag "\n Attributes"))
3095 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3096 "Converted version of the `custom-face-selected' widget.")
3098 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3099 "Return a canonicalized version of SPEC using.
3100 FILTER-INDEX is the index in the entry for each attribute in
3101 `custom-face-attributes' at which the appropriate filter function can be
3102 found, and DEFAULT-FILTER is the filter to apply for attributes that
3104 (mapcar (lambda (entry)
3105 ;; Filter a single face-spec entry
3106 (let ((tests (car entry))
3108 ;; Handle both old- and new-style attribute syntax
3109 (if (listp (car (cdr entry)))
3112 (filtered-attrs nil))
3113 ;; Filter each face attribute
3114 (while unfiltered-attrs
3115 (let* ((attr (pop unfiltered-attrs))
3116 (pre-filtered-value (pop unfiltered-attrs))
3118 (or (nth filter-index (assq attr custom-face-attributes))
3122 (funcall filter pre-filtered-value)
3123 pre-filtered-value)))
3124 (push filtered-value filtered-attrs)
3125 (push attr filtered-attrs)))
3127 (list tests filtered-attrs)))
3130 (defun custom-pre-filter-face-spec (spec)
3131 "Return SPEC changed as necessary for editing by the face customization widget.
3132 SPEC must be a full face spec."
3133 (custom-filter-face-spec spec 2))
3135 (defun custom-post-filter-face-spec (spec)
3136 "Return the customized SPEC in a form suitable for setting the face."
3137 (custom-filter-face-spec spec 3))
3139 (defun custom-face-value-create (widget)
3140 "Create a list of the display specifications for WIDGET."
3141 (let ((buttons (widget-get widget :buttons))
3143 (symbol (widget-get widget :value))
3144 (tag (widget-get widget :tag))
3145 (state (widget-get widget :custom-state))
3147 (is-last (widget-get widget :custom-last))
3148 (prefix (widget-get widget :custom-prefix)))
3150 (setq tag (prin1-to-string symbol)))
3151 (cond ((eq custom-buffer-style 'tree)
3152 (insert prefix (if is-last " `--- " " |--- "))
3153 (push (widget-create-child-and-convert
3154 widget 'custom-browse-face-tag)
3156 (insert " " tag "\n")
3157 (widget-put widget :buttons buttons))
3161 (widget-specify-sample widget begin (point))
3162 (if (eq custom-buffer-style 'face)
3164 (if (string-match "face\\'" tag)
3166 (insert " face: ")))
3168 (push (widget-create-child-and-convert widget 'item
3175 (push (widget-create-child-and-convert
3177 :help-echo "Hide or show this face."
3180 :action 'custom-toggle-parent
3181 (not (eq state 'hidden)))
3185 (let ((magic (widget-create-child-and-convert
3186 widget 'custom-magic nil)))
3187 (widget-put widget :custom-magic magic)
3188 (push magic buttons))
3190 (widget-put widget :buttons buttons)
3191 ;; Insert documentation.
3192 (widget-default-format-handler widget ?h)
3193 ;; The comment field
3194 (unless (eq state 'hidden)
3195 (let* ((comment (get symbol 'face-comment))
3197 (widget-create-child-and-convert
3198 widget 'custom-comment
3200 :value (or comment ""))))
3201 (widget-put widget :comment-widget comment-widget)
3202 (push comment-widget children)))
3204 (unless (eq state 'hidden)
3205 (when (eq (widget-get widget :custom-level) 1)
3206 (custom-add-parent-links widget))
3207 (custom-add-see-also widget))
3209 (unless (eq (preceding-char) ?\n)
3211 (unless (eq state 'hidden)
3212 (message "Creating face editor...")
3213 (custom-load-widget widget)
3214 (unless (widget-get widget :custom-form)
3215 (widget-put widget :custom-form custom-face-default-form))
3216 (let* ((symbol (widget-value widget))
3217 (spec (or (get symbol 'customized-face)
3218 (get symbol 'saved-face)
3219 (get symbol 'face-defface-spec)
3220 ;; Attempt to construct it.
3221 (list (list t (custom-face-attributes-get
3222 symbol (selected-frame))))))
3223 (form (widget-get widget :custom-form))
3224 (indent (widget-get widget :indent))
3226 ;; If the user has changed this face in some other way,
3227 ;; edit it as the user has specified it.
3228 (if (not (face-spec-match-p symbol spec (selected-frame)))
3229 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3230 (setq spec (custom-pre-filter-face-spec spec))
3231 (setq edit (widget-create-child-and-convert
3233 (cond ((and (eq form 'selected)
3234 (widget-apply custom-face-selected
3236 (when indent (insert-char ?\ indent))
3237 'custom-face-selected)
3238 ((and (not (eq form 'lisp))
3239 (widget-apply custom-face-all
3243 (when indent (insert-char ?\ indent))
3246 (custom-face-state-set widget)
3247 (push edit children)
3248 (widget-put widget :children children))
3249 (message "Creating face editor...done"))))))
3251 (defvar custom-face-menu
3252 `(("Set for Current Session" custom-face-set)
3253 ,@(when (or custom-file user-init-file)
3254 '(("Save for Future Sessions" custom-face-save-command)))
3255 ("Reset to Saved" custom-face-reset-saved
3257 (or (get (widget-value widget) 'saved-face)
3258 (get (widget-value widget) 'saved-face-comment))))
3259 ,@(when (or custom-file user-init-file)
3260 '(("Erase Customization" custom-face-reset-standard
3262 (get (widget-value widget) 'face-defface-spec)))))
3263 ("---" ignore ignore)
3264 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3265 ("---" ignore ignore)
3266 ("Show all display specs" custom-face-edit-all
3268 (not (eq (widget-get widget :custom-form) 'all))))
3269 ("Just current attributes" custom-face-edit-selected
3271 (not (eq (widget-get widget :custom-form) 'selected))))
3272 ("Show as Lisp expression" custom-face-edit-lisp
3274 (not (eq (widget-get widget :custom-form) 'lisp)))))
3275 "Alist of actions for the `custom-face' widget.
3276 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3277 the menu entry, ACTION is the function to call on the widget when the
3278 menu is selected, and FILTER is a predicate which takes a `custom-face'
3279 widget as an argument, and returns non-nil if ACTION is valid on that
3280 widget. If FILTER is nil, ACTION is always valid.")
3282 (defun custom-face-edit-selected (widget)
3283 "Edit selected attributes of the value of WIDGET."
3284 (widget-put widget :custom-state 'unknown)
3285 (widget-put widget :custom-form 'selected)
3286 (custom-redraw widget))
3288 (defun custom-face-edit-all (widget)
3289 "Edit all attributes of the value of WIDGET."
3290 (widget-put widget :custom-state 'unknown)
3291 (widget-put widget :custom-form 'all)
3292 (custom-redraw widget))
3294 (defun custom-face-edit-lisp (widget)
3295 "Edit the Lisp representation of the value of WIDGET."
3296 (widget-put widget :custom-state 'unknown)
3297 (widget-put widget :custom-form 'lisp)
3298 (custom-redraw widget))
3300 (defun custom-face-state-set (widget)
3301 "Set the state of WIDGET."
3302 (let* ((symbol (widget-value widget))
3303 (comment (get symbol 'face-comment))
3307 (setq tmp (get symbol 'customized-face))
3308 (setq temp (get symbol 'customized-face-comment))
3310 (if (equal temp comment)
3314 (setq tmp (get symbol 'saved-face))
3315 (setq temp (get symbol 'saved-face-comment))
3317 (if (equal temp comment)
3319 ((eq 'user (caar (get symbol 'theme-face)))
3321 ((eq 'standard (caar (get symbol 'theme-face)))
3325 ((get symbol 'face-defface-spec)
3326 (if (equal comment nil)
3331 ;; If the user called set-face-attribute to change the default
3332 ;; for new frames, this face is "set outside of Customize".
3333 (if (and (not (eq state 'rogue))
3334 (get symbol 'face-modified))
3335 (setq state 'changed))
3336 (widget-put widget :custom-state state)))
3338 (defun custom-face-action (widget &optional event)
3339 "Show the menu for `custom-face' WIDGET.
3340 Optional EVENT is the location for the menu."
3341 (if (eq (widget-get widget :custom-state) 'hidden)
3342 (custom-toggle-hide widget)
3343 (let* ((completion-ignore-case t)
3344 (symbol (widget-get widget :value))
3345 (answer (widget-choose (concat "Operation on "
3346 (custom-unlispify-tag-name symbol))
3347 (custom-menu-filter custom-face-menu
3351 (funcall answer widget)))))
3353 (defun custom-face-set (widget)
3354 "Make the face attributes in WIDGET take effect."
3355 (let* ((symbol (widget-value widget))
3356 (child (car (widget-get widget :children)))
3357 (value (custom-post-filter-face-spec (widget-value child)))
3358 (comment-widget (widget-get widget :comment-widget))
3359 (comment (widget-value comment-widget)))
3360 (when (equal comment "")
3362 ;; Make the comment invisible by hand if it's empty
3363 (custom-comment-hide comment-widget))
3364 (put symbol 'customized-face value)
3365 (if (face-spec-choose value)
3366 (face-spec-set symbol value)
3367 ;; face-set-spec ignores empty attribute lists, so just give it
3368 ;; something harmless instead.
3369 (face-spec-set symbol '((t :foreground unspecified))))
3370 (custom-push-theme 'theme-face symbol 'user 'set value)
3371 (put symbol 'customized-face-comment comment)
3372 (put symbol 'face-comment comment)
3373 (custom-face-state-set widget)
3374 (custom-redraw-magic widget)))
3376 (defun custom-face-save-command (widget)
3377 "Save in `.emacs' the face attributes in WIDGET."
3378 (custom-face-save widget)
3381 (defun custom-face-save (widget)
3382 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3383 (let* ((symbol (widget-value widget))
3384 (child (car (widget-get widget :children)))
3385 (value (custom-post-filter-face-spec (widget-value child)))
3386 (comment-widget (widget-get widget :comment-widget))
3387 (comment (widget-value comment-widget)))
3388 (when (equal comment "")
3390 ;; Make the comment invisible by hand if it's empty
3391 (custom-comment-hide comment-widget))
3392 (if (face-spec-choose value)
3393 (face-spec-set symbol value)
3394 ;; face-set-spec ignores empty attribute lists, so just give it
3395 ;; something harmless instead.
3396 (face-spec-set symbol '((t :foreground unspecified))))
3397 (unless (eq (widget-get widget :custom-state) 'standard)
3398 (put symbol 'saved-face value))
3399 (custom-push-theme 'theme-face symbol 'user 'set value)
3400 (put symbol 'customized-face nil)
3401 (put symbol 'face-comment comment)
3402 (put symbol 'customized-face-comment nil)
3403 (put symbol 'saved-face-comment comment)
3405 (custom-face-state-set widget)
3406 (custom-redraw-magic widget)))
3408 (defun custom-face-reset-saved (widget)
3409 "Restore WIDGET to the face's default attributes."
3410 (let* ((symbol (widget-value widget))
3411 (child (car (widget-get widget :children)))
3412 (value (get symbol 'saved-face))
3413 (comment (get symbol 'saved-face-comment))
3414 (comment-widget (widget-get widget :comment-widget)))
3415 (unless (or value comment)
3416 (error "No saved value for this face"))
3417 (put symbol 'customized-face nil)
3418 (put symbol 'customized-face-comment nil)
3419 (custom-push-theme 'theme-face symbol 'user 'set value)
3420 (face-spec-set symbol value)
3421 (put symbol 'face-comment comment)
3422 (widget-value-set child value)
3423 ;; This call manages the comment visibility
3424 (widget-value-set comment-widget (or comment ""))
3425 (custom-face-state-set widget)
3426 (custom-redraw-magic widget)))
3428 (defun custom-face-standard-value (widget)
3429 (get (widget-value widget) 'face-defface-spec))
3431 (defun custom-face-reset-standard (widget)
3432 "Restore WIDGET to the face's standard attribute values.
3433 This operation eliminates any saved attributes for the face,
3434 restoring it to the state of a face that has never been customized."
3435 (let* ((symbol (widget-value widget))
3436 (child (car (widget-get widget :children)))
3437 (value (get symbol 'face-defface-spec))
3438 (comment-widget (widget-get widget :comment-widget)))
3440 (error "No standard setting for this face"))
3441 (put symbol 'customized-face nil)
3442 (put symbol 'customized-face-comment nil)
3443 (custom-push-theme 'theme-face symbol 'user 'reset nil)
3444 (custom-theme-recalc-face symbol)
3445 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3446 (put symbol 'saved-face nil)
3447 (put symbol 'saved-face-comment nil)
3449 (put symbol 'face-comment nil)
3450 (widget-value-set child value)
3451 ;; This call manages the comment visibility
3452 (widget-value-set comment-widget "")
3453 (custom-face-state-set widget)
3454 (custom-redraw-magic widget)))
3456 ;;; The `face' Widget.
3458 (defvar widget-face-prompt-value-history nil
3459 "History of input to `widget-face-prompt-value'.")
3461 (define-widget 'face 'symbol
3462 "A Lisp face name (with sample)."
3463 :format "%{%t%}: (%{sample%}) %v"
3466 :sample-face-get 'widget-face-sample-face-get
3467 :notify 'widget-face-notify
3468 :match (lambda (widget value) (facep value))
3469 :complete-function (lambda ()
3471 (lisp-complete-symbol 'facep))
3472 :prompt-match 'facep
3473 :prompt-history 'widget-face-prompt-value-history
3474 :validate (lambda (widget)
3475 (unless (facep (widget-value widget))
3477 :error (format "Invalid face: %S"
3478 (widget-value widget)))
3481 (defun widget-face-sample-face-get (widget)
3482 (let ((value (widget-value widget)))
3487 (defun widget-face-notify (widget child &optional event)
3488 "Update the sample, and notify the parent."
3489 (overlay-put (widget-get widget :sample-overlay)
3490 'face (widget-apply widget :sample-face-get))
3491 (widget-default-notify widget child event))
3494 ;;; The `hook' Widget.
3496 (define-widget 'hook 'list
3498 :value-to-internal (lambda (widget value)
3499 (if (and value (symbolp value))
3502 :match (lambda (widget value)
3504 (widget-group-match widget value)))
3505 ;; Avoid adding undefined functions to the hook, especially for
3506 ;; things like `find-file-hook' or even more basic ones, to avoid
3508 :set (lambda (symbol value)
3511 (add-hook symbol elt))))
3512 :convert-widget 'custom-hook-convert-widget
3515 (defun custom-hook-convert-widget (widget)
3516 ;; Handle `:options'.
3517 (let* ((options (widget-get widget :options))
3518 (other `(editable-list :inline t
3519 :entry-format "%i %d%v"
3520 (function :format " %v")))
3522 (list `(checklist :inline t
3523 ,@(mapcar (lambda (entry)
3524 `(function-item ,entry))
3528 (widget-put widget :args args)
3531 ;;; The `custom-group-link' Widget.
3533 (define-widget 'custom-group-link 'link
3534 "Show parent in other window when activated."
3535 :help-echo "Create customization buffer for this group."
3536 :action 'custom-group-link-action)
3538 (defun custom-group-link-action (widget &rest ignore)
3539 (customize-group (widget-value widget)))
3541 ;;; The `custom-group' Widget.
3543 (defcustom custom-group-tag-faces nil
3544 ;; In XEmacs, this ought to play games with font size.
3545 ;; Fixme: make it do so in Emacs.
3546 "Face used for group tags.
3547 The first member is used for level 1 groups, the second for level 2,
3548 and so forth. The remaining group tags are shown with `custom-group-tag'."
3549 :type '(repeat face)
3550 :group 'custom-faces)
3552 (defface custom-group-tag-1
3555 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3556 (((min-colors 88) (class color)
3558 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3561 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3563 "Face used for group tags."
3564 :group 'custom-faces)
3565 ;; backward-compatibility alias
3566 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3568 (defface custom-group-tag
3571 (:foreground "light blue" :weight bold :height 1.2))
3572 (((min-colors 88) (class color)
3574 (:foreground "blue1" :weight bold :height 1.2))
3577 (:foreground "blue" :weight bold :height 1.2))
3579 "Face used for low level group tags."
3580 :group 'custom-faces)
3581 ;; backward-compatibility alias
3582 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3584 (define-widget 'custom-group 'custom
3587 :sample-face-get 'custom-group-sample-face-get
3588 :documentation-property 'group-documentation
3589 :help-echo "Set or reset all members of this group."
3590 :value-create 'custom-group-value-create
3591 :action 'custom-group-action
3592 :custom-category 'group
3593 :custom-set 'custom-group-set
3594 :custom-save 'custom-group-save
3595 :custom-reset-current 'custom-group-reset-current
3596 :custom-reset-saved 'custom-group-reset-saved
3597 :custom-reset-standard 'custom-group-reset-standard
3598 :custom-menu 'custom-group-menu-create)
3600 (defun custom-group-sample-face-get (widget)
3601 ;; Use :sample-face.
3602 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3605 (define-widget 'custom-group-visibility 'visibility
3606 "An indicator and manipulator for hidden group contents."
3607 :create 'custom-group-visibility-create)
3609 (defun custom-group-visibility-create (widget)
3610 (let ((visible (widget-value widget)))
3612 (insert "--------")))
3613 (widget-default-create widget))
3615 (defun custom-group-members (symbol groups-only)
3616 "Return SYMBOL's custom group members.
3617 If GROUPS-ONLY non-nil, return only those members that are groups."
3618 (if (not groups-only)
3619 (get symbol 'custom-group)
3621 (dolist (entry (get symbol 'custom-group))
3622 (when (eq (nth 1 entry) 'custom-group)
3623 (push entry members)))
3624 (nreverse members))))
3626 (defun custom-group-value-create (widget)
3627 "Insert a customize group for WIDGET in the current buffer."
3628 (unless (eq (widget-get widget :custom-state) 'hidden)
3629 (custom-load-widget widget))
3630 (let* ((state (widget-get widget :custom-state))
3631 (level (widget-get widget :custom-level))
3632 ;; (indent (widget-get widget :indent))
3633 (prefix (widget-get widget :custom-prefix))
3634 (buttons (widget-get widget :buttons))
3635 (tag (widget-get widget :tag))
3636 (symbol (widget-value widget))
3637 (members (custom-group-members symbol
3638 (and (eq custom-buffer-style 'tree)
3639 custom-browse-only-groups))))
3640 (cond ((and (eq custom-buffer-style 'tree)
3642 (or members (custom-unloaded-widget-p widget)))
3643 (custom-browse-insert-prefix prefix)
3644 (push (widget-create-child-and-convert
3645 widget 'custom-browse-visibility
3646 ;; :tag-glyph "plus"
3650 ;; (widget-glyph-insert nil "-- " "horizontal")
3651 (push (widget-create-child-and-convert
3652 widget 'custom-browse-group-tag)
3654 (insert " " tag "\n")
3655 (widget-put widget :buttons buttons))
3656 ((and (eq custom-buffer-style 'tree)
3657 (zerop (length members)))
3658 (custom-browse-insert-prefix prefix)
3660 ;; (widget-glyph-insert nil "[ ]" "empty")
3661 ;; (widget-glyph-insert nil "-- " "horizontal")
3662 (push (widget-create-child-and-convert
3663 widget 'custom-browse-group-tag)
3665 (insert " " tag "\n")
3666 (widget-put widget :buttons buttons))
3667 ((eq custom-buffer-style 'tree)
3668 (custom-browse-insert-prefix prefix)
3669 (if (zerop (length members))
3671 (custom-browse-insert-prefix prefix)
3673 ;; (widget-glyph-insert nil "[ ]" "empty")
3674 ;; (widget-glyph-insert nil "-- " "horizontal")
3675 (push (widget-create-child-and-convert
3676 widget 'custom-browse-group-tag)
3678 (insert " " tag "\n")
3679 (widget-put widget :buttons buttons))
3680 (push (widget-create-child-and-convert
3681 widget 'custom-browse-visibility
3682 ;; :tag-glyph "minus"
3686 ;; (widget-glyph-insert nil "-\\ " "top")
3687 (push (widget-create-child-and-convert
3688 widget 'custom-browse-group-tag)
3690 (insert " " tag "\n")
3691 (widget-put widget :buttons buttons)
3692 (message "Creating group...")
3693 (let* ((members (custom-sort-items members
3694 custom-browse-sort-alphabetically
3695 custom-browse-order-groups))
3696 (prefixes (widget-get widget :custom-prefixes))
3697 (custom-prefix-list (custom-prefix-add symbol prefixes))
3698 (extra-prefix (if (widget-get widget :custom-last)
3701 (prefix (concat prefix extra-prefix))
3704 (setq entry (car members)
3705 members (cdr members))
3706 (push (widget-create-child-and-convert
3707 widget (nth 1 entry)
3709 :tag (custom-unlispify-tag-name (nth 0 entry))
3710 :custom-prefixes custom-prefix-list
3711 :custom-level (1+ level)
3712 :custom-last (null members)
3713 :value (nth 0 entry)
3714 :custom-prefix prefix)
3716 (widget-put widget :children (reverse children)))
3717 (message "Creating group...done")))
3720 ;; Create level indicator.
3721 (unless (eq custom-buffer-style 'links)
3722 (insert-char ?\ (* custom-buffer-indent (1- level)))
3725 (let ((begin (point)))
3727 (widget-specify-sample widget begin (point)))
3729 ;; Create link/visibility indicator.
3730 (if (eq custom-buffer-style 'links)
3731 (push (widget-create-child-and-convert
3732 widget 'custom-group-link
3736 (push (widget-create-child-and-convert
3737 widget 'custom-group-visibility
3738 :help-echo "Show members of this group."
3739 :action 'custom-toggle-parent
3740 (not (eq state 'hidden)))
3743 ;; Create magic button.
3744 (let ((magic (widget-create-child-and-convert
3745 widget 'custom-magic nil)))
3746 (widget-put widget :custom-magic magic)
3747 (push magic buttons))
3749 (widget-put widget :buttons buttons)
3750 ;; Insert documentation.
3751 (if (and (eq custom-buffer-style 'links) (> level 1))
3752 (widget-put widget :documentation-indent 0))
3753 (widget-default-format-handler widget ?h))
3756 ;; Add parent groups references above the group.
3757 (if t ;;; This should test that the buffer
3758 ;;; was made to display a group.
3760 (if (custom-add-parent-links widget
3761 "Go to parent group:")
3763 ;; Create level indicator.
3764 (insert-char ?\ (* custom-buffer-indent (1- level)))
3767 (let ((start (point)))
3769 (widget-specify-sample widget start (point)))
3771 ;; Create visibility indicator.
3772 (unless (eq custom-buffer-style 'links)
3774 (push (widget-create-child-and-convert
3776 :help-echo "Hide members of this group."
3777 :action 'custom-toggle-parent
3778 (not (eq state 'hidden)))
3781 ;; Create more dashes.
3782 ;; Use 76 instead of 75 to compensate for the temporary "<"
3783 ;; added by `widget-insert'.
3784 (insert-char ?- (- 76 (current-column)
3785 (* custom-buffer-indent level)))
3787 ;; Create magic button.
3788 (let ((magic (widget-create-child-and-convert
3789 widget 'custom-magic
3792 (widget-put widget :custom-magic magic)
3793 (push magic buttons))
3795 (widget-put widget :buttons buttons)
3796 ;; Insert documentation.
3797 (widget-default-format-handler widget ?h)
3799 (if nil ;;; This should test that the buffer
3800 ;;; was not made to display a group.
3802 (insert-char ?\ custom-buffer-indent)
3803 (custom-add-parent-links widget)))
3804 (custom-add-see-also widget
3805 (make-string (* custom-buffer-indent level)
3808 (message "Creating group...")
3809 (let* ((members (custom-sort-items members
3810 custom-buffer-sort-alphabetically
3811 custom-buffer-order-groups))
3812 (prefixes (widget-get widget :custom-prefixes))
3813 (custom-prefix-list (custom-prefix-add symbol prefixes))
3814 (length (length members))
3816 (children (mapcar (lambda (entry)
3817 (widget-insert "\n")
3819 Creating group members... %2d%%"
3820 (/ (* 100.0 count) length))
3821 (setq count (1+ count))
3823 (widget-create-child-and-convert
3824 widget (nth 1 entry)
3826 :tag (custom-unlispify-tag-name
3828 :custom-prefixes custom-prefix-list
3829 :custom-level (1+ level)
3830 :value (nth 0 entry))
3831 (unless (eq (preceding-char) ?\n)
3832 (widget-insert "\n"))))
3834 (message "Creating group magic...")
3835 (mapc 'custom-magic-reset children)
3836 (message "Creating group state...")
3837 (widget-put widget :children children)
3838 (custom-group-state-update widget)
3839 (message "Creating group... done"))
3842 (insert-char ?\ (* custom-buffer-indent (1- level)))
3843 (insert "\\- " (widget-get widget :tag) " group end ")
3844 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3847 (defvar custom-group-menu
3848 `(("Set for Current Session" custom-group-set
3850 (eq (widget-get widget :custom-state) 'modified)))
3851 ,@(when (or custom-file user-init-file)
3852 '(("Save for Future Sessions" custom-group-save
3854 (memq (widget-get widget :custom-state) '(modified set))))))
3855 ("Reset to Current" custom-group-reset-current
3857 (memq (widget-get widget :custom-state) '(modified))))
3858 ("Reset to Saved" custom-group-reset-saved
3860 (memq (widget-get widget :custom-state) '(modified set))))
3861 ,@(when (or custom-file user-init-file)
3862 '(("Reset to standard setting" custom-group-reset-standard
3864 (memq (widget-get widget :custom-state) '(modified set saved)))))))
3865 "Alist of actions for the `custom-group' widget.
3866 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3867 the menu entry, ACTION is the function to call on the widget when the
3868 menu is selected, and FILTER is a predicate which takes a `custom-group'
3869 widget as an argument, and returns non-nil if ACTION is valid on that
3870 widget. If FILTER is nil, ACTION is always valid.")
3872 (defun custom-group-action (widget &optional event)
3873 "Show the menu for `custom-group' WIDGET.
3874 Optional EVENT is the location for the menu."
3875 (if (eq (widget-get widget :custom-state) 'hidden)
3876 (custom-toggle-hide widget)
3877 (let* ((completion-ignore-case t)
3878 (answer (widget-choose (concat "Operation on "
3879 (custom-unlispify-tag-name
3880 (widget-get widget :value)))
3881 (custom-menu-filter custom-group-menu
3885 (funcall answer widget)))))
3887 (defun custom-group-set (widget)
3888 "Set changes in all modified group members."
3889 (let ((children (widget-get widget :children)))
3890 (mapc (lambda (child)
3891 (when (eq (widget-get child :custom-state) 'modified)
3892 (widget-apply child :custom-set)))
3895 (defun custom-group-save (widget)
3896 "Save all modified group members."
3897 (let ((children (widget-get widget :children)))
3898 (mapc (lambda (child)
3899 (when (memq (widget-get child :custom-state) '(modified set))
3900 (widget-apply child :custom-save)))
3903 (defun custom-group-reset-current (widget)
3904 "Reset all modified group members."
3905 (let ((children (widget-get widget :children)))
3906 (mapc (lambda (child)
3907 (when (eq (widget-get child :custom-state) 'modified)
3908 (widget-apply child :custom-reset-current)))
3911 (defun custom-group-reset-saved (widget)
3912 "Reset all modified or set group members."
3913 (let ((children (widget-get widget :children)))
3914 (mapc (lambda (child)
3915 (when (memq (widget-get child :custom-state) '(modified set))
3916 (widget-apply child :custom-reset-saved)))
3919 (defun custom-group-reset-standard (widget)
3920 "Reset all modified, set, or saved group members."
3921 (let ((children (widget-get widget :children)))
3922 (mapc (lambda (child)
3923 (when (memq (widget-get child :custom-state)
3924 '(modified set saved))
3925 (widget-apply child :custom-reset-standard)))
3928 (defun custom-group-state-update (widget)
3930 (unless (eq (widget-get widget :custom-state) 'hidden)
3931 (let* ((children (widget-get widget :children))
3932 (states (mapcar (lambda (child)
3933 (widget-get child :custom-state))
3935 (magics custom-magic-alist)
3938 (let ((magic (car (car magics))))
3939 (if (and (not (eq magic 'hidden))
3940 (memq magic states))
3943 (setq magics (cdr magics)))))
3944 (widget-put widget :custom-state found)))
3945 (custom-magic-reset widget))
3947 ;;; Reading and writing the custom file.
3950 (defcustom custom-file nil
3951 "File used for storing customization information.
3952 The default is nil, which means to use your init file
3953 as specified by `user-init-file'. If the value is not nil,
3954 it should be an absolute file name.
3956 You can set this option through Custom, if you carefully read the
3957 last paragraph below. However, usually it is simpler to write
3958 something like the following in your init file:
3960 \(setq custom-file \"~/.emacs-custom.el\")
3963 Note that both lines are necessary: the first line tells Custom to
3964 save all customizations in this file, but does not load it.
3966 When you change this variable outside Custom, look in the
3967 previous custom file \(usually your init file) for the
3968 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3969 and copy them (whichever ones you find) to the new custom file.
3970 This will preserve your existing customizations.
3972 If you save this option using Custom, Custom will write all
3973 currently saved customizations, including the new one for this
3974 option itself, into the file you specify, overwriting any
3975 `custom-set-variables' and `custom-set-faces' forms already
3976 present in that file. It will not delete any customizations from
3977 the old custom file. You should do that manually if that is what you
3978 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3979 in your init file, where CUSTOM-FILE is the actual name of the
3980 file. Otherwise, Emacs will not load the file when it starts up,
3981 and hence will not set `custom-file' to that file either."
3982 :type '(choice (const :tag "Your Emacs init file" nil)
3983 (file :format "%t:%v%d"
3985 "Please read entire docstring below before setting \
3986 this through Custom.
3987 Click om \"More\" \(or position point there and press RETURN)
3988 if only the first line of the docstring is shown."))
3991 (defun custom-file ()
3992 "Return the file name for saving customizations."
3995 (let ((user-init-file user-init-file)
3997 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3998 (when (null user-init-file)
3999 (if (or (file-exists-p default-init-file)
4000 (and (eq system-type 'windows-nt)
4001 (file-exists-p "~/_emacs")))
4002 ;; Started with -q, i.e. the file containing
4003 ;; Custom settings hasn't been read. Saving
4004 ;; settings there would overwrite other settings.
4005 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4006 (setq user-init-file default-init-file))
4010 (defun custom-save-all ()
4011 "Save all customizations in `custom-file'."
4012 (let* ((filename (custom-file))
4013 (recentf-exclude (if recentf-mode
4015 (regexp-quote (custom-file))
4018 (old-buffer (find-buffer-visiting filename)))
4019 (with-current-buffer (or old-buffer (find-file-noselect filename))
4020 (let ((inhibit-read-only t))
4021 (custom-save-variables)
4022 (custom-save-faces))
4023 (let ((file-precious-flag t))
4026 (kill-buffer (current-buffer))))))
4028 ;; Editing the custom file contents in a buffer.
4030 (defun custom-save-delete (symbol)
4031 "Delete all calls to SYMBOL from the contents of the current buffer.
4032 Leave point at the old location of the first such call,
4033 or (if there were none) at the end of the buffer.
4035 This function does not save the buffer."
4036 (goto-char (point-min))
4037 ;; Skip all whitespace and comments.
4038 (while (forward-comment 1))
4040 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4043 (while t ;; We exit this loop only via throw.
4044 ;; Skip all whitespace and comments.
4045 (while (forward-comment 1))
4046 (let ((start (point))
4047 (sexp (condition-case nil
4048 (read (current-buffer))
4049 (end-of-file (throw 'found nil)))))
4050 (when (and (listp sexp)
4051 (eq (car sexp) symbol))
4052 (delete-region start (point))
4054 (setq first (point)))))))
4057 ;; Move in front of local variables, otherwise long Custom
4058 ;; entries would make them ineffective.
4059 (let ((pos (point-max))
4060 (case-fold-search t))
4062 (goto-char (point-max))
4063 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4065 (when (search-forward "Local Variables:" nil t)
4066 (setq pos (line-beginning-position))))
4069 (defun custom-save-variables ()
4070 "Save all customized variables in `custom-file'."
4072 (custom-save-delete 'custom-load-themes)
4073 (custom-save-delete 'custom-reset-variables)
4074 (custom-save-delete 'custom-set-variables)
4075 (custom-save-loaded-themes)
4076 (custom-save-resets 'theme-value 'custom-reset-variables nil)
4077 (let ((standard-output (current-buffer))
4078 (saved-list (make-list 1 0))
4080 ;; First create a sorted list of saved variables.
4083 (if (get symbol 'saved-value)
4084 (nconc saved-list (list symbol)))))
4085 (setq saved-list (sort (cdr saved-list) 'string<))
4088 (princ "(custom-set-variables
4089 ;; custom-set-variables was added by Custom.
4090 ;; If you edit it by hand, you could mess it up, so be careful.
4091 ;; Your init file should contain only one such instance.
4092 ;; If there is more than one, they won't work right.\n")
4093 (dolist (symbol saved-list)
4094 (let ((spec (car-safe (get symbol 'theme-value)))
4095 (value (get symbol 'saved-value))
4096 (requests (get symbol 'custom-requests))
4097 (now (not (or (custom-variable-p symbol)
4098 (and (not (boundp symbol))
4099 (not (eq (get symbol 'force-value)
4101 (comment (get symbol 'saved-variable-comment)))
4102 ;; Check `requests'.
4103 (dolist (request requests)
4104 (when (and (symbolp request) (not (featurep request)))
4105 (message "Unknown requested feature: %s" request)
4106 (setq requests (delq request requests))))
4108 (eq (nth 0 spec) 'user)
4109 (eq (nth 1 spec) 'set))
4111 (and (null spec) (get symbol 'saved-value)))
4118 (when (or now requests comment)
4121 (when (or requests comment)
4131 (unless (looking-at "\n")
4134 (defun custom-save-faces ()
4135 "Save all customized faces in `custom-file'."
4137 (custom-save-delete 'custom-reset-faces)
4138 (custom-save-delete 'custom-set-faces)
4139 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
4140 (let ((standard-output (current-buffer))
4141 (saved-list (make-list 1 0))
4143 ;; First create a sorted list of saved faces.
4146 (if (get symbol 'saved-face)
4147 (nconc saved-list (list symbol)))))
4148 (setq saved-list (sort (cdr saved-list) 'string<))
4149 ;; The default face must be first, since it affects the others.
4150 (if (memq 'default saved-list)
4151 (setq saved-list (cons 'default (delq 'default saved-list))))
4154 (princ "(custom-set-faces
4155 ;; custom-set-faces was added by Custom.
4156 ;; If you edit it by hand, you could mess it up, so be careful.
4157 ;; Your init file should contain only one such instance.
4158 ;; If there is more than one, they won't work right.\n")
4159 (dolist (symbol saved-list)
4160 (let ((spec (car-safe (get symbol 'theme-face)))
4161 (value (get symbol 'saved-face))
4162 (now (not (or (get symbol 'face-defface-spec)
4163 (and (not (custom-facep symbol))
4164 (not (get symbol 'force-face))))))
4165 (comment (get symbol 'saved-face-comment)))
4167 (eq (nth 0 spec) 'user)
4168 (eq (nth 1 spec) 'set))
4170 (and (null spec) (get symbol 'saved-face)))
4171 ;; Don't print default face here.
4178 (when (or now comment)
4188 (unless (looking-at "\n")
4191 (defun custom-save-resets (property setter special)
4192 (let (started-writing ignored-special)
4193 ;; (custom-save-delete setter) Done by caller
4194 (let ((standard-output (current-buffer))
4195 (mapper `(lambda (object)
4196 (let ((spec (car-safe (get object (quote ,property)))))
4197 (when (and (not (memq object ignored-special))
4198 (eq (nth 0 spec) 'user)
4199 (eq (nth 1 spec) 'reset))
4200 ;; Do not write reset statements unless necessary.
4201 (unless started-writing
4202 (setq started-writing t)
4206 (princ (quote ,setter))
4210 (prin1 (nth 3 spec))
4212 (mapc mapper special)
4213 (setq ignored-special special)
4215 (when started-writing
4218 (defun custom-save-loaded-themes ()
4219 (let ((themes (reverse (get 'user 'theme-loads-themes)))
4220 (standard-output (current-buffer)))
4222 (unless (bolp) (princ "\n"))
4223 (princ "(custom-load-themes")
4224 (mapc (lambda (theme)
4226 (prin1 theme)) themes)
4230 (defun customize-save-customized ()
4231 "Save all user options which have been set in this session."
4233 (mapatoms (lambda (symbol)
4234 (let ((face (get symbol 'customized-face))
4235 (value (get symbol 'customized-value))
4236 (face-comment (get symbol 'customized-face-comment))
4238 (get symbol 'customized-variable-comment)))
4240 (put symbol 'saved-face face)
4241 (custom-push-theme 'theme-face symbol 'user 'set value)
4242 (put symbol 'customized-face nil))
4244 (put symbol 'saved-value value)
4245 (custom-push-theme 'theme-value symbol 'user 'set value)
4246 (put symbol 'customized-value nil))
4247 (when variable-comment
4248 (put symbol 'saved-variable-comment variable-comment)
4249 (put symbol 'customized-variable-comment nil))
4251 (put symbol 'saved-face-comment face-comment)
4252 (put symbol 'customized-face-comment nil)))))
4253 ;; We really should update all custom buffers here.
4256 ;;; The Customize Menu.
4260 (defcustom custom-menu-nesting 2
4261 "Maximum nesting in custom menus."
4263 :group 'custom-menu)
4265 (defun custom-face-menu-create (widget symbol)
4266 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4267 (vector (custom-unlispify-menu-entry symbol)
4268 `(customize-face ',symbol)
4271 (defun custom-variable-menu-create (widget symbol)
4272 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4273 (let ((type (get symbol 'custom-type)))
4274 (unless (listp type)
4275 (setq type (list type)))
4276 (if (and type (widget-get type :custom-menu))
4277 (widget-apply type :custom-menu symbol)
4278 (vector (custom-unlispify-menu-entry symbol)
4279 `(customize-variable ',symbol)
4282 ;; Add checkboxes to boolean variable entries.
4283 (widget-put (get 'boolean 'widget-type)
4284 :custom-menu (lambda (widget symbol)
4285 (vector (custom-unlispify-menu-entry symbol)
4286 `(customize-variable ',symbol)
4288 ':selected symbol)))
4290 (defun custom-group-menu-create (widget symbol)
4291 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4292 `( ,(custom-unlispify-menu-entry symbol t)
4293 :filter (lambda (&rest junk)
4294 (let ((menu (custom-menu-create ',symbol)))
4295 (if (consp menu) (cdr menu) menu)))))
4298 (defun custom-menu-create (symbol)
4299 "Create menu for customization group SYMBOL.
4300 The menu is in a format applicable to `easy-menu-define'."
4301 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4302 `(customize-group ',symbol)
4304 (if (and (or (not (boundp 'custom-menu-nesting))
4305 (>= custom-menu-nesting 0))
4307 (custom-load-symbol symbol)
4308 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4309 (let ((custom-prefix-list (custom-prefix-add symbol
4310 custom-prefix-list))
4311 (members (custom-sort-items (get symbol 'custom-group)
4312 custom-menu-sort-alphabetically
4313 custom-menu-order-groups)))
4314 `(,(custom-unlispify-menu-entry symbol t)
4317 ,@(mapcar (lambda (entry)
4318 (widget-apply (if (listp (nth 1 entry))
4320 (list (nth 1 entry)))
4321 :custom-menu (nth 0 entry)))
4326 (defun customize-menu-create (symbol &optional name)
4327 "Return a customize menu for customization group SYMBOL.
4328 If optional NAME is given, use that as the name of the menu.
4329 Otherwise the menu will be named `Customize'.
4330 The format is suitable for use with `easy-menu-define'."
4332 (setq name "Customize"))
4334 :filter (lambda (&rest junk)
4335 (let ((menu (custom-menu-create ',symbol)))
4336 (if (consp menu) (cdr menu) menu)))))
4338 ;;; The Custom Mode.
4340 (defvar custom-mode-map
4341 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4342 ;; "\r" bindings from the parent map.
4343 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4344 (let ((map (make-keymap)))
4345 (set-keymap-parent map widget-keymap)
4346 (suppress-keymap map)
4347 (define-key map " " 'scroll-up)
4348 (define-key map "\177" 'scroll-down)
4349 (define-key map "\C-c\C-c" 'Custom-set)
4350 (define-key map "\C-x\C-s" 'Custom-save)
4351 (define-key map "q" 'Custom-buffer-done)
4352 (define-key map "u" 'Custom-goto-parent)
4353 (define-key map "n" 'widget-forward)
4354 (define-key map "p" 'widget-backward)
4355 (define-key map [mouse-1] 'widget-move-and-invoke)
4357 "Keymap for `custom-mode'.")
4359 (easy-menu-define Custom-mode-menu
4361 "Menu used in customization buffers."
4363 ,(customize-menu-create 'customize)
4364 ["Set" Custom-set t]
4365 ["Save" Custom-save t]
4366 ["Reset to Current" Custom-reset-current t]
4367 ["Reset to Saved" Custom-reset-saved t]
4368 ["Reset to Standard Values" Custom-reset-standard t]
4369 ["Info" (info "(emacs)Easy Customization") t]))
4371 (defun Custom-goto-parent ()
4372 "Go to the parent group listed at the top of this buffer.
4373 If several parents are listed, go to the first of them."
4376 (goto-char (point-min))
4377 (if (search-forward "\nGo to parent group: " nil t)
4378 (let* ((button (get-char-property (point) 'button))
4379 (parent (downcase (widget-get button :tag))))
4380 (customize-group parent)))))
4382 (defcustom custom-mode-hook nil
4383 "Hook called when entering Custom mode."
4385 :group 'custom-buffer )
4387 (defun custom-state-buffer-message (widget)
4388 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4389 (message "To install your edits, invoke [State] and choose the Set operation")))
4391 (defun custom-mode ()
4392 "Major mode for editing customization buffers.
4394 The following commands are available:
4396 Move to next button or editable field. \\[widget-forward]
4397 Move to previous button or editable field. \\[widget-backward]
4398 \\<widget-field-keymap>\
4399 Complete content of editable text field. \\[widget-complete]
4400 \\<custom-mode-map>\
4401 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4402 Invoke button under point. \\[widget-button-press]
4403 Set all modifications. \\[Custom-set]
4404 Make all modifications default. \\[Custom-save]
4405 Reset all modified options. \\[Custom-reset-current]
4406 Reset all modified or set options. \\[Custom-reset-saved]
4407 Reset all options. \\[Custom-reset-standard]
4409 Entry to this mode calls the value of `custom-mode-hook'
4410 if that value is non-nil."
4411 (kill-all-local-variables)
4412 (setq major-mode 'custom-mode
4414 (use-local-map custom-mode-map)
4415 (easy-menu-add Custom-mode-menu)
4416 (make-local-variable 'custom-options)
4417 (make-local-variable 'custom-local-buffer)
4418 (make-local-variable 'widget-documentation-face)
4419 (setq widget-documentation-face 'custom-documentation)
4420 (make-local-variable 'widget-button-face)
4421 (setq widget-button-face custom-button)
4422 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4423 (if custom-raised-buttons
4424 (set (make-local-variable 'widget-mouse-face) custom-button))
4426 ;; When possible, use relief for buttons, not bracketing. This test
4427 ;; may not be optimal.
4428 (when custom-raised-buttons
4429 (set (make-local-variable 'widget-push-button-prefix) "")
4430 (set (make-local-variable 'widget-push-button-suffix) "")
4431 (set (make-local-variable 'widget-link-prefix) "")
4432 (set (make-local-variable 'widget-link-suffix) ""))
4433 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4434 (run-mode-hooks 'custom-mode-hook))
4436 (put 'custom-mode 'mode-class 'special)
4439 'debug-ignored-errors
4440 "^No user options have changed defaults in recent Emacs versions$")
4446 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4447 ;;; cus-edit.el ends here