1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
)) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link
'(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag
"Storage Allocation"
388 "Undoing changes in buffers."
389 :link
'(custom-manual "(emacs)Undo")
392 (defgroup modeline nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controling the behavior of the minibuffer."
426 :link
'(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidential loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link
'(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link
'(custom-manual "(emacs)Mac OS")
471 (defun custom-quote (sexp)
472 "Quote SEXP iff it is not self quoting."
473 (if (or (memq sexp
'(t nil
))
476 (memq (car sexp
) '(lambda)))
480 ;;; (and (fboundp 'characterp)
481 ;;; (characterp sexp))
486 (defun custom-split-regexp-maybe (regexp)
487 "If REGEXP is a string, split it to a list at `\\|'.
488 You can get the original back with from the result with:
489 (mapconcat 'identity result \"\\|\")
491 IF REGEXP is not a string, return it unchanged."
495 (while (string-match "\\\\|" regexp start
)
496 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
497 start
(match-end 0)))
498 (nreverse (cons (substring regexp start
) all
)))
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
506 (enable-recursive-minibuffers t
)
508 (setq val
(completing-read
509 (if default
(format "Customize variable (default %s): " default
)
510 "Customize variable: ")
511 obarray
'custom-variable-p t nil nil default
))
512 (list (if (equal val
"")
513 (if (symbolp v
) v nil
)
516 (defun custom-menu-filter (menu widget
)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
521 current name action filter
)
523 (setq current
(car menu
)
525 action
(nth 1 current
)
526 filter
(nth 2 current
)
528 (if (or (null filter
) (funcall filter widget
))
529 (push (cons name action
) result
)
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non nil."
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
546 :group
'custom-buffer
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries
)
552 (symbol-name symbol
))
553 ((get symbol
'custom-tag
)
555 (get symbol
'custom-tag
)
556 (concat (get symbol
'custom-tag
) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
560 (princ symbol
(current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list
)
572 (setq prefix
(car prefixes
))
573 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
576 (delete-region (point-min) (point)))
577 (setq prefixes
(cdr prefixes
))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
579 (capitalize-region (point-min) (point-max))
581 (goto-char (point-max))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non nil."
587 :group
'custom-buffer
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
593 (custom-unlispify-menu-entry symbol t
)))
595 (defun custom-prefix-add (symbol prefixes
)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol
'custom-prefix
)
598 (concat (symbol-name symbol
) "-"))
603 (defcustom custom-guess-name-alist
608 ("-function\\'" function
)
609 ("-functions\\'" (repeat function
))
610 ("-list\\'" (repeat sexp
))
611 ("-alist\\'" (repeat (cons sexp sexp
))))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching the name of a symbol, and TYPE should
615 be a widget suitable for editing the value of that symbol. The TYPE
616 of the first entry where MATCH matches the name of the symbol will be
619 This is used for guessing the type of variables not declared with
621 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
624 (defcustom custom-guess-doc-alist
625 '(("\\`\\*?Non-nil " boolean
))
626 "Alist of (MATCH TYPE).
628 MATCH should be a regexp matching a documentation string, and TYPE
629 should be a widget suitable for editing the value of a variable with
630 that documentation string. The TYPE of the first entry where MATCH
631 matches the name of the symbol will be used.
633 This is used for guessing the type of variables not declared with
635 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
638 (defun custom-guess-type (symbol)
639 "Guess a widget suitable for editing the value of SYMBOL.
640 This is done by matching SYMBOL with `custom-guess-name-alist' and
641 if that fails, the doc string with `custom-guess-doc-alist'."
642 (let ((name (symbol-name symbol
))
643 (names custom-guess-name-alist
)
646 (setq current
(car names
)
648 (when (string-match (nth 0 current
) name
)
649 (setq found
(nth 1 current
)
652 (let ((doc (documentation-property symbol
'variable-documentation
))
653 (docs custom-guess-doc-alist
))
656 (setq current
(car docs
)
658 (when (string-match (nth 0 current
) doc
)
659 (setq found
(nth 1 current
)
665 (defcustom custom-browse-sort-alphabetically nil
666 "If non-nil, sort members of each customization group alphabetically."
668 :group
'custom-browse
)
670 (defcustom custom-browse-order-groups nil
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type
'(choice (const first
)
676 (const :tag
"none" nil
))
677 :group
'custom-browse
)
679 (defcustom custom-browse-only-groups nil
680 "If non-nil, show group members only within each customization group."
682 :group
'custom-browse
)
684 (defcustom custom-buffer-sort-alphabetically nil
685 "If non-nil, sort members of each customization group alphabetically."
687 :group
'custom-buffer
)
689 (defcustom custom-buffer-order-groups
'last
690 "If non-nil, order group members within each customization group.
691 If `first', order groups before non-groups.
692 If `last', order groups after non-groups."
693 :type
'(choice (const first
)
695 (const :tag
"none" nil
))
696 :group
'custom-buffer
)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort members of each customization group alphabetically."
703 (defcustom custom-menu-order-groups
'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups
)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items
)
722 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
723 (namea (nth 0 a
)) (nameb (nth 0 b
)))
724 (cond ((not order-groups
)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb
)))
728 ((eq typea
'custom-group
)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb
'custom-group
)
731 (when sort-alphabetically
732 (string-lessp namea nameb
))
733 (eq order-groups
'first
)))
734 ((eq typeb
'custom-group
)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups
'last
))
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb
)))))))
741 ;;; Custom Mode Commands.
743 (defvar custom-options nil
744 "Customization widgets in the current buffer.")
747 "Set changes in all modified options."
749 (if (y-or-n-p "Set all values according to this buffer? ")
750 (let ((children custom-options
))
751 (mapc (lambda (child)
752 (when (eq (widget-get child
:custom-state
) 'modified
)
753 (widget-apply child
:custom-set
)))
755 (message "Aborted")))
757 (defun Custom-save ()
758 "Set all modified group members and save them."
760 (if (yes-or-no-p "Save all settings in this buffer? ")
761 (let ((children custom-options
))
762 (mapc (lambda (child)
763 (when (memq (widget-get child
:custom-state
)
764 '(modified set changed rogue
))
765 (widget-apply child
:custom-save
)))
768 (message "Aborted")))
770 (defvar custom-reset-menu
771 '(("Current" . Custom-reset-current
)
772 ("Saved" . Custom-reset-saved
)
773 ("Erase Customization (use standard values)" . Custom-reset-standard
))
774 "Alist of actions for the `Reset' button.
775 The key is a string containing the name of the action, the value is a
776 Lisp function taking the widget as an element which will be called
777 when the action is chosen.")
779 (defun custom-reset (event)
780 "Select item from reset menu."
781 (let* ((completion-ignore-case t
)
782 (answer (widget-choose "Reset to"
788 (defun Custom-reset-current (&rest ignore
)
789 "Reset all modified group members to their current value."
791 (if (y-or-n-p "Update buffer text to show all current settings? ")
792 (let ((children custom-options
))
793 (mapc (lambda (widget)
794 (if (memq (widget-get widget
:custom-state
)
796 (widget-apply widget
:custom-reset-current
)))
798 (message "Aborted")))
800 (defun Custom-reset-saved (&rest ignore
)
801 "Reset all modified or set group members to their saved value."
803 (if (y-or-n-p "Update buffer text to show all saved settings? ")
804 (let ((children custom-options
))
805 (mapc (lambda (widget)
806 (if (memq (widget-get widget
:custom-state
)
807 '(modified set changed rogue
))
808 (widget-apply widget
:custom-reset-saved
)))
810 (message "Aborted")))
812 (defun Custom-reset-standard (&rest ignore
)
813 "Erase all customization (either current or saved) for the group members.
814 The immediate result is to restore them to their standard values.
815 This operation eliminates any saved values for the group members,
816 making them as if they had never been customized at all."
818 (let ((children custom-options
))
819 (if (or (and (= 1 (length children
))
820 (memq (widget-type (car children
))
821 '(custom-variable custom-face
)))
822 (yes-or-no-p "Really erase all customizations in this buffer? "))
823 (mapc (lambda (widget)
824 (and (if (widget-get widget
:custom-standard-value
)
825 (widget-apply widget
:custom-standard-value
)
827 (memq (widget-get widget
:custom-state
)
828 '(modified set changed saved rogue
))
829 (widget-apply widget
:custom-reset-standard
)))
831 (message "Aborted"))))
833 ;;; The Customize Commands
835 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
836 "Prompt for a variable and a value and return them as a list.
837 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
838 prompt for the value. The %s escape in PROMPT-VAL is replaced with
839 the name of the variable.
841 If the variable has a `variable-interactive' property, that is used as if
842 it were the arg to `interactive' (which see) to interactively read the value.
844 If the variable has a `custom-type' property, it must be a widget and the
845 `:prompt-value' property of that widget will be used for reading the value.
847 If optional COMMENT argument is non nil, also prompt for a comment and return
848 it as the third element in the list."
849 (let* ((var (read-variable prompt-var
))
850 (minibuffer-help-form '(describe-variable var
))
852 (let ((prop (get var
'variable-interactive
))
853 (type (get var
'custom-type
))
854 (prompt (format prompt-val var
)))
856 (setq type
(list type
)))
858 ;; Use VAR's `variable-interactive' property
859 ;; as an interactive spec for prompting.
860 (call-interactively (list 'lambda
'(arg)
861 (list 'interactive prop
)
864 (widget-prompt-value type
870 (eval-minibuffer prompt
))))))
873 (read-string "Comment: " (get var
'variable-comment
)))
877 (defun customize-set-value (variable value
&optional comment
)
878 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
880 If VARIABLE has a `variable-interactive' property, that is used as if
881 it were the arg to `interactive' (which see) to interactively read the value.
883 If VARIABLE has a `custom-type' property, it must be a widget and the
884 `:prompt-value' property of that widget will be used for reading the value.
886 If given a prefix (or a COMMENT argument), also prompt for a comment."
887 (interactive (custom-prompt-variable "Set variable: "
891 (cond ((string= comment
"")
892 (put variable
'variable-comment nil
))
894 (put variable
'variable-comment comment
)))
895 (set variable value
))
898 (defun customize-set-variable (variable value
&optional comment
)
899 "Set the default for VARIABLE to VALUE, and return VALUE.
900 VALUE is a Lisp object.
902 If VARIABLE has a `custom-set' property, that is used for setting
903 VARIABLE, otherwise `set-default' is used.
905 The `customized-value' property of the VARIABLE will be set to a list
906 with a quoted VALUE as its sole list member.
908 If VARIABLE has a `variable-interactive' property, that is used as if
909 it were the arg to `interactive' (which see) to interactively read the value.
911 If VARIABLE has a `custom-type' property, it must be a widget and the
912 `:prompt-value' property of that widget will be used for reading the value.
914 If given a prefix (or a COMMENT argument), also prompt for a comment."
915 (interactive (custom-prompt-variable "Set variable: "
916 "Set customized value for %s to: "
918 (custom-load-symbol variable
)
919 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
920 (put variable
'customized-value
(list (custom-quote value
)))
921 (cond ((string= comment
"")
922 (put variable
'variable-comment nil
)
923 (put variable
'customized-variable-comment nil
))
925 (put variable
'variable-comment comment
)
926 (put variable
'customized-variable-comment comment
)))
930 (defun customize-save-variable (variable value
&optional comment
)
931 "Set the default for VARIABLE to VALUE, and save it for future sessions.
934 If VARIABLE has a `custom-set' property, that is used for setting
935 VARIABLE, otherwise `set-default' is used.
937 The `customized-value' property of the VARIABLE will be set to a list
938 with a quoted VALUE as its sole list member.
940 If VARIABLE has a `variable-interactive' property, that is used as if
941 it were the arg to `interactive' (which see) to interactively read the value.
943 If VARIABLE has a `custom-type' property, it must be a widget and the
944 `:prompt-value' property of that widget will be used for reading the value.
946 If given a prefix (or a COMMENT argument), also prompt for a comment."
947 (interactive (custom-prompt-variable "Set and save variable: "
948 "Set and save value for %s as: "
950 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
951 (put variable
'saved-value
(list (custom-quote value
)))
952 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
953 (cond ((string= comment
"")
954 (put variable
'variable-comment nil
)
955 (put variable
'saved-variable-comment nil
))
957 (put variable
'variable-comment comment
)
958 (put variable
'saved-variable-comment comment
)))
964 "Select a customization buffer which you can use to set user options.
965 User options are structured into \"groups\".
966 Initially the top-level group `Emacs' and its immediate subgroups
967 are shown; the contents of those subgroups are initially hidden."
969 (customize-group 'emacs
))
972 (defun customize-mode (mode)
973 "Customize options related to the current major mode.
974 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
975 then prompt for the MODE to customize."
978 (let ((completion-regexp-list '("-mode\\'"))
979 (group (custom-group-of-mode major-mode
)))
980 (if (and group
(not current-prefix-arg
))
983 (completing-read (if group
984 (format "Major mode (default %s): " major-mode
)
987 'custom-group-of-mode
988 t nil nil
(if group
(symbol-name major-mode
))))))))
989 (customize-group (custom-group-of-mode mode
)))
993 (defun customize-group (group)
994 "Customize GROUP, which must be a customization group."
996 (list (let ((completion-ignore-case t
))
997 (completing-read "Customize group (default emacs): "
1000 (or (and (get symbol
'custom-loads
)
1001 (not (get symbol
'custom-autoload
)))
1002 (get symbol
'custom-group
)))
1004 (when (stringp group
)
1005 (if (string-equal "" group
)
1007 (setq group
(intern group
))))
1008 (let ((name (format "*Customize Group: %s*"
1009 (custom-unlispify-tag-name group
))))
1010 (if (get-buffer name
)
1011 (pop-to-buffer name
)
1012 (custom-buffer-create (list (list group
'custom-group
))
1014 (concat " for group "
1015 (custom-unlispify-tag-name group
))))))
1018 (defun customize-group-other-window (group)
1019 "Customize GROUP, which must be a customization group."
1021 (list (let ((completion-ignore-case t
))
1022 (completing-read "Customize group (default emacs): "
1025 (or (and (get symbol
'custom-loads
)
1026 (not (get symbol
'custom-autoload
)))
1027 (get symbol
'custom-group
)))
1029 (when (stringp group
)
1030 (if (string-equal "" group
)
1032 (setq group
(intern group
))))
1033 (let ((name (format "*Customize Group: %s*"
1034 (custom-unlispify-tag-name group
))))
1035 (if (get-buffer name
)
1037 ;; Copied from `custom-buffer-create-other-window'.
1039 (same-window-buffer-names nil
)
1040 (same-window-regexps nil
))
1041 (pop-to-buffer name
))
1042 (custom-buffer-create-other-window
1043 (list (list group
'custom-group
))
1045 (concat " for group "
1046 (custom-unlispify-tag-name group
))))))
1049 (defalias 'customize-variable
'customize-option
)
1052 (defun customize-option (symbol)
1053 "Customize SYMBOL, which must be a user option variable."
1054 (interactive (custom-variable-prompt))
1055 (let ((basevar (indirect-variable symbol
)))
1056 (custom-buffer-create (list (list basevar
'custom-variable
))
1057 (format "*Customize Option: %s*"
1058 (custom-unlispify-tag-name basevar
)))
1059 (unless (eq symbol basevar
)
1060 (message "`%s' is an alias for `%s'" symbol basevar
))))
1063 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1066 (defun customize-option-other-window (symbol)
1067 "Customize SYMBOL, which must be a user option variable.
1068 Show the buffer in another window, but don't select it."
1069 (interactive (custom-variable-prompt))
1070 (let ((basevar (indirect-variable symbol
)))
1071 (custom-buffer-create-other-window
1072 (list (list basevar
'custom-variable
))
1073 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1074 (unless (eq symbol basevar
)
1075 (message "`%s' is an alias for `%s'" symbol basevar
))))
1077 (defvar customize-changed-options-previous-release
"21.1"
1078 "Version for `customize-changed-options' to refer back to by default.")
1081 (defalias 'customize-changed
'customize-changed-options
)
1084 (defun customize-changed-options (since-version)
1085 "Customize all settings whose meanings have changed in Emacs itself.
1086 This includes new user option variables and faces, and new
1087 customization groups, as well as older options and faces whose meanings
1088 or default values have changed since the previous major Emacs release.
1090 With argument SINCE-VERSION (a string), customize all settings
1091 that were added or redefined since that version."
1093 (interactive "sCustomize options changed, since version (default all versions): ")
1094 (if (equal since-version
"")
1095 (setq since-version nil
)
1096 (unless (condition-case nil
1097 (numberp (read since-version
))
1099 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1100 (unless since-version
1101 (setq since-version customize-changed-options-previous-release
))
1103 ;; Load the information for versions since since-version. We use
1104 ;; custom-load-symbol for this.
1105 (put 'custom-versions-load-alist
'custom-loads nil
)
1106 (dolist (elt custom-versions-load-alist
)
1107 (if (customize-version-lessp since-version
(car elt
))
1108 (dolist (load (cdr elt
))
1109 (custom-add-load 'custom-versions-load-alist load
))))
1110 (custom-load-symbol 'custom-versions-load-alist
)
1111 (put 'custom-versions-load-alist
'custom-loads nil
)
1116 (let ((version (get symbol
'custom-version
)))
1118 (when (customize-version-lessp since-version version
)
1119 (if (or (get symbol
'custom-group
)
1120 (get symbol
'group-documentation
))
1121 (push (list symbol
'custom-group
) found
))
1122 (if (custom-variable-p symbol
)
1123 (push (list symbol
'custom-variable
) found
))
1124 (if (custom-facep symbol
)
1125 (push (list symbol
'custom-face
) found
)))))))
1127 (custom-buffer-create (custom-sort-items found t
'first
)
1128 "*Customize Changed Options*")
1129 (error "No user option defaults have been changed since Emacs %s"
1132 (defun customize-version-lessp (version1 version2
)
1133 ;; Why are the versions strings, and given that they are, why aren't
1134 ;; they converted to numbers and compared as such here? -- fx
1136 ;; In case someone made a mistake and left out the quotes
1137 ;; in the :version value.
1138 (if (numberp version2
)
1139 (setq version2
(prin1-to-string version2
)))
1140 (let (major1 major2 minor1 minor2
)
1141 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1142 (setq major1
(read (or (match-string 1 version1
)
1144 (setq minor1
(read (or (match-string 3 version1
)
1146 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1147 (setq major2
(read (or (match-string 1 version2
)
1149 (setq minor2
(read (or (match-string 3 version2
)
1151 (or (< major1 major2
)
1152 (and (= major1 major2
)
1153 (< minor1 minor2
)))))
1156 (defun customize-face (&optional face
)
1157 "Customize FACE, which should be a face name or nil.
1158 If FACE is nil, customize all faces. If FACE is actually a
1159 face-alias, customize the face it is aliased to.
1161 Interactively, when point is on text which has a face specified,
1162 suggest to customize that face, if it's customizable."
1164 (list (read-face-name "Customize face" "all faces" t
)))
1165 (if (member face
'(nil ""))
1166 (setq face
(face-list)))
1167 (if (and (listp face
) (null (cdr face
)))
1168 (setq face
(car face
)))
1170 (custom-buffer-create (custom-sort-items
1172 (list s
'custom-face
))
1175 "*Customize Faces*")
1176 ;; If FACE is actually an alias, customize the face it is aliased to.
1177 (if (get face
'face-alias
)
1178 (setq face
(get face
'face-alias
)))
1179 (unless (facep face
)
1180 (error "Invalid face %S" face
))
1181 (custom-buffer-create (list (list face
'custom-face
))
1182 (format "*Customize Face: %s*"
1183 (custom-unlispify-tag-name face
)))))
1186 (defun customize-face-other-window (&optional face
)
1187 "Show customization buffer for face FACE in other window.
1188 If FACE is actually a face-alias, customize the face it is aliased to.
1190 Interactively, when point is on text which has a face specified,
1191 suggest to customize that face, if it's customizable."
1193 (list (read-face-name "Customize face" "all faces" t
)))
1194 (if (member face
'(nil ""))
1195 (setq face
(face-list)))
1196 (if (and (listp face
) (null (cdr face
)))
1197 (setq face
(car face
)))
1199 (custom-buffer-create-other-window
1202 (list s
'custom-face
))
1205 "*Customize Faces*")
1206 (if (get face
'face-alias
)
1207 (setq face
(get face
'face-alias
)))
1208 (unless (facep face
)
1209 (error "Invalid face %S" face
))
1210 (custom-buffer-create-other-window
1211 (list (list face
'custom-face
))
1212 (format "*Customize Face: %s*"
1213 (custom-unlispify-tag-name face
)))))
1216 (defun customize-customized ()
1217 "Customize all user options set since the last save in this session."
1220 (mapatoms (lambda (symbol)
1221 (and (or (get symbol
'customized-face
)
1222 (get symbol
'customized-face-comment
))
1223 (custom-facep symbol
)
1224 (push (list symbol
'custom-face
) found
))
1225 (and (or (get symbol
'customized-value
)
1226 (get symbol
'customized-variable-comment
))
1228 (push (list symbol
'custom-variable
) found
))))
1230 (error "No customized user options")
1231 (custom-buffer-create (custom-sort-items found t nil
)
1232 "*Customize Customized*"))))
1235 (defun customize-rogue ()
1236 "Customize all user variable modified outside customize."
1239 (mapatoms (lambda (symbol)
1240 (let ((cval (or (get symbol
'customized-value
)
1241 (get symbol
'saved-value
)
1242 (get symbol
'standard-value
))))
1243 (when (and cval
;Declared with defcustom.
1244 (default-boundp symbol
) ;Has a value.
1245 (not (equal (eval (car cval
))
1246 ;; Which does not match customize.
1247 (default-value symbol
))))
1248 (push (list symbol
'custom-variable
) found
)))))
1250 (error "No rogue user options")
1251 (custom-buffer-create (custom-sort-items found t nil
)
1252 "*Customize Rogue*"))))
1254 (defun customize-saved ()
1255 "Customize all already saved user options."
1258 (mapatoms (lambda (symbol)
1259 (and (or (get symbol
'saved-face
)
1260 (get symbol
'saved-face-comment
))
1261 (custom-facep symbol
)
1262 (push (list symbol
'custom-face
) found
))
1263 (and (or (get symbol
'saved-value
)
1264 (get symbol
'saved-variable-comment
))
1266 (push (list symbol
'custom-variable
) found
))))
1268 (error "No saved user options")
1269 (custom-buffer-create (custom-sort-items found t nil
)
1270 "*Customize Saved*"))))
1273 (defun customize-apropos (regexp &optional all
)
1274 "Customize all loaded options, faces and groups matching REGEXP.
1275 If ALL is `options', include only options.
1276 If ALL is `faces', include only faces.
1277 If ALL is `groups', include only groups.
1278 If ALL is t (interactively, with prefix arg), include variables
1279 that are not customizable options, as well as faces and groups
1280 \(but we recommend using `apropos-variable' instead)."
1281 (interactive "sCustomize regexp: \nP")
1283 (mapatoms (lambda (symbol)
1284 (when (string-match regexp
(symbol-name symbol
))
1285 (when (and (not (memq all
'(faces options
)))
1286 (get symbol
'custom-group
))
1287 (push (list symbol
'custom-group
) found
))
1288 (when (and (not (memq all
'(options groups
)))
1289 (custom-facep symbol
))
1290 (push (list symbol
'custom-face
) found
))
1291 (when (and (not (memq all
'(groups faces
)))
1293 (eq (indirect-variable symbol
) symbol
)
1294 (or (get symbol
'saved-value
)
1295 (custom-variable-p symbol
)
1296 (and (not (memq all
'(nil options
)))
1297 (get symbol
'variable-documentation
))))
1298 (push (list symbol
'custom-variable
) found
)))))
1300 (error "No matches")
1301 (custom-buffer-create (custom-sort-items found t
1302 custom-buffer-order-groups
)
1303 "*Customize Apropos*"))))
1306 (defun customize-apropos-options (regexp &optional arg
)
1307 "Customize all loaded customizable options matching REGEXP.
1308 With prefix arg, include variables that are not customizable options
1309 \(but we recommend using `apropos-variable' instead)."
1310 (interactive "sCustomize regexp: \nP")
1311 (customize-apropos regexp
(or arg
'options
)))
1314 (defun customize-apropos-faces (regexp)
1315 "Customize all loaded faces matching REGEXP."
1316 (interactive "sCustomize regexp: \n")
1317 (customize-apropos regexp
'faces
))
1320 (defun customize-apropos-groups (regexp)
1321 "Customize all loaded groups matching REGEXP."
1322 (interactive "sCustomize regexp: \n")
1323 (customize-apropos regexp
'groups
))
1327 (defcustom custom-buffer-style
'links
1328 "Control the presentation style for customization buffers.
1329 The value should be a symbol, one of:
1331 brackets: groups nest within each other with big horizontal brackets.
1332 links: groups have links to subgroups."
1333 :type
'(radio (const brackets
)
1335 :group
'custom-buffer
)
1337 (defcustom custom-buffer-done-kill nil
1338 "*Non-nil means exiting a Custom buffer should kill it."
1341 :group
'custom-buffer
)
1343 (defcustom custom-buffer-indent
3
1344 "Number of spaces to indent nested groups."
1346 :group
'custom-buffer
)
1348 (defun custom-get-fresh-buffer (name)
1349 "Get a fresh new buffer with name NAME.
1350 If the buffer already exist, clean it up to be like new.
1351 Beware: it's not quite like new. Good enough for custom, but maybe
1353 ;; To be more complete, we should also kill all permanent-local variables,
1354 ;; but it's not needed for custom.
1355 (let ((buf (get-buffer name
)))
1356 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1357 ;; This will check if the file is not saved.
1361 (get-buffer-create name
)
1362 (with-current-buffer buf
1363 (kill-all-local-variables)
1364 (run-hooks 'kill-buffer-hook
)
1365 ;; Delete overlays before erasing the buffer so the overlay hooks
1366 ;; don't get run spuriously when we erase the buffer.
1367 (let ((ols (overlay-lists)))
1368 (dolist (ol (nconc (car ols
) (cdr ols
)))
1369 (delete-overlay ol
)))
1374 (defun custom-buffer-create (options &optional name description
)
1375 "Create a buffer containing OPTIONS.
1376 Optional NAME is the name of the buffer.
1377 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1378 SYMBOL is a customization option, and WIDGET is a widget for editing
1380 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1381 (custom-buffer-create-internal options description
))
1384 (defun custom-buffer-create-other-window (options &optional name description
)
1385 "Create a buffer containing OPTIONS, and display it in another window.
1386 The result includes selecting that window.
1387 Optional NAME is the name of the buffer.
1388 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1389 SYMBOL is a customization option, and WIDGET is a widget for editing
1391 (unless name
(setq name
"*Customization*"))
1392 (let ((pop-up-windows t
)
1393 (same-window-buffer-names nil
)
1394 (same-window-regexps nil
))
1395 (pop-to-buffer (custom-get-fresh-buffer name
))
1396 (custom-buffer-create-internal options description
)))
1398 (defcustom custom-reset-button-menu nil
1399 "If non-nil, only show a single reset button in customize buffers.
1400 This button will have a menu with all three reset operations."
1402 :group
'custom-buffer
)
1404 (defcustom custom-buffer-verbose-help t
1405 "If non-nil, include explanatory text in the customization buffer."
1407 :group
'custom-buffer
)
1409 (defun Custom-buffer-done (&rest ignore
)
1410 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1412 (quit-window custom-buffer-done-kill
))
1414 (defvar custom-button nil
1415 "Face used for buttons in customization buffers.")
1417 (defvar custom-button-mouse nil
1418 "Mouse face used for buttons in customization buffers.")
1420 (defvar custom-button-pressed nil
1421 "Face used for pressed buttons in customization buffers.")
1423 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1424 '(("unspecified" . unspecified
))))
1425 "If non-nil, indicate active buttons in a `raised-button' style.
1426 Otherwise use brackets."
1429 :group
'custom-buffer
1430 :set
(lambda (variable value
)
1431 (custom-set-default variable value
)
1433 (if value
'custom-button
'custom-button-unraised
))
1434 (setq custom-button-mouse
1435 (if value
'custom-button-mouse
'highlight
))
1436 (setq custom-button-pressed
1438 'custom-button-pressed
1439 'custom-button-pressed-unraised
))))
1441 (defun custom-buffer-create-internal (options &optional description
)
1443 (if custom-buffer-verbose-help
1445 (widget-insert "This is a customization buffer")
1447 (widget-insert description
))
1448 (widget-insert (format ".
1449 %s buttons; type RET or click mouse-1 to actuate one.
1450 Editing a setting changes only the text in the buffer.
1451 Use the setting's State button to set it or save changes in it.
1452 Saving a change normally works by editing your Emacs init file.
1454 (if custom-raised-buttons
1455 "`Raised' text indicates"
1456 "Square brackets indicate")))
1457 (widget-create 'info-link
1459 "(emacs)Saving Customizations")
1461 " for information on how to save in a different file.\n
1463 (widget-create 'info-link
1465 :help-echo
"Read the online help."
1466 "(emacs)Easy Customization")
1467 (widget-insert " for more information.\n\n")
1468 (widget-insert "Operate on everything in this buffer:\n "))
1469 (widget-insert " "))
1470 (widget-create 'push-button
1471 :tag
"Set for Current Session"
1473 Make your editing in this buffer take effect for this session."
1474 :action
(lambda (widget &optional event
)
1476 (when (or custom-file user-init-file
)
1478 (widget-create 'push-button
1479 :tag
"Save for Future Sessions"
1481 Make your editing in this buffer take effect for future Emacs sessions.
1482 This updates your Emacs initialization file or creates a new one."
1483 :action
(lambda (widget &optional event
)
1485 (if custom-reset-button-menu
1488 (widget-create 'push-button
1490 :help-echo
"Show a menu with reset operations."
1491 :mouse-down-action
(lambda (&rest junk
) t
)
1492 :action
(lambda (widget &optional event
)
1493 (custom-reset event
))))
1495 (when (or custom-file user-init-file
)
1496 (widget-create 'push-button
1497 :tag
"Erase Customization"
1499 Un-customize all settings in this buffer--save them with standard values."
1500 :action
'Custom-reset-standard
)))
1501 (widget-insert "\n ")
1502 (widget-create 'push-button
1503 :tag
"Reset to Current"
1505 Reset all edited text in this buffer to reflect current values."
1506 :action
'Custom-reset-current
)
1508 (widget-create 'push-button
1509 :tag
"Reset to Saved"
1511 Reset all settings in this buffer to their saved values."
1512 :action
'Custom-reset-saved
)
1513 (if (not custom-buffer-verbose-help
)
1516 (widget-create 'info-link
1518 :help-echo
"Read the online help."
1519 "(emacs)Easy Customization")))
1521 (widget-create 'push-button
1524 (lambda (&rest ignore
)
1525 (if custom-buffer-done-kill
1527 "Bury this buffer"))
1528 :action
#'Custom-buffer-done
)
1529 (widget-insert "\n\n")
1530 (message "Creating customization items...")
1531 (buffer-disable-undo)
1532 (setq custom-options
1533 (if (= (length options
) 1)
1534 (mapcar (lambda (entry)
1535 (widget-create (nth 1 entry
)
1536 :documentation-shown t
1537 :custom-state
'unknown
1538 :tag
(custom-unlispify-tag-name
1540 :value
(nth 0 entry
)))
1543 (length (length options
)))
1544 (mapcar (lambda (entry)
1546 (message "Creating customization items ...%2d%%"
1547 (/ (* 100.0 count
) length
))
1548 (widget-create (nth 1 entry
)
1549 :tag
(custom-unlispify-tag-name
1551 :value
(nth 0 entry
))
1552 (setq count
(1+ count
))
1553 (unless (eq (preceding-char) ?
\n)
1554 (widget-insert "\n"))
1555 (widget-insert "\n")))
1557 (unless (eq (preceding-char) ?
\n)
1558 (widget-insert "\n"))
1559 (message "Creating customization items ...done")
1560 (message "Resetting customization items...")
1561 (unless (eq custom-buffer-style
'tree
)
1562 (mapc 'custom-magic-reset custom-options
))
1563 (message "Resetting customization items...done")
1564 (message "Creating customization setup...")
1566 (buffer-enable-undo)
1567 (goto-char (point-min))
1568 (message "Creating customization setup...done"))
1570 ;;; The Tree Browser.
1573 (defun customize-browse (&optional group
)
1574 "Create a tree browser for the customize hierarchy."
1577 (setq group
'emacs
))
1578 (let ((name "*Customize Browser*"))
1579 (pop-to-buffer (custom-get-fresh-buffer name
)))
1581 (widget-insert (format "\
1582 %s buttons; type RET or click mouse-1
1583 on a button to invoke its action.
1584 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1585 (if custom-raised-buttons
1586 "`Raised' text indicates"
1587 "Square brackets indicate")))
1590 (if custom-browse-only-groups
1592 Invoke the [Group] button below to edit that item in another window.\n\n")
1593 (widget-insert "Invoke the ")
1594 (widget-create 'item
1597 :tag-glyph
"folder")
1598 (widget-insert ", ")
1599 (widget-create 'item
1603 (widget-insert ", and ")
1604 (widget-create 'item
1607 :tag-glyph
"option")
1608 (widget-insert " buttons below to edit that
1609 item in another window.\n\n"))
1610 (let ((custom-buffer-style 'tree
))
1611 (widget-create 'custom-group
1613 :custom-state
'unknown
1614 :tag
(custom-unlispify-tag-name group
)
1617 (goto-char (point-min)))
1619 (define-widget 'custom-browse-visibility
'item
1620 "Control visibility of items in the customize tree browser."
1622 :action
'custom-browse-visibility-action
)
1624 (defun custom-browse-visibility-action (widget &rest ignore
)
1625 (let ((custom-buffer-style 'tree
))
1626 (custom-toggle-parent widget
)))
1628 (define-widget 'custom-browse-group-tag
'push-button
1629 "Show parent in other window when activated."
1632 :action
'custom-browse-group-tag-action
)
1634 (defun custom-browse-group-tag-action (widget &rest ignore
)
1635 (let ((parent (widget-get widget
:parent
)))
1636 (customize-group-other-window (widget-value parent
))))
1638 (define-widget 'custom-browse-variable-tag
'push-button
1639 "Show parent in other window when activated."
1642 :action
'custom-browse-variable-tag-action
)
1644 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1645 (let ((parent (widget-get widget
:parent
)))
1646 (customize-variable-other-window (widget-value parent
))))
1648 (define-widget 'custom-browse-face-tag
'push-button
1649 "Show parent in other window when activated."
1652 :action
'custom-browse-face-tag-action
)
1654 (defun custom-browse-face-tag-action (widget &rest ignore
)
1655 (let ((parent (widget-get widget
:parent
)))
1656 (customize-face-other-window (widget-value parent
))))
1658 (defconst custom-browse-alist
'((" " "space")
1664 (defun custom-browse-insert-prefix (prefix)
1665 "Insert PREFIX. On XEmacs convert it to line graphics."
1666 ;; Fixme: do graphics.
1667 (if nil
; (string-match "XEmacs" emacs-version)
1670 (while (not (string-equal prefix
""))
1671 (let ((entry (substring prefix
0 3)))
1672 (setq prefix
(substring prefix
3))
1673 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1674 (name (nth 1 (assoc entry custom-browse-alist
))))
1675 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1676 (overlay-put overlay
'start-open t
)
1677 (overlay-put overlay
'end-open t
)))))
1680 ;;; Modification of Basic Widgets.
1682 ;; We add extra properties to the basic widgets needed here. This is
1683 ;; fine, as long as we are careful to stay within out own namespace.
1685 ;; We want simple widgets to be displayed by default, but complex
1686 ;; widgets to be hidden.
1688 (widget-put (get 'item
'widget-type
) :custom-show t
)
1689 (widget-put (get 'editable-field
'widget-type
)
1690 :custom-show
(lambda (widget value
)
1691 (let ((pp (pp-to-string value
)))
1692 (cond ((string-match "\n" pp
)
1697 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1699 ;;; The `custom-manual' Widget.
1701 (define-widget 'custom-manual
'info-link
1702 "Link to the manual entry for this customization option."
1703 :help-echo
"Read the manual entry for this option."
1706 ;;; The `custom-magic' Widget.
1708 (defgroup custom-magic-faces nil
1709 "Faces used by the magic button."
1710 :group
'custom-faces
1711 :group
'custom-buffer
)
1713 (defface custom-invalid
'((((class color
))
1714 (:foreground
"yellow1" :background
"red1"))
1716 (:weight bold
:slant italic
:underline t
)))
1717 "Face used when the customize item is invalid."
1718 :group
'custom-magic-faces
)
1719 ;; backward-compatibility alias
1720 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1722 (defface custom-rogue
'((((class color
))
1723 (:foreground
"pink" :background
"black"))
1726 "Face used when the customize item is not defined for customization."
1727 :group
'custom-magic-faces
)
1728 ;; backward-compatibility alias
1729 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1731 (defface custom-modified
'((((min-colors 88) (class color
))
1732 (:foreground
"white" :background
"blue1"))
1734 (:foreground
"white" :background
"blue"))
1736 (:slant italic
:bold
)))
1737 "Face used when the customize item has been modified."
1738 :group
'custom-magic-faces
)
1739 ;; backward-compatibility alias
1740 (put 'custom-modified-face
'face-alias
'custom-modified
)
1742 (defface custom-set
'((((min-colors 88) (class color
))
1743 (:foreground
"blue1" :background
"white"))
1745 (:foreground
"blue" :background
"white"))
1748 "Face used when the customize item has been set."
1749 :group
'custom-magic-faces
)
1750 ;; backward-compatibility alias
1751 (put 'custom-set-face
'face-alias
'custom-set
)
1753 (defface custom-changed
'((((min-colors 88) (class color
))
1754 (:foreground
"white" :background
"blue1"))
1756 (:foreground
"white" :background
"blue"))
1759 "Face used when the customize item has been changed."
1760 :group
'custom-magic-faces
)
1761 ;; backward-compatibility alias
1762 (put 'custom-changed-face
'face-alias
'custom-changed
)
1764 (defface custom-themed
'((((min-colors 88) (class color
))
1765 (:foreground
"white" :background
"blue1"))
1767 (:foreground
"white" :background
"blue"))
1770 "Face used when the customize item has been set by a theme."
1771 :group
'custom-magic-faces
)
1773 (defface custom-saved
'((t (:underline t
)))
1774 "Face used when the customize item has been saved."
1775 :group
'custom-magic-faces
)
1776 ;; backward-compatibility alias
1777 (put 'custom-saved-face
'face-alias
'custom-saved
)
1779 (defconst custom-magic-alist
1780 '((nil "#" underline
"\
1781 UNINITIALIZED, you should not see this.")
1782 (unknown "?" italic
"\
1783 UNKNOWN, you should not see this.")
1784 (hidden "-" default
"\
1785 HIDDEN, invoke \"Show\" in the previous line to show." "\
1786 group now hidden, invoke \"Show\", above, to show contents.")
1787 (invalid "x" custom-invalid
"\
1788 INVALID, the displayed value cannot be set.")
1789 (modified "*" custom-modified
"\
1790 EDITED, shown value does not take effect until you set or save it." "\
1791 something in this group has been edited but not set.")
1792 (set "+" custom-set
"\
1793 SET for current session only." "\
1794 something in this group has been set but not saved.")
1795 (changed ":" custom-changed
"\
1796 CHANGED outside Customize; operating on it here may be unreliable." "\
1797 something in this group has been changed outside customize.")
1798 (saved "!" custom-saved
"\
1800 something in this group has been set and saved.")
1801 (themed "o" custom-themed
"\
1803 visible group members are all at standard values.")
1804 (rogue "@" custom-rogue
"\
1805 NO CUSTOMIZATION DATA; not intended to be customized." "\
1806 something in this group is not prepared for customization.")
1807 (standard " " nil
"\
1809 visible group members are all at standard values."))
1810 "Alist of customize option states.
1811 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1813 STATE is one of the following symbols:
1816 For internal use, should never occur.
1818 For internal use, should never occur.
1820 This item is not being displayed.
1822 This item is modified, but has an invalid form.
1824 This item is modified, and has a valid form.
1826 This item has been set but not saved.
1828 The current value of this item has been changed outside Customize.
1830 This item is marked for saving.
1832 This item has no customization information.
1834 This item is unchanged from the standard setting.
1836 MAGIC is a string used to present that state.
1838 FACE is a face used to present the state.
1840 ITEM-DESC is a string describing the state for options.
1842 GROUP-DESC is a string describing the state for groups. If this is
1843 left out, ITEM-DESC will be used.
1845 The string %c in either description will be replaced with the
1846 category of the item. These are `group'. `option', and `face'.
1848 The list should be sorted most significant first.")
1850 (defcustom custom-magic-show
'long
1851 "If non-nil, show textual description of the state.
1852 If `long', show a full-line description, not just one word."
1853 :type
'(choice (const :tag
"no" nil
)
1855 (other :tag
"short" short
))
1856 :group
'custom-buffer
)
1858 (defcustom custom-magic-show-hidden
'(option face
)
1859 "Control whether the State button is shown for hidden items.
1860 The value should be a list with the custom categories where the State
1861 button should be visible. Possible categories are `group', `option',
1863 :type
'(set (const group
) (const option
) (const face
))
1864 :group
'custom-buffer
)
1866 (defcustom custom-magic-show-button nil
1867 "Show a \"magic\" button indicating the state of each customization option."
1869 :group
'custom-buffer
)
1871 (define-widget 'custom-magic
'default
1872 "Show and manipulate state for a customization option."
1874 :action
'widget-parent-action
1877 :value-create
'custom-magic-value-create
1878 :value-delete
'widget-children-value-delete
)
1880 (defun widget-magic-mouse-down-action (widget &optional event
)
1881 ;; Non-nil unless hidden.
1882 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1886 (defun custom-magic-value-create (widget)
1887 "Create compact status report for WIDGET."
1888 (let* ((parent (widget-get widget
:parent
))
1889 (state (widget-get parent
:custom-state
))
1890 (hidden (eq state
'hidden
))
1891 (entry (assq state custom-magic-alist
))
1892 (magic (nth 1 entry
))
1893 (face (nth 2 entry
))
1894 (category (widget-get parent
:custom-category
))
1895 (text (or (and (eq category
'group
)
1898 (form (widget-get parent
:custom-form
))
1900 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1901 (setq text
(concat (match-string 1 text
)
1902 (symbol-name category
)
1903 (match-string 2 text
))))
1904 (when (and custom-magic-show
1906 (memq category custom-magic-show-hidden
)))
1908 (when (and (eq category
'group
)
1909 (not (and (eq custom-buffer-style
'links
)
1910 (> (widget-get parent
:custom-level
) 1))))
1911 (insert-char ?\
(* custom-buffer-indent
1912 (widget-get parent
:custom-level
))))
1913 (push (widget-create-child-and-convert
1915 :help-echo
"Change the state of this item."
1916 :format
(if hidden
"%t" "%[%t%]")
1917 :button-prefix
'widget-push-button-prefix
1918 :button-suffix
'widget-push-button-suffix
1919 :mouse-down-action
'widget-magic-mouse-down-action
1923 (let ((start (point)))
1924 (if (eq custom-magic-show
'long
)
1926 (insert (symbol-name state
)))
1927 (cond ((eq form
'lisp
)
1929 ((eq form
'mismatch
)
1930 (insert " (mismatch)")))
1931 (put-text-property start
(point) 'face
'custom-state
))
1933 (when (and (eq category
'group
)
1934 (not (and (eq custom-buffer-style
'links
)
1935 (> (widget-get parent
:custom-level
) 1))))
1936 (insert-char ?\
(* custom-buffer-indent
1937 (widget-get parent
:custom-level
))))
1938 (when custom-magic-show-button
1939 (when custom-magic-show
1940 (let ((indent (widget-get parent
:indent
)))
1942 (insert-char ? indent
))))
1943 (push (widget-create-child-and-convert
1945 :mouse-down-action
'widget-magic-mouse-down-action
1949 :help-echo
"Change the state."
1950 :format
(if hidden
"%t" "%[%t%]")
1951 :tag
(if (memq form
'(lisp mismatch
))
1952 (concat "(" magic
")")
1953 (concat "[" magic
"]")))
1956 (widget-put widget
:children children
)))
1958 (defun custom-magic-reset (widget)
1959 "Redraw the :custom-magic property of WIDGET."
1960 (let ((magic (widget-get widget
:custom-magic
)))
1961 (widget-value-set magic
(widget-value magic
))))
1963 ;;; The `custom' Widget.
1965 (defface custom-button
1966 '((((type x w32 mac
) (class color
)) ; Like default modeline
1967 (:box
(:line-width
2 :style released-button
)
1968 :background
"lightgrey" :foreground
"black"))
1971 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1973 :group
'custom-faces
)
1974 ;; backward-compatibility alias
1975 (put 'custom-button-face
'face-alias
'custom-button
)
1977 (defface custom-button-mouse
1978 '((((type x w32 mac
) (class color
))
1979 (:box
(:line-width
2 :style released-button
)
1980 :background
"grey90" :foreground
"black"))
1983 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1985 :group
'custom-faces
)
1987 (defface custom-button-unraised
1989 (class color
) (background light
)) :foreground
"blue1" :underline t
)
1990 (((class color
) (background light
)) :foreground
"blue" :underline t
)
1992 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
1993 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
1995 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1997 :group
'custom-faces
)
2000 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2002 (setq custom-button-mouse
2003 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2005 (defface custom-button-pressed
2006 '((((type x w32 mac
) (class color
))
2007 (:box
(:line-width
2 :style pressed-button
)
2008 :background
"lightgrey" :foreground
"black"))
2010 (:inverse-video t
)))
2011 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2013 :group
'custom-faces
)
2014 ;; backward-compatibility alias
2015 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2017 (defface custom-button-pressed-unraised
2018 '((default :inherit custom-button-unraised
)
2019 (((class color
) (background light
)) :foreground
"magenta4")
2020 (((class color
) (background dark
)) :foreground
"violet"))
2021 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2023 :group
'custom-faces
)
2025 (setq custom-button-pressed
2026 (if custom-raised-buttons
2027 'custom-button-pressed
2028 'custom-button-pressed-unraised
))
2030 (defface custom-documentation nil
2031 "Face used for documentation strings in customization buffers."
2032 :group
'custom-faces
)
2033 ;; backward-compatibility alias
2034 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2036 (defface custom-state
'((((class color
)
2038 (:foreground
"lime green"))
2041 (:foreground
"dark green"))
2043 "Face used for State descriptions in the customize buffer."
2044 :group
'custom-faces
)
2045 ;; backward-compatibility alias
2046 (put 'custom-state-face
'face-alias
'custom-state
)
2048 (define-widget 'custom
'default
2049 "Customize a user option."
2051 :convert-widget
'custom-convert-widget
2052 :notify
'custom-notify
2055 :custom-state
'hidden
2056 :documentation-property
'widget-subclass-responsibility
2057 :value-create
'widget-subclass-responsibility
2058 :value-delete
'widget-children-value-delete
2059 :value-get
'widget-value-value-get
2060 :validate
'widget-children-validate
2061 :match
(lambda (widget value
) (symbolp value
)))
2063 (defun custom-convert-widget (widget)
2064 "Initialize :value and :tag from :args in WIDGET."
2065 (let ((args (widget-get widget
:args
)))
2067 (widget-put widget
:value
(widget-apply widget
2068 :value-to-internal
(car args
)))
2069 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2070 (widget-put widget
:args nil
)))
2073 (defun custom-notify (widget &rest args
)
2074 "Keep track of changes."
2075 (let ((state (widget-get widget
:custom-state
)))
2076 (unless (eq state
'modified
)
2077 (unless (memq state
'(nil unknown hidden
))
2078 (widget-put widget
:custom-state
'modified
))
2079 (custom-magic-reset widget
)
2080 (apply 'widget-default-notify widget args
))))
2082 (defun custom-redraw (widget)
2083 "Redraw WIDGET with current settings."
2084 (let ((line (count-lines (point-min) (point)))
2085 (column (current-column))
2087 (from (marker-position (widget-get widget
:from
)))
2088 (to (marker-position (widget-get widget
:to
))))
2090 (widget-value-set widget
(widget-value widget
))
2091 (custom-redraw-magic widget
))
2092 (when (and (>= pos from
) (<= pos to
))
2097 (goto-line (1+ line
)))
2098 (move-to-column column
))
2101 (defun custom-redraw-magic (widget)
2102 "Redraw WIDGET state with current settings."
2104 (let ((magic (widget-get widget
:custom-magic
)))
2106 (widget-value-set magic
(widget-value magic
))
2107 (when (setq widget
(widget-get widget
:group
))
2108 (custom-group-state-update widget
)))
2110 (setq widget nil
)))))
2113 (defun custom-show (widget value
)
2114 "Non-nil if WIDGET should be shown with VALUE by default."
2115 (let ((show (widget-get widget
:custom-show
)))
2121 (funcall show widget value
)))))
2123 (defun custom-load-widget (widget)
2124 "Load all dependencies for WIDGET."
2125 (custom-load-symbol (widget-value widget
)))
2127 (defun custom-unloaded-symbol-p (symbol)
2128 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2130 (loads (get symbol
'custom-loads
))
2133 (setq load
(car loads
)
2135 (cond ((symbolp load
)
2136 (unless (featurep load
)
2138 ((assoc load load-history
))
2139 ((assoc (locate-library load
) load-history
)
2145 (defun custom-unloaded-widget-p (widget)
2146 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2147 (custom-unloaded-symbol-p (widget-value widget
)))
2149 (defun custom-toggle-hide (widget)
2150 "Toggle visibility of WIDGET."
2151 (custom-load-widget widget
)
2152 (let ((state (widget-get widget
:custom-state
)))
2153 (cond ((memq state
'(invalid modified
))
2154 (error "There are unset changes"))
2156 (widget-put widget
:custom-state
'unknown
))
2158 (widget-put widget
:documentation-shown nil
)
2159 (widget-put widget
:custom-state
'hidden
)))
2160 (custom-redraw widget
)
2163 (defun custom-toggle-parent (widget &rest ignore
)
2164 "Toggle visibility of parent of WIDGET."
2165 (custom-toggle-hide (widget-get widget
:parent
)))
2167 (defun custom-add-see-also (widget &optional prefix
)
2168 "Add `See also ...' to WIDGET if there are any links.
2169 Insert PREFIX first if non-nil."
2170 (let* ((symbol (widget-get widget
:value
))
2171 (links (get symbol
'custom-links
))
2172 (many (> (length links
) 2))
2173 (buttons (widget-get widget
:buttons
))
2174 (indent (widget-get widget
:indent
)))
2177 (insert-char ?\ indent
))
2180 (insert "See also ")
2182 (push (widget-create-child-and-convert widget
(car links
))
2184 (setq links
(cdr links
))
2193 (widget-put widget
:buttons buttons
))))
2195 (defun custom-add-parent-links (widget &optional initial-string
)
2196 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2197 The value is non-nil if any parents were found.
2198 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2199 (let ((name (widget-value widget
))
2200 (type (widget-type widget
))
2201 (buttons (widget-get widget
:buttons
))
2204 (insert (or initial-string
"Parent groups:"))
2205 (mapatoms (lambda (symbol)
2206 (when (member (list name type
) (get symbol
'custom-group
))
2208 (push (widget-create-child-and-convert
2209 widget
'custom-group-link
2210 :tag
(custom-unlispify-tag-name symbol
)
2213 (setq parents
(cons symbol parents
)))))
2214 (and (null (get name
'custom-links
)) ;No links of its own.
2215 (= (length parents
) 1) ;A single parent.
2216 (let* ((links (delq nil
(mapcar (lambda (w)
2217 (unless (eq (widget-type w
)
2220 (get (car parents
) 'custom-links
))))
2221 (many (> (length links
) 2)))
2223 (insert "\nParent documentation: ")
2225 (push (widget-create-child-and-convert widget
(car links
))
2227 (setq links
(cdr links
))
2238 (delete-region start
(point)))
2239 (widget-put widget
:buttons buttons
)
2242 ;;; The `custom-comment' Widget.
2244 ;; like the editable field
2245 (defface custom-comment
'((((class grayscale color
)
2247 (:background
"gray85"))
2248 (((class grayscale color
)
2250 (:background
"dim gray"))
2253 "Face used for comments on variables or faces"
2255 :group
'custom-faces
)
2256 ;; backward-compatibility alias
2257 (put 'custom-comment-face
'face-alias
'custom-comment
)
2259 ;; like font-lock-comment-face
2260 (defface custom-comment-tag
2261 '((((class color
) (background dark
)) (:foreground
"gray80"))
2262 (((class color
) (background light
)) (:foreground
"blue4"))
2263 (((class grayscale
) (background light
))
2264 (:foreground
"DimGray" :weight bold
:slant italic
))
2265 (((class grayscale
) (background dark
))
2266 (:foreground
"LightGray" :weight bold
:slant italic
))
2268 "Face used for variables or faces comment tags"
2269 :group
'custom-faces
)
2270 ;; backward-compatibility alias
2271 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2273 (define-widget 'custom-comment
'string
2276 :help-echo
"Edit a comment here."
2277 :sample-face
'custom-comment-tag-face
2278 :value-face
'custom-comment-face
2280 :create
'custom-comment-create
)
2282 (defun custom-comment-create (widget)
2283 (let* ((null-comment (equal "" (widget-value widget
))))
2284 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2286 (widget-default-create widget
)
2287 ;; `widget-default-delete' expects markers in these slots --
2288 ;; maybe it shouldn't.
2289 (widget-put widget
:from
(point-marker))
2290 (widget-put widget
:to
(point-marker)))))
2292 (defun custom-comment-hide (widget)
2293 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2295 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2296 ;; the global custom one
2297 (defun custom-comment-show (widget)
2298 (widget-put widget
:comment-shown t
)
2299 (custom-redraw widget
)
2302 (defun custom-comment-invisible-p (widget)
2303 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2305 (not (widget-get widget
:comment-shown
)))))
2307 ;;; The `custom-variable' Widget.
2309 ;; When this was underlined blue, users confused it with a
2310 ;; Mosaic-style hyperlink...
2311 (defface custom-variable-tag
2314 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2315 (((min-colors 88) (class color
)
2317 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2320 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2322 "Face used for unpushable variable tags."
2323 :group
'custom-faces
)
2324 ;; backward-compatibility alias
2325 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2327 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2328 "Face used for pushable variable tags."
2329 :group
'custom-faces
)
2330 ;; backward-compatibility alias
2331 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2333 (defcustom custom-variable-default-form
'edit
2334 "Default form of displaying variable values."
2335 :type
'(choice (const edit
)
2337 :group
'custom-buffer
2340 (defun custom-variable-documentation (variable)
2341 "Return documentation of VARIABLE for use in Custom buffer.
2342 Normally just return the docstring. But if VARIABLE automatically
2343 becomes buffer local when set, append a message to that effect."
2344 (if (and (local-variable-if-set-p variable
)
2345 (or (not (local-variable-p variable
))
2347 (local-variable-if-set-p variable
))))
2348 (concat (documentation-property variable
'variable-documentation
)
2350 This variable automatically becomes buffer-local when set outside Custom.
2351 However, setting it through Custom sets the default value.")
2352 (documentation-property variable
'variable-documentation
)))
2354 (define-widget 'custom-variable
'custom
2355 "Customize variable."
2357 :help-echo
"Set or reset this variable."
2358 :documentation-property
#'custom-variable-documentation
2359 :custom-category
'option
2361 :custom-menu
'custom-variable-menu-create
2362 :custom-form nil
; defaults to value of `custom-variable-default-form'
2363 :value-create
'custom-variable-value-create
2364 :action
'custom-variable-action
2365 :custom-set
'custom-variable-set
2366 :custom-save
'custom-variable-save
2367 :custom-reset-current
'custom-redraw
2368 :custom-reset-saved
'custom-variable-reset-saved
2369 :custom-reset-standard
'custom-variable-reset-standard
2370 :custom-standard-value
'custom-variable-standard-value
)
2372 (defun custom-variable-type (symbol)
2373 "Return a widget suitable for editing the value of SYMBOL.
2374 If SYMBOL has a `custom-type' property, use that.
2375 Otherwise, look up symbol in `custom-guess-type-alist'."
2376 (let* ((type (or (get symbol
'custom-type
)
2377 (and (not (get symbol
'standard-value
))
2378 (custom-guess-type symbol
))
2380 (options (get symbol
'custom-options
))
2381 (tmp (if (listp type
)
2382 (copy-sequence type
)
2385 (widget-put tmp
:options options
))
2388 (defun custom-variable-value-create (widget)
2389 "Here is where you edit the variable's value."
2390 (custom-load-widget widget
)
2391 (unless (widget-get widget
:custom-form
)
2392 (widget-put widget
:custom-form custom-variable-default-form
))
2393 (let* ((buttons (widget-get widget
:buttons
))
2394 (children (widget-get widget
:children
))
2395 (form (widget-get widget
:custom-form
))
2396 (state (widget-get widget
:custom-state
))
2397 (symbol (widget-get widget
:value
))
2398 (tag (widget-get widget
:tag
))
2399 (type (custom-variable-type symbol
))
2400 (conv (widget-convert type
))
2401 (get (or (get symbol
'custom-get
) 'default-value
))
2402 (prefix (widget-get widget
:custom-prefix
))
2403 (last (widget-get widget
:custom-last
))
2404 (value (if (default-boundp symbol
)
2405 (funcall get symbol
)
2406 (widget-get conv
:value
))))
2407 ;; If the widget is new, the child determines whether it is hidden.
2409 ((custom-show type value
)
2410 (setq state
'unknown
))
2412 (setq state
'hidden
)))
2413 ;; If we don't know the state, see if we need to edit it in lisp form.
2414 (when (eq state
'unknown
)
2415 (unless (widget-apply conv
:match value
)
2416 ;; (widget-apply (widget-convert type) :match value)
2417 (setq form
'mismatch
)))
2418 ;; Now we can create the child widget.
2419 (cond ((eq custom-buffer-style
'tree
)
2420 (insert prefix
(if last
" `--- " " |--- "))
2421 (push (widget-create-child-and-convert
2422 widget
'custom-browse-variable-tag
)
2424 (insert " " tag
"\n")
2425 (widget-put widget
:buttons buttons
))
2427 ;; Indicate hidden value.
2428 (push (widget-create-child-and-convert
2431 :sample-face
'custom-variable-tag-face
2435 (push (widget-create-child-and-convert
2437 :help-echo
"Show the value of this option."
2439 :action
'custom-toggle-parent
2442 ((memq form
'(lisp mismatch
))
2443 ;; In lisp mode edit the saved value when possible.
2444 (let* ((value (cond ((get symbol
'saved-value
)
2445 (car (get symbol
'saved-value
)))
2446 ((get symbol
'standard-value
)
2447 (car (get symbol
'standard-value
)))
2448 ((default-boundp symbol
)
2449 (custom-quote (funcall get symbol
)))
2451 (custom-quote (widget-get conv
:value
))))))
2452 (insert (symbol-name symbol
) ": ")
2453 (push (widget-create-child-and-convert
2455 :help-echo
"Hide the value of this option."
2458 :action
'custom-toggle-parent
2462 (push (widget-create-child-and-convert
2464 :button-face
'custom-variable-button-face
2466 :tag
(symbol-name symbol
)
2472 (let* ((format (widget-get type
:format
))
2473 tag-format value-format
)
2474 (unless (string-match ":" format
)
2475 (error "Bad format"))
2476 (setq tag-format
(substring format
0 (match-end 0)))
2477 (setq value-format
(substring format
(match-end 0)))
2478 (push (widget-create-child-and-convert
2481 :action
'custom-tag-action
2482 :help-echo
"Change value of this option."
2483 :mouse-down-action
'custom-tag-mouse-down-action
2484 :button-face
'custom-variable-button-face
2485 :sample-face
'custom-variable-tag-face
2489 (push (widget-create-child-and-convert
2491 :help-echo
"Hide the value of this option."
2494 :action
'custom-toggle-parent
2497 (push (widget-create-child-and-convert
2499 :format value-format
2502 (unless (eq custom-buffer-style
'tree
)
2503 (unless (eq (preceding-char) ?
\n)
2504 (widget-insert "\n"))
2505 ;; Create the magic button.
2506 (let ((magic (widget-create-child-and-convert
2507 widget
'custom-magic nil
)))
2508 (widget-put widget
:custom-magic magic
)
2509 (push magic buttons
))
2510 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2511 ;; before the call to `widget-default-format-handler'. Otherwise, I
2512 ;; loose my current `buttons'. This function shouldn't be called like
2513 ;; this anyway. The doc string widget should be added like the others.
2515 (widget-put widget
:buttons buttons
)
2517 ;; Insert documentation.
2518 (widget-default-format-handler widget ?h
)
2520 ;; The comment field
2521 (unless (eq state
'hidden
)
2522 (let* ((comment (get symbol
'variable-comment
))
2524 (widget-create-child-and-convert
2525 widget
'custom-comment
2527 :value
(or comment
""))))
2528 (widget-put widget
:comment-widget comment-widget
)
2529 ;; Don't push it !!! Custom assumes that the first child is the
2531 (setq children
(append children
(list comment-widget
)))))
2532 ;; Update the rest of the properties properties.
2533 (widget-put widget
:custom-form form
)
2534 (widget-put widget
:children children
)
2535 ;; Now update the state.
2536 (if (eq state
'hidden
)
2537 (widget-put widget
:custom-state state
)
2538 (custom-variable-state-set widget
))
2540 (unless (eq state
'hidden
)
2541 (when (eq (widget-get widget
:custom-level
) 1)
2542 (custom-add-parent-links widget
))
2543 (custom-add-see-also widget
)))))
2545 (defun custom-tag-action (widget &rest args
)
2546 "Pass :action to first child of WIDGET's parent."
2547 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2550 (defun custom-tag-mouse-down-action (widget &rest args
)
2551 "Pass :mouse-down-action to first child of WIDGET's parent."
2552 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2553 :mouse-down-action args
))
2555 (defun custom-variable-state-set (widget)
2556 "Set the state of WIDGET."
2557 (let* ((symbol (widget-value widget
))
2558 (get (or (get symbol
'custom-get
) 'default-value
))
2559 (value (if (default-boundp symbol
)
2560 (funcall get symbol
)
2561 (widget-get widget
:value
)))
2562 (comment (get symbol
'variable-comment
))
2565 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2567 (get symbol
'customized-variable-comment
))
2569 (if (condition-case nil
2570 (and (equal value
(eval (car tmp
)))
2571 (equal comment temp
))
2575 ((progn (setq tmp
(get symbol
'theme-value
))
2576 (setq temp
(get symbol
'saved-variable-comment
))
2578 (if (condition-case nil
2579 (and (equal comment temp
)
2586 ((eq 'user
(caar (get symbol
'theme-value
)))
2588 ((eq 'standard
(caar (get symbol
'theme-value
)))
2592 ((setq tmp
(get symbol
'standard-value
))
2593 (if (condition-case nil
2594 (and (equal value
(eval (car tmp
)))
2595 (equal comment nil
))
2600 (widget-put widget
:custom-state state
)))
2602 (defun custom-variable-standard-value (widget)
2603 (get (widget-value widget
) 'standard-value
))
2605 (defvar custom-variable-menu
2606 `(("Set for Current Session" custom-variable-set
2608 (eq (widget-get widget
:custom-state
) 'modified
)))
2609 ,@(when (or custom-file user-init-file
)
2610 '(("Save for Future Sessions" custom-variable-save
2612 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))))
2613 ("Reset to Current" custom-redraw
2615 (and (default-boundp (widget-value widget
))
2616 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2617 ("Reset to Saved" custom-variable-reset-saved
2619 (and (or (get (widget-value widget
) 'saved-value
)
2620 (get (widget-value widget
) 'saved-variable-comment
))
2621 (memq (widget-get widget
:custom-state
)
2622 '(modified set changed rogue
)))))
2623 ,@(when (or custom-file user-init-file
)
2624 '(("Erase Customization" custom-variable-reset-standard
2626 (and (get (widget-value widget
) 'standard-value
)
2627 (memq (widget-get widget
:custom-state
)
2628 '(modified set changed saved rogue
)))))))
2629 ("Use Backup Value" custom-variable-reset-backup
2631 (get (widget-value widget
) 'backup-value
)))
2632 ("---" ignore ignore
)
2633 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2634 ("---" ignore ignore
)
2635 ("Don't show as Lisp expression" custom-variable-edit
2637 (eq (widget-get widget
:custom-form
) 'lisp
)))
2638 ("Show initial Lisp expression" custom-variable-edit-lisp
2640 (eq (widget-get widget
:custom-form
) 'edit
))))
2641 "Alist of actions for the `custom-variable' widget.
2642 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2643 the menu entry, ACTION is the function to call on the widget when the
2644 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2645 widget as an argument, and returns non-nil if ACTION is valid on that
2646 widget. If FILTER is nil, ACTION is always valid.")
2648 (defun custom-variable-action (widget &optional event
)
2649 "Show the menu for `custom-variable' WIDGET.
2650 Optional EVENT is the location for the menu."
2651 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2652 (custom-toggle-hide widget
)
2653 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2654 (custom-variable-state-set widget
))
2655 (custom-redraw-magic widget
)
2656 (let* ((completion-ignore-case t
)
2657 (answer (widget-choose (concat "Operation on "
2658 (custom-unlispify-tag-name
2659 (widget-get widget
:value
)))
2660 (custom-menu-filter custom-variable-menu
2664 (funcall answer widget
)))))
2666 (defun custom-variable-edit (widget)
2667 "Edit value of WIDGET."
2668 (widget-put widget
:custom-state
'unknown
)
2669 (widget-put widget
:custom-form
'edit
)
2670 (custom-redraw widget
))
2672 (defun custom-variable-edit-lisp (widget)
2673 "Edit the Lisp representation of the value of WIDGET."
2674 (widget-put widget
:custom-state
'unknown
)
2675 (widget-put widget
:custom-form
'lisp
)
2676 (custom-redraw widget
))
2678 (defun custom-variable-set (widget)
2679 "Set the current value for the variable being edited by WIDGET."
2680 (let* ((form (widget-get widget
:custom-form
))
2681 (state (widget-get widget
:custom-state
))
2682 (child (car (widget-get widget
:children
)))
2683 (symbol (widget-value widget
))
2684 (set (or (get symbol
'custom-set
) 'set-default
))
2685 (comment-widget (widget-get widget
:comment-widget
))
2686 (comment (widget-value comment-widget
))
2688 (cond ((eq state
'hidden
)
2689 (error "Cannot set hidden variable"))
2690 ((setq val
(widget-apply child
:validate
))
2691 (goto-char (widget-get val
:from
))
2692 (error "%s" (widget-get val
:error
)))
2693 ((memq form
'(lisp mismatch
))
2694 (when (equal comment
"")
2696 ;; Make the comment invisible by hand if it's empty
2697 (custom-comment-hide comment-widget
))
2698 (custom-variable-backup-value widget
)
2699 (custom-push-theme 'theme-value symbol
'user
2700 'set
(custom-quote (widget-value child
)))
2701 (funcall set symbol
(eval (setq val
(widget-value child
))))
2702 (put symbol
'customized-value
(list val
))
2703 (put symbol
'variable-comment comment
)
2704 (put symbol
'customized-variable-comment comment
))
2706 (when (equal comment
"")
2708 ;; Make the comment invisible by hand if it's empty
2709 (custom-comment-hide comment-widget
))
2710 (custom-variable-backup-value widget
)
2711 (custom-push-theme 'theme-value symbol
'user
2712 'set
(custom-quote (widget-value child
)))
2713 (funcall set symbol
(setq val
(widget-value child
)))
2714 (put symbol
'customized-value
(list (custom-quote val
)))
2715 (put symbol
'variable-comment comment
)
2716 (put symbol
'customized-variable-comment comment
)))
2717 (custom-variable-state-set widget
)
2718 (custom-redraw-magic widget
)))
2720 (defun custom-variable-save (widget)
2721 "Set and save the value for the variable being edited by WIDGET."
2722 (let* ((form (widget-get widget
:custom-form
))
2723 (state (widget-get widget
:custom-state
))
2724 (child (car (widget-get widget
:children
)))
2725 (symbol (widget-value widget
))
2726 (set (or (get symbol
'custom-set
) 'set-default
))
2727 (comment-widget (widget-get widget
:comment-widget
))
2728 (comment (widget-value comment-widget
))
2730 (cond ((eq state
'hidden
)
2731 (error "Cannot set hidden variable"))
2732 ((setq val
(widget-apply child
:validate
))
2733 (goto-char (widget-get val
:from
))
2734 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2735 ((memq form
'(lisp mismatch
))
2736 (when (equal comment
"")
2738 ;; Make the comment invisible by hand if it's empty
2739 (custom-comment-hide comment-widget
))
2740 (put symbol
'saved-value
(list (widget-value child
)))
2741 (custom-push-theme 'theme-value symbol
'user
2742 'set
(custom-quote (widget-value child
)))
2743 (funcall set symbol
(eval (widget-value child
)))
2744 (put symbol
'variable-comment comment
)
2745 (put symbol
'saved-variable-comment comment
))
2747 (when (equal comment
"")
2749 ;; Make the comment invisible by hand if it's empty
2750 (custom-comment-hide comment-widget
))
2751 (put symbol
'saved-value
2752 (list (custom-quote (widget-value child
))))
2753 (custom-push-theme 'theme-value symbol
'user
2754 'set
(custom-quote (widget-value child
)))
2755 (funcall set symbol
(widget-value child
))
2756 (put symbol
'variable-comment comment
)
2757 (put symbol
'saved-variable-comment comment
)))
2758 (put symbol
'customized-value nil
)
2759 (put symbol
'customized-variable-comment nil
)
2761 (custom-variable-state-set widget
)
2762 (custom-redraw-magic widget
)))
2764 (defun custom-variable-reset-saved (widget)
2765 "Restore the saved value for the variable being edited by WIDGET.
2766 The value that was current before this operation
2767 becomes the backup value, so you can get it again."
2768 (let* ((symbol (widget-value widget
))
2769 (set (or (get symbol
'custom-set
) 'set-default
))
2770 (value (get symbol
'saved-value
))
2771 (comment (get symbol
'saved-variable-comment
)))
2772 (cond ((or value comment
)
2773 (put symbol
'variable-comment comment
)
2774 (custom-variable-backup-value widget
)
2775 (custom-push-theme 'theme-value symbol
'user
'set value
)
2777 (funcall set symbol
(eval (car value
)))
2780 (error "No saved value for %s" symbol
)))
2781 (put symbol
'customized-value nil
)
2782 (put symbol
'customized-variable-comment nil
)
2783 (widget-put widget
:custom-state
'unknown
)
2784 ;; This call will possibly make the comment invisible
2785 (custom-redraw widget
)))
2787 (defun custom-variable-reset-standard (widget)
2788 "Restore the standard setting for the variable being edited by WIDGET.
2789 This operation eliminates any saved setting for the variable,
2790 restoring it to the state of a variable that has never been customized.
2791 The value that was current before this operation
2792 becomes the backup value, so you can get it again."
2793 (let* ((symbol (widget-value widget
))
2794 (set (or (get symbol
'custom-set
) 'set-default
)))
2795 (if (get symbol
'standard-value
)
2796 (custom-variable-backup-value widget
)
2797 (error "No standard setting known for %S" symbol
))
2798 (put symbol
'variable-comment nil
)
2799 (put symbol
'customized-value nil
)
2800 (put symbol
'customized-variable-comment nil
)
2801 (custom-push-theme 'theme-value symbol
'user
'reset nil
)
2802 (custom-theme-recalc-variable symbol
)
2803 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2804 (put symbol
'saved-value nil
)
2805 (put symbol
'saved-variable-comment nil
)
2807 (widget-put widget
:custom-state
'unknown
)
2808 ;; This call will possibly make the comment invisible
2809 (custom-redraw widget
)))
2811 (defun custom-variable-backup-value (widget)
2812 "Back up the current value for WIDGET's variable.
2813 The backup value is kept in the car of the `backup-value' property."
2814 (let* ((symbol (widget-value widget
))
2815 (get (or (get symbol
'custom-get
) 'default-value
))
2816 (type (custom-variable-type symbol
))
2817 (conv (widget-convert type
))
2818 (value (if (default-boundp symbol
)
2819 (funcall get symbol
)
2820 (widget-get conv
:value
))))
2821 (put symbol
'backup-value
(list value
))))
2823 (defun custom-variable-reset-backup (widget)
2824 "Restore the backup value for the variable being edited by WIDGET.
2825 The value that was current before this operation
2826 becomes the backup value, so you can use this operation repeatedly
2827 to switch between two values."
2828 (let* ((symbol (widget-value widget
))
2829 (set (or (get symbol
'custom-set
) 'set-default
))
2830 (value (get symbol
'backup-value
))
2831 (comment-widget (widget-get widget
:comment-widget
))
2832 (comment (widget-value comment-widget
)))
2835 (custom-variable-backup-value widget
)
2836 (custom-push-theme 'theme-value symbol
'user
'set value
)
2838 (funcall set symbol
(car value
))
2840 (error "No backup value for %s" symbol
))
2841 (put symbol
'customized-value
(list (car value
)))
2842 (put symbol
'variable-comment comment
)
2843 (put symbol
'customized-variable-comment comment
)
2844 (custom-variable-state-set widget
)
2845 ;; This call will possibly make the comment invisible
2846 (custom-redraw widget
)))
2848 ;;; The `custom-face-edit' Widget.
2850 (define-widget 'custom-face-edit
'checklist
2851 "Edit face attributes."
2855 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2856 :value-to-internal
'custom-face-edit-fix-value
2857 :match
(lambda (widget value
)
2858 (widget-checklist-match widget
2859 (custom-face-edit-fix-value widget value
)))
2860 :convert-widget
'custom-face-edit-convert-widget
2861 :args
(mapcar (lambda (att)
2864 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2865 (list 'const
:format
"" :value
(nth 0 att
))
2867 custom-face-attributes
))
2869 (defun custom-face-edit-fix-value (widget value
)
2870 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2871 Also change :reverse-video to :inverse-video."
2875 (let ((key (car value
))
2876 (val (car (cdr value
))))
2877 (cond ((eq key
:italic
)
2878 (push :slant result
)
2879 (push (if val
'italic
'normal
) result
))
2881 (push :weight result
)
2882 (push (if val
'bold
'normal
) result
))
2883 ((eq key
:reverse-video
)
2884 (push :inverse-video result
)
2888 (push val result
))))
2889 (setq value
(cdr (cdr value
))))
2890 (setq result
(nreverse result
))
2894 (defun custom-face-edit-convert-widget (widget)
2895 "Convert :args as widget types in WIDGET."
2898 :args
(mapcar (lambda (arg)
2900 :deactivate
'custom-face-edit-deactivate
2901 :activate
'custom-face-edit-activate
2902 :delete
'custom-face-edit-delete
))
2903 (widget-get widget
:args
)))
2906 (defun custom-face-edit-deactivate (widget)
2907 "Make face widget WIDGET inactive for user modifications."
2908 (unless (widget-get widget
:inactive
)
2909 (let ((tag (custom-face-edit-attribute-tag widget
))
2910 (from (copy-marker (widget-get widget
:from
)))
2911 (value (widget-value widget
))
2912 (inhibit-read-only t
)
2913 (inhibit-modification-hooks t
))
2916 (widget-default-delete widget
)
2917 (insert tag
": *\n")
2918 (widget-put widget
:inactive
2919 (cons value
(cons from
(- (point) from
))))))))
2921 (defun custom-face-edit-activate (widget)
2922 "Make face widget WIDGET inactive for user modifications."
2923 (let ((inactive (widget-get widget
:inactive
))
2924 (inhibit-read-only t
)
2925 (inhibit-modification-hooks t
))
2926 (when (consp inactive
)
2928 (goto-char (car (cdr inactive
)))
2929 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2930 (widget-put widget
:inactive nil
)
2931 (widget-apply widget
:create
)
2932 (widget-value-set widget
(car inactive
))
2935 (defun custom-face-edit-delete (widget)
2936 "Remove WIDGET from the buffer."
2937 (let ((inactive (widget-get widget
:inactive
))
2938 (inhibit-read-only t
)
2939 (inhibit-modification-hooks t
))
2941 ;; Widget is alive, we don't have to do anything special
2942 (widget-default-delete widget
)
2943 ;; WIDGET is already deleted because we did so to inactivate it;
2944 ;; now just get rid of the label we put in its place.
2945 (delete-region (car (cdr inactive
))
2946 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2947 (widget-put widget
:inactive nil
))))
2950 (defun custom-face-edit-attribute-tag (widget)
2951 "Returns the first :tag property in WIDGET or one of its children."
2952 (let ((tag (widget-get widget
:tag
)))
2953 (or (and (not (equal tag
"")) tag
)
2954 (let ((children (widget-get widget
:children
)))
2955 (while (and (null tag
) children
)
2956 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2959 ;;; The `custom-display' Widget.
2961 (define-widget 'custom-display
'menu-choice
2962 "Select a display type."
2965 :help-echo
"Specify frames where the face attributes should be used."
2966 :args
'((const :tag
"all" t
)
2967 (const :tag
"defaults" default
)
2971 :args
((group :sibling-args
(:help-echo
"\
2972 Only match the specified window systems.")
2973 (const :format
"Type: "
2975 (checklist :inline t
2978 :sibling-args
(:help-echo
"\
2979 The X11 Window System.")
2981 (const :format
"PM "
2982 :sibling-args
(:help-echo
"\
2983 OS/2 Presentation Manager.")
2985 (const :format
"W32 "
2986 :sibling-args
(:help-echo
"\
2989 (const :format
"MAC "
2990 :sibling-args
(:help-echo
"\
2993 (const :format
"DOS "
2994 :sibling-args
(:help-echo
"\
2997 (const :format
"TTY%n"
2998 :sibling-args
(:help-echo
"\
2999 Plain text terminals.")
3001 (group :sibling-args
(:help-echo
"\
3002 Only match the frames with the specified color support.")
3003 (const :format
"Class: "
3005 (checklist :inline t
3007 (const :format
"Color "
3008 :sibling-args
(:help-echo
"\
3009 Match color frames.")
3011 (const :format
"Grayscale "
3012 :sibling-args
(:help-echo
"\
3013 Match grayscale frames.")
3015 (const :format
"Monochrome%n"
3016 :sibling-args
(:help-echo
"\
3017 Match frames with no color support.")
3019 (group :sibling-args
(:help-echo
"\
3020 The minimum number of colors the frame should support.")
3021 (const :format
"" min-colors
)
3022 (integer :tag
"Minimum number of colors" ))
3023 (group :sibling-args
(:help-echo
"\
3024 Only match frames with the specified intensity.")
3026 Background brightness: "
3028 (checklist :inline t
3030 (const :format
"Light "
3031 :sibling-args
(:help-echo
"\
3032 Match frames with light backgrounds.")
3034 (const :format
"Dark\n"
3035 :sibling-args
(:help-echo
"\
3036 Match frames with dark backgrounds.")
3038 (group :sibling-args
(:help-echo
"\
3039 Only match frames that support the specified face attributes.")
3040 (const :format
"Supports attributes:" supports
)
3041 (custom-face-edit :inline t
:format
"%n%v"))))))
3043 ;;; The `custom-face' Widget.
3045 (defface custom-face-tag
3046 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3047 "Face used for face tags."
3048 :group
'custom-faces
)
3049 ;; backward-compatibility alias
3050 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3052 (defcustom custom-face-default-form
'selected
3053 "Default form of displaying face definition."
3054 :type
'(choice (const all
)
3057 :group
'custom-buffer
3060 (define-widget 'custom-face
'custom
3062 :sample-face
'custom-face-tag-face
3063 :help-echo
"Set or reset this face."
3064 :documentation-property
#'face-doc-string
3065 :value-create
'custom-face-value-create
3066 :action
'custom-face-action
3067 :custom-category
'face
3068 :custom-form nil
; defaults to value of `custom-face-default-form'
3069 :custom-set
'custom-face-set
3070 :custom-save
'custom-face-save
3071 :custom-reset-current
'custom-redraw
3072 :custom-reset-saved
'custom-face-reset-saved
3073 :custom-reset-standard
'custom-face-reset-standard
3074 :custom-standard-value
'custom-face-standard-value
3075 :custom-menu
'custom-face-menu-create
)
3077 (define-widget 'custom-face-all
'editable-list
3078 "An editable list of display specifications and attributes."
3079 :entry-format
"%i %d %v"
3080 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3081 :append-button-args
'(:help-echo
"Append new display specification here.")
3082 :delete-button-args
'(:help-echo
"Delete this display specification.")
3083 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3085 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3086 "Converted version of the `custom-face-all' widget.")
3088 (define-widget 'custom-display-unselected
'item
3089 "A display specification that doesn't match the selected display."
3090 :match
'custom-display-unselected-match
)
3092 (defun custom-display-unselected-match (widget value
)
3093 "Non-nil if VALUE is an unselected display specification."
3094 (not (face-spec-set-match-display value
(selected-frame))))
3096 (define-widget 'custom-face-selected
'group
3097 "Edit the attributes of the selected display in a face specification."
3098 :args
'((choice :inline t
3099 (group :tag
"With Defaults" :inline t
3100 (group (const :tag
"" default
)
3101 (custom-face-edit :tag
" Default\n Attributes"))
3104 (group custom-display-unselected sexp
))
3105 (group (sexp :format
"")
3106 (custom-face-edit :tag
" Overriding\n Attributes"))
3110 (group :tag
"No Defaults" :inline t
3113 (group custom-display-unselected sexp
))
3114 (group (sexp :format
"")
3115 (custom-face-edit :tag
"\n Attributes"))
3122 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3123 "Converted version of the `custom-face-selected' widget.")
3125 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3126 "Return a canonicalized version of SPEC using.
3127 FILTER-INDEX is the index in the entry for each attribute in
3128 `custom-face-attributes' at which the appropriate filter function can be
3129 found, and DEFAULT-FILTER is the filter to apply for attributes that
3131 (mapcar (lambda (entry)
3132 ;; Filter a single face-spec entry
3133 (let ((tests (car entry
))
3135 ;; Handle both old- and new-style attribute syntax
3136 (if (listp (car (cdr entry
)))
3139 (filtered-attrs nil
))
3140 ;; Filter each face attribute
3141 (while unfiltered-attrs
3142 (let* ((attr (pop unfiltered-attrs
))
3143 (pre-filtered-value (pop unfiltered-attrs
))
3145 (or (nth filter-index
(assq attr custom-face-attributes
))
3149 (funcall filter pre-filtered-value
)
3150 pre-filtered-value
)))
3151 (push filtered-value filtered-attrs
)
3152 (push attr filtered-attrs
)))
3154 (list tests filtered-attrs
)))
3157 (defun custom-pre-filter-face-spec (spec)
3158 "Return SPEC changed as necessary for editing by the face customization widget.
3159 SPEC must be a full face spec."
3160 (custom-filter-face-spec spec
2))
3162 (defun custom-post-filter-face-spec (spec)
3163 "Return the customized SPEC in a form suitable for setting the face."
3164 (custom-filter-face-spec spec
3))
3166 (defun custom-face-value-create (widget)
3167 "Create a list of the display specifications for WIDGET."
3168 (let ((buttons (widget-get widget
:buttons
))
3170 (symbol (widget-get widget
:value
))
3171 (tag (widget-get widget
:tag
))
3172 (state (widget-get widget
:custom-state
))
3174 (is-last (widget-get widget
:custom-last
))
3175 (prefix (widget-get widget
:custom-prefix
)))
3177 (setq tag
(prin1-to-string symbol
)))
3178 (cond ((eq custom-buffer-style
'tree
)
3179 (insert prefix
(if is-last
" `--- " " |--- "))
3180 (push (widget-create-child-and-convert
3181 widget
'custom-browse-face-tag
)
3183 (insert " " tag
"\n")
3184 (widget-put widget
:buttons buttons
))
3188 (widget-specify-sample widget begin
(point))
3189 (if (eq custom-buffer-style
'face
)
3191 (if (string-match "face\\'" tag
)
3193 (insert " face: ")))
3195 (push (widget-create-child-and-convert widget
'item
3202 (push (widget-create-child-and-convert
3204 :help-echo
"Hide or show this face."
3207 :action
'custom-toggle-parent
3208 (not (eq state
'hidden
)))
3212 (let ((magic (widget-create-child-and-convert
3213 widget
'custom-magic nil
)))
3214 (widget-put widget
:custom-magic magic
)
3215 (push magic buttons
))
3217 (widget-put widget
:buttons buttons
)
3218 ;; Insert documentation.
3219 (widget-default-format-handler widget ?h
)
3220 ;; The comment field
3221 (unless (eq state
'hidden
)
3222 (let* ((comment (get symbol
'face-comment
))
3224 (widget-create-child-and-convert
3225 widget
'custom-comment
3227 :value
(or comment
""))))
3228 (widget-put widget
:comment-widget comment-widget
)
3229 (push comment-widget children
)))
3231 (unless (eq state
'hidden
)
3232 (when (eq (widget-get widget
:custom-level
) 1)
3233 (custom-add-parent-links widget
))
3234 (custom-add-see-also widget
))
3236 (unless (eq (preceding-char) ?
\n)
3238 (unless (eq state
'hidden
)
3239 (message "Creating face editor...")
3240 (custom-load-widget widget
)
3241 (unless (widget-get widget
:custom-form
)
3242 (widget-put widget
:custom-form custom-face-default-form
))
3243 (let* ((symbol (widget-value widget
))
3244 (spec (or (get symbol
'customized-face
)
3245 (get symbol
'saved-face
)
3246 (get symbol
'face-defface-spec
)
3247 ;; Attempt to construct it.
3248 (list (list t
(custom-face-attributes-get
3249 symbol
(selected-frame))))))
3250 (form (widget-get widget
:custom-form
))
3251 (indent (widget-get widget
:indent
))
3253 ;; If the user has changed this face in some other way,
3254 ;; edit it as the user has specified it.
3255 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3256 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3257 (setq spec
(custom-pre-filter-face-spec spec
))
3258 (setq edit
(widget-create-child-and-convert
3260 (cond ((and (eq form
'selected
)
3261 (widget-apply custom-face-selected
3263 (when indent
(insert-char ?\ indent
))
3264 'custom-face-selected
)
3265 ((and (not (eq form
'lisp
))
3266 (widget-apply custom-face-all
3270 (when indent
(insert-char ?\ indent
))
3273 (custom-face-state-set widget
)
3274 (push edit children
)
3275 (widget-put widget
:children children
))
3276 (message "Creating face editor...done"))))))
3278 (defvar custom-face-menu
3279 `(("Set for Current Session" custom-face-set
)
3280 ,@(when (or custom-file user-init-file
)
3281 '(("Save for Future Sessions" custom-face-save-command
)))
3282 ("Reset to Saved" custom-face-reset-saved
3284 (or (get (widget-value widget
) 'saved-face
)
3285 (get (widget-value widget
) 'saved-face-comment
))))
3286 ,@(when (or custom-file user-init-file
)
3287 '(("Erase Customization" custom-face-reset-standard
3289 (get (widget-value widget
) 'face-defface-spec
)))))
3290 ("---" ignore ignore
)
3291 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3292 ("---" ignore ignore
)
3293 ("Show all display specs" custom-face-edit-all
3295 (not (eq (widget-get widget
:custom-form
) 'all
))))
3296 ("Just current attributes" custom-face-edit-selected
3298 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3299 ("Show as Lisp expression" custom-face-edit-lisp
3301 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3302 "Alist of actions for the `custom-face' widget.
3303 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3304 the menu entry, ACTION is the function to call on the widget when the
3305 menu is selected, and FILTER is a predicate which takes a `custom-face'
3306 widget as an argument, and returns non-nil if ACTION is valid on that
3307 widget. If FILTER is nil, ACTION is always valid.")
3309 (defun custom-face-edit-selected (widget)
3310 "Edit selected attributes of the value of WIDGET."
3311 (widget-put widget
:custom-state
'unknown
)
3312 (widget-put widget
:custom-form
'selected
)
3313 (custom-redraw widget
))
3315 (defun custom-face-edit-all (widget)
3316 "Edit all attributes of the value of WIDGET."
3317 (widget-put widget
:custom-state
'unknown
)
3318 (widget-put widget
:custom-form
'all
)
3319 (custom-redraw widget
))
3321 (defun custom-face-edit-lisp (widget)
3322 "Edit the Lisp representation of the value of WIDGET."
3323 (widget-put widget
:custom-state
'unknown
)
3324 (widget-put widget
:custom-form
'lisp
)
3325 (custom-redraw widget
))
3327 (defun custom-face-state-set (widget)
3328 "Set the state of WIDGET."
3329 (let* ((symbol (widget-value widget
))
3330 (comment (get symbol
'face-comment
))
3334 (setq tmp
(get symbol
'customized-face
))
3335 (setq temp
(get symbol
'customized-face-comment
))
3337 (if (equal temp comment
)
3341 (setq tmp
(get symbol
'saved-face
))
3342 (setq temp
(get symbol
'saved-face-comment
))
3344 (if (equal temp comment
)
3346 ((eq 'user
(caar (get symbol
'theme-face
)))
3348 ((eq 'standard
(caar (get symbol
'theme-face
)))
3352 ((get symbol
'face-defface-spec
)
3353 (if (equal comment nil
)
3358 ;; If the user called set-face-attribute to change the default
3359 ;; for new frames, this face is "set outside of Customize".
3360 (if (and (not (eq state
'rogue
))
3361 (get symbol
'face-modified
))
3362 (setq state
'changed
))
3363 (widget-put widget
:custom-state state
)))
3365 (defun custom-face-action (widget &optional event
)
3366 "Show the menu for `custom-face' WIDGET.
3367 Optional EVENT is the location for the menu."
3368 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3369 (custom-toggle-hide widget
)
3370 (let* ((completion-ignore-case t
)
3371 (symbol (widget-get widget
:value
))
3372 (answer (widget-choose (concat "Operation on "
3373 (custom-unlispify-tag-name symbol
))
3374 (custom-menu-filter custom-face-menu
3378 (funcall answer widget
)))))
3380 (defun custom-face-set (widget)
3381 "Make the face attributes in WIDGET take effect."
3382 (let* ((symbol (widget-value widget
))
3383 (child (car (widget-get widget
:children
)))
3384 (value (custom-post-filter-face-spec (widget-value child
)))
3385 (comment-widget (widget-get widget
:comment-widget
))
3386 (comment (widget-value comment-widget
)))
3387 (when (equal comment
"")
3389 ;; Make the comment invisible by hand if it's empty
3390 (custom-comment-hide comment-widget
))
3391 (put symbol
'customized-face value
)
3392 (if (face-spec-choose value
)
3393 (face-spec-set symbol value
)
3394 ;; face-set-spec ignores empty attribute lists, so just give it
3395 ;; something harmless instead.
3396 (face-spec-set symbol
'((t :foreground unspecified
))))
3397 (custom-push-theme 'theme-face symbol
'user
'set value
)
3398 (put symbol
'customized-face-comment comment
)
3399 (put symbol
'face-comment comment
)
3400 (custom-face-state-set widget
)
3401 (custom-redraw-magic widget
)))
3403 (defun custom-face-save-command (widget)
3404 "Save in `.emacs' the face attributes in WIDGET."
3405 (custom-face-save widget
)
3408 (defun custom-face-save (widget)
3409 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3410 (let* ((symbol (widget-value widget
))
3411 (child (car (widget-get widget
:children
)))
3412 (value (custom-post-filter-face-spec (widget-value child
)))
3413 (comment-widget (widget-get widget
:comment-widget
))
3414 (comment (widget-value comment-widget
)))
3415 (when (equal comment
"")
3417 ;; Make the comment invisible by hand if it's empty
3418 (custom-comment-hide comment-widget
))
3419 (if (face-spec-choose value
)
3420 (face-spec-set symbol value
)
3421 ;; face-set-spec ignores empty attribute lists, so just give it
3422 ;; something harmless instead.
3423 (face-spec-set symbol
'((t :foreground unspecified
))))
3424 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3425 (put symbol
'saved-face value
))
3426 (custom-push-theme 'theme-face symbol
'user
'set value
)
3427 (put symbol
'customized-face nil
)
3428 (put symbol
'face-comment comment
)
3429 (put symbol
'customized-face-comment nil
)
3430 (put symbol
'saved-face-comment comment
)
3432 (custom-face-state-set widget
)
3433 (custom-redraw-magic widget
)))
3435 (defun custom-face-reset-saved (widget)
3436 "Restore WIDGET to the face's default attributes."
3437 (let* ((symbol (widget-value widget
))
3438 (child (car (widget-get widget
:children
)))
3439 (value (get symbol
'saved-face
))
3440 (comment (get symbol
'saved-face-comment
))
3441 (comment-widget (widget-get widget
:comment-widget
)))
3442 (unless (or value comment
)
3443 (error "No saved value for this face"))
3444 (put symbol
'customized-face nil
)
3445 (put symbol
'customized-face-comment nil
)
3446 (custom-push-theme 'theme-face symbol
'user
'set value
)
3447 (face-spec-set symbol value
)
3448 (put symbol
'face-comment comment
)
3449 (widget-value-set child value
)
3450 ;; This call manages the comment visibility
3451 (widget-value-set comment-widget
(or comment
""))
3452 (custom-face-state-set widget
)
3453 (custom-redraw-magic widget
)))
3455 (defun custom-face-standard-value (widget)
3456 (get (widget-value widget
) 'face-defface-spec
))
3458 (defun custom-face-reset-standard (widget)
3459 "Restore WIDGET to the face's standard attribute values.
3460 This operation eliminates any saved attributes for the face,
3461 restoring it to the state of a face that has never been customized."
3462 (let* ((symbol (widget-value widget
))
3463 (child (car (widget-get widget
:children
)))
3464 (value (get symbol
'face-defface-spec
))
3465 (comment-widget (widget-get widget
:comment-widget
)))
3467 (error "No standard setting for this face"))
3468 (put symbol
'customized-face nil
)
3469 (put symbol
'customized-face-comment nil
)
3470 (custom-push-theme 'theme-face symbol
'user
'reset nil
)
3471 (custom-theme-recalc-face symbol
)
3472 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3473 (put symbol
'saved-face nil
)
3474 (put symbol
'saved-face-comment nil
)
3476 (put symbol
'face-comment nil
)
3477 (widget-value-set child value
)
3478 ;; This call manages the comment visibility
3479 (widget-value-set comment-widget
"")
3480 (custom-face-state-set widget
)
3481 (custom-redraw-magic widget
)))
3483 ;;; The `face' Widget.
3485 (defvar widget-face-prompt-value-history nil
3486 "History of input to `widget-face-prompt-value'.")
3488 (define-widget 'face
'symbol
3489 "A Lisp face name (with sample)."
3490 :format
"%{%t%}: (%{sample%}) %v"
3493 :sample-face-get
'widget-face-sample-face-get
3494 :notify
'widget-face-notify
3495 :match
(lambda (widget value
) (facep value
))
3496 :complete-function
(lambda ()
3498 (lisp-complete-symbol 'facep
))
3499 :prompt-match
'facep
3500 :prompt-history
'widget-face-prompt-value-history
3501 :validate
(lambda (widget)
3502 (unless (facep (widget-value widget
))
3504 :error
(format "Invalid face: %S"
3505 (widget-value widget
)))
3508 (defun widget-face-sample-face-get (widget)
3509 (let ((value (widget-value widget
)))
3514 (defun widget-face-notify (widget child
&optional event
)
3515 "Update the sample, and notify the parent."
3516 (overlay-put (widget-get widget
:sample-overlay
)
3517 'face
(widget-apply widget
:sample-face-get
))
3518 (widget-default-notify widget child event
))
3521 ;;; The `hook' Widget.
3523 (define-widget 'hook
'list
3525 :value-to-internal
(lambda (widget value
)
3526 (if (and value
(symbolp value
))
3529 :match
(lambda (widget value
)
3531 (widget-group-match widget value
)))
3532 ;; Avoid adding undefined functions to the hook, especially for
3533 ;; things like `find-file-hook' or even more basic ones, to avoid
3535 :set
(lambda (symbol value
)
3538 (add-hook symbol elt
))))
3539 :convert-widget
'custom-hook-convert-widget
3542 (defun custom-hook-convert-widget (widget)
3543 ;; Handle `:options'.
3544 (let* ((options (widget-get widget
:options
))
3545 (other `(editable-list :inline t
3546 :entry-format
"%i %d%v"
3547 (function :format
" %v")))
3549 (list `(checklist :inline t
3550 ,@(mapcar (lambda (entry)
3551 `(function-item ,entry
))
3555 (widget-put widget
:args args
)
3558 ;;; The `custom-group-link' Widget.
3560 (define-widget 'custom-group-link
'link
3561 "Show parent in other window when activated."
3562 :help-echo
"Create customization buffer for this group."
3563 :action
'custom-group-link-action
)
3565 (defun custom-group-link-action (widget &rest ignore
)
3566 (customize-group (widget-value widget
)))
3568 ;;; The `custom-group' Widget.
3570 (defcustom custom-group-tag-faces nil
3571 ;; In XEmacs, this ought to play games with font size.
3572 ;; Fixme: make it do so in Emacs.
3573 "Face used for group tags.
3574 The first member is used for level 1 groups, the second for level 2,
3575 and so forth. The remaining group tags are shown with `custom-group-tag'."
3576 :type
'(repeat face
)
3577 :group
'custom-faces
)
3579 (defface custom-group-tag-1
3582 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3583 (((min-colors 88) (class color
)
3585 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3588 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3590 "Face used for group tags."
3591 :group
'custom-faces
)
3592 ;; backward-compatibility alias
3593 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3595 (defface custom-group-tag
3598 (:foreground
"light blue" :weight bold
:height
1.2))
3599 (((min-colors 88) (class color
)
3601 (:foreground
"blue1" :weight bold
:height
1.2))
3604 (:foreground
"blue" :weight bold
:height
1.2))
3606 "Face used for low level group tags."
3607 :group
'custom-faces
)
3608 ;; backward-compatibility alias
3609 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3611 (define-widget 'custom-group
'custom
3614 :sample-face-get
'custom-group-sample-face-get
3615 :documentation-property
'group-documentation
3616 :help-echo
"Set or reset all members of this group."
3617 :value-create
'custom-group-value-create
3618 :action
'custom-group-action
3619 :custom-category
'group
3620 :custom-set
'custom-group-set
3621 :custom-save
'custom-group-save
3622 :custom-reset-current
'custom-group-reset-current
3623 :custom-reset-saved
'custom-group-reset-saved
3624 :custom-reset-standard
'custom-group-reset-standard
3625 :custom-menu
'custom-group-menu-create
)
3627 (defun custom-group-sample-face-get (widget)
3628 ;; Use :sample-face.
3629 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3632 (define-widget 'custom-group-visibility
'visibility
3633 "An indicator and manipulator for hidden group contents."
3634 :create
'custom-group-visibility-create
)
3636 (defun custom-group-visibility-create (widget)
3637 (let ((visible (widget-value widget
)))
3639 (insert "--------")))
3640 (widget-default-create widget
))
3642 (defun custom-group-members (symbol groups-only
)
3643 "Return SYMBOL's custom group members.
3644 If GROUPS-ONLY non-nil, return only those members that are groups."
3645 (if (not groups-only
)
3646 (get symbol
'custom-group
)
3648 (dolist (entry (get symbol
'custom-group
))
3649 (when (eq (nth 1 entry
) 'custom-group
)
3650 (push entry members
)))
3651 (nreverse members
))))
3653 (defun custom-group-value-create (widget)
3654 "Insert a customize group for WIDGET in the current buffer."
3655 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3656 (custom-load-widget widget
))
3657 (let* ((state (widget-get widget
:custom-state
))
3658 (level (widget-get widget
:custom-level
))
3659 ;; (indent (widget-get widget :indent))
3660 (prefix (widget-get widget
:custom-prefix
))
3661 (buttons (widget-get widget
:buttons
))
3662 (tag (widget-get widget
:tag
))
3663 (symbol (widget-value widget
))
3664 (members (custom-group-members symbol
3665 (and (eq custom-buffer-style
'tree
)
3666 custom-browse-only-groups
))))
3667 (cond ((and (eq custom-buffer-style
'tree
)
3669 (or members
(custom-unloaded-widget-p widget
)))
3670 (custom-browse-insert-prefix prefix
)
3671 (push (widget-create-child-and-convert
3672 widget
'custom-browse-visibility
3673 ;; :tag-glyph "plus"
3677 ;; (widget-glyph-insert nil "-- " "horizontal")
3678 (push (widget-create-child-and-convert
3679 widget
'custom-browse-group-tag
)
3681 (insert " " tag
"\n")
3682 (widget-put widget
:buttons buttons
))
3683 ((and (eq custom-buffer-style
'tree
)
3684 (zerop (length members
)))
3685 (custom-browse-insert-prefix prefix
)
3687 ;; (widget-glyph-insert nil "[ ]" "empty")
3688 ;; (widget-glyph-insert nil "-- " "horizontal")
3689 (push (widget-create-child-and-convert
3690 widget
'custom-browse-group-tag
)
3692 (insert " " tag
"\n")
3693 (widget-put widget
:buttons buttons
))
3694 ((eq custom-buffer-style
'tree
)
3695 (custom-browse-insert-prefix prefix
)
3696 (if (zerop (length members
))
3698 (custom-browse-insert-prefix prefix
)
3700 ;; (widget-glyph-insert nil "[ ]" "empty")
3701 ;; (widget-glyph-insert nil "-- " "horizontal")
3702 (push (widget-create-child-and-convert
3703 widget
'custom-browse-group-tag
)
3705 (insert " " tag
"\n")
3706 (widget-put widget
:buttons buttons
))
3707 (push (widget-create-child-and-convert
3708 widget
'custom-browse-visibility
3709 ;; :tag-glyph "minus"
3713 ;; (widget-glyph-insert nil "-\\ " "top")
3714 (push (widget-create-child-and-convert
3715 widget
'custom-browse-group-tag
)
3717 (insert " " tag
"\n")
3718 (widget-put widget
:buttons buttons
)
3719 (message "Creating group...")
3720 (let* ((members (custom-sort-items members
3721 custom-browse-sort-alphabetically
3722 custom-browse-order-groups
))
3723 (prefixes (widget-get widget
:custom-prefixes
))
3724 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3725 (extra-prefix (if (widget-get widget
:custom-last
)
3728 (prefix (concat prefix extra-prefix
))
3731 (setq entry
(car members
)
3732 members
(cdr members
))
3733 (push (widget-create-child-and-convert
3734 widget
(nth 1 entry
)
3736 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3737 :custom-prefixes custom-prefix-list
3738 :custom-level
(1+ level
)
3739 :custom-last
(null members
)
3740 :value
(nth 0 entry
)
3741 :custom-prefix prefix
)
3743 (widget-put widget
:children
(reverse children
)))
3744 (message "Creating group...done")))
3747 ;; Create level indicator.
3748 (unless (eq custom-buffer-style
'links
)
3749 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3752 (let ((begin (point)))
3754 (widget-specify-sample widget begin
(point)))
3756 ;; Create link/visibility indicator.
3757 (if (eq custom-buffer-style
'links
)
3758 (push (widget-create-child-and-convert
3759 widget
'custom-group-link
3763 (push (widget-create-child-and-convert
3764 widget
'custom-group-visibility
3765 :help-echo
"Show members of this group."
3766 :action
'custom-toggle-parent
3767 (not (eq state
'hidden
)))
3770 ;; Create magic button.
3771 (let ((magic (widget-create-child-and-convert
3772 widget
'custom-magic nil
)))
3773 (widget-put widget
:custom-magic magic
)
3774 (push magic buttons
))
3776 (widget-put widget
:buttons buttons
)
3777 ;; Insert documentation.
3778 (if (and (eq custom-buffer-style
'links
) (> level
1))
3779 (widget-put widget
:documentation-indent
0))
3780 (widget-default-format-handler widget ?h
))
3783 ;; Add parent groups references above the group.
3784 (if t
;;; This should test that the buffer
3785 ;;; was made to display a group.
3787 (if (custom-add-parent-links widget
3788 "Go to parent group:")
3790 ;; Create level indicator.
3791 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3794 (let ((start (point)))
3796 (widget-specify-sample widget start
(point)))
3798 ;; Create visibility indicator.
3799 (unless (eq custom-buffer-style
'links
)
3801 (push (widget-create-child-and-convert
3803 :help-echo
"Hide members of this group."
3804 :action
'custom-toggle-parent
3805 (not (eq state
'hidden
)))
3808 ;; Create more dashes.
3809 ;; Use 76 instead of 75 to compensate for the temporary "<"
3810 ;; added by `widget-insert'.
3811 (insert-char ?-
(- 76 (current-column)
3812 (* custom-buffer-indent level
)))
3814 ;; Create magic button.
3815 (let ((magic (widget-create-child-and-convert
3816 widget
'custom-magic
3819 (widget-put widget
:custom-magic magic
)
3820 (push magic buttons
))
3822 (widget-put widget
:buttons buttons
)
3823 ;; Insert documentation.
3824 (widget-default-format-handler widget ?h
)
3826 (if nil
;;; This should test that the buffer
3827 ;;; was not made to display a group.
3829 (insert-char ?\ custom-buffer-indent
)
3830 (custom-add-parent-links widget
)))
3831 (custom-add-see-also widget
3832 (make-string (* custom-buffer-indent level
)
3835 (message "Creating group...")
3836 (let* ((members (custom-sort-items members
3837 custom-buffer-sort-alphabetically
3838 custom-buffer-order-groups
))
3839 (prefixes (widget-get widget
:custom-prefixes
))
3840 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3841 (length (length members
))
3843 (children (mapcar (lambda (entry)
3844 (widget-insert "\n")
3846 Creating group members... %2d%%"
3847 (/ (* 100.0 count
) length
))
3848 (setq count
(1+ count
))
3850 (widget-create-child-and-convert
3851 widget
(nth 1 entry
)
3853 :tag
(custom-unlispify-tag-name
3855 :custom-prefixes custom-prefix-list
3856 :custom-level
(1+ level
)
3857 :value
(nth 0 entry
))
3858 (unless (eq (preceding-char) ?
\n)
3859 (widget-insert "\n"))))
3861 (message "Creating group magic...")
3862 (mapc 'custom-magic-reset children
)
3863 (message "Creating group state...")
3864 (widget-put widget
:children children
)
3865 (custom-group-state-update widget
)
3866 (message "Creating group... done"))
3869 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3870 (insert "\\- " (widget-get widget
:tag
) " group end ")
3871 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3874 (defvar custom-group-menu
3875 `(("Set for Current Session" custom-group-set
3877 (eq (widget-get widget
:custom-state
) 'modified
)))
3878 ,@(when (or custom-file user-init-file
)
3879 '(("Save for Future Sessions" custom-group-save
3881 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3882 ("Reset to Current" custom-group-reset-current
3884 (memq (widget-get widget
:custom-state
) '(modified))))
3885 ("Reset to Saved" custom-group-reset-saved
3887 (memq (widget-get widget
:custom-state
) '(modified set
))))
3888 ,@(when (or custom-file user-init-file
)
3889 '(("Reset to standard setting" custom-group-reset-standard
3891 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
3892 "Alist of actions for the `custom-group' widget.
3893 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3894 the menu entry, ACTION is the function to call on the widget when the
3895 menu is selected, and FILTER is a predicate which takes a `custom-group'
3896 widget as an argument, and returns non-nil if ACTION is valid on that
3897 widget. If FILTER is nil, ACTION is always valid.")
3899 (defun custom-group-action (widget &optional event
)
3900 "Show the menu for `custom-group' WIDGET.
3901 Optional EVENT is the location for the menu."
3902 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3903 (custom-toggle-hide widget
)
3904 (let* ((completion-ignore-case t
)
3905 (answer (widget-choose (concat "Operation on "
3906 (custom-unlispify-tag-name
3907 (widget-get widget
:value
)))
3908 (custom-menu-filter custom-group-menu
3912 (funcall answer widget
)))))
3914 (defun custom-group-set (widget)
3915 "Set changes in all modified group members."
3916 (let ((children (widget-get widget
:children
)))
3917 (mapc (lambda (child)
3918 (when (eq (widget-get child
:custom-state
) 'modified
)
3919 (widget-apply child
:custom-set
)))
3922 (defun custom-group-save (widget)
3923 "Save all modified group members."
3924 (let ((children (widget-get widget
:children
)))
3925 (mapc (lambda (child)
3926 (when (memq (widget-get child
:custom-state
) '(modified set
))
3927 (widget-apply child
:custom-save
)))
3930 (defun custom-group-reset-current (widget)
3931 "Reset all modified group members."
3932 (let ((children (widget-get widget
:children
)))
3933 (mapc (lambda (child)
3934 (when (eq (widget-get child
:custom-state
) 'modified
)
3935 (widget-apply child
:custom-reset-current
)))
3938 (defun custom-group-reset-saved (widget)
3939 "Reset all modified or set group members."
3940 (let ((children (widget-get widget
:children
)))
3941 (mapc (lambda (child)
3942 (when (memq (widget-get child
:custom-state
) '(modified set
))
3943 (widget-apply child
:custom-reset-saved
)))
3946 (defun custom-group-reset-standard (widget)
3947 "Reset all modified, set, or saved group members."
3948 (let ((children (widget-get widget
:children
)))
3949 (mapc (lambda (child)
3950 (when (memq (widget-get child
:custom-state
)
3951 '(modified set saved
))
3952 (widget-apply child
:custom-reset-standard
)))
3955 (defun custom-group-state-update (widget)
3957 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3958 (let* ((children (widget-get widget
:children
))
3959 (states (mapcar (lambda (child)
3960 (widget-get child
:custom-state
))
3962 (magics custom-magic-alist
)
3965 (let ((magic (car (car magics
))))
3966 (if (and (not (eq magic
'hidden
))
3967 (memq magic states
))
3970 (setq magics
(cdr magics
)))))
3971 (widget-put widget
:custom-state found
)))
3972 (custom-magic-reset widget
))
3974 ;;; Reading and writing the custom file.
3977 (defcustom custom-file nil
3978 "File used for storing customization information.
3979 The default is nil, which means to use your init file
3980 as specified by `user-init-file'. If the value is not nil,
3981 it should be an absolute file name.
3983 You can set this option through Custom, if you carefully read the
3984 last paragraph below. However, usually it is simpler to write
3985 something like the following in your init file:
3987 \(setq custom-file \"~/.emacs-custom.el\")
3990 Note that both lines are necessary: the first line tells Custom to
3991 save all customizations in this file, but does not load it.
3993 When you change this variable outside Custom, look in the
3994 previous custom file \(usually your init file) for the
3995 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3996 and copy them (whichever ones you find) to the new custom file.
3997 This will preserve your existing customizations.
3999 If you save this option using Custom, Custom will write all
4000 currently saved customizations, including the new one for this
4001 option itself, into the file you specify, overwriting any
4002 `custom-set-variables' and `custom-set-faces' forms already
4003 present in that file. It will not delete any customizations from
4004 the old custom file. You should do that manually if that is what you
4005 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4006 in your init file, where CUSTOM-FILE is the actual name of the
4007 file. Otherwise, Emacs will not load the file when it starts up,
4008 and hence will not set `custom-file' to that file either."
4009 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4010 (file :format
"%t:%v%d"
4012 "Please read entire docstring below before setting \
4013 this through Custom.
4014 Click om \"More\" \(or position point there and press RETURN)
4015 if only the first line of the docstring is shown."))
4018 (defun custom-file ()
4019 "Return the file name for saving customizations."
4022 (let ((user-init-file user-init-file
)
4024 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4025 (when (null user-init-file
)
4026 (if (or (file-exists-p default-init-file
)
4027 (and (eq system-type
'windows-nt
)
4028 (file-exists-p "~/_emacs")))
4029 ;; Started with -q, i.e. the file containing
4030 ;; Custom settings hasn't been read. Saving
4031 ;; settings there would overwrite other settings.
4032 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4033 (setq user-init-file default-init-file
))
4037 (defun custom-save-all ()
4038 "Save all customizations in `custom-file'."
4039 (let* ((filename (custom-file))
4040 (recentf-exclude (if recentf-mode
4042 (regexp-quote (custom-file))
4045 (old-buffer (find-buffer-visiting filename
)))
4046 (with-current-buffer (or old-buffer
(find-file-noselect filename
))
4047 (let ((inhibit-read-only t
))
4048 (custom-save-variables)
4049 (custom-save-faces))
4050 (let ((file-precious-flag t
))
4053 (kill-buffer (current-buffer))))))
4056 (defun customize-save-customized ()
4057 "Save all user options which have been set in this session."
4059 (mapatoms (lambda (symbol)
4060 (let ((face (get symbol
'customized-face
))
4061 (value (get symbol
'customized-value
))
4062 (face-comment (get symbol
'customized-face-comment
))
4064 (get symbol
'customized-variable-comment
)))
4066 (put symbol
'saved-face face
)
4067 (custom-push-theme 'theme-face symbol
'user
'set value
)
4068 (put symbol
'customized-face nil
))
4070 (put symbol
'saved-value value
)
4071 (custom-push-theme 'theme-value symbol
'user
'set value
)
4072 (put symbol
'customized-value nil
))
4073 (when variable-comment
4074 (put symbol
'saved-variable-comment variable-comment
)
4075 (put symbol
'customized-variable-comment nil
))
4077 (put symbol
'saved-face-comment face-comment
)
4078 (put symbol
'customized-face-comment nil
)))))
4079 ;; We really should update all custom buffers here.
4082 ;; Editing the custom file contents in a buffer.
4084 (defun custom-save-delete (symbol)
4085 "Delete all calls to SYMBOL from the contents of the current buffer.
4086 Leave point at the old location of the first such call,
4087 or (if there were none) at the end of the buffer.
4089 This function does not save the buffer."
4090 (goto-char (point-min))
4091 ;; Skip all whitespace and comments.
4092 (while (forward-comment 1))
4094 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4097 (while t
;; We exit this loop only via throw.
4098 ;; Skip all whitespace and comments.
4099 (while (forward-comment 1))
4100 (let ((start (point))
4101 (sexp (condition-case nil
4102 (read (current-buffer))
4103 (end-of-file (throw 'found nil
)))))
4104 (when (and (listp sexp
)
4105 (eq (car sexp
) symbol
))
4106 (delete-region start
(point))
4108 (setq first
(point)))))))
4111 ;; Move in front of local variables, otherwise long Custom
4112 ;; entries would make them ineffective.
4113 (let ((pos (point-max))
4114 (case-fold-search t
))
4116 (goto-char (point-max))
4117 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4119 (when (search-forward "Local Variables:" nil t
)
4120 (setq pos
(line-beginning-position))))
4123 (defun custom-save-variables ()
4124 "Save all customized variables in `custom-file'."
4126 (custom-save-delete 'custom-reset-variables
)
4127 (custom-save-delete 'custom-set-variables
)
4128 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
4129 (let ((standard-output (current-buffer))
4130 (saved-list (make-list 1 0))
4132 ;; First create a sorted list of saved variables.
4135 (if (get symbol
'saved-value
)
4136 (nconc saved-list
(list symbol
)))))
4137 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4140 (princ "(custom-set-variables
4141 ;; custom-set-variables was added by Custom.
4142 ;; If you edit it by hand, you could mess it up, so be careful.
4143 ;; Your init file should contain only one such instance.
4144 ;; If there is more than one, they won't work right.\n")
4145 (dolist (symbol saved-list
)
4146 (let ((spec (car-safe (get symbol
'theme-value
)))
4147 (value (get symbol
'saved-value
))
4148 (requests (get symbol
'custom-requests
))
4149 (now (not (or (custom-variable-p symbol
)
4150 (and (not (boundp symbol
))
4151 (not (eq (get symbol
'force-value
)
4153 (comment (get symbol
'saved-variable-comment
)))
4154 ;; Check `requests'.
4155 (dolist (request requests
)
4156 (when (and (symbolp request
) (not (featurep request
)))
4157 (message "Unknown requested feature: %s" request
)
4158 (setq requests
(delq request requests
))))
4160 (eq (nth 0 spec
) 'user
)
4161 (eq (nth 1 spec
) 'set
))
4163 (and (null spec
) (get symbol
'saved-value
)))
4170 (when (or now requests comment
)
4173 (when (or requests comment
)
4183 (unless (looking-at "\n")
4186 (defun custom-save-resets (property setter special
)
4187 (let (started-writing ignored-special
)
4188 ;; (custom-save-delete setter) Done by caller
4189 (let ((standard-output (current-buffer))
4190 (mapper `(lambda (object)
4191 (let ((spec (car-safe (get object
(quote ,property
)))))
4192 (when (and (not (memq object ignored-special
))
4193 (eq (nth 0 spec
) 'user
)
4194 (eq (nth 1 spec
) 'reset
))
4195 ;; Do not write reset statements unless necessary.
4196 (unless started-writing
4197 (setq started-writing t
)
4201 (princ (quote ,setter
))
4205 (prin1 (nth 3 spec
))
4207 (mapc mapper special
)
4208 (setq ignored-special special
)
4210 (when started-writing
4213 (defun custom-save-faces ()
4214 "Save all customized faces in `custom-file'."
4216 (custom-save-delete 'custom-reset-faces
)
4217 (custom-save-delete 'custom-set-faces
)
4218 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
4219 (let ((standard-output (current-buffer))
4220 (saved-list (make-list 1 0))
4222 ;; First create a sorted list of saved faces.
4225 (if (get symbol
'saved-face
)
4226 (nconc saved-list
(list symbol
)))))
4227 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4228 ;; The default face must be first, since it affects the others.
4229 (if (memq 'default saved-list
)
4230 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4233 (princ "(custom-set-faces
4234 ;; custom-set-faces was added by Custom.
4235 ;; If you edit it by hand, you could mess it up, so be careful.
4236 ;; Your init file should contain only one such instance.
4237 ;; If there is more than one, they won't work right.\n")
4238 (dolist (symbol saved-list
)
4239 (let ((spec (car-safe (get symbol
'theme-face
)))
4240 (value (get symbol
'saved-face
))
4241 (now (not (or (get symbol
'face-defface-spec
)
4242 (and (not (custom-facep symbol
))
4243 (not (get symbol
'force-face
))))))
4244 (comment (get symbol
'saved-face-comment
)))
4246 (eq (nth 0 spec
) 'user
)
4247 (eq (nth 1 spec
) 'set
))
4249 (and (null spec
) (get symbol
'saved-face
)))
4250 ;; Don't print default face here.
4257 (when (or now comment
)
4267 (unless (looking-at "\n")
4270 ;;; The Customize Menu.
4274 (defcustom custom-menu-nesting
2
4275 "Maximum nesting in custom menus."
4277 :group
'custom-menu
)
4279 (defun custom-face-menu-create (widget symbol
)
4280 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4281 (vector (custom-unlispify-menu-entry symbol
)
4282 `(customize-face ',symbol
)
4285 (defun custom-variable-menu-create (widget symbol
)
4286 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4287 (let ((type (get symbol
'custom-type
)))
4288 (unless (listp type
)
4289 (setq type
(list type
)))
4290 (if (and type
(widget-get type
:custom-menu
))
4291 (widget-apply type
:custom-menu symbol
)
4292 (vector (custom-unlispify-menu-entry symbol
)
4293 `(customize-variable ',symbol
)
4296 ;; Add checkboxes to boolean variable entries.
4297 (widget-put (get 'boolean
'widget-type
)
4298 :custom-menu
(lambda (widget symbol
)
4299 (vector (custom-unlispify-menu-entry symbol
)
4300 `(customize-variable ',symbol
)
4302 ':selected symbol
)))
4304 (defun custom-group-menu-create (widget symbol
)
4305 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4306 `( ,(custom-unlispify-menu-entry symbol t
)
4307 :filter
(lambda (&rest junk
)
4308 (let ((menu (custom-menu-create ',symbol
)))
4309 (if (consp menu
) (cdr menu
) menu
)))))
4312 (defun custom-menu-create (symbol)
4313 "Create menu for customization group SYMBOL.
4314 The menu is in a format applicable to `easy-menu-define'."
4315 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4316 `(customize-group ',symbol
)
4318 (if (and (or (not (boundp 'custom-menu-nesting
))
4319 (>= custom-menu-nesting
0))
4321 (custom-load-symbol symbol
)
4322 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4323 (let ((custom-prefix-list (custom-prefix-add symbol
4324 custom-prefix-list
))
4325 (members (custom-sort-items (get symbol
'custom-group
)
4326 custom-menu-sort-alphabetically
4327 custom-menu-order-groups
)))
4328 `(,(custom-unlispify-menu-entry symbol t
)
4331 ,@(mapcar (lambda (entry)
4332 (widget-apply (if (listp (nth 1 entry
))
4334 (list (nth 1 entry
)))
4335 :custom-menu
(nth 0 entry
)))
4340 (defun customize-menu-create (symbol &optional name
)
4341 "Return a customize menu for customization group SYMBOL.
4342 If optional NAME is given, use that as the name of the menu.
4343 Otherwise the menu will be named `Customize'.
4344 The format is suitable for use with `easy-menu-define'."
4346 (setq name
"Customize"))
4348 :filter
(lambda (&rest junk
)
4349 (let ((menu (custom-menu-create ',symbol
)))
4350 (if (consp menu
) (cdr menu
) menu
)))))
4352 ;;; The Custom Mode.
4354 (defvar custom-mode-map
4355 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4356 ;; "\r" bindings from the parent map.
4357 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4358 (let ((map (make-keymap)))
4359 (set-keymap-parent map widget-keymap
)
4360 (suppress-keymap map
)
4361 (define-key map
" " 'scroll-up
)
4362 (define-key map
"\177" 'scroll-down
)
4363 (define-key map
"\C-c\C-c" 'Custom-set
)
4364 (define-key map
"\C-x\C-s" 'Custom-save
)
4365 (define-key map
"q" 'Custom-buffer-done
)
4366 (define-key map
"u" 'Custom-goto-parent
)
4367 (define-key map
"n" 'widget-forward
)
4368 (define-key map
"p" 'widget-backward
)
4369 (define-key map
[mouse-1
] 'widget-move-and-invoke
)
4371 "Keymap for `custom-mode'.")
4373 (easy-menu-define Custom-mode-menu
4375 "Menu used in customization buffers."
4377 ,(customize-menu-create 'customize
)
4378 ["Set" Custom-set t
]
4379 ["Save" Custom-save t
]
4380 ["Reset to Current" Custom-reset-current t
]
4381 ["Reset to Saved" Custom-reset-saved t
]
4382 ["Reset to Standard Values" Custom-reset-standard t
]
4383 ["Info" (info "(emacs)Easy Customization") t
]))
4385 (defun Custom-goto-parent ()
4386 "Go to the parent group listed at the top of this buffer.
4387 If several parents are listed, go to the first of them."
4390 (goto-char (point-min))
4391 (if (search-forward "\nGo to parent group: " nil t
)
4392 (let* ((button (get-char-property (point) 'button
))
4393 (parent (downcase (widget-get button
:tag
))))
4394 (customize-group parent
)))))
4396 (defcustom custom-mode-hook nil
4397 "Hook called when entering Custom mode."
4399 :group
'custom-buffer
)
4401 (defun custom-state-buffer-message (widget)
4402 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4403 (message "To install your edits, invoke [State] and choose the Set operation")))
4405 (defun custom-mode ()
4406 "Major mode for editing customization buffers.
4408 The following commands are available:
4410 Move to next button or editable field. \\[widget-forward]
4411 Move to previous button or editable field. \\[widget-backward]
4412 \\<widget-field-keymap>\
4413 Complete content of editable text field. \\[widget-complete]
4414 \\<custom-mode-map>\
4415 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4416 Invoke button under point. \\[widget-button-press]
4417 Set all options from current text. \\[Custom-set]
4418 Make values in current text permanent. \\[Custom-save]
4419 Make text match actual option values. \\[Custom-reset-current]
4420 Reset options to permanent settings. \\[Custom-reset-saved]
4421 Erase customizations; set options
4422 and buffer text to the standard values. \\[Custom-reset-standard]
4424 Entry to this mode calls the value of `custom-mode-hook'
4425 if that value is non-nil."
4426 (kill-all-local-variables)
4427 (setq major-mode
'custom-mode
4429 (use-local-map custom-mode-map
)
4430 (easy-menu-add Custom-mode-menu
)
4431 (make-local-variable 'custom-options
)
4432 (make-local-variable 'custom-local-buffer
)
4433 (make-local-variable 'widget-documentation-face
)
4434 (setq widget-documentation-face
'custom-documentation
)
4435 (make-local-variable 'widget-button-face
)
4436 (setq widget-button-face custom-button
)
4437 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4438 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4440 ;; When possible, use relief for buttons, not bracketing. This test
4441 ;; may not be optimal.
4442 (when custom-raised-buttons
4443 (set (make-local-variable 'widget-push-button-prefix
) "")
4444 (set (make-local-variable 'widget-push-button-suffix
) "")
4445 (set (make-local-variable 'widget-link-prefix
) "")
4446 (set (make-local-variable 'widget-link-suffix
) ""))
4447 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4448 (run-mode-hooks 'custom-mode-hook
))
4450 (put 'custom-mode
'mode-class
'special
)
4453 'debug-ignored-errors
4454 "^No user options have changed defaults in recent Emacs versions$")
4460 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4461 ;;; cus-edit.el ends here