1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 ;; 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
154 (put 'custom-define-hook
'custom-type
'hook
)
155 (put 'custom-define-hook
'standard-value
'(nil))
156 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link
'(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
170 "Abbreviation handling, typing shortcuts, macros."
174 (defgroup matching nil
175 "Various sorts of searching and matching."
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link
'(custom-manual "(emacs)Emulation")
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
191 (defgroup external nil
192 "Interfacing to external utilities."
195 (defgroup processes nil
196 "Process, subshell, compilation, and job control support."
200 (defgroup convenience nil
201 "Convenience features for faster editing."
204 (defgroup programming nil
205 "Support for programming in other languages."
208 (defgroup languages nil
209 "Specialized modes for editing programming languages."
213 "Lisp support, including Emacs Lisp."
218 "Support for the C language and related languages."
219 :link
'(custom-manual "(ccmode)")
227 "Support for object-oriented programming."
230 (defgroup applications nil
231 "Applications written in Emacs."
234 (defgroup calendar nil
235 "Calendar and time management support."
236 :group
'applications
)
239 "Modes for electronic-mail handling."
240 :group
'applications
)
243 "Support for netnews reading and posting."
244 :link
'(custom-manual "(gnus)")
245 :group
'applications
)
248 "Games, jokes and amusements."
249 :group
'applications
)
251 (defgroup development nil
252 "Support for further development of Emacs."
256 "Support for Emacs documentation."
259 (defgroup extensions nil
260 "Emacs Lisp language extensions."
263 (defgroup internal nil
264 "Code for Emacs internals, build process, defaults."
268 "Maintenance aids for the Emacs development group."
272 (defgroup environment nil
273 "Fitting Emacs with its environment."
277 "Communications, networking, remote access to files."
281 (defgroup hardware nil
282 "Support for interfacing with exotic hardware."
285 (defgroup terminals nil
286 "Support for terminal types."
290 "Front-ends/assistants for, or emulators of, UNIX features."
294 "Support code for vms."
298 "Internationalization and alternate character-set support."
299 :link
'(custom-manual "(emacs)International")
304 "The X Window system."
308 "Support for Emacs frames and window systems."
312 "Support editing files of data."
316 "Support editing files."
324 "Code related to the TeX formatter."
328 "Support for multiple fonts."
331 (defgroup hypermedia nil
332 "Support for links between text or other media types."
336 "Support for on-line help systems."
339 (defgroup multimedia nil
340 "Non-textual support, specifically images and sound."
344 "Code local to your site."
347 (defgroup customize
'((widgets custom-group
))
348 "Customization of the Customization support."
352 (defgroup custom-faces nil
353 "Faces used by customize."
357 (defgroup custom-browse nil
358 "Control customize browser."
362 (defgroup custom-buffer nil
363 "Control customize buffers."
367 (defgroup custom-menu nil
368 "Control customize menus."
372 (defgroup abbrev-mode nil
373 "Word abbreviations mode."
374 :link
'(custom-manual "(emacs)Abbrevs")
378 "Storage allocation and gc for GNU Emacs Lisp interpreter."
379 :tag
"Storage Allocation"
383 "Undoing changes in buffers."
384 :link
'(custom-manual "(emacs)Undo")
387 (defgroup modeline nil
388 "Content of the modeline."
391 (defgroup editing-basics nil
392 "Most basic editing facilities."
395 (defgroup display nil
396 "How characters are displayed in buffers."
399 (defgroup execute nil
400 "Executing external commands."
403 (defgroup installation nil
404 "The Emacs installation."
412 "Internal Emacs limits."
416 "Debugging Emacs itself."
419 (defgroup minibuffer nil
420 "Controling the behavior of the minibuffer."
421 :link
'(custom-manual "(emacs)Minibuffer")
424 (defgroup keyboard nil
425 "Input from the keyboard."
429 "Input from the mouse."
433 "Input from the menus."
437 "Handling data from drag and drop."
440 (defgroup auto-save nil
441 "Preventing accidential loss of data."
444 (defgroup processes-basics nil
445 "Basic stuff dealing with processes."
449 "MULE Emacs internationalization."
452 (defgroup windows nil
453 "Windows within a frame."
454 :link
'(custom-manual "(emacs)Windows")
459 (defun custom-quote (sexp)
460 "Quote SEXP iff it is not self quoting."
461 (if (or (memq sexp
'(t nil
))
464 (memq (car sexp
) '(lambda)))
468 ;;; (and (fboundp 'characterp)
469 ;;; (characterp sexp))
474 (defun custom-split-regexp-maybe (regexp)
475 "If REGEXP is a string, split it to a list at `\\|'.
476 You can get the original back with from the result with:
477 (mapconcat 'identity result \"\\|\")
479 IF REGEXP is not a string, return it unchanged."
483 (while (string-match "\\\\|" regexp start
)
484 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
485 start
(match-end 0)))
486 (nreverse (cons (substring regexp start
) all
)))
489 (defun custom-variable-prompt ()
490 "Prompt for a custom variable, defaulting to the variable at point.
491 Return a list suitable for use in `interactive'."
492 (let ((v (variable-at-point))
493 (enable-recursive-minibuffers t
)
495 (setq val
(completing-read
496 (if (and (symbolp v
) (custom-variable-p v
))
497 (format "Customize option: (default %s) " v
)
498 "Customize option: ")
499 obarray
'custom-variable-p t
))
500 (list (if (equal val
"")
501 (if (symbolp v
) v nil
)
504 (defun custom-menu-filter (menu widget
)
505 "Convert MENU to the form used by `widget-choose'.
506 MENU should be in the same format as `custom-variable-menu'.
507 WIDGET is the widget to apply the filter entries of MENU on."
509 current name action filter
)
511 (setq current
(car menu
)
513 action
(nth 1 current
)
514 filter
(nth 2 current
)
516 (if (or (null filter
) (funcall filter widget
))
517 (push (cons name action
) result
)
523 (defvar custom-prefix-list nil
524 "List of prefixes that should be ignored by `custom-unlispify'.")
526 (defcustom custom-unlispify-menu-entries t
527 "Display menu entries as words instead of symbols if non nil."
531 (defcustom custom-unlispify-remove-prefixes nil
532 "Non-nil means remove group prefixes from option names in buffer."
534 :group
'custom-buffer
537 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
538 "Convert SYMBOL into a menu entry."
539 (cond ((not custom-unlispify-menu-entries
)
540 (symbol-name symbol
))
541 ((get symbol
'custom-tag
)
543 (get symbol
'custom-tag
)
544 (concat (get symbol
'custom-tag
) "...")))
546 (with-current-buffer (get-buffer-create " *Custom-Work*")
548 (princ symbol
(current-buffer))
549 (goto-char (point-min))
550 ;; FIXME: Boolean variables are not predicates, so they shouldn't
551 ;; end with `-p'. -stef
552 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
553 ;; (re-search-forward "-p\\'" nil t))
554 ;; (replace-match "" t t)
555 ;; (goto-char (point-min)))
556 (if custom-unlispify-remove-prefixes
557 (let ((prefixes custom-prefix-list
)
560 (setq prefix
(car prefixes
))
561 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
564 (delete-region (point-min) (point)))
565 (setq prefixes
(cdr prefixes
))))))
566 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
567 (capitalize-region (point-min) (point-max))
569 (goto-char (point-max))
573 (defcustom custom-unlispify-tag-names t
574 "Display tag names as words instead of symbols if non nil."
575 :group
'custom-buffer
578 (defun custom-unlispify-tag-name (symbol)
579 "Convert SYMBOL into a menu entry."
580 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
581 (custom-unlispify-menu-entry symbol t
)))
583 (defun custom-prefix-add (symbol prefixes
)
584 "Add SYMBOL to list of ignored PREFIXES."
585 (cons (or (get symbol
'custom-prefix
)
586 (concat (symbol-name symbol
) "-"))
591 (defcustom custom-guess-name-alist
596 ("-function\\'" function
)
597 ("-functions\\'" (repeat function
))
598 ("-list\\'" (repeat sexp
))
599 ("-alist\\'" (repeat (cons sexp sexp
))))
600 "Alist of (MATCH TYPE).
602 MATCH should be a regexp matching the name of a symbol, and TYPE should
603 be a widget suitable for editing the value of that symbol. The TYPE
604 of the first entry where MATCH matches the name of the symbol will be
607 This is used for guessing the type of variables not declared with
609 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
612 (defcustom custom-guess-doc-alist
613 '(("\\`\\*?Non-nil " boolean
))
614 "Alist of (MATCH TYPE).
616 MATCH should be a regexp matching a documentation string, and TYPE
617 should be a widget suitable for editing the value of a variable with
618 that documentation string. The TYPE of the first entry where MATCH
619 matches the name of the symbol will be used.
621 This is used for guessing the type of variables not declared with
623 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
626 (defun custom-guess-type (symbol)
627 "Guess a widget suitable for editing the value of SYMBOL.
628 This is done by matching SYMBOL with `custom-guess-name-alist' and
629 if that fails, the doc string with `custom-guess-doc-alist'."
630 (let ((name (symbol-name symbol
))
631 (names custom-guess-name-alist
)
634 (setq current
(car names
)
636 (when (string-match (nth 0 current
) name
)
637 (setq found
(nth 1 current
)
640 (let ((doc (documentation-property symbol
'variable-documentation
))
641 (docs custom-guess-doc-alist
))
644 (setq current
(car docs
)
646 (when (string-match (nth 0 current
) doc
)
647 (setq found
(nth 1 current
)
653 (defcustom custom-browse-sort-alphabetically nil
654 "If non-nil, sort members of each customization group alphabetically."
656 :group
'custom-browse
)
658 (defcustom custom-browse-order-groups nil
659 "If non-nil, order group members within each customization group.
660 If `first', order groups before non-groups.
661 If `last', order groups after non-groups."
662 :type
'(choice (const first
)
664 (const :tag
"none" nil
))
665 :group
'custom-browse
)
667 (defcustom custom-browse-only-groups nil
668 "If non-nil, show group members only within each customization group."
670 :group
'custom-browse
)
672 (defcustom custom-buffer-sort-alphabetically nil
673 "If non-nil, sort members of each customization group alphabetically."
675 :group
'custom-buffer
)
677 (defcustom custom-buffer-order-groups
'last
678 "If non-nil, order group members within each customization group.
679 If `first', order groups before non-groups.
680 If `last', order groups after non-groups."
681 :type
'(choice (const first
)
683 (const :tag
"none" nil
))
684 :group
'custom-buffer
)
686 (defcustom custom-menu-sort-alphabetically nil
687 "If non-nil, sort members of each customization group alphabetically."
691 (defcustom custom-menu-order-groups
'first
692 "If non-nil, order group members within each customization group.
693 If `first', order groups before non-groups.
694 If `last', order groups after non-groups."
695 :type
'(choice (const first
)
697 (const :tag
"none" nil
))
700 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
702 (defun custom-sort-items (items sort-alphabetically order-groups
)
703 "Return a sorted copy of ITEMS.
704 ITEMS should be a `custom-group' property.
705 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
706 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
707 groups after non-groups, if nil do not order groups at all."
708 (sort (copy-sequence items
)
710 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
711 (namea (nth 0 a
)) (nameb (nth 0 b
)))
712 (cond ((not order-groups
)
713 ;; Since we don't care about A and B order, maybe sort.
714 (when sort-alphabetically
715 (string-lessp namea nameb
)))
716 ((eq typea
'custom-group
)
717 ;; If B is also a group, maybe sort. Otherwise, order A and B.
718 (if (eq typeb
'custom-group
)
719 (when sort-alphabetically
720 (string-lessp namea nameb
))
721 (eq order-groups
'first
)))
722 ((eq typeb
'custom-group
)
723 ;; Since A cannot be a group, order A and B.
724 (eq order-groups
'last
))
726 ;; Since A and B cannot be groups, sort.
727 (string-lessp namea nameb
)))))))
729 ;;; Custom Mode Commands.
731 (defvar custom-options nil
732 "Customization widgets in the current buffer.")
735 "Set changes in all modified options."
737 (let ((children custom-options
))
738 (mapc (lambda (child)
739 (when (eq (widget-get child
:custom-state
) 'modified
)
740 (widget-apply child
:custom-set
)))
743 (defun Custom-save ()
744 "Set all modified group members and save them."
746 (let ((children custom-options
))
747 (mapc (lambda (child)
748 (when (memq (widget-get child
:custom-state
)
749 '(modified set changed rogue
))
750 (widget-apply child
:custom-save
)))
754 (defvar custom-reset-menu
755 '(("Current" . Custom-reset-current
)
756 ("Saved" . Custom-reset-saved
)
757 ("Erase Customization (use standard settings)" . Custom-reset-standard
))
758 "Alist of actions for the `Reset' button.
759 The key is a string containing the name of the action, the value is a
760 Lisp function taking the widget as an element which will be called
761 when the action is chosen.")
763 (defun custom-reset (event)
764 "Select item from reset menu."
765 (let* ((completion-ignore-case t
)
766 (answer (widget-choose "Reset to"
772 (defun Custom-reset-current (&rest ignore
)
773 "Reset all modified group members to their current value."
775 (let ((children custom-options
))
776 (mapc (lambda (widget)
777 (if (memq (widget-get widget
:custom-state
)
779 (widget-apply widget
:custom-reset-current
)))
782 (defun Custom-reset-saved (&rest ignore
)
783 "Reset all modified or set group members to their saved value."
785 (let ((children custom-options
))
786 (mapc (lambda (widget)
787 (if (memq (widget-get widget
:custom-state
)
788 '(modified set changed rogue
))
789 (widget-apply widget
:custom-reset-saved
)))
792 (defun Custom-reset-standard (&rest ignore
)
793 "Erase all customization (either current or saved) for the group members.
794 The immediate result is to restore them to their standard settings.
795 This operation eliminates any saved settings for the group members,
796 making them as if they had never been customized at all."
798 (let ((children custom-options
))
799 (mapc (lambda (widget)
800 (and (widget-apply widget
:custom-standard-value
)
801 (if (memq (widget-get widget
:custom-state
)
802 '(modified set changed saved rogue
))
803 (widget-apply widget
:custom-reset-standard
))))
806 ;;; The Customize Commands
808 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
809 "Prompt for a variable and a value and return them as a list.
810 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
811 prompt for the value. The %s escape in PROMPT-VAL is replaced with
812 the name of the variable.
814 If the variable has a `variable-interactive' property, that is used as if
815 it were the arg to `interactive' (which see) to interactively read the value.
817 If the variable has a `custom-type' property, it must be a widget and the
818 `:prompt-value' property of that widget will be used for reading the value.
820 If optional COMMENT argument is non nil, also prompt for a comment and return
821 it as the third element in the list."
822 (let* ((var (read-variable prompt-var
))
823 (minibuffer-help-form '(describe-variable var
))
825 (let ((prop (get var
'variable-interactive
))
826 (type (get var
'custom-type
))
827 (prompt (format prompt-val var
)))
829 (setq type
(list type
)))
831 ;; Use VAR's `variable-interactive' property
832 ;; as an interactive spec for prompting.
833 (call-interactively (list 'lambda
'(arg)
834 (list 'interactive prop
)
837 (widget-prompt-value type
843 (eval-minibuffer prompt
))))))
846 (read-string "Comment: " (get var
'variable-comment
)))
850 (defun customize-set-value (variable value
&optional comment
)
851 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
853 If VARIABLE has a `variable-interactive' property, that is used as if
854 it were the arg to `interactive' (which see) to interactively read the value.
856 If VARIABLE has a `custom-type' property, it must be a widget and the
857 `:prompt-value' property of that widget will be used for reading the value.
859 If given a prefix (or a COMMENT argument), also prompt for a comment."
860 (interactive (custom-prompt-variable "Set variable: "
864 (cond ((string= comment
"")
865 (put variable
'variable-comment nil
))
867 (put variable
'variable-comment comment
)))
868 (set variable value
))
871 (defun customize-set-variable (variable value
&optional comment
)
872 "Set the default for VARIABLE to VALUE, and return VALUE.
873 VALUE is a Lisp object.
875 If VARIABLE has a `custom-set' property, that is used for setting
876 VARIABLE, otherwise `set-default' is used.
878 The `customized-value' property of the VARIABLE will be set to a list
879 with a quoted VALUE as its sole list member.
881 If VARIABLE has a `variable-interactive' property, that is used as if
882 it were the arg to `interactive' (which see) to interactively read the value.
884 If VARIABLE has a `custom-type' property, it must be a widget and the
885 `:prompt-value' property of that widget will be used for reading the value.
887 If given a prefix (or a COMMENT argument), also prompt for a comment."
888 (interactive (custom-prompt-variable "Set variable: "
889 "Set customized value for %s to: "
891 (custom-load-symbol variable
)
892 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
893 (put variable
'customized-value
(list (custom-quote value
)))
894 (cond ((string= comment
"")
895 (put variable
'variable-comment nil
)
896 (put variable
'customized-variable-comment nil
))
898 (put variable
'variable-comment comment
)
899 (put variable
'customized-variable-comment comment
)))
903 (defun customize-save-variable (variable value
&optional comment
)
904 "Set the default for VARIABLE to VALUE, and save it for future sessions.
907 If VARIABLE has a `custom-set' property, that is used for setting
908 VARIABLE, otherwise `set-default' is used.
910 The `customized-value' property of the VARIABLE will be set to a list
911 with a quoted VALUE as its sole list member.
913 If VARIABLE has a `variable-interactive' property, that is used as if
914 it were the arg to `interactive' (which see) to interactively read the value.
916 If VARIABLE has a `custom-type' property, it must be a widget and the
917 `:prompt-value' property of that widget will be used for reading the value.
919 If given a prefix (or a COMMENT argument), also prompt for a comment."
920 (interactive (custom-prompt-variable "Set and save variable: "
921 "Set and save value for %s as: "
923 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
924 (put variable
'saved-value
(list (custom-quote value
)))
925 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
926 (cond ((string= comment
"")
927 (put variable
'variable-comment nil
)
928 (put variable
'saved-variable-comment nil
))
930 (put variable
'variable-comment comment
)
931 (put variable
'saved-variable-comment comment
)))
937 "Select a customization buffer which you can use to set user options.
938 User options are structured into \"groups\".
939 Initially the top-level group `Emacs' and its immediate subgroups
940 are shown; the contents of those subgroups are initially hidden."
942 (customize-group 'emacs
))
945 (defun customize-mode (mode)
946 "Customize options related to the current major mode.
947 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
948 then prompt for the MODE to customize."
951 (let ((completion-regexp-list '("-mode\\'"))
952 (group (custom-group-of-mode major-mode
)))
953 (if (and group
(not current-prefix-arg
))
956 (completing-read (if group
957 (format "Major mode (default %s): " major-mode
)
960 'custom-group-of-mode
961 t nil nil
(if group
(symbol-name major-mode
))))))))
962 (customize-group (custom-group-of-mode mode
)))
966 (defun customize-group (group)
967 "Customize GROUP, which must be a customization group."
968 (interactive (list (let ((completion-ignore-case t
))
969 (completing-read "Customize group: (default emacs) "
972 (or (get symbol
'custom-loads
)
973 (get symbol
'custom-group
)))
975 (when (stringp group
)
976 (if (string-equal "" group
)
978 (setq group
(intern group
))))
979 (let ((name (format "*Customize Group: %s*"
980 (custom-unlispify-tag-name group
))))
981 (if (get-buffer name
)
983 (custom-buffer-create (list (list group
'custom-group
))
985 (concat " for group "
986 (custom-unlispify-tag-name group
))))))
989 (defun customize-group-other-window (group)
990 "Customize GROUP, which must be a customization group."
991 (interactive (list (let ((completion-ignore-case t
))
992 (completing-read "Customize group: (default emacs) "
995 (or (get symbol
'custom-loads
)
996 (get symbol
'custom-group
)))
998 (when (stringp group
)
999 (if (string-equal "" group
)
1001 (setq group
(intern group
))))
1002 (let ((name (format "*Customize Group: %s*"
1003 (custom-unlispify-tag-name group
))))
1004 (if (get-buffer name
)
1006 ;; Copied from `custom-buffer-create-other-window'.
1008 (same-window-buffer-names nil
)
1009 (same-window-regexps nil
))
1010 (pop-to-buffer name
))
1011 (custom-buffer-create-other-window
1012 (list (list group
'custom-group
))
1014 (concat " for group "
1015 (custom-unlispify-tag-name group
))))))
1018 (defalias 'customize-variable
'customize-option
)
1021 (defun customize-option (symbol)
1022 "Customize SYMBOL, which must be a user option variable."
1023 (interactive (custom-variable-prompt))
1024 (let ((basevar (indirect-variable symbol
)))
1025 (custom-buffer-create (list (list basevar
'custom-variable
))
1026 (format "*Customize Option: %s*"
1027 (custom-unlispify-tag-name basevar
)))
1028 (unless (eq symbol basevar
)
1029 (message "`%s' is an alias for `%s'" symbol basevar
))))
1032 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1035 (defun customize-option-other-window (symbol)
1036 "Customize SYMBOL, which must be a user option variable.
1037 Show the buffer in another window, but don't select it."
1038 (interactive (custom-variable-prompt))
1039 (let ((basevar (indirect-variable symbol
)))
1040 (custom-buffer-create-other-window
1041 (list (list basevar
'custom-variable
))
1042 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1043 (unless (eq symbol basevar
)
1044 (message "`%s' is an alias for `%s'" symbol basevar
))))
1046 (defvar customize-changed-options-previous-release
"20.2"
1047 "Version for `customize-changed-options' to refer back to by default.")
1050 (defun customize-changed-options (since-version)
1051 "Customize all user option variables changed in Emacs itself.
1052 This includes new user option variables and faces, and new
1053 customization groups, as well as older options and faces whose default
1054 values have changed since the previous major Emacs release.
1056 With argument SINCE-VERSION (a string), customize all user option
1057 variables that were added (or their meanings were changed) since that
1060 (interactive "sCustomize options changed, since version (default all versions): ")
1061 (if (equal since-version
"")
1062 (setq since-version nil
)
1063 (unless (condition-case nil
1064 (numberp (read since-version
))
1066 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1067 (unless since-version
1068 (setq since-version customize-changed-options-previous-release
))
1070 ;; Load the information for versions since since-version. We use
1071 ;; custom-load-symbol for this.
1072 (put 'custom-versions-load-alist
'custom-loads nil
)
1073 (dolist (elt custom-versions-load-alist
)
1074 (if (customize-version-lessp since-version
(car elt
))
1075 (dolist (load (cdr elt
))
1076 (custom-add-load 'custom-versions-load-alist load
))))
1077 (custom-load-symbol 'custom-versions-load-alist
)
1078 (put 'custom-versions-load-alist
'custom-loads nil
)
1083 (let ((version (get symbol
'custom-version
)))
1085 (when (customize-version-lessp since-version version
)
1086 (if (or (get symbol
'custom-group
)
1087 (get symbol
'group-documentation
))
1088 (push (list symbol
'custom-group
) found
))
1089 (if (custom-variable-p symbol
)
1090 (push (list symbol
'custom-variable
) found
))
1091 (if (custom-facep symbol
)
1092 (push (list symbol
'custom-face
) found
)))))))
1094 (custom-buffer-create (custom-sort-items found t
'first
)
1095 "*Customize Changed Options*")
1096 (error "No user option defaults have been changed since Emacs %s"
1099 (defun customize-version-lessp (version1 version2
)
1100 ;; Why are the versions strings, and given that they are, why aren't
1101 ;; they converted to numbers and compared as such here? -- fx
1103 ;; In case someone made a mistake and left out the quotes
1104 ;; in the :version value.
1105 (if (numberp version2
)
1106 (setq version2
(prin1-to-string version2
)))
1107 (let (major1 major2 minor1 minor2
)
1108 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1109 (setq major1
(read (or (match-string 1 version1
)
1111 (setq minor1
(read (or (match-string 3 version1
)
1113 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1114 (setq major2
(read (or (match-string 1 version2
)
1116 (setq minor2
(read (or (match-string 3 version2
)
1118 (or (< major1 major2
)
1119 (and (= major1 major2
)
1120 (< minor1 minor2
)))))
1123 (defun customize-face (&optional face
)
1124 "Customize FACE, which should be a face name or nil.
1125 If FACE is nil, customize all faces. If FACE is actually a
1126 face-alias, customize the face it is aliased to.
1128 Interactively, when point is on text which has a face specified,
1129 suggest to customize that face, if it's customizable."
1131 (list (read-face-name "Customize face" "all faces" t
)))
1132 (if (member face
'(nil ""))
1133 (setq face
(face-list)))
1134 (if (and (listp face
) (null (cdr face
)))
1135 (setq face
(car face
)))
1137 (custom-buffer-create (custom-sort-items
1139 (list s
'custom-face
))
1142 "*Customize Faces*")
1143 ;; If FACE is actually an alias, customize the face it is aliased to.
1144 (if (get face
'face-alias
)
1145 (setq face
(get face
'face-alias
)))
1146 (unless (facep face
)
1147 (error "Invalid face %S" face
))
1148 (custom-buffer-create (list (list face
'custom-face
))
1149 (format "*Customize Face: %s*"
1150 (custom-unlispify-tag-name face
)))))
1153 (defun customize-face-other-window (&optional face
)
1154 "Show customization buffer for face FACE in other window.
1155 If FACE is actually a face-alias, customize the face it is aliased to.
1157 Interactively, when point is on text which has a face specified,
1158 suggest to customize that face, if it's customizable."
1160 (list (read-face-name "Customize face" "all faces" t
)))
1161 (if (member face
'(nil ""))
1162 (setq face
(face-list)))
1163 (if (and (listp face
) (null (cdr face
)))
1164 (setq face
(car face
)))
1166 (custom-buffer-create-other-window
1169 (list s
'custom-face
))
1172 "*Customize Faces*")
1173 (if (get face
'face-alias
)
1174 (setq face
(get face
'face-alias
)))
1175 (unless (facep face
)
1176 (error "Invalid face %S" face
))
1177 (custom-buffer-create-other-window
1178 (list (list face
'custom-face
))
1179 (format "*Customize Face: %s*"
1180 (custom-unlispify-tag-name face
)))))
1183 (defun customize-customized ()
1184 "Customize all user options set since the last save in this session."
1187 (mapatoms (lambda (symbol)
1188 (and (or (get symbol
'customized-face
)
1189 (get symbol
'customized-face-comment
))
1190 (custom-facep symbol
)
1191 (push (list symbol
'custom-face
) found
))
1192 (and (or (get symbol
'customized-value
)
1193 (get symbol
'customized-variable-comment
))
1195 (push (list symbol
'custom-variable
) found
))))
1197 (error "No customized user options")
1198 (custom-buffer-create (custom-sort-items found t nil
)
1199 "*Customize Customized*"))))
1202 (defun customize-rogue ()
1203 "Customize all user variable modified outside customize."
1206 (mapatoms (lambda (symbol)
1207 (let ((cval (or (get symbol
'customized-value
)
1208 (get symbol
'saved-value
)
1209 (get symbol
'standard-value
))))
1210 (when (and cval
;Declared with defcustom.
1211 (default-boundp symbol
) ;Has a value.
1212 (not (equal (eval (car cval
))
1213 ;; Which does not match customize.
1214 (default-value symbol
))))
1215 (push (list symbol
'custom-variable
) found
)))))
1217 (error "No rogue user options")
1218 (custom-buffer-create (custom-sort-items found t nil
)
1219 "*Customize Rogue*"))))
1221 (defun customize-saved ()
1222 "Customize all already saved user options."
1225 (mapatoms (lambda (symbol)
1226 (and (or (get symbol
'saved-face
)
1227 (get symbol
'saved-face-comment
))
1228 (custom-facep symbol
)
1229 (push (list symbol
'custom-face
) found
))
1230 (and (or (get symbol
'saved-value
)
1231 (get symbol
'saved-variable-comment
))
1233 (push (list symbol
'custom-variable
) found
))))
1235 (error "No saved user options")
1236 (custom-buffer-create (custom-sort-items found t nil
)
1237 "*Customize Saved*"))))
1240 (defun customize-apropos (regexp &optional all
)
1241 "Customize all user options matching REGEXP.
1242 If ALL is `options', include only options.
1243 If ALL is `faces', include only faces.
1244 If ALL is `groups', include only groups.
1245 If ALL is t (interactively, with prefix arg), include options which are not
1246 user-settable, as well as faces and groups."
1247 (interactive "sCustomize regexp: \nP")
1249 (mapatoms (lambda (symbol)
1250 (when (string-match regexp
(symbol-name symbol
))
1251 (when (and (not (memq all
'(faces options
)))
1252 (get symbol
'custom-group
))
1253 (push (list symbol
'custom-group
) found
))
1254 (when (and (not (memq all
'(options groups
)))
1255 (custom-facep symbol
))
1256 (push (list symbol
'custom-face
) found
))
1257 (when (and (not (memq all
'(groups faces
)))
1259 (or (get symbol
'saved-value
)
1260 (custom-variable-p symbol
)
1261 (if (memq all
'(nil options
))
1262 (user-variable-p symbol
)
1263 (get symbol
'variable-documentation
))))
1264 (push (list symbol
'custom-variable
) found
)))))
1266 (error "No matches")
1267 (custom-buffer-create (custom-sort-items found t
1268 custom-buffer-order-groups
)
1269 "*Customize Apropos*"))))
1272 (defun customize-apropos-options (regexp &optional arg
)
1273 "Customize all user options matching REGEXP.
1274 With prefix arg, include options which are not user-settable."
1275 (interactive "sCustomize regexp: \nP")
1276 (customize-apropos regexp
(or arg
'options
)))
1279 (defun customize-apropos-faces (regexp)
1280 "Customize all user faces matching REGEXP."
1281 (interactive "sCustomize regexp: \n")
1282 (customize-apropos regexp
'faces
))
1285 (defun customize-apropos-groups (regexp)
1286 "Customize all user groups matching REGEXP."
1287 (interactive "sCustomize regexp: \n")
1288 (customize-apropos regexp
'groups
))
1292 (defcustom custom-buffer-style
'links
1293 "Control the presentation style for customization buffers.
1294 The value should be a symbol, one of:
1296 brackets: groups nest within each other with big horizontal brackets.
1297 links: groups have links to subgroups."
1298 :type
'(radio (const brackets
)
1300 :group
'custom-buffer
)
1302 (defcustom custom-buffer-done-kill nil
1303 "*Non-nil means exiting a Custom buffer should kill it."
1306 :group
'custom-buffer
)
1308 (defcustom custom-buffer-indent
3
1309 "Number of spaces to indent nested groups."
1311 :group
'custom-buffer
)
1313 (defun custom-get-fresh-buffer (name)
1314 "Get a fresh new buffer with name NAME.
1315 If the buffer already exist, clean it up to be like new.
1316 Beware: it's not quite like new. Good enough for custom, but maybe
1318 ;; To be more complete, we should also kill all permanent-local variables,
1319 ;; but it's not needed for custom.
1320 (let ((buf (get-buffer name
)))
1321 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1322 ;; This will check if the file is not saved.
1326 (get-buffer-create name
)
1327 (with-current-buffer buf
1328 (kill-all-local-variables)
1329 (run-hooks 'kill-buffer-hook
)
1330 ;; Delete overlays before erasing the buffer so the overlay hooks
1331 ;; don't get run spuriously when we erase the buffer.
1332 (let ((ols (overlay-lists)))
1333 (dolist (ol (nconc (car ols
) (cdr ols
)))
1334 (delete-overlay ol
)))
1339 (defun custom-buffer-create (options &optional name description
)
1340 "Create a buffer containing OPTIONS.
1341 Optional NAME is the name of the buffer.
1342 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1343 SYMBOL is a customization option, and WIDGET is a widget for editing
1345 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1346 (custom-buffer-create-internal options description
))
1349 (defun custom-buffer-create-other-window (options &optional name description
)
1350 "Create a buffer containing OPTIONS, and display it in another window.
1351 The result includes selecting that window.
1352 Optional NAME is the name of the buffer.
1353 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1354 SYMBOL is a customization option, and WIDGET is a widget for editing
1356 (unless name
(setq name
"*Customization*"))
1357 (let ((pop-up-windows t
)
1358 (same-window-buffer-names nil
)
1359 (same-window-regexps nil
))
1360 (pop-to-buffer (custom-get-fresh-buffer name
))
1361 (custom-buffer-create-internal options description
)))
1363 (defcustom custom-reset-button-menu nil
1364 "If non-nil, only show a single reset button in customize buffers.
1365 This button will have a menu with all three reset operations."
1367 :group
'custom-buffer
)
1369 (defcustom custom-buffer-verbose-help t
1370 "If non-nil, include explanatory text in the customization buffer."
1372 :group
'custom-buffer
)
1374 (defun Custom-buffer-done (&rest ignore
)
1375 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1377 (quit-window custom-buffer-done-kill
))
1379 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1380 '(("unspecified" . unspecified
))))
1381 "If non-nil, indicate active buttons in a `raised-button' style.
1382 Otherwise use brackets."
1385 :group
'custom-buffer
)
1387 (defun custom-buffer-create-internal (options &optional description
)
1389 (if custom-buffer-verbose-help
1391 (widget-insert "This is a customization buffer")
1393 (widget-insert description
))
1394 (widget-insert (format ".
1395 %s show active fields; type RET or click mouse-1
1396 on an active field to invoke its action. Editing an option value
1397 changes only the text in the buffer. Invoke the State button to set or
1398 save the option value. Saving an option normally edits your init file.
1400 (if custom-raised-buttons
1402 "Square brackets")))
1403 (widget-create 'info-link
1405 "(emacs)Saving Customizations")
1407 " for information on how to save in a different file.
1409 (widget-create 'info-link
1411 :help-echo
"Read the online help."
1412 "(emacs)Easy Customization")
1413 (widget-insert " for general information.\n\n")
1414 (widget-insert "Operate on everything in this buffer:\n "))
1415 (widget-insert " "))
1416 (widget-create 'push-button
1417 :tag
"Set for Current Session"
1419 Make your editing in this buffer take effect for this session."
1420 :action
(lambda (widget &optional event
)
1423 (widget-create 'push-button
1424 :tag
"Save for Future Sessions"
1426 Make your editing in this buffer take effect for future Emacs sessions.
1427 This updates your Emacs initialization file or creates a new one."
1428 :action
(lambda (widget &optional event
)
1430 (if custom-reset-button-menu
1433 (widget-create 'push-button
1435 :help-echo
"Show a menu with reset operations."
1436 :mouse-down-action
(lambda (&rest junk
) t
)
1437 :action
(lambda (widget &optional event
)
1438 (custom-reset event
))))
1439 (widget-insert "\n ")
1440 (widget-create 'push-button
1443 Reset all edited text in this buffer to reflect current values."
1444 :action
'Custom-reset-current
)
1446 (widget-create 'push-button
1447 :tag
"Reset to Saved"
1449 Reset all values in this buffer to their saved settings."
1450 :action
'Custom-reset-saved
)
1452 (widget-create 'push-button
1453 :tag
"Erase Customization"
1455 Un-customize all values in this buffer. They get their standard settings."
1456 :action
'Custom-reset-standard
))
1457 (if (not custom-buffer-verbose-help
)
1460 (widget-create 'info-link
1462 :help-echo
"Read the online help."
1463 "(emacs)Easy Customization")))
1465 (widget-create 'push-button
1468 (lambda (&rest ignore
)
1469 (if custom-buffer-done-kill
1471 "Bury this buffer"))
1472 :action
#'Custom-buffer-done
)
1473 (widget-insert "\n\n")
1474 (message "Creating customization items...")
1475 (buffer-disable-undo)
1476 (setq custom-options
1477 (if (= (length options
) 1)
1478 (mapcar (lambda (entry)
1479 (widget-create (nth 1 entry
)
1480 :documentation-shown t
1481 :custom-state
'unknown
1482 :tag
(custom-unlispify-tag-name
1484 :value
(nth 0 entry
)))
1487 (length (length options
)))
1488 (mapcar (lambda (entry)
1490 (message "Creating customization items ...%2d%%"
1491 (/ (* 100.0 count
) length
))
1492 (widget-create (nth 1 entry
)
1493 :tag
(custom-unlispify-tag-name
1495 :value
(nth 0 entry
))
1496 (setq count
(1+ count
))
1497 (unless (eq (preceding-char) ?
\n)
1498 (widget-insert "\n"))
1499 (widget-insert "\n")))
1501 (unless (eq (preceding-char) ?
\n)
1502 (widget-insert "\n"))
1503 (message "Creating customization items ...done")
1504 (message "Resetting customization items...")
1505 (unless (eq custom-buffer-style
'tree
)
1506 (mapc 'custom-magic-reset custom-options
))
1507 (message "Resetting customization items...done")
1508 (message "Creating customization setup...")
1510 (buffer-enable-undo)
1511 (goto-char (point-min))
1512 (message "Creating customization setup...done"))
1514 ;;; The Tree Browser.
1517 (defun customize-browse (&optional group
)
1518 "Create a tree browser for the customize hierarchy."
1521 (setq group
'emacs
))
1522 (let ((name "*Customize Browser*"))
1523 (pop-to-buffer (custom-get-fresh-buffer name
)))
1526 Square brackets show active fields; type RET or click mouse-1
1527 on an active field to invoke its action.
1528 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1529 (if custom-browse-only-groups
1531 Invoke the [Group] button below to edit that item in another window.\n\n")
1532 (widget-insert "Invoke the ")
1533 (widget-create 'item
1536 :tag-glyph
"folder")
1537 (widget-insert ", ")
1538 (widget-create 'item
1542 (widget-insert ", and ")
1543 (widget-create 'item
1546 :tag-glyph
"option")
1547 (widget-insert " buttons below to edit that
1548 item in another window.\n\n"))
1549 (let ((custom-buffer-style 'tree
))
1550 (widget-create 'custom-group
1552 :custom-state
'unknown
1553 :tag
(custom-unlispify-tag-name group
)
1556 (goto-char (point-min)))
1558 (define-widget 'custom-browse-visibility
'item
1559 "Control visibility of items in the customize tree browser."
1561 :action
'custom-browse-visibility-action
)
1563 (defun custom-browse-visibility-action (widget &rest ignore
)
1564 (let ((custom-buffer-style 'tree
))
1565 (custom-toggle-parent widget
)))
1567 (define-widget 'custom-browse-group-tag
'push-button
1568 "Show parent in other window when activated."
1571 :action
'custom-browse-group-tag-action
)
1573 (defun custom-browse-group-tag-action (widget &rest ignore
)
1574 (let ((parent (widget-get widget
:parent
)))
1575 (customize-group-other-window (widget-value parent
))))
1577 (define-widget 'custom-browse-variable-tag
'push-button
1578 "Show parent in other window when activated."
1581 :action
'custom-browse-variable-tag-action
)
1583 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1584 (let ((parent (widget-get widget
:parent
)))
1585 (customize-variable-other-window (widget-value parent
))))
1587 (define-widget 'custom-browse-face-tag
'push-button
1588 "Show parent in other window when activated."
1591 :action
'custom-browse-face-tag-action
)
1593 (defun custom-browse-face-tag-action (widget &rest ignore
)
1594 (let ((parent (widget-get widget
:parent
)))
1595 (customize-face-other-window (widget-value parent
))))
1597 (defconst custom-browse-alist
'((" " "space")
1603 (defun custom-browse-insert-prefix (prefix)
1604 "Insert PREFIX. On XEmacs convert it to line graphics."
1605 ;; Fixme: do graphics.
1606 (if nil
; (string-match "XEmacs" emacs-version)
1609 (while (not (string-equal prefix
""))
1610 (let ((entry (substring prefix
0 3)))
1611 (setq prefix
(substring prefix
3))
1612 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1613 (name (nth 1 (assoc entry custom-browse-alist
))))
1614 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1615 (overlay-put overlay
'start-open t
)
1616 (overlay-put overlay
'end-open t
)))))
1619 ;;; Modification of Basic Widgets.
1621 ;; We add extra properties to the basic widgets needed here. This is
1622 ;; fine, as long as we are careful to stay within out own namespace.
1624 ;; We want simple widgets to be displayed by default, but complex
1625 ;; widgets to be hidden.
1627 (widget-put (get 'item
'widget-type
) :custom-show t
)
1628 (widget-put (get 'editable-field
'widget-type
)
1629 :custom-show
(lambda (widget value
)
1630 (let ((pp (pp-to-string value
)))
1631 (cond ((string-match "\n" pp
)
1636 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1638 ;;; The `custom-manual' Widget.
1640 (define-widget 'custom-manual
'info-link
1641 "Link to the manual entry for this customization option."
1642 :help-echo
"Read the manual entry for this option."
1645 ;;; The `custom-magic' Widget.
1647 (defgroup custom-magic-faces nil
1648 "Faces used by the magic button."
1649 :group
'custom-faces
1650 :group
'custom-buffer
)
1652 (defface custom-invalid
'((((class color
))
1653 (:foreground
"yellow1" :background
"red1"))
1655 (:weight bold
:slant italic
:underline t
)))
1656 "Face used when the customize item is invalid."
1657 :group
'custom-magic-faces
)
1658 ;; backward-compatibility alias
1659 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1661 (defface custom-rogue
'((((class color
))
1662 (:foreground
"pink" :background
"black"))
1665 "Face used when the customize item is not defined for customization."
1666 :group
'custom-magic-faces
)
1667 ;; backward-compatibility alias
1668 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1670 (defface custom-modified
'((((min-colors 88) (class color
))
1671 (:foreground
"white" :background
"blue1"))
1673 (:foreground
"white" :background
"blue"))
1675 (:slant italic
:bold
)))
1676 "Face used when the customize item has been modified."
1677 :group
'custom-magic-faces
)
1678 ;; backward-compatibility alias
1679 (put 'custom-modified-face
'face-alias
'custom-modified
)
1681 (defface custom-set
'((((min-colors 88) (class color
))
1682 (:foreground
"blue1" :background
"white"))
1684 (:foreground
"blue" :background
"white"))
1687 "Face used when the customize item has been set."
1688 :group
'custom-magic-faces
)
1689 ;; backward-compatibility alias
1690 (put 'custom-set-face
'face-alias
'custom-set
)
1692 (defface custom-changed
'((((min-colors 88) (class color
))
1693 (:foreground
"white" :background
"blue1"))
1695 (:foreground
"white" :background
"blue"))
1698 "Face used when the customize item has been changed."
1699 :group
'custom-magic-faces
)
1700 ;; backward-compatibility alias
1701 (put 'custom-changed-face
'face-alias
'custom-changed
)
1703 (defface custom-saved
'((t (:underline t
)))
1704 "Face used when the customize item has been saved."
1705 :group
'custom-magic-faces
)
1706 ;; backward-compatibility alias
1707 (put 'custom-saved-face
'face-alias
'custom-saved
)
1709 (defconst custom-magic-alist
1710 '((nil "#" underline
"\
1711 UNINITIALIZED, you should not see this.")
1712 (unknown "?" italic
"\
1713 UNKNOWN, you should not see this.")
1714 (hidden "-" default
"\
1715 HIDDEN, invoke \"Show\" in the previous line to show." "\
1716 group now hidden, invoke \"Show\", above, to show contents.")
1717 (invalid "x" custom-invalid
"\
1718 INVALID, the displayed value cannot be set.")
1719 (modified "*" custom-modified
"\
1720 EDITED, shown value does not take effect until you set or save it." "\
1721 something in this group has been edited but not set.")
1722 (set "+" custom-set
"\
1723 SET for current session only." "\
1724 something in this group has been set but not saved.")
1725 (changed ":" custom-changed
"\
1726 CHANGED outside Customize; operating on it here may be unreliable." "\
1727 something in this group has been changed outside customize.")
1728 (saved "!" custom-saved
"\
1730 something in this group has been set and saved.")
1731 (rogue "@" custom-rogue
"\
1732 NO CUSTOMIZATION DATA; you should not see this." "\
1733 something in this group is not prepared for customization.")
1734 (standard " " nil
"\
1736 visible group members are all at standard settings."))
1737 "Alist of customize option states.
1738 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1740 STATE is one of the following symbols:
1743 For internal use, should never occur.
1745 For internal use, should never occur.
1747 This item is not being displayed.
1749 This item is modified, but has an invalid form.
1751 This item is modified, and has a valid form.
1753 This item has been set but not saved.
1755 The current value of this item has been changed outside Customize.
1757 This item is marked for saving.
1759 This item has no customization information.
1761 This item is unchanged from the standard setting.
1763 MAGIC is a string used to present that state.
1765 FACE is a face used to present the state.
1767 ITEM-DESC is a string describing the state for options.
1769 GROUP-DESC is a string describing the state for groups. If this is
1770 left out, ITEM-DESC will be used.
1772 The string %c in either description will be replaced with the
1773 category of the item. These are `group'. `option', and `face'.
1775 The list should be sorted most significant first.")
1777 (defcustom custom-magic-show
'long
1778 "If non-nil, show textual description of the state.
1779 If `long', show a full-line description, not just one word."
1780 :type
'(choice (const :tag
"no" nil
)
1782 (other :tag
"short" short
))
1783 :group
'custom-buffer
)
1785 (defcustom custom-magic-show-hidden
'(option face
)
1786 "Control whether the State button is shown for hidden items.
1787 The value should be a list with the custom categories where the State
1788 button should be visible. Possible categories are `group', `option',
1790 :type
'(set (const group
) (const option
) (const face
))
1791 :group
'custom-buffer
)
1793 (defcustom custom-magic-show-button nil
1794 "Show a \"magic\" button indicating the state of each customization option."
1796 :group
'custom-buffer
)
1798 (define-widget 'custom-magic
'default
1799 "Show and manipulate state for a customization option."
1801 :action
'widget-parent-action
1804 :value-create
'custom-magic-value-create
1805 :value-delete
'widget-children-value-delete
)
1807 (defun widget-magic-mouse-down-action (widget &optional event
)
1808 ;; Non-nil unless hidden.
1809 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1813 (defun custom-magic-value-create (widget)
1814 "Create compact status report for WIDGET."
1815 (let* ((parent (widget-get widget
:parent
))
1816 (state (widget-get parent
:custom-state
))
1817 (hidden (eq state
'hidden
))
1818 (entry (assq state custom-magic-alist
))
1819 (magic (nth 1 entry
))
1820 (face (nth 2 entry
))
1821 (category (widget-get parent
:custom-category
))
1822 (text (or (and (eq category
'group
)
1825 (form (widget-get parent
:custom-form
))
1827 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1828 (setq text
(concat (match-string 1 text
)
1829 (symbol-name category
)
1830 (match-string 2 text
))))
1831 (when (and custom-magic-show
1833 (memq category custom-magic-show-hidden
)))
1835 (when (and (eq category
'group
)
1836 (not (and (eq custom-buffer-style
'links
)
1837 (> (widget-get parent
:custom-level
) 1))))
1838 (insert-char ?\
(* custom-buffer-indent
1839 (widget-get parent
:custom-level
))))
1840 (push (widget-create-child-and-convert
1842 :help-echo
"Change the state of this item."
1843 :format
(if hidden
"%t" "%[%t%]")
1844 :button-prefix
'widget-push-button-prefix
1845 :button-suffix
'widget-push-button-suffix
1846 :mouse-down-action
'widget-magic-mouse-down-action
1850 (let ((start (point)))
1851 (if (eq custom-magic-show
'long
)
1853 (insert (symbol-name state
)))
1854 (cond ((eq form
'lisp
)
1856 ((eq form
'mismatch
)
1857 (insert " (mismatch)")))
1858 (put-text-property start
(point) 'face
'custom-state
))
1860 (when (and (eq category
'group
)
1861 (not (and (eq custom-buffer-style
'links
)
1862 (> (widget-get parent
:custom-level
) 1))))
1863 (insert-char ?\
(* custom-buffer-indent
1864 (widget-get parent
:custom-level
))))
1865 (when custom-magic-show-button
1866 (when custom-magic-show
1867 (let ((indent (widget-get parent
:indent
)))
1869 (insert-char ? indent
))))
1870 (push (widget-create-child-and-convert
1872 :mouse-down-action
'widget-magic-mouse-down-action
1876 :help-echo
"Change the state."
1877 :format
(if hidden
"%t" "%[%t%]")
1878 :tag
(if (memq form
'(lisp mismatch
))
1879 (concat "(" magic
")")
1880 (concat "[" magic
"]")))
1883 (widget-put widget
:children children
)))
1885 (defun custom-magic-reset (widget)
1886 "Redraw the :custom-magic property of WIDGET."
1887 (let ((magic (widget-get widget
:custom-magic
)))
1888 (widget-value-set magic
(widget-value magic
))))
1890 ;;; The `custom' Widget.
1892 (defface custom-button
1893 '((((type x w32 mac
) (class color
)) ; Like default modeline
1894 (:box
(:line-width
2 :style released-button
)
1895 :background
"lightgrey" :foreground
"black"))
1898 "Face used for buttons in customization buffers."
1900 :group
'custom-faces
)
1901 ;; backward-compatibility alias
1902 (put 'custom-button-face
'face-alias
'custom-button
)
1904 (defface custom-button-pressed
1905 '((((type x w32 mac
) (class color
))
1906 (:box
(:line-width
2 :style pressed-button
)
1907 :background
"lightgrey" :foreground
"black"))
1909 (:inverse-video t
)))
1910 "Face used for buttons in customization buffers."
1912 :group
'custom-faces
)
1913 ;; backward-compatibility alias
1914 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
1916 (defface custom-documentation nil
1917 "Face used for documentation strings in customization buffers."
1918 :group
'custom-faces
)
1919 ;; backward-compatibility alias
1920 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
1922 (defface custom-state
'((((class color
)
1924 (:foreground
"lime green"))
1927 (:foreground
"dark green"))
1929 "Face used for State descriptions in the customize buffer."
1930 :group
'custom-faces
)
1931 ;; backward-compatibility alias
1932 (put 'custom-state-face
'face-alias
'custom-state
)
1934 (define-widget 'custom
'default
1935 "Customize a user option."
1937 :convert-widget
'custom-convert-widget
1938 :notify
'custom-notify
1941 :custom-state
'hidden
1942 :documentation-property
'widget-subclass-responsibility
1943 :value-create
'widget-subclass-responsibility
1944 :value-delete
'widget-children-value-delete
1945 :value-get
'widget-value-value-get
1946 :validate
'widget-children-validate
1947 :match
(lambda (widget value
) (symbolp value
)))
1949 (defun custom-convert-widget (widget)
1950 "Initialize :value and :tag from :args in WIDGET."
1951 (let ((args (widget-get widget
:args
)))
1953 (widget-put widget
:value
(widget-apply widget
1954 :value-to-internal
(car args
)))
1955 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1956 (widget-put widget
:args nil
)))
1959 (defun custom-notify (widget &rest args
)
1960 "Keep track of changes."
1961 (let ((state (widget-get widget
:custom-state
)))
1962 (unless (eq state
'modified
)
1963 (unless (memq state
'(nil unknown hidden
))
1964 (widget-put widget
:custom-state
'modified
))
1965 (custom-magic-reset widget
)
1966 (apply 'widget-default-notify widget args
))))
1968 (defun custom-redraw (widget)
1969 "Redraw WIDGET with current settings."
1970 (let ((line (count-lines (point-min) (point)))
1971 (column (current-column))
1973 (from (marker-position (widget-get widget
:from
)))
1974 (to (marker-position (widget-get widget
:to
))))
1976 (widget-value-set widget
(widget-value widget
))
1977 (custom-redraw-magic widget
))
1978 (when (and (>= pos from
) (<= pos to
))
1983 (goto-line (1+ line
)))
1984 (move-to-column column
))
1987 (defun custom-redraw-magic (widget)
1988 "Redraw WIDGET state with current settings."
1990 (let ((magic (widget-get widget
:custom-magic
)))
1992 (widget-value-set magic
(widget-value magic
))
1993 (when (setq widget
(widget-get widget
:group
))
1994 (custom-group-state-update widget
)))
1996 (setq widget nil
)))))
1999 (defun custom-show (widget value
)
2000 "Non-nil if WIDGET should be shown with VALUE by default."
2001 (let ((show (widget-get widget
:custom-show
)))
2007 (funcall show widget value
)))))
2009 (defun custom-load-widget (widget)
2010 "Load all dependencies for WIDGET."
2011 (custom-load-symbol (widget-value widget
)))
2013 (defun custom-unloaded-symbol-p (symbol)
2014 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2016 (loads (get symbol
'custom-loads
))
2019 (setq load
(car loads
)
2021 (cond ((symbolp load
)
2022 (unless (featurep load
)
2024 ((assoc load load-history
))
2025 ((assoc (locate-library load
) load-history
)
2031 (defun custom-unloaded-widget-p (widget)
2032 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2033 (custom-unloaded-symbol-p (widget-value widget
)))
2035 (defun custom-toggle-hide (widget)
2036 "Toggle visibility of WIDGET."
2037 (custom-load-widget widget
)
2038 (let ((state (widget-get widget
:custom-state
)))
2039 (cond ((memq state
'(invalid modified
))
2040 (error "There are unset changes"))
2042 (widget-put widget
:custom-state
'unknown
))
2044 (widget-put widget
:documentation-shown nil
)
2045 (widget-put widget
:custom-state
'hidden
)))
2046 (custom-redraw widget
)
2049 (defun custom-toggle-parent (widget &rest ignore
)
2050 "Toggle visibility of parent of WIDGET."
2051 (custom-toggle-hide (widget-get widget
:parent
)))
2053 (defun custom-add-see-also (widget &optional prefix
)
2054 "Add `See also ...' to WIDGET if there are any links.
2055 Insert PREFIX first if non-nil."
2056 (let* ((symbol (widget-get widget
:value
))
2057 (links (get symbol
'custom-links
))
2058 (many (> (length links
) 2))
2059 (buttons (widget-get widget
:buttons
))
2060 (indent (widget-get widget
:indent
)))
2063 (insert-char ?\ indent
))
2066 (insert "See also ")
2068 (push (widget-create-child-and-convert widget
(car links
))
2070 (setq links
(cdr links
))
2079 (widget-put widget
:buttons buttons
))))
2081 (defun custom-add-parent-links (widget &optional initial-string
)
2082 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2083 The value if non-nil if any parents were found.
2084 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2085 (let ((name (widget-value widget
))
2086 (type (widget-type widget
))
2087 (buttons (widget-get widget
:buttons
))
2090 (insert (or initial-string
"Parent groups:"))
2091 (mapatoms (lambda (symbol)
2092 (let ((entry (assq name
(get symbol
'custom-group
))))
2093 (when (eq (nth 1 entry
) type
)
2095 (push (widget-create-child-and-convert
2096 widget
'custom-group-link
2097 :tag
(custom-unlispify-tag-name symbol
)
2100 (setq parents
(cons symbol parents
))))))
2101 (and (null (get name
'custom-links
)) ;No links of its own.
2102 (= (length parents
) 1) ;A single parent.
2103 (let* ((links (get (car parents
) 'custom-links
))
2104 (many (> (length links
) 2)))
2106 (insert "\nParent documentation: ")
2108 (push (widget-create-child-and-convert widget
(car links
))
2110 (setq links
(cdr links
))
2121 (delete-region start
(point)))
2122 (widget-put widget
:buttons buttons
)
2125 ;;; The `custom-comment' Widget.
2127 ;; like the editable field
2128 (defface custom-comment
'((((class grayscale color
)
2130 (:background
"gray85"))
2131 (((class grayscale color
)
2133 (:background
"dim gray"))
2136 "Face used for comments on variables or faces"
2138 :group
'custom-faces
)
2139 ;; backward-compatibility alias
2140 (put 'custom-comment-face
'face-alias
'custom-comment
)
2142 ;; like font-lock-comment-face
2143 (defface custom-comment-tag
2144 '((((class color
) (background dark
)) (:foreground
"gray80"))
2145 (((class color
) (background light
)) (:foreground
"blue4"))
2146 (((class grayscale
) (background light
))
2147 (:foreground
"DimGray" :weight bold
:slant italic
))
2148 (((class grayscale
) (background dark
))
2149 (:foreground
"LightGray" :weight bold
:slant italic
))
2151 "Face used for variables or faces comment tags"
2152 :group
'custom-faces
)
2153 ;; backward-compatibility alias
2154 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2156 (define-widget 'custom-comment
'string
2159 :help-echo
"Edit a comment here."
2160 :sample-face
'custom-comment-tag-face
2161 :value-face
'custom-comment-face
2163 :create
'custom-comment-create
)
2165 (defun custom-comment-create (widget)
2166 (let* ((null-comment (equal "" (widget-value widget
))))
2167 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2169 (widget-default-create widget
)
2170 ;; `widget-default-delete' expects markers in these slots --
2171 ;; maybe it shouldn't.
2172 (widget-put widget
:from
(point-marker))
2173 (widget-put widget
:to
(point-marker)))))
2175 (defun custom-comment-hide (widget)
2176 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2178 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2179 ;; the global custom one
2180 (defun custom-comment-show (widget)
2181 (widget-put widget
:comment-shown t
)
2182 (custom-redraw widget
)
2185 (defun custom-comment-invisible-p (widget)
2186 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2188 (not (widget-get widget
:comment-shown
)))))
2190 ;;; The `custom-variable' Widget.
2192 ;; When this was underlined blue, users confused it with a
2193 ;; Mosaic-style hyperlink...
2194 (defface custom-variable-tag
2197 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2198 (((min-colors 88) (class color
)
2200 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2203 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2205 "Face used for unpushable variable tags."
2206 :group
'custom-faces
)
2207 ;; backward-compatibility alias
2208 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2210 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2211 "Face used for pushable variable tags."
2212 :group
'custom-faces
)
2213 ;; backward-compatibility alias
2214 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2216 (defcustom custom-variable-default-form
'edit
2217 "Default form of displaying variable values."
2218 :type
'(choice (const edit
)
2220 :group
'custom-buffer
2223 (defun custom-variable-documentation (variable)
2224 "Return documentation of VARIABLE for use in Custom buffer.
2225 Normally just return the docstring. But if VARIABLE automatically
2226 becomes buffer local when set, append a message to that effect."
2227 (if (and (local-variable-if-set-p variable
)
2228 (or (not (local-variable-p variable
))
2230 (local-variable-if-set-p variable
))))
2231 (concat (documentation-property variable
'variable-documentation
)
2233 This variable automatically becomes buffer-local when set outside Custom.
2234 However, setting it through Custom sets the default value.")
2235 (documentation-property variable
'variable-documentation
)))
2237 (define-widget 'custom-variable
'custom
2238 "Customize variable."
2240 :help-echo
"Set or reset this variable."
2241 :documentation-property
#'custom-variable-documentation
2242 :custom-category
'option
2244 :custom-menu
'custom-variable-menu-create
2245 :custom-form nil
; defaults to value of `custom-variable-default-form'
2246 :value-create
'custom-variable-value-create
2247 :action
'custom-variable-action
2248 :custom-set
'custom-variable-set
2249 :custom-save
'custom-variable-save
2250 :custom-reset-current
'custom-redraw
2251 :custom-reset-saved
'custom-variable-reset-saved
2252 :custom-reset-standard
'custom-variable-reset-standard
2253 :custom-standard-value
'custom-variable-standard-value
)
2255 (defun custom-variable-type (symbol)
2256 "Return a widget suitable for editing the value of SYMBOL.
2257 If SYMBOL has a `custom-type' property, use that.
2258 Otherwise, look up symbol in `custom-guess-type-alist'."
2259 (let* ((type (or (get symbol
'custom-type
)
2260 (and (not (get symbol
'standard-value
))
2261 (custom-guess-type symbol
))
2263 (options (get symbol
'custom-options
))
2264 (tmp (if (listp type
)
2265 (copy-sequence type
)
2268 (widget-put tmp
:options options
))
2271 (defun custom-variable-value-create (widget)
2272 "Here is where you edit the variable's value."
2273 (custom-load-widget widget
)
2274 (unless (widget-get widget
:custom-form
)
2275 (widget-put widget
:custom-form custom-variable-default-form
))
2276 (let* ((buttons (widget-get widget
:buttons
))
2277 (children (widget-get widget
:children
))
2278 (form (widget-get widget
:custom-form
))
2279 (state (widget-get widget
:custom-state
))
2280 (symbol (widget-get widget
:value
))
2281 (tag (widget-get widget
:tag
))
2282 (type (custom-variable-type symbol
))
2283 (conv (widget-convert type
))
2284 (get (or (get symbol
'custom-get
) 'default-value
))
2285 (prefix (widget-get widget
:custom-prefix
))
2286 (last (widget-get widget
:custom-last
))
2287 (value (if (default-boundp symbol
)
2288 (funcall get symbol
)
2289 (widget-get conv
:value
))))
2290 ;; If the widget is new, the child determines whether it is hidden.
2292 ((custom-show type value
)
2293 (setq state
'unknown
))
2295 (setq state
'hidden
)))
2296 ;; If we don't know the state, see if we need to edit it in lisp form.
2297 (when (eq state
'unknown
)
2298 (unless (widget-apply conv
:match value
)
2299 ;; (widget-apply (widget-convert type) :match value)
2300 (setq form
'mismatch
)))
2301 ;; Now we can create the child widget.
2302 (cond ((eq custom-buffer-style
'tree
)
2303 (insert prefix
(if last
" `--- " " |--- "))
2304 (push (widget-create-child-and-convert
2305 widget
'custom-browse-variable-tag
)
2307 (insert " " tag
"\n")
2308 (widget-put widget
:buttons buttons
))
2310 ;; Indicate hidden value.
2311 (push (widget-create-child-and-convert
2314 :sample-face
'custom-variable-tag-face
2318 (push (widget-create-child-and-convert
2320 :help-echo
"Show the value of this option."
2322 :action
'custom-toggle-parent
2325 ((memq form
'(lisp mismatch
))
2326 ;; In lisp mode edit the saved value when possible.
2327 (let* ((value (cond ((get symbol
'saved-value
)
2328 (car (get symbol
'saved-value
)))
2329 ((get symbol
'standard-value
)
2330 (car (get symbol
'standard-value
)))
2331 ((default-boundp symbol
)
2332 (custom-quote (funcall get symbol
)))
2334 (custom-quote (widget-get conv
:value
))))))
2335 (insert (symbol-name symbol
) ": ")
2336 (push (widget-create-child-and-convert
2338 :help-echo
"Hide the value of this option."
2341 :action
'custom-toggle-parent
2345 (push (widget-create-child-and-convert
2347 :button-face
'custom-variable-button-face
2349 :tag
(symbol-name symbol
)
2355 (let* ((format (widget-get type
:format
))
2356 tag-format value-format
)
2357 (unless (string-match ":" format
)
2358 (error "Bad format"))
2359 (setq tag-format
(substring format
0 (match-end 0)))
2360 (setq value-format
(substring format
(match-end 0)))
2361 (push (widget-create-child-and-convert
2364 :action
'custom-tag-action
2365 :help-echo
"Change value of this option."
2366 :mouse-down-action
'custom-tag-mouse-down-action
2367 :button-face
'custom-variable-button-face
2368 :sample-face
'custom-variable-tag-face
2372 (push (widget-create-child-and-convert
2374 :help-echo
"Hide the value of this option."
2377 :action
'custom-toggle-parent
2380 (push (widget-create-child-and-convert
2382 :format value-format
2385 (unless (eq custom-buffer-style
'tree
)
2386 (unless (eq (preceding-char) ?
\n)
2387 (widget-insert "\n"))
2388 ;; Create the magic button.
2389 (let ((magic (widget-create-child-and-convert
2390 widget
'custom-magic nil
)))
2391 (widget-put widget
:custom-magic magic
)
2392 (push magic buttons
))
2393 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2394 ;; before the call to `widget-default-format-handler'. Otherwise, I
2395 ;; loose my current `buttons'. This function shouldn't be called like
2396 ;; this anyway. The doc string widget should be added like the others.
2398 (widget-put widget
:buttons buttons
)
2400 ;; Insert documentation.
2401 (widget-default-format-handler widget ?h
)
2403 ;; The comment field
2404 (unless (eq state
'hidden
)
2405 (let* ((comment (get symbol
'variable-comment
))
2407 (widget-create-child-and-convert
2408 widget
'custom-comment
2410 :value
(or comment
""))))
2411 (widget-put widget
:comment-widget comment-widget
)
2412 ;; Don't push it !!! Custom assumes that the first child is the
2414 (setq children
(append children
(list comment-widget
)))))
2415 ;; Update the rest of the properties properties.
2416 (widget-put widget
:custom-form form
)
2417 (widget-put widget
:children children
)
2418 ;; Now update the state.
2419 (if (eq state
'hidden
)
2420 (widget-put widget
:custom-state state
)
2421 (custom-variable-state-set widget
))
2423 (unless (eq state
'hidden
)
2424 (when (eq (widget-get widget
:custom-level
) 1)
2425 (custom-add-parent-links widget
))
2426 (custom-add-see-also widget
)))))
2428 (defun custom-tag-action (widget &rest args
)
2429 "Pass :action to first child of WIDGET's parent."
2430 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2433 (defun custom-tag-mouse-down-action (widget &rest args
)
2434 "Pass :mouse-down-action to first child of WIDGET's parent."
2435 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2436 :mouse-down-action args
))
2438 (defun custom-variable-state-set (widget)
2439 "Set the state of WIDGET."
2440 (let* ((symbol (widget-value widget
))
2441 (get (or (get symbol
'custom-get
) 'default-value
))
2442 (value (if (default-boundp symbol
)
2443 (funcall get symbol
)
2444 (widget-get widget
:value
)))
2445 (comment (get symbol
'variable-comment
))
2448 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2450 (get symbol
'customized-variable-comment
))
2452 (if (condition-case nil
2453 (and (equal value
(eval (car tmp
)))
2454 (equal comment temp
))
2458 ((progn (setq tmp
(get symbol
'saved-value
))
2459 (setq temp
(get symbol
'saved-variable-comment
))
2461 (if (condition-case nil
2462 (and (equal value
(eval (car tmp
)))
2463 (equal comment temp
))
2467 ((setq tmp
(get symbol
'standard-value
))
2468 (if (condition-case nil
2469 (and (equal value
(eval (car tmp
)))
2470 (equal comment nil
))
2475 (widget-put widget
:custom-state state
)))
2477 (defun custom-variable-standard-value (widget)
2478 (get (widget-value widget
) 'standard-value
))
2480 (defvar custom-variable-menu
2481 '(("Set for Current Session" custom-variable-set
2483 (eq (widget-get widget
:custom-state
) 'modified
)))
2484 ("Save for Future Sessions" custom-variable-save
2486 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2487 ("Reset to Current" custom-redraw
2489 (and (default-boundp (widget-value widget
))
2490 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2491 ("Reset to Saved" custom-variable-reset-saved
2493 (and (or (get (widget-value widget
) 'saved-value
)
2494 (get (widget-value widget
) 'saved-variable-comment
))
2495 (memq (widget-get widget
:custom-state
)
2496 '(modified set changed rogue
)))))
2497 ("Erase Customization" custom-variable-reset-standard
2499 (and (get (widget-value widget
) 'standard-value
)
2500 (memq (widget-get widget
:custom-state
)
2501 '(modified set changed saved rogue
)))))
2502 ("Use Backup Value" custom-variable-reset-backup
2504 (get (widget-value widget
) 'backup-value
)))
2505 ("---" ignore ignore
)
2506 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2507 ("---" ignore ignore
)
2508 ("Don't show as Lisp expression" custom-variable-edit
2510 (eq (widget-get widget
:custom-form
) 'lisp
)))
2511 ("Show initial Lisp expression" custom-variable-edit-lisp
2513 (eq (widget-get widget
:custom-form
) 'edit
))))
2514 "Alist of actions for the `custom-variable' widget.
2515 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2516 the menu entry, ACTION is the function to call on the widget when the
2517 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2518 widget as an argument, and returns non-nil if ACTION is valid on that
2519 widget. If FILTER is nil, ACTION is always valid.")
2521 (defun custom-variable-action (widget &optional event
)
2522 "Show the menu for `custom-variable' WIDGET.
2523 Optional EVENT is the location for the menu."
2524 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2525 (custom-toggle-hide widget
)
2526 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2527 (custom-variable-state-set widget
))
2528 (custom-redraw-magic widget
)
2529 (let* ((completion-ignore-case t
)
2530 (answer (widget-choose (concat "Operation on "
2531 (custom-unlispify-tag-name
2532 (widget-get widget
:value
)))
2533 (custom-menu-filter custom-variable-menu
2537 (funcall answer widget
)))))
2539 (defun custom-variable-edit (widget)
2540 "Edit value of WIDGET."
2541 (widget-put widget
:custom-state
'unknown
)
2542 (widget-put widget
:custom-form
'edit
)
2543 (custom-redraw widget
))
2545 (defun custom-variable-edit-lisp (widget)
2546 "Edit the Lisp representation of the value of WIDGET."
2547 (widget-put widget
:custom-state
'unknown
)
2548 (widget-put widget
:custom-form
'lisp
)
2549 (custom-redraw widget
))
2551 (defun custom-variable-set (widget)
2552 "Set the current value for the variable being edited by WIDGET."
2553 (let* ((form (widget-get widget
:custom-form
))
2554 (state (widget-get widget
:custom-state
))
2555 (child (car (widget-get widget
:children
)))
2556 (symbol (widget-value widget
))
2557 (set (or (get symbol
'custom-set
) 'set-default
))
2558 (comment-widget (widget-get widget
:comment-widget
))
2559 (comment (widget-value comment-widget
))
2561 (cond ((eq state
'hidden
)
2562 (error "Cannot set hidden variable"))
2563 ((setq val
(widget-apply child
:validate
))
2564 (goto-char (widget-get val
:from
))
2565 (error "%s" (widget-get val
:error
)))
2566 ((memq form
'(lisp mismatch
))
2567 (when (equal comment
"")
2569 ;; Make the comment invisible by hand if it's empty
2570 (custom-comment-hide comment-widget
))
2571 (custom-variable-backup-value widget
)
2572 (funcall set symbol
(eval (setq val
(widget-value child
))))
2573 (put symbol
'customized-value
(list val
))
2574 (put symbol
'variable-comment comment
)
2575 (put symbol
'customized-variable-comment comment
))
2577 (when (equal comment
"")
2579 ;; Make the comment invisible by hand if it's empty
2580 (custom-comment-hide comment-widget
))
2581 (custom-variable-backup-value widget
)
2582 (funcall set symbol
(setq val
(widget-value child
)))
2583 (put symbol
'customized-value
(list (custom-quote val
)))
2584 (put symbol
'variable-comment comment
)
2585 (put symbol
'customized-variable-comment comment
)))
2586 (custom-variable-state-set widget
)
2587 (custom-redraw-magic widget
)))
2589 (defun custom-variable-save (widget)
2590 "Set and save the value for the variable being edited by WIDGET."
2591 (let* ((form (widget-get widget
:custom-form
))
2592 (state (widget-get widget
:custom-state
))
2593 (child (car (widget-get widget
:children
)))
2594 (symbol (widget-value widget
))
2595 (set (or (get symbol
'custom-set
) 'set-default
))
2596 (comment-widget (widget-get widget
:comment-widget
))
2597 (comment (widget-value comment-widget
))
2599 (cond ((eq state
'hidden
)
2600 (error "Cannot set hidden variable"))
2601 ((setq val
(widget-apply child
:validate
))
2602 (goto-char (widget-get val
:from
))
2603 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2604 ((memq form
'(lisp mismatch
))
2605 (when (equal comment
"")
2607 ;; Make the comment invisible by hand if it's empty
2608 (custom-comment-hide comment-widget
))
2609 (put symbol
'saved-value
(list (widget-value child
)))
2610 (custom-push-theme 'theme-value symbol
'user
2611 'set
(list (widget-value child
)))
2612 (funcall set symbol
(eval (widget-value child
)))
2613 (put symbol
'variable-comment comment
)
2614 (put symbol
'saved-variable-comment comment
))
2616 (when (equal comment
"")
2618 ;; Make the comment invisible by hand if it's empty
2619 (custom-comment-hide comment-widget
))
2620 (put symbol
'saved-value
2621 (list (custom-quote (widget-value child
))))
2622 (custom-push-theme 'theme-value symbol
'user
2623 'set
(list (custom-quote (widget-value
2625 (funcall set symbol
(widget-value child
))
2626 (put symbol
'variable-comment comment
)
2627 (put symbol
'saved-variable-comment comment
)))
2628 (put symbol
'customized-value nil
)
2629 (put symbol
'customized-variable-comment nil
)
2631 (custom-variable-state-set widget
)
2632 (custom-redraw-magic widget
)))
2634 (defun custom-variable-reset-saved (widget)
2635 "Restore the saved value for the variable being edited by WIDGET.
2636 The value that was current before this operation
2637 becomes the backup value, so you can get it again."
2638 (let* ((symbol (widget-value widget
))
2639 (set (or (get symbol
'custom-set
) 'set-default
))
2640 (value (get symbol
'saved-value
))
2641 (comment (get symbol
'saved-variable-comment
)))
2642 (cond ((or value comment
)
2643 (put symbol
'variable-comment comment
)
2644 (custom-variable-backup-value widget
)
2646 (funcall set symbol
(eval (car value
)))
2649 (error "No saved value for %s" symbol
)))
2650 (put symbol
'customized-value nil
)
2651 (put symbol
'customized-variable-comment nil
)
2652 (widget-put widget
:custom-state
'unknown
)
2653 ;; This call will possibly make the comment invisible
2654 (custom-redraw widget
)))
2656 (defun custom-variable-reset-standard (widget)
2657 "Restore the standard setting for the variable being edited by WIDGET.
2658 This operation eliminates any saved setting for the variable,
2659 restoring it to the state of a variable that has never been customized.
2660 The value that was current before this operation
2661 becomes the backup value, so you can get it again."
2662 (let* ((symbol (widget-value widget
))
2663 (set (or (get symbol
'custom-set
) 'set-default
)))
2664 (if (get symbol
'standard-value
)
2666 (custom-variable-backup-value widget
)
2667 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2668 (error "No standard setting known for %S" symbol
))
2669 (put symbol
'variable-comment nil
)
2670 (put symbol
'customized-value nil
)
2671 (put symbol
'customized-variable-comment nil
)
2672 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2673 (put symbol
'saved-value nil
)
2674 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2675 ;; As a special optimizations we do not (explictly)
2676 ;; save resets to standard when no theme set the value.
2677 (if (null (cdr (get symbol
'theme-value
)))
2678 (put symbol
'theme-value nil
))
2679 (put symbol
'saved-variable-comment nil
)
2681 (widget-put widget
:custom-state
'unknown
)
2682 ;; This call will possibly make the comment invisible
2683 (custom-redraw widget
)))
2685 (defun custom-variable-backup-value (widget)
2686 "Back up the current value for WIDGET's variable.
2687 The backup value is kept in the car of the `backup-value' property."
2688 (let* ((symbol (widget-value widget
))
2689 (get (or (get symbol
'custom-get
) 'default-value
))
2690 (type (custom-variable-type symbol
))
2691 (conv (widget-convert type
))
2692 (value (if (default-boundp symbol
)
2693 (funcall get symbol
)
2694 (widget-get conv
:value
))))
2695 (put symbol
'backup-value
(list value
))))
2697 (defun custom-variable-reset-backup (widget)
2698 "Restore the backup value for the variable being edited by WIDGET.
2699 The value that was current before this operation
2700 becomes the backup value, so you can use this operation repeatedly
2701 to switch between two values."
2702 (let* ((symbol (widget-value widget
))
2703 (set (or (get symbol
'custom-set
) 'set-default
))
2704 (value (get symbol
'backup-value
))
2705 (comment-widget (widget-get widget
:comment-widget
))
2706 (comment (widget-value comment-widget
)))
2709 (custom-variable-backup-value widget
)
2711 (funcall set symbol
(car value
))
2713 (error "No backup value for %s" symbol
))
2714 (put symbol
'customized-value
(list (car value
)))
2715 (put symbol
'variable-comment comment
)
2716 (put symbol
'customized-variable-comment comment
)
2717 (custom-variable-state-set widget
)
2718 ;; This call will possibly make the comment invisible
2719 (custom-redraw widget
)))
2721 ;;; The `custom-face-edit' Widget.
2723 (define-widget 'custom-face-edit
'checklist
2724 "Edit face attributes."
2728 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2729 :value-to-internal
'custom-face-edit-fix-value
2730 :match
(lambda (widget value
)
2731 (widget-checklist-match widget
2732 (custom-face-edit-fix-value widget value
)))
2733 :convert-widget
'custom-face-edit-convert-widget
2734 :args
(mapcar (lambda (att)
2737 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2738 (list 'const
:format
"" :value
(nth 0 att
))
2740 custom-face-attributes
))
2742 (defun custom-face-edit-fix-value (widget value
)
2743 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2744 Also change :reverse-video to :inverse-video."
2748 (let ((key (car value
))
2749 (val (car (cdr value
))))
2750 (cond ((eq key
:italic
)
2751 (push :slant result
)
2752 (push (if val
'italic
'normal
) result
))
2754 (push :weight result
)
2755 (push (if val
'bold
'normal
) result
))
2756 ((eq key
:reverse-video
)
2757 (push :inverse-video result
)
2761 (push val result
))))
2762 (setq value
(cdr (cdr value
))))
2763 (setq result
(nreverse result
))
2767 (defun custom-face-edit-convert-widget (widget)
2768 "Convert :args as widget types in WIDGET."
2771 :args
(mapcar (lambda (arg)
2773 :deactivate
'custom-face-edit-deactivate
2774 :activate
'custom-face-edit-activate
2775 :delete
'custom-face-edit-delete
))
2776 (widget-get widget
:args
)))
2779 (defun custom-face-edit-deactivate (widget)
2780 "Make face widget WIDGET inactive for user modifications."
2781 (unless (widget-get widget
:inactive
)
2782 (let ((tag (custom-face-edit-attribute-tag widget
))
2783 (from (copy-marker (widget-get widget
:from
)))
2784 (value (widget-value widget
))
2785 (inhibit-read-only t
)
2786 (inhibit-modification-hooks t
))
2789 (widget-default-delete widget
)
2790 (insert tag
": *\n")
2791 (widget-put widget
:inactive
2792 (cons value
(cons from
(- (point) from
))))))))
2794 (defun custom-face-edit-activate (widget)
2795 "Make face widget WIDGET inactive for user modifications."
2796 (let ((inactive (widget-get widget
:inactive
))
2797 (inhibit-read-only t
)
2798 (inhibit-modification-hooks t
))
2799 (when (consp inactive
)
2801 (goto-char (car (cdr inactive
)))
2802 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2803 (widget-put widget
:inactive nil
)
2804 (widget-apply widget
:create
)
2805 (widget-value-set widget
(car inactive
))
2808 (defun custom-face-edit-delete (widget)
2809 "Remove WIDGET from the buffer."
2810 (let ((inactive (widget-get widget
:inactive
))
2811 (inhibit-read-only t
)
2812 (inhibit-modification-hooks t
))
2814 ;; Widget is alive, we don't have to do anything special
2815 (widget-default-delete widget
)
2816 ;; WIDGET is already deleted because we did so to inactivate it;
2817 ;; now just get rid of the label we put in its place.
2818 (delete-region (car (cdr inactive
))
2819 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2820 (widget-put widget
:inactive nil
))))
2823 (defun custom-face-edit-attribute-tag (widget)
2824 "Returns the first :tag property in WIDGET or one of its children."
2825 (let ((tag (widget-get widget
:tag
)))
2826 (or (and (not (equal tag
"")) tag
)
2827 (let ((children (widget-get widget
:children
)))
2828 (while (and (null tag
) children
)
2829 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2832 ;;; The `custom-display' Widget.
2834 (define-widget 'custom-display
'menu-choice
2835 "Select a display type."
2838 :help-echo
"Specify frames where the face attributes should be used."
2839 :args
'((const :tag
"all" t
)
2840 (const :tag
"defaults" default
)
2844 :args
((group :sibling-args
(:help-echo
"\
2845 Only match the specified window systems.")
2846 (const :format
"Type: "
2848 (checklist :inline t
2851 :sibling-args
(:help-echo
"\
2852 The X11 Window System.")
2854 (const :format
"PM "
2855 :sibling-args
(:help-echo
"\
2856 OS/2 Presentation Manager.")
2858 (const :format
"W32 "
2859 :sibling-args
(:help-echo
"\
2862 (const :format
"MAC "
2863 :sibling-args
(:help-echo
"\
2866 (const :format
"DOS "
2867 :sibling-args
(:help-echo
"\
2870 (const :format
"TTY%n"
2871 :sibling-args
(:help-echo
"\
2872 Plain text terminals.")
2874 (group :sibling-args
(:help-echo
"\
2875 Only match the frames with the specified color support.")
2876 (const :format
"Class: "
2878 (checklist :inline t
2880 (const :format
"Color "
2881 :sibling-args
(:help-echo
"\
2882 Match color frames.")
2884 (const :format
"Grayscale "
2885 :sibling-args
(:help-echo
"\
2886 Match grayscale frames.")
2888 (const :format
"Monochrome%n"
2889 :sibling-args
(:help-echo
"\
2890 Match frames with no color support.")
2892 (group :sibling-args
(:help-echo
"\
2893 The minimum number of colors the frame should support.")
2894 (const :format
"" min-colors
)
2895 (integer :tag
"Minimum number of colors" ))
2896 (group :sibling-args
(:help-echo
"\
2897 Only match frames with the specified intensity.")
2899 Background brightness: "
2901 (checklist :inline t
2903 (const :format
"Light "
2904 :sibling-args
(:help-echo
"\
2905 Match frames with light backgrounds.")
2907 (const :format
"Dark\n"
2908 :sibling-args
(:help-echo
"\
2909 Match frames with dark backgrounds.")
2911 (group :sibling-args
(:help-echo
"\
2912 Only match frames that support the specified face attributes.")
2913 (const :format
"Supports attributes:" supports
)
2914 (custom-face-edit :inline t
:format
"%n%v"))))))
2916 ;;; The `custom-face' Widget.
2918 (defface custom-face-tag
2919 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2920 "Face used for face tags."
2921 :group
'custom-faces
)
2922 ;; backward-compatibility alias
2923 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
2925 (defcustom custom-face-default-form
'selected
2926 "Default form of displaying face definition."
2927 :type
'(choice (const all
)
2930 :group
'custom-buffer
2933 (define-widget 'custom-face
'custom
2935 :sample-face
'custom-face-tag-face
2936 :help-echo
"Set or reset this face."
2937 :documentation-property
#'face-doc-string
2938 :value-create
'custom-face-value-create
2939 :action
'custom-face-action
2940 :custom-category
'face
2941 :custom-form nil
; defaults to value of `custom-face-default-form'
2942 :custom-set
'custom-face-set
2943 :custom-save
'custom-face-save
2944 :custom-reset-current
'custom-redraw
2945 :custom-reset-saved
'custom-face-reset-saved
2946 :custom-reset-standard
'custom-face-reset-standard
2947 :custom-standard-value
'custom-face-standard-value
2948 :custom-menu
'custom-face-menu-create
)
2950 (define-widget 'custom-face-all
'editable-list
2951 "An editable list of display specifications and attributes."
2952 :entry-format
"%i %d %v"
2953 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2954 :append-button-args
'(:help-echo
"Append new display specification here.")
2955 :delete-button-args
'(:help-echo
"Delete this display specification.")
2956 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2958 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2959 "Converted version of the `custom-face-all' widget.")
2961 (define-widget 'custom-display-unselected
'item
2962 "A display specification that doesn't match the selected display."
2963 :match
'custom-display-unselected-match
)
2965 (defun custom-display-unselected-match (widget value
)
2966 "Non-nil if VALUE is an unselected display specification."
2967 (not (face-spec-set-match-display value
(selected-frame))))
2969 (define-widget 'custom-face-selected
'group
2970 "Edit the attributes of the selected display in a face specification."
2971 :args
'((choice :inline t
2972 (group :tag
"With Defaults" :inline t
2973 (group (const :tag
"" default
)
2974 (custom-face-edit :tag
" Default\n Attributes"))
2977 (group custom-display-unselected sexp
))
2978 (group (sexp :format
"")
2979 (custom-face-edit :tag
" Overriding\n Attributes"))
2983 (group :tag
"No Defaults" :inline t
2986 (group custom-display-unselected sexp
))
2987 (group (sexp :format
"")
2988 (custom-face-edit :tag
"\n Attributes"))
2995 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2996 "Converted version of the `custom-face-selected' widget.")
2998 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2999 "Return a canonicalized version of SPEC using.
3000 FILTER-INDEX is the index in the entry for each attribute in
3001 `custom-face-attributes' at which the appropriate filter function can be
3002 found, and DEFAULT-FILTER is the filter to apply for attributes that
3004 (mapcar (lambda (entry)
3005 ;; Filter a single face-spec entry
3006 (let ((tests (car entry
))
3008 ;; Handle both old- and new-style attribute syntax
3009 (if (listp (car (cdr entry
)))
3012 (filtered-attrs nil
))
3013 ;; Filter each face attribute
3014 (while unfiltered-attrs
3015 (let* ((attr (pop unfiltered-attrs
))
3016 (pre-filtered-value (pop unfiltered-attrs
))
3018 (or (nth filter-index
(assq attr custom-face-attributes
))
3022 (funcall filter pre-filtered-value
)
3023 pre-filtered-value
)))
3024 (push filtered-value filtered-attrs
)
3025 (push attr filtered-attrs
)))
3027 (list tests filtered-attrs
)))
3030 (defun custom-pre-filter-face-spec (spec)
3031 "Return SPEC changed as necessary for editing by the face customization widget.
3032 SPEC must be a full face spec."
3033 (custom-filter-face-spec spec
2))
3035 (defun custom-post-filter-face-spec (spec)
3036 "Return the customized SPEC in a form suitable for setting the face."
3037 (custom-filter-face-spec spec
3))
3039 (defun custom-face-value-create (widget)
3040 "Create a list of the display specifications for WIDGET."
3041 (let ((buttons (widget-get widget
:buttons
))
3043 (symbol (widget-get widget
:value
))
3044 (tag (widget-get widget
:tag
))
3045 (state (widget-get widget
:custom-state
))
3047 (is-last (widget-get widget
:custom-last
))
3048 (prefix (widget-get widget
:custom-prefix
)))
3050 (setq tag
(prin1-to-string symbol
)))
3051 (cond ((eq custom-buffer-style
'tree
)
3052 (insert prefix
(if is-last
" `--- " " |--- "))
3053 (push (widget-create-child-and-convert
3054 widget
'custom-browse-face-tag
)
3056 (insert " " tag
"\n")
3057 (widget-put widget
:buttons buttons
))
3061 (widget-specify-sample widget begin
(point))
3062 (if (eq custom-buffer-style
'face
)
3064 (if (string-match "face\\'" tag
)
3066 (insert " face: ")))
3068 (push (widget-create-child-and-convert widget
'item
3075 (push (widget-create-child-and-convert
3077 :help-echo
"Hide or show this face."
3080 :action
'custom-toggle-parent
3081 (not (eq state
'hidden
)))
3085 (let ((magic (widget-create-child-and-convert
3086 widget
'custom-magic nil
)))
3087 (widget-put widget
:custom-magic magic
)
3088 (push magic buttons
))
3090 (widget-put widget
:buttons buttons
)
3091 ;; Insert documentation.
3092 (widget-default-format-handler widget ?h
)
3093 ;; The comment field
3094 (unless (eq state
'hidden
)
3095 (let* ((comment (get symbol
'face-comment
))
3097 (widget-create-child-and-convert
3098 widget
'custom-comment
3100 :value
(or comment
""))))
3101 (widget-put widget
:comment-widget comment-widget
)
3102 (push comment-widget children
)))
3104 (unless (eq state
'hidden
)
3105 (when (eq (widget-get widget
:custom-level
) 1)
3106 (custom-add-parent-links widget
))
3107 (custom-add-see-also widget
))
3109 (unless (eq (preceding-char) ?
\n)
3111 (unless (eq state
'hidden
)
3112 (message "Creating face editor...")
3113 (custom-load-widget widget
)
3114 (unless (widget-get widget
:custom-form
)
3115 (widget-put widget
:custom-form custom-face-default-form
))
3116 (let* ((symbol (widget-value widget
))
3117 (spec (or (get symbol
'customized-face
)
3118 (get symbol
'saved-face
)
3119 (get symbol
'face-defface-spec
)
3120 ;; Attempt to construct it.
3121 (list (list t
(custom-face-attributes-get
3122 symbol
(selected-frame))))))
3123 (form (widget-get widget
:custom-form
))
3124 (indent (widget-get widget
:indent
))
3126 ;; If the user has changed this face in some other way,
3127 ;; edit it as the user has specified it.
3128 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3129 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3130 (setq spec
(custom-pre-filter-face-spec spec
))
3131 (setq edit
(widget-create-child-and-convert
3133 (cond ((and (eq form
'selected
)
3134 (widget-apply custom-face-selected
3136 (when indent
(insert-char ?\ indent
))
3137 'custom-face-selected
)
3138 ((and (not (eq form
'lisp
))
3139 (widget-apply custom-face-all
3143 (when indent
(insert-char ?\ indent
))
3146 (custom-face-state-set widget
)
3147 (push edit children
)
3148 (widget-put widget
:children children
))
3149 (message "Creating face editor...done"))))))
3151 (defvar custom-face-menu
3152 '(("Set for Current Session" custom-face-set
)
3153 ("Save for Future Sessions" custom-face-save-command
)
3154 ("Reset to Saved" custom-face-reset-saved
3156 (or (get (widget-value widget
) 'saved-face
)
3157 (get (widget-value widget
) 'saved-face-comment
))))
3158 ("Erase Customization" custom-face-reset-standard
3160 (get (widget-value widget
) 'face-defface-spec
)))
3161 ("---" ignore ignore
)
3162 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3163 ("---" ignore ignore
)
3164 ("Show all display specs" custom-face-edit-all
3166 (not (eq (widget-get widget
:custom-form
) 'all
))))
3167 ("Just current attributes" custom-face-edit-selected
3169 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3170 ("Show as Lisp expression" custom-face-edit-lisp
3172 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3173 "Alist of actions for the `custom-face' widget.
3174 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3175 the menu entry, ACTION is the function to call on the widget when the
3176 menu is selected, and FILTER is a predicate which takes a `custom-face'
3177 widget as an argument, and returns non-nil if ACTION is valid on that
3178 widget. If FILTER is nil, ACTION is always valid.")
3180 (defun custom-face-edit-selected (widget)
3181 "Edit selected attributes of the value of WIDGET."
3182 (widget-put widget
:custom-state
'unknown
)
3183 (widget-put widget
:custom-form
'selected
)
3184 (custom-redraw widget
))
3186 (defun custom-face-edit-all (widget)
3187 "Edit all attributes of the value of WIDGET."
3188 (widget-put widget
:custom-state
'unknown
)
3189 (widget-put widget
:custom-form
'all
)
3190 (custom-redraw widget
))
3192 (defun custom-face-edit-lisp (widget)
3193 "Edit the Lisp representation of the value of WIDGET."
3194 (widget-put widget
:custom-state
'unknown
)
3195 (widget-put widget
:custom-form
'lisp
)
3196 (custom-redraw widget
))
3198 (defun custom-face-state-set (widget)
3199 "Set the state of WIDGET."
3200 (let* ((symbol (widget-value widget
))
3201 (comment (get symbol
'face-comment
))
3205 (setq tmp
(get symbol
'customized-face
))
3206 (setq temp
(get symbol
'customized-face-comment
))
3208 (if (equal temp comment
)
3212 (setq tmp
(get symbol
'saved-face
))
3213 (setq temp
(get symbol
'saved-face-comment
))
3215 (if (equal temp comment
)
3218 ((get symbol
'face-defface-spec
)
3219 (if (equal comment nil
)
3224 ;; If the user called set-face-attribute to change the default
3225 ;; for new frames, this face is "set outside of Customize".
3226 (if (and (not (eq state
'rogue
))
3227 (get symbol
'face-modified
))
3228 (setq state
'changed
))
3229 (widget-put widget
:custom-state state
)))
3231 (defun custom-face-action (widget &optional event
)
3232 "Show the menu for `custom-face' WIDGET.
3233 Optional EVENT is the location for the menu."
3234 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3235 (custom-toggle-hide widget
)
3236 (let* ((completion-ignore-case t
)
3237 (symbol (widget-get widget
:value
))
3238 (answer (widget-choose (concat "Operation on "
3239 (custom-unlispify-tag-name symbol
))
3240 (custom-menu-filter custom-face-menu
3244 (funcall answer widget
)))))
3246 (defun custom-face-set (widget)
3247 "Make the face attributes in WIDGET take effect."
3248 (let* ((symbol (widget-value widget
))
3249 (child (car (widget-get widget
:children
)))
3250 (value (custom-post-filter-face-spec (widget-value child
)))
3251 (comment-widget (widget-get widget
:comment-widget
))
3252 (comment (widget-value comment-widget
)))
3253 (when (equal comment
"")
3255 ;; Make the comment invisible by hand if it's empty
3256 (custom-comment-hide comment-widget
))
3257 (put symbol
'customized-face value
)
3258 (if (face-spec-choose value
)
3259 (face-spec-set symbol value
)
3260 ;; face-set-spec ignores empty attribute lists, so just give it
3261 ;; something harmless instead.
3262 (face-spec-set symbol
'((t :foreground unspecified
))))
3263 (put symbol
'customized-face-comment comment
)
3264 (put symbol
'face-comment comment
)
3265 (custom-face-state-set widget
)
3266 (custom-redraw-magic widget
)))
3268 (defun custom-face-save-command (widget)
3269 "Save in `.emacs' the face attributes in WIDGET."
3270 (custom-face-save widget
)
3273 (defun custom-face-save (widget)
3274 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3275 (let* ((symbol (widget-value widget
))
3276 (child (car (widget-get widget
:children
)))
3277 (value (custom-post-filter-face-spec (widget-value child
)))
3278 (comment-widget (widget-get widget
:comment-widget
))
3279 (comment (widget-value comment-widget
)))
3280 (when (equal comment
"")
3282 ;; Make the comment invisible by hand if it's empty
3283 (custom-comment-hide comment-widget
))
3284 (if (face-spec-choose value
)
3285 (face-spec-set symbol value
)
3286 ;; face-set-spec ignores empty attribute lists, so just give it
3287 ;; something harmless instead.
3288 (face-spec-set symbol
'((t :foreground unspecified
))))
3289 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3290 (put symbol
'saved-face value
))
3291 (custom-push-theme 'theme-face symbol
'user
'set value
)
3292 (put symbol
'customized-face nil
)
3293 (put symbol
'face-comment comment
)
3294 (put symbol
'customized-face-comment nil
)
3295 (put symbol
'saved-face-comment comment
)
3297 (custom-face-state-set widget
)
3298 (custom-redraw-magic widget
)))
3300 (defun custom-face-reset-saved (widget)
3301 "Restore WIDGET to the face's default attributes."
3302 (let* ((symbol (widget-value widget
))
3303 (child (car (widget-get widget
:children
)))
3304 (value (get symbol
'saved-face
))
3305 (comment (get symbol
'saved-face-comment
))
3306 (comment-widget (widget-get widget
:comment-widget
)))
3307 (unless (or value comment
)
3308 (error "No saved value for this face"))
3309 (put symbol
'customized-face nil
)
3310 (put symbol
'customized-face-comment nil
)
3311 (face-spec-set symbol value
)
3312 (put symbol
'face-comment comment
)
3313 (widget-value-set child value
)
3314 ;; This call manages the comment visibility
3315 (widget-value-set comment-widget
(or comment
""))
3316 (custom-face-state-set widget
)
3317 (custom-redraw-magic widget
)))
3319 (defun custom-face-standard-value (widget)
3320 (get (widget-value widget
) 'face-defface-spec
))
3322 (defun custom-face-reset-standard (widget)
3323 "Restore WIDGET to the face's standard settings.
3324 This operation eliminates any saved setting for the face,
3325 restoring it to the state of a face that has never been customized."
3326 (let* ((symbol (widget-value widget
))
3327 (child (car (widget-get widget
:children
)))
3328 (value (get symbol
'face-defface-spec
))
3329 (comment-widget (widget-get widget
:comment-widget
)))
3331 (error "No standard setting for this face"))
3332 (put symbol
'customized-face nil
)
3333 (put symbol
'customized-face-comment nil
)
3334 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3335 (put symbol
'saved-face nil
)
3336 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3337 ;; Do not explictly save resets to standards without themes.
3338 (if (null (cdr (get symbol
'theme-face
)))
3339 (put symbol
'theme-face nil
))
3340 (put symbol
'saved-face-comment nil
)
3342 (face-spec-set symbol value
)
3343 (put symbol
'face-comment nil
)
3344 (widget-value-set child value
)
3345 ;; This call manages the comment visibility
3346 (widget-value-set comment-widget
"")
3347 (custom-face-state-set widget
)
3348 (custom-redraw-magic widget
)))
3350 ;;; The `face' Widget.
3352 (defvar widget-face-prompt-value-history nil
3353 "History of input to `widget-face-prompt-value'.")
3355 (define-widget 'face
'symbol
3356 "A Lisp face name (with sample)."
3357 :format
"%t: (%{sample%}) %v"
3360 :sample-face-get
'widget-face-sample-face-get
3361 :notify
'widget-face-notify
3362 :match
(lambda (widget value
) (facep value
))
3363 :complete-function
(lambda ()
3365 (lisp-complete-symbol 'facep
))
3366 :prompt-match
'facep
3367 :prompt-history
'widget-face-prompt-value-history
3368 :validate
(lambda (widget)
3369 (unless (facep (widget-value widget
))
3371 :error
(format "Invalid face: %S"
3372 (widget-value widget
)))
3375 (defun widget-face-sample-face-get (widget)
3376 (let ((value (widget-value widget
)))
3381 (defun widget-face-notify (widget child
&optional event
)
3382 "Update the sample, and notify the parent."
3383 (overlay-put (widget-get widget
:sample-overlay
)
3384 'face
(widget-apply widget
:sample-face-get
))
3385 (widget-default-notify widget child event
))
3388 ;;; The `hook' Widget.
3390 (define-widget 'hook
'list
3392 :value-to-internal
(lambda (widget value
)
3393 (if (and value
(symbolp value
))
3396 :match
(lambda (widget value
)
3398 (widget-group-match widget value
)))
3399 ;; Avoid adding undefined functions to the hook, especially for
3400 ;; things like `find-file-hook' or even more basic ones, to avoid
3402 :set
(lambda (symbol value
)
3405 (add-hook symbol elt
))))
3406 :convert-widget
'custom-hook-convert-widget
3409 (defun custom-hook-convert-widget (widget)
3410 ;; Handle `:options'.
3411 (let* ((options (widget-get widget
:options
))
3412 (other `(editable-list :inline t
3413 :entry-format
"%i %d%v"
3414 (function :format
" %v")))
3416 (list `(checklist :inline t
3417 ,@(mapcar (lambda (entry)
3418 `(function-item ,entry
))
3422 (widget-put widget
:args args
)
3425 ;;; The `custom-group-link' Widget.
3427 (define-widget 'custom-group-link
'link
3428 "Show parent in other window when activated."
3429 :help-echo
"Create customization buffer for this group."
3430 :action
'custom-group-link-action
)
3432 (defun custom-group-link-action (widget &rest ignore
)
3433 (customize-group (widget-value widget
)))
3435 ;;; The `custom-group' Widget.
3437 (defcustom custom-group-tag-faces nil
3438 ;; In XEmacs, this ought to play games with font size.
3439 ;; Fixme: make it do so in Emacs.
3440 "Face used for group tags.
3441 The first member is used for level 1 groups, the second for level 2,
3442 and so forth. The remaining group tags are shown with `custom-group-tag'."
3443 :type
'(repeat face
)
3444 :group
'custom-faces
)
3446 (defface custom-group-tag-1
3449 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3450 (((min-colors 88) (class color
)
3452 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3455 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3457 "Face used for group tags."
3458 :group
'custom-faces
)
3459 ;; backward-compatibility alias
3460 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3462 (defface custom-group-tag
3465 (:foreground
"light blue" :weight bold
:height
1.2))
3466 (((min-colors 88) (class color
)
3468 (:foreground
"blue1" :weight bold
:height
1.2))
3471 (:foreground
"blue" :weight bold
:height
1.2))
3473 "Face used for low level group tags."
3474 :group
'custom-faces
)
3475 ;; backward-compatibility alias
3476 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3478 (define-widget 'custom-group
'custom
3481 :sample-face-get
'custom-group-sample-face-get
3482 :documentation-property
'group-documentation
3483 :help-echo
"Set or reset all members of this group."
3484 :value-create
'custom-group-value-create
3485 :action
'custom-group-action
3486 :custom-category
'group
3487 :custom-set
'custom-group-set
3488 :custom-save
'custom-group-save
3489 :custom-reset-current
'custom-group-reset-current
3490 :custom-reset-saved
'custom-group-reset-saved
3491 :custom-reset-standard
'custom-group-reset-standard
3492 :custom-menu
'custom-group-menu-create
)
3494 (defun custom-group-sample-face-get (widget)
3495 ;; Use :sample-face.
3496 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3499 (define-widget 'custom-group-visibility
'visibility
3500 "An indicator and manipulator for hidden group contents."
3501 :create
'custom-group-visibility-create
)
3503 (defun custom-group-visibility-create (widget)
3504 (let ((visible (widget-value widget
)))
3506 (insert "--------")))
3507 (widget-default-create widget
))
3509 (defun custom-group-members (symbol groups-only
)
3510 "Return SYMBOL's custom group members.
3511 If GROUPS-ONLY non-nil, return only those members that are groups."
3512 (if (not groups-only
)
3513 (get symbol
'custom-group
)
3515 (dolist (entry (get symbol
'custom-group
))
3516 (when (eq (nth 1 entry
) 'custom-group
)
3517 (push entry members
)))
3518 (nreverse members
))))
3520 (defun custom-group-value-create (widget)
3521 "Insert a customize group for WIDGET in the current buffer."
3522 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3523 (custom-load-widget widget
))
3524 (let* ((state (widget-get widget
:custom-state
))
3525 (level (widget-get widget
:custom-level
))
3526 ;; (indent (widget-get widget :indent))
3527 (prefix (widget-get widget
:custom-prefix
))
3528 (buttons (widget-get widget
:buttons
))
3529 (tag (widget-get widget
:tag
))
3530 (symbol (widget-value widget
))
3531 (members (custom-group-members symbol
3532 (and (eq custom-buffer-style
'tree
)
3533 custom-browse-only-groups
))))
3534 (cond ((and (eq custom-buffer-style
'tree
)
3536 (or members
(custom-unloaded-widget-p widget
)))
3537 (custom-browse-insert-prefix prefix
)
3538 (push (widget-create-child-and-convert
3539 widget
'custom-browse-visibility
3540 ;; :tag-glyph "plus"
3544 ;; (widget-glyph-insert nil "-- " "horizontal")
3545 (push (widget-create-child-and-convert
3546 widget
'custom-browse-group-tag
)
3548 (insert " " tag
"\n")
3549 (widget-put widget
:buttons buttons
))
3550 ((and (eq custom-buffer-style
'tree
)
3551 (zerop (length members
)))
3552 (custom-browse-insert-prefix prefix
)
3554 ;; (widget-glyph-insert nil "[ ]" "empty")
3555 ;; (widget-glyph-insert nil "-- " "horizontal")
3556 (push (widget-create-child-and-convert
3557 widget
'custom-browse-group-tag
)
3559 (insert " " tag
"\n")
3560 (widget-put widget
:buttons buttons
))
3561 ((eq custom-buffer-style
'tree
)
3562 (custom-browse-insert-prefix prefix
)
3563 (if (zerop (length members
))
3565 (custom-browse-insert-prefix prefix
)
3567 ;; (widget-glyph-insert nil "[ ]" "empty")
3568 ;; (widget-glyph-insert nil "-- " "horizontal")
3569 (push (widget-create-child-and-convert
3570 widget
'custom-browse-group-tag
)
3572 (insert " " tag
"\n")
3573 (widget-put widget
:buttons buttons
))
3574 (push (widget-create-child-and-convert
3575 widget
'custom-browse-visibility
3576 ;; :tag-glyph "minus"
3580 ;; (widget-glyph-insert nil "-\\ " "top")
3581 (push (widget-create-child-and-convert
3582 widget
'custom-browse-group-tag
)
3584 (insert " " tag
"\n")
3585 (widget-put widget
:buttons buttons
)
3586 (message "Creating group...")
3587 (let* ((members (custom-sort-items members
3588 custom-browse-sort-alphabetically
3589 custom-browse-order-groups
))
3590 (prefixes (widget-get widget
:custom-prefixes
))
3591 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3592 (extra-prefix (if (widget-get widget
:custom-last
)
3595 (prefix (concat prefix extra-prefix
))
3598 (setq entry
(car members
)
3599 members
(cdr members
))
3600 (push (widget-create-child-and-convert
3601 widget
(nth 1 entry
)
3603 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3604 :custom-prefixes custom-prefix-list
3605 :custom-level
(1+ level
)
3606 :custom-last
(null members
)
3607 :value
(nth 0 entry
)
3608 :custom-prefix prefix
)
3610 (widget-put widget
:children
(reverse children
)))
3611 (message "Creating group...done")))
3614 ;; Create level indicator.
3615 (unless (eq custom-buffer-style
'links
)
3616 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3619 (let ((begin (point)))
3621 (widget-specify-sample widget begin
(point)))
3623 ;; Create link/visibility indicator.
3624 (if (eq custom-buffer-style
'links
)
3625 (push (widget-create-child-and-convert
3626 widget
'custom-group-link
3630 (push (widget-create-child-and-convert
3631 widget
'custom-group-visibility
3632 :help-echo
"Show members of this group."
3633 :action
'custom-toggle-parent
3634 (not (eq state
'hidden
)))
3637 ;; Create magic button.
3638 (let ((magic (widget-create-child-and-convert
3639 widget
'custom-magic nil
)))
3640 (widget-put widget
:custom-magic magic
)
3641 (push magic buttons
))
3643 (widget-put widget
:buttons buttons
)
3644 ;; Insert documentation.
3645 (if (and (eq custom-buffer-style
'links
) (> level
1))
3646 (widget-put widget
:documentation-indent
0))
3647 (widget-default-format-handler widget ?h
))
3650 ;; Add parent groups references above the group.
3651 (if t
;;; This should test that the buffer
3652 ;;; was made to display a group.
3654 (if (custom-add-parent-links widget
3655 "Go to parent group:")
3657 ;; Create level indicator.
3658 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3661 (let ((start (point)))
3663 (widget-specify-sample widget start
(point)))
3665 ;; Create visibility indicator.
3666 (unless (eq custom-buffer-style
'links
)
3668 (push (widget-create-child-and-convert
3670 :help-echo
"Hide members of this group."
3671 :action
'custom-toggle-parent
3672 (not (eq state
'hidden
)))
3675 ;; Create more dashes.
3676 ;; Use 76 instead of 75 to compensate for the temporary "<"
3677 ;; added by `widget-insert'.
3678 (insert-char ?-
(- 76 (current-column)
3679 (* custom-buffer-indent level
)))
3681 ;; Create magic button.
3682 (let ((magic (widget-create-child-and-convert
3683 widget
'custom-magic
3686 (widget-put widget
:custom-magic magic
)
3687 (push magic buttons
))
3689 (widget-put widget
:buttons buttons
)
3690 ;; Insert documentation.
3691 (widget-default-format-handler widget ?h
)
3693 (if nil
;;; This should test that the buffer
3694 ;;; was not made to display a group.
3696 (insert-char ?\ custom-buffer-indent
)
3697 (custom-add-parent-links widget
)))
3698 (custom-add-see-also widget
3699 (make-string (* custom-buffer-indent level
)
3702 (message "Creating group...")
3703 (let* ((members (custom-sort-items members
3704 custom-buffer-sort-alphabetically
3705 custom-buffer-order-groups
))
3706 (prefixes (widget-get widget
:custom-prefixes
))
3707 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3708 (length (length members
))
3710 (children (mapcar (lambda (entry)
3711 (widget-insert "\n")
3713 Creating group members... %2d%%"
3714 (/ (* 100.0 count
) length
))
3715 (setq count
(1+ count
))
3717 (widget-create-child-and-convert
3718 widget
(nth 1 entry
)
3720 :tag
(custom-unlispify-tag-name
3722 :custom-prefixes custom-prefix-list
3723 :custom-level
(1+ level
)
3724 :value
(nth 0 entry
))
3725 (unless (eq (preceding-char) ?
\n)
3726 (widget-insert "\n"))))
3728 (message "Creating group magic...")
3729 (mapc 'custom-magic-reset children
)
3730 (message "Creating group state...")
3731 (widget-put widget
:children children
)
3732 (custom-group-state-update widget
)
3733 (message "Creating group... done"))
3736 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3737 (insert "\\- " (widget-get widget
:tag
) " group end ")
3738 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3741 (defvar custom-group-menu
3742 '(("Set for Current Session" custom-group-set
3744 (eq (widget-get widget
:custom-state
) 'modified
)))
3745 ("Save for Future Sessions" custom-group-save
3747 (memq (widget-get widget
:custom-state
) '(modified set
))))
3748 ("Reset to Current" custom-group-reset-current
3750 (memq (widget-get widget
:custom-state
) '(modified))))
3751 ("Reset to Saved" custom-group-reset-saved
3753 (memq (widget-get widget
:custom-state
) '(modified set
))))
3754 ("Reset to standard setting" custom-group-reset-standard
3756 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3757 "Alist of actions for the `custom-group' widget.
3758 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3759 the menu entry, ACTION is the function to call on the widget when the
3760 menu is selected, and FILTER is a predicate which takes a `custom-group'
3761 widget as an argument, and returns non-nil if ACTION is valid on that
3762 widget. If FILTER is nil, ACTION is always valid.")
3764 (defun custom-group-action (widget &optional event
)
3765 "Show the menu for `custom-group' WIDGET.
3766 Optional EVENT is the location for the menu."
3767 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3768 (custom-toggle-hide widget
)
3769 (let* ((completion-ignore-case t
)
3770 (answer (widget-choose (concat "Operation on "
3771 (custom-unlispify-tag-name
3772 (widget-get widget
:value
)))
3773 (custom-menu-filter custom-group-menu
3777 (funcall answer widget
)))))
3779 (defun custom-group-set (widget)
3780 "Set changes in all modified group members."
3781 (let ((children (widget-get widget
:children
)))
3782 (mapc (lambda (child)
3783 (when (eq (widget-get child
:custom-state
) 'modified
)
3784 (widget-apply child
:custom-set
)))
3787 (defun custom-group-save (widget)
3788 "Save all modified group members."
3789 (let ((children (widget-get widget
:children
)))
3790 (mapc (lambda (child)
3791 (when (memq (widget-get child
:custom-state
) '(modified set
))
3792 (widget-apply child
:custom-save
)))
3795 (defun custom-group-reset-current (widget)
3796 "Reset all modified group members."
3797 (let ((children (widget-get widget
:children
)))
3798 (mapc (lambda (child)
3799 (when (eq (widget-get child
:custom-state
) 'modified
)
3800 (widget-apply child
:custom-reset-current
)))
3803 (defun custom-group-reset-saved (widget)
3804 "Reset all modified or set group members."
3805 (let ((children (widget-get widget
:children
)))
3806 (mapc (lambda (child)
3807 (when (memq (widget-get child
:custom-state
) '(modified set
))
3808 (widget-apply child
:custom-reset-saved
)))
3811 (defun custom-group-reset-standard (widget)
3812 "Reset all modified, set, or saved group members."
3813 (let ((children (widget-get widget
:children
)))
3814 (mapc (lambda (child)
3815 (when (memq (widget-get child
:custom-state
)
3816 '(modified set saved
))
3817 (widget-apply child
:custom-reset-standard
)))
3820 (defun custom-group-state-update (widget)
3822 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3823 (let* ((children (widget-get widget
:children
))
3824 (states (mapcar (lambda (child)
3825 (widget-get child
:custom-state
))
3827 (magics custom-magic-alist
)
3830 (let ((magic (car (car magics
))))
3831 (if (and (not (eq magic
'hidden
))
3832 (memq magic states
))
3835 (setq magics
(cdr magics
)))))
3836 (widget-put widget
:custom-state found
)))
3837 (custom-magic-reset widget
))
3839 ;;; The `custom-save-all' Function.
3841 (defcustom custom-file nil
3842 "File used for storing customization information.
3843 The default is nil, which means to use your init file
3844 as specified by `user-init-file'. If the value is not nil,
3845 it should be an absolute file name.
3847 You can set this option through Custom, if you carefully read the
3848 last paragraph below. However, usually it is simpler to write
3849 something like the following in your init file:
3851 \(setq custom-file \"~/.emacs-custom.el\")
3854 Note that both lines are necessary: the first line tells Custom to
3855 save all customizations in this file, but does not load it.
3857 When you change this variable outside Custom, look in the
3858 previous custom file \(usually your init file) for the
3859 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3860 and copy them (whichever ones you find) to the new custom file.
3861 This will preserve your existing customizations.
3863 If you save this option using Custom, Custom will write all
3864 currently saved customizations, including the new one for this
3865 option itself, into the file you specify, overwriting any
3866 `custom-set-variables' and `custom-set-faces' forms already
3867 present in that file. It will not delete any customizations from
3868 the old custom file. You should do that manually if that is what you
3869 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3870 in your init file, where CUSTOM-FILE is the actual name of the
3871 file. Otherwise, Emacs will not load the file when it starts up,
3872 and hence will not set `custom-file' to that file either."
3873 :type
'(choice (const :tag
"Your Emacs init file" nil
)
3874 (file :format
"%t:%v%d"
3876 "Please read entire docstring below before setting \
3877 this through Custom.
3878 Click om \"More\" \(or position point there and press RETURN)
3879 if only the first line of the docstring is shown."))
3882 (defun custom-file ()
3883 "Return the file name for saving customizations."
3886 (let ((user-init-file user-init-file
)
3888 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3889 (when (null user-init-file
)
3890 (if (or (file-exists-p default-init-file
)
3891 (and (eq system-type
'windows-nt
)
3892 (file-exists-p "~/_emacs")))
3893 ;; Started with -q, i.e. the file containing
3894 ;; Custom settings hasn't been read. Saving
3895 ;; settings there would overwrite other settings.
3896 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3897 (setq user-init-file default-init-file
))
3900 (defun custom-save-delete (symbol)
3901 "Visit `custom-file' and delete all calls to SYMBOL from it.
3902 Leave point at the old location of the first such call,
3903 or (if there were none) at the end of the buffer."
3904 (let ((default-major-mode 'emacs-lisp-mode
))
3905 (set-buffer (find-file-noselect (custom-file))))
3906 (goto-char (point-min))
3907 ;; Skip all whitespace and comments.
3908 (while (forward-comment 1))
3910 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3913 (while t
;; We exit this loop only via throw.
3914 ;; Skip all whitespace and comments.
3915 (while (forward-comment 1))
3916 (let ((start (point))
3917 (sexp (condition-case nil
3918 (read (current-buffer))
3919 (end-of-file (throw 'found nil
)))))
3920 (when (and (listp sexp
)
3921 (eq (car sexp
) symbol
))
3922 (delete-region start
(point))
3924 (setq first
(point)))))))
3927 ;; Move in front of local variables, otherwise long Custom
3928 ;; entries would make them ineffective.
3929 (let ((pos (point-max))
3930 (case-fold-search t
))
3932 (goto-char (point-max))
3933 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3935 (when (search-forward "Local Variables:" nil t
)
3936 (setq pos
(line-beginning-position))))
3939 (defun custom-save-variables ()
3940 "Save all customized variables in `custom-file'."
3942 (custom-save-delete 'custom-load-themes
)
3943 (custom-save-delete 'custom-reset-variables
)
3944 (custom-save-delete 'custom-set-variables
)
3945 (custom-save-loaded-themes)
3946 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3947 (let ((standard-output (current-buffer))
3948 (saved-list (make-list 1 0))
3950 ;; First create a sorted list of saved variables.
3953 (if (get symbol
'saved-value
)
3954 (nconc saved-list
(list symbol
)))))
3955 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3958 (princ "(custom-set-variables
3959 ;; custom-set-variables was added by Custom.
3960 ;; If you edit it by hand, you could mess it up, so be careful.
3961 ;; Your init file should contain only one such instance.
3962 ;; If there is more than one, they won't work right.\n")
3963 (dolist (symbol saved-list
)
3964 (let ((spec (car-safe (get symbol
'theme-value
)))
3965 (value (get symbol
'saved-value
))
3966 (requests (get symbol
'custom-requests
))
3967 (now (not (or (custom-variable-p symbol
)
3968 (and (not (boundp symbol
))
3969 (not (eq (get symbol
'force-value
)
3971 (comment (get symbol
'saved-variable-comment
)))
3972 ;; Check `requests'.
3973 (dolist (request requests
)
3974 (when (and (symbolp request
) (not (featurep request
)))
3975 (message "Unknown requested feature: %s" request
)
3976 (setq requests
(delq request requests
))))
3978 (eq (nth 0 spec
) 'user
)
3979 (eq (nth 1 spec
) 'set
))
3981 (and (null spec
) (get symbol
'saved-value
)))
3988 (when (or now requests comment
)
3991 (when (or requests comment
)
4001 (unless (looking-at "\n")
4004 (defun custom-save-faces ()
4005 "Save all customized faces in `custom-file'."
4007 (custom-save-delete 'custom-reset-faces
)
4008 (custom-save-delete 'custom-set-faces
)
4009 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
4010 (let ((standard-output (current-buffer))
4011 (saved-list (make-list 1 0))
4013 ;; First create a sorted list of saved faces.
4016 (if (get symbol
'saved-face
)
4017 (nconc saved-list
(list symbol
)))))
4018 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4019 ;; The default face must be first, since it affects the others.
4020 (if (memq 'default saved-list
)
4021 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4024 (princ "(custom-set-faces
4025 ;; custom-set-faces was added by Custom.
4026 ;; If you edit it by hand, you could mess it up, so be careful.
4027 ;; Your init file should contain only one such instance.
4028 ;; If there is more than one, they won't work right.\n")
4029 (dolist (symbol saved-list
)
4030 (let ((spec (car-safe (get symbol
'theme-face
)))
4031 (value (get symbol
'saved-face
))
4032 (now (not (or (get symbol
'face-defface-spec
)
4033 (and (not (custom-facep symbol
))
4034 (not (get symbol
'force-face
))))))
4035 (comment (get symbol
'saved-face-comment
)))
4037 (eq (nth 0 spec
) 'user
)
4038 (eq (nth 1 spec
) 'set
))
4040 (and (null spec
) (get symbol
'saved-face
)))
4041 ;; Don't print default face here.
4048 (when (or now comment
)
4058 (unless (looking-at "\n")
4061 (defun custom-save-resets (property setter special
)
4062 (let (started-writing ignored-special
)
4063 ;; (custom-save-delete setter) Done by caller
4064 (let ((standard-output (current-buffer))
4065 (mapper `(lambda (object)
4066 (let ((spec (car-safe (get object
(quote ,property
)))))
4067 (when (and (not (memq object ignored-special
))
4068 (eq (nth 0 spec
) 'user
)
4069 (eq (nth 1 spec
) 'reset
))
4070 ;; Do not write reset statements unless necessary.
4071 (unless started-writing
4072 (setq started-writing t
)
4076 (princ (quote ,setter
))
4080 (prin1 (nth 3 spec
))
4082 (mapc mapper special
)
4083 (setq ignored-special special
)
4085 (when started-writing
4088 (defun custom-save-loaded-themes ()
4089 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
4090 (standard-output (current-buffer)))
4092 (unless (bolp) (princ "\n"))
4093 (princ "(custom-load-themes")
4094 (mapc (lambda (theme)
4096 (prin1 theme
)) themes
)
4100 (defun customize-save-customized ()
4101 "Save all user options which have been set in this session."
4103 (mapatoms (lambda (symbol)
4104 (let ((face (get symbol
'customized-face
))
4105 (value (get symbol
'customized-value
))
4106 (face-comment (get symbol
'customized-face-comment
))
4108 (get symbol
'customized-variable-comment
)))
4110 (put symbol
'saved-face face
)
4111 (custom-push-theme 'theme-face symbol
'user
'set value
)
4112 (put symbol
'customized-face nil
))
4114 (put symbol
'saved-value value
)
4115 (custom-push-theme 'theme-value symbol
'user
'set value
)
4116 (put symbol
'customized-value nil
))
4117 (when variable-comment
4118 (put symbol
'saved-variable-comment variable-comment
)
4119 (put symbol
'customized-variable-comment nil
))
4121 (put symbol
'saved-face-comment face-comment
)
4122 (put symbol
'customized-face-comment nil
)))))
4123 ;; We really should update all custom buffers here.
4127 (defun custom-save-all ()
4128 "Save all customizations in `custom-file'."
4129 (let ((inhibit-read-only t
))
4130 (custom-save-variables)
4133 (let ((default-major-mode nil
))
4134 (set-buffer (find-file-noselect (custom-file))))
4135 (let ((file-precious-flag t
))
4138 ;;; The Customize Menu.
4142 (defcustom custom-menu-nesting
2
4143 "Maximum nesting in custom menus."
4145 :group
'custom-menu
)
4147 (defun custom-face-menu-create (widget symbol
)
4148 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4149 (vector (custom-unlispify-menu-entry symbol
)
4150 `(customize-face ',symbol
)
4153 (defun custom-variable-menu-create (widget symbol
)
4154 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4155 (let ((type (get symbol
'custom-type
)))
4156 (unless (listp type
)
4157 (setq type
(list type
)))
4158 (if (and type
(widget-get type
:custom-menu
))
4159 (widget-apply type
:custom-menu symbol
)
4160 (vector (custom-unlispify-menu-entry symbol
)
4161 `(customize-variable ',symbol
)
4164 ;; Add checkboxes to boolean variable entries.
4165 (widget-put (get 'boolean
'widget-type
)
4166 :custom-menu
(lambda (widget symbol
)
4167 (vector (custom-unlispify-menu-entry symbol
)
4168 `(customize-variable ',symbol
)
4170 ':selected symbol
)))
4172 (defun custom-group-menu-create (widget symbol
)
4173 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4174 `( ,(custom-unlispify-menu-entry symbol t
)
4175 :filter
(lambda (&rest junk
)
4176 (let ((menu (custom-menu-create ',symbol
)))
4177 (if (consp menu
) (cdr menu
) menu
)))))
4180 (defun custom-menu-create (symbol)
4181 "Create menu for customization group SYMBOL.
4182 The menu is in a format applicable to `easy-menu-define'."
4183 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4184 `(customize-group ',symbol
)
4186 (if (and (or (not (boundp 'custom-menu-nesting
))
4187 (>= custom-menu-nesting
0))
4189 (custom-load-symbol symbol
)
4190 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4191 (let ((custom-prefix-list (custom-prefix-add symbol
4192 custom-prefix-list
))
4193 (members (custom-sort-items (get symbol
'custom-group
)
4194 custom-menu-sort-alphabetically
4195 custom-menu-order-groups
)))
4196 `(,(custom-unlispify-menu-entry symbol t
)
4199 ,@(mapcar (lambda (entry)
4200 (widget-apply (if (listp (nth 1 entry
))
4202 (list (nth 1 entry
)))
4203 :custom-menu
(nth 0 entry
)))
4208 (defun customize-menu-create (symbol &optional name
)
4209 "Return a customize menu for customization group SYMBOL.
4210 If optional NAME is given, use that as the name of the menu.
4211 Otherwise the menu will be named `Customize'.
4212 The format is suitable for use with `easy-menu-define'."
4214 (setq name
"Customize"))
4216 :filter
(lambda (&rest junk
)
4217 (let ((menu (custom-menu-create ',symbol
)))
4218 (if (consp menu
) (cdr menu
) menu
)))))
4220 ;;; The Custom Mode.
4222 (defvar custom-mode-map
4223 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4224 ;; "\r" bindings from the parent map.
4225 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4226 (let ((map (make-keymap)))
4227 (set-keymap-parent map widget-keymap
)
4228 (suppress-keymap map
)
4229 (define-key map
" " 'scroll-up
)
4230 (define-key map
"\177" 'scroll-down
)
4231 (define-key map
"\C-c\C-c" 'Custom-set
)
4232 (define-key map
"\C-x\C-s" 'Custom-save
)
4233 (define-key map
"q" 'Custom-buffer-done
)
4234 (define-key map
"u" 'Custom-goto-parent
)
4235 (define-key map
"n" 'widget-forward
)
4236 (define-key map
"p" 'widget-backward
)
4237 (define-key map
[mouse-1
] 'Custom-move-and-invoke
)
4239 "Keymap for `custom-mode'.")
4241 (defun Custom-move-and-invoke (event)
4242 "Move to where you click, and if it is an active field, invoke it."
4244 (mouse-set-point event
)
4245 (if (widget-event-point event
)
4246 (let* ((pos (widget-event-point event
))
4247 (button (get-char-property pos
'button
)))
4249 (widget-button-click event
)))))
4251 (easy-menu-define Custom-mode-menu
4253 "Menu used in customization buffers."
4255 ,(customize-menu-create 'customize
)
4256 ["Set" Custom-set t
]
4257 ["Save" Custom-save t
]
4258 ["Reset to Current" Custom-reset-current t
]
4259 ["Reset to Saved" Custom-reset-saved t
]
4260 ["Reset to Standard Settings" Custom-reset-standard t
]
4261 ["Info" (info "(emacs)Easy Customization") t
]))
4263 (defun Custom-goto-parent ()
4264 "Go to the parent group listed at the top of this buffer.
4265 If several parents are listed, go to the first of them."
4268 (goto-char (point-min))
4269 (if (search-forward "\nGo to parent group: " nil t
)
4270 (let* ((button (get-char-property (point) 'button
))
4271 (parent (downcase (widget-get button
:tag
))))
4272 (customize-group parent
)))))
4274 (defcustom custom-mode-hook nil
4275 "Hook called when entering Custom mode."
4277 :group
'custom-buffer
)
4279 (defun custom-state-buffer-message (widget)
4280 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4281 (message "To install your edits, invoke [State] and choose the Set operation")))
4283 (defun custom-mode ()
4284 "Major mode for editing customization buffers.
4286 The following commands are available:
4288 Move to next button or editable field. \\[widget-forward]
4289 Move to previous button or editable field. \\[widget-backward]
4290 \\<widget-field-keymap>\
4291 Complete content of editable text field. \\[widget-complete]
4292 \\<custom-mode-map>\
4293 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4294 Invoke button under point. \\[widget-button-press]
4295 Set all modifications. \\[Custom-set]
4296 Make all modifications default. \\[Custom-save]
4297 Reset all modified options. \\[Custom-reset-current]
4298 Reset all modified or set options. \\[Custom-reset-saved]
4299 Reset all options. \\[Custom-reset-standard]
4301 Entry to this mode calls the value of `custom-mode-hook'
4302 if that value is non-nil."
4303 (kill-all-local-variables)
4304 (setq major-mode
'custom-mode
4306 (use-local-map custom-mode-map
)
4307 (easy-menu-add Custom-mode-menu
)
4308 (make-local-variable 'custom-options
)
4309 (make-local-variable 'custom-local-buffer
)
4310 (make-local-variable 'widget-documentation-face
)
4311 (setq widget-documentation-face
'custom-documentation
)
4312 (make-local-variable 'widget-button-face
)
4313 (setq widget-button-face
'custom-button
)
4314 (set (make-local-variable 'widget-button-pressed-face
) 'custom-button-pressed
)
4315 (set (make-local-variable 'widget-mouse-face
)
4316 'custom-button-pressed
) ; buttons `depress' when moused
4317 ;; When possible, use relief for buttons, not bracketing. This test
4318 ;; may not be optimal.
4319 (when custom-raised-buttons
4320 (set (make-local-variable 'widget-push-button-prefix
) "")
4321 (set (make-local-variable 'widget-push-button-suffix
) "")
4322 (set (make-local-variable 'widget-link-prefix
) "")
4323 (set (make-local-variable 'widget-link-suffix
) ""))
4324 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4325 (run-mode-hooks 'custom-mode-hook
))
4327 (put 'custom-mode
'mode-class
'special
)
4330 'debug-ignored-errors
4331 "^No user options have changed defaults in recent Emacs versions$")
4337 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4338 ;;; cus-edit.el ends here