1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. You
125 ;; can not create a Custom buffer for such variables using the
126 ;; normal interactive Custom commands. However, such Custom
127 ;; buffers can be created in other ways, for instance, by calling
128 ;; `customize-option' non-interactively.
132 ;; There is no widget value.
136 ;; The widget value is not valid member of the :type specified for the
144 (defvar custom-versions-load-alist
) ; from cus-load
145 (defvar recentf-exclude
)) ; from recentf.el
155 (put 'custom-define-hook
'custom-type
'hook
)
156 (put 'custom-define-hook
'standard-value
'(nil))
157 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
159 ;;; Customization Groups.
162 "Customization of the One True Editor."
163 :link
'(custom-manual "(emacs)Top"))
165 ;; Most of these groups are stolen from `finder.el',
166 (defgroup editing nil
167 "Basic text editing facilities."
171 "Abbreviation handling, typing shortcuts, macros."
175 (defgroup matching nil
176 "Various sorts of searching and matching."
179 (defgroup emulations nil
180 "Emulations of other editors."
181 :link
'(custom-manual "(emacs)Emulation")
188 (defgroup outlines nil
189 "Support for hierarchical outlining."
192 (defgroup external nil
193 "Interfacing to external utilities."
196 (defgroup processes nil
197 "Process, subshell, compilation, and job control support."
201 (defgroup convenience nil
202 "Convenience features for faster editing."
205 (defgroup programming nil
206 "Support for programming in other languages."
209 (defgroup languages nil
210 "Specialized modes for editing programming languages."
214 "Lisp support, including Emacs Lisp."
215 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
220 "Support for the C language and related languages."
221 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
222 :link
'(custom-manual "(ccmode)")
230 "Support for object-oriented programming."
233 (defgroup applications nil
234 "Applications written in Emacs."
237 (defgroup calendar nil
238 "Calendar and time management support."
239 :group
'applications
)
242 "Modes for electronic-mail handling."
243 :group
'applications
)
246 "Support for netnews reading and posting."
247 :link
'(custom-manual "(gnus)")
248 :group
'applications
)
251 "Games, jokes and amusements."
252 :group
'applications
)
254 (defgroup development nil
255 "Support for further development of Emacs."
259 "Support for Emacs documentation."
262 (defgroup extensions nil
263 "Emacs Lisp language extensions."
266 (defgroup internal nil
267 "Code for Emacs internals, build process, defaults."
271 "Maintenance aids for the Emacs development group."
275 (defgroup environment nil
276 "Fitting Emacs with its environment."
280 "Communications, networking, remote access to files."
284 (defgroup hardware nil
285 "Support for interfacing with exotic hardware."
288 (defgroup terminals nil
289 "Support for terminal types."
293 "Front-ends/assistants for, or emulators of, UNIX features."
297 "Support code for vms."
301 "Internationalization and alternate character-set support."
302 :link
'(custom-manual "(emacs)International")
307 "The X Window system."
311 "Support for Emacs frames and window systems."
315 "Support editing files of data."
319 "Support editing files."
327 "Code related to the TeX formatter."
328 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
332 "Support for multiple fonts."
335 (defgroup hypermedia nil
336 "Support for links between text or other media types."
340 "Support for on-line help systems."
343 (defgroup multimedia nil
344 "Non-textual support, specifically images and sound."
348 "Code local to your site."
351 (defgroup customize
'((widgets custom-group
))
352 "Customization of the Customization support."
356 (defgroup custom-faces nil
357 "Faces used by customize."
361 (defgroup custom-browse nil
362 "Control customize browser."
366 (defgroup custom-buffer nil
367 "Control customize buffers."
371 (defgroup custom-menu nil
372 "Control customize menus."
376 (defgroup abbrev-mode nil
377 "Word abbreviations mode."
378 :link
'(custom-manual "(emacs)Abbrevs")
382 "Storage allocation and gc for GNU Emacs Lisp interpreter."
383 :tag
"Storage Allocation"
387 "Undoing changes in buffers."
388 :link
'(custom-manual "(emacs)Undo")
391 (defgroup modeline nil
392 "Content of the modeline."
395 (defgroup editing-basics nil
396 "Most basic editing facilities."
399 (defgroup display nil
400 "How characters are displayed in buffers."
403 (defgroup execute nil
404 "Executing external commands."
407 (defgroup installation nil
408 "The Emacs installation."
416 "Internal Emacs limits."
420 "Debugging Emacs itself."
423 (defgroup minibuffer nil
424 "Controling the behavior of the minibuffer."
425 :link
'(custom-manual "(emacs)Minibuffer")
428 (defgroup keyboard nil
429 "Input from the keyboard."
433 "Input from the mouse."
437 "Input from the menus."
441 "Handling data from drag and drop."
444 (defgroup auto-save nil
445 "Preventing accidential loss of data."
448 (defgroup processes-basics nil
449 "Basic stuff dealing with processes."
453 "MULE Emacs internationalization."
456 (defgroup windows nil
457 "Windows within a frame."
458 :link
'(custom-manual "(emacs)Windows")
463 (defun custom-quote (sexp)
464 "Quote SEXP iff it is not self quoting."
465 (if (or (memq sexp
'(t nil
))
468 (memq (car sexp
) '(lambda)))
472 ;;; (and (fboundp 'characterp)
473 ;;; (characterp sexp))
478 (defun custom-split-regexp-maybe (regexp)
479 "If REGEXP is a string, split it to a list at `\\|'.
480 You can get the original back with from the result with:
481 (mapconcat 'identity result \"\\|\")
483 IF REGEXP is not a string, return it unchanged."
487 (while (string-match "\\\\|" regexp start
)
488 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
489 start
(match-end 0)))
490 (nreverse (cons (substring regexp start
) all
)))
493 (defun custom-variable-prompt ()
494 "Prompt for a custom variable, defaulting to the variable at point.
495 Return a list suitable for use in `interactive'."
496 (let* ((v (variable-at-point))
497 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
498 (enable-recursive-minibuffers t
)
500 (setq val
(completing-read
501 (if default
(format "Customize option (default %s): " default
)
502 "Customize option: ")
503 obarray
'custom-variable-p t nil nil default
))
504 (list (if (equal val
"")
505 (if (symbolp v
) v nil
)
508 (defun custom-menu-filter (menu widget
)
509 "Convert MENU to the form used by `widget-choose'.
510 MENU should be in the same format as `custom-variable-menu'.
511 WIDGET is the widget to apply the filter entries of MENU on."
513 current name action filter
)
515 (setq current
(car menu
)
517 action
(nth 1 current
)
518 filter
(nth 2 current
)
520 (if (or (null filter
) (funcall filter widget
))
521 (push (cons name action
) result
)
527 (defvar custom-prefix-list nil
528 "List of prefixes that should be ignored by `custom-unlispify'.")
530 (defcustom custom-unlispify-menu-entries t
531 "Display menu entries as words instead of symbols if non nil."
535 (defcustom custom-unlispify-remove-prefixes nil
536 "Non-nil means remove group prefixes from option names in buffer."
538 :group
'custom-buffer
541 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
542 "Convert SYMBOL into a menu entry."
543 (cond ((not custom-unlispify-menu-entries
)
544 (symbol-name symbol
))
545 ((get symbol
'custom-tag
)
547 (get symbol
'custom-tag
)
548 (concat (get symbol
'custom-tag
) "...")))
550 (with-current-buffer (get-buffer-create " *Custom-Work*")
552 (princ symbol
(current-buffer))
553 (goto-char (point-min))
554 ;; FIXME: Boolean variables are not predicates, so they shouldn't
555 ;; end with `-p'. -stef
556 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
557 ;; (re-search-forward "-p\\'" nil t))
558 ;; (replace-match "" t t)
559 ;; (goto-char (point-min)))
560 (if custom-unlispify-remove-prefixes
561 (let ((prefixes custom-prefix-list
)
564 (setq prefix
(car prefixes
))
565 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
568 (delete-region (point-min) (point)))
569 (setq prefixes
(cdr prefixes
))))))
570 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
571 (capitalize-region (point-min) (point-max))
573 (goto-char (point-max))
577 (defcustom custom-unlispify-tag-names t
578 "Display tag names as words instead of symbols if non nil."
579 :group
'custom-buffer
582 (defun custom-unlispify-tag-name (symbol)
583 "Convert SYMBOL into a menu entry."
584 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
585 (custom-unlispify-menu-entry symbol t
)))
587 (defun custom-prefix-add (symbol prefixes
)
588 "Add SYMBOL to list of ignored PREFIXES."
589 (cons (or (get symbol
'custom-prefix
)
590 (concat (symbol-name symbol
) "-"))
595 (defcustom custom-guess-name-alist
600 ("-function\\'" function
)
601 ("-functions\\'" (repeat function
))
602 ("-list\\'" (repeat sexp
))
603 ("-alist\\'" (repeat (cons sexp sexp
))))
604 "Alist of (MATCH TYPE).
606 MATCH should be a regexp matching the name of a symbol, and TYPE should
607 be a widget suitable for editing the value of that symbol. The TYPE
608 of the first entry where MATCH matches the name of the symbol will be
611 This is used for guessing the type of variables not declared with
613 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
616 (defcustom custom-guess-doc-alist
617 '(("\\`\\*?Non-nil " boolean
))
618 "Alist of (MATCH TYPE).
620 MATCH should be a regexp matching a documentation string, and TYPE
621 should be a widget suitable for editing the value of a variable with
622 that documentation string. The TYPE of the first entry where MATCH
623 matches the name of the symbol will be used.
625 This is used for guessing the type of variables not declared with
627 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
630 (defun custom-guess-type (symbol)
631 "Guess a widget suitable for editing the value of SYMBOL.
632 This is done by matching SYMBOL with `custom-guess-name-alist' and
633 if that fails, the doc string with `custom-guess-doc-alist'."
634 (let ((name (symbol-name symbol
))
635 (names custom-guess-name-alist
)
638 (setq current
(car names
)
640 (when (string-match (nth 0 current
) name
)
641 (setq found
(nth 1 current
)
644 (let ((doc (documentation-property symbol
'variable-documentation
))
645 (docs custom-guess-doc-alist
))
648 (setq current
(car docs
)
650 (when (string-match (nth 0 current
) doc
)
651 (setq found
(nth 1 current
)
657 (defcustom custom-browse-sort-alphabetically nil
658 "If non-nil, sort members of each customization group alphabetically."
660 :group
'custom-browse
)
662 (defcustom custom-browse-order-groups nil
663 "If non-nil, order group members within each customization group.
664 If `first', order groups before non-groups.
665 If `last', order groups after non-groups."
666 :type
'(choice (const first
)
668 (const :tag
"none" nil
))
669 :group
'custom-browse
)
671 (defcustom custom-browse-only-groups nil
672 "If non-nil, show group members only within each customization group."
674 :group
'custom-browse
)
676 (defcustom custom-buffer-sort-alphabetically nil
677 "If non-nil, sort members of each customization group alphabetically."
679 :group
'custom-buffer
)
681 (defcustom custom-buffer-order-groups
'last
682 "If non-nil, order group members within each customization group.
683 If `first', order groups before non-groups.
684 If `last', order groups after non-groups."
685 :type
'(choice (const first
)
687 (const :tag
"none" nil
))
688 :group
'custom-buffer
)
690 (defcustom custom-menu-sort-alphabetically nil
691 "If non-nil, sort members of each customization group alphabetically."
695 (defcustom custom-menu-order-groups
'first
696 "If non-nil, order group members within each customization group.
697 If `first', order groups before non-groups.
698 If `last', order groups after non-groups."
699 :type
'(choice (const first
)
701 (const :tag
"none" nil
))
704 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
706 (defun custom-sort-items (items sort-alphabetically order-groups
)
707 "Return a sorted copy of ITEMS.
708 ITEMS should be a `custom-group' property.
709 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
710 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
711 groups after non-groups, if nil do not order groups at all."
712 (sort (copy-sequence items
)
714 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
715 (namea (nth 0 a
)) (nameb (nth 0 b
)))
716 (cond ((not order-groups
)
717 ;; Since we don't care about A and B order, maybe sort.
718 (when sort-alphabetically
719 (string-lessp namea nameb
)))
720 ((eq typea
'custom-group
)
721 ;; If B is also a group, maybe sort. Otherwise, order A and B.
722 (if (eq typeb
'custom-group
)
723 (when sort-alphabetically
724 (string-lessp namea nameb
))
725 (eq order-groups
'first
)))
726 ((eq typeb
'custom-group
)
727 ;; Since A cannot be a group, order A and B.
728 (eq order-groups
'last
))
730 ;; Since A and B cannot be groups, sort.
731 (string-lessp namea nameb
)))))))
733 ;;; Custom Mode Commands.
735 (defvar custom-options nil
736 "Customization widgets in the current buffer.")
739 "Set changes in all modified options."
741 (let ((children custom-options
))
742 (mapc (lambda (child)
743 (when (eq (widget-get child
:custom-state
) 'modified
)
744 (widget-apply child
:custom-set
)))
747 (defun Custom-save ()
748 "Set all modified group members and save them."
750 (let ((children custom-options
))
751 (mapc (lambda (child)
752 (when (memq (widget-get child
:custom-state
)
753 '(modified set changed rogue
))
754 (widget-apply child
:custom-save
)))
758 (defvar custom-reset-menu
759 '(("Current" . Custom-reset-current
)
760 ("Saved" . Custom-reset-saved
)
761 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
762 "Alist of actions for the `Reset' button.
763 The key is a string containing the name of the action, the value is a
764 Lisp function taking the widget as an element which will be called
765 when the action is chosen.")
767 (defun custom-reset (event)
768 "Select item from reset menu."
769 (let* ((completion-ignore-case t
)
770 (answer (widget-choose "Reset to"
776 (defun Custom-reset-current (&rest ignore
)
777 "Reset all modified group members to their current value."
779 (let ((children custom-options
))
780 (mapc (lambda (widget)
781 (if (memq (widget-get widget
:custom-state
)
783 (widget-apply widget
:custom-reset-current
)))
786 (defun Custom-reset-saved (&rest ignore
)
787 "Reset all modified or set group members to their saved value."
789 (let ((children custom-options
))
790 (mapc (lambda (widget)
791 (if (memq (widget-get widget
:custom-state
)
792 '(modified set changed rogue
))
793 (widget-apply widget
:custom-reset-saved
)))
796 (defun Custom-reset-standard (&rest ignore
)
797 "Erase all customization (either current or saved) for the group members.
798 The immediate result is to restore them to their standard settings.
799 This operation eliminates any saved settings for the group members,
800 making them as if they had never been customized at all."
802 (let ((children custom-options
))
803 (when (or (and (= 1 (length children
))
804 (memq (widget-type (car children
))
805 '(custom-variable custom-face
)))
806 (yes-or-no-p "Really erase all customizations in this buffer? "))
807 (mapc (lambda (widget)
808 (and (if (widget-get widget
:custom-standard-value
)
809 (widget-apply widget
:custom-standard-value
)
811 (memq (widget-get widget
:custom-state
)
812 '(modified set changed saved rogue
))
813 (widget-apply widget
:custom-reset-standard
)))
816 ;;; The Customize Commands
818 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
819 "Prompt for a variable and a value and return them as a list.
820 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
821 prompt for the value. The %s escape in PROMPT-VAL is replaced with
822 the name of the variable.
824 If the variable has a `variable-interactive' property, that is used as if
825 it were the arg to `interactive' (which see) to interactively read the value.
827 If the variable has a `custom-type' property, it must be a widget and the
828 `:prompt-value' property of that widget will be used for reading the value.
830 If optional COMMENT argument is non nil, also prompt for a comment and return
831 it as the third element in the list."
832 (let* ((var (read-variable prompt-var
))
833 (minibuffer-help-form '(describe-variable var
))
835 (let ((prop (get var
'variable-interactive
))
836 (type (get var
'custom-type
))
837 (prompt (format prompt-val var
)))
839 (setq type
(list type
)))
841 ;; Use VAR's `variable-interactive' property
842 ;; as an interactive spec for prompting.
843 (call-interactively (list 'lambda
'(arg)
844 (list 'interactive prop
)
847 (widget-prompt-value type
853 (eval-minibuffer prompt
))))))
856 (read-string "Comment: " (get var
'variable-comment
)))
860 (defun customize-set-value (variable value
&optional comment
)
861 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
863 If VARIABLE has a `variable-interactive' property, that is used as if
864 it were the arg to `interactive' (which see) to interactively read the value.
866 If VARIABLE has a `custom-type' property, it must be a widget and the
867 `:prompt-value' property of that widget will be used for reading the value.
869 If given a prefix (or a COMMENT argument), also prompt for a comment."
870 (interactive (custom-prompt-variable "Set variable: "
874 (cond ((string= comment
"")
875 (put variable
'variable-comment nil
))
877 (put variable
'variable-comment comment
)))
878 (set variable value
))
881 (defun customize-set-variable (variable value
&optional comment
)
882 "Set the default for VARIABLE to VALUE, and return VALUE.
883 VALUE is a Lisp object.
885 If VARIABLE has a `custom-set' property, that is used for setting
886 VARIABLE, otherwise `set-default' is used.
888 The `customized-value' property of the VARIABLE will be set to a list
889 with a quoted VALUE as its sole list member.
891 If VARIABLE has a `variable-interactive' property, that is used as if
892 it were the arg to `interactive' (which see) to interactively read the value.
894 If VARIABLE has a `custom-type' property, it must be a widget and the
895 `:prompt-value' property of that widget will be used for reading the value.
897 If given a prefix (or a COMMENT argument), also prompt for a comment."
898 (interactive (custom-prompt-variable "Set variable: "
899 "Set customized value for %s to: "
901 (custom-load-symbol variable
)
902 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
903 (put variable
'customized-value
(list (custom-quote value
)))
904 (cond ((string= comment
"")
905 (put variable
'variable-comment nil
)
906 (put variable
'customized-variable-comment nil
))
908 (put variable
'variable-comment comment
)
909 (put variable
'customized-variable-comment comment
)))
913 (defun customize-save-variable (variable value
&optional comment
)
914 "Set the default for VARIABLE to VALUE, and save it for future sessions.
917 If VARIABLE has a `custom-set' property, that is used for setting
918 VARIABLE, otherwise `set-default' is used.
920 The `customized-value' property of the VARIABLE will be set to a list
921 with a quoted VALUE as its sole list member.
923 If VARIABLE has a `variable-interactive' property, that is used as if
924 it were the arg to `interactive' (which see) to interactively read the value.
926 If VARIABLE has a `custom-type' property, it must be a widget and the
927 `:prompt-value' property of that widget will be used for reading the value.
929 If given a prefix (or a COMMENT argument), also prompt for a comment."
930 (interactive (custom-prompt-variable "Set and save variable: "
931 "Set and save value for %s as: "
933 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
934 (put variable
'saved-value
(list (custom-quote value
)))
935 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
936 (cond ((string= comment
"")
937 (put variable
'variable-comment nil
)
938 (put variable
'saved-variable-comment nil
))
940 (put variable
'variable-comment comment
)
941 (put variable
'saved-variable-comment comment
)))
947 "Select a customization buffer which you can use to set user options.
948 User options are structured into \"groups\".
949 Initially the top-level group `Emacs' and its immediate subgroups
950 are shown; the contents of those subgroups are initially hidden."
952 (customize-group 'emacs
))
955 (defun customize-mode (mode)
956 "Customize options related to the current major mode.
957 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
958 then prompt for the MODE to customize."
961 (let ((completion-regexp-list '("-mode\\'"))
962 (group (custom-group-of-mode major-mode
)))
963 (if (and group
(not current-prefix-arg
))
966 (completing-read (if group
967 (format "Major mode (default %s): " major-mode
)
970 'custom-group-of-mode
971 t nil nil
(if group
(symbol-name major-mode
))))))))
972 (customize-group (custom-group-of-mode mode
)))
976 (defun customize-group (group)
977 "Customize GROUP, which must be a customization group."
978 (interactive (list (let ((completion-ignore-case t
))
979 (completing-read "Customize group (default emacs): "
982 (or (get symbol
'custom-loads
)
983 (get symbol
'custom-group
)))
985 (when (stringp group
)
986 (if (string-equal "" group
)
988 (setq group
(intern group
))))
989 (let ((name (format "*Customize Group: %s*"
990 (custom-unlispify-tag-name group
))))
991 (if (get-buffer name
)
993 (custom-buffer-create (list (list group
'custom-group
))
995 (concat " for group "
996 (custom-unlispify-tag-name group
))))))
999 (defun customize-group-other-window (group)
1000 "Customize GROUP, which must be a customization group."
1001 (interactive (list (let ((completion-ignore-case t
))
1002 (completing-read "Customize group (default emacs): "
1005 (or (get symbol
'custom-loads
)
1006 (get symbol
'custom-group
)))
1008 (when (stringp group
)
1009 (if (string-equal "" group
)
1011 (setq group
(intern group
))))
1012 (let ((name (format "*Customize Group: %s*"
1013 (custom-unlispify-tag-name group
))))
1014 (if (get-buffer name
)
1016 ;; Copied from `custom-buffer-create-other-window'.
1018 (same-window-buffer-names nil
)
1019 (same-window-regexps nil
))
1020 (pop-to-buffer name
))
1021 (custom-buffer-create-other-window
1022 (list (list group
'custom-group
))
1024 (concat " for group "
1025 (custom-unlispify-tag-name group
))))))
1028 (defalias 'customize-variable
'customize-option
)
1031 (defun customize-option (symbol)
1032 "Customize SYMBOL, which must be a user option variable."
1033 (interactive (custom-variable-prompt))
1034 (let ((basevar (indirect-variable symbol
)))
1035 (custom-buffer-create (list (list basevar
'custom-variable
))
1036 (format "*Customize Option: %s*"
1037 (custom-unlispify-tag-name basevar
)))
1038 (unless (eq symbol basevar
)
1039 (message "`%s' is an alias for `%s'" symbol basevar
))))
1042 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1045 (defun customize-option-other-window (symbol)
1046 "Customize SYMBOL, which must be a user option variable.
1047 Show the buffer in another window, but don't select it."
1048 (interactive (custom-variable-prompt))
1049 (let ((basevar (indirect-variable symbol
)))
1050 (custom-buffer-create-other-window
1051 (list (list basevar
'custom-variable
))
1052 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1053 (unless (eq symbol basevar
)
1054 (message "`%s' is an alias for `%s'" symbol basevar
))))
1056 (defvar customize-changed-options-previous-release
"20.2"
1057 "Version for `customize-changed-options' to refer back to by default.")
1060 (defun customize-changed-options (since-version)
1061 "Customize all user option variables changed in Emacs itself.
1062 This includes new user option variables and faces, and new
1063 customization groups, as well as older options and faces whose default
1064 values have changed since the previous major Emacs release.
1066 With argument SINCE-VERSION (a string), customize all user option
1067 variables that were added (or their meanings were changed) since that
1070 (interactive "sCustomize options changed, since version (default all versions): ")
1071 (if (equal since-version
"")
1072 (setq since-version nil
)
1073 (unless (condition-case nil
1074 (numberp (read since-version
))
1076 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1077 (unless since-version
1078 (setq since-version customize-changed-options-previous-release
))
1080 ;; Load the information for versions since since-version. We use
1081 ;; custom-load-symbol for this.
1082 (put 'custom-versions-load-alist
'custom-loads nil
)
1083 (dolist (elt custom-versions-load-alist
)
1084 (if (customize-version-lessp since-version
(car elt
))
1085 (dolist (load (cdr elt
))
1086 (custom-add-load 'custom-versions-load-alist load
))))
1087 (custom-load-symbol 'custom-versions-load-alist
)
1088 (put 'custom-versions-load-alist
'custom-loads nil
)
1093 (let ((version (get symbol
'custom-version
)))
1095 (when (customize-version-lessp since-version version
)
1096 (if (or (get symbol
'custom-group
)
1097 (get symbol
'group-documentation
))
1098 (push (list symbol
'custom-group
) found
))
1099 (if (custom-variable-p symbol
)
1100 (push (list symbol
'custom-variable
) found
))
1101 (if (custom-facep symbol
)
1102 (push (list symbol
'custom-face
) found
)))))))
1104 (custom-buffer-create (custom-sort-items found t
'first
)
1105 "*Customize Changed Options*")
1106 (error "No user option defaults have been changed since Emacs %s"
1109 (defun customize-version-lessp (version1 version2
)
1110 ;; Why are the versions strings, and given that they are, why aren't
1111 ;; they converted to numbers and compared as such here? -- fx
1113 ;; In case someone made a mistake and left out the quotes
1114 ;; in the :version value.
1115 (if (numberp version2
)
1116 (setq version2
(prin1-to-string version2
)))
1117 (let (major1 major2 minor1 minor2
)
1118 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1119 (setq major1
(read (or (match-string 1 version1
)
1121 (setq minor1
(read (or (match-string 3 version1
)
1123 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1124 (setq major2
(read (or (match-string 1 version2
)
1126 (setq minor2
(read (or (match-string 3 version2
)
1128 (or (< major1 major2
)
1129 (and (= major1 major2
)
1130 (< minor1 minor2
)))))
1133 (defun customize-face (&optional face
)
1134 "Customize FACE, which should be a face name or nil.
1135 If FACE is nil, customize all faces. If FACE is actually a
1136 face-alias, customize the face it is aliased to.
1138 Interactively, when point is on text which has a face specified,
1139 suggest to customize that face, if it's customizable."
1141 (list (read-face-name "Customize face" "all faces" t
)))
1142 (if (member face
'(nil ""))
1143 (setq face
(face-list)))
1144 (if (and (listp face
) (null (cdr face
)))
1145 (setq face
(car face
)))
1147 (custom-buffer-create (custom-sort-items
1149 (list s
'custom-face
))
1152 "*Customize Faces*")
1153 ;; If FACE is actually an alias, customize the face it is aliased to.
1154 (if (get face
'face-alias
)
1155 (setq face
(get face
'face-alias
)))
1156 (unless (facep face
)
1157 (error "Invalid face %S" face
))
1158 (custom-buffer-create (list (list face
'custom-face
))
1159 (format "*Customize Face: %s*"
1160 (custom-unlispify-tag-name face
)))))
1163 (defun customize-face-other-window (&optional face
)
1164 "Show customization buffer for face FACE in other window.
1165 If FACE is actually a face-alias, customize the face it is aliased to.
1167 Interactively, when point is on text which has a face specified,
1168 suggest to customize that face, if it's customizable."
1170 (list (read-face-name "Customize face" "all faces" t
)))
1171 (if (member face
'(nil ""))
1172 (setq face
(face-list)))
1173 (if (and (listp face
) (null (cdr face
)))
1174 (setq face
(car face
)))
1176 (custom-buffer-create-other-window
1179 (list s
'custom-face
))
1182 "*Customize Faces*")
1183 (if (get face
'face-alias
)
1184 (setq face
(get face
'face-alias
)))
1185 (unless (facep face
)
1186 (error "Invalid face %S" face
))
1187 (custom-buffer-create-other-window
1188 (list (list face
'custom-face
))
1189 (format "*Customize Face: %s*"
1190 (custom-unlispify-tag-name face
)))))
1193 (defun customize-customized ()
1194 "Customize all user options set since the last save in this session."
1197 (mapatoms (lambda (symbol)
1198 (and (or (get symbol
'customized-face
)
1199 (get symbol
'customized-face-comment
))
1200 (custom-facep symbol
)
1201 (push (list symbol
'custom-face
) found
))
1202 (and (or (get symbol
'customized-value
)
1203 (get symbol
'customized-variable-comment
))
1205 (push (list symbol
'custom-variable
) found
))))
1207 (error "No customized user options")
1208 (custom-buffer-create (custom-sort-items found t nil
)
1209 "*Customize Customized*"))))
1212 (defun customize-rogue ()
1213 "Customize all user variable modified outside customize."
1216 (mapatoms (lambda (symbol)
1217 (let ((cval (or (get symbol
'customized-value
)
1218 (get symbol
'saved-value
)
1219 (get symbol
'standard-value
))))
1220 (when (and cval
;Declared with defcustom.
1221 (default-boundp symbol
) ;Has a value.
1222 (not (equal (eval (car cval
))
1223 ;; Which does not match customize.
1224 (default-value symbol
))))
1225 (push (list symbol
'custom-variable
) found
)))))
1227 (error "No rogue user options")
1228 (custom-buffer-create (custom-sort-items found t nil
)
1229 "*Customize Rogue*"))))
1231 (defun customize-saved ()
1232 "Customize all already saved user options."
1235 (mapatoms (lambda (symbol)
1236 (and (or (get symbol
'saved-face
)
1237 (get symbol
'saved-face-comment
))
1238 (custom-facep symbol
)
1239 (push (list symbol
'custom-face
) found
))
1240 (and (or (get symbol
'saved-value
)
1241 (get symbol
'saved-variable-comment
))
1243 (push (list symbol
'custom-variable
) found
))))
1245 (error "No saved user options")
1246 (custom-buffer-create (custom-sort-items found t nil
)
1247 "*Customize Saved*"))))
1250 (defun customize-apropos (regexp &optional all
)
1251 "Customize all user options matching REGEXP.
1252 If ALL is `options', include only options.
1253 If ALL is `faces', include only faces.
1254 If ALL is `groups', include only groups.
1255 If ALL is t (interactively, with prefix arg), include options which are not
1256 user-settable, as well as faces and groups."
1257 (interactive "sCustomize regexp: \nP")
1259 (mapatoms (lambda (symbol)
1260 (when (string-match regexp
(symbol-name symbol
))
1261 (when (and (not (memq all
'(faces options
)))
1262 (get symbol
'custom-group
))
1263 (push (list symbol
'custom-group
) found
))
1264 (when (and (not (memq all
'(options groups
)))
1265 (custom-facep symbol
))
1266 (push (list symbol
'custom-face
) found
))
1267 (when (and (not (memq all
'(groups faces
)))
1269 (or (get symbol
'saved-value
)
1270 (custom-variable-p symbol
)
1271 (if (memq all
'(nil options
))
1272 (user-variable-p symbol
)
1273 (get symbol
'variable-documentation
))))
1274 (push (list symbol
'custom-variable
) found
)))))
1276 (error "No matches")
1277 (custom-buffer-create (custom-sort-items found t
1278 custom-buffer-order-groups
)
1279 "*Customize Apropos*"))))
1282 (defun customize-apropos-options (regexp &optional arg
)
1283 "Customize all user options matching REGEXP.
1284 With prefix arg, include options which are not user-settable."
1285 (interactive "sCustomize regexp: \nP")
1286 (customize-apropos regexp
(or arg
'options
)))
1289 (defun customize-apropos-faces (regexp)
1290 "Customize all user faces matching REGEXP."
1291 (interactive "sCustomize regexp: \n")
1292 (customize-apropos regexp
'faces
))
1295 (defun customize-apropos-groups (regexp)
1296 "Customize all user groups matching REGEXP."
1297 (interactive "sCustomize regexp: \n")
1298 (customize-apropos regexp
'groups
))
1302 (defcustom custom-buffer-style
'links
1303 "Control the presentation style for customization buffers.
1304 The value should be a symbol, one of:
1306 brackets: groups nest within each other with big horizontal brackets.
1307 links: groups have links to subgroups."
1308 :type
'(radio (const brackets
)
1310 :group
'custom-buffer
)
1312 (defcustom custom-buffer-done-kill nil
1313 "*Non-nil means exiting a Custom buffer should kill it."
1316 :group
'custom-buffer
)
1318 (defcustom custom-buffer-indent
3
1319 "Number of spaces to indent nested groups."
1321 :group
'custom-buffer
)
1323 (defun custom-get-fresh-buffer (name)
1324 "Get a fresh new buffer with name NAME.
1325 If the buffer already exist, clean it up to be like new.
1326 Beware: it's not quite like new. Good enough for custom, but maybe
1328 ;; To be more complete, we should also kill all permanent-local variables,
1329 ;; but it's not needed for custom.
1330 (let ((buf (get-buffer name
)))
1331 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1332 ;; This will check if the file is not saved.
1336 (get-buffer-create name
)
1337 (with-current-buffer buf
1338 (kill-all-local-variables)
1339 (run-hooks 'kill-buffer-hook
)
1340 ;; Delete overlays before erasing the buffer so the overlay hooks
1341 ;; don't get run spuriously when we erase the buffer.
1342 (let ((ols (overlay-lists)))
1343 (dolist (ol (nconc (car ols
) (cdr ols
)))
1344 (delete-overlay ol
)))
1349 (defun custom-buffer-create (options &optional name description
)
1350 "Create a buffer containing OPTIONS.
1351 Optional NAME is the name of the buffer.
1352 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1353 SYMBOL is a customization option, and WIDGET is a widget for editing
1355 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1356 (custom-buffer-create-internal options description
))
1359 (defun custom-buffer-create-other-window (options &optional name description
)
1360 "Create a buffer containing OPTIONS, and display it in another window.
1361 The result includes selecting that window.
1362 Optional NAME is the name of the buffer.
1363 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1364 SYMBOL is a customization option, and WIDGET is a widget for editing
1366 (unless name
(setq name
"*Customization*"))
1367 (let ((pop-up-windows t
)
1368 (same-window-buffer-names nil
)
1369 (same-window-regexps nil
))
1370 (pop-to-buffer (custom-get-fresh-buffer name
))
1371 (custom-buffer-create-internal options description
)))
1373 (defcustom custom-reset-button-menu nil
1374 "If non-nil, only show a single reset button in customize buffers.
1375 This button will have a menu with all three reset operations."
1377 :group
'custom-buffer
)
1379 (defcustom custom-buffer-verbose-help t
1380 "If non-nil, include explanatory text in the customization buffer."
1382 :group
'custom-buffer
)
1384 (defun Custom-buffer-done (&rest ignore
)
1385 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1387 (quit-window custom-buffer-done-kill
))
1389 (defvar custom-button nil
1390 "Face used for buttons in customization buffers.")
1392 (defvar custom-button-pressed nil
1393 "Face used for pressed buttons in customization buffers.")
1395 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1396 '(("unspecified" . unspecified
))))
1397 "If non-nil, indicate active buttons in a `raised-button' style.
1398 Otherwise use brackets."
1401 :group
'custom-buffer
1402 :set
(lambda (variable value
)
1403 (custom-set-default variable value
)
1405 (if value
'custom-button
'custom-button-unraised
))
1406 (setq custom-button-pressed
1408 'custom-button-pressed
1409 'custom-button-pressed-unraised
))))
1411 (defun custom-buffer-create-internal (options &optional description
)
1413 (if custom-buffer-verbose-help
1415 (widget-insert "This is a customization buffer")
1417 (widget-insert description
))
1418 (widget-insert (format ".
1419 %s show active fields; type RET or click mouse-1
1420 on an active field to invoke its action. Editing an option value
1421 changes only the text in the buffer. Invoke the State button to set or
1422 save the option value. Saving an option normally edits your init file.
1424 (if custom-raised-buttons
1426 "Square brackets")))
1427 (widget-create 'info-link
1429 "(emacs)Saving Customizations")
1431 " for information on how to save in a different file.
1433 (widget-create 'info-link
1435 :help-echo
"Read the online help."
1436 "(emacs)Easy Customization")
1437 (widget-insert " for general information.\n\n")
1438 (widget-insert "Operate on everything in this buffer:\n "))
1439 (widget-insert " "))
1440 (widget-create 'push-button
1441 :tag
"Set for Current Session"
1443 Make your editing in this buffer take effect for this session."
1444 :action
(lambda (widget &optional event
)
1447 (widget-create 'push-button
1448 :tag
"Save for Future Sessions"
1450 Make your editing in this buffer take effect for future Emacs sessions.
1451 This updates your Emacs initialization file or creates a new one."
1452 :action
(lambda (widget &optional event
)
1454 (if custom-reset-button-menu
1457 (widget-create 'push-button
1459 :help-echo
"Show a menu with reset operations."
1460 :mouse-down-action
(lambda (&rest junk
) t
)
1461 :action
(lambda (widget &optional event
)
1462 (custom-reset event
))))
1463 (widget-insert "\n ")
1464 (widget-create 'push-button
1467 Reset all edited text in this buffer to reflect current values."
1468 :action
'Custom-reset-current
)
1470 (widget-create 'push-button
1471 :tag
"Reset to Saved"
1473 Reset all values in this buffer to their saved settings."
1474 :action
'Custom-reset-saved
)
1476 (widget-create 'push-button
1477 :tag
"Erase Customization"
1479 Un-customize all values in this buffer. They get their standard settings."
1480 :action
'Custom-reset-standard
))
1481 (if (not custom-buffer-verbose-help
)
1484 (widget-create 'info-link
1486 :help-echo
"Read the online help."
1487 "(emacs)Easy Customization")))
1489 (widget-create 'push-button
1492 (lambda (&rest ignore
)
1493 (if custom-buffer-done-kill
1495 "Bury this buffer"))
1496 :action
#'Custom-buffer-done
)
1497 (widget-insert "\n\n")
1498 (message "Creating customization items...")
1499 (buffer-disable-undo)
1500 (setq custom-options
1501 (if (= (length options
) 1)
1502 (mapcar (lambda (entry)
1503 (widget-create (nth 1 entry
)
1504 :documentation-shown t
1505 :custom-state
'unknown
1506 :tag
(custom-unlispify-tag-name
1508 :value
(nth 0 entry
)))
1511 (length (length options
)))
1512 (mapcar (lambda (entry)
1514 (message "Creating customization items ...%2d%%"
1515 (/ (* 100.0 count
) length
))
1516 (widget-create (nth 1 entry
)
1517 :tag
(custom-unlispify-tag-name
1519 :value
(nth 0 entry
))
1520 (setq count
(1+ count
))
1521 (unless (eq (preceding-char) ?
\n)
1522 (widget-insert "\n"))
1523 (widget-insert "\n")))
1525 (unless (eq (preceding-char) ?
\n)
1526 (widget-insert "\n"))
1527 (message "Creating customization items ...done")
1528 (message "Resetting customization items...")
1529 (unless (eq custom-buffer-style
'tree
)
1530 (mapc 'custom-magic-reset custom-options
))
1531 (message "Resetting customization items...done")
1532 (message "Creating customization setup...")
1534 (buffer-enable-undo)
1535 (goto-char (point-min))
1536 (message "Creating customization setup...done"))
1538 ;;; The Tree Browser.
1541 (defun customize-browse (&optional group
)
1542 "Create a tree browser for the customize hierarchy."
1545 (setq group
'emacs
))
1546 (let ((name "*Customize Browser*"))
1547 (pop-to-buffer (custom-get-fresh-buffer name
)))
1550 Square brackets show active fields; type RET or click mouse-1
1551 on an active field to invoke its action.
1552 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1553 (if custom-browse-only-groups
1555 Invoke the [Group] button below to edit that item in another window.\n\n")
1556 (widget-insert "Invoke the ")
1557 (widget-create 'item
1560 :tag-glyph
"folder")
1561 (widget-insert ", ")
1562 (widget-create 'item
1566 (widget-insert ", and ")
1567 (widget-create 'item
1570 :tag-glyph
"option")
1571 (widget-insert " buttons below to edit that
1572 item in another window.\n\n"))
1573 (let ((custom-buffer-style 'tree
))
1574 (widget-create 'custom-group
1576 :custom-state
'unknown
1577 :tag
(custom-unlispify-tag-name group
)
1580 (goto-char (point-min)))
1582 (define-widget 'custom-browse-visibility
'item
1583 "Control visibility of items in the customize tree browser."
1585 :action
'custom-browse-visibility-action
)
1587 (defun custom-browse-visibility-action (widget &rest ignore
)
1588 (let ((custom-buffer-style 'tree
))
1589 (custom-toggle-parent widget
)))
1591 (define-widget 'custom-browse-group-tag
'push-button
1592 "Show parent in other window when activated."
1595 :action
'custom-browse-group-tag-action
)
1597 (defun custom-browse-group-tag-action (widget &rest ignore
)
1598 (let ((parent (widget-get widget
:parent
)))
1599 (customize-group-other-window (widget-value parent
))))
1601 (define-widget 'custom-browse-variable-tag
'push-button
1602 "Show parent in other window when activated."
1605 :action
'custom-browse-variable-tag-action
)
1607 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1608 (let ((parent (widget-get widget
:parent
)))
1609 (customize-variable-other-window (widget-value parent
))))
1611 (define-widget 'custom-browse-face-tag
'push-button
1612 "Show parent in other window when activated."
1615 :action
'custom-browse-face-tag-action
)
1617 (defun custom-browse-face-tag-action (widget &rest ignore
)
1618 (let ((parent (widget-get widget
:parent
)))
1619 (customize-face-other-window (widget-value parent
))))
1621 (defconst custom-browse-alist
'((" " "space")
1627 (defun custom-browse-insert-prefix (prefix)
1628 "Insert PREFIX. On XEmacs convert it to line graphics."
1629 ;; Fixme: do graphics.
1630 (if nil
; (string-match "XEmacs" emacs-version)
1633 (while (not (string-equal prefix
""))
1634 (let ((entry (substring prefix
0 3)))
1635 (setq prefix
(substring prefix
3))
1636 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1637 (name (nth 1 (assoc entry custom-browse-alist
))))
1638 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1639 (overlay-put overlay
'start-open t
)
1640 (overlay-put overlay
'end-open t
)))))
1643 ;;; Modification of Basic Widgets.
1645 ;; We add extra properties to the basic widgets needed here. This is
1646 ;; fine, as long as we are careful to stay within out own namespace.
1648 ;; We want simple widgets to be displayed by default, but complex
1649 ;; widgets to be hidden.
1651 (widget-put (get 'item
'widget-type
) :custom-show t
)
1652 (widget-put (get 'editable-field
'widget-type
)
1653 :custom-show
(lambda (widget value
)
1654 (let ((pp (pp-to-string value
)))
1655 (cond ((string-match "\n" pp
)
1660 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1662 ;;; The `custom-manual' Widget.
1664 (define-widget 'custom-manual
'info-link
1665 "Link to the manual entry for this customization option."
1666 :help-echo
"Read the manual entry for this option."
1669 ;;; The `custom-magic' Widget.
1671 (defgroup custom-magic-faces nil
1672 "Faces used by the magic button."
1673 :group
'custom-faces
1674 :group
'custom-buffer
)
1676 (defface custom-invalid
'((((class color
))
1677 (:foreground
"yellow1" :background
"red1"))
1679 (:weight bold
:slant italic
:underline t
)))
1680 "Face used when the customize item is invalid."
1681 :group
'custom-magic-faces
)
1682 ;; backward-compatibility alias
1683 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1685 (defface custom-rogue
'((((class color
))
1686 (:foreground
"pink" :background
"black"))
1689 "Face used when the customize item is not defined for customization."
1690 :group
'custom-magic-faces
)
1691 ;; backward-compatibility alias
1692 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1694 (defface custom-modified
'((((min-colors 88) (class color
))
1695 (:foreground
"white" :background
"blue1"))
1697 (:foreground
"white" :background
"blue"))
1699 (:slant italic
:bold
)))
1700 "Face used when the customize item has been modified."
1701 :group
'custom-magic-faces
)
1702 ;; backward-compatibility alias
1703 (put 'custom-modified-face
'face-alias
'custom-modified
)
1705 (defface custom-set
'((((min-colors 88) (class color
))
1706 (:foreground
"blue1" :background
"white"))
1708 (:foreground
"blue" :background
"white"))
1711 "Face used when the customize item has been set."
1712 :group
'custom-magic-faces
)
1713 ;; backward-compatibility alias
1714 (put 'custom-set-face
'face-alias
'custom-set
)
1716 (defface custom-changed
'((((min-colors 88) (class color
))
1717 (:foreground
"white" :background
"blue1"))
1719 (:foreground
"white" :background
"blue"))
1722 "Face used when the customize item has been changed."
1723 :group
'custom-magic-faces
)
1724 ;; backward-compatibility alias
1725 (put 'custom-changed-face
'face-alias
'custom-changed
)
1727 (defface custom-saved
'((t (:underline t
)))
1728 "Face used when the customize item has been saved."
1729 :group
'custom-magic-faces
)
1730 ;; backward-compatibility alias
1731 (put 'custom-saved-face
'face-alias
'custom-saved
)
1733 (defconst custom-magic-alist
1734 '((nil "#" underline
"\
1735 UNINITIALIZED, you should not see this.")
1736 (unknown "?" italic
"\
1737 UNKNOWN, you should not see this.")
1738 (hidden "-" default
"\
1739 HIDDEN, invoke \"Show\" in the previous line to show." "\
1740 group now hidden, invoke \"Show\", above, to show contents.")
1741 (invalid "x" custom-invalid
"\
1742 INVALID, the displayed value cannot be set.")
1743 (modified "*" custom-modified
"\
1744 EDITED, shown value does not take effect until you set or save it." "\
1745 something in this group has been edited but not set.")
1746 (set "+" custom-set
"\
1747 SET for current session only." "\
1748 something in this group has been set but not saved.")
1749 (changed ":" custom-changed
"\
1750 CHANGED outside Customize; operating on it here may be unreliable." "\
1751 something in this group has been changed outside customize.")
1752 (saved "!" custom-saved
"\
1754 something in this group has been set and saved.")
1755 (rogue "@" custom-rogue
"\
1756 NO CUSTOMIZATION DATA; you should not see this." "\
1757 something in this group is not prepared for customization.")
1758 (standard " " nil
"\
1760 visible group members are all at standard settings."))
1761 "Alist of customize option states.
1762 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1764 STATE is one of the following symbols:
1767 For internal use, should never occur.
1769 For internal use, should never occur.
1771 This item is not being displayed.
1773 This item is modified, but has an invalid form.
1775 This item is modified, and has a valid form.
1777 This item has been set but not saved.
1779 The current value of this item has been changed outside Customize.
1781 This item is marked for saving.
1783 This item has no customization information.
1785 This item is unchanged from the standard setting.
1787 MAGIC is a string used to present that state.
1789 FACE is a face used to present the state.
1791 ITEM-DESC is a string describing the state for options.
1793 GROUP-DESC is a string describing the state for groups. If this is
1794 left out, ITEM-DESC will be used.
1796 The string %c in either description will be replaced with the
1797 category of the item. These are `group'. `option', and `face'.
1799 The list should be sorted most significant first.")
1801 (defcustom custom-magic-show
'long
1802 "If non-nil, show textual description of the state.
1803 If `long', show a full-line description, not just one word."
1804 :type
'(choice (const :tag
"no" nil
)
1806 (other :tag
"short" short
))
1807 :group
'custom-buffer
)
1809 (defcustom custom-magic-show-hidden
'(option face
)
1810 "Control whether the State button is shown for hidden items.
1811 The value should be a list with the custom categories where the State
1812 button should be visible. Possible categories are `group', `option',
1814 :type
'(set (const group
) (const option
) (const face
))
1815 :group
'custom-buffer
)
1817 (defcustom custom-magic-show-button nil
1818 "Show a \"magic\" button indicating the state of each customization option."
1820 :group
'custom-buffer
)
1822 (define-widget 'custom-magic
'default
1823 "Show and manipulate state for a customization option."
1825 :action
'widget-parent-action
1828 :value-create
'custom-magic-value-create
1829 :value-delete
'widget-children-value-delete
)
1831 (defun widget-magic-mouse-down-action (widget &optional event
)
1832 ;; Non-nil unless hidden.
1833 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1837 (defun custom-magic-value-create (widget)
1838 "Create compact status report for WIDGET."
1839 (let* ((parent (widget-get widget
:parent
))
1840 (state (widget-get parent
:custom-state
))
1841 (hidden (eq state
'hidden
))
1842 (entry (assq state custom-magic-alist
))
1843 (magic (nth 1 entry
))
1844 (face (nth 2 entry
))
1845 (category (widget-get parent
:custom-category
))
1846 (text (or (and (eq category
'group
)
1849 (form (widget-get parent
:custom-form
))
1851 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1852 (setq text
(concat (match-string 1 text
)
1853 (symbol-name category
)
1854 (match-string 2 text
))))
1855 (when (and custom-magic-show
1857 (memq category custom-magic-show-hidden
)))
1859 (when (and (eq category
'group
)
1860 (not (and (eq custom-buffer-style
'links
)
1861 (> (widget-get parent
:custom-level
) 1))))
1862 (insert-char ?\
(* custom-buffer-indent
1863 (widget-get parent
:custom-level
))))
1864 (push (widget-create-child-and-convert
1866 :help-echo
"Change the state of this item."
1867 :format
(if hidden
"%t" "%[%t%]")
1868 :button-prefix
'widget-push-button-prefix
1869 :button-suffix
'widget-push-button-suffix
1870 :mouse-down-action
'widget-magic-mouse-down-action
1874 (let ((start (point)))
1875 (if (eq custom-magic-show
'long
)
1877 (insert (symbol-name state
)))
1878 (cond ((eq form
'lisp
)
1880 ((eq form
'mismatch
)
1881 (insert " (mismatch)")))
1882 (put-text-property start
(point) 'face
'custom-state
))
1884 (when (and (eq category
'group
)
1885 (not (and (eq custom-buffer-style
'links
)
1886 (> (widget-get parent
:custom-level
) 1))))
1887 (insert-char ?\
(* custom-buffer-indent
1888 (widget-get parent
:custom-level
))))
1889 (when custom-magic-show-button
1890 (when custom-magic-show
1891 (let ((indent (widget-get parent
:indent
)))
1893 (insert-char ? indent
))))
1894 (push (widget-create-child-and-convert
1896 :mouse-down-action
'widget-magic-mouse-down-action
1900 :help-echo
"Change the state."
1901 :format
(if hidden
"%t" "%[%t%]")
1902 :tag
(if (memq form
'(lisp mismatch
))
1903 (concat "(" magic
")")
1904 (concat "[" magic
"]")))
1907 (widget-put widget
:children children
)))
1909 (defun custom-magic-reset (widget)
1910 "Redraw the :custom-magic property of WIDGET."
1911 (let ((magic (widget-get widget
:custom-magic
)))
1912 (widget-value-set magic
(widget-value magic
))))
1914 ;;; The `custom' Widget.
1916 (defface custom-button
1917 '((((type x w32 mac
) (class color
)) ; Like default modeline
1918 (:box
(:line-width
2 :style released-button
)
1919 :background
"lightgrey" :foreground
"black"))
1922 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1924 :group
'custom-faces
)
1925 ;; backward-compatibility alias
1926 (put 'custom-button-face
'face-alias
'custom-button
)
1928 (defface custom-button-unraised
1930 (class color
) (background light
)) :foreground
"blue1" :underline t
)
1931 (((class color
) (background light
)) :foreground
"blue" :underline t
)
1933 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
1934 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
1936 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1938 :group
'custom-faces
)
1941 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
1943 (defface custom-button-pressed
1944 '((((type x w32 mac
) (class color
))
1945 (:box
(:line-width
2 :style pressed-button
)
1946 :background
"lightgrey" :foreground
"black"))
1948 (:inverse-video t
)))
1949 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1951 :group
'custom-faces
)
1952 ;; backward-compatibility alias
1953 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
1955 (defface custom-button-pressed-unraised
1956 '((default :inherit custom-button-unraised
)
1957 (((class color
) (background light
)) :foreground
"magenta4")
1958 (((class color
) (background dark
)) :foreground
"violet"))
1959 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1961 :group
'custom-faces
)
1963 (setq custom-button-pressed
1964 (if custom-raised-buttons
1965 'custom-button-pressed
1966 'custom-button-pressed-unraised
))
1968 (defface custom-documentation nil
1969 "Face used for documentation strings in customization buffers."
1970 :group
'custom-faces
)
1971 ;; backward-compatibility alias
1972 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
1974 (defface custom-state
'((((class color
)
1976 (:foreground
"lime green"))
1979 (:foreground
"dark green"))
1981 "Face used for State descriptions in the customize buffer."
1982 :group
'custom-faces
)
1983 ;; backward-compatibility alias
1984 (put 'custom-state-face
'face-alias
'custom-state
)
1986 (define-widget 'custom
'default
1987 "Customize a user option."
1989 :convert-widget
'custom-convert-widget
1990 :notify
'custom-notify
1993 :custom-state
'hidden
1994 :documentation-property
'widget-subclass-responsibility
1995 :value-create
'widget-subclass-responsibility
1996 :value-delete
'widget-children-value-delete
1997 :value-get
'widget-value-value-get
1998 :validate
'widget-children-validate
1999 :match
(lambda (widget value
) (symbolp value
)))
2001 (defun custom-convert-widget (widget)
2002 "Initialize :value and :tag from :args in WIDGET."
2003 (let ((args (widget-get widget
:args
)))
2005 (widget-put widget
:value
(widget-apply widget
2006 :value-to-internal
(car args
)))
2007 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2008 (widget-put widget
:args nil
)))
2011 (defun custom-notify (widget &rest args
)
2012 "Keep track of changes."
2013 (let ((state (widget-get widget
:custom-state
)))
2014 (unless (eq state
'modified
)
2015 (unless (memq state
'(nil unknown hidden
))
2016 (widget-put widget
:custom-state
'modified
))
2017 (custom-magic-reset widget
)
2018 (apply 'widget-default-notify widget args
))))
2020 (defun custom-redraw (widget)
2021 "Redraw WIDGET with current settings."
2022 (let ((line (count-lines (point-min) (point)))
2023 (column (current-column))
2025 (from (marker-position (widget-get widget
:from
)))
2026 (to (marker-position (widget-get widget
:to
))))
2028 (widget-value-set widget
(widget-value widget
))
2029 (custom-redraw-magic widget
))
2030 (when (and (>= pos from
) (<= pos to
))
2035 (goto-line (1+ line
)))
2036 (move-to-column column
))
2039 (defun custom-redraw-magic (widget)
2040 "Redraw WIDGET state with current settings."
2042 (let ((magic (widget-get widget
:custom-magic
)))
2044 (widget-value-set magic
(widget-value magic
))
2045 (when (setq widget
(widget-get widget
:group
))
2046 (custom-group-state-update widget
)))
2048 (setq widget nil
)))))
2051 (defun custom-show (widget value
)
2052 "Non-nil if WIDGET should be shown with VALUE by default."
2053 (let ((show (widget-get widget
:custom-show
)))
2059 (funcall show widget value
)))))
2061 (defun custom-load-widget (widget)
2062 "Load all dependencies for WIDGET."
2063 (custom-load-symbol (widget-value widget
)))
2065 (defun custom-unloaded-symbol-p (symbol)
2066 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2068 (loads (get symbol
'custom-loads
))
2071 (setq load
(car loads
)
2073 (cond ((symbolp load
)
2074 (unless (featurep load
)
2076 ((assoc load load-history
))
2077 ((assoc (locate-library load
) load-history
)
2083 (defun custom-unloaded-widget-p (widget)
2084 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2085 (custom-unloaded-symbol-p (widget-value widget
)))
2087 (defun custom-toggle-hide (widget)
2088 "Toggle visibility of WIDGET."
2089 (custom-load-widget widget
)
2090 (let ((state (widget-get widget
:custom-state
)))
2091 (cond ((memq state
'(invalid modified
))
2092 (error "There are unset changes"))
2094 (widget-put widget
:custom-state
'unknown
))
2096 (widget-put widget
:documentation-shown nil
)
2097 (widget-put widget
:custom-state
'hidden
)))
2098 (custom-redraw widget
)
2101 (defun custom-toggle-parent (widget &rest ignore
)
2102 "Toggle visibility of parent of WIDGET."
2103 (custom-toggle-hide (widget-get widget
:parent
)))
2105 (defun custom-add-see-also (widget &optional prefix
)
2106 "Add `See also ...' to WIDGET if there are any links.
2107 Insert PREFIX first if non-nil."
2108 (let* ((symbol (widget-get widget
:value
))
2109 (links (get symbol
'custom-links
))
2110 (many (> (length links
) 2))
2111 (buttons (widget-get widget
:buttons
))
2112 (indent (widget-get widget
:indent
)))
2115 (insert-char ?\ indent
))
2118 (insert "See also ")
2120 (push (widget-create-child-and-convert widget
(car links
))
2122 (setq links
(cdr links
))
2131 (widget-put widget
:buttons buttons
))))
2133 (defun custom-add-parent-links (widget &optional initial-string
)
2134 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2135 The value is non-nil if any parents were found.
2136 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2137 (let ((name (widget-value widget
))
2138 (type (widget-type widget
))
2139 (buttons (widget-get widget
:buttons
))
2142 (insert (or initial-string
"Parent groups:"))
2143 (mapatoms (lambda (symbol)
2144 (when (member (list name type
) (get symbol
'custom-group
))
2146 (push (widget-create-child-and-convert
2147 widget
'custom-group-link
2148 :tag
(custom-unlispify-tag-name symbol
)
2151 (setq parents
(cons symbol parents
)))))
2152 (and (null (get name
'custom-links
)) ;No links of its own.
2153 (= (length parents
) 1) ;A single parent.
2154 (let* ((links (get (car parents
) 'custom-links
))
2155 (many (> (length links
) 2)))
2157 (insert "\nParent documentation: ")
2159 (push (widget-create-child-and-convert widget
(car links
))
2161 (setq links
(cdr links
))
2172 (delete-region start
(point)))
2173 (widget-put widget
:buttons buttons
)
2176 ;;; The `custom-comment' Widget.
2178 ;; like the editable field
2179 (defface custom-comment
'((((class grayscale color
)
2181 (:background
"gray85"))
2182 (((class grayscale color
)
2184 (:background
"dim gray"))
2187 "Face used for comments on variables or faces"
2189 :group
'custom-faces
)
2190 ;; backward-compatibility alias
2191 (put 'custom-comment-face
'face-alias
'custom-comment
)
2193 ;; like font-lock-comment-face
2194 (defface custom-comment-tag
2195 '((((class color
) (background dark
)) (:foreground
"gray80"))
2196 (((class color
) (background light
)) (:foreground
"blue4"))
2197 (((class grayscale
) (background light
))
2198 (:foreground
"DimGray" :weight bold
:slant italic
))
2199 (((class grayscale
) (background dark
))
2200 (:foreground
"LightGray" :weight bold
:slant italic
))
2202 "Face used for variables or faces comment tags"
2203 :group
'custom-faces
)
2204 ;; backward-compatibility alias
2205 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2207 (define-widget 'custom-comment
'string
2210 :help-echo
"Edit a comment here."
2211 :sample-face
'custom-comment-tag-face
2212 :value-face
'custom-comment-face
2214 :create
'custom-comment-create
)
2216 (defun custom-comment-create (widget)
2217 (let* ((null-comment (equal "" (widget-value widget
))))
2218 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2220 (widget-default-create widget
)
2221 ;; `widget-default-delete' expects markers in these slots --
2222 ;; maybe it shouldn't.
2223 (widget-put widget
:from
(point-marker))
2224 (widget-put widget
:to
(point-marker)))))
2226 (defun custom-comment-hide (widget)
2227 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2229 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2230 ;; the global custom one
2231 (defun custom-comment-show (widget)
2232 (widget-put widget
:comment-shown t
)
2233 (custom-redraw widget
)
2236 (defun custom-comment-invisible-p (widget)
2237 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2239 (not (widget-get widget
:comment-shown
)))))
2241 ;;; The `custom-variable' Widget.
2243 ;; When this was underlined blue, users confused it with a
2244 ;; Mosaic-style hyperlink...
2245 (defface custom-variable-tag
2248 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2249 (((min-colors 88) (class color
)
2251 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2254 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2256 "Face used for unpushable variable tags."
2257 :group
'custom-faces
)
2258 ;; backward-compatibility alias
2259 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2261 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2262 "Face used for pushable variable tags."
2263 :group
'custom-faces
)
2264 ;; backward-compatibility alias
2265 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2267 (defcustom custom-variable-default-form
'edit
2268 "Default form of displaying variable values."
2269 :type
'(choice (const edit
)
2271 :group
'custom-buffer
2274 (defun custom-variable-documentation (variable)
2275 "Return documentation of VARIABLE for use in Custom buffer.
2276 Normally just return the docstring. But if VARIABLE automatically
2277 becomes buffer local when set, append a message to that effect."
2278 (if (and (local-variable-if-set-p variable
)
2279 (or (not (local-variable-p variable
))
2281 (local-variable-if-set-p variable
))))
2282 (concat (documentation-property variable
'variable-documentation
)
2284 This variable automatically becomes buffer-local when set outside Custom.
2285 However, setting it through Custom sets the default value.")
2286 (documentation-property variable
'variable-documentation
)))
2288 (define-widget 'custom-variable
'custom
2289 "Customize variable."
2291 :help-echo
"Set or reset this variable."
2292 :documentation-property
#'custom-variable-documentation
2293 :custom-category
'option
2295 :custom-menu
'custom-variable-menu-create
2296 :custom-form nil
; defaults to value of `custom-variable-default-form'
2297 :value-create
'custom-variable-value-create
2298 :action
'custom-variable-action
2299 :custom-set
'custom-variable-set
2300 :custom-save
'custom-variable-save
2301 :custom-reset-current
'custom-redraw
2302 :custom-reset-saved
'custom-variable-reset-saved
2303 :custom-reset-standard
'custom-variable-reset-standard
2304 :custom-standard-value
'custom-variable-standard-value
)
2306 (defun custom-variable-type (symbol)
2307 "Return a widget suitable for editing the value of SYMBOL.
2308 If SYMBOL has a `custom-type' property, use that.
2309 Otherwise, look up symbol in `custom-guess-type-alist'."
2310 (let* ((type (or (get symbol
'custom-type
)
2311 (and (not (get symbol
'standard-value
))
2312 (custom-guess-type symbol
))
2314 (options (get symbol
'custom-options
))
2315 (tmp (if (listp type
)
2316 (copy-sequence type
)
2319 (widget-put tmp
:options options
))
2322 (defun custom-variable-value-create (widget)
2323 "Here is where you edit the variable's value."
2324 (custom-load-widget widget
)
2325 (unless (widget-get widget
:custom-form
)
2326 (widget-put widget
:custom-form custom-variable-default-form
))
2327 (let* ((buttons (widget-get widget
:buttons
))
2328 (children (widget-get widget
:children
))
2329 (form (widget-get widget
:custom-form
))
2330 (state (widget-get widget
:custom-state
))
2331 (symbol (widget-get widget
:value
))
2332 (tag (widget-get widget
:tag
))
2333 (type (custom-variable-type symbol
))
2334 (conv (widget-convert type
))
2335 (get (or (get symbol
'custom-get
) 'default-value
))
2336 (prefix (widget-get widget
:custom-prefix
))
2337 (last (widget-get widget
:custom-last
))
2338 (value (if (default-boundp symbol
)
2339 (funcall get symbol
)
2340 (widget-get conv
:value
))))
2341 ;; If the widget is new, the child determines whether it is hidden.
2343 ((custom-show type value
)
2344 (setq state
'unknown
))
2346 (setq state
'hidden
)))
2347 ;; If we don't know the state, see if we need to edit it in lisp form.
2348 (when (eq state
'unknown
)
2349 (unless (widget-apply conv
:match value
)
2350 ;; (widget-apply (widget-convert type) :match value)
2351 (setq form
'mismatch
)))
2352 ;; Now we can create the child widget.
2353 (cond ((eq custom-buffer-style
'tree
)
2354 (insert prefix
(if last
" `--- " " |--- "))
2355 (push (widget-create-child-and-convert
2356 widget
'custom-browse-variable-tag
)
2358 (insert " " tag
"\n")
2359 (widget-put widget
:buttons buttons
))
2361 ;; Indicate hidden value.
2362 (push (widget-create-child-and-convert
2365 :sample-face
'custom-variable-tag-face
2369 (push (widget-create-child-and-convert
2371 :help-echo
"Show the value of this option."
2373 :action
'custom-toggle-parent
2376 ((memq form
'(lisp mismatch
))
2377 ;; In lisp mode edit the saved value when possible.
2378 (let* ((value (cond ((get symbol
'saved-value
)
2379 (car (get symbol
'saved-value
)))
2380 ((get symbol
'standard-value
)
2381 (car (get symbol
'standard-value
)))
2382 ((default-boundp symbol
)
2383 (custom-quote (funcall get symbol
)))
2385 (custom-quote (widget-get conv
:value
))))))
2386 (insert (symbol-name symbol
) ": ")
2387 (push (widget-create-child-and-convert
2389 :help-echo
"Hide the value of this option."
2392 :action
'custom-toggle-parent
2396 (push (widget-create-child-and-convert
2398 :button-face
'custom-variable-button-face
2400 :tag
(symbol-name symbol
)
2406 (let* ((format (widget-get type
:format
))
2407 tag-format value-format
)
2408 (unless (string-match ":" format
)
2409 (error "Bad format"))
2410 (setq tag-format
(substring format
0 (match-end 0)))
2411 (setq value-format
(substring format
(match-end 0)))
2412 (push (widget-create-child-and-convert
2415 :action
'custom-tag-action
2416 :help-echo
"Change value of this option."
2417 :mouse-down-action
'custom-tag-mouse-down-action
2418 :button-face
'custom-variable-button-face
2419 :sample-face
'custom-variable-tag-face
2423 (push (widget-create-child-and-convert
2425 :help-echo
"Hide the value of this option."
2428 :action
'custom-toggle-parent
2431 (push (widget-create-child-and-convert
2433 :format value-format
2436 (unless (eq custom-buffer-style
'tree
)
2437 (unless (eq (preceding-char) ?
\n)
2438 (widget-insert "\n"))
2439 ;; Create the magic button.
2440 (let ((magic (widget-create-child-and-convert
2441 widget
'custom-magic nil
)))
2442 (widget-put widget
:custom-magic magic
)
2443 (push magic buttons
))
2444 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2445 ;; before the call to `widget-default-format-handler'. Otherwise, I
2446 ;; loose my current `buttons'. This function shouldn't be called like
2447 ;; this anyway. The doc string widget should be added like the others.
2449 (widget-put widget
:buttons buttons
)
2451 ;; Insert documentation.
2452 (widget-default-format-handler widget ?h
)
2454 ;; The comment field
2455 (unless (eq state
'hidden
)
2456 (let* ((comment (get symbol
'variable-comment
))
2458 (widget-create-child-and-convert
2459 widget
'custom-comment
2461 :value
(or comment
""))))
2462 (widget-put widget
:comment-widget comment-widget
)
2463 ;; Don't push it !!! Custom assumes that the first child is the
2465 (setq children
(append children
(list comment-widget
)))))
2466 ;; Update the rest of the properties properties.
2467 (widget-put widget
:custom-form form
)
2468 (widget-put widget
:children children
)
2469 ;; Now update the state.
2470 (if (eq state
'hidden
)
2471 (widget-put widget
:custom-state state
)
2472 (custom-variable-state-set widget
))
2474 (unless (eq state
'hidden
)
2475 (when (eq (widget-get widget
:custom-level
) 1)
2476 (custom-add-parent-links widget
))
2477 (custom-add-see-also widget
)))))
2479 (defun custom-tag-action (widget &rest args
)
2480 "Pass :action to first child of WIDGET's parent."
2481 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2484 (defun custom-tag-mouse-down-action (widget &rest args
)
2485 "Pass :mouse-down-action to first child of WIDGET's parent."
2486 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2487 :mouse-down-action args
))
2489 (defun custom-variable-state-set (widget)
2490 "Set the state of WIDGET."
2491 (let* ((symbol (widget-value widget
))
2492 (get (or (get symbol
'custom-get
) 'default-value
))
2493 (value (if (default-boundp symbol
)
2494 (funcall get symbol
)
2495 (widget-get widget
:value
)))
2496 (comment (get symbol
'variable-comment
))
2499 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2501 (get symbol
'customized-variable-comment
))
2503 (if (condition-case nil
2504 (and (equal value
(eval (car tmp
)))
2505 (equal comment temp
))
2509 ((progn (setq tmp
(get symbol
'saved-value
))
2510 (setq temp
(get symbol
'saved-variable-comment
))
2512 (if (condition-case nil
2513 (and (equal value
(eval (car tmp
)))
2514 (equal comment temp
))
2518 ((setq tmp
(get symbol
'standard-value
))
2519 (if (condition-case nil
2520 (and (equal value
(eval (car tmp
)))
2521 (equal comment nil
))
2526 (widget-put widget
:custom-state state
)))
2528 (defun custom-variable-standard-value (widget)
2529 (get (widget-value widget
) 'standard-value
))
2531 (defvar custom-variable-menu
2532 '(("Set for Current Session" custom-variable-set
2534 (eq (widget-get widget
:custom-state
) 'modified
)))
2535 ("Save for Future Sessions" custom-variable-save
2537 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2538 ("Reset to Current" custom-redraw
2540 (and (default-boundp (widget-value widget
))
2541 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2542 ("Reset to Saved" custom-variable-reset-saved
2544 (and (or (get (widget-value widget
) 'saved-value
)
2545 (get (widget-value widget
) 'saved-variable-comment
))
2546 (memq (widget-get widget
:custom-state
)
2547 '(modified set changed rogue
)))))
2548 ("Erase Customization" custom-variable-reset-standard
2550 (and (get (widget-value widget
) 'standard-value
)
2551 (memq (widget-get widget
:custom-state
)
2552 '(modified set changed saved rogue
)))))
2553 ("Use Backup Value" custom-variable-reset-backup
2555 (get (widget-value widget
) 'backup-value
)))
2556 ("---" ignore ignore
)
2557 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2558 ("---" ignore ignore
)
2559 ("Don't show as Lisp expression" custom-variable-edit
2561 (eq (widget-get widget
:custom-form
) 'lisp
)))
2562 ("Show initial Lisp expression" custom-variable-edit-lisp
2564 (eq (widget-get widget
:custom-form
) 'edit
))))
2565 "Alist of actions for the `custom-variable' widget.
2566 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2567 the menu entry, ACTION is the function to call on the widget when the
2568 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2569 widget as an argument, and returns non-nil if ACTION is valid on that
2570 widget. If FILTER is nil, ACTION is always valid.")
2572 (defun custom-variable-action (widget &optional event
)
2573 "Show the menu for `custom-variable' WIDGET.
2574 Optional EVENT is the location for the menu."
2575 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2576 (custom-toggle-hide widget
)
2577 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2578 (custom-variable-state-set widget
))
2579 (custom-redraw-magic widget
)
2580 (let* ((completion-ignore-case t
)
2581 (answer (widget-choose (concat "Operation on "
2582 (custom-unlispify-tag-name
2583 (widget-get widget
:value
)))
2584 (custom-menu-filter custom-variable-menu
2588 (funcall answer widget
)))))
2590 (defun custom-variable-edit (widget)
2591 "Edit value of WIDGET."
2592 (widget-put widget
:custom-state
'unknown
)
2593 (widget-put widget
:custom-form
'edit
)
2594 (custom-redraw widget
))
2596 (defun custom-variable-edit-lisp (widget)
2597 "Edit the Lisp representation of the value of WIDGET."
2598 (widget-put widget
:custom-state
'unknown
)
2599 (widget-put widget
:custom-form
'lisp
)
2600 (custom-redraw widget
))
2602 (defun custom-variable-set (widget)
2603 "Set the current value for the variable being edited by WIDGET."
2604 (let* ((form (widget-get widget
:custom-form
))
2605 (state (widget-get widget
:custom-state
))
2606 (child (car (widget-get widget
:children
)))
2607 (symbol (widget-value widget
))
2608 (set (or (get symbol
'custom-set
) 'set-default
))
2609 (comment-widget (widget-get widget
:comment-widget
))
2610 (comment (widget-value comment-widget
))
2612 (cond ((eq state
'hidden
)
2613 (error "Cannot set hidden variable"))
2614 ((setq val
(widget-apply child
:validate
))
2615 (goto-char (widget-get val
:from
))
2616 (error "%s" (widget-get val
:error
)))
2617 ((memq form
'(lisp mismatch
))
2618 (when (equal comment
"")
2620 ;; Make the comment invisible by hand if it's empty
2621 (custom-comment-hide comment-widget
))
2622 (custom-variable-backup-value widget
)
2623 (funcall set symbol
(eval (setq val
(widget-value child
))))
2624 (put symbol
'customized-value
(list val
))
2625 (put symbol
'variable-comment comment
)
2626 (put symbol
'customized-variable-comment comment
))
2628 (when (equal comment
"")
2630 ;; Make the comment invisible by hand if it's empty
2631 (custom-comment-hide comment-widget
))
2632 (custom-variable-backup-value widget
)
2633 (funcall set symbol
(setq val
(widget-value child
)))
2634 (put symbol
'customized-value
(list (custom-quote val
)))
2635 (put symbol
'variable-comment comment
)
2636 (put symbol
'customized-variable-comment comment
)))
2637 (custom-variable-state-set widget
)
2638 (custom-redraw-magic widget
)))
2640 (defun custom-variable-save (widget)
2641 "Set and save the value for the variable being edited by WIDGET."
2642 (let* ((form (widget-get widget
:custom-form
))
2643 (state (widget-get widget
:custom-state
))
2644 (child (car (widget-get widget
:children
)))
2645 (symbol (widget-value widget
))
2646 (set (or (get symbol
'custom-set
) 'set-default
))
2647 (comment-widget (widget-get widget
:comment-widget
))
2648 (comment (widget-value comment-widget
))
2650 (cond ((eq state
'hidden
)
2651 (error "Cannot set hidden variable"))
2652 ((setq val
(widget-apply child
:validate
))
2653 (goto-char (widget-get val
:from
))
2654 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2655 ((memq form
'(lisp mismatch
))
2656 (when (equal comment
"")
2658 ;; Make the comment invisible by hand if it's empty
2659 (custom-comment-hide comment-widget
))
2660 (put symbol
'saved-value
(list (widget-value child
)))
2661 (custom-push-theme 'theme-value symbol
'user
2662 'set
(list (widget-value child
)))
2663 (funcall set symbol
(eval (widget-value child
)))
2664 (put symbol
'variable-comment comment
)
2665 (put symbol
'saved-variable-comment comment
))
2667 (when (equal comment
"")
2669 ;; Make the comment invisible by hand if it's empty
2670 (custom-comment-hide comment-widget
))
2671 (put symbol
'saved-value
2672 (list (custom-quote (widget-value child
))))
2673 (custom-push-theme 'theme-value symbol
'user
2674 'set
(list (custom-quote (widget-value
2676 (funcall set symbol
(widget-value child
))
2677 (put symbol
'variable-comment comment
)
2678 (put symbol
'saved-variable-comment comment
)))
2679 (put symbol
'customized-value nil
)
2680 (put symbol
'customized-variable-comment nil
)
2682 (custom-variable-state-set widget
)
2683 (custom-redraw-magic widget
)))
2685 (defun custom-variable-reset-saved (widget)
2686 "Restore the saved value for the variable being edited by WIDGET.
2687 The value that was current before this operation
2688 becomes the backup value, so you can get it again."
2689 (let* ((symbol (widget-value widget
))
2690 (set (or (get symbol
'custom-set
) 'set-default
))
2691 (value (get symbol
'saved-value
))
2692 (comment (get symbol
'saved-variable-comment
)))
2693 (cond ((or value comment
)
2694 (put symbol
'variable-comment comment
)
2695 (custom-variable-backup-value widget
)
2697 (funcall set symbol
(eval (car value
)))
2700 (error "No saved value for %s" symbol
)))
2701 (put symbol
'customized-value nil
)
2702 (put symbol
'customized-variable-comment nil
)
2703 (widget-put widget
:custom-state
'unknown
)
2704 ;; This call will possibly make the comment invisible
2705 (custom-redraw widget
)))
2707 (defun custom-variable-reset-standard (widget)
2708 "Restore the standard setting for the variable being edited by WIDGET.
2709 This operation eliminates any saved setting for the variable,
2710 restoring it to the state of a variable that has never been customized.
2711 The value that was current before this operation
2712 becomes the backup value, so you can get it again."
2713 (let* ((symbol (widget-value widget
))
2714 (set (or (get symbol
'custom-set
) 'set-default
)))
2715 (if (get symbol
'standard-value
)
2717 (custom-variable-backup-value widget
)
2718 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2719 (error "No standard setting known for %S" symbol
))
2720 (put symbol
'variable-comment nil
)
2721 (put symbol
'customized-value nil
)
2722 (put symbol
'customized-variable-comment nil
)
2723 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2724 (put symbol
'saved-value nil
)
2725 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2726 ;; As a special optimizations we do not (explictly)
2727 ;; save resets to standard when no theme set the value.
2728 (if (null (cdr (get symbol
'theme-value
)))
2729 (put symbol
'theme-value nil
))
2730 (put symbol
'saved-variable-comment nil
)
2732 (widget-put widget
:custom-state
'unknown
)
2733 ;; This call will possibly make the comment invisible
2734 (custom-redraw widget
)))
2736 (defun custom-variable-backup-value (widget)
2737 "Back up the current value for WIDGET's variable.
2738 The backup value is kept in the car of the `backup-value' property."
2739 (let* ((symbol (widget-value widget
))
2740 (get (or (get symbol
'custom-get
) 'default-value
))
2741 (type (custom-variable-type symbol
))
2742 (conv (widget-convert type
))
2743 (value (if (default-boundp symbol
)
2744 (funcall get symbol
)
2745 (widget-get conv
:value
))))
2746 (put symbol
'backup-value
(list value
))))
2748 (defun custom-variable-reset-backup (widget)
2749 "Restore the backup value for the variable being edited by WIDGET.
2750 The value that was current before this operation
2751 becomes the backup value, so you can use this operation repeatedly
2752 to switch between two values."
2753 (let* ((symbol (widget-value widget
))
2754 (set (or (get symbol
'custom-set
) 'set-default
))
2755 (value (get symbol
'backup-value
))
2756 (comment-widget (widget-get widget
:comment-widget
))
2757 (comment (widget-value comment-widget
)))
2760 (custom-variable-backup-value widget
)
2762 (funcall set symbol
(car value
))
2764 (error "No backup value for %s" symbol
))
2765 (put symbol
'customized-value
(list (car value
)))
2766 (put symbol
'variable-comment comment
)
2767 (put symbol
'customized-variable-comment comment
)
2768 (custom-variable-state-set widget
)
2769 ;; This call will possibly make the comment invisible
2770 (custom-redraw widget
)))
2772 ;;; The `custom-face-edit' Widget.
2774 (define-widget 'custom-face-edit
'checklist
2775 "Edit face attributes."
2779 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2780 :value-to-internal
'custom-face-edit-fix-value
2781 :match
(lambda (widget value
)
2782 (widget-checklist-match widget
2783 (custom-face-edit-fix-value widget value
)))
2784 :convert-widget
'custom-face-edit-convert-widget
2785 :args
(mapcar (lambda (att)
2788 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2789 (list 'const
:format
"" :value
(nth 0 att
))
2791 custom-face-attributes
))
2793 (defun custom-face-edit-fix-value (widget value
)
2794 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2795 Also change :reverse-video to :inverse-video."
2799 (let ((key (car value
))
2800 (val (car (cdr value
))))
2801 (cond ((eq key
:italic
)
2802 (push :slant result
)
2803 (push (if val
'italic
'normal
) result
))
2805 (push :weight result
)
2806 (push (if val
'bold
'normal
) result
))
2807 ((eq key
:reverse-video
)
2808 (push :inverse-video result
)
2812 (push val result
))))
2813 (setq value
(cdr (cdr value
))))
2814 (setq result
(nreverse result
))
2818 (defun custom-face-edit-convert-widget (widget)
2819 "Convert :args as widget types in WIDGET."
2822 :args
(mapcar (lambda (arg)
2824 :deactivate
'custom-face-edit-deactivate
2825 :activate
'custom-face-edit-activate
2826 :delete
'custom-face-edit-delete
))
2827 (widget-get widget
:args
)))
2830 (defun custom-face-edit-deactivate (widget)
2831 "Make face widget WIDGET inactive for user modifications."
2832 (unless (widget-get widget
:inactive
)
2833 (let ((tag (custom-face-edit-attribute-tag widget
))
2834 (from (copy-marker (widget-get widget
:from
)))
2835 (value (widget-value widget
))
2836 (inhibit-read-only t
)
2837 (inhibit-modification-hooks t
))
2840 (widget-default-delete widget
)
2841 (insert tag
": *\n")
2842 (widget-put widget
:inactive
2843 (cons value
(cons from
(- (point) from
))))))))
2845 (defun custom-face-edit-activate (widget)
2846 "Make face widget WIDGET inactive for user modifications."
2847 (let ((inactive (widget-get widget
:inactive
))
2848 (inhibit-read-only t
)
2849 (inhibit-modification-hooks t
))
2850 (when (consp inactive
)
2852 (goto-char (car (cdr inactive
)))
2853 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2854 (widget-put widget
:inactive nil
)
2855 (widget-apply widget
:create
)
2856 (widget-value-set widget
(car inactive
))
2859 (defun custom-face-edit-delete (widget)
2860 "Remove WIDGET from the buffer."
2861 (let ((inactive (widget-get widget
:inactive
))
2862 (inhibit-read-only t
)
2863 (inhibit-modification-hooks t
))
2865 ;; Widget is alive, we don't have to do anything special
2866 (widget-default-delete widget
)
2867 ;; WIDGET is already deleted because we did so to inactivate it;
2868 ;; now just get rid of the label we put in its place.
2869 (delete-region (car (cdr inactive
))
2870 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2871 (widget-put widget
:inactive nil
))))
2874 (defun custom-face-edit-attribute-tag (widget)
2875 "Returns the first :tag property in WIDGET or one of its children."
2876 (let ((tag (widget-get widget
:tag
)))
2877 (or (and (not (equal tag
"")) tag
)
2878 (let ((children (widget-get widget
:children
)))
2879 (while (and (null tag
) children
)
2880 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2883 ;;; The `custom-display' Widget.
2885 (define-widget 'custom-display
'menu-choice
2886 "Select a display type."
2889 :help-echo
"Specify frames where the face attributes should be used."
2890 :args
'((const :tag
"all" t
)
2891 (const :tag
"defaults" default
)
2895 :args
((group :sibling-args
(:help-echo
"\
2896 Only match the specified window systems.")
2897 (const :format
"Type: "
2899 (checklist :inline t
2902 :sibling-args
(:help-echo
"\
2903 The X11 Window System.")
2905 (const :format
"PM "
2906 :sibling-args
(:help-echo
"\
2907 OS/2 Presentation Manager.")
2909 (const :format
"W32 "
2910 :sibling-args
(:help-echo
"\
2913 (const :format
"MAC "
2914 :sibling-args
(:help-echo
"\
2917 (const :format
"DOS "
2918 :sibling-args
(:help-echo
"\
2921 (const :format
"TTY%n"
2922 :sibling-args
(:help-echo
"\
2923 Plain text terminals.")
2925 (group :sibling-args
(:help-echo
"\
2926 Only match the frames with the specified color support.")
2927 (const :format
"Class: "
2929 (checklist :inline t
2931 (const :format
"Color "
2932 :sibling-args
(:help-echo
"\
2933 Match color frames.")
2935 (const :format
"Grayscale "
2936 :sibling-args
(:help-echo
"\
2937 Match grayscale frames.")
2939 (const :format
"Monochrome%n"
2940 :sibling-args
(:help-echo
"\
2941 Match frames with no color support.")
2943 (group :sibling-args
(:help-echo
"\
2944 The minimum number of colors the frame should support.")
2945 (const :format
"" min-colors
)
2946 (integer :tag
"Minimum number of colors" ))
2947 (group :sibling-args
(:help-echo
"\
2948 Only match frames with the specified intensity.")
2950 Background brightness: "
2952 (checklist :inline t
2954 (const :format
"Light "
2955 :sibling-args
(:help-echo
"\
2956 Match frames with light backgrounds.")
2958 (const :format
"Dark\n"
2959 :sibling-args
(:help-echo
"\
2960 Match frames with dark backgrounds.")
2962 (group :sibling-args
(:help-echo
"\
2963 Only match frames that support the specified face attributes.")
2964 (const :format
"Supports attributes:" supports
)
2965 (custom-face-edit :inline t
:format
"%n%v"))))))
2967 ;;; The `custom-face' Widget.
2969 (defface custom-face-tag
2970 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2971 "Face used for face tags."
2972 :group
'custom-faces
)
2973 ;; backward-compatibility alias
2974 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
2976 (defcustom custom-face-default-form
'selected
2977 "Default form of displaying face definition."
2978 :type
'(choice (const all
)
2981 :group
'custom-buffer
2984 (define-widget 'custom-face
'custom
2986 :sample-face
'custom-face-tag-face
2987 :help-echo
"Set or reset this face."
2988 :documentation-property
#'face-doc-string
2989 :value-create
'custom-face-value-create
2990 :action
'custom-face-action
2991 :custom-category
'face
2992 :custom-form nil
; defaults to value of `custom-face-default-form'
2993 :custom-set
'custom-face-set
2994 :custom-save
'custom-face-save
2995 :custom-reset-current
'custom-redraw
2996 :custom-reset-saved
'custom-face-reset-saved
2997 :custom-reset-standard
'custom-face-reset-standard
2998 :custom-standard-value
'custom-face-standard-value
2999 :custom-menu
'custom-face-menu-create
)
3001 (define-widget 'custom-face-all
'editable-list
3002 "An editable list of display specifications and attributes."
3003 :entry-format
"%i %d %v"
3004 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3005 :append-button-args
'(:help-echo
"Append new display specification here.")
3006 :delete-button-args
'(:help-echo
"Delete this display specification.")
3007 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3009 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3010 "Converted version of the `custom-face-all' widget.")
3012 (define-widget 'custom-display-unselected
'item
3013 "A display specification that doesn't match the selected display."
3014 :match
'custom-display-unselected-match
)
3016 (defun custom-display-unselected-match (widget value
)
3017 "Non-nil if VALUE is an unselected display specification."
3018 (not (face-spec-set-match-display value
(selected-frame))))
3020 (define-widget 'custom-face-selected
'group
3021 "Edit the attributes of the selected display in a face specification."
3022 :args
'((choice :inline t
3023 (group :tag
"With Defaults" :inline t
3024 (group (const :tag
"" default
)
3025 (custom-face-edit :tag
" Default\n Attributes"))
3028 (group custom-display-unselected sexp
))
3029 (group (sexp :format
"")
3030 (custom-face-edit :tag
" Overriding\n Attributes"))
3034 (group :tag
"No Defaults" :inline t
3037 (group custom-display-unselected sexp
))
3038 (group (sexp :format
"")
3039 (custom-face-edit :tag
"\n Attributes"))
3046 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3047 "Converted version of the `custom-face-selected' widget.")
3049 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3050 "Return a canonicalized version of SPEC using.
3051 FILTER-INDEX is the index in the entry for each attribute in
3052 `custom-face-attributes' at which the appropriate filter function can be
3053 found, and DEFAULT-FILTER is the filter to apply for attributes that
3055 (mapcar (lambda (entry)
3056 ;; Filter a single face-spec entry
3057 (let ((tests (car entry
))
3059 ;; Handle both old- and new-style attribute syntax
3060 (if (listp (car (cdr entry
)))
3063 (filtered-attrs nil
))
3064 ;; Filter each face attribute
3065 (while unfiltered-attrs
3066 (let* ((attr (pop unfiltered-attrs
))
3067 (pre-filtered-value (pop unfiltered-attrs
))
3069 (or (nth filter-index
(assq attr custom-face-attributes
))
3073 (funcall filter pre-filtered-value
)
3074 pre-filtered-value
)))
3075 (push filtered-value filtered-attrs
)
3076 (push attr filtered-attrs
)))
3078 (list tests filtered-attrs
)))
3081 (defun custom-pre-filter-face-spec (spec)
3082 "Return SPEC changed as necessary for editing by the face customization widget.
3083 SPEC must be a full face spec."
3084 (custom-filter-face-spec spec
2))
3086 (defun custom-post-filter-face-spec (spec)
3087 "Return the customized SPEC in a form suitable for setting the face."
3088 (custom-filter-face-spec spec
3))
3090 (defun custom-face-value-create (widget)
3091 "Create a list of the display specifications for WIDGET."
3092 (let ((buttons (widget-get widget
:buttons
))
3094 (symbol (widget-get widget
:value
))
3095 (tag (widget-get widget
:tag
))
3096 (state (widget-get widget
:custom-state
))
3098 (is-last (widget-get widget
:custom-last
))
3099 (prefix (widget-get widget
:custom-prefix
)))
3101 (setq tag
(prin1-to-string symbol
)))
3102 (cond ((eq custom-buffer-style
'tree
)
3103 (insert prefix
(if is-last
" `--- " " |--- "))
3104 (push (widget-create-child-and-convert
3105 widget
'custom-browse-face-tag
)
3107 (insert " " tag
"\n")
3108 (widget-put widget
:buttons buttons
))
3112 (widget-specify-sample widget begin
(point))
3113 (if (eq custom-buffer-style
'face
)
3115 (if (string-match "face\\'" tag
)
3117 (insert " face: ")))
3119 (push (widget-create-child-and-convert widget
'item
3126 (push (widget-create-child-and-convert
3128 :help-echo
"Hide or show this face."
3131 :action
'custom-toggle-parent
3132 (not (eq state
'hidden
)))
3136 (let ((magic (widget-create-child-and-convert
3137 widget
'custom-magic nil
)))
3138 (widget-put widget
:custom-magic magic
)
3139 (push magic buttons
))
3141 (widget-put widget
:buttons buttons
)
3142 ;; Insert documentation.
3143 (widget-default-format-handler widget ?h
)
3144 ;; The comment field
3145 (unless (eq state
'hidden
)
3146 (let* ((comment (get symbol
'face-comment
))
3148 (widget-create-child-and-convert
3149 widget
'custom-comment
3151 :value
(or comment
""))))
3152 (widget-put widget
:comment-widget comment-widget
)
3153 (push comment-widget children
)))
3155 (unless (eq state
'hidden
)
3156 (when (eq (widget-get widget
:custom-level
) 1)
3157 (custom-add-parent-links widget
))
3158 (custom-add-see-also widget
))
3160 (unless (eq (preceding-char) ?
\n)
3162 (unless (eq state
'hidden
)
3163 (message "Creating face editor...")
3164 (custom-load-widget widget
)
3165 (unless (widget-get widget
:custom-form
)
3166 (widget-put widget
:custom-form custom-face-default-form
))
3167 (let* ((symbol (widget-value widget
))
3168 (spec (or (get symbol
'customized-face
)
3169 (get symbol
'saved-face
)
3170 (get symbol
'face-defface-spec
)
3171 ;; Attempt to construct it.
3172 (list (list t
(custom-face-attributes-get
3173 symbol
(selected-frame))))))
3174 (form (widget-get widget
:custom-form
))
3175 (indent (widget-get widget
:indent
))
3177 ;; If the user has changed this face in some other way,
3178 ;; edit it as the user has specified it.
3179 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3180 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3181 (setq spec
(custom-pre-filter-face-spec spec
))
3182 (setq edit
(widget-create-child-and-convert
3184 (cond ((and (eq form
'selected
)
3185 (widget-apply custom-face-selected
3187 (when indent
(insert-char ?\ indent
))
3188 'custom-face-selected
)
3189 ((and (not (eq form
'lisp
))
3190 (widget-apply custom-face-all
3194 (when indent
(insert-char ?\ indent
))
3197 (custom-face-state-set widget
)
3198 (push edit children
)
3199 (widget-put widget
:children children
))
3200 (message "Creating face editor...done"))))))
3202 (defvar custom-face-menu
3203 '(("Set for Current Session" custom-face-set
)
3204 ("Save for Future Sessions" custom-face-save-command
)
3205 ("Reset to Saved" custom-face-reset-saved
3207 (or (get (widget-value widget
) 'saved-face
)
3208 (get (widget-value widget
) 'saved-face-comment
))))
3209 ("Erase Customization" custom-face-reset-standard
3211 (get (widget-value widget
) 'face-defface-spec
)))
3212 ("---" ignore ignore
)
3213 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3214 ("---" ignore ignore
)
3215 ("Show all display specs" custom-face-edit-all
3217 (not (eq (widget-get widget
:custom-form
) 'all
))))
3218 ("Just current attributes" custom-face-edit-selected
3220 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3221 ("Show as Lisp expression" custom-face-edit-lisp
3223 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3224 "Alist of actions for the `custom-face' widget.
3225 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3226 the menu entry, ACTION is the function to call on the widget when the
3227 menu is selected, and FILTER is a predicate which takes a `custom-face'
3228 widget as an argument, and returns non-nil if ACTION is valid on that
3229 widget. If FILTER is nil, ACTION is always valid.")
3231 (defun custom-face-edit-selected (widget)
3232 "Edit selected attributes of the value of WIDGET."
3233 (widget-put widget
:custom-state
'unknown
)
3234 (widget-put widget
:custom-form
'selected
)
3235 (custom-redraw widget
))
3237 (defun custom-face-edit-all (widget)
3238 "Edit all attributes of the value of WIDGET."
3239 (widget-put widget
:custom-state
'unknown
)
3240 (widget-put widget
:custom-form
'all
)
3241 (custom-redraw widget
))
3243 (defun custom-face-edit-lisp (widget)
3244 "Edit the Lisp representation of the value of WIDGET."
3245 (widget-put widget
:custom-state
'unknown
)
3246 (widget-put widget
:custom-form
'lisp
)
3247 (custom-redraw widget
))
3249 (defun custom-face-state-set (widget)
3250 "Set the state of WIDGET."
3251 (let* ((symbol (widget-value widget
))
3252 (comment (get symbol
'face-comment
))
3256 (setq tmp
(get symbol
'customized-face
))
3257 (setq temp
(get symbol
'customized-face-comment
))
3259 (if (equal temp comment
)
3263 (setq tmp
(get symbol
'saved-face
))
3264 (setq temp
(get symbol
'saved-face-comment
))
3266 (if (equal temp comment
)
3269 ((get symbol
'face-defface-spec
)
3270 (if (equal comment nil
)
3275 ;; If the user called set-face-attribute to change the default
3276 ;; for new frames, this face is "set outside of Customize".
3277 (if (and (not (eq state
'rogue
))
3278 (get symbol
'face-modified
))
3279 (setq state
'changed
))
3280 (widget-put widget
:custom-state state
)))
3282 (defun custom-face-action (widget &optional event
)
3283 "Show the menu for `custom-face' WIDGET.
3284 Optional EVENT is the location for the menu."
3285 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3286 (custom-toggle-hide widget
)
3287 (let* ((completion-ignore-case t
)
3288 (symbol (widget-get widget
:value
))
3289 (answer (widget-choose (concat "Operation on "
3290 (custom-unlispify-tag-name symbol
))
3291 (custom-menu-filter custom-face-menu
3295 (funcall answer widget
)))))
3297 (defun custom-face-set (widget)
3298 "Make the face attributes in WIDGET take effect."
3299 (let* ((symbol (widget-value widget
))
3300 (child (car (widget-get widget
:children
)))
3301 (value (custom-post-filter-face-spec (widget-value child
)))
3302 (comment-widget (widget-get widget
:comment-widget
))
3303 (comment (widget-value comment-widget
)))
3304 (when (equal comment
"")
3306 ;; Make the comment invisible by hand if it's empty
3307 (custom-comment-hide comment-widget
))
3308 (put symbol
'customized-face value
)
3309 (if (face-spec-choose value
)
3310 (face-spec-set symbol value
)
3311 ;; face-set-spec ignores empty attribute lists, so just give it
3312 ;; something harmless instead.
3313 (face-spec-set symbol
'((t :foreground unspecified
))))
3314 (put symbol
'customized-face-comment comment
)
3315 (put symbol
'face-comment comment
)
3316 (custom-face-state-set widget
)
3317 (custom-redraw-magic widget
)))
3319 (defun custom-face-save-command (widget)
3320 "Save in `.emacs' the face attributes in WIDGET."
3321 (custom-face-save widget
)
3324 (defun custom-face-save (widget)
3325 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3326 (let* ((symbol (widget-value widget
))
3327 (child (car (widget-get widget
:children
)))
3328 (value (custom-post-filter-face-spec (widget-value child
)))
3329 (comment-widget (widget-get widget
:comment-widget
))
3330 (comment (widget-value comment-widget
)))
3331 (when (equal comment
"")
3333 ;; Make the comment invisible by hand if it's empty
3334 (custom-comment-hide comment-widget
))
3335 (if (face-spec-choose value
)
3336 (face-spec-set symbol value
)
3337 ;; face-set-spec ignores empty attribute lists, so just give it
3338 ;; something harmless instead.
3339 (face-spec-set symbol
'((t :foreground unspecified
))))
3340 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3341 (put symbol
'saved-face value
))
3342 (custom-push-theme 'theme-face symbol
'user
'set value
)
3343 (put symbol
'customized-face nil
)
3344 (put symbol
'face-comment comment
)
3345 (put symbol
'customized-face-comment nil
)
3346 (put symbol
'saved-face-comment comment
)
3348 (custom-face-state-set widget
)
3349 (custom-redraw-magic widget
)))
3351 (defun custom-face-reset-saved (widget)
3352 "Restore WIDGET to the face's default attributes."
3353 (let* ((symbol (widget-value widget
))
3354 (child (car (widget-get widget
:children
)))
3355 (value (get symbol
'saved-face
))
3356 (comment (get symbol
'saved-face-comment
))
3357 (comment-widget (widget-get widget
:comment-widget
)))
3358 (unless (or value comment
)
3359 (error "No saved value for this face"))
3360 (put symbol
'customized-face nil
)
3361 (put symbol
'customized-face-comment nil
)
3362 (face-spec-set symbol value
)
3363 (put symbol
'face-comment comment
)
3364 (widget-value-set child value
)
3365 ;; This call manages the comment visibility
3366 (widget-value-set comment-widget
(or comment
""))
3367 (custom-face-state-set widget
)
3368 (custom-redraw-magic widget
)))
3370 (defun custom-face-standard-value (widget)
3371 (get (widget-value widget
) 'face-defface-spec
))
3373 (defun custom-face-reset-standard (widget)
3374 "Restore WIDGET to the face's standard settings.
3375 This operation eliminates any saved setting for the face,
3376 restoring it to the state of a face that has never been customized."
3377 (let* ((symbol (widget-value widget
))
3378 (child (car (widget-get widget
:children
)))
3379 (value (get symbol
'face-defface-spec
))
3380 (comment-widget (widget-get widget
:comment-widget
)))
3382 (error "No standard setting for this face"))
3383 (put symbol
'customized-face nil
)
3384 (put symbol
'customized-face-comment nil
)
3385 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3386 (put symbol
'saved-face nil
)
3387 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3388 ;; Do not explictly save resets to standards without themes.
3389 (if (null (cdr (get symbol
'theme-face
)))
3390 (put symbol
'theme-face nil
))
3391 (put symbol
'saved-face-comment nil
)
3393 (face-spec-set symbol value
)
3394 (put symbol
'face-comment nil
)
3395 (widget-value-set child value
)
3396 ;; This call manages the comment visibility
3397 (widget-value-set comment-widget
"")
3398 (custom-face-state-set widget
)
3399 (custom-redraw-magic widget
)))
3401 ;;; The `face' Widget.
3403 (defvar widget-face-prompt-value-history nil
3404 "History of input to `widget-face-prompt-value'.")
3406 (define-widget 'face
'symbol
3407 "A Lisp face name (with sample)."
3408 :format
"%{%t%}: (%{sample%}) %v"
3411 :sample-face-get
'widget-face-sample-face-get
3412 :notify
'widget-face-notify
3413 :match
(lambda (widget value
) (facep value
))
3414 :complete-function
(lambda ()
3416 (lisp-complete-symbol 'facep
))
3417 :prompt-match
'facep
3418 :prompt-history
'widget-face-prompt-value-history
3419 :validate
(lambda (widget)
3420 (unless (facep (widget-value widget
))
3422 :error
(format "Invalid face: %S"
3423 (widget-value widget
)))
3426 (defun widget-face-sample-face-get (widget)
3427 (let ((value (widget-value widget
)))
3432 (defun widget-face-notify (widget child
&optional event
)
3433 "Update the sample, and notify the parent."
3434 (overlay-put (widget-get widget
:sample-overlay
)
3435 'face
(widget-apply widget
:sample-face-get
))
3436 (widget-default-notify widget child event
))
3439 ;;; The `hook' Widget.
3441 (define-widget 'hook
'list
3443 :value-to-internal
(lambda (widget value
)
3444 (if (and value
(symbolp value
))
3447 :match
(lambda (widget value
)
3449 (widget-group-match widget value
)))
3450 ;; Avoid adding undefined functions to the hook, especially for
3451 ;; things like `find-file-hook' or even more basic ones, to avoid
3453 :set
(lambda (symbol value
)
3456 (add-hook symbol elt
))))
3457 :convert-widget
'custom-hook-convert-widget
3460 (defun custom-hook-convert-widget (widget)
3461 ;; Handle `:options'.
3462 (let* ((options (widget-get widget
:options
))
3463 (other `(editable-list :inline t
3464 :entry-format
"%i %d%v"
3465 (function :format
" %v")))
3467 (list `(checklist :inline t
3468 ,@(mapcar (lambda (entry)
3469 `(function-item ,entry
))
3473 (widget-put widget
:args args
)
3476 ;;; The `custom-group-link' Widget.
3478 (define-widget 'custom-group-link
'link
3479 "Show parent in other window when activated."
3480 :help-echo
"Create customization buffer for this group."
3481 :action
'custom-group-link-action
)
3483 (defun custom-group-link-action (widget &rest ignore
)
3484 (customize-group (widget-value widget
)))
3486 ;;; The `custom-group' Widget.
3488 (defcustom custom-group-tag-faces nil
3489 ;; In XEmacs, this ought to play games with font size.
3490 ;; Fixme: make it do so in Emacs.
3491 "Face used for group tags.
3492 The first member is used for level 1 groups, the second for level 2,
3493 and so forth. The remaining group tags are shown with `custom-group-tag'."
3494 :type
'(repeat face
)
3495 :group
'custom-faces
)
3497 (defface custom-group-tag-1
3500 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3501 (((min-colors 88) (class color
)
3503 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3506 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3508 "Face used for group tags."
3509 :group
'custom-faces
)
3510 ;; backward-compatibility alias
3511 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3513 (defface custom-group-tag
3516 (:foreground
"light blue" :weight bold
:height
1.2))
3517 (((min-colors 88) (class color
)
3519 (:foreground
"blue1" :weight bold
:height
1.2))
3522 (:foreground
"blue" :weight bold
:height
1.2))
3524 "Face used for low level group tags."
3525 :group
'custom-faces
)
3526 ;; backward-compatibility alias
3527 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3529 (define-widget 'custom-group
'custom
3532 :sample-face-get
'custom-group-sample-face-get
3533 :documentation-property
'group-documentation
3534 :help-echo
"Set or reset all members of this group."
3535 :value-create
'custom-group-value-create
3536 :action
'custom-group-action
3537 :custom-category
'group
3538 :custom-set
'custom-group-set
3539 :custom-save
'custom-group-save
3540 :custom-reset-current
'custom-group-reset-current
3541 :custom-reset-saved
'custom-group-reset-saved
3542 :custom-reset-standard
'custom-group-reset-standard
3543 :custom-menu
'custom-group-menu-create
)
3545 (defun custom-group-sample-face-get (widget)
3546 ;; Use :sample-face.
3547 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3550 (define-widget 'custom-group-visibility
'visibility
3551 "An indicator and manipulator for hidden group contents."
3552 :create
'custom-group-visibility-create
)
3554 (defun custom-group-visibility-create (widget)
3555 (let ((visible (widget-value widget
)))
3557 (insert "--------")))
3558 (widget-default-create widget
))
3560 (defun custom-group-members (symbol groups-only
)
3561 "Return SYMBOL's custom group members.
3562 If GROUPS-ONLY non-nil, return only those members that are groups."
3563 (if (not groups-only
)
3564 (get symbol
'custom-group
)
3566 (dolist (entry (get symbol
'custom-group
))
3567 (when (eq (nth 1 entry
) 'custom-group
)
3568 (push entry members
)))
3569 (nreverse members
))))
3571 (defun custom-group-value-create (widget)
3572 "Insert a customize group for WIDGET in the current buffer."
3573 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3574 (custom-load-widget widget
))
3575 (let* ((state (widget-get widget
:custom-state
))
3576 (level (widget-get widget
:custom-level
))
3577 ;; (indent (widget-get widget :indent))
3578 (prefix (widget-get widget
:custom-prefix
))
3579 (buttons (widget-get widget
:buttons
))
3580 (tag (widget-get widget
:tag
))
3581 (symbol (widget-value widget
))
3582 (members (custom-group-members symbol
3583 (and (eq custom-buffer-style
'tree
)
3584 custom-browse-only-groups
))))
3585 (cond ((and (eq custom-buffer-style
'tree
)
3587 (or members
(custom-unloaded-widget-p widget
)))
3588 (custom-browse-insert-prefix prefix
)
3589 (push (widget-create-child-and-convert
3590 widget
'custom-browse-visibility
3591 ;; :tag-glyph "plus"
3595 ;; (widget-glyph-insert nil "-- " "horizontal")
3596 (push (widget-create-child-and-convert
3597 widget
'custom-browse-group-tag
)
3599 (insert " " tag
"\n")
3600 (widget-put widget
:buttons buttons
))
3601 ((and (eq custom-buffer-style
'tree
)
3602 (zerop (length members
)))
3603 (custom-browse-insert-prefix prefix
)
3605 ;; (widget-glyph-insert nil "[ ]" "empty")
3606 ;; (widget-glyph-insert nil "-- " "horizontal")
3607 (push (widget-create-child-and-convert
3608 widget
'custom-browse-group-tag
)
3610 (insert " " tag
"\n")
3611 (widget-put widget
:buttons buttons
))
3612 ((eq custom-buffer-style
'tree
)
3613 (custom-browse-insert-prefix prefix
)
3614 (if (zerop (length members
))
3616 (custom-browse-insert-prefix prefix
)
3618 ;; (widget-glyph-insert nil "[ ]" "empty")
3619 ;; (widget-glyph-insert nil "-- " "horizontal")
3620 (push (widget-create-child-and-convert
3621 widget
'custom-browse-group-tag
)
3623 (insert " " tag
"\n")
3624 (widget-put widget
:buttons buttons
))
3625 (push (widget-create-child-and-convert
3626 widget
'custom-browse-visibility
3627 ;; :tag-glyph "minus"
3631 ;; (widget-glyph-insert nil "-\\ " "top")
3632 (push (widget-create-child-and-convert
3633 widget
'custom-browse-group-tag
)
3635 (insert " " tag
"\n")
3636 (widget-put widget
:buttons buttons
)
3637 (message "Creating group...")
3638 (let* ((members (custom-sort-items members
3639 custom-browse-sort-alphabetically
3640 custom-browse-order-groups
))
3641 (prefixes (widget-get widget
:custom-prefixes
))
3642 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3643 (extra-prefix (if (widget-get widget
:custom-last
)
3646 (prefix (concat prefix extra-prefix
))
3649 (setq entry
(car members
)
3650 members
(cdr members
))
3651 (push (widget-create-child-and-convert
3652 widget
(nth 1 entry
)
3654 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3655 :custom-prefixes custom-prefix-list
3656 :custom-level
(1+ level
)
3657 :custom-last
(null members
)
3658 :value
(nth 0 entry
)
3659 :custom-prefix prefix
)
3661 (widget-put widget
:children
(reverse children
)))
3662 (message "Creating group...done")))
3665 ;; Create level indicator.
3666 (unless (eq custom-buffer-style
'links
)
3667 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3670 (let ((begin (point)))
3672 (widget-specify-sample widget begin
(point)))
3674 ;; Create link/visibility indicator.
3675 (if (eq custom-buffer-style
'links
)
3676 (push (widget-create-child-and-convert
3677 widget
'custom-group-link
3681 (push (widget-create-child-and-convert
3682 widget
'custom-group-visibility
3683 :help-echo
"Show members of this group."
3684 :action
'custom-toggle-parent
3685 (not (eq state
'hidden
)))
3688 ;; Create magic button.
3689 (let ((magic (widget-create-child-and-convert
3690 widget
'custom-magic nil
)))
3691 (widget-put widget
:custom-magic magic
)
3692 (push magic buttons
))
3694 (widget-put widget
:buttons buttons
)
3695 ;; Insert documentation.
3696 (if (and (eq custom-buffer-style
'links
) (> level
1))
3697 (widget-put widget
:documentation-indent
0))
3698 (widget-default-format-handler widget ?h
))
3701 ;; Add parent groups references above the group.
3702 (if t
;;; This should test that the buffer
3703 ;;; was made to display a group.
3705 (if (custom-add-parent-links widget
3706 "Go to parent group:")
3708 ;; Create level indicator.
3709 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3712 (let ((start (point)))
3714 (widget-specify-sample widget start
(point)))
3716 ;; Create visibility indicator.
3717 (unless (eq custom-buffer-style
'links
)
3719 (push (widget-create-child-and-convert
3721 :help-echo
"Hide members of this group."
3722 :action
'custom-toggle-parent
3723 (not (eq state
'hidden
)))
3726 ;; Create more dashes.
3727 ;; Use 76 instead of 75 to compensate for the temporary "<"
3728 ;; added by `widget-insert'.
3729 (insert-char ?-
(- 76 (current-column)
3730 (* custom-buffer-indent level
)))
3732 ;; Create magic button.
3733 (let ((magic (widget-create-child-and-convert
3734 widget
'custom-magic
3737 (widget-put widget
:custom-magic magic
)
3738 (push magic buttons
))
3740 (widget-put widget
:buttons buttons
)
3741 ;; Insert documentation.
3742 (widget-default-format-handler widget ?h
)
3744 (if nil
;;; This should test that the buffer
3745 ;;; was not made to display a group.
3747 (insert-char ?\ custom-buffer-indent
)
3748 (custom-add-parent-links widget
)))
3749 (custom-add-see-also widget
3750 (make-string (* custom-buffer-indent level
)
3753 (message "Creating group...")
3754 (let* ((members (custom-sort-items members
3755 custom-buffer-sort-alphabetically
3756 custom-buffer-order-groups
))
3757 (prefixes (widget-get widget
:custom-prefixes
))
3758 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3759 (length (length members
))
3761 (children (mapcar (lambda (entry)
3762 (widget-insert "\n")
3764 Creating group members... %2d%%"
3765 (/ (* 100.0 count
) length
))
3766 (setq count
(1+ count
))
3768 (widget-create-child-and-convert
3769 widget
(nth 1 entry
)
3771 :tag
(custom-unlispify-tag-name
3773 :custom-prefixes custom-prefix-list
3774 :custom-level
(1+ level
)
3775 :value
(nth 0 entry
))
3776 (unless (eq (preceding-char) ?
\n)
3777 (widget-insert "\n"))))
3779 (message "Creating group magic...")
3780 (mapc 'custom-magic-reset children
)
3781 (message "Creating group state...")
3782 (widget-put widget
:children children
)
3783 (custom-group-state-update widget
)
3784 (message "Creating group... done"))
3787 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3788 (insert "\\- " (widget-get widget
:tag
) " group end ")
3789 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3792 (defvar custom-group-menu
3793 '(("Set for Current Session" custom-group-set
3795 (eq (widget-get widget
:custom-state
) 'modified
)))
3796 ("Save for Future Sessions" custom-group-save
3798 (memq (widget-get widget
:custom-state
) '(modified set
))))
3799 ("Reset to Current" custom-group-reset-current
3801 (memq (widget-get widget
:custom-state
) '(modified))))
3802 ("Reset to Saved" custom-group-reset-saved
3804 (memq (widget-get widget
:custom-state
) '(modified set
))))
3805 ("Reset to standard setting" custom-group-reset-standard
3807 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3808 "Alist of actions for the `custom-group' widget.
3809 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3810 the menu entry, ACTION is the function to call on the widget when the
3811 menu is selected, and FILTER is a predicate which takes a `custom-group'
3812 widget as an argument, and returns non-nil if ACTION is valid on that
3813 widget. If FILTER is nil, ACTION is always valid.")
3815 (defun custom-group-action (widget &optional event
)
3816 "Show the menu for `custom-group' WIDGET.
3817 Optional EVENT is the location for the menu."
3818 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3819 (custom-toggle-hide widget
)
3820 (let* ((completion-ignore-case t
)
3821 (answer (widget-choose (concat "Operation on "
3822 (custom-unlispify-tag-name
3823 (widget-get widget
:value
)))
3824 (custom-menu-filter custom-group-menu
3828 (funcall answer widget
)))))
3830 (defun custom-group-set (widget)
3831 "Set changes in all modified group members."
3832 (let ((children (widget-get widget
:children
)))
3833 (mapc (lambda (child)
3834 (when (eq (widget-get child
:custom-state
) 'modified
)
3835 (widget-apply child
:custom-set
)))
3838 (defun custom-group-save (widget)
3839 "Save all modified group members."
3840 (let ((children (widget-get widget
:children
)))
3841 (mapc (lambda (child)
3842 (when (memq (widget-get child
:custom-state
) '(modified set
))
3843 (widget-apply child
:custom-save
)))
3846 (defun custom-group-reset-current (widget)
3847 "Reset all modified group members."
3848 (let ((children (widget-get widget
:children
)))
3849 (mapc (lambda (child)
3850 (when (eq (widget-get child
:custom-state
) 'modified
)
3851 (widget-apply child
:custom-reset-current
)))
3854 (defun custom-group-reset-saved (widget)
3855 "Reset all modified or set group members."
3856 (let ((children (widget-get widget
:children
)))
3857 (mapc (lambda (child)
3858 (when (memq (widget-get child
:custom-state
) '(modified set
))
3859 (widget-apply child
:custom-reset-saved
)))
3862 (defun custom-group-reset-standard (widget)
3863 "Reset all modified, set, or saved group members."
3864 (let ((children (widget-get widget
:children
)))
3865 (mapc (lambda (child)
3866 (when (memq (widget-get child
:custom-state
)
3867 '(modified set saved
))
3868 (widget-apply child
:custom-reset-standard
)))
3871 (defun custom-group-state-update (widget)
3873 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3874 (let* ((children (widget-get widget
:children
))
3875 (states (mapcar (lambda (child)
3876 (widget-get child
:custom-state
))
3878 (magics custom-magic-alist
)
3881 (let ((magic (car (car magics
))))
3882 (if (and (not (eq magic
'hidden
))
3883 (memq magic states
))
3886 (setq magics
(cdr magics
)))))
3887 (widget-put widget
:custom-state found
)))
3888 (custom-magic-reset widget
))
3890 ;;; Reading and writing the custom file.
3893 (defcustom custom-file nil
3894 "File used for storing customization information.
3895 The default is nil, which means to use your init file
3896 as specified by `user-init-file'. If the value is not nil,
3897 it should be an absolute file name.
3899 You can set this option through Custom, if you carefully read the
3900 last paragraph below. However, usually it is simpler to write
3901 something like the following in your init file:
3903 \(setq custom-file \"~/.emacs-custom.el\")
3906 Note that both lines are necessary: the first line tells Custom to
3907 save all customizations in this file, but does not load it.
3909 When you change this variable outside Custom, look in the
3910 previous custom file \(usually your init file) for the
3911 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3912 and copy them (whichever ones you find) to the new custom file.
3913 This will preserve your existing customizations.
3915 If you save this option using Custom, Custom will write all
3916 currently saved customizations, including the new one for this
3917 option itself, into the file you specify, overwriting any
3918 `custom-set-variables' and `custom-set-faces' forms already
3919 present in that file. It will not delete any customizations from
3920 the old custom file. You should do that manually if that is what you
3921 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3922 in your init file, where CUSTOM-FILE is the actual name of the
3923 file. Otherwise, Emacs will not load the file when it starts up,
3924 and hence will not set `custom-file' to that file either."
3925 :type
'(choice (const :tag
"Your Emacs init file" nil
)
3926 (file :format
"%t:%v%d"
3928 "Please read entire docstring below before setting \
3929 this through Custom.
3930 Click om \"More\" \(or position point there and press RETURN)
3931 if only the first line of the docstring is shown."))
3934 (defun custom-file ()
3935 "Return the file name for saving customizations."
3938 (let ((user-init-file user-init-file
)
3940 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3941 (when (null user-init-file
)
3942 (if (or (file-exists-p default-init-file
)
3943 (and (eq system-type
'windows-nt
)
3944 (file-exists-p "~/_emacs")))
3945 ;; Started with -q, i.e. the file containing
3946 ;; Custom settings hasn't been read. Saving
3947 ;; settings there would overwrite other settings.
3948 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3949 (setq user-init-file default-init-file
))
3953 (defun custom-save-all ()
3954 "Save all customizations in `custom-file'."
3955 (let* ((filename (custom-file))
3956 (recentf-exclude (if recentf-mode
3958 (regexp-quote (custom-file))
3961 (old-buffer (find-buffer-visiting filename
)))
3962 (with-current-buffer (or old-buffer
(find-file-noselect filename
))
3963 (let ((inhibit-read-only t
))
3964 (custom-save-variables)
3965 (custom-save-faces))
3966 (let ((file-precious-flag t
))
3969 (kill-buffer (current-buffer))))))
3971 ;; Editing the custom file contents in a buffer.
3973 (defun custom-save-delete (symbol)
3974 "Delete all calls to SYMBOL from the contents of the current buffer.
3975 Leave point at the old location of the first such call,
3976 or (if there were none) at the end of the buffer.
3978 This function does not save the buffer."
3979 (goto-char (point-min))
3980 ;; Skip all whitespace and comments.
3981 (while (forward-comment 1))
3983 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3986 (while t
;; We exit this loop only via throw.
3987 ;; Skip all whitespace and comments.
3988 (while (forward-comment 1))
3989 (let ((start (point))
3990 (sexp (condition-case nil
3991 (read (current-buffer))
3992 (end-of-file (throw 'found nil
)))))
3993 (when (and (listp sexp
)
3994 (eq (car sexp
) symbol
))
3995 (delete-region start
(point))
3997 (setq first
(point)))))))
4000 ;; Move in front of local variables, otherwise long Custom
4001 ;; entries would make them ineffective.
4002 (let ((pos (point-max))
4003 (case-fold-search t
))
4005 (goto-char (point-max))
4006 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4008 (when (search-forward "Local Variables:" nil t
)
4009 (setq pos
(line-beginning-position))))
4012 (defun custom-save-variables ()
4013 "Save all customized variables in `custom-file'."
4015 (custom-save-delete 'custom-load-themes
)
4016 (custom-save-delete 'custom-reset-variables
)
4017 (custom-save-delete 'custom-set-variables
)
4018 (custom-save-loaded-themes)
4019 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
4020 (let ((standard-output (current-buffer))
4021 (saved-list (make-list 1 0))
4023 ;; First create a sorted list of saved variables.
4026 (if (get symbol
'saved-value
)
4027 (nconc saved-list
(list symbol
)))))
4028 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4031 (princ "(custom-set-variables
4032 ;; custom-set-variables was added by Custom.
4033 ;; If you edit it by hand, you could mess it up, so be careful.
4034 ;; Your init file should contain only one such instance.
4035 ;; If there is more than one, they won't work right.\n")
4036 (dolist (symbol saved-list
)
4037 (let ((spec (car-safe (get symbol
'theme-value
)))
4038 (value (get symbol
'saved-value
))
4039 (requests (get symbol
'custom-requests
))
4040 (now (not (or (custom-variable-p symbol
)
4041 (and (not (boundp symbol
))
4042 (not (eq (get symbol
'force-value
)
4044 (comment (get symbol
'saved-variable-comment
)))
4045 ;; Check `requests'.
4046 (dolist (request requests
)
4047 (when (and (symbolp request
) (not (featurep request
)))
4048 (message "Unknown requested feature: %s" request
)
4049 (setq requests
(delq request requests
))))
4051 (eq (nth 0 spec
) 'user
)
4052 (eq (nth 1 spec
) 'set
))
4054 (and (null spec
) (get symbol
'saved-value
)))
4061 (when (or now requests comment
)
4064 (when (or requests comment
)
4074 (unless (looking-at "\n")
4077 (defun custom-save-faces ()
4078 "Save all customized faces in `custom-file'."
4080 (custom-save-delete 'custom-reset-faces
)
4081 (custom-save-delete 'custom-set-faces
)
4082 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
4083 (let ((standard-output (current-buffer))
4084 (saved-list (make-list 1 0))
4086 ;; First create a sorted list of saved faces.
4089 (if (get symbol
'saved-face
)
4090 (nconc saved-list
(list symbol
)))))
4091 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4092 ;; The default face must be first, since it affects the others.
4093 (if (memq 'default saved-list
)
4094 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4097 (princ "(custom-set-faces
4098 ;; custom-set-faces was added by Custom.
4099 ;; If you edit it by hand, you could mess it up, so be careful.
4100 ;; Your init file should contain only one such instance.
4101 ;; If there is more than one, they won't work right.\n")
4102 (dolist (symbol saved-list
)
4103 (let ((spec (car-safe (get symbol
'theme-face
)))
4104 (value (get symbol
'saved-face
))
4105 (now (not (or (get symbol
'face-defface-spec
)
4106 (and (not (custom-facep symbol
))
4107 (not (get symbol
'force-face
))))))
4108 (comment (get symbol
'saved-face-comment
)))
4110 (eq (nth 0 spec
) 'user
)
4111 (eq (nth 1 spec
) 'set
))
4113 (and (null spec
) (get symbol
'saved-face
)))
4114 ;; Don't print default face here.
4121 (when (or now comment
)
4131 (unless (looking-at "\n")
4134 (defun custom-save-resets (property setter special
)
4135 (let (started-writing ignored-special
)
4136 ;; (custom-save-delete setter) Done by caller
4137 (let ((standard-output (current-buffer))
4138 (mapper `(lambda (object)
4139 (let ((spec (car-safe (get object
(quote ,property
)))))
4140 (when (and (not (memq object ignored-special
))
4141 (eq (nth 0 spec
) 'user
)
4142 (eq (nth 1 spec
) 'reset
))
4143 ;; Do not write reset statements unless necessary.
4144 (unless started-writing
4145 (setq started-writing t
)
4149 (princ (quote ,setter
))
4153 (prin1 (nth 3 spec
))
4155 (mapc mapper special
)
4156 (setq ignored-special special
)
4158 (when started-writing
4161 (defun custom-save-loaded-themes ()
4162 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
4163 (standard-output (current-buffer)))
4165 (unless (bolp) (princ "\n"))
4166 (princ "(custom-load-themes")
4167 (mapc (lambda (theme)
4169 (prin1 theme
)) themes
)
4173 (defun customize-save-customized ()
4174 "Save all user options which have been set in this session."
4176 (mapatoms (lambda (symbol)
4177 (let ((face (get symbol
'customized-face
))
4178 (value (get symbol
'customized-value
))
4179 (face-comment (get symbol
'customized-face-comment
))
4181 (get symbol
'customized-variable-comment
)))
4183 (put symbol
'saved-face face
)
4184 (custom-push-theme 'theme-face symbol
'user
'set value
)
4185 (put symbol
'customized-face nil
))
4187 (put symbol
'saved-value value
)
4188 (custom-push-theme 'theme-value symbol
'user
'set value
)
4189 (put symbol
'customized-value nil
))
4190 (when variable-comment
4191 (put symbol
'saved-variable-comment variable-comment
)
4192 (put symbol
'customized-variable-comment nil
))
4194 (put symbol
'saved-face-comment face-comment
)
4195 (put symbol
'customized-face-comment nil
)))))
4196 ;; We really should update all custom buffers here.
4199 ;;; The Customize Menu.
4203 (defcustom custom-menu-nesting
2
4204 "Maximum nesting in custom menus."
4206 :group
'custom-menu
)
4208 (defun custom-face-menu-create (widget symbol
)
4209 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4210 (vector (custom-unlispify-menu-entry symbol
)
4211 `(customize-face ',symbol
)
4214 (defun custom-variable-menu-create (widget symbol
)
4215 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4216 (let ((type (get symbol
'custom-type
)))
4217 (unless (listp type
)
4218 (setq type
(list type
)))
4219 (if (and type
(widget-get type
:custom-menu
))
4220 (widget-apply type
:custom-menu symbol
)
4221 (vector (custom-unlispify-menu-entry symbol
)
4222 `(customize-variable ',symbol
)
4225 ;; Add checkboxes to boolean variable entries.
4226 (widget-put (get 'boolean
'widget-type
)
4227 :custom-menu
(lambda (widget symbol
)
4228 (vector (custom-unlispify-menu-entry symbol
)
4229 `(customize-variable ',symbol
)
4231 ':selected symbol
)))
4233 (defun custom-group-menu-create (widget symbol
)
4234 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4235 `( ,(custom-unlispify-menu-entry symbol t
)
4236 :filter
(lambda (&rest junk
)
4237 (let ((menu (custom-menu-create ',symbol
)))
4238 (if (consp menu
) (cdr menu
) menu
)))))
4241 (defun custom-menu-create (symbol)
4242 "Create menu for customization group SYMBOL.
4243 The menu is in a format applicable to `easy-menu-define'."
4244 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4245 `(customize-group ',symbol
)
4247 (if (and (or (not (boundp 'custom-menu-nesting
))
4248 (>= custom-menu-nesting
0))
4250 (custom-load-symbol symbol
)
4251 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4252 (let ((custom-prefix-list (custom-prefix-add symbol
4253 custom-prefix-list
))
4254 (members (custom-sort-items (get symbol
'custom-group
)
4255 custom-menu-sort-alphabetically
4256 custom-menu-order-groups
)))
4257 `(,(custom-unlispify-menu-entry symbol t
)
4260 ,@(mapcar (lambda (entry)
4261 (widget-apply (if (listp (nth 1 entry
))
4263 (list (nth 1 entry
)))
4264 :custom-menu
(nth 0 entry
)))
4269 (defun customize-menu-create (symbol &optional name
)
4270 "Return a customize menu for customization group SYMBOL.
4271 If optional NAME is given, use that as the name of the menu.
4272 Otherwise the menu will be named `Customize'.
4273 The format is suitable for use with `easy-menu-define'."
4275 (setq name
"Customize"))
4277 :filter
(lambda (&rest junk
)
4278 (let ((menu (custom-menu-create ',symbol
)))
4279 (if (consp menu
) (cdr menu
) menu
)))))
4281 ;;; The Custom Mode.
4283 (defvar custom-mode-map
4284 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4285 ;; "\r" bindings from the parent map.
4286 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4287 (let ((map (make-keymap)))
4288 (set-keymap-parent map widget-keymap
)
4289 (suppress-keymap map
)
4290 (define-key map
" " 'scroll-up
)
4291 (define-key map
"\177" 'scroll-down
)
4292 (define-key map
"\C-c\C-c" 'Custom-set
)
4293 (define-key map
"\C-x\C-s" 'Custom-save
)
4294 (define-key map
"q" 'Custom-buffer-done
)
4295 (define-key map
"u" 'Custom-goto-parent
)
4296 (define-key map
"n" 'widget-forward
)
4297 (define-key map
"p" 'widget-backward
)
4298 (define-key map
[mouse-1
] 'widget-move-and-invoke
)
4300 "Keymap for `custom-mode'.")
4302 (easy-menu-define Custom-mode-menu
4304 "Menu used in customization buffers."
4306 ,(customize-menu-create 'customize
)
4307 ["Set" Custom-set t
]
4308 ["Save" Custom-save t
]
4309 ["Reset to Current" Custom-reset-current t
]
4310 ["Reset to Saved" Custom-reset-saved t
]
4311 ["Reset to Standard Settings" Custom-reset-standard t
]
4312 ["Info" (info "(emacs)Easy Customization") t
]))
4314 (defun Custom-goto-parent ()
4315 "Go to the parent group listed at the top of this buffer.
4316 If several parents are listed, go to the first of them."
4319 (goto-char (point-min))
4320 (if (search-forward "\nGo to parent group: " nil t
)
4321 (let* ((button (get-char-property (point) 'button
))
4322 (parent (downcase (widget-get button
:tag
))))
4323 (customize-group parent
)))))
4325 (defcustom custom-mode-hook nil
4326 "Hook called when entering Custom mode."
4328 :group
'custom-buffer
)
4330 (defun custom-state-buffer-message (widget)
4331 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4332 (message "To install your edits, invoke [State] and choose the Set operation")))
4334 (defun custom-mode ()
4335 "Major mode for editing customization buffers.
4337 The following commands are available:
4339 Move to next button or editable field. \\[widget-forward]
4340 Move to previous button or editable field. \\[widget-backward]
4341 \\<widget-field-keymap>\
4342 Complete content of editable text field. \\[widget-complete]
4343 \\<custom-mode-map>\
4344 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4345 Invoke button under point. \\[widget-button-press]
4346 Set all modifications. \\[Custom-set]
4347 Make all modifications default. \\[Custom-save]
4348 Reset all modified options. \\[Custom-reset-current]
4349 Reset all modified or set options. \\[Custom-reset-saved]
4350 Reset all options. \\[Custom-reset-standard]
4352 Entry to this mode calls the value of `custom-mode-hook'
4353 if that value is non-nil."
4354 (kill-all-local-variables)
4355 (setq major-mode
'custom-mode
4357 (use-local-map custom-mode-map
)
4358 (easy-menu-add Custom-mode-menu
)
4359 (make-local-variable 'custom-options
)
4360 (make-local-variable 'custom-local-buffer
)
4361 (make-local-variable 'widget-documentation-face
)
4362 (setq widget-documentation-face
'custom-documentation
)
4363 (make-local-variable 'widget-button-face
)
4364 (setq widget-button-face custom-button
)
4365 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4366 (if custom-raised-buttons
4367 (set (make-local-variable 'widget-mouse-face
) custom-button
))
4369 ;; When possible, use relief for buttons, not bracketing. This test
4370 ;; may not be optimal.
4371 (when custom-raised-buttons
4372 (set (make-local-variable 'widget-push-button-prefix
) "")
4373 (set (make-local-variable 'widget-push-button-suffix
) "")
4374 (set (make-local-variable 'widget-link-prefix
) "")
4375 (set (make-local-variable 'widget-link-suffix
) ""))
4376 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4377 (run-mode-hooks 'custom-mode-hook
))
4379 (put 'custom-mode
'mode-class
'special
)
4382 'debug-ignored-errors
4383 "^No user options have changed defaults in recent Emacs versions$")
4389 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4390 ;;; cus-edit.el ends here