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. You
125 ;; can not create a Custom buffer for such variables using the
126 ;; normal interactive Custom commands. However, such Custom
127 ;; buffers can be created in other ways, for instance, by calling
128 ;; `customize-option' non-interactively.
132 ;; There is no widget value.
136 ;; The widget value is not valid member of the :type specified for the
144 (defvar custom-versions-load-alist) ; from cus-load
145 (defvar recentf-exclude)) ; from recentf.el
155 (put 'custom-define-hook 'custom-type 'hook)
156 (put 'custom-define-hook 'standard-value '(nil))
157 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
159 ;;; Customization Groups.
162 "Customization of the One True Editor."
163 :link '(custom-manual "(emacs)Top"))
165 ;; Most of these groups are stolen from `finder.el',
166 (defgroup editing nil
167 "Basic text editing facilities."
171 "Abbreviation handling, typing shortcuts, macros."
175 (defgroup matching nil
176 "Various sorts of searching and matching."
179 (defgroup emulations nil
180 "Emulations of other editors."
181 :link '(custom-manual "(emacs)Emulation")
188 (defgroup outlines nil
189 "Support for hierarchical outlining."
192 (defgroup external nil
193 "Interfacing to external utilities."
196 (defgroup processes nil
197 "Process, subshell, compilation, and job control support."
201 (defgroup convenience nil
202 "Convenience features for faster editing."
205 (defgroup programming nil
206 "Support for programming in other languages."
209 (defgroup languages nil
210 "Specialized modes for editing programming languages."
214 "Lisp support, including Emacs Lisp."
215 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
220 "Support for the C language and related languages."
221 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
222 :link '(custom-manual "(ccmode)")
230 "Support for object-oriented programming."
233 (defgroup applications nil
234 "Applications written in Emacs."
237 (defgroup calendar nil
238 "Calendar and time management support."
239 :group 'applications)
242 "Modes for electronic-mail handling."
243 :group 'applications)
246 "Support for netnews reading and posting."
247 :link '(custom-manual "(gnus)")
248 :group 'applications)
251 "Games, jokes and amusements."
252 :group 'applications)
254 (defgroup development nil
255 "Support for further development of Emacs."
259 "Support for Emacs documentation."
262 (defgroup extensions nil
263 "Emacs Lisp language extensions."
266 (defgroup internal nil
267 "Code for Emacs internals, build process, defaults."
271 "Maintenance aids for the Emacs development group."
275 (defgroup environment nil
276 "Fitting Emacs with its environment."
280 "Communications, networking, remote access to files."
284 (defgroup hardware nil
285 "Support for interfacing with exotic hardware."
288 (defgroup terminals nil
289 "Support for terminal types."
293 "Front-ends/assistants for, or emulators of, UNIX features."
297 "Support code for vms."
301 "Internationalization and alternate character-set support."
302 :link '(custom-manual "(emacs)International")
307 "The X Window system."
311 "Support for Emacs frames and window systems."
315 "Support editing files of data."
319 "Support editing files."
327 "Code related to the TeX formatter."
328 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
332 "Support for multiple fonts."
335 (defgroup hypermedia nil
336 "Support for links between text or other media types."
340 "Support for on-line help systems."
343 (defgroup multimedia nil
344 "Non-textual support, specifically images and sound."
348 "Code local to your site."
351 (defgroup customize '((widgets custom-group))
352 "Customization of the Customization support."
356 (defgroup custom-faces nil
357 "Faces used by customize."
361 (defgroup custom-browse nil
362 "Control customize browser."
366 (defgroup custom-buffer nil
367 "Control customize buffers."
371 (defgroup custom-menu nil
372 "Control customize menus."
376 (defgroup abbrev-mode nil
377 "Word abbreviations mode."
378 :link '(custom-manual "(emacs)Abbrevs")
382 "Storage allocation and gc for GNU Emacs Lisp interpreter."
383 :tag "Storage Allocation"
387 "Undoing changes in buffers."
388 :link '(custom-manual "(emacs)Undo")
391 (defgroup modeline nil
392 "Content of the modeline."
395 (defgroup editing-basics nil
396 "Most basic editing facilities."
399 (defgroup display nil
400 "How characters are displayed in buffers."
403 (defgroup execute nil
404 "Executing external commands."
407 (defgroup installation nil
408 "The Emacs installation."
416 "Internal Emacs limits."
420 "Debugging Emacs itself."
423 (defgroup minibuffer nil
424 "Controling the behavior of the minibuffer."
425 :link '(custom-manual "(emacs)Minibuffer")
428 (defgroup keyboard nil
429 "Input from the keyboard."
433 "Input from the mouse."
437 "Input from the menus."
441 "Handling data from drag and drop."
444 (defgroup auto-save nil
445 "Preventing accidential loss of data."
448 (defgroup processes-basics nil
449 "Basic stuff dealing with processes."
453 "MULE Emacs internationalization."
456 (defgroup windows nil
457 "Windows within a frame."
458 :link '(custom-manual "(emacs)Windows")
463 (defun custom-quote (sexp)
464 "Quote SEXP iff it is not self quoting."
465 (if (or (memq sexp '(t nil))
468 (memq (car sexp) '(lambda)))
472 ;;; (and (fboundp 'characterp)
473 ;;; (characterp sexp))
478 (defun custom-split-regexp-maybe (regexp)
479 "If REGEXP is a string, split it to a list at `\\|'.
480 You can get the original back with from the result with:
481 (mapconcat 'identity result \"\\|\")
483 IF REGEXP is not a string, return it unchanged."
487 (while (string-match "\\\\|" regexp start)
488 (setq all (cons (substring regexp start (match-beginning 0)) all)
489 start (match-end 0)))
490 (nreverse (cons (substring regexp start) all)))
493 (defun custom-variable-prompt ()
494 "Prompt for a custom variable, defaulting to the variable at point.
495 Return a list suitable for use in `interactive'."
496 (let* ((v (variable-at-point))
497 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
498 (enable-recursive-minibuffers t)
500 (setq val (completing-read
501 (if default (format "Customize option (default %s): " default)
502 "Customize option: ")
503 obarray 'custom-variable-p t nil nil default))
504 (list (if (equal val "")
505 (if (symbolp v) v nil)
508 (defun custom-menu-filter (menu widget)
509 "Convert MENU to the form used by `widget-choose'.
510 MENU should be in the same format as `custom-variable-menu'.
511 WIDGET is the widget to apply the filter entries of MENU on."
513 current name action filter)
515 (setq current (car menu)
517 action (nth 1 current)
518 filter (nth 2 current)
520 (if (or (null filter) (funcall filter widget))
521 (push (cons name action) result)
527 (defvar custom-prefix-list nil
528 "List of prefixes that should be ignored by `custom-unlispify'.")
530 (defcustom custom-unlispify-menu-entries t
531 "Display menu entries as words instead of symbols if non nil."
535 (defcustom custom-unlispify-remove-prefixes nil
536 "Non-nil means remove group prefixes from option names in buffer."
538 :group 'custom-buffer
541 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
542 "Convert SYMBOL into a menu entry."
543 (cond ((not custom-unlispify-menu-entries)
544 (symbol-name symbol))
545 ((get symbol 'custom-tag)
547 (get symbol 'custom-tag)
548 (concat (get symbol 'custom-tag) "...")))
550 (with-current-buffer (get-buffer-create " *Custom-Work*")
552 (princ symbol (current-buffer))
553 (goto-char (point-min))
554 ;; FIXME: Boolean variables are not predicates, so they shouldn't
555 ;; end with `-p'. -stef
556 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
557 ;; (re-search-forward "-p\\'" nil t))
558 ;; (replace-match "" t t)
559 ;; (goto-char (point-min)))
560 (if custom-unlispify-remove-prefixes
561 (let ((prefixes custom-prefix-list)
564 (setq prefix (car prefixes))
565 (if (search-forward prefix (+ (point) (length prefix)) t)
568 (delete-region (point-min) (point)))
569 (setq prefixes (cdr prefixes))))))
570 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
571 (capitalize-region (point-min) (point-max))
573 (goto-char (point-max))
577 (defcustom custom-unlispify-tag-names t
578 "Display tag names as words instead of symbols if non nil."
579 :group 'custom-buffer
582 (defun custom-unlispify-tag-name (symbol)
583 "Convert SYMBOL into a menu entry."
584 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
585 (custom-unlispify-menu-entry symbol t)))
587 (defun custom-prefix-add (symbol prefixes)
588 "Add SYMBOL to list of ignored PREFIXES."
589 (cons (or (get symbol 'custom-prefix)
590 (concat (symbol-name symbol) "-"))
595 (defcustom custom-guess-name-alist
600 ("-function\\'" function)
601 ("-functions\\'" (repeat function))
602 ("-list\\'" (repeat sexp))
603 ("-alist\\'" (repeat (cons sexp sexp))))
604 "Alist of (MATCH TYPE).
606 MATCH should be a regexp matching the name of a symbol, and TYPE should
607 be a widget suitable for editing the value of that symbol. The TYPE
608 of the first entry where MATCH matches the name of the symbol will be
611 This is used for guessing the type of variables not declared with
613 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
616 (defcustom custom-guess-doc-alist
617 '(("\\`\\*?Non-nil " boolean))
618 "Alist of (MATCH TYPE).
620 MATCH should be a regexp matching a documentation string, and TYPE
621 should be a widget suitable for editing the value of a variable with
622 that documentation string. The TYPE of the first entry where MATCH
623 matches the name of the symbol will be used.
625 This is used for guessing the type of variables not declared with
627 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
630 (defun custom-guess-type (symbol)
631 "Guess a widget suitable for editing the value of SYMBOL.
632 This is done by matching SYMBOL with `custom-guess-name-alist' and
633 if that fails, the doc string with `custom-guess-doc-alist'."
634 (let ((name (symbol-name symbol))
635 (names custom-guess-name-alist)
638 (setq current (car names)
640 (when (string-match (nth 0 current) name)
641 (setq found (nth 1 current)
644 (let ((doc (documentation-property symbol 'variable-documentation))
645 (docs custom-guess-doc-alist))
648 (setq current (car docs)
650 (when (string-match (nth 0 current) doc)
651 (setq found (nth 1 current)
657 (defcustom custom-browse-sort-alphabetically nil
658 "If non-nil, sort members of each customization group alphabetically."
660 :group 'custom-browse)
662 (defcustom custom-browse-order-groups nil
663 "If non-nil, order group members within each customization group.
664 If `first', order groups before non-groups.
665 If `last', order groups after non-groups."
666 :type '(choice (const first)
668 (const :tag "none" nil))
669 :group 'custom-browse)
671 (defcustom custom-browse-only-groups nil
672 "If non-nil, show group members only within each customization group."
674 :group 'custom-browse)
676 (defcustom custom-buffer-sort-alphabetically nil
677 "If non-nil, sort members of each customization group alphabetically."
679 :group 'custom-buffer)
681 (defcustom custom-buffer-order-groups 'last
682 "If non-nil, order group members within each customization group.
683 If `first', order groups before non-groups.
684 If `last', order groups after non-groups."
685 :type '(choice (const first)
687 (const :tag "none" nil))
688 :group 'custom-buffer)
690 (defcustom custom-menu-sort-alphabetically nil
691 "If non-nil, sort members of each customization group alphabetically."
695 (defcustom custom-menu-order-groups 'first
696 "If non-nil, order group members within each customization group.
697 If `first', order groups before non-groups.
698 If `last', order groups after non-groups."
699 :type '(choice (const first)
701 (const :tag "none" nil))
704 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
706 (defun custom-sort-items (items sort-alphabetically order-groups)
707 "Return a sorted copy of ITEMS.
708 ITEMS should be a `custom-group' property.
709 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
710 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
711 groups after non-groups, if nil do not order groups at all."
712 (sort (copy-sequence items)
714 (let ((typea (nth 1 a)) (typeb (nth 1 b))
715 (namea (nth 0 a)) (nameb (nth 0 b)))
716 (cond ((not order-groups)
717 ;; Since we don't care about A and B order, maybe sort.
718 (when sort-alphabetically
719 (string-lessp namea nameb)))
720 ((eq typea 'custom-group)
721 ;; If B is also a group, maybe sort. Otherwise, order A and B.
722 (if (eq typeb 'custom-group)
723 (when sort-alphabetically
724 (string-lessp namea nameb))
725 (eq order-groups 'first)))
726 ((eq typeb 'custom-group)
727 ;; Since A cannot be a group, order A and B.
728 (eq order-groups 'last))
730 ;; Since A and B cannot be groups, sort.
731 (string-lessp namea nameb)))))))
733 ;;; Custom Mode Commands.
735 (defvar custom-options nil
736 "Customization widgets in the current buffer.")
739 "Set changes in all modified options."
741 (let ((children custom-options))
742 (mapc (lambda (child)
743 (when (eq (widget-get child :custom-state) 'modified)
744 (widget-apply child :custom-set)))
747 (defun Custom-save ()
748 "Set all modified group members and save them."
750 (let ((children custom-options))
751 (mapc (lambda (child)
752 (when (memq (widget-get child :custom-state)
753 '(modified set changed rogue))
754 (widget-apply child :custom-save)))
758 (defvar custom-reset-menu
759 '(("Current" . Custom-reset-current)
760 ("Saved" . Custom-reset-saved)
761 ("Erase Customization (use standard settings)" . Custom-reset-standard))
762 "Alist of actions for the `Reset' button.
763 The key is a string containing the name of the action, the value is a
764 Lisp function taking the widget as an element which will be called
765 when the action is chosen.")
767 (defun custom-reset (event)
768 "Select item from reset menu."
769 (let* ((completion-ignore-case t)
770 (answer (widget-choose "Reset to"
776 (defun Custom-reset-current (&rest ignore)
777 "Reset all modified group members to their current value."
779 (let ((children custom-options))
780 (mapc (lambda (widget)
781 (if (memq (widget-get widget :custom-state)
783 (widget-apply widget :custom-reset-current)))
786 (defun Custom-reset-saved (&rest ignore)
787 "Reset all modified or set group members to their saved value."
789 (let ((children custom-options))
790 (mapc (lambda (widget)
791 (if (memq (widget-get widget :custom-state)
792 '(modified set changed rogue))
793 (widget-apply widget :custom-reset-saved)))
796 (defun Custom-reset-standard (&rest ignore)
797 "Erase all customization (either current or saved) for the group members.
798 The immediate result is to restore them to their standard settings.
799 This operation eliminates any saved settings for the group members,
800 making them as if they had never been customized at all."
802 (let ((children custom-options))
803 (mapc (lambda (widget)
804 (and (widget-get widget :custom-standard-value)
805 (widget-apply widget :custom-standard-value)
806 (if (memq (widget-get widget :custom-state)
807 '(modified set changed saved rogue))
808 (widget-apply widget :custom-reset-standard))))
811 ;;; The Customize Commands
813 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
814 "Prompt for a variable and a value and return them as a list.
815 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
816 prompt for the value. The %s escape in PROMPT-VAL is replaced with
817 the name of the variable.
819 If the variable has a `variable-interactive' property, that is used as if
820 it were the arg to `interactive' (which see) to interactively read the value.
822 If the variable has a `custom-type' property, it must be a widget and the
823 `:prompt-value' property of that widget will be used for reading the value.
825 If optional COMMENT argument is non nil, also prompt for a comment and return
826 it as the third element in the list."
827 (let* ((var (read-variable prompt-var))
828 (minibuffer-help-form '(describe-variable var))
830 (let ((prop (get var 'variable-interactive))
831 (type (get var 'custom-type))
832 (prompt (format prompt-val var)))
834 (setq type (list type)))
836 ;; Use VAR's `variable-interactive' property
837 ;; as an interactive spec for prompting.
838 (call-interactively (list 'lambda '(arg)
839 (list 'interactive prop)
842 (widget-prompt-value type
848 (eval-minibuffer prompt))))))
851 (read-string "Comment: " (get var 'variable-comment)))
855 (defun customize-set-value (variable value &optional comment)
856 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
858 If VARIABLE has a `variable-interactive' property, that is used as if
859 it were the arg to `interactive' (which see) to interactively read the value.
861 If VARIABLE has a `custom-type' property, it must be a widget and the
862 `:prompt-value' property of that widget will be used for reading the value.
864 If given a prefix (or a COMMENT argument), also prompt for a comment."
865 (interactive (custom-prompt-variable "Set variable: "
869 (cond ((string= comment "")
870 (put variable 'variable-comment nil))
872 (put variable 'variable-comment comment)))
873 (set variable value))
876 (defun customize-set-variable (variable value &optional comment)
877 "Set the default for VARIABLE to VALUE, and return VALUE.
878 VALUE is a Lisp object.
880 If VARIABLE has a `custom-set' property, that is used for setting
881 VARIABLE, otherwise `set-default' is used.
883 The `customized-value' property of the VARIABLE will be set to a list
884 with a quoted VALUE as its sole list member.
886 If VARIABLE has a `variable-interactive' property, that is used as if
887 it were the arg to `interactive' (which see) to interactively read the value.
889 If VARIABLE has a `custom-type' property, it must be a widget and the
890 `:prompt-value' property of that widget will be used for reading the value.
892 If given a prefix (or a COMMENT argument), also prompt for a comment."
893 (interactive (custom-prompt-variable "Set variable: "
894 "Set customized value for %s to: "
896 (custom-load-symbol variable)
897 (funcall (or (get variable 'custom-set) 'set-default) variable value)
898 (put variable 'customized-value (list (custom-quote value)))
899 (cond ((string= comment "")
900 (put variable 'variable-comment nil)
901 (put variable 'customized-variable-comment nil))
903 (put variable 'variable-comment comment)
904 (put variable 'customized-variable-comment comment)))
908 (defun customize-save-variable (variable value &optional comment)
909 "Set the default for VARIABLE to VALUE, and save it for future sessions.
912 If VARIABLE has a `custom-set' property, that is used for setting
913 VARIABLE, otherwise `set-default' is used.
915 The `customized-value' property of the VARIABLE will be set to a list
916 with a quoted VALUE as its sole list member.
918 If VARIABLE has a `variable-interactive' property, that is used as if
919 it were the arg to `interactive' (which see) to interactively read the value.
921 If VARIABLE has a `custom-type' property, it must be a widget and the
922 `:prompt-value' property of that widget will be used for reading the value.
924 If given a prefix (or a COMMENT argument), also prompt for a comment."
925 (interactive (custom-prompt-variable "Set and save variable: "
926 "Set and save value for %s as: "
928 (funcall (or (get variable 'custom-set) 'set-default) variable value)
929 (put variable 'saved-value (list (custom-quote value)))
930 (custom-push-theme 'theme-value variable 'user 'set (list (custom-quote value)))
931 (cond ((string= comment "")
932 (put variable 'variable-comment nil)
933 (put variable 'saved-variable-comment nil))
935 (put variable 'variable-comment comment)
936 (put variable 'saved-variable-comment comment)))
942 "Select a customization buffer which you can use to set user options.
943 User options are structured into \"groups\".
944 Initially the top-level group `Emacs' and its immediate subgroups
945 are shown; the contents of those subgroups are initially hidden."
947 (customize-group 'emacs))
950 (defun customize-mode (mode)
951 "Customize options related to the current major mode.
952 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
953 then prompt for the MODE to customize."
956 (let ((completion-regexp-list '("-mode\\'"))
957 (group (custom-group-of-mode major-mode)))
958 (if (and group (not current-prefix-arg))
961 (completing-read (if group
962 (format "Major mode (default %s): " major-mode)
965 'custom-group-of-mode
966 t nil nil (if group (symbol-name major-mode))))))))
967 (customize-group (custom-group-of-mode mode)))
971 (defun customize-group (group)
972 "Customize GROUP, which must be a customization group."
973 (interactive (list (let ((completion-ignore-case t))
974 (completing-read "Customize group (default emacs): "
977 (or (get symbol 'custom-loads)
978 (get symbol 'custom-group)))
980 (when (stringp group)
981 (if (string-equal "" group)
983 (setq group (intern group))))
984 (let ((name (format "*Customize Group: %s*"
985 (custom-unlispify-tag-name group))))
986 (if (get-buffer name)
988 (custom-buffer-create (list (list group 'custom-group))
990 (concat " for group "
991 (custom-unlispify-tag-name group))))))
994 (defun customize-group-other-window (group)
995 "Customize GROUP, which must be a customization group."
996 (interactive (list (let ((completion-ignore-case t))
997 (completing-read "Customize group (default emacs): "
1000 (or (get symbol 'custom-loads)
1001 (get symbol 'custom-group)))
1003 (when (stringp group)
1004 (if (string-equal "" group)
1006 (setq group (intern group))))
1007 (let ((name (format "*Customize Group: %s*"
1008 (custom-unlispify-tag-name group))))
1009 (if (get-buffer name)
1011 ;; Copied from `custom-buffer-create-other-window'.
1013 (same-window-buffer-names nil)
1014 (same-window-regexps nil))
1015 (pop-to-buffer name))
1016 (custom-buffer-create-other-window
1017 (list (list group 'custom-group))
1019 (concat " for group "
1020 (custom-unlispify-tag-name group))))))
1023 (defalias 'customize-variable 'customize-option)
1026 (defun customize-option (symbol)
1027 "Customize SYMBOL, which must be a user option variable."
1028 (interactive (custom-variable-prompt))
1029 (let ((basevar (indirect-variable symbol)))
1030 (custom-buffer-create (list (list basevar 'custom-variable))
1031 (format "*Customize Option: %s*"
1032 (custom-unlispify-tag-name basevar)))
1033 (unless (eq symbol basevar)
1034 (message "`%s' is an alias for `%s'" symbol basevar))))
1037 (defalias 'customize-variable-other-window 'customize-option-other-window)
1040 (defun customize-option-other-window (symbol)
1041 "Customize SYMBOL, which must be a user option variable.
1042 Show the buffer in another window, but don't select it."
1043 (interactive (custom-variable-prompt))
1044 (let ((basevar (indirect-variable symbol)))
1045 (custom-buffer-create-other-window
1046 (list (list basevar 'custom-variable))
1047 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1048 (unless (eq symbol basevar)
1049 (message "`%s' is an alias for `%s'" symbol basevar))))
1051 (defvar customize-changed-options-previous-release "20.2"
1052 "Version for `customize-changed-options' to refer back to by default.")
1055 (defun customize-changed-options (since-version)
1056 "Customize all user option variables changed in Emacs itself.
1057 This includes new user option variables and faces, and new
1058 customization groups, as well as older options and faces whose default
1059 values have changed since the previous major Emacs release.
1061 With argument SINCE-VERSION (a string), customize all user option
1062 variables that were added (or their meanings were changed) since that
1065 (interactive "sCustomize options changed, since version (default all versions): ")
1066 (if (equal since-version "")
1067 (setq since-version nil)
1068 (unless (condition-case nil
1069 (numberp (read since-version))
1071 (signal 'wrong-type-argument (list 'numberp since-version))))
1072 (unless since-version
1073 (setq since-version customize-changed-options-previous-release))
1075 ;; Load the information for versions since since-version. We use
1076 ;; custom-load-symbol for this.
1077 (put 'custom-versions-load-alist 'custom-loads nil)
1078 (dolist (elt custom-versions-load-alist)
1079 (if (customize-version-lessp since-version (car elt))
1080 (dolist (load (cdr elt))
1081 (custom-add-load 'custom-versions-load-alist load))))
1082 (custom-load-symbol 'custom-versions-load-alist)
1083 (put 'custom-versions-load-alist 'custom-loads nil)
1088 (let ((version (get symbol 'custom-version)))
1090 (when (customize-version-lessp since-version version)
1091 (if (or (get symbol 'custom-group)
1092 (get symbol 'group-documentation))
1093 (push (list symbol 'custom-group) found))
1094 (if (custom-variable-p symbol)
1095 (push (list symbol 'custom-variable) found))
1096 (if (custom-facep symbol)
1097 (push (list symbol 'custom-face) found)))))))
1099 (custom-buffer-create (custom-sort-items found t 'first)
1100 "*Customize Changed Options*")
1101 (error "No user option defaults have been changed since Emacs %s"
1104 (defun customize-version-lessp (version1 version2)
1105 ;; Why are the versions strings, and given that they are, why aren't
1106 ;; they converted to numbers and compared as such here? -- fx
1108 ;; In case someone made a mistake and left out the quotes
1109 ;; in the :version value.
1110 (if (numberp version2)
1111 (setq version2 (prin1-to-string version2)))
1112 (let (major1 major2 minor1 minor2)
1113 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1114 (setq major1 (read (or (match-string 1 version1)
1116 (setq minor1 (read (or (match-string 3 version1)
1118 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1119 (setq major2 (read (or (match-string 1 version2)
1121 (setq minor2 (read (or (match-string 3 version2)
1123 (or (< major1 major2)
1124 (and (= major1 major2)
1125 (< minor1 minor2)))))
1128 (defun customize-face (&optional face)
1129 "Customize FACE, which should be a face name or nil.
1130 If FACE is nil, customize all faces. If FACE is actually a
1131 face-alias, customize the face it is aliased to.
1133 Interactively, when point is on text which has a face specified,
1134 suggest to customize that face, if it's customizable."
1136 (list (read-face-name "Customize face" "all faces" t)))
1137 (if (member face '(nil ""))
1138 (setq face (face-list)))
1139 (if (and (listp face) (null (cdr face)))
1140 (setq face (car face)))
1142 (custom-buffer-create (custom-sort-items
1144 (list s 'custom-face))
1147 "*Customize Faces*")
1148 ;; If FACE is actually an alias, customize the face it is aliased to.
1149 (if (get face 'face-alias)
1150 (setq face (get face 'face-alias)))
1151 (unless (facep face)
1152 (error "Invalid face %S" face))
1153 (custom-buffer-create (list (list face 'custom-face))
1154 (format "*Customize Face: %s*"
1155 (custom-unlispify-tag-name face)))))
1158 (defun customize-face-other-window (&optional face)
1159 "Show customization buffer for face FACE in other window.
1160 If FACE is actually a face-alias, customize the face it is aliased to.
1162 Interactively, when point is on text which has a face specified,
1163 suggest to customize that face, if it's customizable."
1165 (list (read-face-name "Customize face" "all faces" t)))
1166 (if (member face '(nil ""))
1167 (setq face (face-list)))
1168 (if (and (listp face) (null (cdr face)))
1169 (setq face (car face)))
1171 (custom-buffer-create-other-window
1174 (list s 'custom-face))
1177 "*Customize Faces*")
1178 (if (get face 'face-alias)
1179 (setq face (get face 'face-alias)))
1180 (unless (facep face)
1181 (error "Invalid face %S" face))
1182 (custom-buffer-create-other-window
1183 (list (list face 'custom-face))
1184 (format "*Customize Face: %s*"
1185 (custom-unlispify-tag-name face)))))
1188 (defun customize-customized ()
1189 "Customize all user options set since the last save in this session."
1192 (mapatoms (lambda (symbol)
1193 (and (or (get symbol 'customized-face)
1194 (get symbol 'customized-face-comment))
1195 (custom-facep symbol)
1196 (push (list symbol 'custom-face) found))
1197 (and (or (get symbol 'customized-value)
1198 (get symbol 'customized-variable-comment))
1200 (push (list symbol 'custom-variable) found))))
1202 (error "No customized user options")
1203 (custom-buffer-create (custom-sort-items found t nil)
1204 "*Customize Customized*"))))
1207 (defun customize-rogue ()
1208 "Customize all user variable modified outside customize."
1211 (mapatoms (lambda (symbol)
1212 (let ((cval (or (get symbol 'customized-value)
1213 (get symbol 'saved-value)
1214 (get symbol 'standard-value))))
1215 (when (and cval ;Declared with defcustom.
1216 (default-boundp symbol) ;Has a value.
1217 (not (equal (eval (car cval))
1218 ;; Which does not match customize.
1219 (default-value symbol))))
1220 (push (list symbol 'custom-variable) found)))))
1222 (error "No rogue user options")
1223 (custom-buffer-create (custom-sort-items found t nil)
1224 "*Customize Rogue*"))))
1226 (defun customize-saved ()
1227 "Customize all already saved user options."
1230 (mapatoms (lambda (symbol)
1231 (and (or (get symbol 'saved-face)
1232 (get symbol 'saved-face-comment))
1233 (custom-facep symbol)
1234 (push (list symbol 'custom-face) found))
1235 (and (or (get symbol 'saved-value)
1236 (get symbol 'saved-variable-comment))
1238 (push (list symbol 'custom-variable) found))))
1240 (error "No saved user options")
1241 (custom-buffer-create (custom-sort-items found t nil)
1242 "*Customize Saved*"))))
1245 (defun customize-apropos (regexp &optional all)
1246 "Customize all user options matching REGEXP.
1247 If ALL is `options', include only options.
1248 If ALL is `faces', include only faces.
1249 If ALL is `groups', include only groups.
1250 If ALL is t (interactively, with prefix arg), include options which are not
1251 user-settable, as well as faces and groups."
1252 (interactive "sCustomize regexp: \nP")
1254 (mapatoms (lambda (symbol)
1255 (when (string-match regexp (symbol-name symbol))
1256 (when (and (not (memq all '(faces options)))
1257 (get symbol 'custom-group))
1258 (push (list symbol 'custom-group) found))
1259 (when (and (not (memq all '(options groups)))
1260 (custom-facep symbol))
1261 (push (list symbol 'custom-face) found))
1262 (when (and (not (memq all '(groups faces)))
1264 (or (get symbol 'saved-value)
1265 (custom-variable-p symbol)
1266 (if (memq all '(nil options))
1267 (user-variable-p symbol)
1268 (get symbol 'variable-documentation))))
1269 (push (list symbol 'custom-variable) found)))))
1271 (error "No matches")
1272 (custom-buffer-create (custom-sort-items found t
1273 custom-buffer-order-groups)
1274 "*Customize Apropos*"))))
1277 (defun customize-apropos-options (regexp &optional arg)
1278 "Customize all user options matching REGEXP.
1279 With prefix arg, include options which are not user-settable."
1280 (interactive "sCustomize regexp: \nP")
1281 (customize-apropos regexp (or arg 'options)))
1284 (defun customize-apropos-faces (regexp)
1285 "Customize all user faces matching REGEXP."
1286 (interactive "sCustomize regexp: \n")
1287 (customize-apropos regexp 'faces))
1290 (defun customize-apropos-groups (regexp)
1291 "Customize all user groups matching REGEXP."
1292 (interactive "sCustomize regexp: \n")
1293 (customize-apropos regexp 'groups))
1297 (defcustom custom-buffer-style 'links
1298 "Control the presentation style for customization buffers.
1299 The value should be a symbol, one of:
1301 brackets: groups nest within each other with big horizontal brackets.
1302 links: groups have links to subgroups."
1303 :type '(radio (const brackets)
1305 :group 'custom-buffer)
1307 (defcustom custom-buffer-done-kill nil
1308 "*Non-nil means exiting a Custom buffer should kill it."
1311 :group 'custom-buffer)
1313 (defcustom custom-buffer-indent 3
1314 "Number of spaces to indent nested groups."
1316 :group 'custom-buffer)
1318 (defun custom-get-fresh-buffer (name)
1319 "Get a fresh new buffer with name NAME.
1320 If the buffer already exist, clean it up to be like new.
1321 Beware: it's not quite like new. Good enough for custom, but maybe
1323 ;; To be more complete, we should also kill all permanent-local variables,
1324 ;; but it's not needed for custom.
1325 (let ((buf (get-buffer name)))
1326 (when (and buf (buffer-local-value 'buffer-file-name buf))
1327 ;; This will check if the file is not saved.
1331 (get-buffer-create name)
1332 (with-current-buffer buf
1333 (kill-all-local-variables)
1334 (run-hooks 'kill-buffer-hook)
1335 ;; Delete overlays before erasing the buffer so the overlay hooks
1336 ;; don't get run spuriously when we erase the buffer.
1337 (let ((ols (overlay-lists)))
1338 (dolist (ol (nconc (car ols) (cdr ols)))
1339 (delete-overlay ol)))
1344 (defun custom-buffer-create (options &optional name description)
1345 "Create a buffer containing OPTIONS.
1346 Optional NAME is the name of the buffer.
1347 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1348 SYMBOL is a customization option, and WIDGET is a widget for editing
1350 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1351 (custom-buffer-create-internal options description))
1354 (defun custom-buffer-create-other-window (options &optional name description)
1355 "Create a buffer containing OPTIONS, and display it in another window.
1356 The result includes selecting that window.
1357 Optional NAME is the name of the buffer.
1358 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1359 SYMBOL is a customization option, and WIDGET is a widget for editing
1361 (unless name (setq name "*Customization*"))
1362 (let ((pop-up-windows t)
1363 (same-window-buffer-names nil)
1364 (same-window-regexps nil))
1365 (pop-to-buffer (custom-get-fresh-buffer name))
1366 (custom-buffer-create-internal options description)))
1368 (defcustom custom-reset-button-menu nil
1369 "If non-nil, only show a single reset button in customize buffers.
1370 This button will have a menu with all three reset operations."
1372 :group 'custom-buffer)
1374 (defcustom custom-buffer-verbose-help t
1375 "If non-nil, include explanatory text in the customization buffer."
1377 :group 'custom-buffer)
1379 (defun Custom-buffer-done (&rest ignore)
1380 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1382 (quit-window custom-buffer-done-kill))
1384 (defvar custom-button nil
1385 "Face used for buttons in customization buffers.")
1387 (defvar custom-button-pressed nil
1388 "Face used for pressed buttons in customization buffers.")
1390 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1391 '(("unspecified" . unspecified))))
1392 "If non-nil, indicate active buttons in a `raised-button' style.
1393 Otherwise use brackets."
1396 :group 'custom-buffer
1397 :set (lambda (variable value)
1398 (custom-set-default variable value)
1400 (if value 'custom-button 'custom-button-unraised))
1401 (setq custom-button-pressed
1403 'custom-button-pressed
1404 'custom-button-pressed-unraised))))
1406 (defun custom-buffer-create-internal (options &optional description)
1408 (if custom-buffer-verbose-help
1410 (widget-insert "This is a customization buffer")
1412 (widget-insert description))
1413 (widget-insert (format ".
1414 %s show active fields; type RET or click mouse-1
1415 on an active field to invoke its action. Editing an option value
1416 changes only the text in the buffer. Invoke the State button to set or
1417 save the option value. Saving an option normally edits your init file.
1419 (if custom-raised-buttons
1421 "Square brackets")))
1422 (widget-create 'info-link
1424 "(emacs)Saving Customizations")
1426 " for information on how to save in a different file.
1428 (widget-create 'info-link
1430 :help-echo "Read the online help."
1431 "(emacs)Easy Customization")
1432 (widget-insert " for general information.\n\n")
1433 (widget-insert "Operate on everything in this buffer:\n "))
1434 (widget-insert " "))
1435 (widget-create 'push-button
1436 :tag "Set for Current Session"
1438 Make your editing in this buffer take effect for this session."
1439 :action (lambda (widget &optional event)
1442 (widget-create 'push-button
1443 :tag "Save for Future Sessions"
1445 Make your editing in this buffer take effect for future Emacs sessions.
1446 This updates your Emacs initialization file or creates a new one."
1447 :action (lambda (widget &optional event)
1449 (if custom-reset-button-menu
1452 (widget-create 'push-button
1454 :help-echo "Show a menu with reset operations."
1455 :mouse-down-action (lambda (&rest junk) t)
1456 :action (lambda (widget &optional event)
1457 (custom-reset event))))
1458 (widget-insert "\n ")
1459 (widget-create 'push-button
1462 Reset all edited text in this buffer to reflect current values."
1463 :action 'Custom-reset-current)
1465 (widget-create 'push-button
1466 :tag "Reset to Saved"
1468 Reset all values in this buffer to their saved settings."
1469 :action 'Custom-reset-saved)
1471 (widget-create 'push-button
1472 :tag "Erase Customization"
1474 Un-customize all values in this buffer. They get their standard settings."
1475 :action 'Custom-reset-standard))
1476 (if (not custom-buffer-verbose-help)
1479 (widget-create 'info-link
1481 :help-echo "Read the online help."
1482 "(emacs)Easy Customization")))
1484 (widget-create 'push-button
1487 (lambda (&rest ignore)
1488 (if custom-buffer-done-kill
1490 "Bury this buffer"))
1491 :action #'Custom-buffer-done)
1492 (widget-insert "\n\n")
1493 (message "Creating customization items...")
1494 (buffer-disable-undo)
1495 (setq custom-options
1496 (if (= (length options) 1)
1497 (mapcar (lambda (entry)
1498 (widget-create (nth 1 entry)
1499 :documentation-shown t
1500 :custom-state 'unknown
1501 :tag (custom-unlispify-tag-name
1503 :value (nth 0 entry)))
1506 (length (length options)))
1507 (mapcar (lambda (entry)
1509 (message "Creating customization items ...%2d%%"
1510 (/ (* 100.0 count) length))
1511 (widget-create (nth 1 entry)
1512 :tag (custom-unlispify-tag-name
1514 :value (nth 0 entry))
1515 (setq count (1+ count))
1516 (unless (eq (preceding-char) ?\n)
1517 (widget-insert "\n"))
1518 (widget-insert "\n")))
1520 (unless (eq (preceding-char) ?\n)
1521 (widget-insert "\n"))
1522 (message "Creating customization items ...done")
1523 (message "Resetting customization items...")
1524 (unless (eq custom-buffer-style 'tree)
1525 (mapc 'custom-magic-reset custom-options))
1526 (message "Resetting customization items...done")
1527 (message "Creating customization setup...")
1529 (buffer-enable-undo)
1530 (goto-char (point-min))
1531 (message "Creating customization setup...done"))
1533 ;;; The Tree Browser.
1536 (defun customize-browse (&optional group)
1537 "Create a tree browser for the customize hierarchy."
1540 (setq group 'emacs))
1541 (let ((name "*Customize Browser*"))
1542 (pop-to-buffer (custom-get-fresh-buffer name)))
1545 Square brackets show active fields; type RET or click mouse-1
1546 on an active field to invoke its action.
1547 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1548 (if custom-browse-only-groups
1550 Invoke the [Group] button below to edit that item in another window.\n\n")
1551 (widget-insert "Invoke the ")
1552 (widget-create 'item
1555 :tag-glyph "folder")
1556 (widget-insert ", ")
1557 (widget-create 'item
1561 (widget-insert ", and ")
1562 (widget-create 'item
1565 :tag-glyph "option")
1566 (widget-insert " buttons below to edit that
1567 item in another window.\n\n"))
1568 (let ((custom-buffer-style 'tree))
1569 (widget-create 'custom-group
1571 :custom-state 'unknown
1572 :tag (custom-unlispify-tag-name group)
1575 (goto-char (point-min)))
1577 (define-widget 'custom-browse-visibility 'item
1578 "Control visibility of items in the customize tree browser."
1580 :action 'custom-browse-visibility-action)
1582 (defun custom-browse-visibility-action (widget &rest ignore)
1583 (let ((custom-buffer-style 'tree))
1584 (custom-toggle-parent widget)))
1586 (define-widget 'custom-browse-group-tag 'push-button
1587 "Show parent in other window when activated."
1590 :action 'custom-browse-group-tag-action)
1592 (defun custom-browse-group-tag-action (widget &rest ignore)
1593 (let ((parent (widget-get widget :parent)))
1594 (customize-group-other-window (widget-value parent))))
1596 (define-widget 'custom-browse-variable-tag 'push-button
1597 "Show parent in other window when activated."
1600 :action 'custom-browse-variable-tag-action)
1602 (defun custom-browse-variable-tag-action (widget &rest ignore)
1603 (let ((parent (widget-get widget :parent)))
1604 (customize-variable-other-window (widget-value parent))))
1606 (define-widget 'custom-browse-face-tag 'push-button
1607 "Show parent in other window when activated."
1610 :action 'custom-browse-face-tag-action)
1612 (defun custom-browse-face-tag-action (widget &rest ignore)
1613 (let ((parent (widget-get widget :parent)))
1614 (customize-face-other-window (widget-value parent))))
1616 (defconst custom-browse-alist '((" " "space")
1622 (defun custom-browse-insert-prefix (prefix)
1623 "Insert PREFIX. On XEmacs convert it to line graphics."
1624 ;; Fixme: do graphics.
1625 (if nil ; (string-match "XEmacs" emacs-version)
1628 (while (not (string-equal prefix ""))
1629 (let ((entry (substring prefix 0 3)))
1630 (setq prefix (substring prefix 3))
1631 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1632 (name (nth 1 (assoc entry custom-browse-alist))))
1633 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1634 (overlay-put overlay 'start-open t)
1635 (overlay-put overlay 'end-open t)))))
1638 ;;; Modification of Basic Widgets.
1640 ;; We add extra properties to the basic widgets needed here. This is
1641 ;; fine, as long as we are careful to stay within out own namespace.
1643 ;; We want simple widgets to be displayed by default, but complex
1644 ;; widgets to be hidden.
1646 (widget-put (get 'item 'widget-type) :custom-show t)
1647 (widget-put (get 'editable-field 'widget-type)
1648 :custom-show (lambda (widget value)
1649 (let ((pp (pp-to-string value)))
1650 (cond ((string-match "\n" pp)
1655 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1657 ;;; The `custom-manual' Widget.
1659 (define-widget 'custom-manual 'info-link
1660 "Link to the manual entry for this customization option."
1661 :help-echo "Read the manual entry for this option."
1664 ;;; The `custom-magic' Widget.
1666 (defgroup custom-magic-faces nil
1667 "Faces used by the magic button."
1668 :group 'custom-faces
1669 :group 'custom-buffer)
1671 (defface custom-invalid '((((class color))
1672 (:foreground "yellow1" :background "red1"))
1674 (:weight bold :slant italic :underline t)))
1675 "Face used when the customize item is invalid."
1676 :group 'custom-magic-faces)
1677 ;; backward-compatibility alias
1678 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1680 (defface custom-rogue '((((class color))
1681 (:foreground "pink" :background "black"))
1684 "Face used when the customize item is not defined for customization."
1685 :group 'custom-magic-faces)
1686 ;; backward-compatibility alias
1687 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1689 (defface custom-modified '((((min-colors 88) (class color))
1690 (:foreground "white" :background "blue1"))
1692 (:foreground "white" :background "blue"))
1694 (:slant italic :bold)))
1695 "Face used when the customize item has been modified."
1696 :group 'custom-magic-faces)
1697 ;; backward-compatibility alias
1698 (put 'custom-modified-face 'face-alias 'custom-modified)
1700 (defface custom-set '((((min-colors 88) (class color))
1701 (:foreground "blue1" :background "white"))
1703 (:foreground "blue" :background "white"))
1706 "Face used when the customize item has been set."
1707 :group 'custom-magic-faces)
1708 ;; backward-compatibility alias
1709 (put 'custom-set-face 'face-alias 'custom-set)
1711 (defface custom-changed '((((min-colors 88) (class color))
1712 (:foreground "white" :background "blue1"))
1714 (:foreground "white" :background "blue"))
1717 "Face used when the customize item has been changed."
1718 :group 'custom-magic-faces)
1719 ;; backward-compatibility alias
1720 (put 'custom-changed-face 'face-alias 'custom-changed)
1722 (defface custom-saved '((t (:underline t)))
1723 "Face used when the customize item has been saved."
1724 :group 'custom-magic-faces)
1725 ;; backward-compatibility alias
1726 (put 'custom-saved-face 'face-alias 'custom-saved)
1728 (defconst custom-magic-alist
1729 '((nil "#" underline "\
1730 UNINITIALIZED, you should not see this.")
1731 (unknown "?" italic "\
1732 UNKNOWN, you should not see this.")
1733 (hidden "-" default "\
1734 HIDDEN, invoke \"Show\" in the previous line to show." "\
1735 group now hidden, invoke \"Show\", above, to show contents.")
1736 (invalid "x" custom-invalid "\
1737 INVALID, the displayed value cannot be set.")
1738 (modified "*" custom-modified "\
1739 EDITED, shown value does not take effect until you set or save it." "\
1740 something in this group has been edited but not set.")
1741 (set "+" custom-set "\
1742 SET for current session only." "\
1743 something in this group has been set but not saved.")
1744 (changed ":" custom-changed "\
1745 CHANGED outside Customize; operating on it here may be unreliable." "\
1746 something in this group has been changed outside customize.")
1747 (saved "!" custom-saved "\
1749 something in this group has been set and saved.")
1750 (rogue "@" custom-rogue "\
1751 NO CUSTOMIZATION DATA; you should not see this." "\
1752 something in this group is not prepared for customization.")
1753 (standard " " nil "\
1755 visible group members are all at standard settings."))
1756 "Alist of customize option states.
1757 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1759 STATE is one of the following symbols:
1762 For internal use, should never occur.
1764 For internal use, should never occur.
1766 This item is not being displayed.
1768 This item is modified, but has an invalid form.
1770 This item is modified, and has a valid form.
1772 This item has been set but not saved.
1774 The current value of this item has been changed outside Customize.
1776 This item is marked for saving.
1778 This item has no customization information.
1780 This item is unchanged from the standard setting.
1782 MAGIC is a string used to present that state.
1784 FACE is a face used to present the state.
1786 ITEM-DESC is a string describing the state for options.
1788 GROUP-DESC is a string describing the state for groups. If this is
1789 left out, ITEM-DESC will be used.
1791 The string %c in either description will be replaced with the
1792 category of the item. These are `group'. `option', and `face'.
1794 The list should be sorted most significant first.")
1796 (defcustom custom-magic-show 'long
1797 "If non-nil, show textual description of the state.
1798 If `long', show a full-line description, not just one word."
1799 :type '(choice (const :tag "no" nil)
1801 (other :tag "short" short))
1802 :group 'custom-buffer)
1804 (defcustom custom-magic-show-hidden '(option face)
1805 "Control whether the State button is shown for hidden items.
1806 The value should be a list with the custom categories where the State
1807 button should be visible. Possible categories are `group', `option',
1809 :type '(set (const group) (const option) (const face))
1810 :group 'custom-buffer)
1812 (defcustom custom-magic-show-button nil
1813 "Show a \"magic\" button indicating the state of each customization option."
1815 :group 'custom-buffer)
1817 (define-widget 'custom-magic 'default
1818 "Show and manipulate state for a customization option."
1820 :action 'widget-parent-action
1823 :value-create 'custom-magic-value-create
1824 :value-delete 'widget-children-value-delete)
1826 (defun widget-magic-mouse-down-action (widget &optional event)
1827 ;; Non-nil unless hidden.
1828 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1832 (defun custom-magic-value-create (widget)
1833 "Create compact status report for WIDGET."
1834 (let* ((parent (widget-get widget :parent))
1835 (state (widget-get parent :custom-state))
1836 (hidden (eq state 'hidden))
1837 (entry (assq state custom-magic-alist))
1838 (magic (nth 1 entry))
1839 (face (nth 2 entry))
1840 (category (widget-get parent :custom-category))
1841 (text (or (and (eq category 'group)
1844 (form (widget-get parent :custom-form))
1846 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1847 (setq text (concat (match-string 1 text)
1848 (symbol-name category)
1849 (match-string 2 text))))
1850 (when (and custom-magic-show
1852 (memq category custom-magic-show-hidden)))
1854 (when (and (eq category 'group)
1855 (not (and (eq custom-buffer-style 'links)
1856 (> (widget-get parent :custom-level) 1))))
1857 (insert-char ?\ (* custom-buffer-indent
1858 (widget-get parent :custom-level))))
1859 (push (widget-create-child-and-convert
1861 :help-echo "Change the state of this item."
1862 :format (if hidden "%t" "%[%t%]")
1863 :button-prefix 'widget-push-button-prefix
1864 :button-suffix 'widget-push-button-suffix
1865 :mouse-down-action 'widget-magic-mouse-down-action
1869 (let ((start (point)))
1870 (if (eq custom-magic-show 'long)
1872 (insert (symbol-name state)))
1873 (cond ((eq form 'lisp)
1875 ((eq form 'mismatch)
1876 (insert " (mismatch)")))
1877 (put-text-property start (point) 'face 'custom-state))
1879 (when (and (eq category 'group)
1880 (not (and (eq custom-buffer-style 'links)
1881 (> (widget-get parent :custom-level) 1))))
1882 (insert-char ?\ (* custom-buffer-indent
1883 (widget-get parent :custom-level))))
1884 (when custom-magic-show-button
1885 (when custom-magic-show
1886 (let ((indent (widget-get parent :indent)))
1888 (insert-char ? indent))))
1889 (push (widget-create-child-and-convert
1891 :mouse-down-action 'widget-magic-mouse-down-action
1895 :help-echo "Change the state."
1896 :format (if hidden "%t" "%[%t%]")
1897 :tag (if (memq form '(lisp mismatch))
1898 (concat "(" magic ")")
1899 (concat "[" magic "]")))
1902 (widget-put widget :children children)))
1904 (defun custom-magic-reset (widget)
1905 "Redraw the :custom-magic property of WIDGET."
1906 (let ((magic (widget-get widget :custom-magic)))
1907 (widget-value-set magic (widget-value magic))))
1909 ;;; The `custom' Widget.
1911 (defface custom-button
1912 '((((type x w32 mac) (class color)) ; Like default modeline
1913 (:box (:line-width 2 :style released-button)
1914 :background "lightgrey" :foreground "black"))
1917 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1919 :group 'custom-faces)
1920 ;; backward-compatibility alias
1921 (put 'custom-button-face 'face-alias 'custom-button)
1923 (defface custom-button-unraised
1925 (class color) (background light)) :foreground "blue1" :underline t)
1926 (((class color) (background light)) :foreground "blue" :underline t)
1928 (class color) (background dark)) :foreground "cyan1" :underline t)
1929 (((class color) (background dark)) :foreground "cyan" :underline t)
1931 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1933 :group 'custom-faces)
1936 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
1938 (defface custom-button-pressed
1939 '((((type x w32 mac) (class color))
1940 (:box (:line-width 2 :style pressed-button)
1941 :background "lightgrey" :foreground "black"))
1943 (:inverse-video t)))
1944 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1946 :group 'custom-faces)
1947 ;; backward-compatibility alias
1948 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
1950 (defface custom-button-pressed-unraised
1951 '((default :inherit custom-button-unraised)
1952 (((class color) (background light)) :foreground "magenta4")
1953 (((class color) (background dark)) :foreground "violet"))
1954 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1956 :group 'custom-faces)
1958 (setq custom-button-pressed
1959 (if custom-raised-buttons
1960 'custom-button-pressed
1961 'custom-button-pressed-unraised))
1963 (defface custom-documentation nil
1964 "Face used for documentation strings in customization buffers."
1965 :group 'custom-faces)
1966 ;; backward-compatibility alias
1967 (put 'custom-documentation-face 'face-alias 'custom-documentation)
1969 (defface custom-state '((((class color)
1971 (:foreground "lime green"))
1974 (:foreground "dark green"))
1976 "Face used for State descriptions in the customize buffer."
1977 :group 'custom-faces)
1978 ;; backward-compatibility alias
1979 (put 'custom-state-face 'face-alias 'custom-state)
1981 (define-widget 'custom 'default
1982 "Customize a user option."
1984 :convert-widget 'custom-convert-widget
1985 :notify 'custom-notify
1988 :custom-state 'hidden
1989 :documentation-property 'widget-subclass-responsibility
1990 :value-create 'widget-subclass-responsibility
1991 :value-delete 'widget-children-value-delete
1992 :value-get 'widget-value-value-get
1993 :validate 'widget-children-validate
1994 :match (lambda (widget value) (symbolp value)))
1996 (defun custom-convert-widget (widget)
1997 "Initialize :value and :tag from :args in WIDGET."
1998 (let ((args (widget-get widget :args)))
2000 (widget-put widget :value (widget-apply widget
2001 :value-to-internal (car args)))
2002 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2003 (widget-put widget :args nil)))
2006 (defun custom-notify (widget &rest args)
2007 "Keep track of changes."
2008 (let ((state (widget-get widget :custom-state)))
2009 (unless (eq state 'modified)
2010 (unless (memq state '(nil unknown hidden))
2011 (widget-put widget :custom-state 'modified))
2012 (custom-magic-reset widget)
2013 (apply 'widget-default-notify widget args))))
2015 (defun custom-redraw (widget)
2016 "Redraw WIDGET with current settings."
2017 (let ((line (count-lines (point-min) (point)))
2018 (column (current-column))
2020 (from (marker-position (widget-get widget :from)))
2021 (to (marker-position (widget-get widget :to))))
2023 (widget-value-set widget (widget-value widget))
2024 (custom-redraw-magic widget))
2025 (when (and (>= pos from) (<= pos to))
2030 (goto-line (1+ line)))
2031 (move-to-column column))
2034 (defun custom-redraw-magic (widget)
2035 "Redraw WIDGET state with current settings."
2037 (let ((magic (widget-get widget :custom-magic)))
2039 (widget-value-set magic (widget-value magic))
2040 (when (setq widget (widget-get widget :group))
2041 (custom-group-state-update widget)))
2043 (setq widget nil)))))
2046 (defun custom-show (widget value)
2047 "Non-nil if WIDGET should be shown with VALUE by default."
2048 (let ((show (widget-get widget :custom-show)))
2054 (funcall show widget value)))))
2056 (defun custom-load-widget (widget)
2057 "Load all dependencies for WIDGET."
2058 (custom-load-symbol (widget-value widget)))
2060 (defun custom-unloaded-symbol-p (symbol)
2061 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2063 (loads (get symbol 'custom-loads))
2066 (setq load (car loads)
2068 (cond ((symbolp load)
2069 (unless (featurep load)
2071 ((assoc load load-history))
2072 ((assoc (locate-library load) load-history)
2078 (defun custom-unloaded-widget-p (widget)
2079 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2080 (custom-unloaded-symbol-p (widget-value widget)))
2082 (defun custom-toggle-hide (widget)
2083 "Toggle visibility of WIDGET."
2084 (custom-load-widget widget)
2085 (let ((state (widget-get widget :custom-state)))
2086 (cond ((memq state '(invalid modified))
2087 (error "There are unset changes"))
2089 (widget-put widget :custom-state 'unknown))
2091 (widget-put widget :documentation-shown nil)
2092 (widget-put widget :custom-state 'hidden)))
2093 (custom-redraw widget)
2096 (defun custom-toggle-parent (widget &rest ignore)
2097 "Toggle visibility of parent of WIDGET."
2098 (custom-toggle-hide (widget-get widget :parent)))
2100 (defun custom-add-see-also (widget &optional prefix)
2101 "Add `See also ...' to WIDGET if there are any links.
2102 Insert PREFIX first if non-nil."
2103 (let* ((symbol (widget-get widget :value))
2104 (links (get symbol 'custom-links))
2105 (many (> (length links) 2))
2106 (buttons (widget-get widget :buttons))
2107 (indent (widget-get widget :indent)))
2110 (insert-char ?\ indent))
2113 (insert "See also ")
2115 (push (widget-create-child-and-convert widget (car links))
2117 (setq links (cdr links))
2126 (widget-put widget :buttons buttons))))
2128 (defun custom-add-parent-links (widget &optional initial-string)
2129 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2130 The value is non-nil if any parents were found.
2131 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2132 (let ((name (widget-value widget))
2133 (type (widget-type widget))
2134 (buttons (widget-get widget :buttons))
2137 (insert (or initial-string "Parent groups:"))
2138 (mapatoms (lambda (symbol)
2139 (when (member (list name type) (get symbol 'custom-group))
2141 (push (widget-create-child-and-convert
2142 widget 'custom-group-link
2143 :tag (custom-unlispify-tag-name symbol)
2146 (setq parents (cons symbol parents)))))
2147 (and (null (get name 'custom-links)) ;No links of its own.
2148 (= (length parents) 1) ;A single parent.
2149 (let* ((links (get (car parents) 'custom-links))
2150 (many (> (length links) 2)))
2152 (insert "\nParent documentation: ")
2154 (push (widget-create-child-and-convert widget (car links))
2156 (setq links (cdr links))
2167 (delete-region start (point)))
2168 (widget-put widget :buttons buttons)
2171 ;;; The `custom-comment' Widget.
2173 ;; like the editable field
2174 (defface custom-comment '((((class grayscale color)
2176 (:background "gray85"))
2177 (((class grayscale color)
2179 (:background "dim gray"))
2182 "Face used for comments on variables or faces"
2184 :group 'custom-faces)
2185 ;; backward-compatibility alias
2186 (put 'custom-comment-face 'face-alias 'custom-comment)
2188 ;; like font-lock-comment-face
2189 (defface custom-comment-tag
2190 '((((class color) (background dark)) (:foreground "gray80"))
2191 (((class color) (background light)) (:foreground "blue4"))
2192 (((class grayscale) (background light))
2193 (:foreground "DimGray" :weight bold :slant italic))
2194 (((class grayscale) (background dark))
2195 (:foreground "LightGray" :weight bold :slant italic))
2197 "Face used for variables or faces comment tags"
2198 :group 'custom-faces)
2199 ;; backward-compatibility alias
2200 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2202 (define-widget 'custom-comment 'string
2205 :help-echo "Edit a comment here."
2206 :sample-face 'custom-comment-tag-face
2207 :value-face 'custom-comment-face
2209 :create 'custom-comment-create)
2211 (defun custom-comment-create (widget)
2212 (let* ((null-comment (equal "" (widget-value widget))))
2213 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2215 (widget-default-create widget)
2216 ;; `widget-default-delete' expects markers in these slots --
2217 ;; maybe it shouldn't.
2218 (widget-put widget :from (point-marker))
2219 (widget-put widget :to (point-marker)))))
2221 (defun custom-comment-hide (widget)
2222 (widget-put (widget-get widget :parent) :comment-shown nil))
2224 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2225 ;; the global custom one
2226 (defun custom-comment-show (widget)
2227 (widget-put widget :comment-shown t)
2228 (custom-redraw widget)
2231 (defun custom-comment-invisible-p (widget)
2232 (let ((val (widget-value (widget-get widget :comment-widget))))
2234 (not (widget-get widget :comment-shown)))))
2236 ;;; The `custom-variable' Widget.
2238 ;; When this was underlined blue, users confused it with a
2239 ;; Mosaic-style hyperlink...
2240 (defface custom-variable-tag
2243 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
2244 (((min-colors 88) (class color)
2246 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
2249 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
2251 "Face used for unpushable variable tags."
2252 :group 'custom-faces)
2253 ;; backward-compatibility alias
2254 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2256 (defface custom-variable-button '((t (:underline t :weight bold)))
2257 "Face used for pushable variable tags."
2258 :group 'custom-faces)
2259 ;; backward-compatibility alias
2260 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2262 (defcustom custom-variable-default-form 'edit
2263 "Default form of displaying variable values."
2264 :type '(choice (const edit)
2266 :group 'custom-buffer
2269 (defun custom-variable-documentation (variable)
2270 "Return documentation of VARIABLE for use in Custom buffer.
2271 Normally just return the docstring. But if VARIABLE automatically
2272 becomes buffer local when set, append a message to that effect."
2273 (if (and (local-variable-if-set-p variable)
2274 (or (not (local-variable-p variable))
2276 (local-variable-if-set-p variable))))
2277 (concat (documentation-property variable 'variable-documentation)
2279 This variable automatically becomes buffer-local when set outside Custom.
2280 However, setting it through Custom sets the default value.")
2281 (documentation-property variable 'variable-documentation)))
2283 (define-widget 'custom-variable 'custom
2284 "Customize variable."
2286 :help-echo "Set or reset this variable."
2287 :documentation-property #'custom-variable-documentation
2288 :custom-category 'option
2290 :custom-menu 'custom-variable-menu-create
2291 :custom-form nil ; defaults to value of `custom-variable-default-form'
2292 :value-create 'custom-variable-value-create
2293 :action 'custom-variable-action
2294 :custom-set 'custom-variable-set
2295 :custom-save 'custom-variable-save
2296 :custom-reset-current 'custom-redraw
2297 :custom-reset-saved 'custom-variable-reset-saved
2298 :custom-reset-standard 'custom-variable-reset-standard
2299 :custom-standard-value 'custom-variable-standard-value)
2301 (defun custom-variable-type (symbol)
2302 "Return a widget suitable for editing the value of SYMBOL.
2303 If SYMBOL has a `custom-type' property, use that.
2304 Otherwise, look up symbol in `custom-guess-type-alist'."
2305 (let* ((type (or (get symbol 'custom-type)
2306 (and (not (get symbol 'standard-value))
2307 (custom-guess-type symbol))
2309 (options (get symbol 'custom-options))
2310 (tmp (if (listp type)
2311 (copy-sequence type)
2314 (widget-put tmp :options options))
2317 (defun custom-variable-value-create (widget)
2318 "Here is where you edit the variable's value."
2319 (custom-load-widget widget)
2320 (unless (widget-get widget :custom-form)
2321 (widget-put widget :custom-form custom-variable-default-form))
2322 (let* ((buttons (widget-get widget :buttons))
2323 (children (widget-get widget :children))
2324 (form (widget-get widget :custom-form))
2325 (state (widget-get widget :custom-state))
2326 (symbol (widget-get widget :value))
2327 (tag (widget-get widget :tag))
2328 (type (custom-variable-type symbol))
2329 (conv (widget-convert type))
2330 (get (or (get symbol 'custom-get) 'default-value))
2331 (prefix (widget-get widget :custom-prefix))
2332 (last (widget-get widget :custom-last))
2333 (value (if (default-boundp symbol)
2334 (funcall get symbol)
2335 (widget-get conv :value))))
2336 ;; If the widget is new, the child determines whether it is hidden.
2338 ((custom-show type value)
2339 (setq state 'unknown))
2341 (setq state 'hidden)))
2342 ;; If we don't know the state, see if we need to edit it in lisp form.
2343 (when (eq state 'unknown)
2344 (unless (widget-apply conv :match value)
2345 ;; (widget-apply (widget-convert type) :match value)
2346 (setq form 'mismatch)))
2347 ;; Now we can create the child widget.
2348 (cond ((eq custom-buffer-style 'tree)
2349 (insert prefix (if last " `--- " " |--- "))
2350 (push (widget-create-child-and-convert
2351 widget 'custom-browse-variable-tag)
2353 (insert " " tag "\n")
2354 (widget-put widget :buttons buttons))
2356 ;; Indicate hidden value.
2357 (push (widget-create-child-and-convert
2360 :sample-face 'custom-variable-tag-face
2364 (push (widget-create-child-and-convert
2366 :help-echo "Show the value of this option."
2368 :action 'custom-toggle-parent
2371 ((memq form '(lisp mismatch))
2372 ;; In lisp mode edit the saved value when possible.
2373 (let* ((value (cond ((get symbol 'saved-value)
2374 (car (get symbol 'saved-value)))
2375 ((get symbol 'standard-value)
2376 (car (get symbol 'standard-value)))
2377 ((default-boundp symbol)
2378 (custom-quote (funcall get symbol)))
2380 (custom-quote (widget-get conv :value))))))
2381 (insert (symbol-name symbol) ": ")
2382 (push (widget-create-child-and-convert
2384 :help-echo "Hide the value of this option."
2387 :action 'custom-toggle-parent
2391 (push (widget-create-child-and-convert
2393 :button-face 'custom-variable-button-face
2395 :tag (symbol-name symbol)
2401 (let* ((format (widget-get type :format))
2402 tag-format value-format)
2403 (unless (string-match ":" format)
2404 (error "Bad format"))
2405 (setq tag-format (substring format 0 (match-end 0)))
2406 (setq value-format (substring format (match-end 0)))
2407 (push (widget-create-child-and-convert
2410 :action 'custom-tag-action
2411 :help-echo "Change value of this option."
2412 :mouse-down-action 'custom-tag-mouse-down-action
2413 :button-face 'custom-variable-button-face
2414 :sample-face 'custom-variable-tag-face
2418 (push (widget-create-child-and-convert
2420 :help-echo "Hide the value of this option."
2423 :action 'custom-toggle-parent
2426 (push (widget-create-child-and-convert
2428 :format value-format
2431 (unless (eq custom-buffer-style 'tree)
2432 (unless (eq (preceding-char) ?\n)
2433 (widget-insert "\n"))
2434 ;; Create the magic button.
2435 (let ((magic (widget-create-child-and-convert
2436 widget 'custom-magic nil)))
2437 (widget-put widget :custom-magic magic)
2438 (push magic buttons))
2439 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2440 ;; before the call to `widget-default-format-handler'. Otherwise, I
2441 ;; loose my current `buttons'. This function shouldn't be called like
2442 ;; this anyway. The doc string widget should be added like the others.
2444 (widget-put widget :buttons buttons)
2446 ;; Insert documentation.
2447 (widget-default-format-handler widget ?h)
2449 ;; The comment field
2450 (unless (eq state 'hidden)
2451 (let* ((comment (get symbol 'variable-comment))
2453 (widget-create-child-and-convert
2454 widget 'custom-comment
2456 :value (or comment ""))))
2457 (widget-put widget :comment-widget comment-widget)
2458 ;; Don't push it !!! Custom assumes that the first child is the
2460 (setq children (append children (list comment-widget)))))
2461 ;; Update the rest of the properties properties.
2462 (widget-put widget :custom-form form)
2463 (widget-put widget :children children)
2464 ;; Now update the state.
2465 (if (eq state 'hidden)
2466 (widget-put widget :custom-state state)
2467 (custom-variable-state-set widget))
2469 (unless (eq state 'hidden)
2470 (when (eq (widget-get widget :custom-level) 1)
2471 (custom-add-parent-links widget))
2472 (custom-add-see-also widget)))))
2474 (defun custom-tag-action (widget &rest args)
2475 "Pass :action to first child of WIDGET's parent."
2476 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2479 (defun custom-tag-mouse-down-action (widget &rest args)
2480 "Pass :mouse-down-action to first child of WIDGET's parent."
2481 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2482 :mouse-down-action args))
2484 (defun custom-variable-state-set (widget)
2485 "Set the state of WIDGET."
2486 (let* ((symbol (widget-value widget))
2487 (get (or (get symbol 'custom-get) 'default-value))
2488 (value (if (default-boundp symbol)
2489 (funcall get symbol)
2490 (widget-get widget :value)))
2491 (comment (get symbol 'variable-comment))
2494 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2496 (get symbol 'customized-variable-comment))
2498 (if (condition-case nil
2499 (and (equal value (eval (car tmp)))
2500 (equal comment temp))
2504 ((progn (setq tmp (get symbol 'saved-value))
2505 (setq temp (get symbol 'saved-variable-comment))
2507 (if (condition-case nil
2508 (and (equal value (eval (car tmp)))
2509 (equal comment temp))
2513 ((setq tmp (get symbol 'standard-value))
2514 (if (condition-case nil
2515 (and (equal value (eval (car tmp)))
2516 (equal comment nil))
2521 (widget-put widget :custom-state state)))
2523 (defun custom-variable-standard-value (widget)
2524 (get (widget-value widget) 'standard-value))
2526 (defvar custom-variable-menu
2527 '(("Set for Current Session" custom-variable-set
2529 (eq (widget-get widget :custom-state) 'modified)))
2530 ("Save for Future Sessions" custom-variable-save
2532 (memq (widget-get widget :custom-state) '(modified set changed rogue))))
2533 ("Reset to Current" custom-redraw
2535 (and (default-boundp (widget-value widget))
2536 (memq (widget-get widget :custom-state) '(modified changed)))))
2537 ("Reset to Saved" custom-variable-reset-saved
2539 (and (or (get (widget-value widget) 'saved-value)
2540 (get (widget-value widget) 'saved-variable-comment))
2541 (memq (widget-get widget :custom-state)
2542 '(modified set changed rogue)))))
2543 ("Erase Customization" custom-variable-reset-standard
2545 (and (get (widget-value widget) 'standard-value)
2546 (memq (widget-get widget :custom-state)
2547 '(modified set changed saved rogue)))))
2548 ("Use Backup Value" custom-variable-reset-backup
2550 (get (widget-value widget) 'backup-value)))
2551 ("---" ignore ignore)
2552 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2553 ("---" ignore ignore)
2554 ("Don't show as Lisp expression" custom-variable-edit
2556 (eq (widget-get widget :custom-form) 'lisp)))
2557 ("Show initial Lisp expression" custom-variable-edit-lisp
2559 (eq (widget-get widget :custom-form) 'edit))))
2560 "Alist of actions for the `custom-variable' widget.
2561 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2562 the menu entry, ACTION is the function to call on the widget when the
2563 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2564 widget as an argument, and returns non-nil if ACTION is valid on that
2565 widget. If FILTER is nil, ACTION is always valid.")
2567 (defun custom-variable-action (widget &optional event)
2568 "Show the menu for `custom-variable' WIDGET.
2569 Optional EVENT is the location for the menu."
2570 (if (eq (widget-get widget :custom-state) 'hidden)
2571 (custom-toggle-hide widget)
2572 (unless (eq (widget-get widget :custom-state) 'modified)
2573 (custom-variable-state-set widget))
2574 (custom-redraw-magic widget)
2575 (let* ((completion-ignore-case t)
2576 (answer (widget-choose (concat "Operation on "
2577 (custom-unlispify-tag-name
2578 (widget-get widget :value)))
2579 (custom-menu-filter custom-variable-menu
2583 (funcall answer widget)))))
2585 (defun custom-variable-edit (widget)
2586 "Edit value of WIDGET."
2587 (widget-put widget :custom-state 'unknown)
2588 (widget-put widget :custom-form 'edit)
2589 (custom-redraw widget))
2591 (defun custom-variable-edit-lisp (widget)
2592 "Edit the Lisp representation of the value of WIDGET."
2593 (widget-put widget :custom-state 'unknown)
2594 (widget-put widget :custom-form 'lisp)
2595 (custom-redraw widget))
2597 (defun custom-variable-set (widget)
2598 "Set the current value for the variable being edited by WIDGET."
2599 (let* ((form (widget-get widget :custom-form))
2600 (state (widget-get widget :custom-state))
2601 (child (car (widget-get widget :children)))
2602 (symbol (widget-value widget))
2603 (set (or (get symbol 'custom-set) 'set-default))
2604 (comment-widget (widget-get widget :comment-widget))
2605 (comment (widget-value comment-widget))
2607 (cond ((eq state 'hidden)
2608 (error "Cannot set hidden variable"))
2609 ((setq val (widget-apply child :validate))
2610 (goto-char (widget-get val :from))
2611 (error "%s" (widget-get val :error)))
2612 ((memq form '(lisp mismatch))
2613 (when (equal comment "")
2615 ;; Make the comment invisible by hand if it's empty
2616 (custom-comment-hide comment-widget))
2617 (custom-variable-backup-value widget)
2618 (funcall set symbol (eval (setq val (widget-value child))))
2619 (put symbol 'customized-value (list val))
2620 (put symbol 'variable-comment comment)
2621 (put symbol 'customized-variable-comment comment))
2623 (when (equal comment "")
2625 ;; Make the comment invisible by hand if it's empty
2626 (custom-comment-hide comment-widget))
2627 (custom-variable-backup-value widget)
2628 (funcall set symbol (setq val (widget-value child)))
2629 (put symbol 'customized-value (list (custom-quote val)))
2630 (put symbol 'variable-comment comment)
2631 (put symbol 'customized-variable-comment comment)))
2632 (custom-variable-state-set widget)
2633 (custom-redraw-magic widget)))
2635 (defun custom-variable-save (widget)
2636 "Set and save the value for the variable being edited by WIDGET."
2637 (let* ((form (widget-get widget :custom-form))
2638 (state (widget-get widget :custom-state))
2639 (child (car (widget-get widget :children)))
2640 (symbol (widget-value widget))
2641 (set (or (get symbol 'custom-set) 'set-default))
2642 (comment-widget (widget-get widget :comment-widget))
2643 (comment (widget-value comment-widget))
2645 (cond ((eq state 'hidden)
2646 (error "Cannot set hidden variable"))
2647 ((setq val (widget-apply child :validate))
2648 (goto-char (widget-get val :from))
2649 (error "Saving %s: %s" symbol (widget-get val :error)))
2650 ((memq form '(lisp mismatch))
2651 (when (equal comment "")
2653 ;; Make the comment invisible by hand if it's empty
2654 (custom-comment-hide comment-widget))
2655 (put symbol 'saved-value (list (widget-value child)))
2656 (custom-push-theme 'theme-value symbol 'user
2657 'set (list (widget-value child)))
2658 (funcall set symbol (eval (widget-value child)))
2659 (put symbol 'variable-comment comment)
2660 (put symbol 'saved-variable-comment comment))
2662 (when (equal comment "")
2664 ;; Make the comment invisible by hand if it's empty
2665 (custom-comment-hide comment-widget))
2666 (put symbol 'saved-value
2667 (list (custom-quote (widget-value child))))
2668 (custom-push-theme 'theme-value symbol 'user
2669 'set (list (custom-quote (widget-value
2671 (funcall set symbol (widget-value child))
2672 (put symbol 'variable-comment comment)
2673 (put symbol 'saved-variable-comment comment)))
2674 (put symbol 'customized-value nil)
2675 (put symbol 'customized-variable-comment nil)
2677 (custom-variable-state-set widget)
2678 (custom-redraw-magic widget)))
2680 (defun custom-variable-reset-saved (widget)
2681 "Restore the saved value for the variable being edited by WIDGET.
2682 The value that was current before this operation
2683 becomes the backup value, so you can get it again."
2684 (let* ((symbol (widget-value widget))
2685 (set (or (get symbol 'custom-set) 'set-default))
2686 (value (get symbol 'saved-value))
2687 (comment (get symbol 'saved-variable-comment)))
2688 (cond ((or value comment)
2689 (put symbol 'variable-comment comment)
2690 (custom-variable-backup-value widget)
2692 (funcall set symbol (eval (car value)))
2695 (error "No saved value for %s" symbol)))
2696 (put symbol 'customized-value nil)
2697 (put symbol 'customized-variable-comment nil)
2698 (widget-put widget :custom-state 'unknown)
2699 ;; This call will possibly make the comment invisible
2700 (custom-redraw widget)))
2702 (defun custom-variable-reset-standard (widget)
2703 "Restore the standard setting for the variable being edited by WIDGET.
2704 This operation eliminates any saved setting for the variable,
2705 restoring it to the state of a variable that has never been customized.
2706 The value that was current before this operation
2707 becomes the backup value, so you can get it again."
2708 (let* ((symbol (widget-value widget))
2709 (set (or (get symbol 'custom-set) 'set-default)))
2710 (if (get symbol 'standard-value)
2712 (custom-variable-backup-value widget)
2713 (funcall set symbol (eval (car (get symbol 'standard-value)))))
2714 (error "No standard setting known for %S" symbol))
2715 (put symbol 'variable-comment nil)
2716 (put symbol 'customized-value nil)
2717 (put symbol 'customized-variable-comment nil)
2718 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2719 (put symbol 'saved-value nil)
2720 (custom-push-theme 'theme-value symbol 'user 'reset 'standard)
2721 ;; As a special optimizations we do not (explictly)
2722 ;; save resets to standard when no theme set the value.
2723 (if (null (cdr (get symbol 'theme-value)))
2724 (put symbol 'theme-value nil))
2725 (put symbol 'saved-variable-comment nil)
2727 (widget-put widget :custom-state 'unknown)
2728 ;; This call will possibly make the comment invisible
2729 (custom-redraw widget)))
2731 (defun custom-variable-backup-value (widget)
2732 "Back up the current value for WIDGET's variable.
2733 The backup value is kept in the car of the `backup-value' property."
2734 (let* ((symbol (widget-value widget))
2735 (get (or (get symbol 'custom-get) 'default-value))
2736 (type (custom-variable-type symbol))
2737 (conv (widget-convert type))
2738 (value (if (default-boundp symbol)
2739 (funcall get symbol)
2740 (widget-get conv :value))))
2741 (put symbol 'backup-value (list value))))
2743 (defun custom-variable-reset-backup (widget)
2744 "Restore the backup value for the variable being edited by WIDGET.
2745 The value that was current before this operation
2746 becomes the backup value, so you can use this operation repeatedly
2747 to switch between two values."
2748 (let* ((symbol (widget-value widget))
2749 (set (or (get symbol 'custom-set) 'set-default))
2750 (value (get symbol 'backup-value))
2751 (comment-widget (widget-get widget :comment-widget))
2752 (comment (widget-value comment-widget)))
2755 (custom-variable-backup-value widget)
2757 (funcall set symbol (car value))
2759 (error "No backup value for %s" symbol))
2760 (put symbol 'customized-value (list (car value)))
2761 (put symbol 'variable-comment comment)
2762 (put symbol 'customized-variable-comment comment)
2763 (custom-variable-state-set widget)
2764 ;; This call will possibly make the comment invisible
2765 (custom-redraw widget)))
2767 ;;; The `custom-face-edit' Widget.
2769 (define-widget 'custom-face-edit 'checklist
2770 "Edit face attributes."
2774 :button-args '(:help-echo "Control whether this attribute has any effect.")
2775 :value-to-internal 'custom-face-edit-fix-value
2776 :match (lambda (widget value)
2777 (widget-checklist-match widget
2778 (custom-face-edit-fix-value widget value)))
2779 :convert-widget 'custom-face-edit-convert-widget
2780 :args (mapcar (lambda (att)
2783 :sibling-args (widget-get (nth 1 att) :sibling-args)
2784 (list 'const :format "" :value (nth 0 att))
2786 custom-face-attributes))
2788 (defun custom-face-edit-fix-value (widget value)
2789 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2790 Also change :reverse-video to :inverse-video."
2794 (let ((key (car value))
2795 (val (car (cdr value))))
2796 (cond ((eq key :italic)
2797 (push :slant result)
2798 (push (if val 'italic 'normal) result))
2800 (push :weight result)
2801 (push (if val 'bold 'normal) result))
2802 ((eq key :reverse-video)
2803 (push :inverse-video result)
2807 (push val result))))
2808 (setq value (cdr (cdr value))))
2809 (setq result (nreverse result))
2813 (defun custom-face-edit-convert-widget (widget)
2814 "Convert :args as widget types in WIDGET."
2817 :args (mapcar (lambda (arg)
2819 :deactivate 'custom-face-edit-deactivate
2820 :activate 'custom-face-edit-activate
2821 :delete 'custom-face-edit-delete))
2822 (widget-get widget :args)))
2825 (defun custom-face-edit-deactivate (widget)
2826 "Make face widget WIDGET inactive for user modifications."
2827 (unless (widget-get widget :inactive)
2828 (let ((tag (custom-face-edit-attribute-tag widget))
2829 (from (copy-marker (widget-get widget :from)))
2830 (value (widget-value widget))
2831 (inhibit-read-only t)
2832 (inhibit-modification-hooks t))
2835 (widget-default-delete widget)
2836 (insert tag ": *\n")
2837 (widget-put widget :inactive
2838 (cons value (cons from (- (point) from))))))))
2840 (defun custom-face-edit-activate (widget)
2841 "Make face widget WIDGET inactive for user modifications."
2842 (let ((inactive (widget-get widget :inactive))
2843 (inhibit-read-only t)
2844 (inhibit-modification-hooks t))
2845 (when (consp inactive)
2847 (goto-char (car (cdr inactive)))
2848 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2849 (widget-put widget :inactive nil)
2850 (widget-apply widget :create)
2851 (widget-value-set widget (car inactive))
2854 (defun custom-face-edit-delete (widget)
2855 "Remove WIDGET from the buffer."
2856 (let ((inactive (widget-get widget :inactive))
2857 (inhibit-read-only t)
2858 (inhibit-modification-hooks t))
2860 ;; Widget is alive, we don't have to do anything special
2861 (widget-default-delete widget)
2862 ;; WIDGET is already deleted because we did so to inactivate it;
2863 ;; now just get rid of the label we put in its place.
2864 (delete-region (car (cdr inactive))
2865 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2866 (widget-put widget :inactive nil))))
2869 (defun custom-face-edit-attribute-tag (widget)
2870 "Returns the first :tag property in WIDGET or one of its children."
2871 (let ((tag (widget-get widget :tag)))
2872 (or (and (not (equal tag "")) tag)
2873 (let ((children (widget-get widget :children)))
2874 (while (and (null tag) children)
2875 (setq tag (custom-face-edit-attribute-tag (pop children))))
2878 ;;; The `custom-display' Widget.
2880 (define-widget 'custom-display 'menu-choice
2881 "Select a display type."
2884 :help-echo "Specify frames where the face attributes should be used."
2885 :args '((const :tag "all" t)
2886 (const :tag "defaults" default)
2890 :args ((group :sibling-args (:help-echo "\
2891 Only match the specified window systems.")
2892 (const :format "Type: "
2894 (checklist :inline t
2897 :sibling-args (:help-echo "\
2898 The X11 Window System.")
2900 (const :format "PM "
2901 :sibling-args (:help-echo "\
2902 OS/2 Presentation Manager.")
2904 (const :format "W32 "
2905 :sibling-args (:help-echo "\
2908 (const :format "MAC "
2909 :sibling-args (:help-echo "\
2912 (const :format "DOS "
2913 :sibling-args (:help-echo "\
2916 (const :format "TTY%n"
2917 :sibling-args (:help-echo "\
2918 Plain text terminals.")
2920 (group :sibling-args (:help-echo "\
2921 Only match the frames with the specified color support.")
2922 (const :format "Class: "
2924 (checklist :inline t
2926 (const :format "Color "
2927 :sibling-args (:help-echo "\
2928 Match color frames.")
2930 (const :format "Grayscale "
2931 :sibling-args (:help-echo "\
2932 Match grayscale frames.")
2934 (const :format "Monochrome%n"
2935 :sibling-args (:help-echo "\
2936 Match frames with no color support.")
2938 (group :sibling-args (:help-echo "\
2939 The minimum number of colors the frame should support.")
2940 (const :format "" min-colors)
2941 (integer :tag "Minimum number of colors" ))
2942 (group :sibling-args (:help-echo "\
2943 Only match frames with the specified intensity.")
2945 Background brightness: "
2947 (checklist :inline t
2949 (const :format "Light "
2950 :sibling-args (:help-echo "\
2951 Match frames with light backgrounds.")
2953 (const :format "Dark\n"
2954 :sibling-args (:help-echo "\
2955 Match frames with dark backgrounds.")
2957 (group :sibling-args (:help-echo "\
2958 Only match frames that support the specified face attributes.")
2959 (const :format "Supports attributes:" supports)
2960 (custom-face-edit :inline t :format "%n%v"))))))
2962 ;;; The `custom-face' Widget.
2964 (defface custom-face-tag
2965 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
2966 "Face used for face tags."
2967 :group 'custom-faces)
2968 ;; backward-compatibility alias
2969 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
2971 (defcustom custom-face-default-form 'selected
2972 "Default form of displaying face definition."
2973 :type '(choice (const all)
2976 :group 'custom-buffer
2979 (define-widget 'custom-face 'custom
2981 :sample-face 'custom-face-tag-face
2982 :help-echo "Set or reset this face."
2983 :documentation-property #'face-doc-string
2984 :value-create 'custom-face-value-create
2985 :action 'custom-face-action
2986 :custom-category 'face
2987 :custom-form nil ; defaults to value of `custom-face-default-form'
2988 :custom-set 'custom-face-set
2989 :custom-save 'custom-face-save
2990 :custom-reset-current 'custom-redraw
2991 :custom-reset-saved 'custom-face-reset-saved
2992 :custom-reset-standard 'custom-face-reset-standard
2993 :custom-standard-value 'custom-face-standard-value
2994 :custom-menu 'custom-face-menu-create)
2996 (define-widget 'custom-face-all 'editable-list
2997 "An editable list of display specifications and attributes."
2998 :entry-format "%i %d %v"
2999 :insert-button-args '(:help-echo "Insert new display specification here.")
3000 :append-button-args '(:help-echo "Append new display specification here.")
3001 :delete-button-args '(:help-echo "Delete this display specification.")
3002 :args '((group :format "%v" custom-display custom-face-edit)))
3004 (defconst custom-face-all (widget-convert 'custom-face-all)
3005 "Converted version of the `custom-face-all' widget.")
3007 (define-widget 'custom-display-unselected 'item
3008 "A display specification that doesn't match the selected display."
3009 :match 'custom-display-unselected-match)
3011 (defun custom-display-unselected-match (widget value)
3012 "Non-nil if VALUE is an unselected display specification."
3013 (not (face-spec-set-match-display value (selected-frame))))
3015 (define-widget 'custom-face-selected 'group
3016 "Edit the attributes of the selected display in a face specification."
3017 :args '((choice :inline t
3018 (group :tag "With Defaults" :inline t
3019 (group (const :tag "" default)
3020 (custom-face-edit :tag " Default\n Attributes"))
3023 (group custom-display-unselected sexp))
3024 (group (sexp :format "")
3025 (custom-face-edit :tag " Overriding\n Attributes"))
3029 (group :tag "No Defaults" :inline t
3032 (group custom-display-unselected sexp))
3033 (group (sexp :format "")
3034 (custom-face-edit :tag "\n Attributes"))
3041 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3042 "Converted version of the `custom-face-selected' widget.")
3044 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3045 "Return a canonicalized version of SPEC using.
3046 FILTER-INDEX is the index in the entry for each attribute in
3047 `custom-face-attributes' at which the appropriate filter function can be
3048 found, and DEFAULT-FILTER is the filter to apply for attributes that
3050 (mapcar (lambda (entry)
3051 ;; Filter a single face-spec entry
3052 (let ((tests (car entry))
3054 ;; Handle both old- and new-style attribute syntax
3055 (if (listp (car (cdr entry)))
3058 (filtered-attrs nil))
3059 ;; Filter each face attribute
3060 (while unfiltered-attrs
3061 (let* ((attr (pop unfiltered-attrs))
3062 (pre-filtered-value (pop unfiltered-attrs))
3064 (or (nth filter-index (assq attr custom-face-attributes))
3068 (funcall filter pre-filtered-value)
3069 pre-filtered-value)))
3070 (push filtered-value filtered-attrs)
3071 (push attr filtered-attrs)))
3073 (list tests filtered-attrs)))
3076 (defun custom-pre-filter-face-spec (spec)
3077 "Return SPEC changed as necessary for editing by the face customization widget.
3078 SPEC must be a full face spec."
3079 (custom-filter-face-spec spec 2))
3081 (defun custom-post-filter-face-spec (spec)
3082 "Return the customized SPEC in a form suitable for setting the face."
3083 (custom-filter-face-spec spec 3))
3085 (defun custom-face-value-create (widget)
3086 "Create a list of the display specifications for WIDGET."
3087 (let ((buttons (widget-get widget :buttons))
3089 (symbol (widget-get widget :value))
3090 (tag (widget-get widget :tag))
3091 (state (widget-get widget :custom-state))
3093 (is-last (widget-get widget :custom-last))
3094 (prefix (widget-get widget :custom-prefix)))
3096 (setq tag (prin1-to-string symbol)))
3097 (cond ((eq custom-buffer-style 'tree)
3098 (insert prefix (if is-last " `--- " " |--- "))
3099 (push (widget-create-child-and-convert
3100 widget 'custom-browse-face-tag)
3102 (insert " " tag "\n")
3103 (widget-put widget :buttons buttons))
3107 (widget-specify-sample widget begin (point))
3108 (if (eq custom-buffer-style 'face)
3110 (if (string-match "face\\'" tag)
3112 (insert " face: ")))
3114 (push (widget-create-child-and-convert widget 'item
3121 (push (widget-create-child-and-convert
3123 :help-echo "Hide or show this face."
3126 :action 'custom-toggle-parent
3127 (not (eq state 'hidden)))
3131 (let ((magic (widget-create-child-and-convert
3132 widget 'custom-magic nil)))
3133 (widget-put widget :custom-magic magic)
3134 (push magic buttons))
3136 (widget-put widget :buttons buttons)
3137 ;; Insert documentation.
3138 (widget-default-format-handler widget ?h)
3139 ;; The comment field
3140 (unless (eq state 'hidden)
3141 (let* ((comment (get symbol 'face-comment))
3143 (widget-create-child-and-convert
3144 widget 'custom-comment
3146 :value (or comment ""))))
3147 (widget-put widget :comment-widget comment-widget)
3148 (push comment-widget children)))
3150 (unless (eq state 'hidden)
3151 (when (eq (widget-get widget :custom-level) 1)
3152 (custom-add-parent-links widget))
3153 (custom-add-see-also widget))
3155 (unless (eq (preceding-char) ?\n)
3157 (unless (eq state 'hidden)
3158 (message "Creating face editor...")
3159 (custom-load-widget widget)
3160 (unless (widget-get widget :custom-form)
3161 (widget-put widget :custom-form custom-face-default-form))
3162 (let* ((symbol (widget-value widget))
3163 (spec (or (get symbol 'customized-face)
3164 (get symbol 'saved-face)
3165 (get symbol 'face-defface-spec)
3166 ;; Attempt to construct it.
3167 (list (list t (custom-face-attributes-get
3168 symbol (selected-frame))))))
3169 (form (widget-get widget :custom-form))
3170 (indent (widget-get widget :indent))
3172 ;; If the user has changed this face in some other way,
3173 ;; edit it as the user has specified it.
3174 (if (not (face-spec-match-p symbol spec (selected-frame)))
3175 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3176 (setq spec (custom-pre-filter-face-spec spec))
3177 (setq edit (widget-create-child-and-convert
3179 (cond ((and (eq form 'selected)
3180 (widget-apply custom-face-selected
3182 (when indent (insert-char ?\ indent))
3183 'custom-face-selected)
3184 ((and (not (eq form 'lisp))
3185 (widget-apply custom-face-all
3189 (when indent (insert-char ?\ indent))
3192 (custom-face-state-set widget)
3193 (push edit children)
3194 (widget-put widget :children children))
3195 (message "Creating face editor...done"))))))
3197 (defvar custom-face-menu
3198 '(("Set for Current Session" custom-face-set)
3199 ("Save for Future Sessions" custom-face-save-command)
3200 ("Reset to Saved" custom-face-reset-saved
3202 (or (get (widget-value widget) 'saved-face)
3203 (get (widget-value widget) 'saved-face-comment))))
3204 ("Erase Customization" custom-face-reset-standard
3206 (get (widget-value widget) 'face-defface-spec)))
3207 ("---" ignore ignore)
3208 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3209 ("---" ignore ignore)
3210 ("Show all display specs" custom-face-edit-all
3212 (not (eq (widget-get widget :custom-form) 'all))))
3213 ("Just current attributes" custom-face-edit-selected
3215 (not (eq (widget-get widget :custom-form) 'selected))))
3216 ("Show as Lisp expression" custom-face-edit-lisp
3218 (not (eq (widget-get widget :custom-form) 'lisp)))))
3219 "Alist of actions for the `custom-face' widget.
3220 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3221 the menu entry, ACTION is the function to call on the widget when the
3222 menu is selected, and FILTER is a predicate which takes a `custom-face'
3223 widget as an argument, and returns non-nil if ACTION is valid on that
3224 widget. If FILTER is nil, ACTION is always valid.")
3226 (defun custom-face-edit-selected (widget)
3227 "Edit selected attributes of the value of WIDGET."
3228 (widget-put widget :custom-state 'unknown)
3229 (widget-put widget :custom-form 'selected)
3230 (custom-redraw widget))
3232 (defun custom-face-edit-all (widget)
3233 "Edit all attributes of the value of WIDGET."
3234 (widget-put widget :custom-state 'unknown)
3235 (widget-put widget :custom-form 'all)
3236 (custom-redraw widget))
3238 (defun custom-face-edit-lisp (widget)
3239 "Edit the Lisp representation of the value of WIDGET."
3240 (widget-put widget :custom-state 'unknown)
3241 (widget-put widget :custom-form 'lisp)
3242 (custom-redraw widget))
3244 (defun custom-face-state-set (widget)
3245 "Set the state of WIDGET."
3246 (let* ((symbol (widget-value widget))
3247 (comment (get symbol 'face-comment))
3251 (setq tmp (get symbol 'customized-face))
3252 (setq temp (get symbol 'customized-face-comment))
3254 (if (equal temp comment)
3258 (setq tmp (get symbol 'saved-face))
3259 (setq temp (get symbol 'saved-face-comment))
3261 (if (equal temp comment)
3264 ((get symbol 'face-defface-spec)
3265 (if (equal comment nil)
3270 ;; If the user called set-face-attribute to change the default
3271 ;; for new frames, this face is "set outside of Customize".
3272 (if (and (not (eq state 'rogue))
3273 (get symbol 'face-modified))
3274 (setq state 'changed))
3275 (widget-put widget :custom-state state)))
3277 (defun custom-face-action (widget &optional event)
3278 "Show the menu for `custom-face' WIDGET.
3279 Optional EVENT is the location for the menu."
3280 (if (eq (widget-get widget :custom-state) 'hidden)
3281 (custom-toggle-hide widget)
3282 (let* ((completion-ignore-case t)
3283 (symbol (widget-get widget :value))
3284 (answer (widget-choose (concat "Operation on "
3285 (custom-unlispify-tag-name symbol))
3286 (custom-menu-filter custom-face-menu
3290 (funcall answer widget)))))
3292 (defun custom-face-set (widget)
3293 "Make the face attributes in WIDGET take effect."
3294 (let* ((symbol (widget-value widget))
3295 (child (car (widget-get widget :children)))
3296 (value (custom-post-filter-face-spec (widget-value child)))
3297 (comment-widget (widget-get widget :comment-widget))
3298 (comment (widget-value comment-widget)))
3299 (when (equal comment "")
3301 ;; Make the comment invisible by hand if it's empty
3302 (custom-comment-hide comment-widget))
3303 (put symbol 'customized-face value)
3304 (if (face-spec-choose value)
3305 (face-spec-set symbol value)
3306 ;; face-set-spec ignores empty attribute lists, so just give it
3307 ;; something harmless instead.
3308 (face-spec-set symbol '((t :foreground unspecified))))
3309 (put symbol 'customized-face-comment comment)
3310 (put symbol 'face-comment comment)
3311 (custom-face-state-set widget)
3312 (custom-redraw-magic widget)))
3314 (defun custom-face-save-command (widget)
3315 "Save in `.emacs' the face attributes in WIDGET."
3316 (custom-face-save widget)
3319 (defun custom-face-save (widget)
3320 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3321 (let* ((symbol (widget-value widget))
3322 (child (car (widget-get widget :children)))
3323 (value (custom-post-filter-face-spec (widget-value child)))
3324 (comment-widget (widget-get widget :comment-widget))
3325 (comment (widget-value comment-widget)))
3326 (when (equal comment "")
3328 ;; Make the comment invisible by hand if it's empty
3329 (custom-comment-hide comment-widget))
3330 (if (face-spec-choose value)
3331 (face-spec-set symbol value)
3332 ;; face-set-spec ignores empty attribute lists, so just give it
3333 ;; something harmless instead.
3334 (face-spec-set symbol '((t :foreground unspecified))))
3335 (unless (eq (widget-get widget :custom-state) 'standard)
3336 (put symbol 'saved-face value))
3337 (custom-push-theme 'theme-face symbol 'user 'set value)
3338 (put symbol 'customized-face nil)
3339 (put symbol 'face-comment comment)
3340 (put symbol 'customized-face-comment nil)
3341 (put symbol 'saved-face-comment comment)
3343 (custom-face-state-set widget)
3344 (custom-redraw-magic widget)))
3346 (defun custom-face-reset-saved (widget)
3347 "Restore WIDGET to the face's default attributes."
3348 (let* ((symbol (widget-value widget))
3349 (child (car (widget-get widget :children)))
3350 (value (get symbol 'saved-face))
3351 (comment (get symbol 'saved-face-comment))
3352 (comment-widget (widget-get widget :comment-widget)))
3353 (unless (or value comment)
3354 (error "No saved value for this face"))
3355 (put symbol 'customized-face nil)
3356 (put symbol 'customized-face-comment nil)
3357 (face-spec-set symbol value)
3358 (put symbol 'face-comment comment)
3359 (widget-value-set child value)
3360 ;; This call manages the comment visibility
3361 (widget-value-set comment-widget (or comment ""))
3362 (custom-face-state-set widget)
3363 (custom-redraw-magic widget)))
3365 (defun custom-face-standard-value (widget)
3366 (get (widget-value widget) 'face-defface-spec))
3368 (defun custom-face-reset-standard (widget)
3369 "Restore WIDGET to the face's standard settings.
3370 This operation eliminates any saved setting for the face,
3371 restoring it to the state of a face that has never been customized."
3372 (let* ((symbol (widget-value widget))
3373 (child (car (widget-get widget :children)))
3374 (value (get symbol 'face-defface-spec))
3375 (comment-widget (widget-get widget :comment-widget)))
3377 (error "No standard setting for this face"))
3378 (put symbol 'customized-face nil)
3379 (put symbol 'customized-face-comment nil)
3380 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3381 (put symbol 'saved-face nil)
3382 (custom-push-theme 'theme-face symbol 'user 'reset 'standard)
3383 ;; Do not explictly save resets to standards without themes.
3384 (if (null (cdr (get symbol 'theme-face)))
3385 (put symbol 'theme-face nil))
3386 (put symbol 'saved-face-comment nil)
3388 (face-spec-set symbol value)
3389 (put symbol 'face-comment nil)
3390 (widget-value-set child value)
3391 ;; This call manages the comment visibility
3392 (widget-value-set comment-widget "")
3393 (custom-face-state-set widget)
3394 (custom-redraw-magic widget)))
3396 ;;; The `face' Widget.
3398 (defvar widget-face-prompt-value-history nil
3399 "History of input to `widget-face-prompt-value'.")
3401 (define-widget 'face 'symbol
3402 "A Lisp face name (with sample)."
3403 :format "%{%t%}: (%{sample%}) %v"
3406 :sample-face-get 'widget-face-sample-face-get
3407 :notify 'widget-face-notify
3408 :match (lambda (widget value) (facep value))
3409 :complete-function (lambda ()
3411 (lisp-complete-symbol 'facep))
3412 :prompt-match 'facep
3413 :prompt-history 'widget-face-prompt-value-history
3414 :validate (lambda (widget)
3415 (unless (facep (widget-value widget))
3417 :error (format "Invalid face: %S"
3418 (widget-value widget)))
3421 (defun widget-face-sample-face-get (widget)
3422 (let ((value (widget-value widget)))
3427 (defun widget-face-notify (widget child &optional event)
3428 "Update the sample, and notify the parent."
3429 (overlay-put (widget-get widget :sample-overlay)
3430 'face (widget-apply widget :sample-face-get))
3431 (widget-default-notify widget child event))
3434 ;;; The `hook' Widget.
3436 (define-widget 'hook 'list
3438 :value-to-internal (lambda (widget value)
3439 (if (and value (symbolp value))
3442 :match (lambda (widget value)
3444 (widget-group-match widget value)))
3445 ;; Avoid adding undefined functions to the hook, especially for
3446 ;; things like `find-file-hook' or even more basic ones, to avoid
3448 :set (lambda (symbol value)
3451 (add-hook symbol elt))))
3452 :convert-widget 'custom-hook-convert-widget
3455 (defun custom-hook-convert-widget (widget)
3456 ;; Handle `:options'.
3457 (let* ((options (widget-get widget :options))
3458 (other `(editable-list :inline t
3459 :entry-format "%i %d%v"
3460 (function :format " %v")))
3462 (list `(checklist :inline t
3463 ,@(mapcar (lambda (entry)
3464 `(function-item ,entry))
3468 (widget-put widget :args args)
3471 ;;; The `custom-group-link' Widget.
3473 (define-widget 'custom-group-link 'link
3474 "Show parent in other window when activated."
3475 :help-echo "Create customization buffer for this group."
3476 :action 'custom-group-link-action)
3478 (defun custom-group-link-action (widget &rest ignore)
3479 (customize-group (widget-value widget)))
3481 ;;; The `custom-group' Widget.
3483 (defcustom custom-group-tag-faces nil
3484 ;; In XEmacs, this ought to play games with font size.
3485 ;; Fixme: make it do so in Emacs.
3486 "Face used for group tags.
3487 The first member is used for level 1 groups, the second for level 2,
3488 and so forth. The remaining group tags are shown with `custom-group-tag'."
3489 :type '(repeat face)
3490 :group 'custom-faces)
3492 (defface custom-group-tag-1
3495 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3496 (((min-colors 88) (class color)
3498 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3501 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3503 "Face used for group tags."
3504 :group 'custom-faces)
3505 ;; backward-compatibility alias
3506 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3508 (defface custom-group-tag
3511 (:foreground "light blue" :weight bold :height 1.2))
3512 (((min-colors 88) (class color)
3514 (:foreground "blue1" :weight bold :height 1.2))
3517 (:foreground "blue" :weight bold :height 1.2))
3519 "Face used for low level group tags."
3520 :group 'custom-faces)
3521 ;; backward-compatibility alias
3522 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3524 (define-widget 'custom-group 'custom
3527 :sample-face-get 'custom-group-sample-face-get
3528 :documentation-property 'group-documentation
3529 :help-echo "Set or reset all members of this group."
3530 :value-create 'custom-group-value-create
3531 :action 'custom-group-action
3532 :custom-category 'group
3533 :custom-set 'custom-group-set
3534 :custom-save 'custom-group-save
3535 :custom-reset-current 'custom-group-reset-current
3536 :custom-reset-saved 'custom-group-reset-saved
3537 :custom-reset-standard 'custom-group-reset-standard
3538 :custom-menu 'custom-group-menu-create)
3540 (defun custom-group-sample-face-get (widget)
3541 ;; Use :sample-face.
3542 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3545 (define-widget 'custom-group-visibility 'visibility
3546 "An indicator and manipulator for hidden group contents."
3547 :create 'custom-group-visibility-create)
3549 (defun custom-group-visibility-create (widget)
3550 (let ((visible (widget-value widget)))
3552 (insert "--------")))
3553 (widget-default-create widget))
3555 (defun custom-group-members (symbol groups-only)
3556 "Return SYMBOL's custom group members.
3557 If GROUPS-ONLY non-nil, return only those members that are groups."
3558 (if (not groups-only)
3559 (get symbol 'custom-group)
3561 (dolist (entry (get symbol 'custom-group))
3562 (when (eq (nth 1 entry) 'custom-group)
3563 (push entry members)))
3564 (nreverse members))))
3566 (defun custom-group-value-create (widget)
3567 "Insert a customize group for WIDGET in the current buffer."
3568 (unless (eq (widget-get widget :custom-state) 'hidden)
3569 (custom-load-widget widget))
3570 (let* ((state (widget-get widget :custom-state))
3571 (level (widget-get widget :custom-level))
3572 ;; (indent (widget-get widget :indent))
3573 (prefix (widget-get widget :custom-prefix))
3574 (buttons (widget-get widget :buttons))
3575 (tag (widget-get widget :tag))
3576 (symbol (widget-value widget))
3577 (members (custom-group-members symbol
3578 (and (eq custom-buffer-style 'tree)
3579 custom-browse-only-groups))))
3580 (cond ((and (eq custom-buffer-style 'tree)
3582 (or members (custom-unloaded-widget-p widget)))
3583 (custom-browse-insert-prefix prefix)
3584 (push (widget-create-child-and-convert
3585 widget 'custom-browse-visibility
3586 ;; :tag-glyph "plus"
3590 ;; (widget-glyph-insert nil "-- " "horizontal")
3591 (push (widget-create-child-and-convert
3592 widget 'custom-browse-group-tag)
3594 (insert " " tag "\n")
3595 (widget-put widget :buttons buttons))
3596 ((and (eq custom-buffer-style 'tree)
3597 (zerop (length members)))
3598 (custom-browse-insert-prefix prefix)
3600 ;; (widget-glyph-insert nil "[ ]" "empty")
3601 ;; (widget-glyph-insert nil "-- " "horizontal")
3602 (push (widget-create-child-and-convert
3603 widget 'custom-browse-group-tag)
3605 (insert " " tag "\n")
3606 (widget-put widget :buttons buttons))
3607 ((eq custom-buffer-style 'tree)
3608 (custom-browse-insert-prefix prefix)
3609 (if (zerop (length members))
3611 (custom-browse-insert-prefix prefix)
3613 ;; (widget-glyph-insert nil "[ ]" "empty")
3614 ;; (widget-glyph-insert nil "-- " "horizontal")
3615 (push (widget-create-child-and-convert
3616 widget 'custom-browse-group-tag)
3618 (insert " " tag "\n")
3619 (widget-put widget :buttons buttons))
3620 (push (widget-create-child-and-convert
3621 widget 'custom-browse-visibility
3622 ;; :tag-glyph "minus"
3626 ;; (widget-glyph-insert nil "-\\ " "top")
3627 (push (widget-create-child-and-convert
3628 widget 'custom-browse-group-tag)
3630 (insert " " tag "\n")
3631 (widget-put widget :buttons buttons)
3632 (message "Creating group...")
3633 (let* ((members (custom-sort-items members
3634 custom-browse-sort-alphabetically
3635 custom-browse-order-groups))
3636 (prefixes (widget-get widget :custom-prefixes))
3637 (custom-prefix-list (custom-prefix-add symbol prefixes))
3638 (extra-prefix (if (widget-get widget :custom-last)
3641 (prefix (concat prefix extra-prefix))
3644 (setq entry (car members)
3645 members (cdr members))
3646 (push (widget-create-child-and-convert
3647 widget (nth 1 entry)
3649 :tag (custom-unlispify-tag-name (nth 0 entry))
3650 :custom-prefixes custom-prefix-list
3651 :custom-level (1+ level)
3652 :custom-last (null members)
3653 :value (nth 0 entry)
3654 :custom-prefix prefix)
3656 (widget-put widget :children (reverse children)))
3657 (message "Creating group...done")))
3660 ;; Create level indicator.
3661 (unless (eq custom-buffer-style 'links)
3662 (insert-char ?\ (* custom-buffer-indent (1- level)))
3665 (let ((begin (point)))
3667 (widget-specify-sample widget begin (point)))
3669 ;; Create link/visibility indicator.
3670 (if (eq custom-buffer-style 'links)
3671 (push (widget-create-child-and-convert
3672 widget 'custom-group-link
3676 (push (widget-create-child-and-convert
3677 widget 'custom-group-visibility
3678 :help-echo "Show members of this group."
3679 :action 'custom-toggle-parent
3680 (not (eq state 'hidden)))
3683 ;; Create magic button.
3684 (let ((magic (widget-create-child-and-convert
3685 widget 'custom-magic nil)))
3686 (widget-put widget :custom-magic magic)
3687 (push magic buttons))
3689 (widget-put widget :buttons buttons)
3690 ;; Insert documentation.
3691 (if (and (eq custom-buffer-style 'links) (> level 1))
3692 (widget-put widget :documentation-indent 0))
3693 (widget-default-format-handler widget ?h))
3696 ;; Add parent groups references above the group.
3697 (if t ;;; This should test that the buffer
3698 ;;; was made to display a group.
3700 (if (custom-add-parent-links widget
3701 "Go to parent group:")
3703 ;; Create level indicator.
3704 (insert-char ?\ (* custom-buffer-indent (1- level)))
3707 (let ((start (point)))
3709 (widget-specify-sample widget start (point)))
3711 ;; Create visibility indicator.
3712 (unless (eq custom-buffer-style 'links)
3714 (push (widget-create-child-and-convert
3716 :help-echo "Hide members of this group."
3717 :action 'custom-toggle-parent
3718 (not (eq state 'hidden)))
3721 ;; Create more dashes.
3722 ;; Use 76 instead of 75 to compensate for the temporary "<"
3723 ;; added by `widget-insert'.
3724 (insert-char ?- (- 76 (current-column)
3725 (* custom-buffer-indent level)))
3727 ;; Create magic button.
3728 (let ((magic (widget-create-child-and-convert
3729 widget 'custom-magic
3732 (widget-put widget :custom-magic magic)
3733 (push magic buttons))
3735 (widget-put widget :buttons buttons)
3736 ;; Insert documentation.
3737 (widget-default-format-handler widget ?h)
3739 (if nil ;;; This should test that the buffer
3740 ;;; was not made to display a group.
3742 (insert-char ?\ custom-buffer-indent)
3743 (custom-add-parent-links widget)))
3744 (custom-add-see-also widget
3745 (make-string (* custom-buffer-indent level)
3748 (message "Creating group...")
3749 (let* ((members (custom-sort-items members
3750 custom-buffer-sort-alphabetically
3751 custom-buffer-order-groups))
3752 (prefixes (widget-get widget :custom-prefixes))
3753 (custom-prefix-list (custom-prefix-add symbol prefixes))
3754 (length (length members))
3756 (children (mapcar (lambda (entry)
3757 (widget-insert "\n")
3759 Creating group members... %2d%%"
3760 (/ (* 100.0 count) length))
3761 (setq count (1+ count))
3763 (widget-create-child-and-convert
3764 widget (nth 1 entry)
3766 :tag (custom-unlispify-tag-name
3768 :custom-prefixes custom-prefix-list
3769 :custom-level (1+ level)
3770 :value (nth 0 entry))
3771 (unless (eq (preceding-char) ?\n)
3772 (widget-insert "\n"))))
3774 (message "Creating group magic...")
3775 (mapc 'custom-magic-reset children)
3776 (message "Creating group state...")
3777 (widget-put widget :children children)
3778 (custom-group-state-update widget)
3779 (message "Creating group... done"))
3782 (insert-char ?\ (* custom-buffer-indent (1- level)))
3783 (insert "\\- " (widget-get widget :tag) " group end ")
3784 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
3787 (defvar custom-group-menu
3788 '(("Set for Current Session" custom-group-set
3790 (eq (widget-get widget :custom-state) 'modified)))
3791 ("Save for Future Sessions" custom-group-save
3793 (memq (widget-get widget :custom-state) '(modified set))))
3794 ("Reset to Current" custom-group-reset-current
3796 (memq (widget-get widget :custom-state) '(modified))))
3797 ("Reset to Saved" custom-group-reset-saved
3799 (memq (widget-get widget :custom-state) '(modified set))))
3800 ("Reset to standard setting" custom-group-reset-standard
3802 (memq (widget-get widget :custom-state) '(modified set saved)))))
3803 "Alist of actions for the `custom-group' widget.
3804 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3805 the menu entry, ACTION is the function to call on the widget when the
3806 menu is selected, and FILTER is a predicate which takes a `custom-group'
3807 widget as an argument, and returns non-nil if ACTION is valid on that
3808 widget. If FILTER is nil, ACTION is always valid.")
3810 (defun custom-group-action (widget &optional event)
3811 "Show the menu for `custom-group' WIDGET.
3812 Optional EVENT is the location for the menu."
3813 (if (eq (widget-get widget :custom-state) 'hidden)
3814 (custom-toggle-hide widget)
3815 (let* ((completion-ignore-case t)
3816 (answer (widget-choose (concat "Operation on "
3817 (custom-unlispify-tag-name
3818 (widget-get widget :value)))
3819 (custom-menu-filter custom-group-menu
3823 (funcall answer widget)))))
3825 (defun custom-group-set (widget)
3826 "Set changes in all modified group members."
3827 (let ((children (widget-get widget :children)))
3828 (mapc (lambda (child)
3829 (when (eq (widget-get child :custom-state) 'modified)
3830 (widget-apply child :custom-set)))
3833 (defun custom-group-save (widget)
3834 "Save all modified group members."
3835 (let ((children (widget-get widget :children)))
3836 (mapc (lambda (child)
3837 (when (memq (widget-get child :custom-state) '(modified set))
3838 (widget-apply child :custom-save)))
3841 (defun custom-group-reset-current (widget)
3842 "Reset all modified group members."
3843 (let ((children (widget-get widget :children)))
3844 (mapc (lambda (child)
3845 (when (eq (widget-get child :custom-state) 'modified)
3846 (widget-apply child :custom-reset-current)))
3849 (defun custom-group-reset-saved (widget)
3850 "Reset all modified or set group members."
3851 (let ((children (widget-get widget :children)))
3852 (mapc (lambda (child)
3853 (when (memq (widget-get child :custom-state) '(modified set))
3854 (widget-apply child :custom-reset-saved)))
3857 (defun custom-group-reset-standard (widget)
3858 "Reset all modified, set, or saved group members."
3859 (let ((children (widget-get widget :children)))
3860 (mapc (lambda (child)
3861 (when (memq (widget-get child :custom-state)
3862 '(modified set saved))
3863 (widget-apply child :custom-reset-standard)))
3866 (defun custom-group-state-update (widget)
3868 (unless (eq (widget-get widget :custom-state) 'hidden)
3869 (let* ((children (widget-get widget :children))
3870 (states (mapcar (lambda (child)
3871 (widget-get child :custom-state))
3873 (magics custom-magic-alist)
3876 (let ((magic (car (car magics))))
3877 (if (and (not (eq magic 'hidden))
3878 (memq magic states))
3881 (setq magics (cdr magics)))))
3882 (widget-put widget :custom-state found)))
3883 (custom-magic-reset widget))
3885 ;;; Reading and writing the custom file.
3888 (defcustom custom-file nil
3889 "File used for storing customization information.
3890 The default is nil, which means to use your init file
3891 as specified by `user-init-file'. If the value is not nil,
3892 it should be an absolute file name.
3894 You can set this option through Custom, if you carefully read the
3895 last paragraph below. However, usually it is simpler to write
3896 something like the following in your init file:
3898 \(setq custom-file \"~/.emacs-custom.el\")
3901 Note that both lines are necessary: the first line tells Custom to
3902 save all customizations in this file, but does not load it.
3904 When you change this variable outside Custom, look in the
3905 previous custom file \(usually your init file) for the
3906 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3907 and copy them (whichever ones you find) to the new custom file.
3908 This will preserve your existing customizations.
3910 If you save this option using Custom, Custom will write all
3911 currently saved customizations, including the new one for this
3912 option itself, into the file you specify, overwriting any
3913 `custom-set-variables' and `custom-set-faces' forms already
3914 present in that file. It will not delete any customizations from
3915 the old custom file. You should do that manually if that is what you
3916 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3917 in your init file, where CUSTOM-FILE is the actual name of the
3918 file. Otherwise, Emacs will not load the file when it starts up,
3919 and hence will not set `custom-file' to that file either."
3920 :type '(choice (const :tag "Your Emacs init file" nil)
3921 (file :format "%t:%v%d"
3923 "Please read entire docstring below before setting \
3924 this through Custom.
3925 Click om \"More\" \(or position point there and press RETURN)
3926 if only the first line of the docstring is shown."))
3929 (defun custom-file ()
3930 "Return the file name for saving customizations."
3933 (let ((user-init-file user-init-file)
3935 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
3936 (when (null user-init-file)
3937 (if (or (file-exists-p default-init-file)
3938 (and (eq system-type 'windows-nt)
3939 (file-exists-p "~/_emacs")))
3940 ;; Started with -q, i.e. the file containing
3941 ;; Custom settings hasn't been read. Saving
3942 ;; settings there would overwrite other settings.
3943 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3944 (setq user-init-file default-init-file))
3948 (defun custom-save-all ()
3949 "Save all customizations in `custom-file'."
3950 (let* ((filename (custom-file))
3951 (recentf-exclude (if recentf-mode
3953 (regexp-quote (custom-file))
3956 (old-buffer (find-buffer-visiting filename)))
3957 (with-current-buffer (or old-buffer (find-file-noselect filename))
3958 (let ((inhibit-read-only t))
3959 (custom-save-variables)
3960 (custom-save-faces))
3961 (let ((file-precious-flag t))
3964 (kill-buffer (current-buffer))))))
3966 ;; Editing the custom file contents in a buffer.
3968 (defun custom-save-delete (symbol)
3969 "Delete all calls to SYMBOL from the contents of the current buffer.
3970 Leave point at the old location of the first such call,
3971 or (if there were none) at the end of the buffer.
3973 This function does not save the buffer."
3974 (goto-char (point-min))
3975 ;; Skip all whitespace and comments.
3976 (while (forward-comment 1))
3978 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3981 (while t ;; We exit this loop only via throw.
3982 ;; Skip all whitespace and comments.
3983 (while (forward-comment 1))
3984 (let ((start (point))
3985 (sexp (condition-case nil
3986 (read (current-buffer))
3987 (end-of-file (throw 'found nil)))))
3988 (when (and (listp sexp)
3989 (eq (car sexp) symbol))
3990 (delete-region start (point))
3992 (setq first (point)))))))
3995 ;; Move in front of local variables, otherwise long Custom
3996 ;; entries would make them ineffective.
3997 (let ((pos (point-max))
3998 (case-fold-search t))
4000 (goto-char (point-max))
4001 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4003 (when (search-forward "Local Variables:" nil t)
4004 (setq pos (line-beginning-position))))
4007 (defun custom-save-variables ()
4008 "Save all customized variables in `custom-file'."
4010 (custom-save-delete 'custom-load-themes)
4011 (custom-save-delete 'custom-reset-variables)
4012 (custom-save-delete 'custom-set-variables)
4013 (custom-save-loaded-themes)
4014 (custom-save-resets 'theme-value 'custom-reset-variables nil)
4015 (let ((standard-output (current-buffer))
4016 (saved-list (make-list 1 0))
4018 ;; First create a sorted list of saved variables.
4021 (if (get symbol 'saved-value)
4022 (nconc saved-list (list symbol)))))
4023 (setq saved-list (sort (cdr saved-list) 'string<))
4026 (princ "(custom-set-variables
4027 ;; custom-set-variables was added by Custom.
4028 ;; If you edit it by hand, you could mess it up, so be careful.
4029 ;; Your init file should contain only one such instance.
4030 ;; If there is more than one, they won't work right.\n")
4031 (dolist (symbol saved-list)
4032 (let ((spec (car-safe (get symbol 'theme-value)))
4033 (value (get symbol 'saved-value))
4034 (requests (get symbol 'custom-requests))
4035 (now (not (or (custom-variable-p symbol)
4036 (and (not (boundp symbol))
4037 (not (eq (get symbol 'force-value)
4039 (comment (get symbol 'saved-variable-comment)))
4040 ;; Check `requests'.
4041 (dolist (request requests)
4042 (when (and (symbolp request) (not (featurep request)))
4043 (message "Unknown requested feature: %s" request)
4044 (setq requests (delq request requests))))
4046 (eq (nth 0 spec) 'user)
4047 (eq (nth 1 spec) 'set))
4049 (and (null spec) (get symbol 'saved-value)))
4056 (when (or now requests comment)
4059 (when (or requests comment)
4069 (unless (looking-at "\n")
4072 (defun custom-save-faces ()
4073 "Save all customized faces in `custom-file'."
4075 (custom-save-delete 'custom-reset-faces)
4076 (custom-save-delete 'custom-set-faces)
4077 (custom-save-resets 'theme-face 'custom-reset-faces '(default))
4078 (let ((standard-output (current-buffer))
4079 (saved-list (make-list 1 0))
4081 ;; First create a sorted list of saved faces.
4084 (if (get symbol 'saved-face)
4085 (nconc saved-list (list symbol)))))
4086 (setq saved-list (sort (cdr saved-list) 'string<))
4087 ;; The default face must be first, since it affects the others.
4088 (if (memq 'default saved-list)
4089 (setq saved-list (cons 'default (delq 'default saved-list))))
4092 (princ "(custom-set-faces
4093 ;; custom-set-faces was added by Custom.
4094 ;; If you edit it by hand, you could mess it up, so be careful.
4095 ;; Your init file should contain only one such instance.
4096 ;; If there is more than one, they won't work right.\n")
4097 (dolist (symbol saved-list)
4098 (let ((spec (car-safe (get symbol 'theme-face)))
4099 (value (get symbol 'saved-face))
4100 (now (not (or (get symbol 'face-defface-spec)
4101 (and (not (custom-facep symbol))
4102 (not (get symbol 'force-face))))))
4103 (comment (get symbol 'saved-face-comment)))
4105 (eq (nth 0 spec) 'user)
4106 (eq (nth 1 spec) 'set))
4108 (and (null spec) (get symbol 'saved-face)))
4109 ;; Don't print default face here.
4116 (when (or now comment)
4126 (unless (looking-at "\n")
4129 (defun custom-save-resets (property setter special)
4130 (let (started-writing ignored-special)
4131 ;; (custom-save-delete setter) Done by caller
4132 (let ((standard-output (current-buffer))
4133 (mapper `(lambda (object)
4134 (let ((spec (car-safe (get object (quote ,property)))))
4135 (when (and (not (memq object ignored-special))
4136 (eq (nth 0 spec) 'user)
4137 (eq (nth 1 spec) 'reset))
4138 ;; Do not write reset statements unless necessary.
4139 (unless started-writing
4140 (setq started-writing t)
4144 (princ (quote ,setter))
4148 (prin1 (nth 3 spec))
4150 (mapc mapper special)
4151 (setq ignored-special special)
4153 (when started-writing
4156 (defun custom-save-loaded-themes ()
4157 (let ((themes (reverse (get 'user 'theme-loads-themes)))
4158 (standard-output (current-buffer)))
4160 (unless (bolp) (princ "\n"))
4161 (princ "(custom-load-themes")
4162 (mapc (lambda (theme)
4164 (prin1 theme)) themes)
4168 (defun customize-save-customized ()
4169 "Save all user options which have been set in this session."
4171 (mapatoms (lambda (symbol)
4172 (let ((face (get symbol 'customized-face))
4173 (value (get symbol 'customized-value))
4174 (face-comment (get symbol 'customized-face-comment))
4176 (get symbol 'customized-variable-comment)))
4178 (put symbol 'saved-face face)
4179 (custom-push-theme 'theme-face symbol 'user 'set value)
4180 (put symbol 'customized-face nil))
4182 (put symbol 'saved-value value)
4183 (custom-push-theme 'theme-value symbol 'user 'set value)
4184 (put symbol 'customized-value nil))
4185 (when variable-comment
4186 (put symbol 'saved-variable-comment variable-comment)
4187 (put symbol 'customized-variable-comment nil))
4189 (put symbol 'saved-face-comment face-comment)
4190 (put symbol 'customized-face-comment nil)))))
4191 ;; We really should update all custom buffers here.
4194 ;;; The Customize Menu.
4198 (defcustom custom-menu-nesting 2
4199 "Maximum nesting in custom menus."
4201 :group 'custom-menu)
4203 (defun custom-face-menu-create (widget symbol)
4204 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4205 (vector (custom-unlispify-menu-entry symbol)
4206 `(customize-face ',symbol)
4209 (defun custom-variable-menu-create (widget symbol)
4210 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4211 (let ((type (get symbol 'custom-type)))
4212 (unless (listp type)
4213 (setq type (list type)))
4214 (if (and type (widget-get type :custom-menu))
4215 (widget-apply type :custom-menu symbol)
4216 (vector (custom-unlispify-menu-entry symbol)
4217 `(customize-variable ',symbol)
4220 ;; Add checkboxes to boolean variable entries.
4221 (widget-put (get 'boolean 'widget-type)
4222 :custom-menu (lambda (widget symbol)
4223 (vector (custom-unlispify-menu-entry symbol)
4224 `(customize-variable ',symbol)
4226 ':selected symbol)))
4228 (defun custom-group-menu-create (widget symbol)
4229 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4230 `( ,(custom-unlispify-menu-entry symbol t)
4231 :filter (lambda (&rest junk)
4232 (let ((menu (custom-menu-create ',symbol)))
4233 (if (consp menu) (cdr menu) menu)))))
4236 (defun custom-menu-create (symbol)
4237 "Create menu for customization group SYMBOL.
4238 The menu is in a format applicable to `easy-menu-define'."
4239 (let* ((item (vector (custom-unlispify-menu-entry symbol)
4240 `(customize-group ',symbol)
4242 (if (and (or (not (boundp 'custom-menu-nesting))
4243 (>= custom-menu-nesting 0))
4245 (custom-load-symbol symbol)
4246 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4247 (let ((custom-prefix-list (custom-prefix-add symbol
4248 custom-prefix-list))
4249 (members (custom-sort-items (get symbol 'custom-group)
4250 custom-menu-sort-alphabetically
4251 custom-menu-order-groups)))
4252 `(,(custom-unlispify-menu-entry symbol t)
4255 ,@(mapcar (lambda (entry)
4256 (widget-apply (if (listp (nth 1 entry))
4258 (list (nth 1 entry)))
4259 :custom-menu (nth 0 entry)))
4264 (defun customize-menu-create (symbol &optional name)
4265 "Return a customize menu for customization group SYMBOL.
4266 If optional NAME is given, use that as the name of the menu.
4267 Otherwise the menu will be named `Customize'.
4268 The format is suitable for use with `easy-menu-define'."
4270 (setq name "Customize"))
4272 :filter (lambda (&rest junk)
4273 (let ((menu (custom-menu-create ',symbol)))
4274 (if (consp menu) (cdr menu) menu)))))
4276 ;;; The Custom Mode.
4278 (defvar custom-mode-map
4279 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4280 ;; "\r" bindings from the parent map.
4281 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4282 (let ((map (make-keymap)))
4283 (set-keymap-parent map widget-keymap)
4284 (suppress-keymap map)
4285 (define-key map " " 'scroll-up)
4286 (define-key map "\177" 'scroll-down)
4287 (define-key map "\C-c\C-c" 'Custom-set)
4288 (define-key map "\C-x\C-s" 'Custom-save)
4289 (define-key map "q" 'Custom-buffer-done)
4290 (define-key map "u" 'Custom-goto-parent)
4291 (define-key map "n" 'widget-forward)
4292 (define-key map "p" 'widget-backward)
4293 (define-key map [mouse-1] 'widget-move-and-invoke)
4295 "Keymap for `custom-mode'.")
4297 (easy-menu-define Custom-mode-menu
4299 "Menu used in customization buffers."
4301 ,(customize-menu-create 'customize)
4302 ["Set" Custom-set t]
4303 ["Save" Custom-save t]
4304 ["Reset to Current" Custom-reset-current t]
4305 ["Reset to Saved" Custom-reset-saved t]
4306 ["Reset to Standard Settings" Custom-reset-standard t]
4307 ["Info" (info "(emacs)Easy Customization") t]))
4309 (defun Custom-goto-parent ()
4310 "Go to the parent group listed at the top of this buffer.
4311 If several parents are listed, go to the first of them."
4314 (goto-char (point-min))
4315 (if (search-forward "\nGo to parent group: " nil t)
4316 (let* ((button (get-char-property (point) 'button))
4317 (parent (downcase (widget-get button :tag))))
4318 (customize-group parent)))))
4320 (defcustom custom-mode-hook nil
4321 "Hook called when entering Custom mode."
4323 :group 'custom-buffer )
4325 (defun custom-state-buffer-message (widget)
4326 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4327 (message "To install your edits, invoke [State] and choose the Set operation")))
4329 (defun custom-mode ()
4330 "Major mode for editing customization buffers.
4332 The following commands are available:
4334 Move to next button or editable field. \\[widget-forward]
4335 Move to previous button or editable field. \\[widget-backward]
4336 \\<widget-field-keymap>\
4337 Complete content of editable text field. \\[widget-complete]
4338 \\<custom-mode-map>\
4339 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4340 Invoke button under point. \\[widget-button-press]
4341 Set all modifications. \\[Custom-set]
4342 Make all modifications default. \\[Custom-save]
4343 Reset all modified options. \\[Custom-reset-current]
4344 Reset all modified or set options. \\[Custom-reset-saved]
4345 Reset all options. \\[Custom-reset-standard]
4347 Entry to this mode calls the value of `custom-mode-hook'
4348 if that value is non-nil."
4349 (kill-all-local-variables)
4350 (setq major-mode 'custom-mode
4352 (use-local-map custom-mode-map)
4353 (easy-menu-add Custom-mode-menu)
4354 (make-local-variable 'custom-options)
4355 (make-local-variable 'custom-local-buffer)
4356 (make-local-variable 'widget-documentation-face)
4357 (setq widget-documentation-face 'custom-documentation)
4358 (make-local-variable 'widget-button-face)
4359 (setq widget-button-face custom-button)
4360 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4361 (if custom-raised-buttons
4362 (set (make-local-variable 'widget-mouse-face) custom-button))
4364 ;; When possible, use relief for buttons, not bracketing. This test
4365 ;; may not be optimal.
4366 (when custom-raised-buttons
4367 (set (make-local-variable 'widget-push-button-prefix) "")
4368 (set (make-local-variable 'widget-push-button-suffix) "")
4369 (set (make-local-variable 'widget-link-prefix) "")
4370 (set (make-local-variable 'widget-link-suffix) ""))
4371 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
4372 (run-mode-hooks 'custom-mode-hook))
4374 (put 'custom-mode 'mode-class 'special)
4377 'debug-ignored-errors
4378 "^No user options have changed defaults in recent Emacs versions$")
4384 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4385 ;;; cus-edit.el ends here