1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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 3 of the License, or
15 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file implements the code to create and edit customize buffers.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
35 ;; The identity of a customize option is represented by a Lisp symbol.
36 ;; The following values are associated with an option.
38 ;; 0. The current value.
40 ;; This is the value of the option as seen by "the rest of Emacs".
42 ;; Usually extracted by 'default-value', but can be extracted with
43 ;; different means if the option symbol has the 'custom-get'
44 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; 1. The widget value.
49 ;; This is the value shown in the widget in a customize buffer.
51 ;; 2. The customized value.
53 ;; This is the last value given to the option through customize.
55 ;; It is stored in the 'customized-value' property of the option, in a
56 ;; cons-cell whose car evaluates to the customized value.
58 ;; 3. The saved value.
60 ;; This is last value saved from customize.
62 ;; It is stored in the 'saved-value' property of the option, in a
63 ;; cons-cell whose car evaluates to the saved value.
65 ;; 4. The standard value.
67 ;; This is the value given in the 'defcustom' declaration.
69 ;; It is stored in the 'standard-value' property of the option, in a
70 ;; cons-cell whose car evaluates to the standard value.
72 ;; 5. The "think" value.
74 ;; This is what customize thinks the current value should be.
76 ;; This is the customized value, if any such value exists, otherwise
77 ;; the saved value, if that exists, and as a last resort the standard
80 ;; The reason for storing values unevaluated: This is so you can have
81 ;; values that depend on the environment. For example, you can have a
82 ;; variable that has one value when Emacs is running under a window
83 ;; system, and another value on a tty. Since the evaluation is only done
84 ;; when the variable is first initialized, this is only relevant for the
85 ;; saved (and standard) values, but affect others values for
88 ;; You can see (and modify and save) this unevaluated value by selecting
89 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
90 ;; give you the unevaluated saved value, if any, otherwise the
91 ;; unevaluated standard value.
93 ;; The possible states for a customize widget are:
97 ;; The state has not been determined yet.
101 ;; The widget value is different from the current value.
105 ;; The current value is different from the "think" value.
109 ;; The "think" value is the customized value.
113 ;; The "think" value is the saved value.
117 ;; The "think" value is the standard value.
121 ;; There is no standard value. This means that the variable was
122 ;; not defined with defcustom, nor handled in cus-start.el. Most
123 ;; standard interactive Custom commands do not let you create a
124 ;; Custom buffer containing such variables. However, such Custom
125 ;; buffers can be created, for instance, by calling
126 ;; `customize-apropos' with a prefix arg or by calling
127 ;; `customize-option' non-interactively.
131 ;; There is no widget value.
135 ;; The widget value is not valid member of the :type specified for the
143 (defvar custom-versions-load-alist) ; from cus-load
144 (defvar recentf-exclude) ; from recentf.el
154 (put 'custom-define-hook 'custom-type 'hook)
155 (put 'custom-define-hook 'standard-value '(nil))
156 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link '(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
170 "Abbreviation handling, typing shortcuts, macros."
174 (defgroup matching nil
175 "Various sorts of searching and matching."
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link '(custom-manual "(emacs)Emulation")
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
191 (defgroup external nil
192 "Interfacing to external utilities."
195 (defgroup processes nil
196 "Process, subshell, compilation, and job control support."
200 (defgroup convenience nil
201 "Convenience features for faster editing."
204 (defgroup programming nil
205 "Support for programming in other languages."
208 (defgroup languages nil
209 "Specialized modes for editing programming languages."
213 "Lisp support, including Emacs Lisp."
214 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
219 "Support for the C language and related languages."
220 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
221 :link '(custom-manual "(ccmode)")
229 "Support for object-oriented programming."
232 (defgroup applications nil
233 "Applications written in Emacs."
236 (defgroup calendar nil
237 "Calendar and time management support."
238 :group 'applications)
241 "Modes for electronic-mail handling."
242 :group 'applications)
245 "Support for netnews reading and posting."
246 :link '(custom-manual "(gnus)")
247 :group 'applications)
250 "Games, jokes and amusements."
251 :group 'applications)
253 (defgroup development nil
254 "Support for further development of Emacs."
258 "Support for Emacs documentation."
261 (defgroup extensions nil
262 "Emacs Lisp language extensions."
265 (defgroup internal nil
266 "Code for Emacs internals, build process, defaults."
270 "Maintenance aids for the Emacs development group."
274 (defgroup environment nil
275 "Fitting Emacs with its environment."
279 "Communications, networking, remote access to files."
283 (defgroup hardware nil
284 "Support for interfacing with exotic hardware."
287 (defgroup terminals nil
288 "Support for terminal types."
292 "Front-ends/assistants for, or emulators of, UNIX features."
296 "Support code for vms."
300 "Internationalization and alternate character-set support."
301 :link '(custom-manual "(emacs)International")
306 "The X Window system."
310 "Support for Emacs frames and window systems."
314 "Support editing files of data."
318 "Support editing files."
326 "Code related to the TeX formatter."
327 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
331 "Support for multiple fonts."
334 (defgroup hypermedia nil
335 "Support for links between text or other media types."
339 "Support for on-line help systems."
342 (defgroup multimedia nil
343 "Non-textual support, specifically images and sound."
347 "Code local to your site."
350 (defgroup customize '((widgets custom-group))
351 "Customization of the Customization support."
355 (defgroup custom-faces nil
356 "Faces used by customize."
360 (defgroup custom-browse nil
361 "Control customize browser."
365 (defgroup custom-buffer nil
366 "Control customize buffers."
370 (defgroup custom-menu nil
371 "Control customize menus."
376 "Storage allocation and gc for GNU Emacs Lisp interpreter."
377 :tag "Storage Allocation"
381 "Undoing changes in buffers."
382 :link '(custom-manual "(emacs)Undo")
385 (defgroup mode-line nil
386 "Content of the modeline."
389 (defgroup editing-basics nil
390 "Most basic editing facilities."
393 (defgroup display nil
394 "How characters are displayed in buffers."
397 (defgroup execute nil
398 "Executing external commands."
401 (defgroup installation nil
402 "The Emacs installation."
410 "Internal Emacs limits."
414 "Debugging Emacs itself."
417 (defgroup keyboard nil
418 "Input from the keyboard."
422 "Input from the mouse."
426 "Input from the menus."
430 "Handling data from drag and drop."
433 (defgroup auto-save nil
434 "Preventing accidental loss of data."
437 (defgroup processes-basics nil
438 "Basic stuff dealing with processes."
442 "MULE Emacs internationalization."
445 (defgroup windows nil
446 "Windows within a frame."
447 :link '(custom-manual "(emacs)Windows")
450 ;;; Custom mode keymaps
452 (defvar custom-mode-map
453 ;; This keymap should be dense, but a dense keymap would prevent inheriting
454 ;; "\r" bindings from the parent map.
455 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
456 (let ((map (make-keymap)))
457 (set-keymap-parent map widget-keymap)
458 (define-key map [remap self-insert-command] 'Custom-no-edit)
459 (define-key map "\^m" 'Custom-newline)
460 (define-key map " " 'scroll-up)
461 (define-key map "\177" 'scroll-down)
462 (define-key map "\C-c\C-c" 'Custom-set)
463 (define-key map "\C-x\C-s" 'Custom-save)
464 (define-key map "q" 'Custom-buffer-done)
465 (define-key map "u" 'Custom-goto-parent)
466 (define-key map "n" 'widget-forward)
467 (define-key map "p" 'widget-backward)
469 "Keymap for `Custom-mode'.")
471 (defvar custom-mode-link-map
472 (let ((map (make-keymap)))
473 (set-keymap-parent map custom-mode-map)
474 (define-key map [down-mouse-2] nil)
475 (define-key map [down-mouse-1] 'mouse-drag-region)
476 (define-key map [mouse-2] 'widget-move-and-invoke)
478 "Local keymap for links in `Custom-mode'.")
480 (defvar custom-field-keymap
481 (let ((map (copy-keymap widget-field-keymap)))
482 (define-key map "\C-c\C-c" 'Custom-set)
483 (define-key map "\C-x\C-s" 'Custom-save)
485 "Keymap used inside editable fields in customization buffers.")
487 (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
491 (defun custom-split-regexp-maybe (regexp)
492 "If REGEXP is a string, split it to a list at `\\|'.
493 You can get the original back from the result with:
494 (mapconcat 'identity result \"\\|\")
496 IF REGEXP is not a string, return it unchanged."
498 (split-string regexp "\\\\|")
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
506 (enable-recursive-minibuffers t)
508 (setq val (completing-read
509 (if default (format "Customize variable (default %s): " default)
510 "Customize variable: ")
511 obarray 'custom-variable-p t nil nil default))
512 (list (if (equal val "")
513 (if (symbolp v) v nil)
516 (defun custom-menu-filter (menu widget)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
521 current name action filter)
523 (setq current (car menu)
525 action (nth 1 current)
526 filter (nth 2 current)
528 (if (or (null filter) (funcall filter widget))
529 (push (cons name action) result)
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non-nil."
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
546 :group 'custom-buffer
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries)
552 (symbol-name symbol))
553 ((get symbol 'custom-tag)
555 (get symbol 'custom-tag)
556 (concat (get symbol 'custom-tag) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
560 (princ symbol (current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list)
572 (setq prefix (car prefixes))
573 (if (search-forward prefix (+ (point) (length prefix)) t)
576 (delete-region (point-min) (point)))
577 (setq prefixes (cdr prefixes))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t)
579 (capitalize-region (point-min) (point-max))
581 (goto-char (point-max))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non-nil."
587 :group 'custom-buffer
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
593 (custom-unlispify-menu-entry symbol t)))
595 (defun custom-prefix-add (symbol prefixes)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol 'custom-prefix)
598 (concat (symbol-name symbol) "-"))
603 (defcustom custom-guess-name-alist
609 ("-function\\'" function)
610 ("-functions\\'" (repeat function))
611 ("-list\\'" (repeat sexp))
612 ("-alist\\'" (repeat (cons sexp sexp))))
613 "Alist of (MATCH TYPE).
615 MATCH should be a regexp matching the name of a symbol, and TYPE should
616 be a widget suitable for editing the value of that symbol. The TYPE
617 of the first entry where MATCH matches the name of the symbol will be
620 This is used for guessing the type of variables not declared with
622 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
623 :group 'custom-buffer)
625 (defcustom custom-guess-doc-alist
626 '(("\\`\\*?Non-nil " boolean))
627 "Alist of (MATCH TYPE).
629 MATCH should be a regexp matching a documentation string, and TYPE
630 should be a widget suitable for editing the value of a variable with
631 that documentation string. The TYPE of the first entry where MATCH
632 matches the name of the symbol will be used.
634 This is used for guessing the type of variables not declared with
636 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
637 :group 'custom-buffer)
639 (defun custom-guess-type (symbol)
640 "Guess a widget suitable for editing the value of SYMBOL.
641 This is done by matching SYMBOL with `custom-guess-name-alist' and
642 if that fails, the doc string with `custom-guess-doc-alist'."
643 (let ((name (symbol-name symbol))
644 (names custom-guess-name-alist)
647 (setq current (car names)
649 (when (string-match (nth 0 current) name)
650 (setq found (nth 1 current)
653 (let ((doc (documentation-property symbol 'variable-documentation))
654 (docs custom-guess-doc-alist))
657 (setq current (car docs)
659 (when (string-match (nth 0 current) doc)
660 (setq found (nth 1 current)
667 (defcustom custom-browse-sort-alphabetically nil
668 "If non-nil, sort customization group alphabetically in `custom-browse'."
670 :group 'custom-browse)
672 (defcustom custom-browse-order-groups nil
673 "If non-nil, order group members within each customization group.
674 If `first', order groups before non-groups.
675 If `last', order groups after non-groups."
676 :type '(choice (const first)
678 (const :tag "none" nil))
679 :group 'custom-browse)
681 (defcustom custom-browse-only-groups nil
682 "If non-nil, show group members only within each customization group."
684 :group 'custom-browse)
687 (defcustom custom-buffer-sort-alphabetically nil
688 "If non-nil, sort each customization group alphabetically in Custom buffer."
690 :group 'custom-buffer)
692 (defcustom custom-buffer-order-groups 'last
693 "If non-nil, order group members within each customization group.
694 If `first', order groups before non-groups.
695 If `last', order groups after non-groups."
696 :type '(choice (const first)
698 (const :tag "none" nil))
699 :group 'custom-buffer)
702 (defcustom custom-menu-sort-alphabetically nil
703 "If non-nil, sort each customization group alphabetically in menus."
707 (defcustom custom-menu-order-groups 'first
708 "If non-nil, order group members within each customization group.
709 If `first', order groups before non-groups.
710 If `last', order groups after non-groups."
711 :type '(choice (const first)
713 (const :tag "none" nil))
716 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
718 (defun custom-sort-items (items sort-alphabetically order-groups)
719 "Return a sorted copy of ITEMS.
720 ITEMS should be a `custom-group' property.
721 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
722 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
723 groups after non-groups, if nil do not order groups at all."
724 (sort (copy-sequence items)
726 (let ((typea (nth 1 a)) (typeb (nth 1 b))
727 (namea (nth 0 a)) (nameb (nth 0 b)))
728 (cond ((not order-groups)
729 ;; Since we don't care about A and B order, maybe sort.
730 (when sort-alphabetically
731 (string-lessp namea nameb)))
732 ((eq typea 'custom-group)
733 ;; If B is also a group, maybe sort. Otherwise, order A and B.
734 (if (eq typeb 'custom-group)
735 (when sort-alphabetically
736 (string-lessp namea nameb))
737 (eq order-groups 'first)))
738 ((eq typeb 'custom-group)
739 ;; Since A cannot be a group, order A and B.
740 (eq order-groups 'last))
742 ;; Since A and B cannot be groups, sort.
743 (string-lessp namea nameb)))))))
745 ;;; Custom Mode Commands.
747 ;; This variable is used by `custom-tool-bar-map', or directly by
748 ;; `custom-buffer-create-internal' if the toolbar is not present and
749 ;; `custom-buffer-verbose-help' is non-nil.
751 (defvar custom-commands
752 '(("Set for current session" Custom-set t
753 "Apply all settings in this buffer to the current session"
755 ("Save for future sessions" Custom-save
756 (or custom-file user-init-file)
757 "Apply all settings in this buffer and save them for future Emacs sessions."
759 ("Undo edits" Custom-reset-current t
760 "Restore all settings in this buffer to reflect their current values."
762 ("Reset to saved" Custom-reset-saved t
763 "Restore all settings in this buffer to their saved values (if any)."
765 ("Erase customizations" Custom-reset-standard
766 (or custom-file user-init-file)
767 "Un-customize all settings in this buffer and save them with standard values."
769 ("Help for Customize" Custom-help t
770 "Get help for using Customize."
772 ("Exit" Custom-buffer-done t "Exit Customize." "exit")))
774 (defun Custom-help ()
775 "Read the node on Easy Customization in the Emacs manual."
777 (info "(emacs)Easy Customization"))
779 (defvar custom-reset-menu
780 '(("Undo Edits" . Custom-reset-current)
781 ("Reset to Saved" . Custom-reset-saved)
782 ("Erase Customizations (use standard values)" . Custom-reset-standard))
783 "Alist of actions for the `Reset' button.
784 The key is a string containing the name of the action, the value is a
785 Lisp function taking the widget as an element which will be called
786 when the action is chosen.")
788 (defvar custom-options nil
789 "Customization widgets in the current buffer.")
791 (defun custom-command-apply (fun query &optional strong-query)
792 "Call function FUN on all widgets in `custom-options'.
793 If there is more than one widget, ask user for confirmation using
794 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
795 and `yes-or-no-p' otherwise."
796 (if (or (and (= 1 (length custom-options))
797 (memq (widget-type (car custom-options))
798 '(custom-variable custom-face)))
799 (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query))
800 (progn (mapc fun custom-options) t)
804 (defun Custom-set (&rest ignore)
805 "Set the current value of all edited settings in the buffer."
807 (custom-command-apply
809 (when (eq (widget-get child :custom-state) 'modified)
810 (widget-apply child :custom-set)))
811 "Set all values according to this buffer? "))
813 (defun Custom-save (&rest ignore)
814 "Set all edited settings, then save all settings that have been set.
815 If a setting was edited and set before, this saves it. If a
816 setting was merely edited before, this sets it then saves it."
818 (when (custom-command-apply
820 (when (memq (widget-get child :custom-state)
821 '(modified set changed rogue))
822 (widget-apply child :custom-mark-to-save)))
823 "Save all settings in this buffer? " t)
824 ;; Save changes to buffer and redraw.
826 (dolist (child custom-options)
827 (widget-apply child :custom-state-set-and-redraw))))
829 (defun custom-reset (widget &optional event)
830 "Select item from reset menu."
831 (let* ((completion-ignore-case t)
832 (answer (widget-choose "Reset settings"
838 (defun Custom-reset-current (&rest ignore)
839 "Reset all edited settings in the buffer to show their current values."
841 (custom-command-apply
843 (if (memq (widget-get widget :custom-state) '(modified changed))
844 (widget-apply widget :custom-reset-current)))
845 "Reset all settings' buffer text to show current values? "))
847 (defun Custom-reset-saved (&rest ignore)
848 "Reset all edited or set settings in the buffer to their saved value.
849 This also shows the saved values in the buffer."
851 (custom-command-apply
853 (if (memq (widget-get widget :custom-state) '(modified set changed rogue))
854 (widget-apply widget :custom-reset-saved)))
855 "Reset all settings (current values and buffer text) to saved values? "))
857 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
858 ;; and `custom-group-reset-standard'. If these variables are nil, both
859 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
860 ;; save, reset and redraw the handled widget immediately. Otherwise,
861 ;; they add the widget to the corresponding list and leave it to
862 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
863 (defvar custom-reset-standard-variables-list nil)
864 (defvar custom-reset-standard-faces-list nil)
866 ;; The next function was excerpted from `custom-variable-reset-standard'
867 ;; and `custom-face-reset-standard' and is used to avoid calling
868 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
869 ;; one) when erasing all customizations.
870 (defun custom-reset-standard-save-and-update ()
871 "Save settings and redraw after erasing customizations."
872 (when (or (and custom-reset-standard-variables-list
873 (not (eq custom-reset-standard-variables-list '(t))))
874 (and custom-reset-standard-faces-list
875 (not (eq custom-reset-standard-faces-list '(t)))))
876 ;; Save settings to file.
878 ;; Set state of and redraw variables.
879 (dolist (widget custom-reset-standard-variables-list)
880 (unless (eq widget t)
881 (widget-put widget :custom-state 'unknown)
882 (custom-redraw widget)))
883 ;; Set state of and redraw faces.
884 (dolist (widget custom-reset-standard-faces-list)
885 (unless (eq widget t)
886 (let* ((symbol (widget-value widget))
887 (child (car (widget-get widget :children)))
888 (value (get symbol 'face-defface-spec))
889 (comment-widget (widget-get widget :comment-widget)))
890 (put symbol 'face-comment nil)
891 (widget-value-set child
892 (custom-pre-filter-face-spec
893 (list (list t (custom-face-attributes-get
895 ;; This call manages the comment visibility
896 (widget-value-set comment-widget "")
897 (custom-face-state-set widget)
898 (custom-redraw-magic widget))))))
900 (defun Custom-reset-standard (&rest ignore)
901 "Erase all customizations (either current or saved) in current buffer.
902 The immediate result is to restore them to their standard values.
903 This operation eliminates any saved values for the group members,
904 making them as if they had never been customized at all."
906 ;; Bind these temporarily.
907 (let ((custom-reset-standard-variables-list '(t))
908 (custom-reset-standard-faces-list '(t)))
909 (custom-command-apply
911 (and (or (null (widget-get widget :custom-standard-value))
912 (widget-apply widget :custom-standard-value))
913 (memq (widget-get widget :custom-state)
914 '(modified set changed saved rogue))
915 (widget-apply widget :custom-mark-to-reset-standard)))
916 "Erase all customizations for settings in this buffer? " t)
917 (custom-reset-standard-save-and-update)))
919 ;;; The Customize Commands
921 (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
922 "Prompt for a variable and a value and return them as a list.
923 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
924 prompt for the value. The %s escape in PROMPT-VAL is replaced with
925 the name of the variable.
927 If the variable has a `variable-interactive' property, that is used as if
928 it were the arg to `interactive' (which see) to interactively read the value.
930 If the variable has a `custom-type' property, it must be a widget and the
931 `:prompt-value' property of that widget will be used for reading the value.
933 If optional COMMENT argument is non-nil, also prompt for a comment and return
934 it as the third element in the list."
935 (let* ((var (read-variable prompt-var))
936 (minibuffer-help-form '(describe-variable var))
938 (let ((prop (get var 'variable-interactive))
939 (type (get var 'custom-type))
940 (prompt (format prompt-val var)))
942 (setq type (list type)))
944 ;; Use VAR's `variable-interactive' property
945 ;; as an interactive spec for prompting.
946 (call-interactively `(lambda (arg)
950 (widget-prompt-value type
956 (eval-minibuffer prompt))))))
959 (read-string "Comment: " (get var 'variable-comment)))
963 (defun customize-set-value (variable value &optional comment)
964 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
966 If VARIABLE has a `variable-interactive' property, that is used as if
967 it were the arg to `interactive' (which see) to interactively read the value.
969 If VARIABLE has a `custom-type' property, it must be a widget and the
970 `:prompt-value' property of that widget will be used for reading the value.
972 If given a prefix (or a COMMENT argument), also prompt for a comment."
973 (interactive (custom-prompt-variable "Set variable: "
977 (cond ((string= comment "")
978 (put variable 'variable-comment nil))
980 (put variable 'variable-comment comment)))
981 (set variable value))
984 (defun customize-set-variable (variable value &optional comment)
985 "Set the default for VARIABLE to VALUE, and return VALUE.
986 VALUE is a Lisp object.
988 If VARIABLE has a `custom-set' property, that is used for setting
989 VARIABLE, otherwise `set-default' is used.
991 If VARIABLE has a `variable-interactive' property, that is used as if
992 it were the arg to `interactive' (which see) to interactively read the value.
994 If VARIABLE has a `custom-type' property, it must be a widget and the
995 `:prompt-value' property of that widget will be used for reading the value.
997 If given a prefix (or a COMMENT argument), also prompt for a comment."
998 (interactive (custom-prompt-variable "Set variable: "
999 "Set customized value for %s to: "
1000 current-prefix-arg))
1001 (custom-load-symbol variable)
1002 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
1003 (funcall (or (get variable 'custom-set) 'set-default) variable value)
1004 (put variable 'customized-value (list (custom-quote value)))
1005 (cond ((string= comment "")
1006 (put variable 'variable-comment nil)
1007 (put variable 'customized-variable-comment nil))
1009 (put variable 'variable-comment comment)
1010 (put variable 'customized-variable-comment comment)))
1014 (defun customize-save-variable (variable value &optional comment)
1015 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1018 If VARIABLE has a `custom-set' property, that is used for setting
1019 VARIABLE, otherwise `set-default' is used.
1021 If VARIABLE has a `variable-interactive' property, that is used as if
1022 it were the arg to `interactive' (which see) to interactively read the value.
1024 If VARIABLE has a `custom-type' property, it must be a widget and the
1025 `:prompt-value' property of that widget will be used for reading the value.
1027 If given a prefix (or a COMMENT argument), also prompt for a comment."
1028 (interactive (custom-prompt-variable "Set and save variable: "
1029 "Set and save value for %s as: "
1030 current-prefix-arg))
1031 (funcall (or (get variable 'custom-set) 'set-default) variable value)
1032 (put variable 'saved-value (list (custom-quote value)))
1033 (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
1034 (cond ((string= comment "")
1035 (put variable 'variable-comment nil)
1036 (put variable 'saved-variable-comment nil))
1038 (put variable 'variable-comment comment)
1039 (put variable 'saved-variable-comment comment)))
1040 (put variable 'customized-value nil)
1041 (put variable 'customized-variable-comment nil)
1047 "Select a customization buffer which you can use to set user options.
1048 User options are structured into \"groups\".
1049 Initially the top-level group `Emacs' and its immediate subgroups
1050 are shown; the contents of those subgroups are initially hidden."
1052 (customize-group 'emacs))
1055 (defun customize-mode (mode)
1056 "Customize options related to the current major mode.
1057 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1058 then prompt for the MODE to customize."
1061 (let ((completion-regexp-list '("-mode\\'"))
1062 (group (custom-group-of-mode major-mode)))
1063 (if (and group (not current-prefix-arg))
1066 (completing-read (if group
1067 (format "Major mode (default %s): " major-mode)
1070 'custom-group-of-mode
1071 t nil nil (if group (symbol-name major-mode))))))))
1072 (customize-group (custom-group-of-mode mode)))
1074 (defun customize-read-group ()
1075 (let ((completion-ignore-case t))
1076 (completing-read "Customize group (default emacs): "
1079 (or (and (get symbol 'custom-loads)
1080 (not (get symbol 'custom-autoload)))
1081 (get symbol 'custom-group)))
1085 (defun customize-group (&optional group)
1086 "Customize GROUP, which must be a customization group."
1087 (interactive (list (customize-read-group)))
1088 (when (stringp group)
1089 (if (string-equal "" group)
1091 (setq group (intern group))))
1092 (let ((name (format "*Customize Group: %s*"
1093 (custom-unlispify-tag-name group))))
1094 (if (get-buffer name)
1095 (pop-to-buffer name)
1096 (custom-buffer-create
1097 (list (list group 'custom-group))
1099 (concat " for group "
1100 (custom-unlispify-tag-name group))))))
1103 (defun customize-group-other-window (&optional group)
1104 "Customize GROUP, which must be a customization group, in another window."
1105 (interactive (list (customize-read-group)))
1106 (let ((pop-up-windows t)
1107 (same-window-buffer-names nil)
1108 (same-window-regexps nil))
1109 (customize-group group)))
1112 (defalias 'customize-variable 'customize-option)
1115 (defun customize-option (symbol)
1116 "Customize SYMBOL, which must be a user option variable."
1117 (interactive (custom-variable-prompt))
1119 (error "No variable specified"))
1120 (let ((basevar (indirect-variable symbol)))
1121 (custom-buffer-create (list (list basevar 'custom-variable))
1122 (format "*Customize Option: %s*"
1123 (custom-unlispify-tag-name basevar)))
1124 (unless (eq symbol basevar)
1125 (message "`%s' is an alias for `%s'" symbol basevar))))
1128 (defalias 'customize-variable-other-window 'customize-option-other-window)
1131 (defun customize-option-other-window (symbol)
1132 "Customize SYMBOL, which must be a user option variable.
1133 Show the buffer in another window, but don't select it."
1134 (interactive (custom-variable-prompt))
1136 (error "No variable specified"))
1137 (let ((basevar (indirect-variable symbol)))
1138 (custom-buffer-create-other-window
1139 (list (list basevar 'custom-variable))
1140 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
1141 (unless (eq symbol basevar)
1142 (message "`%s' is an alias for `%s'" symbol basevar))))
1144 (defvar customize-changed-options-previous-release "21.1"
1145 "Version for `customize-changed-options' to refer back to by default.")
1147 ;; Packages will update this variable, so make it available.
1149 (defvar customize-package-emacs-version-alist nil
1150 "Alist mapping versions of a package to Emacs versions.
1151 We use this for packages that have their own names, but are released
1152 as part of Emacs itself.
1154 Each elements looks like this:
1156 (PACKAGE (PVERSION . EVERSION)...)
1158 Here PACKAGE is the name of a package, as a symbol. After
1159 PACKAGE come one or more elements, each associating a
1160 package version PVERSION with the first Emacs version
1161 EVERSION in which it (or a subsequent version of PACKAGE)
1162 was first released. Both PVERSION and EVERSION are strings.
1163 PVERSION should be a string that this package used in
1164 the :package-version keyword for `defcustom', `defgroup',
1167 For example, the MH-E package updates this alist as follows:
1169 (add-to-list 'customize-package-emacs-version-alist
1170 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1171 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1172 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1173 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1175 The value of PACKAGE needs to be unique and it needs to match the
1176 PACKAGE value appearing in the :package-version keyword. Since
1177 the user might see the value in a error message, a good choice is
1178 the official name of the package, such as MH-E or Gnus.")
1181 (defalias 'customize-changed 'customize-changed-options)
1184 (defun customize-changed-options (&optional since-version)
1185 "Customize all settings whose meanings have changed in Emacs itself.
1186 This includes new user option variables and faces, and new
1187 customization groups, as well as older options and faces whose meanings
1188 or default values have changed since the previous major Emacs release.
1190 With argument SINCE-VERSION (a string), customize all settings
1191 that were added or redefined since that version."
1195 (read-from-minibuffer
1196 (format "Customize options changed, since version (default %s): "
1197 customize-changed-options-previous-release))))
1198 (if (equal since-version "")
1199 (setq since-version nil)
1200 (unless (condition-case nil
1201 (numberp (read since-version))
1203 (signal 'wrong-type-argument (list 'numberp since-version))))
1204 (unless since-version
1205 (setq since-version customize-changed-options-previous-release))
1207 ;; Load the information for versions since since-version. We use
1208 ;; custom-load-symbol for this.
1209 (put 'custom-versions-load-alist 'custom-loads nil)
1210 (dolist (elt custom-versions-load-alist)
1211 (if (customize-version-lessp since-version (car elt))
1212 (dolist (load (cdr elt))
1213 (custom-add-load 'custom-versions-load-alist load))))
1214 (custom-load-symbol 'custom-versions-load-alist)
1215 (put 'custom-versions-load-alist 'custom-loads nil)
1220 (let* ((package-version (get symbol 'custom-package-version))
1222 (or (and package-version
1223 (customize-package-emacs-version symbol
1225 (get symbol 'custom-version))))
1227 (when (customize-version-lessp since-version version)
1228 (if (or (get symbol 'custom-group)
1229 (get symbol 'group-documentation))
1230 (push (list symbol 'custom-group) found))
1231 (if (custom-variable-p symbol)
1232 (push (list symbol 'custom-variable) found))
1233 (if (custom-facep symbol)
1234 (push (list symbol 'custom-face) found)))))))
1236 (custom-buffer-create (custom-sort-items found t 'first)
1237 "*Customize Changed Options*")
1238 (error "No user option defaults have been changed since Emacs %s"
1241 (defun customize-package-emacs-version (symbol package-version)
1242 "Return the Emacs version in which SYMBOL's meaning last changed.
1243 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1244 `customize-package-emacs-version-alist' to find the version of
1245 Emacs that is associated with version VERSION of PACKAGE."
1246 (let (package-versions emacs-version)
1247 ;; Use message instead of error since we want user to be able to
1248 ;; see the rest of the symbols even if a package author has
1249 ;; botched things up.
1250 (cond ((not (listp package-version))
1251 (message "Invalid package-version value for %s" symbol))
1252 ((setq package-versions (assq (car package-version)
1253 customize-package-emacs-version-alist))
1255 (cdr (assoc (cdr package-version) package-versions)))
1256 (unless emacs-version
1257 (message "%s version %s not found in %s" symbol
1258 (cdr package-version)
1259 "customize-package-emacs-version-alist")))
1261 (message "Package %s version %s lists no corresponding Emacs version"
1262 (car package-version)
1263 (cdr package-version))))
1266 (defun customize-version-lessp (version1 version2)
1267 ;; Why are the versions strings, and given that they are, why aren't
1268 ;; they converted to numbers and compared as such here? -- fx
1270 ;; In case someone made a mistake and left out the quotes
1271 ;; in the :version value.
1272 (if (numberp version2)
1273 (setq version2 (prin1-to-string version2)))
1274 (let (major1 major2 minor1 minor2)
1275 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
1276 (setq major1 (read (or (match-string 1 version1)
1278 (setq minor1 (read (or (match-string 3 version1)
1280 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
1281 (setq major2 (read (or (match-string 1 version2)
1283 (setq minor2 (read (or (match-string 3 version2)
1285 (or (< major1 major2)
1286 (and (= major1 major2)
1287 (< minor1 minor2)))))
1290 (defun customize-face (&optional face)
1291 "Customize FACE, which should be a face name or nil.
1292 If FACE is nil, customize all faces. If FACE is actually a
1293 face-alias, customize the face it is aliased to.
1295 Interactively, when point is on text which has a face specified,
1296 suggest to customize that face, if it's customizable."
1297 (interactive (list (read-face-name "Customize face" "all faces" t)))
1298 (if (member face '(nil ""))
1299 (setq face (face-list)))
1300 (if (and (listp face) (null (cdr face)))
1301 (setq face (car face)))
1303 (custom-buffer-create
1305 (mapcar (lambda (s) (list s 'custom-face)) face)
1307 "*Customize Faces*")
1308 ;; If FACE is actually an alias, customize the face it is aliased to.
1309 (if (get face 'face-alias)
1310 (setq face (get face 'face-alias)))
1311 (unless (facep face)
1312 (error "Invalid face %S" face))
1313 (custom-buffer-create
1314 (list (list face 'custom-face))
1315 (format "*Customize Face: %s*"
1316 (custom-unlispify-tag-name face)))))
1319 (defun customize-face-other-window (&optional face)
1320 "Show customization buffer for face FACE in other window.
1321 If FACE is actually a face-alias, customize the face it is aliased to.
1323 Interactively, when point is on text which has a face specified,
1324 suggest to customize that face, if it's customizable."
1325 (interactive (list (read-face-name "Customize face" "all faces" t)))
1326 (let ((pop-up-windows t)
1327 (same-window-buffer-names nil)
1328 (same-window-regexps nil))
1329 (customize-face face)))
1331 (defalias 'customize-customized 'customize-unsaved)
1334 (defun customize-unsaved ()
1335 "Customize all user options set in this session but not saved."
1338 (mapatoms (lambda (symbol)
1339 (and (or (get symbol 'customized-face)
1340 (get symbol 'customized-face-comment))
1341 (custom-facep symbol)
1342 (push (list symbol 'custom-face) found))
1343 (and (or (get symbol 'customized-value)
1344 (get symbol 'customized-variable-comment))
1346 (push (list symbol 'custom-variable) found))))
1348 (error "No user options are set but unsaved")
1349 (custom-buffer-create (custom-sort-items found t nil)
1350 "*Customize Unsaved*"))))
1353 (defun customize-rogue ()
1354 "Customize all user variables modified outside customize."
1357 (mapatoms (lambda (symbol)
1358 (let ((cval (or (get symbol 'customized-value)
1359 (get symbol 'saved-value)
1360 (get symbol 'standard-value))))
1361 (when (and cval ;Declared with defcustom.
1362 (default-boundp symbol) ;Has a value.
1363 (not (equal (eval (car cval))
1364 ;; Which does not match customize.
1365 (default-value symbol))))
1366 (push (list symbol 'custom-variable) found)))))
1368 (error "No rogue user options")
1369 (custom-buffer-create (custom-sort-items found t nil)
1370 "*Customize Rogue*"))))
1372 (defun customize-saved ()
1373 "Customize all already saved user options."
1376 (mapatoms (lambda (symbol)
1377 (and (or (get symbol 'saved-face)
1378 (get symbol 'saved-face-comment))
1379 (custom-facep symbol)
1380 (push (list symbol 'custom-face) found))
1381 (and (or (get symbol 'saved-value)
1382 (get symbol 'saved-variable-comment))
1384 (push (list symbol 'custom-variable) found))))
1386 (error "No saved user options")
1387 (custom-buffer-create (custom-sort-items found t nil)
1388 "*Customize Saved*"))))
1391 (defun customize-apropos (regexp &optional all)
1392 "Customize all loaded options, faces and groups matching REGEXP.
1393 If ALL is `options', include only options.
1394 If ALL is `faces', include only faces.
1395 If ALL is `groups', include only groups.
1396 If ALL is t (interactively, with prefix arg), include variables
1397 that are not customizable options, as well as faces and groups
1398 \(but we recommend using `apropos-variable' instead)."
1399 (interactive "sCustomize (regexp): \nP")
1401 (mapatoms (lambda (symbol)
1402 (when (string-match regexp (symbol-name symbol))
1403 (when (and (not (memq all '(faces options)))
1404 (get symbol 'custom-group))
1405 (push (list symbol 'custom-group) found))
1406 (when (and (not (memq all '(options groups)))
1407 (custom-facep symbol))
1408 (push (list symbol 'custom-face) found))
1409 (when (and (not (memq all '(groups faces)))
1411 (eq (indirect-variable symbol) symbol)
1412 (or (get symbol 'saved-value)
1413 (custom-variable-p symbol)
1414 (and (not (memq all '(nil options)))
1415 (get symbol 'variable-documentation))))
1416 (push (list symbol 'custom-variable) found)))))
1418 (error "No %s matching %s"
1421 (format "customizable %s"
1422 (if (memq all '(options faces groups))
1426 (custom-buffer-create
1427 (custom-sort-items found t custom-buffer-order-groups)
1428 "*Customize Apropos*"))))
1431 (defun customize-apropos-options (regexp &optional arg)
1432 "Customize all loaded customizable options matching REGEXP.
1433 With prefix arg, include variables that are not customizable options
1434 \(but it is better to use `apropos-variable' if you want to find those)."
1435 (interactive "sCustomize options (regexp): \nP")
1436 (customize-apropos regexp (or arg 'options)))
1439 (defun customize-apropos-faces (regexp)
1440 "Customize all loaded faces matching REGEXP."
1441 (interactive "sCustomize faces (regexp): \n")
1442 (customize-apropos regexp 'faces))
1445 (defun customize-apropos-groups (regexp)
1446 "Customize all loaded groups matching REGEXP."
1447 (interactive "sCustomize groups (regexp): \n")
1448 (customize-apropos regexp 'groups))
1452 (defcustom custom-buffer-style 'links
1453 "Control the presentation style for customization buffers.
1454 The value should be a symbol, one of:
1456 brackets: groups nest within each other with big horizontal brackets.
1457 links: groups have links to subgroups."
1458 :type '(radio (const brackets)
1460 :group 'custom-buffer)
1462 (defcustom custom-buffer-done-kill nil
1463 "*Non-nil means exiting a Custom buffer should kill it."
1466 :group 'custom-buffer)
1468 (defcustom custom-buffer-indent 3
1469 "Number of spaces to indent nested groups."
1471 :group 'custom-buffer)
1473 (defun custom-get-fresh-buffer (name)
1474 "Get a fresh new buffer with name NAME.
1475 If the buffer already exist, clean it up to be like new.
1476 Beware: it's not quite like new. Good enough for custom, but maybe
1478 ;; To be more complete, we should also kill all permanent-local variables,
1479 ;; but it's not needed for custom.
1480 (let ((buf (get-buffer name)))
1481 (when (and buf (buffer-local-value 'buffer-file-name buf))
1482 ;; This will check if the file is not saved.
1486 (get-buffer-create name)
1487 (with-current-buffer buf
1488 (kill-all-local-variables)
1489 (run-hooks 'kill-buffer-hook)
1490 ;; Delete overlays before erasing the buffer so the overlay hooks
1491 ;; don't get run spuriously when we erase the buffer.
1492 (let ((ols (overlay-lists)))
1493 (dolist (ol (nconc (car ols) (cdr ols)))
1494 (delete-overlay ol)))
1499 (defun custom-buffer-create (options &optional name description)
1500 "Create a buffer containing OPTIONS.
1501 Optional NAME is the name of the buffer.
1502 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1503 SYMBOL is a customization option, and WIDGET is a widget for editing
1505 (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*")))
1506 (custom-buffer-create-internal options description))
1509 (defun custom-buffer-create-other-window (options &optional name description)
1510 "Create a buffer containing OPTIONS, and display it in another window.
1511 The result includes selecting that window.
1512 Optional NAME is the name of the buffer.
1513 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1514 SYMBOL is a customization option, and WIDGET is a widget for editing
1516 (unless name (setq name "*Customization*"))
1517 (let ((pop-up-windows t)
1518 (same-window-buffer-names nil)
1519 (same-window-regexps nil))
1520 (pop-to-buffer (custom-get-fresh-buffer name))
1521 (custom-buffer-create-internal options description)))
1523 (defcustom custom-reset-button-menu nil
1524 "If non-nil, only show a single reset button in customize buffers.
1525 This button will have a menu with all three reset operations."
1527 :group 'custom-buffer)
1529 (defcustom custom-buffer-verbose-help t
1530 "If non-nil, include explanatory text in the customization buffer."
1532 :group 'custom-buffer)
1534 (defun Custom-buffer-done (&rest ignore)
1535 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1537 (quit-window custom-buffer-done-kill))
1539 (defvar custom-button nil
1540 "Face used for buttons in customization buffers.")
1542 (defvar custom-button-mouse nil
1543 "Mouse face used for buttons in customization buffers.")
1545 (defvar custom-button-pressed nil
1546 "Face used for pressed buttons in customization buffers.")
1548 (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
1549 '(("unspecified" . unspecified))))
1550 "If non-nil, indicate active buttons in a `raised-button' style.
1551 Otherwise use brackets."
1554 :group 'custom-buffer
1555 :set (lambda (variable value)
1556 (custom-set-default variable value)
1558 (if value 'custom-button 'custom-button-unraised))
1559 (setq custom-button-mouse
1560 (if value 'custom-button-mouse 'highlight))
1561 (setq custom-button-pressed
1563 'custom-button-pressed
1564 'custom-button-pressed-unraised))))
1566 (defun custom-buffer-create-internal (options &optional description)
1568 (let ((init-file (or custom-file user-init-file)))
1569 ;; Insert verbose help at the top of the custom buffer.
1570 (when custom-buffer-verbose-help
1571 (widget-insert "Editing a setting changes only the text in this buffer."
1574 To apply your changes, use the Save or Set buttons.
1575 Saving a change normally works by editing your init file."
1577 Currently, these settings cannot be saved for future Emacs sessions,
1578 possibly because you started Emacs with `-q'.")
1579 "\nFor details, see ")
1580 (widget-create 'custom-manual
1581 :tag "Saving Customizations"
1582 "(emacs)Saving Customizations")
1583 (widget-insert " in the ")
1584 (widget-create 'custom-manual
1586 :help-echo "Read the Emacs manual."
1588 (widget-insert "."))
1589 ;; Insert custom command buttons if the toolbar is not in use.
1591 (widget-insert "\n")
1592 ;; tool-bar is not dumped in builds without x.
1593 (when (not (and (bound-and-true-p tool-bar-mode) (display-graphic-p)))
1594 (if custom-buffer-verbose-help
1596 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1597 (let ((button (lambda (tag action active help icon)
1600 (widget-create 'push-button :tag tag
1601 :help-echo help :action action))))
1602 (commands custom-commands))
1603 (apply button (pop commands)) ; Set for current session
1604 (apply button (pop commands)) ; Save for future sessions
1605 (if custom-reset-button-menu
1608 (widget-create 'push-button
1610 :help-echo "Show a menu with reset operations."
1611 :mouse-down-action 'ignore
1612 :action 'custom-reset))
1613 (widget-insert "\n")
1614 (apply button (pop commands)) ; Undo edits
1615 (apply button (pop commands)) ; Reset to saved
1616 (apply button (pop commands)) ; Erase customization
1618 (pop commands) ; Help (omitted)
1619 (apply button (pop commands))))) ; Exit
1620 (widget-insert "\n\n"))
1622 ;; Now populate the custom buffer.
1623 (message "Creating customization items...")
1624 (buffer-disable-undo)
1625 (setq custom-options
1626 (if (= (length options) 1)
1627 (mapcar (lambda (entry)
1628 (widget-create (nth 1 entry)
1629 :documentation-shown t
1630 :custom-state 'unknown
1631 :tag (custom-unlispify-tag-name
1633 :value (nth 0 entry)))
1636 (length (length options)))
1637 (mapcar (lambda (entry)
1639 (message "Creating customization items ...%2d%%"
1640 (/ (* 100.0 count) length))
1641 (widget-create (nth 1 entry)
1642 :tag (custom-unlispify-tag-name
1644 :value (nth 0 entry))
1645 (setq count (1+ count))
1646 (unless (eq (preceding-char) ?\n)
1647 (widget-insert "\n"))
1648 (widget-insert "\n")))
1650 (unless (eq (preceding-char) ?\n)
1651 (widget-insert "\n"))
1652 (message "Creating customization items ...done")
1653 (message "Resetting customization items...")
1654 (unless (eq custom-buffer-style 'tree)
1655 (mapc 'custom-magic-reset custom-options))
1656 (message "Resetting customization items...done")
1657 (message "Creating customization setup...")
1659 (buffer-enable-undo)
1660 (goto-char (point-min))
1661 (message "Creating customization setup...done"))
1663 ;;; The Tree Browser.
1666 (defun customize-browse (&optional group)
1667 "Create a tree browser for the customize hierarchy."
1670 (setq group 'emacs))
1671 (let ((name "*Customize Browser*"))
1672 (pop-to-buffer (custom-get-fresh-buffer name)))
1674 (widget-insert (format "\
1675 %s buttons; type RET or click mouse-1
1676 on a button to invoke its action.
1677 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1678 (if custom-raised-buttons
1679 "`Raised' text indicates"
1680 "Square brackets indicate")))
1683 (if custom-browse-only-groups
1685 Invoke the [Group] button below to edit that item in another window.\n\n")
1686 (widget-insert "Invoke the ")
1687 (widget-create 'item
1690 :tag-glyph "folder")
1691 (widget-insert ", ")
1692 (widget-create 'item
1696 (widget-insert ", and ")
1697 (widget-create 'item
1700 :tag-glyph "option")
1701 (widget-insert " buttons below to edit that
1702 item in another window.\n\n"))
1703 (let ((custom-buffer-style 'tree))
1704 (widget-create 'custom-group
1706 :custom-state 'unknown
1707 :tag (custom-unlispify-tag-name group)
1710 (goto-char (point-min)))
1712 (define-widget 'custom-browse-visibility 'item
1713 "Control visibility of items in the customize tree browser."
1715 :action 'custom-browse-visibility-action)
1717 (defun custom-browse-visibility-action (widget &rest ignore)
1718 (let ((custom-buffer-style 'tree))
1719 (custom-toggle-parent widget)))
1721 (define-widget 'custom-browse-group-tag 'custom-group-link
1722 "Show parent in other window when activated."
1725 :action 'custom-browse-group-tag-action)
1727 (defun custom-browse-group-tag-action (widget &rest ignore)
1728 (let ((parent (widget-get widget :parent)))
1729 (customize-group-other-window (widget-value parent))))
1731 (define-widget 'custom-browse-variable-tag 'custom-group-link
1732 "Show parent in other window when activated."
1735 :action 'custom-browse-variable-tag-action)
1737 (defun custom-browse-variable-tag-action (widget &rest ignore)
1738 (let ((parent (widget-get widget :parent)))
1739 (customize-variable-other-window (widget-value parent))))
1741 (define-widget 'custom-browse-face-tag 'custom-group-link
1742 "Show parent in other window when activated."
1745 :action 'custom-browse-face-tag-action)
1747 (defun custom-browse-face-tag-action (widget &rest ignore)
1748 (let ((parent (widget-get widget :parent)))
1749 (customize-face-other-window (widget-value parent))))
1751 (defconst custom-browse-alist '((" " "space")
1757 (defun custom-browse-insert-prefix (prefix)
1758 "Insert PREFIX. On XEmacs convert it to line graphics."
1759 ;; Fixme: do graphics.
1760 (if nil ; (featurep 'xemacs)
1763 (while (not (string-equal prefix ""))
1764 (let ((entry (substring prefix 0 3)))
1765 (setq prefix (substring prefix 3))
1766 (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
1767 (name (nth 1 (assoc entry custom-browse-alist))))
1768 (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
1769 (overlay-put overlay 'start-open t)
1770 (overlay-put overlay 'end-open t)))))
1773 ;;; Modification of Basic Widgets.
1775 ;; We add extra properties to the basic widgets needed here. This is
1776 ;; fine, as long as we are careful to stay within our own namespace.
1778 ;; We want simple widgets to be displayed by default, but complex
1779 ;; widgets to be hidden.
1781 (widget-put (get 'item 'widget-type) :custom-show t)
1782 (widget-put (get 'editable-field 'widget-type)
1783 :custom-show (lambda (widget value)
1784 (let ((pp (pp-to-string value)))
1785 (cond ((string-match "\n" pp)
1790 (widget-put (get 'menu-choice 'widget-type) :custom-show t)
1792 ;;; The `custom-manual' Widget.
1794 (define-widget 'custom-manual 'info-link
1795 "Link to the manual entry for this customization option."
1796 :help-echo "Read the manual entry for this option."
1797 :keymap custom-mode-link-map
1798 :follow-link 'mouse-face
1799 :button-face 'custom-link
1800 :mouse-face 'highlight
1801 :pressed-face 'highlight
1804 ;;; The `custom-magic' Widget.
1806 (defgroup custom-magic-faces nil
1807 "Faces used by the magic button."
1808 :group 'custom-faces
1809 :group 'custom-buffer)
1811 (defface custom-invalid '((((class color))
1812 (:foreground "yellow1" :background "red1"))
1814 (:weight bold :slant italic :underline t)))
1815 "Face used when the customize item is invalid."
1816 :group 'custom-magic-faces)
1817 ;; backward-compatibility alias
1818 (put 'custom-invalid-face 'face-alias 'custom-invalid)
1820 (defface custom-rogue '((((class color))
1821 (:foreground "pink" :background "black"))
1824 "Face used when the customize item is not defined for customization."
1825 :group 'custom-magic-faces)
1826 ;; backward-compatibility alias
1827 (put 'custom-rogue-face 'face-alias 'custom-rogue)
1829 (defface custom-modified '((((min-colors 88) (class color))
1830 (:foreground "white" :background "blue1"))
1832 (:foreground "white" :background "blue"))
1834 (:slant italic :bold)))
1835 "Face used when the customize item has been modified."
1836 :group 'custom-magic-faces)
1837 ;; backward-compatibility alias
1838 (put 'custom-modified-face 'face-alias 'custom-modified)
1840 (defface custom-set '((((min-colors 88) (class color))
1841 (:foreground "blue1" :background "white"))
1843 (:foreground "blue" :background "white"))
1846 "Face used when the customize item has been set."
1847 :group 'custom-magic-faces)
1848 ;; backward-compatibility alias
1849 (put 'custom-set-face 'face-alias 'custom-set)
1851 (defface custom-changed '((((min-colors 88) (class color))
1852 (:foreground "white" :background "blue1"))
1854 (:foreground "white" :background "blue"))
1857 "Face used when the customize item has been changed."
1858 :group 'custom-magic-faces)
1859 ;; backward-compatibility alias
1860 (put 'custom-changed-face 'face-alias 'custom-changed)
1862 (defface custom-themed '((((min-colors 88) (class color))
1863 (:foreground "white" :background "blue1"))
1865 (:foreground "white" :background "blue"))
1868 "Face used when the customize item has been set by a theme."
1869 :group 'custom-magic-faces)
1871 (defface custom-saved '((t (:underline t)))
1872 "Face used when the customize item has been saved."
1873 :group 'custom-magic-faces)
1874 ;; backward-compatibility alias
1875 (put 'custom-saved-face 'face-alias 'custom-saved)
1877 (defconst custom-magic-alist
1878 '((nil "#" underline "\
1879 UNINITIALIZED, you should not see this.")
1880 (unknown "?" italic "\
1881 UNKNOWN, you should not see this.")
1882 (hidden "-" default "\
1883 HIDDEN, invoke \"Show\" in the previous line to show." "\
1884 group now hidden, invoke \"Show\", above, to show contents.")
1885 (invalid "x" custom-invalid "\
1886 INVALID, the displayed value cannot be set.")
1887 (modified "*" custom-modified "\
1888 EDITED, shown value does not take effect until you set or save it." "\
1889 something in this group has been edited but not set.")
1890 (set "+" custom-set "\
1891 SET for current session only." "\
1892 something in this group has been set but not saved.")
1893 (changed ":" custom-changed "\
1894 CHANGED outside Customize; operating on it here may be unreliable." "\
1895 something in this group has been changed outside customize.")
1896 (saved "!" custom-saved "\
1898 something in this group has been set and saved.")
1899 (themed "o" custom-themed "\
1901 visible group members are all at standard values.")
1902 (rogue "@" custom-rogue "\
1903 NO CUSTOMIZATION DATA; not intended to be customized." "\
1904 something in this group is not prepared for customization.")
1905 (standard " " nil "\
1907 visible group members are all at standard values."))
1908 "Alist of customize option states.
1909 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1911 STATE is one of the following symbols:
1914 For internal use, should never occur.
1916 For internal use, should never occur.
1918 This item is not being displayed.
1920 This item is modified, but has an invalid form.
1922 This item is modified, and has a valid form.
1924 This item has been set but not saved.
1926 The current value of this item has been changed outside Customize.
1928 This item is marked for saving.
1930 This item has no customization information.
1932 This item is unchanged from the standard setting.
1934 MAGIC is a string used to present that state.
1936 FACE is a face used to present the state.
1938 ITEM-DESC is a string describing the state for options.
1940 GROUP-DESC is a string describing the state for groups. If this is
1941 left out, ITEM-DESC will be used.
1943 The string %c in either description will be replaced with the
1944 category of the item. These are `group'. `option', and `face'.
1946 The list should be sorted most significant first.")
1948 (defcustom custom-magic-show 'long
1949 "If non-nil, show textual description of the state.
1950 If `long', show a full-line description, not just one word."
1951 :type '(choice (const :tag "no" nil)
1953 (other :tag "short" short))
1954 :group 'custom-buffer)
1956 (defcustom custom-magic-show-hidden '(option face)
1957 "Control whether the State button is shown for hidden items.
1958 The value should be a list with the custom categories where the State
1959 button should be visible. Possible categories are `group', `option',
1961 :type '(set (const group) (const option) (const face))
1962 :group 'custom-buffer)
1964 (defcustom custom-magic-show-button nil
1965 "Show a \"magic\" button indicating the state of each customization option."
1967 :group 'custom-buffer)
1969 (define-widget 'custom-magic 'default
1970 "Show and manipulate state for a customization option."
1972 :action 'widget-parent-action
1975 :value-create 'custom-magic-value-create
1976 :value-delete 'widget-children-value-delete)
1978 (defun widget-magic-mouse-down-action (widget &optional event)
1979 ;; Non-nil unless hidden.
1980 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1984 (defun custom-magic-value-create (widget)
1985 "Create compact status report for WIDGET."
1986 (let* ((parent (widget-get widget :parent))
1987 (state (widget-get parent :custom-state))
1988 (hidden (eq state 'hidden))
1989 (entry (assq state custom-magic-alist))
1990 (magic (nth 1 entry))
1991 (face (nth 2 entry))
1992 (category (widget-get parent :custom-category))
1993 (text (or (and (eq category 'group)
1996 (form (widget-get parent :custom-form))
1998 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
1999 (setq text (concat (match-string 1 text)
2000 (symbol-name category)
2001 (match-string 2 text))))
2002 (when (and custom-magic-show
2004 (memq category custom-magic-show-hidden)))
2006 (when (and (eq category 'group)
2007 (not (and (eq custom-buffer-style 'links)
2008 (> (widget-get parent :custom-level) 1))))
2009 (insert-char ?\ (* custom-buffer-indent
2010 (widget-get parent :custom-level))))
2011 (push (widget-create-child-and-convert
2013 :help-echo "Change the state of this item."
2014 :format (if hidden "%t" "%[%t%]")
2015 :button-prefix 'widget-push-button-prefix
2016 :button-suffix 'widget-push-button-suffix
2017 :mouse-down-action 'widget-magic-mouse-down-action
2021 (let ((start (point)))
2022 (if (eq custom-magic-show 'long)
2024 (insert (symbol-name state)))
2025 (cond ((eq form 'lisp)
2027 ((eq form 'mismatch)
2028 (insert " (mismatch)")))
2029 (put-text-property start (point) 'face 'custom-state))
2031 (when (and (eq category 'group)
2032 (not (and (eq custom-buffer-style 'links)
2033 (> (widget-get parent :custom-level) 1))))
2034 (insert-char ?\ (* custom-buffer-indent
2035 (widget-get parent :custom-level))))
2036 (when custom-magic-show-button
2037 (when custom-magic-show
2038 (let ((indent (widget-get parent :indent)))
2040 (insert-char ? indent))))
2041 (push (widget-create-child-and-convert
2043 :mouse-down-action 'widget-magic-mouse-down-action
2047 :help-echo "Change the state."
2048 :format (if hidden "%t" "%[%t%]")
2049 :tag (if (memq form '(lisp mismatch))
2050 (concat "(" magic ")")
2051 (concat "[" magic "]")))
2054 (widget-put widget :children children)))
2056 (defun custom-magic-reset (widget)
2057 "Redraw the :custom-magic property of WIDGET."
2058 (let ((magic (widget-get widget :custom-magic)))
2059 (widget-value-set magic (widget-value magic))))
2061 ;;; The `custom' Widget.
2063 (defface custom-button
2064 '((((type x w32 ns) (class color)) ; Like default modeline
2065 (:box (:line-width 2 :style released-button)
2066 :background "lightgrey" :foreground "black"))
2069 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2071 :group 'custom-faces)
2072 ;; backward-compatibility alias
2073 (put 'custom-button-face 'face-alias 'custom-button)
2075 (defface custom-button-mouse
2076 '((((type x w32 ns) (class color))
2077 (:box (:line-width 2 :style released-button)
2078 :background "grey90" :foreground "black"))
2081 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2083 :group 'custom-faces)
2085 (defface custom-button-unraised
2086 '((t :inherit underline))
2087 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2089 :group 'custom-faces)
2092 (if custom-raised-buttons 'custom-button 'custom-button-unraised))
2094 (setq custom-button-mouse
2095 (if custom-raised-buttons 'custom-button-mouse 'highlight))
2097 (defface custom-button-pressed
2098 '((((type x w32 ns) (class color))
2099 (:box (:line-width 2 :style pressed-button)
2100 :background "lightgrey" :foreground "black"))
2102 (:inverse-video t)))
2103 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2105 :group 'custom-faces)
2106 ;; backward-compatibility alias
2107 (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed)
2109 (defface custom-button-pressed-unraised
2110 '((default :inherit custom-button-unraised)
2111 (((class color) (background light)) :foreground "magenta4")
2112 (((class color) (background dark)) :foreground "violet"))
2113 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2115 :group 'custom-faces)
2117 (setq custom-button-pressed
2118 (if custom-raised-buttons
2119 'custom-button-pressed
2120 'custom-button-pressed-unraised))
2122 (defface custom-documentation '((t nil))
2123 "Face used for documentation strings in customization buffers."
2124 :group 'custom-faces)
2125 ;; backward-compatibility alias
2126 (put 'custom-documentation-face 'face-alias 'custom-documentation)
2128 (defface custom-state '((((class color)
2130 (:foreground "lime green"))
2133 (:foreground "dark green"))
2135 "Face used for State descriptions in the customize buffer."
2136 :group 'custom-faces)
2137 ;; backward-compatibility alias
2138 (put 'custom-state-face 'face-alias 'custom-state)
2140 (defface custom-link
2141 '((t :inherit link))
2142 "Face for links in customization buffers."
2144 :group 'custom-faces)
2146 (define-widget 'custom 'default
2147 "Customize a user option."
2149 :convert-widget 'custom-convert-widget
2150 :notify 'custom-notify
2153 :custom-state 'hidden
2154 :documentation-property 'widget-subclass-responsibility
2155 :value-create 'widget-subclass-responsibility
2156 :value-delete 'widget-children-value-delete
2157 :value-get 'widget-value-value-get
2158 :validate 'widget-children-validate
2159 :match (lambda (widget value) (symbolp value)))
2161 (defun custom-convert-widget (widget)
2162 "Initialize :value and :tag from :args in WIDGET."
2163 (let ((args (widget-get widget :args)))
2165 (widget-put widget :value (widget-apply widget
2166 :value-to-internal (car args)))
2167 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
2168 (widget-put widget :args nil)))
2171 (defun custom-notify (widget &rest args)
2172 "Keep track of changes."
2173 (let ((state (widget-get widget :custom-state)))
2174 (unless (eq state 'modified)
2175 (unless (memq state '(nil unknown hidden))
2176 (widget-put widget :custom-state 'modified))
2177 (custom-magic-reset widget)
2178 (apply 'widget-default-notify widget args))))
2180 (defun custom-redraw (widget)
2181 "Redraw WIDGET with current settings."
2182 (let ((line (count-lines (point-min) (point)))
2183 (column (current-column))
2185 (from (marker-position (widget-get widget :from)))
2186 (to (marker-position (widget-get widget :to))))
2188 (widget-value-set widget (widget-value widget))
2189 (custom-redraw-magic widget))
2190 (when (and (>= pos from) (<= pos to))
2195 (goto-line (1+ line)))
2196 (move-to-column column))
2199 (defun custom-redraw-magic (widget)
2200 "Redraw WIDGET state with current settings."
2202 (let ((magic (widget-get widget :custom-magic)))
2204 (widget-value-set magic (widget-value magic))
2205 (when (setq widget (widget-get widget :group))
2206 (custom-group-state-update widget)))
2208 (setq widget nil)))))
2211 (defun custom-show (widget value)
2212 "Non-nil if WIDGET should be shown with VALUE by default."
2213 (let ((show (widget-get widget :custom-show)))
2219 (funcall show widget value)))))
2221 (defun custom-load-widget (widget)
2222 "Load all dependencies for WIDGET."
2223 (custom-load-symbol (widget-value widget)))
2225 (defun custom-unloaded-symbol-p (symbol)
2226 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2228 (loads (get symbol 'custom-loads))
2231 (setq load (car loads)
2233 (cond ((symbolp load)
2234 (unless (featurep load)
2236 ((assoc load load-history))
2237 ((assoc (locate-library load) load-history)
2243 (defun custom-unloaded-widget-p (widget)
2244 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2245 (custom-unloaded-symbol-p (widget-value widget)))
2247 (defun custom-toggle-hide (widget)
2248 "Toggle visibility of WIDGET."
2249 (custom-load-widget widget)
2250 (let ((state (widget-get widget :custom-state)))
2251 (cond ((memq state '(invalid modified))
2252 (error "There are unset changes"))
2254 (widget-put widget :custom-state 'unknown))
2256 (widget-put widget :documentation-shown nil)
2257 (widget-put widget :custom-state 'hidden)))
2258 (custom-redraw widget)
2261 (defun custom-toggle-parent (widget &rest ignore)
2262 "Toggle visibility of parent of WIDGET."
2263 (custom-toggle-hide (widget-get widget :parent)))
2265 (defun custom-add-see-also (widget &optional prefix)
2266 "Add `See also ...' to WIDGET if there are any links.
2267 Insert PREFIX first if non-nil."
2268 (let* ((symbol (widget-get widget :value))
2269 (links (get symbol 'custom-links))
2270 (many (> (length links) 2))
2271 (buttons (widget-get widget :buttons))
2272 (indent (widget-get widget :indent)))
2275 (insert-char ?\ indent))
2278 (insert "See also ")
2280 (push (widget-create-child-and-convert
2282 :button-face 'custom-link
2283 :mouse-face 'highlight
2284 :pressed-face 'highlight)
2286 (setq links (cdr links))
2295 (widget-put widget :buttons buttons))))
2297 (defun custom-add-parent-links (widget &optional initial-string
2299 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2300 The value is non-nil if any parents were found.
2301 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2302 (let ((name (widget-value widget))
2303 (type (widget-type widget))
2304 (buttons (widget-get widget :buttons))
2307 (insert (or initial-string "Groups:"))
2308 (mapatoms (lambda (symbol)
2309 (when (member (list name type) (get symbol 'custom-group))
2311 (push (widget-create-child-and-convert
2312 widget 'custom-group-link
2313 :tag (custom-unlispify-tag-name symbol)
2316 (setq parents (cons symbol parents)))))
2317 (and (null (get name 'custom-links)) ;No links of its own.
2318 (= (length parents) 1) ;A single parent.
2319 (let* ((links (delq nil (mapcar (lambda (w)
2320 (unless (eq (widget-type w)
2323 (get (car parents) 'custom-links))))
2324 (many (> (length links) 2)))
2327 (left-margin (+ left-margin 2)))
2328 (insert "\n" (or doc-initial-string "Group documentation:") " ")
2330 (push (widget-create-child-and-convert
2332 :button-face 'custom-link
2333 :mouse-face 'highlight
2334 :pressed-face 'highlight)
2336 (setq links (cdr links))
2345 (fill-region-as-paragraph pt (point))
2346 (delete-to-left-margin (1+ pt) (+ pt 2))))))
2349 (delete-region start (point)))
2350 (widget-put widget :buttons buttons)
2353 ;;; The `custom-comment' Widget.
2355 ;; like the editable field
2356 (defface custom-comment '((((type tty))
2357 :background "yellow3"
2358 :foreground "black")
2359 (((class grayscale color)
2361 :background "gray85")
2362 (((class grayscale color)
2364 :background "dim gray")
2367 "Face used for comments on variables or faces"
2369 :group 'custom-faces)
2370 ;; backward-compatibility alias
2371 (put 'custom-comment-face 'face-alias 'custom-comment)
2373 ;; like font-lock-comment-face
2374 (defface custom-comment-tag
2375 '((((class color) (background dark)) (:foreground "gray80"))
2376 (((class color) (background light)) (:foreground "blue4"))
2377 (((class grayscale) (background light))
2378 (:foreground "DimGray" :weight bold :slant italic))
2379 (((class grayscale) (background dark))
2380 (:foreground "LightGray" :weight bold :slant italic))
2382 "Face used for variables or faces comment tags"
2383 :group 'custom-faces)
2384 ;; backward-compatibility alias
2385 (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag)
2387 (define-widget 'custom-comment 'string
2390 :help-echo "Edit a comment here."
2391 :sample-face 'custom-comment-tag-face
2392 :value-face 'custom-comment-face
2394 :create 'custom-comment-create)
2396 (defun custom-comment-create (widget)
2397 (let* ((null-comment (equal "" (widget-value widget))))
2398 (if (or (widget-get (widget-get widget :parent) :comment-shown)
2400 (widget-default-create widget)
2401 ;; `widget-default-delete' expects markers in these slots --
2402 ;; maybe it shouldn't.
2403 (widget-put widget :from (point-marker))
2404 (widget-put widget :to (point-marker)))))
2406 (defun custom-comment-hide (widget)
2407 (widget-put (widget-get widget :parent) :comment-shown nil))
2409 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2410 ;; the global custom one
2411 (defun custom-comment-show (widget)
2412 (widget-put widget :comment-shown t)
2413 (custom-redraw widget)
2416 (defun custom-comment-invisible-p (widget)
2417 (let ((val (widget-value (widget-get widget :comment-widget))))
2419 (not (widget-get widget :comment-shown)))))
2421 ;;; The `custom-variable' Widget.
2423 ;; When this was underlined blue, users confused it with a
2424 ;; Mosaic-style hyperlink...
2425 (defface custom-variable-tag
2428 (:foreground "light blue" :weight bold))
2429 (((min-colors 88) (class color)
2431 (:foreground "blue1" :weight bold))
2434 (:foreground "blue" :weight bold))
2436 "Face used for unpushable variable tags."
2437 :group 'custom-faces)
2438 ;; backward-compatibility alias
2439 (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag)
2441 (defface custom-variable-button '((t (:underline t :weight bold)))
2442 "Face used for pushable variable tags."
2443 :group 'custom-faces)
2444 ;; backward-compatibility alias
2445 (put 'custom-variable-button-face 'face-alias 'custom-variable-button)
2447 (defcustom custom-variable-default-form 'edit
2448 "Default form of displaying variable values."
2449 :type '(choice (const edit)
2451 :group 'custom-buffer
2454 (defun custom-variable-documentation (variable)
2455 "Return documentation of VARIABLE for use in Custom buffer.
2456 Normally just return the docstring. But if VARIABLE automatically
2457 becomes buffer local when set, append a message to that effect."
2458 (if (and (local-variable-if-set-p variable)
2459 (or (not (local-variable-p variable))
2461 (local-variable-if-set-p variable))))
2462 (concat (documentation-property variable 'variable-documentation)
2464 This variable automatically becomes buffer-local when set outside Custom.
2465 However, setting it through Custom sets the default value.")
2466 (documentation-property variable 'variable-documentation)))
2468 (define-widget 'custom-variable 'custom
2469 "Customize variable."
2471 :help-echo "Set or reset this variable."
2472 :documentation-property #'custom-variable-documentation
2473 :custom-category 'option
2475 :custom-menu 'custom-variable-menu-create
2476 :custom-form nil ; defaults to value of `custom-variable-default-form'
2477 :value-create 'custom-variable-value-create
2478 :action 'custom-variable-action
2479 :custom-set 'custom-variable-set
2480 :custom-mark-to-save 'custom-variable-mark-to-save
2481 :custom-reset-current 'custom-redraw
2482 :custom-reset-saved 'custom-variable-reset-saved
2483 :custom-reset-standard 'custom-variable-reset-standard
2484 :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
2485 :custom-standard-value 'custom-variable-standard-value
2486 :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
2488 (defun custom-variable-type (symbol)
2489 "Return a widget suitable for editing the value of SYMBOL.
2490 If SYMBOL has a `custom-type' property, use that.
2491 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2492 try matching its doc string against `custom-guess-doc-alist'."
2493 (let* ((type (or (get symbol 'custom-type)
2494 (and (not (get symbol 'standard-value))
2495 (custom-guess-type symbol))
2497 (options (get symbol 'custom-options))
2498 (tmp (if (listp type)
2499 (copy-sequence type)
2502 (widget-put tmp :options options))
2505 (defun custom-variable-value-create (widget)
2506 "Here is where you edit the variable's value."
2507 (custom-load-widget widget)
2508 (unless (widget-get widget :custom-form)
2509 (widget-put widget :custom-form custom-variable-default-form))
2510 (let* ((buttons (widget-get widget :buttons))
2511 (children (widget-get widget :children))
2512 (form (widget-get widget :custom-form))
2513 (state (widget-get widget :custom-state))
2514 (symbol (widget-get widget :value))
2515 (tag (widget-get widget :tag))
2516 (type (custom-variable-type symbol))
2517 (conv (widget-convert type))
2518 (get (or (get symbol 'custom-get) 'default-value))
2519 (prefix (widget-get widget :custom-prefix))
2520 (last (widget-get widget :custom-last))
2521 (value (if (default-boundp symbol)
2522 (funcall get symbol)
2523 (widget-get conv :value))))
2524 ;; If the widget is new, the child determines whether it is hidden.
2526 ((custom-show type value)
2527 (setq state 'unknown))
2529 (setq state 'hidden)))
2530 ;; If we don't know the state, see if we need to edit it in lisp form.
2531 (when (eq state 'unknown)
2532 (unless (widget-apply conv :match value)
2533 ;; (widget-apply (widget-convert type) :match value)
2534 (setq form 'mismatch)))
2535 ;; Now we can create the child widget.
2536 (cond ((eq custom-buffer-style 'tree)
2537 (insert prefix (if last " `--- " " |--- "))
2538 (push (widget-create-child-and-convert
2539 widget 'custom-browse-variable-tag)
2541 (insert " " tag "\n")
2542 (widget-put widget :buttons buttons))
2544 ;; Indicate hidden value.
2545 (push (widget-create-child-and-convert
2548 :sample-face 'custom-variable-tag-face
2552 (push (widget-create-child-and-convert
2554 :help-echo "Show the value of this option."
2556 :action 'custom-toggle-parent
2559 ((memq form '(lisp mismatch))
2560 ;; In lisp mode edit the saved value when possible.
2561 (let* ((value (cond ((get symbol 'saved-value)
2562 (car (get symbol 'saved-value)))
2563 ((get symbol 'standard-value)
2564 (car (get symbol 'standard-value)))
2565 ((default-boundp symbol)
2566 (custom-quote (funcall get symbol)))
2568 (custom-quote (widget-get conv :value))))))
2569 (insert (symbol-name symbol) ": ")
2570 (push (widget-create-child-and-convert
2572 :help-echo "Hide the value of this option."
2575 :action 'custom-toggle-parent
2579 (push (widget-create-child-and-convert
2581 :button-face 'custom-variable-button-face
2583 :tag (symbol-name symbol)
2589 (let* ((format (widget-get type :format))
2590 tag-format value-format)
2591 (unless (string-match ":" format)
2592 (error "Bad format"))
2593 (setq tag-format (substring format 0 (match-end 0)))
2594 (setq value-format (substring format (match-end 0)))
2595 (push (widget-create-child-and-convert
2598 :action 'custom-tag-action
2599 :help-echo "Change value of this option."
2600 :mouse-down-action 'custom-tag-mouse-down-action
2601 :button-face 'custom-variable-button-face
2602 :sample-face 'custom-variable-tag-face
2606 (push (widget-create-child-and-convert
2608 :help-echo "Hide the value of this option."
2611 :action 'custom-toggle-parent
2614 (push (widget-create-child-and-convert
2616 :format value-format
2619 (unless (eq custom-buffer-style 'tree)
2620 (unless (eq (preceding-char) ?\n)
2621 (widget-insert "\n"))
2622 ;; Create the magic button.
2623 (let ((magic (widget-create-child-and-convert
2624 widget 'custom-magic nil)))
2625 (widget-put widget :custom-magic magic)
2626 (push magic buttons))
2627 (widget-put widget :buttons buttons)
2628 ;; Insert documentation.
2629 (widget-put widget :documentation-indent 3)
2630 (widget-add-documentation-string-button
2631 widget :visibility-widget 'custom-visibility)
2633 ;; The comment field
2634 (unless (eq state 'hidden)
2635 (let* ((comment (get symbol 'variable-comment))
2637 (widget-create-child-and-convert
2638 widget 'custom-comment
2640 :value (or comment ""))))
2641 (widget-put widget :comment-widget comment-widget)
2642 ;; Don't push it !!! Custom assumes that the first child is the
2644 (setq children (append children (list comment-widget)))))
2645 ;; Update the rest of the properties properties.
2646 (widget-put widget :custom-form form)
2647 (widget-put widget :children children)
2648 ;; Now update the state.
2649 (if (eq state 'hidden)
2650 (widget-put widget :custom-state state)
2651 (custom-variable-state-set widget))
2653 (unless (eq state 'hidden)
2654 (when (eq (widget-get widget :custom-level) 1)
2655 (custom-add-parent-links widget))
2656 (custom-add-see-also widget)))))
2658 (defun custom-tag-action (widget &rest args)
2659 "Pass :action to first child of WIDGET's parent."
2660 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2663 (defun custom-tag-mouse-down-action (widget &rest args)
2664 "Pass :mouse-down-action to first child of WIDGET's parent."
2665 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
2666 :mouse-down-action args))
2668 (defun custom-variable-state-set (widget)
2669 "Set the state of WIDGET."
2670 (let* ((symbol (widget-value widget))
2671 (get (or (get symbol 'custom-get) 'default-value))
2672 (value (if (default-boundp symbol)
2673 (funcall get symbol)
2674 (widget-get widget :value)))
2675 (comment (get symbol 'variable-comment))
2678 (state (cond ((progn (setq tmp (get symbol 'customized-value))
2680 (get symbol 'customized-variable-comment))
2682 (if (condition-case nil
2683 (and (equal value (eval (car tmp)))
2684 (equal comment temp))
2688 ((progn (setq tmp (get symbol 'theme-value))
2689 (setq temp (get symbol 'saved-variable-comment))
2691 (if (condition-case nil
2692 (and (equal comment temp)
2695 (car (custom-variable-theme-value
2699 ((eq (caar tmp) 'user) 'saved)
2700 ((eq (caar tmp) 'changed)
2701 (if (condition-case nil
2705 (car (get symbol 'standard-value)))))
2707 ;; The value was originally set outside
2708 ;; custom, but it was set to the standard
2709 ;; value (probably an autoloaded defcustom).
2714 ((setq tmp (get symbol 'standard-value))
2715 (if (condition-case nil
2716 (and (equal value (eval (car tmp)))
2717 (equal comment nil))
2722 (widget-put widget :custom-state state)))
2724 (defun custom-variable-standard-value (widget)
2725 (get (widget-value widget) 'standard-value))
2727 (defvar custom-variable-menu
2728 `(("Set for Current Session" custom-variable-set
2730 (eq (widget-get widget :custom-state) 'modified)))
2731 ;; Note that in all the backquoted code in this file, we test
2732 ;; init-file-user rather than user-init-file. This is in case
2733 ;; cus-edit is loaded by something in site-start.el, because
2734 ;; user-init-file is not set at that stage.
2735 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2736 ,@(when (or custom-file init-file-user)
2737 '(("Save for Future Sessions" custom-variable-save
2739 (memq (widget-get widget :custom-state)
2740 '(modified set changed rogue))))))
2741 ("Undo Edits" custom-redraw
2743 (and (default-boundp (widget-value widget))
2744 (memq (widget-get widget :custom-state) '(modified changed)))))
2745 ("Reset to Saved" custom-variable-reset-saved
2747 (and (or (get (widget-value widget) 'saved-value)
2748 (get (widget-value widget) 'saved-variable-comment))
2749 (memq (widget-get widget :custom-state)
2750 '(modified set changed rogue)))))
2751 ,@(when (or custom-file init-file-user)
2752 '(("Erase Customization" custom-variable-reset-standard
2754 (and (get (widget-value widget) 'standard-value)
2755 (memq (widget-get widget :custom-state)
2756 '(modified set changed saved rogue)))))))
2757 ("Set to Backup Value" custom-variable-reset-backup
2759 (get (widget-value widget) 'backup-value)))
2760 ("---" ignore ignore)
2761 ("Add Comment" custom-comment-show custom-comment-invisible-p)
2762 ("---" ignore ignore)
2763 ("Show Current Value" custom-variable-edit
2765 (eq (widget-get widget :custom-form) 'lisp)))
2766 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2768 (eq (widget-get widget :custom-form) 'edit))))
2769 "Alist of actions for the `custom-variable' widget.
2770 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2771 the menu entry, ACTION is the function to call on the widget when the
2772 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2773 widget as an argument, and returns non-nil if ACTION is valid on that
2774 widget. If FILTER is nil, ACTION is always valid.")
2776 (defun custom-variable-action (widget &optional event)
2777 "Show the menu for `custom-variable' WIDGET.
2778 Optional EVENT is the location for the menu."
2779 (if (eq (widget-get widget :custom-state) 'hidden)
2780 (custom-toggle-hide widget)
2781 (unless (eq (widget-get widget :custom-state) 'modified)
2782 (custom-variable-state-set widget))
2783 (custom-redraw-magic widget)
2784 (let* ((completion-ignore-case t)
2785 (answer (widget-choose (concat "Operation on "
2786 (custom-unlispify-tag-name
2787 (widget-get widget :value)))
2788 (custom-menu-filter custom-variable-menu
2792 (funcall answer widget)))))
2794 (defun custom-variable-edit (widget)
2795 "Edit value of WIDGET."
2796 (widget-put widget :custom-state 'unknown)
2797 (widget-put widget :custom-form 'edit)
2798 (custom-redraw widget))
2800 (defun custom-variable-edit-lisp (widget)
2801 "Edit the Lisp representation of the value of WIDGET."
2802 (widget-put widget :custom-state 'unknown)
2803 (widget-put widget :custom-form 'lisp)
2804 (custom-redraw widget))
2806 (defun custom-variable-set (widget)
2807 "Set the current value for the variable being edited by WIDGET."
2808 (let* ((form (widget-get widget :custom-form))
2809 (state (widget-get widget :custom-state))
2810 (child (car (widget-get widget :children)))
2811 (symbol (widget-value widget))
2812 (set (or (get symbol 'custom-set) 'set-default))
2813 (comment-widget (widget-get widget :comment-widget))
2814 (comment (widget-value comment-widget))
2816 (cond ((eq state 'hidden)
2817 (error "Cannot set hidden variable"))
2818 ((setq val (widget-apply child :validate))
2819 (goto-char (widget-get val :from))
2820 (error "%s" (widget-get val :error)))
2821 ((memq form '(lisp mismatch))
2822 (when (equal comment "")
2824 ;; Make the comment invisible by hand if it's empty
2825 (custom-comment-hide comment-widget))
2826 (custom-variable-backup-value widget)
2827 (custom-push-theme 'theme-value symbol 'user
2828 'set (custom-quote (widget-value child)))
2829 (funcall set symbol (eval (setq val (widget-value child))))
2830 (put symbol 'customized-value (list val))
2831 (put symbol 'variable-comment comment)
2832 (put symbol 'customized-variable-comment comment))
2834 (when (equal comment "")
2836 ;; Make the comment invisible by hand if it's empty
2837 (custom-comment-hide comment-widget))
2838 (custom-variable-backup-value widget)
2839 (custom-push-theme 'theme-value symbol 'user
2840 'set (custom-quote (widget-value child)))
2841 (funcall set symbol (setq val (widget-value child)))
2842 (put symbol 'customized-value (list (custom-quote val)))
2843 (put symbol 'variable-comment comment)
2844 (put symbol 'customized-variable-comment comment)))
2845 (custom-variable-state-set widget)
2846 (custom-redraw-magic widget)))
2848 (defun custom-variable-mark-to-save (widget)
2849 "Set value and mark for saving the variable edited by WIDGET."
2850 (let* ((form (widget-get widget :custom-form))
2851 (state (widget-get widget :custom-state))
2852 (child (car (widget-get widget :children)))
2853 (symbol (widget-value widget))
2854 (set (or (get symbol 'custom-set) 'set-default))
2855 (comment-widget (widget-get widget :comment-widget))
2856 (comment (widget-value comment-widget))
2858 (cond ((eq state 'hidden)
2859 (error "Cannot set hidden variable"))
2860 ((setq val (widget-apply child :validate))
2861 (goto-char (widget-get val :from))
2862 (error "Saving %s: %s" symbol (widget-get val :error)))
2863 ((memq form '(lisp mismatch))
2864 (when (equal comment "")
2866 ;; Make the comment invisible by hand if it's empty
2867 (custom-comment-hide comment-widget))
2868 (put symbol 'saved-value (list (widget-value child)))
2869 (custom-push-theme 'theme-value symbol 'user
2870 'set (custom-quote (widget-value child)))
2871 (funcall set symbol (eval (widget-value child)))
2872 (put symbol 'variable-comment comment)
2873 (put symbol 'saved-variable-comment comment))
2875 (when (equal comment "")
2877 ;; Make the comment invisible by hand if it's empty
2878 (custom-comment-hide comment-widget))
2879 (put symbol 'saved-value
2880 (list (custom-quote (widget-value child))))
2881 (custom-push-theme 'theme-value symbol 'user
2882 'set (custom-quote (widget-value child)))
2883 (funcall set symbol (widget-value child))
2884 (put symbol 'variable-comment comment)
2885 (put symbol 'saved-variable-comment comment)))
2886 (put symbol 'customized-value nil)
2887 (put symbol 'customized-variable-comment nil)))
2889 (defsubst custom-variable-state-set-and-redraw (widget)
2890 "Set state of variable widget WIDGET and redraw with current settings."
2891 (custom-variable-state-set widget)
2892 (custom-redraw-magic widget))
2894 (defun custom-variable-save (widget)
2895 "Save value of variable edited by widget WIDGET."
2896 (custom-variable-mark-to-save widget)
2898 (custom-variable-state-set-and-redraw widget))
2900 (defun custom-variable-reset-saved (widget)
2901 "Restore the saved value for the variable being edited by WIDGET.
2902 This also updates the buffer to show that value.
2903 The value that was current before this operation
2904 becomes the backup value, so you can get it again."
2905 (let* ((symbol (widget-value widget))
2906 (set (or (get symbol 'custom-set) 'set-default))
2907 (value (get symbol 'saved-value))
2908 (comment (get symbol 'saved-variable-comment)))
2909 (cond ((or value comment)
2910 (put symbol 'variable-comment comment)
2911 (custom-variable-backup-value widget)
2912 (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
2914 (funcall set symbol (eval (car value)))
2917 (error "No saved value for %s" symbol)))
2918 (put symbol 'customized-value nil)
2919 (put symbol 'customized-variable-comment nil)
2920 (widget-put widget :custom-state 'unknown)
2921 ;; This call will possibly make the comment invisible
2922 (custom-redraw widget)))
2924 (defun custom-variable-mark-to-reset-standard (widget)
2925 "Mark to restore standard setting for the variable edited by widget WIDGET.
2926 If `custom-reset-standard-variables-list' is nil, save, reset and
2927 redraw the widget immediately."
2928 (let* ((symbol (widget-value widget)))
2929 (if (get symbol 'standard-value)
2930 (custom-variable-backup-value widget)
2931 (error "No standard setting known for %S" symbol))
2932 (put symbol 'variable-comment nil)
2933 (put symbol 'customized-value nil)
2934 (put symbol 'customized-variable-comment nil)
2935 (custom-push-theme 'theme-value symbol 'user 'reset)
2936 (custom-theme-recalc-variable symbol)
2937 (if (and custom-reset-standard-variables-list
2938 (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)))
2940 (put symbol 'saved-value nil)
2941 (put symbol 'saved-variable-comment nil)
2942 ;; Append this to `custom-reset-standard-variables-list' to
2943 ;; have `custom-reset-standard-save-and-update' save setting
2944 ;; to the file, update the widget's state, and redraw it.
2945 (setq custom-reset-standard-variables-list
2946 (cons widget custom-reset-standard-variables-list)))
2947 (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
2948 (put symbol 'saved-value nil)
2949 (put symbol 'saved-variable-comment nil)
2951 (widget-put widget :custom-state 'unknown)
2952 ;; This call will possibly make the comment invisible
2953 (custom-redraw widget))))
2955 (defun custom-variable-reset-standard (widget)
2956 "Restore standard setting for the variable edited by WIDGET.
2957 This operation eliminates any saved setting for the variable,
2958 restoring it to the state of a variable that has never been customized.
2959 The value that was current before this operation
2960 becomes the backup value, so you can get it again."
2961 (let (custom-reset-standard-variables-list)
2962 (custom-variable-mark-to-reset-standard widget)))
2964 (defun custom-variable-backup-value (widget)
2965 "Back up the current value for WIDGET's variable.
2966 The backup value is kept in the car of the `backup-value' property."
2967 (let* ((symbol (widget-value widget))
2968 (get (or (get symbol 'custom-get) 'default-value))
2969 (type (custom-variable-type symbol))
2970 (conv (widget-convert type))
2971 (value (if (default-boundp symbol)
2972 (funcall get symbol)
2973 (widget-get conv :value))))
2974 (put symbol 'backup-value (list value))))
2976 (defun custom-variable-reset-backup (widget)
2977 "Restore the backup value for the variable being edited by WIDGET.
2978 The value that was current before this operation
2979 becomes the backup value, so you can use this operation repeatedly
2980 to switch between two values."
2981 (let* ((symbol (widget-value widget))
2982 (set (or (get symbol 'custom-set) 'set-default))
2983 (value (get symbol 'backup-value))
2984 (comment-widget (widget-get widget :comment-widget))
2985 (comment (widget-value comment-widget)))
2988 (custom-variable-backup-value widget)
2989 (custom-push-theme 'theme-value symbol 'user 'set value)
2991 (funcall set symbol (car value))
2993 (error "No backup value for %s" symbol))
2994 (put symbol 'customized-value (list (car value)))
2995 (put symbol 'variable-comment comment)
2996 (put symbol 'customized-variable-comment comment)
2997 (custom-variable-state-set widget)
2998 ;; This call will possibly make the comment invisible
2999 (custom-redraw widget)))
3001 ;;; The `custom-visibility' Widget
3003 (define-widget 'custom-visibility 'visibility
3004 "Show or hide a documentation string."
3005 :button-face 'custom-visibility
3006 :pressed-face 'custom-visibility
3007 :mouse-face 'highlight
3008 :pressed-face 'highlight)
3010 (defface custom-visibility
3011 '((t :height 0.8 :inherit link))
3012 "Face for the `custom-visibility' widget."
3014 :group 'custom-faces)
3016 ;;; The `custom-face-edit' Widget.
3018 (define-widget 'custom-face-edit 'checklist
3019 "Edit face attributes."
3023 :button-args '(:help-echo "Control whether this attribute has any effect.")
3024 :value-to-internal 'custom-face-edit-fix-value
3025 :match (lambda (widget value)
3026 (widget-checklist-match widget
3027 (custom-face-edit-fix-value widget value)))
3028 :convert-widget 'custom-face-edit-convert-widget
3029 :args (mapcar (lambda (att)
3032 :sibling-args (widget-get (nth 1 att) :sibling-args)
3033 (list 'const :format "" :value (nth 0 att))
3035 custom-face-attributes))
3037 (defun custom-face-edit-fix-value (widget value)
3038 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3039 Also change :reverse-video to :inverse-video."
3043 (let ((key (car value))
3044 (val (car (cdr value))))
3045 (cond ((eq key :italic)
3046 (push :slant result)
3047 (push (if val 'italic 'normal) result))
3049 (push :weight result)
3050 (push (if val 'bold 'normal) result))
3051 ((eq key :reverse-video)
3052 (push :inverse-video result)
3056 (push val result))))
3057 (setq value (cdr (cdr value))))
3058 (setq result (nreverse result))
3062 (defun custom-face-edit-convert-widget (widget)
3063 "Convert :args as widget types in WIDGET."
3066 :args (mapcar (lambda (arg)
3068 :deactivate 'custom-face-edit-deactivate
3069 :activate 'custom-face-edit-activate
3070 :delete 'custom-face-edit-delete))
3071 (widget-get widget :args)))
3074 (defun custom-face-edit-deactivate (widget)
3075 "Make face widget WIDGET inactive for user modifications."
3076 (unless (widget-get widget :inactive)
3077 (let ((tag (custom-face-edit-attribute-tag widget))
3078 (from (copy-marker (widget-get widget :from)))
3079 (value (widget-value widget))
3080 (inhibit-read-only t)
3081 (inhibit-modification-hooks t))
3084 (widget-default-delete widget)
3085 (insert tag ": *\n")
3086 (widget-put widget :inactive
3087 (cons value (cons from (- (point) from))))))))
3089 (defun custom-face-edit-activate (widget)
3090 "Make face widget WIDGET active for user modifications."
3091 (let ((inactive (widget-get widget :inactive))
3092 (inhibit-read-only t)
3093 (inhibit-modification-hooks t))
3094 (when (consp inactive)
3096 (goto-char (car (cdr inactive)))
3097 (delete-region (point) (+ (point) (cdr (cdr inactive))))
3098 (widget-put widget :inactive nil)
3099 (widget-apply widget :create)
3100 (widget-value-set widget (car inactive))
3103 (defun custom-face-edit-delete (widget)
3104 "Remove WIDGET from the buffer."
3105 (let ((inactive (widget-get widget :inactive))
3106 (inhibit-read-only t)
3107 (inhibit-modification-hooks t))
3109 ;; Widget is alive, we don't have to do anything special
3110 (widget-default-delete widget)
3111 ;; WIDGET is already deleted because we did so to inactivate it;
3112 ;; now just get rid of the label we put in its place.
3113 (delete-region (car (cdr inactive))
3114 (+ (car (cdr inactive)) (cdr (cdr inactive))))
3115 (widget-put widget :inactive nil))))
3118 (defun custom-face-edit-attribute-tag (widget)
3119 "Returns the first :tag property in WIDGET or one of its children."
3120 (let ((tag (widget-get widget :tag)))
3121 (or (and (not (equal tag "")) tag)
3122 (let ((children (widget-get widget :children)))
3123 (while (and (null tag) children)
3124 (setq tag (custom-face-edit-attribute-tag (pop children))))
3127 ;;; The `custom-display' Widget.
3129 (define-widget 'custom-display 'menu-choice
3130 "Select a display type."
3133 :help-echo "Specify frames where the face attributes should be used."
3134 :args '((const :tag "all" t)
3135 (const :tag "defaults" default)
3139 :args ((group :sibling-args (:help-echo "\
3140 Only match the specified window systems.")
3141 (const :format "Type: "
3143 (checklist :inline t
3146 :sibling-args (:help-echo "\
3147 The X11 Window System.")
3149 (const :format "PM "
3150 :sibling-args (:help-echo "\
3151 OS/2 Presentation Manager.")
3153 (const :format "W32 "
3154 :sibling-args (:help-echo "\
3157 (const :format "NS "
3158 :sibling-args (:help-echo "\
3159 GNUstep or Macintosh OS Cocoa interface.")
3161 (const :format "DOS "
3162 :sibling-args (:help-echo "\
3165 (const :format "TTY%n"
3166 :sibling-args (:help-echo "\
3167 Plain text terminals.")
3169 (group :sibling-args (:help-echo "\
3170 Only match the frames with the specified color support.")
3171 (const :format "Class: "
3173 (checklist :inline t
3175 (const :format "Color "
3176 :sibling-args (:help-echo "\
3177 Match color frames.")
3179 (const :format "Grayscale "
3180 :sibling-args (:help-echo "\
3181 Match grayscale frames.")
3183 (const :format "Monochrome%n"
3184 :sibling-args (:help-echo "\
3185 Match frames with no color support.")
3187 (group :sibling-args (:help-echo "\
3188 The minimum number of colors the frame should support.")
3189 (const :format "" min-colors)
3190 (integer :tag "Minimum number of colors" ))
3191 (group :sibling-args (:help-echo "\
3192 Only match frames with the specified intensity.")
3194 Background brightness: "
3196 (checklist :inline t
3198 (const :format "Light "
3199 :sibling-args (:help-echo "\
3200 Match frames with light backgrounds.")
3202 (const :format "Dark\n"
3203 :sibling-args (:help-echo "\
3204 Match frames with dark backgrounds.")
3206 (group :sibling-args (:help-echo "\
3207 Only match frames that support the specified face attributes.")
3208 (const :format "Supports attributes:" supports)
3209 (custom-face-edit :inline t :format "%n%v"))))))
3211 ;;; The `custom-face' Widget.
3213 (defface custom-face-tag
3214 `((t (:weight bold :height 1.2 :inherit variable-pitch)))
3215 "Face used for face tags."
3216 :group 'custom-faces)
3217 ;; backward-compatibility alias
3218 (put 'custom-face-tag-face 'face-alias 'custom-face-tag)
3220 (defcustom custom-face-default-form 'selected
3221 "Default form of displaying face definition."
3222 :type '(choice (const all)
3225 :group 'custom-buffer
3228 (define-widget 'custom-face 'custom
3230 :sample-face 'custom-face-tag-face
3231 :help-echo "Set or reset this face."
3232 :documentation-property #'face-doc-string
3233 :value-create 'custom-face-value-create
3234 :action 'custom-face-action
3235 :custom-category 'face
3236 :custom-form nil ; defaults to value of `custom-face-default-form'
3237 :custom-set 'custom-face-set
3238 :custom-mark-to-save 'custom-face-mark-to-save
3239 :custom-reset-current 'custom-redraw
3240 :custom-reset-saved 'custom-face-reset-saved
3241 :custom-reset-standard 'custom-face-reset-standard
3242 :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
3243 :custom-standard-value 'custom-face-standard-value
3244 :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
3245 :custom-menu 'custom-face-menu-create)
3247 (define-widget 'custom-face-all 'editable-list
3248 "An editable list of display specifications and attributes."
3249 :entry-format "%i %d %v"
3250 :insert-button-args '(:help-echo "Insert new display specification here.")
3251 :append-button-args '(:help-echo "Append new display specification here.")
3252 :delete-button-args '(:help-echo "Delete this display specification.")
3253 :args '((group :format "%v" custom-display custom-face-edit)))
3255 (defconst custom-face-all (widget-convert 'custom-face-all)
3256 "Converted version of the `custom-face-all' widget.")
3258 (define-widget 'custom-display-unselected 'item
3259 "A display specification that doesn't match the selected display."
3260 :match 'custom-display-unselected-match)
3262 (defun custom-display-unselected-match (widget value)
3263 "Non-nil if VALUE is an unselected display specification."
3264 (not (face-spec-set-match-display value (selected-frame))))
3266 (define-widget 'custom-face-selected 'group
3267 "Edit the attributes of the selected display in a face specification."
3268 :args '((choice :inline t
3269 (group :tag "With Defaults" :inline t
3270 (group (const :tag "" default)
3271 (custom-face-edit :tag " Default\n Attributes"))
3274 (group custom-display-unselected sexp))
3275 (group (sexp :format "")
3276 (custom-face-edit :tag " Overriding\n Attributes"))
3280 (group :tag "No Defaults" :inline t
3283 (group custom-display-unselected sexp))
3284 (group (sexp :format "")
3285 (custom-face-edit :tag "\n Attributes"))
3292 (defconst custom-face-selected (widget-convert 'custom-face-selected)
3293 "Converted version of the `custom-face-selected' widget.")
3295 (defun custom-filter-face-spec (spec filter-index &optional default-filter)
3296 "Return a canonicalized version of SPEC using.
3297 FILTER-INDEX is the index in the entry for each attribute in
3298 `custom-face-attributes' at which the appropriate filter function can be
3299 found, and DEFAULT-FILTER is the filter to apply for attributes that
3301 (mapcar (lambda (entry)
3302 ;; Filter a single face-spec entry
3303 (let ((tests (car entry))
3305 ;; Handle both old- and new-style attribute syntax
3306 (if (listp (car (cdr entry)))
3309 (filtered-attrs nil))
3310 ;; Filter each face attribute
3311 (while unfiltered-attrs
3312 (let* ((attr (pop unfiltered-attrs))
3313 (pre-filtered-value (pop unfiltered-attrs))
3315 (or (nth filter-index (assq attr custom-face-attributes))
3319 (funcall filter pre-filtered-value)
3320 pre-filtered-value)))
3321 (push filtered-value filtered-attrs)
3322 (push attr filtered-attrs)))
3324 (list tests filtered-attrs)))
3327 (defun custom-pre-filter-face-spec (spec)
3328 "Return SPEC changed as necessary for editing by the face customization widget.
3329 SPEC must be a full face spec."
3330 (custom-filter-face-spec spec 2))
3332 (defun custom-post-filter-face-spec (spec)
3333 "Return the customized SPEC in a form suitable for setting the face."
3334 (custom-filter-face-spec spec 3))
3336 (defun custom-face-value-create (widget)
3337 "Create a list of the display specifications for WIDGET."
3338 (let ((buttons (widget-get widget :buttons))
3340 (symbol (widget-get widget :value))
3341 (tag (widget-get widget :tag))
3342 (state (widget-get widget :custom-state))
3344 (is-last (widget-get widget :custom-last))
3345 (prefix (widget-get widget :custom-prefix)))
3347 (setq tag (prin1-to-string symbol)))
3348 (cond ((eq custom-buffer-style 'tree)
3349 (insert prefix (if is-last " `--- " " |--- "))
3350 (push (widget-create-child-and-convert
3351 widget 'custom-browse-face-tag)
3353 (insert " " tag "\n")
3354 (widget-put widget :buttons buttons))
3358 (widget-specify-sample widget begin (point))
3359 (if (eq custom-buffer-style 'face)
3361 (if (string-match "face\\'" tag)
3363 (insert " face: ")))
3365 (push (widget-create-child-and-convert widget 'item
3372 (push (widget-create-child-and-convert
3374 :help-echo "Hide or show this face."
3377 :action 'custom-toggle-parent
3378 (not (eq state 'hidden)))
3382 (let ((magic (widget-create-child-and-convert
3383 widget 'custom-magic nil)))
3384 (widget-put widget :custom-magic magic)
3385 (push magic buttons))
3387 (widget-put widget :buttons buttons)
3388 ;; Insert documentation.
3389 (widget-put widget :documentation-indent 3)
3390 (widget-add-documentation-string-button
3391 widget :visibility-widget 'custom-visibility)
3393 ;; The comment field
3394 (unless (eq state 'hidden)
3395 (let* ((comment (get symbol 'face-comment))
3397 (widget-create-child-and-convert
3398 widget 'custom-comment
3400 :value (or comment ""))))
3401 (widget-put widget :comment-widget comment-widget)
3402 (push comment-widget children)))
3404 (unless (eq state 'hidden)
3405 (when (eq (widget-get widget :custom-level) 1)
3406 (custom-add-parent-links widget))
3407 (custom-add-see-also widget))
3409 (unless (eq (preceding-char) ?\n)
3411 (unless (eq state 'hidden)
3412 (message "Creating face editor...")
3413 (custom-load-widget widget)
3414 (unless (widget-get widget :custom-form)
3415 (widget-put widget :custom-form custom-face-default-form))
3416 (let* ((symbol (widget-value widget))
3417 (spec (or (get symbol 'customized-face)
3418 (get symbol 'saved-face)
3419 (get symbol 'face-defface-spec)
3420 ;; Attempt to construct it.
3421 (list (list t (custom-face-attributes-get
3422 symbol (selected-frame))))))
3423 (form (widget-get widget :custom-form))
3424 (indent (widget-get widget :indent))
3426 ;; If the user has changed this face in some other way,
3427 ;; edit it as the user has specified it.
3428 (if (not (face-spec-match-p symbol spec (selected-frame)))
3429 (setq spec (list (list t (face-attr-construct symbol (selected-frame))))))
3430 (setq spec (custom-pre-filter-face-spec spec))
3431 (setq edit (widget-create-child-and-convert
3433 (cond ((and (eq form 'selected)
3434 (widget-apply custom-face-selected
3436 (when indent (insert-char ?\ indent))
3437 'custom-face-selected)
3438 ((and (not (eq form 'lisp))
3439 (widget-apply custom-face-all
3443 (when indent (insert-char ?\ indent))
3446 (custom-face-state-set widget)
3447 (push edit children)
3448 (widget-put widget :children children))
3449 (message "Creating face editor...done"))))))
3451 (defvar custom-face-menu
3452 `(("Set for Current Session" custom-face-set)
3453 ,@(when (or custom-file init-file-user)
3454 '(("Save for Future Sessions" custom-face-save)))
3455 ("Undo Edits" custom-redraw
3457 (memq (widget-get widget :custom-state) '(modified changed))))
3458 ("Reset to Saved" custom-face-reset-saved
3460 (or (get (widget-value widget) 'saved-face)
3461 (get (widget-value widget) 'saved-face-comment))))
3462 ,@(when (or custom-file init-file-user)
3463 '(("Erase Customization" custom-face-reset-standard
3465 (get (widget-value widget) 'face-defface-spec)))))
3466 ("---" ignore ignore)
3467 ("Add Comment" custom-comment-show custom-comment-invisible-p)
3468 ("---" ignore ignore)
3469 ("For Current Display" custom-face-edit-selected
3471 (not (eq (widget-get widget :custom-form) 'selected))))
3472 ("For All Kinds of Displays" custom-face-edit-all
3474 (not (eq (widget-get widget :custom-form) 'all))))
3475 ("Show Lisp Expression" custom-face-edit-lisp
3477 (not (eq (widget-get widget :custom-form) 'lisp)))))
3478 "Alist of actions for the `custom-face' widget.
3479 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3480 the menu entry, ACTION is the function to call on the widget when the
3481 menu is selected, and FILTER is a predicate which takes a `custom-face'
3482 widget as an argument, and returns non-nil if ACTION is valid on that
3483 widget. If FILTER is nil, ACTION is always valid.")
3485 (defun custom-face-edit-selected (widget)
3486 "Edit selected attributes of the value of WIDGET."
3487 (widget-put widget :custom-state 'unknown)
3488 (widget-put widget :custom-form 'selected)
3489 (custom-redraw widget))
3491 (defun custom-face-edit-all (widget)
3492 "Edit all attributes of the value of WIDGET."
3493 (widget-put widget :custom-state 'unknown)
3494 (widget-put widget :custom-form 'all)
3495 (custom-redraw widget))
3497 (defun custom-face-edit-lisp (widget)
3498 "Edit the Lisp representation of the value of WIDGET."
3499 (widget-put widget :custom-state 'unknown)
3500 (widget-put widget :custom-form 'lisp)
3501 (custom-redraw widget))
3503 (defun custom-face-state-set (widget)
3504 "Set the state of WIDGET."
3505 (let* ((symbol (widget-value widget))
3506 (comment (get symbol 'face-comment))
3510 (setq tmp (get symbol 'customized-face))
3511 (setq temp (get symbol 'customized-face-comment))
3513 (if (equal temp comment)
3517 (setq tmp (get symbol 'saved-face))
3518 (setq temp (get symbol 'saved-face-comment))
3520 (if (equal temp comment)
3522 ((eq 'user (caar (get symbol 'theme-face)))
3524 ((eq 'changed (caar (get symbol 'theme-face)))
3528 ((get symbol 'face-defface-spec)
3529 (if (equal comment nil)
3534 ;; If the user called set-face-attribute to change the default
3535 ;; for new frames, this face is "set outside of Customize".
3536 (if (and (not (eq state 'rogue))
3537 (get symbol 'face-modified))
3538 (setq state 'changed))
3539 (widget-put widget :custom-state state)))
3541 (defun custom-face-action (widget &optional event)
3542 "Show the menu for `custom-face' WIDGET.
3543 Optional EVENT is the location for the menu."
3544 (if (eq (widget-get widget :custom-state) 'hidden)
3545 (custom-toggle-hide widget)
3546 (let* ((completion-ignore-case t)
3547 (symbol (widget-get widget :value))
3548 (answer (widget-choose (concat "Operation on "
3549 (custom-unlispify-tag-name symbol))
3550 (custom-menu-filter custom-face-menu
3554 (funcall answer widget)))))
3556 (defun custom-face-set (widget)
3557 "Make the face attributes in WIDGET take effect."
3558 (let* ((symbol (widget-value widget))
3559 (child (car (widget-get widget :children)))
3560 (value (custom-post-filter-face-spec (widget-value child)))
3561 (comment-widget (widget-get widget :comment-widget))
3562 (comment (widget-value comment-widget)))
3563 (when (equal comment "")
3565 ;; Make the comment invisible by hand if it's empty
3566 (custom-comment-hide comment-widget))
3567 (put symbol 'customized-face value)
3568 (custom-push-theme 'theme-face symbol 'user 'set value)
3569 (if (face-spec-choose value)
3570 (face-spec-set symbol value t)
3571 ;; face-set-spec ignores empty attribute lists, so just give it
3572 ;; something harmless instead.
3573 (face-spec-set symbol '((t :foreground unspecified)) t))
3574 (put symbol 'customized-face-comment comment)
3575 (put symbol 'face-comment comment)
3576 (custom-face-state-set widget)
3577 (custom-redraw-magic widget)))
3579 (defun custom-face-mark-to-save (widget)
3580 "Mark for saving the face edited by WIDGET."
3581 (let* ((symbol (widget-value widget))
3582 (child (car (widget-get widget :children)))
3583 (value (custom-post-filter-face-spec (widget-value child)))
3584 (comment-widget (widget-get widget :comment-widget))
3585 (comment (widget-value comment-widget)))
3586 (when (equal comment "")
3588 ;; Make the comment invisible by hand if it's empty
3589 (custom-comment-hide comment-widget))
3590 (custom-push-theme 'theme-face symbol 'user 'set value)
3591 (if (face-spec-choose value)
3592 (face-spec-set symbol value t)
3593 ;; face-set-spec ignores empty attribute lists, so just give it
3594 ;; something harmless instead.
3595 (face-spec-set symbol '((t :foreground unspecified)) t))
3596 (unless (eq (widget-get widget :custom-state) 'standard)
3597 (put symbol 'saved-face value))
3598 (put symbol 'customized-face nil)
3599 (put symbol 'face-comment comment)
3600 (put symbol 'customized-face-comment nil)
3601 (put symbol 'saved-face-comment comment)))
3603 (defsubst custom-face-state-set-and-redraw (widget)
3604 "Set state of face widget WIDGET and redraw with current settings."
3605 (custom-face-state-set widget)
3606 (custom-redraw-magic widget))
3608 (defun custom-face-save (widget)
3609 "Save the face edited by WIDGET."
3610 (custom-face-mark-to-save widget)
3612 (custom-face-state-set-and-redraw widget))
3614 ;; For backward compatibility.
3615 (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
3618 (defun custom-face-reset-saved (widget)
3619 "Restore WIDGET to the face's default attributes."
3620 (let* ((symbol (widget-value widget))
3621 (child (car (widget-get widget :children)))
3622 (value (get symbol 'saved-face))
3623 (comment (get symbol 'saved-face-comment))
3624 (comment-widget (widget-get widget :comment-widget)))
3625 (unless (or value comment)
3626 (error "No saved value for this face"))
3627 (put symbol 'customized-face nil)
3628 (put symbol 'customized-face-comment nil)
3629 (custom-push-theme 'theme-face symbol 'user 'set value)
3630 (face-spec-set symbol value t)
3631 (put symbol 'face-comment comment)
3632 (widget-value-set child value)
3633 ;; This call manages the comment visibility
3634 (widget-value-set comment-widget (or comment ""))
3635 (custom-face-state-set widget)
3636 (custom-redraw-magic widget)))
3638 (defun custom-face-standard-value (widget)
3639 (get (widget-value widget) 'face-defface-spec))
3641 (defun custom-face-mark-to-reset-standard (widget)
3642 "Restore widget WIDGET to the face's standard attribute values.
3643 If `custom-reset-standard-faces-list' is nil, save, reset and
3644 redraw the widget immediately."
3645 (let* ((symbol (widget-value widget))
3646 (child (car (widget-get widget :children)))
3647 (value (get symbol 'face-defface-spec))
3648 (comment-widget (widget-get widget :comment-widget)))
3650 (error "No standard setting for this face"))
3651 (put symbol 'customized-face nil)
3652 (put symbol 'customized-face-comment nil)
3653 (custom-push-theme 'theme-face symbol 'user 'reset)
3654 (face-spec-set symbol value t)
3655 (custom-theme-recalc-face symbol)
3656 (if (and custom-reset-standard-faces-list
3657 (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
3660 (put symbol 'saved-face nil)
3661 (put symbol 'saved-face-comment nil)
3662 ;; Append this to `custom-reset-standard-faces-list' and have
3663 ;; `custom-reset-standard-save-and-update' save setting to the
3664 ;; file, update the widget's state, and redraw it.
3665 (setq custom-reset-standard-faces-list
3666 (cons widget custom-reset-standard-faces-list)))
3667 (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
3668 (put symbol 'saved-face nil)
3669 (put symbol 'saved-face-comment nil)
3671 (put symbol 'face-comment nil)
3672 (widget-value-set child
3673 (custom-pre-filter-face-spec
3674 (list (list t (custom-face-attributes-get
3676 ;; This call manages the comment visibility
3677 (widget-value-set comment-widget "")
3678 (custom-face-state-set widget)
3679 (custom-redraw-magic widget))))
3681 (defun custom-face-reset-standard (widget)
3682 "Restore WIDGET to the face's standard attribute values.
3683 This operation eliminates any saved attributes for the face,
3684 restoring it to the state of a face that has never been customized."
3685 (let (custom-reset-standard-faces-list)
3686 (custom-face-mark-to-reset-standard widget)))
3688 ;;; The `face' Widget.
3690 (defvar widget-face-prompt-value-history nil
3691 "History of input to `widget-face-prompt-value'.")
3693 (define-widget 'face 'symbol
3694 "A Lisp face name (with sample)."
3695 :format "%{%t%}: (%{sample%}) %v"
3698 :sample-face-get 'widget-face-sample-face-get
3699 :notify 'widget-face-notify
3700 :match (lambda (widget value) (facep value))
3701 :complete-function (lambda ()
3703 (lisp-complete-symbol 'facep))
3704 :prompt-match 'facep
3705 :prompt-history 'widget-face-prompt-value-history
3706 :validate (lambda (widget)
3707 (unless (facep (widget-value widget))
3709 :error (format "Invalid face: %S"
3710 (widget-value widget)))
3713 (defun widget-face-sample-face-get (widget)
3714 (let ((value (widget-value widget)))
3719 (defun widget-face-notify (widget child &optional event)
3720 "Update the sample, and notify the parent."
3721 (overlay-put (widget-get widget :sample-overlay)
3722 'face (widget-apply widget :sample-face-get))
3723 (widget-default-notify widget child event))
3726 ;;; The `hook' Widget.
3728 (define-widget 'hook 'list
3729 "An Emacs Lisp hook."
3730 :value-to-internal (lambda (widget value)
3731 (if (and value (symbolp value))
3734 :match (lambda (widget value)
3736 (widget-group-match widget value)))
3737 ;; Avoid adding undefined functions to the hook, especially for
3738 ;; things like `find-file-hook' or even more basic ones, to avoid
3740 :set (lambda (symbol value)
3743 (add-hook symbol elt))))
3744 :convert-widget 'custom-hook-convert-widget
3747 (defun custom-hook-convert-widget (widget)
3748 ;; Handle `:options'.
3749 (let* ((options (widget-get widget :options))
3750 (other `(editable-list :inline t
3751 :entry-format "%i %d%v"
3752 (function :format " %v")))
3754 (list `(checklist :inline t
3755 ,@(mapcar (lambda (entry)
3756 `(function-item ,entry))
3760 (widget-put widget :args args)
3763 ;;; The `custom-group-link' Widget.
3765 (define-widget 'custom-group-link 'link
3766 "Show parent in other window when activated."
3767 :button-face 'custom-link
3768 :mouse-face 'highlight
3769 :pressed-face 'highlight
3770 :help-echo "Create customization buffer for this group."
3771 :keymap custom-mode-link-map
3772 :follow-link 'mouse-face
3773 :action 'custom-group-link-action)
3775 (defun custom-group-link-action (widget &rest ignore)
3776 (customize-group (widget-value widget)))
3778 ;;; The `custom-group' Widget.
3780 (defcustom custom-group-tag-faces nil
3781 ;; In XEmacs, this ought to play games with font size.
3782 ;; Fixme: make it do so in Emacs.
3783 "Face used for group tags.
3784 The first member is used for level 1 groups, the second for level 2,
3785 and so forth. The remaining group tags are shown with `custom-group-tag'."
3786 :type '(repeat face)
3787 :group 'custom-faces)
3789 (defface custom-group-tag-1
3792 (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
3793 (((min-colors 88) (class color)
3795 (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
3798 (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
3800 "Face used for group tags."
3801 :group 'custom-faces)
3802 ;; backward-compatibility alias
3803 (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1)
3805 (defface custom-group-tag
3808 (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
3809 (((min-colors 88) (class color)
3811 (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
3814 (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
3816 "Face used for low level group tags."
3817 :group 'custom-faces)
3818 ;; backward-compatibility alias
3819 (put 'custom-group-tag-face 'face-alias 'custom-group-tag)
3821 (define-widget 'custom-group 'custom
3824 :sample-face-get 'custom-group-sample-face-get
3825 :documentation-property 'group-documentation
3826 :help-echo "Set or reset all members of this group."
3827 :value-create 'custom-group-value-create
3828 :action 'custom-group-action
3829 :custom-category 'group
3830 :custom-set 'custom-group-set
3831 :custom-mark-to-save 'custom-group-mark-to-save
3832 :custom-reset-current 'custom-group-reset-current
3833 :custom-reset-saved 'custom-group-reset-saved
3834 :custom-reset-standard 'custom-group-reset-standard
3835 :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
3836 :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
3837 :custom-menu 'custom-group-menu-create)
3839 (defun custom-group-sample-face-get (widget)
3840 ;; Use :sample-face.
3841 (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
3844 (define-widget 'custom-group-visibility 'visibility
3845 "An indicator and manipulator for hidden group contents."
3846 :create 'custom-group-visibility-create)
3848 (defun custom-group-visibility-create (widget)
3849 (let ((visible (widget-value widget)))
3851 (insert "--------")))
3852 (widget-default-create widget))
3854 (defun custom-group-members (symbol groups-only)
3855 "Return SYMBOL's custom group members.
3856 If GROUPS-ONLY non-nil, return only those members that are groups."
3857 (if (not groups-only)
3858 (get symbol 'custom-group)
3860 (dolist (entry (get symbol 'custom-group))
3861 (when (eq (nth 1 entry) 'custom-group)
3862 (push entry members)))
3863 (nreverse members))))
3865 (defun custom-group-value-create (widget)
3866 "Insert a customize group for WIDGET in the current buffer."
3867 (unless (eq (widget-get widget :custom-state) 'hidden)
3868 (custom-load-widget widget))
3869 (let* ((state (widget-get widget :custom-state))
3870 (level (widget-get widget :custom-level))
3871 ;; (indent (widget-get widget :indent))
3872 (prefix (widget-get widget :custom-prefix))
3873 (buttons (widget-get widget :buttons))
3874 (tag (widget-get widget :tag))
3875 (symbol (widget-value widget))
3876 (members (custom-group-members symbol
3877 (and (eq custom-buffer-style 'tree)
3878 custom-browse-only-groups))))
3879 (cond ((and (eq custom-buffer-style 'tree)
3881 (or members (custom-unloaded-widget-p widget)))
3882 (custom-browse-insert-prefix prefix)
3883 (push (widget-create-child-and-convert
3884 widget 'custom-browse-visibility
3885 ;; :tag-glyph "plus"
3889 ;; (widget-glyph-insert nil "-- " "horizontal")
3890 (push (widget-create-child-and-convert
3891 widget 'custom-browse-group-tag)
3893 (insert " " tag "\n")
3894 (widget-put widget :buttons buttons))
3895 ((and (eq custom-buffer-style 'tree)
3896 (zerop (length members)))
3897 (custom-browse-insert-prefix prefix)
3899 ;; (widget-glyph-insert nil "[ ]" "empty")
3900 ;; (widget-glyph-insert nil "-- " "horizontal")
3901 (push (widget-create-child-and-convert
3902 widget 'custom-browse-group-tag)
3904 (insert " " tag "\n")
3905 (widget-put widget :buttons buttons))
3906 ((eq custom-buffer-style 'tree)
3907 (custom-browse-insert-prefix prefix)
3908 (if (zerop (length members))
3910 (custom-browse-insert-prefix prefix)
3912 ;; (widget-glyph-insert nil "[ ]" "empty")
3913 ;; (widget-glyph-insert nil "-- " "horizontal")
3914 (push (widget-create-child-and-convert
3915 widget 'custom-browse-group-tag)
3917 (insert " " tag "\n")
3918 (widget-put widget :buttons buttons))
3919 (push (widget-create-child-and-convert
3920 widget 'custom-browse-visibility
3921 ;; :tag-glyph "minus"
3925 ;; (widget-glyph-insert nil "-\\ " "top")
3926 (push (widget-create-child-and-convert
3927 widget 'custom-browse-group-tag)
3929 (insert " " tag "\n")
3930 (widget-put widget :buttons buttons)
3931 (message "Creating group...")
3932 (let* ((members (custom-sort-items members
3933 custom-browse-sort-alphabetically
3934 custom-browse-order-groups))
3935 (prefixes (widget-get widget :custom-prefixes))
3936 (custom-prefix-list (custom-prefix-add symbol prefixes))
3937 (extra-prefix (if (widget-get widget :custom-last)
3940 (prefix (concat prefix extra-prefix))
3943 (setq entry (car members)
3944 members (cdr members))
3945 (push (widget-create-child-and-convert
3946 widget (nth 1 entry)
3948 :tag (custom-unlispify-tag-name (nth 0 entry))
3949 :custom-prefixes custom-prefix-list
3950 :custom-level (1+ level)
3951 :custom-last (null members)
3952 :value (nth 0 entry)
3953 :custom-prefix prefix)
3955 (widget-put widget :children (reverse children)))
3956 (message "Creating group...done")))
3959 ;; Create level indicator.
3961 (if (eq custom-buffer-style 'links)
3962 (push (widget-create-child-and-convert
3963 widget 'custom-group-link
3967 (insert-char ?\ (* custom-buffer-indent (1- level)))
3969 (push (widget-create-child-and-convert
3970 widget 'custom-group-visibility
3971 :help-echo "Show members of this group."
3972 :action 'custom-toggle-parent
3973 (not (eq state 'hidden)))
3976 ;; Create magic button.
3977 (let ((magic (widget-create-child-and-convert
3978 widget 'custom-magic nil)))
3979 (widget-put widget :custom-magic magic)
3980 (push magic buttons))
3982 (widget-put widget :buttons buttons)
3983 ;; Insert documentation.
3984 (if (and (eq custom-buffer-style 'links) (> level 1))
3985 (widget-put widget :documentation-indent 0))
3986 (widget-add-documentation-string-button
3987 widget :visibility-widget 'custom-visibility))
3991 ;; Add parent groups references above the group.
3992 (if t ;;; This should test that the buffer
3993 ;;; was made to display a group.
3995 (if (custom-add-parent-links widget
3997 "Parent group documentation:")
3999 ;; Create level indicator.
4000 (insert-char ?\ (* custom-buffer-indent (1- level)))
4003 (let ((start (point)))
4004 (insert tag " group: ")
4005 (widget-specify-sample widget start (point)))
4006 (insert (widget-docstring widget))
4007 ;; Create visibility indicator.
4008 (unless (eq custom-buffer-style 'links)
4010 (push (widget-create-child-and-convert
4012 :help-echo "Hide members of this group."
4013 :action 'custom-toggle-parent
4014 (not (eq state 'hidden)))
4017 ;; Create more dashes.
4018 ;; Use 76 instead of 75 to compensate for the temporary "<"
4019 ;; added by `widget-insert'.
4020 (insert-char ?- (- 76 (current-column)
4021 (* custom-buffer-indent level)))
4023 ;; Create magic button.
4024 (let ((magic (widget-create-child-and-convert
4025 widget 'custom-magic
4028 (widget-put widget :custom-magic magic)
4029 (push magic buttons))
4031 (widget-put widget :buttons buttons)
4032 ;; Insert documentation.
4033 (widget-add-documentation-string-button
4034 widget :visibility-widget 'custom-visibility)
4037 (if nil ;;; This should test that the buffer
4038 ;;; was not made to display a group.
4040 (insert-char ?\ custom-buffer-indent)
4041 (custom-add-parent-links widget)))
4042 (custom-add-see-also widget
4043 (make-string (* custom-buffer-indent level)
4046 (message "Creating group...")
4047 (let* ((members (custom-sort-items members
4048 custom-buffer-sort-alphabetically
4049 custom-buffer-order-groups))
4050 (prefixes (widget-get widget :custom-prefixes))
4051 (custom-prefix-list (custom-prefix-add symbol prefixes))
4052 (length (length members))
4054 (children (mapcar (lambda (entry)
4055 (widget-insert "\n")
4057 Creating group members... %2d%%"
4058 (/ (* 100.0 count) length))
4059 (setq count (1+ count))
4061 (widget-create-child-and-convert
4062 widget (nth 1 entry)
4064 :tag (custom-unlispify-tag-name
4066 :custom-prefixes custom-prefix-list
4067 :custom-level (1+ level)
4068 :value (nth 0 entry))
4069 (unless (eq (preceding-char) ?\n)
4070 (widget-insert "\n"))))
4072 (message "Creating group magic...")
4073 (mapc 'custom-magic-reset children)
4074 (message "Creating group state...")
4075 (widget-put widget :children children)
4076 (custom-group-state-update widget)
4077 (message "Creating group... done"))
4080 (insert-char ?\ (* custom-buffer-indent (1- level)))
4081 (insert "\\- " (widget-get widget :tag) " group end ")
4082 (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level)))
4085 (defvar custom-group-menu
4086 `(("Set for Current Session" custom-group-set
4088 (eq (widget-get widget :custom-state) 'modified)))
4089 ,@(when (or custom-file init-file-user)
4090 '(("Save for Future Sessions" custom-group-save
4092 (memq (widget-get widget :custom-state) '(modified set))))))
4093 ("Undo Edits" custom-group-reset-current
4095 (memq (widget-get widget :custom-state) '(modified))))
4096 ("Reset to Saved" custom-group-reset-saved
4098 (memq (widget-get widget :custom-state) '(modified set))))
4099 ,@(when (or custom-file init-file-user)
4100 '(("Erase Customization" custom-group-reset-standard
4102 (memq (widget-get widget :custom-state) '(modified set saved)))))))
4103 "Alist of actions for the `custom-group' widget.
4104 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4105 the menu entry, ACTION is the function to call on the widget when the
4106 menu is selected, and FILTER is a predicate which takes a `custom-group'
4107 widget as an argument, and returns non-nil if ACTION is valid on that
4108 widget. If FILTER is nil, ACTION is always valid.")
4110 (defun custom-group-action (widget &optional event)
4111 "Show the menu for `custom-group' WIDGET.
4112 Optional EVENT is the location for the menu."
4113 (if (eq (widget-get widget :custom-state) 'hidden)
4114 (custom-toggle-hide widget)
4115 (let* ((completion-ignore-case t)
4116 (answer (widget-choose (concat "Operation on "
4117 (custom-unlispify-tag-name
4118 (widget-get widget :value)))
4119 (custom-menu-filter custom-group-menu
4123 (funcall answer widget)))))
4125 (defun custom-group-set (widget)
4126 "Set changes in all modified group members."
4127 (dolist (child (widget-get widget :children))
4128 (when (eq (widget-get child :custom-state) 'modified)
4129 (widget-apply child :custom-set))))
4131 (defun custom-group-mark-to-save (widget)
4132 "Mark all modified group members for saving."
4133 (dolist (child (widget-get widget :children))
4134 (when (memq (widget-get child :custom-state) '(modified set))
4135 (widget-apply child :custom-mark-to-save))))
4137 (defsubst custom-group-state-set-and-redraw (widget)
4138 "Set state of group widget WIDGET and redraw with current settings."
4139 (dolist (child (widget-get widget :children))
4140 (when (memq (widget-get child :custom-state) '(modified set))
4141 (widget-apply child :custom-state-set-and-redraw))))
4143 (defun custom-group-save (widget)
4144 "Save all modified group members."
4145 (custom-group-mark-to-save widget)
4147 (custom-group-state-set-and-redraw widget))
4149 (defun custom-group-reset-current (widget)
4150 "Reset all modified group members."
4151 (dolist (child (widget-get widget :children))
4152 (when (eq (widget-get child :custom-state) 'modified)
4153 (widget-apply child :custom-reset-current))))
4155 (defun custom-group-reset-saved (widget)
4156 "Reset all modified or set group members."
4157 (dolist (child (widget-get widget :children))
4158 (when (memq (widget-get child :custom-state) '(modified set))
4159 (widget-apply child :custom-reset-saved))))
4161 (defun custom-group-reset-standard (widget)
4162 "Reset all modified, set, or saved group members."
4163 (let ((custom-reset-standard-variables-list '(t))
4164 (custom-reset-standard-faces-list '(t)))
4165 (custom-group-mark-to-reset-standard widget)
4166 (custom-reset-standard-save-and-update)))
4168 (defun custom-group-mark-to-reset-standard (widget)
4169 "Mark to reset all modified, set, or saved group members."
4170 (dolist (child (widget-get widget :children))
4171 (when (memq (widget-get child :custom-state)
4172 '(modified set saved))
4173 (widget-apply child :custom-mark-to-reset-standard))))
4175 (defun custom-group-state-update (widget)
4177 (unless (eq (widget-get widget :custom-state) 'hidden)
4178 (let* ((children (widget-get widget :children))
4179 (states (mapcar (lambda (child)
4180 (widget-get child :custom-state))
4182 (magics custom-magic-alist)
4185 (let ((magic (car (car magics))))
4186 (if (and (not (eq magic 'hidden))
4187 (memq magic states))
4190 (setq magics (cdr magics)))))
4191 (widget-put widget :custom-state found)))
4192 (custom-magic-reset widget))
4194 ;;; Reading and writing the custom file.
4197 (defcustom custom-file nil
4198 "File used for storing customization information.
4199 The default is nil, which means to use your init file
4200 as specified by `user-init-file'. If the value is not nil,
4201 it should be an absolute file name.
4203 You can set this option through Custom, if you carefully read the
4204 last paragraph below. However, usually it is simpler to write
4205 something like the following in your init file:
4207 \(setq custom-file \"~/.emacs-custom.el\")
4210 Note that both lines are necessary: the first line tells Custom to
4211 save all customizations in this file, but does not load it.
4213 When you change this variable outside Custom, look in the
4214 previous custom file \(usually your init file) for the
4215 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4216 and copy them (whichever ones you find) to the new custom file.
4217 This will preserve your existing customizations.
4219 If you save this option using Custom, Custom will write all
4220 currently saved customizations, including the new one for this
4221 option itself, into the file you specify, overwriting any
4222 `custom-set-variables' and `custom-set-faces' forms already
4223 present in that file. It will not delete any customizations from
4224 the old custom file. You should do that manually if that is what you
4225 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4226 in your init file, where CUSTOM-FILE is the actual name of the
4227 file. Otherwise, Emacs will not load the file when it starts up,
4228 and hence will not set `custom-file' to that file either."
4229 :type '(choice (const :tag "Your Emacs init file" nil)
4230 (file :format "%t:%v%d"
4232 "Please read entire docstring below before setting \
4233 this through Custom.
4234 Click om \"More\" \(or position point there and press RETURN)
4235 if only the first line of the docstring is shown."))
4238 (defun custom-file ()
4239 "Return the file name for saving customizations."
4242 (let ((user-init-file user-init-file)
4244 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
4245 (when (null user-init-file)
4246 (if (or (file-exists-p default-init-file)
4247 (and (eq system-type 'windows-nt)
4248 (file-exists-p "~/_emacs")))
4249 ;; Started with -q, i.e. the file containing
4250 ;; Custom settings hasn't been read. Saving
4251 ;; settings there would overwrite other settings.
4252 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4253 (setq user-init-file default-init-file))
4256 ;; If recentf-mode is non-nil, this is defined.
4257 (declare-function recentf-expand-file-name "recentf" (name))
4260 (defun custom-save-all ()
4261 "Save all customizations in `custom-file'."
4262 (when (and (null custom-file) init-file-had-error)
4263 (error "Cannot save customizations; init file was not fully loaded"))
4264 (let* ((filename (custom-file))
4269 (recentf-expand-file-name (custom-file)))
4272 (old-buffer (find-buffer-visiting filename)))
4273 (with-current-buffer (let ((find-file-visit-truename t))
4274 (or old-buffer (find-file-noselect filename)))
4275 (unless (eq major-mode 'emacs-lisp-mode)
4277 (let ((inhibit-read-only t))
4278 (custom-save-variables)
4279 (custom-save-faces))
4280 (let ((file-precious-flag t))
4283 (kill-buffer (current-buffer))))))
4286 (defun customize-save-customized ()
4287 "Save all user options which have been set in this session."
4289 (mapatoms (lambda (symbol)
4290 (let ((face (get symbol 'customized-face))
4291 (value (get symbol 'customized-value))
4292 (face-comment (get symbol 'customized-face-comment))
4294 (get symbol 'customized-variable-comment)))
4296 (put symbol 'saved-face face)
4297 (custom-push-theme 'theme-face symbol 'user 'set value)
4298 (put symbol 'customized-face nil))
4300 (put symbol 'saved-value value)
4301 (custom-push-theme 'theme-value symbol 'user 'set value)
4302 (put symbol 'customized-value nil))
4303 (when variable-comment
4304 (put symbol 'saved-variable-comment variable-comment)
4305 (put symbol 'customized-variable-comment nil))
4307 (put symbol 'saved-face-comment face-comment)
4308 (put symbol 'customized-face-comment nil)))))
4309 ;; We really should update all custom buffers here.
4312 ;; Editing the custom file contents in a buffer.
4314 (defun custom-save-delete (symbol)
4315 "Delete all calls to SYMBOL from the contents of the current buffer.
4316 Leave point at the old location of the first such call,
4317 or (if there were none) at the end of the buffer.
4319 This function does not save the buffer."
4320 (goto-char (point-min))
4321 ;; Skip all whitespace and comments.
4322 (while (forward-comment 1))
4324 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4327 (while t ;; We exit this loop only via throw.
4328 ;; Skip all whitespace and comments.
4329 (while (forward-comment 1))
4330 (let ((start (point))
4331 (sexp (condition-case nil
4332 (read (current-buffer))
4333 (end-of-file (throw 'found nil)))))
4334 (when (and (listp sexp)
4335 (eq (car sexp) symbol))
4336 (delete-region start (point))
4338 (setq first (point)))))))
4341 ;; Move in front of local variables, otherwise long Custom
4342 ;; entries would make them ineffective.
4343 (let ((pos (point-max))
4344 (case-fold-search t))
4346 (goto-char (point-max))
4347 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4349 (when (search-forward "Local Variables:" nil t)
4350 (setq pos (line-beginning-position))))
4353 (defun custom-save-variables ()
4354 "Save all customized variables in `custom-file'."
4356 (custom-save-delete 'custom-set-variables)
4357 (let ((standard-output (current-buffer))
4358 (saved-list (make-list 1 0))
4360 ;; First create a sorted list of saved variables.
4363 (if (and (get symbol 'saved-value)
4364 ;; ignore theme values
4365 (or (null (get symbol 'theme-value))
4366 (eq 'user (caar (get symbol 'theme-value)))))
4367 (nconc saved-list (list symbol)))))
4368 (setq saved-list (sort (cdr saved-list) 'string<))
4371 (princ "(custom-set-variables
4372 ;; custom-set-variables was added by Custom.
4373 ;; If you edit it by hand, you could mess it up, so be careful.
4374 ;; Your init file should contain only one such instance.
4375 ;; If there is more than one, they won't work right.\n")
4376 (dolist (symbol saved-list)
4377 (let ((spec (car-safe (get symbol 'theme-value)))
4378 (value (get symbol 'saved-value))
4379 (requests (get symbol 'custom-requests))
4380 (now (and (not (custom-variable-p symbol))
4382 (eq (get symbol 'force-value)
4384 (comment (get symbol 'saved-variable-comment)))
4385 ;; Check REQUESTS for validity.
4386 (dolist (request requests)
4387 (when (and (symbolp request) (not (featurep request)))
4388 (message "Unknown requested feature: %s" request)
4389 (setq requests (delq request requests))))
4390 ;; Is there anything customized about this variable?
4391 (when (or (and spec (eq (car spec) 'user))
4393 (and (null spec) (get symbol 'saved-value)))
4394 ;; Output an element for this variable.
4395 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4396 ;; SYMBOL is the variable name.
4397 ;; VALUE-FORM is an expression to return the customized value.
4398 ;; NOW if non-nil means always set the variable immediately
4399 ;; when the customizations are reloaded. This is used
4400 ;; for rogue variables
4401 ;; REQUESTS is a list of packages to load before setting the
4402 ;; variable. Each element of it will be passed to `require'.
4403 ;; COMMENT is whatever comment the user has specified
4404 ;; with the customize facility.
4411 (when (or now requests comment)
4414 (when (or requests comment)
4424 (unless (looking-at "\n")
4427 (defun custom-save-faces ()
4428 "Save all customized faces in `custom-file'."
4430 (custom-save-delete 'custom-reset-faces)
4431 (custom-save-delete 'custom-set-faces)
4432 (let ((standard-output (current-buffer))
4433 (saved-list (make-list 1 0))
4435 ;; First create a sorted list of saved faces.
4438 (if (and (get symbol 'saved-face)
4439 (eq 'user (car (car-safe (get symbol 'theme-face)))))
4440 (nconc saved-list (list symbol)))))
4441 (setq saved-list (sort (cdr saved-list) 'string<))
4442 ;; The default face must be first, since it affects the others.
4443 (if (memq 'default saved-list)
4444 (setq saved-list (cons 'default (delq 'default saved-list))))
4447 (princ "(custom-set-faces
4448 ;; custom-set-faces was added by Custom.
4449 ;; If you edit it by hand, you could mess it up, so be careful.
4450 ;; Your init file should contain only one such instance.
4451 ;; If there is more than one, they won't work right.\n")
4452 (dolist (symbol saved-list)
4453 (let ((spec (car-safe (get symbol 'theme-face)))
4454 (value (get symbol 'saved-face))
4455 (now (not (or (get symbol 'face-defface-spec)
4456 (and (not (custom-facep symbol))
4457 (not (get symbol 'force-face))))))
4458 (comment (get symbol 'saved-face-comment)))
4459 (when (or (and spec (eq (nth 0 spec) 'user))
4461 (and (null spec) (get symbol 'saved-face)))
4462 ;; Don't print default face here.
4469 (when (or now comment)
4479 (unless (looking-at "\n")
4482 ;;; The Customize Menu.
4486 (defcustom custom-menu-nesting 2
4487 "Maximum nesting in custom menus."
4489 :group 'custom-menu)
4491 (defun custom-face-menu-create (widget symbol)
4492 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4493 (vector (custom-unlispify-menu-entry symbol)
4494 `(customize-face ',symbol)
4497 (defun custom-variable-menu-create (widget symbol)
4498 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4499 (let ((type (get symbol 'custom-type)))
4500 (unless (listp type)
4501 (setq type (list type)))
4502 (if (and type (widget-get type :custom-menu))
4503 (widget-apply type :custom-menu symbol)
4504 (vector (custom-unlispify-menu-entry symbol)
4505 `(customize-variable ',symbol)
4508 ;; Add checkboxes to boolean variable entries.
4509 (widget-put (get 'boolean 'widget-type)
4510 :custom-menu (lambda (widget symbol)
4511 (vector (custom-unlispify-menu-entry symbol)
4512 `(customize-variable ',symbol)
4514 ':selected symbol)))
4516 (defun custom-group-menu-create (widget symbol)
4517 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4518 `( ,(custom-unlispify-menu-entry symbol t)
4519 :filter (lambda (&rest junk)
4520 (let* ((menu (custom-menu-create ',symbol)))
4521 (if (consp menu) (cdr menu) menu)))))
4524 (defun custom-menu-create (symbol)
4525 "Create menu for customization group SYMBOL.
4526 The menu is in a format applicable to `easy-menu-define'."
4527 (let* ((deactivate-mark nil)
4528 (item (vector (custom-unlispify-menu-entry symbol)
4529 `(customize-group ',symbol)
4531 (if (and (or (not (boundp 'custom-menu-nesting))
4532 (>= custom-menu-nesting 0))
4534 (custom-load-symbol symbol)
4535 (< (length (get symbol 'custom-group)) widget-menu-max-size)))
4536 (let ((custom-prefix-list (custom-prefix-add symbol
4537 custom-prefix-list))
4538 (members (custom-sort-items (get symbol 'custom-group)
4539 custom-menu-sort-alphabetically
4540 custom-menu-order-groups)))
4541 `(,(custom-unlispify-menu-entry symbol t)
4544 ,@(mapcar (lambda (entry)
4545 (widget-apply (if (listp (nth 1 entry))
4547 (list (nth 1 entry)))
4548 :custom-menu (nth 0 entry)))
4553 (defun customize-menu-create (symbol &optional name)
4554 "Return a customize menu for customization group SYMBOL.
4555 If optional NAME is given, use that as the name of the menu.
4556 Otherwise the menu will be named `Customize'.
4557 The format is suitable for use with `easy-menu-define'."
4559 (setq name "Customize"))
4561 :filter (lambda (&rest junk)
4562 (let ((menu (custom-menu-create ',symbol)))
4563 (if (consp menu) (cdr menu) menu)))))
4565 ;;; Toolbar and menubar support
4568 Custom-mode-menu (list custom-mode-map custom-field-keymap)
4569 "Menu used in customization buffers."
4570 (nconc (list "Custom"
4571 (customize-menu-create 'customize))
4572 (mapcar (lambda (arg)
4573 (let ((tag (nth 0 arg))
4574 (command (nth 1 arg))
4575 (active (nth 2 arg))
4577 (vector tag command :active (eval active) :help help)))
4580 (defvar tool-bar-map)
4582 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4583 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4584 ;;; we set this up lazily in `Custom-mode'.
4585 (defvar custom-tool-bar-map nil
4586 "Keymap for toolbar in Custom mode.")
4588 ;;; The Custom Mode.
4590 (defun Custom-no-edit (pos &optional event)
4591 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4593 (error "You can't edit this part of the Custom buffer"))
4595 (defun Custom-newline (pos &optional event)
4596 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4598 (let ((button (get-char-property pos 'button)))
4600 (widget-apply-action button event)
4601 (error "You can't edit this part of the Custom buffer"))))
4603 (defun Custom-goto-parent ()
4604 "Go to the parent group listed at the top of this buffer.
4605 If several parents are listed, go to the first of them."
4608 (goto-char (point-min))
4609 (if (search-forward "\nParent groups: " nil t)
4610 (let* ((button (get-char-property (point) 'button))
4611 (parent (downcase (widget-get button :tag))))
4612 (customize-group parent)))))
4614 (defcustom Custom-mode-hook nil
4615 "Hook called when entering Custom mode."
4617 :group 'custom-buffer)
4619 (defun custom-state-buffer-message (widget)
4620 (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
4621 (message "To install your edits, invoke [State] and choose the Set operation")))
4623 (define-derived-mode Custom-mode nil "Custom"
4624 "Major mode for editing customization buffers.
4626 The following commands are available:
4629 Move to next button, link or editable field. \\[widget-forward]
4630 Move to previous button, link or editable field. \\[advertised-widget-backward]
4631 \\<custom-field-keymap>\
4632 Complete content of editable text field. \\[widget-complete]
4633 \\<custom-mode-map>\
4634 Invoke button under the mouse pointer. \\[widget-button-click]
4635 Invoke button under point. \\[widget-button-press]
4636 Set all options from current text. \\[Custom-set]
4637 Make values in current text permanent. \\[Custom-save]
4638 Make text match actual option values. \\[Custom-reset-current]
4639 Reset options to permanent settings. \\[Custom-reset-saved]
4640 Erase customizations; set options
4641 and buffer text to the standard values. \\[Custom-reset-standard]
4643 Entry to this mode calls the value of `Custom-mode-hook'
4644 if that value is non-nil."
4645 (use-local-map custom-mode-map)
4646 (easy-menu-add Custom-mode-menu)
4647 (when (display-graphic-p)
4648 (set (make-local-variable 'tool-bar-map)
4649 (or custom-tool-bar-map
4650 ;; Set up `custom-tool-bar-map'.
4651 (let ((map (make-sparse-keymap)))
4654 (tool-bar-local-item-from-menu
4655 (nth 1 arg) (nth 4 arg) map custom-mode-map))
4657 (setq custom-tool-bar-map map)))))
4658 (make-local-variable 'custom-options)
4659 (make-local-variable 'custom-local-buffer)
4660 (make-local-variable 'widget-documentation-face)
4661 (setq widget-documentation-face 'custom-documentation)
4662 (make-local-variable 'widget-button-face)
4663 (setq widget-button-face custom-button)
4664 (setq show-trailing-whitespace nil)
4666 ;; We need this because of the "More" button on docstrings.
4667 ;; Otherwise clicking on "More" can push point offscreen, which
4668 ;; causes the window to recenter on point, which pushes the
4669 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4670 (set (make-local-variable 'widget-button-click-moves-point) t)
4672 (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
4673 (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
4675 ;; When possible, use relief for buttons, not bracketing. This test
4676 ;; may not be optimal.
4677 (when custom-raised-buttons
4678 (set (make-local-variable 'widget-push-button-prefix) "")
4679 (set (make-local-variable 'widget-push-button-suffix) "")
4680 (set (make-local-variable 'widget-link-prefix) "")
4681 (set (make-local-variable 'widget-link-suffix) ""))
4682 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
4684 (put 'Custom-mode 'mode-class 'special)
4686 ;; backward-compatibility
4687 (defun custom-mode ()
4688 "Non-interactive variant of `Custom-mode'."
4690 (make-obsolete 'custom-mode 'Custom-mode "23.1")
4691 (put 'custom-mode 'mode-class 'special)
4692 (define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1")
4695 '("^No user option defaults have been changed since Emacs "
4697 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4698 "^No customizable items matching "
4699 "^There are unset changes"
4700 "^Cannot set hidden variable"
4701 "^No \\(?:saved\\|backup\\) value for "
4702 "^No standard setting known for "
4703 "^No standard setting for this face"
4704 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4705 (add-to-list 'debug-ignored-errors regexp))
4711 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4712 ;;; cus-edit.el ends here