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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, 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 (custom-buffer-create (list (list symbol
'custom-variable
))
1025 (format "*Customize Option: %s*"
1026 (custom-unlispify-tag-name symbol
))))
1029 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1032 (defun customize-option-other-window (symbol)
1033 "Customize SYMBOL, which must be a user option variable.
1034 Show the buffer in another window, but don't select it."
1035 (interactive (custom-variable-prompt))
1036 (custom-buffer-create-other-window
1037 (list (list symbol
'custom-variable
))
1038 (format "*Customize Option: %s*" (custom-unlispify-tag-name symbol
))))
1040 (defvar customize-changed-options-previous-release
"20.2"
1041 "Version for `customize-changed-options' to refer back to by default.")
1044 (defun customize-changed-options (since-version)
1045 "Customize all user option variables changed in Emacs itself.
1046 This includes new user option variables and faces, and new
1047 customization groups, as well as older options and faces whose default
1048 values have changed since the previous major Emacs release.
1050 With argument SINCE-VERSION (a string), customize all user option
1051 variables that were added (or their meanings were changed) since that
1054 (interactive "sCustomize options changed, since version (default all versions): ")
1055 (if (equal since-version
"")
1056 (setq since-version nil
)
1057 (unless (condition-case nil
1058 (numberp (read since-version
))
1060 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1061 (unless since-version
1062 (setq since-version customize-changed-options-previous-release
))
1064 ;; Load the information for versions since since-version. We use
1065 ;; custom-load-symbol for this.
1066 (put 'custom-versions-load-alist
'custom-loads nil
)
1067 (dolist (elt custom-versions-load-alist
)
1068 (if (customize-version-lessp since-version
(car elt
))
1069 (dolist (load (cdr elt
))
1070 (custom-add-load 'custom-versions-load-alist load
))))
1071 (custom-load-symbol 'custom-versions-load-alist
)
1072 (put 'custom-versions-load-alist
'custom-loads nil
)
1077 (let ((version (get symbol
'custom-version
)))
1079 (when (customize-version-lessp since-version version
)
1080 (if (or (get symbol
'custom-group
)
1081 (get symbol
'group-documentation
))
1082 (push (list symbol
'custom-group
) found
))
1083 (if (custom-variable-p symbol
)
1084 (push (list symbol
'custom-variable
) found
))
1085 (if (custom-facep symbol
)
1086 (push (list symbol
'custom-face
) found
)))))))
1088 (custom-buffer-create (custom-sort-items found t
'first
)
1089 "*Customize Changed Options*")
1090 (error "No user option defaults have been changed since Emacs %s"
1093 (defun customize-version-lessp (version1 version2
)
1094 ;; Why are the versions strings, and given that they are, why aren't
1095 ;; they converted to numbers and compared as such here? -- fx
1097 ;; In case someone made a mistake and left out the quotes
1098 ;; in the :version value.
1099 (if (numberp version2
)
1100 (setq version2
(prin1-to-string version2
)))
1101 (let (major1 major2 minor1 minor2
)
1102 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1103 (setq major1
(read (or (match-string 1 version1
)
1105 (setq minor1
(read (or (match-string 3 version1
)
1107 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1108 (setq major2
(read (or (match-string 1 version2
)
1110 (setq minor2
(read (or (match-string 3 version2
)
1112 (or (< major1 major2
)
1113 (and (= major1 major2
)
1114 (< minor1 minor2
)))))
1117 (defun customize-face (&optional face
)
1118 "Customize FACE, which should be a face name or nil.
1119 If FACE is nil, customize all faces. If FACE is actually a
1120 face-alias, customize the face it is aliased to.
1122 Interactively, when point is on text which has a face specified,
1123 suggest to customize that face, if it's customizable."
1125 (list (read-face-name "Customize face" "all faces" t
)))
1126 (if (member face
'(nil ""))
1127 (setq face
(face-list)))
1128 (if (and (listp face
) (null (cdr face
)))
1129 (setq face
(car face
)))
1131 (custom-buffer-create (custom-sort-items
1133 (list s
'custom-face
))
1136 "*Customize Faces*")
1137 ;; If FACE is actually an alias, customize the face it is aliased to.
1138 (if (get face
'face-alias
)
1139 (setq face
(get face
'face-alias
)))
1140 (unless (facep face
)
1141 (error "Invalid face %S" face
))
1142 (custom-buffer-create (list (list face
'custom-face
))
1143 (format "*Customize Face: %s*"
1144 (custom-unlispify-tag-name face
)))))
1147 (defun customize-face-other-window (&optional face
)
1148 "Show customization buffer for face FACE in other window.
1149 If FACE is actually a face-alias, customize the face it is aliased to.
1151 Interactively, when point is on text which has a face specified,
1152 suggest to customize that face, if it's customizable."
1154 (list (read-face-name "Customize face" "all faces" t
)))
1155 (if (member face
'(nil ""))
1156 (setq face
(face-list)))
1157 (if (and (listp face
) (null (cdr face
)))
1158 (setq face
(car face
)))
1160 (custom-buffer-create-other-window
1163 (list s
'custom-face
))
1166 "*Customize Faces*")
1167 (if (get face
'face-alias
)
1168 (setq face
(get face
'face-alias
)))
1169 (unless (facep face
)
1170 (error "Invalid face %S" face
))
1171 (custom-buffer-create-other-window
1172 (list (list face
'custom-face
))
1173 (format "*Customize Face: %s*"
1174 (custom-unlispify-tag-name face
)))))
1177 (defun customize-customized ()
1178 "Customize all user options set since the last save in this session."
1181 (mapatoms (lambda (symbol)
1182 (and (or (get symbol
'customized-face
)
1183 (get symbol
'customized-face-comment
))
1184 (custom-facep symbol
)
1185 (push (list symbol
'custom-face
) found
))
1186 (and (or (get symbol
'customized-value
)
1187 (get symbol
'customized-variable-comment
))
1189 (push (list symbol
'custom-variable
) found
))))
1191 (error "No customized user options")
1192 (custom-buffer-create (custom-sort-items found t nil
)
1193 "*Customize Customized*"))))
1196 (defun customize-rogue ()
1197 "Customize all user variable modified outside customize."
1200 (mapatoms (lambda (symbol)
1201 (let ((cval (or (get symbol
'customized-value
)
1202 (get symbol
'saved-value
)
1203 (get symbol
'standard-value
))))
1204 (when (and cval
;Declared with defcustom.
1205 (default-boundp symbol
) ;Has a value.
1206 (not (equal (eval (car cval
))
1207 ;; Which does not match customize.
1208 (default-value symbol
))))
1209 (push (list symbol
'custom-variable
) found
)))))
1211 (error "No rogue user options")
1212 (custom-buffer-create (custom-sort-items found t nil
)
1213 "*Customize Rogue*"))))
1215 (defun customize-saved ()
1216 "Customize all already saved user options."
1219 (mapatoms (lambda (symbol)
1220 (and (or (get symbol
'saved-face
)
1221 (get symbol
'saved-face-comment
))
1222 (custom-facep symbol
)
1223 (push (list symbol
'custom-face
) found
))
1224 (and (or (get symbol
'saved-value
)
1225 (get symbol
'saved-variable-comment
))
1227 (push (list symbol
'custom-variable
) found
))))
1229 (error "No saved user options")
1230 (custom-buffer-create (custom-sort-items found t nil
)
1231 "*Customize Saved*"))))
1234 (defun customize-apropos (regexp &optional all
)
1235 "Customize all user options matching REGEXP.
1236 If ALL is `options', include only options.
1237 If ALL is `faces', include only faces.
1238 If ALL is `groups', include only groups.
1239 If ALL is t (interactively, with prefix arg), include options which are not
1240 user-settable, as well as faces and groups."
1241 (interactive "sCustomize regexp: \nP")
1243 (mapatoms (lambda (symbol)
1244 (when (string-match regexp
(symbol-name symbol
))
1245 (when (and (not (memq all
'(faces options
)))
1246 (get symbol
'custom-group
))
1247 (push (list symbol
'custom-group
) found
))
1248 (when (and (not (memq all
'(options groups
)))
1249 (custom-facep symbol
))
1250 (push (list symbol
'custom-face
) found
))
1251 (when (and (not (memq all
'(groups faces
)))
1253 (or (get symbol
'saved-value
)
1254 (custom-variable-p symbol
)
1255 (if (memq all
'(nil options
))
1256 (user-variable-p symbol
)
1257 (get symbol
'variable-documentation
))))
1258 (push (list symbol
'custom-variable
) found
)))))
1260 (error "No matches")
1261 (custom-buffer-create (custom-sort-items found t
1262 custom-buffer-order-groups
)
1263 "*Customize Apropos*"))))
1266 (defun customize-apropos-options (regexp &optional arg
)
1267 "Customize all user options matching REGEXP.
1268 With prefix arg, include options which are not user-settable."
1269 (interactive "sCustomize regexp: \nP")
1270 (customize-apropos regexp
(or arg
'options
)))
1273 (defun customize-apropos-faces (regexp)
1274 "Customize all user faces matching REGEXP."
1275 (interactive "sCustomize regexp: \n")
1276 (customize-apropos regexp
'faces
))
1279 (defun customize-apropos-groups (regexp)
1280 "Customize all user groups matching REGEXP."
1281 (interactive "sCustomize regexp: \n")
1282 (customize-apropos regexp
'groups
))
1286 (defcustom custom-buffer-style
'links
1287 "Control the presentation style for customization buffers.
1288 The value should be a symbol, one of:
1290 brackets: groups nest within each other with big horizontal brackets.
1291 links: groups have links to subgroups."
1292 :type
'(radio (const brackets
)
1294 :group
'custom-buffer
)
1296 (defcustom custom-buffer-done-kill nil
1297 "*Non-nil means exiting a Custom buffer should kill it."
1300 :group
'custom-buffer
)
1302 (defcustom custom-buffer-indent
3
1303 "Number of spaces to indent nested groups."
1305 :group
'custom-buffer
)
1307 (defun custom-get-fresh-buffer (name)
1308 "Get a fresh new buffer with name NAME.
1309 If the buffer already exist, clean it up to be like new.
1310 Beware: it's not quite like new. Good enough for custom, but maybe
1312 ;; To be more complete, we should also kill all permanent-local variables,
1313 ;; but it's not needed for custom.
1314 (let ((buf (get-buffer name
)))
1315 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1316 ;; This will check if the file is not saved.
1320 (get-buffer-create name
)
1321 (with-current-buffer buf
1322 (kill-all-local-variables)
1323 (run-hooks 'kill-buffer-hook
)
1324 ;; Delete overlays before erasing the buffer so the overlay hooks
1325 ;; don't get run spuriously when we erase the buffer.
1326 (let ((ols (overlay-lists)))
1327 (dolist (ol (nconc (car ols
) (cdr ols
)))
1328 (delete-overlay ol
)))
1333 (defun custom-buffer-create (options &optional name description
)
1334 "Create a buffer containing OPTIONS.
1335 Optional NAME is the name of the buffer.
1336 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1337 SYMBOL is a customization option, and WIDGET is a widget for editing
1339 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1340 (custom-buffer-create-internal options description
))
1343 (defun custom-buffer-create-other-window (options &optional name description
)
1344 "Create a buffer containing OPTIONS, and display it in another window.
1345 The result includes selecting that window.
1346 Optional NAME is the name of the buffer.
1347 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1348 SYMBOL is a customization option, and WIDGET is a widget for editing
1350 (unless name
(setq name
"*Customization*"))
1351 (let ((pop-up-windows t
)
1352 (same-window-buffer-names nil
)
1353 (same-window-regexps nil
))
1354 (pop-to-buffer (custom-get-fresh-buffer name
))
1355 (custom-buffer-create-internal options description
)))
1357 (defcustom custom-reset-button-menu nil
1358 "If non-nil, only show a single reset button in customize buffers.
1359 This button will have a menu with all three reset operations."
1361 :group
'custom-buffer
)
1363 (defcustom custom-buffer-verbose-help t
1364 "If non-nil, include explanatory text in the customization buffer."
1366 :group
'custom-buffer
)
1368 (defun Custom-buffer-done (&rest ignore
)
1369 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1371 (quit-window custom-buffer-done-kill
))
1373 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1374 '(("unspecified" . unspecified
))))
1375 "If non-nil, indicate active buttons in a `raised-button' style.
1376 Otherwise use brackets."
1379 :group
'custom-buffer
)
1381 (defun custom-buffer-create-internal (options &optional description
)
1383 (if custom-buffer-verbose-help
1385 (widget-insert "This is a customization buffer")
1387 (widget-insert description
))
1388 (widget-insert (format ".
1389 %s show active fields; type RET or click mouse-1
1390 on an active field to invoke its action. Editing an option value
1391 changes only the text in the buffer. Invoke the State button to set or
1392 save the option value. Saving an option normally edits your init file.
1394 (if custom-raised-buttons
1396 "Square brackets")))
1397 (widget-create 'info-link
1399 "(emacs)Saving Customizations")
1401 " for information on how to save in a different file.
1403 (widget-create 'info-link
1405 :help-echo
"Read the online help."
1406 "(emacs)Easy Customization")
1407 (widget-insert " for general information.\n\n")
1408 (widget-insert "Operate on everything in this buffer:\n "))
1409 (widget-insert " "))
1410 (widget-create 'push-button
1411 :tag
"Set for Current Session"
1413 Make your editing in this buffer take effect for this session."
1414 :action
(lambda (widget &optional event
)
1417 (widget-create 'push-button
1418 :tag
"Save for Future Sessions"
1420 Make your editing in this buffer take effect for future Emacs sessions.
1421 This updates your Emacs initialization file or creates a new one."
1422 :action
(lambda (widget &optional event
)
1424 (if custom-reset-button-menu
1427 (widget-create 'push-button
1429 :help-echo
"Show a menu with reset operations."
1430 :mouse-down-action
(lambda (&rest junk
) t
)
1431 :action
(lambda (widget &optional event
)
1432 (custom-reset event
))))
1433 (widget-insert "\n ")
1434 (widget-create 'push-button
1437 Reset all edited text in this buffer to reflect current values."
1438 :action
'Custom-reset-current
)
1440 (widget-create 'push-button
1441 :tag
"Reset to Saved"
1443 Reset all values in this buffer to their saved settings."
1444 :action
'Custom-reset-saved
)
1446 (widget-create 'push-button
1447 :tag
"Erase Customization"
1449 Un-customize all values in this buffer. They get their standard settings."
1450 :action
'Custom-reset-standard
))
1451 (if (not custom-buffer-verbose-help
)
1454 (widget-create 'info-link
1456 :help-echo
"Read the online help."
1457 "(emacs)Easy Customization")))
1459 (widget-create 'push-button
1462 (lambda (&rest ignore
)
1463 (if custom-buffer-done-kill
1465 "Bury this buffer"))
1466 :action
#'Custom-buffer-done
)
1467 (widget-insert "\n\n")
1468 (message "Creating customization items...")
1469 (buffer-disable-undo)
1470 (setq custom-options
1471 (if (= (length options
) 1)
1472 (mapcar (lambda (entry)
1473 (widget-create (nth 1 entry
)
1474 :documentation-shown t
1475 :custom-state
'unknown
1476 :tag
(custom-unlispify-tag-name
1478 :value
(nth 0 entry
)))
1481 (length (length options
)))
1482 (mapcar (lambda (entry)
1484 (message "Creating customization items ...%2d%%"
1485 (/ (* 100.0 count
) length
))
1486 (widget-create (nth 1 entry
)
1487 :tag
(custom-unlispify-tag-name
1489 :value
(nth 0 entry
))
1490 (setq count
(1+ count
))
1491 (unless (eq (preceding-char) ?
\n)
1492 (widget-insert "\n"))
1493 (widget-insert "\n")))
1495 (unless (eq (preceding-char) ?
\n)
1496 (widget-insert "\n"))
1497 (message "Creating customization items ...done")
1498 (message "Resetting customization items...")
1499 (unless (eq custom-buffer-style
'tree
)
1500 (mapc 'custom-magic-reset custom-options
))
1501 (message "Resetting customization items...done")
1502 (message "Creating customization setup...")
1504 (buffer-enable-undo)
1505 (goto-char (point-min))
1506 (message "Creating customization setup...done"))
1508 ;;; The Tree Browser.
1511 (defun customize-browse (&optional group
)
1512 "Create a tree browser for the customize hierarchy."
1515 (setq group
'emacs
))
1516 (let ((name "*Customize Browser*"))
1517 (pop-to-buffer (custom-get-fresh-buffer name
)))
1520 Square brackets show active fields; type RET or click mouse-1
1521 on an active field to invoke its action.
1522 Invoke [+] below to expand a group, and [-] to collapse an expanded group.\n")
1523 (if custom-browse-only-groups
1525 Invoke the [Group] button below to edit that item in another window.\n\n")
1526 (widget-insert "Invoke the ")
1527 (widget-create 'item
1530 :tag-glyph
"folder")
1531 (widget-insert ", ")
1532 (widget-create 'item
1536 (widget-insert ", and ")
1537 (widget-create 'item
1540 :tag-glyph
"option")
1541 (widget-insert " buttons below to edit that
1542 item in another window.\n\n"))
1543 (let ((custom-buffer-style 'tree
))
1544 (widget-create 'custom-group
1546 :custom-state
'unknown
1547 :tag
(custom-unlispify-tag-name group
)
1550 (goto-char (point-min)))
1552 (define-widget 'custom-browse-visibility
'item
1553 "Control visibility of items in the customize tree browser."
1555 :action
'custom-browse-visibility-action
)
1557 (defun custom-browse-visibility-action (widget &rest ignore
)
1558 (let ((custom-buffer-style 'tree
))
1559 (custom-toggle-parent widget
)))
1561 (define-widget 'custom-browse-group-tag
'push-button
1562 "Show parent in other window when activated."
1565 :action
'custom-browse-group-tag-action
)
1567 (defun custom-browse-group-tag-action (widget &rest ignore
)
1568 (let ((parent (widget-get widget
:parent
)))
1569 (customize-group-other-window (widget-value parent
))))
1571 (define-widget 'custom-browse-variable-tag
'push-button
1572 "Show parent in other window when activated."
1575 :action
'custom-browse-variable-tag-action
)
1577 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1578 (let ((parent (widget-get widget
:parent
)))
1579 (customize-variable-other-window (widget-value parent
))))
1581 (define-widget 'custom-browse-face-tag
'push-button
1582 "Show parent in other window when activated."
1585 :action
'custom-browse-face-tag-action
)
1587 (defun custom-browse-face-tag-action (widget &rest ignore
)
1588 (let ((parent (widget-get widget
:parent
)))
1589 (customize-face-other-window (widget-value parent
))))
1591 (defconst custom-browse-alist
'((" " "space")
1597 (defun custom-browse-insert-prefix (prefix)
1598 "Insert PREFIX. On XEmacs convert it to line graphics."
1599 ;; Fixme: do graphics.
1600 (if nil
; (string-match "XEmacs" emacs-version)
1603 (while (not (string-equal prefix
""))
1604 (let ((entry (substring prefix
0 3)))
1605 (setq prefix
(substring prefix
3))
1606 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1607 (name (nth 1 (assoc entry custom-browse-alist
))))
1608 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1609 (overlay-put overlay
'start-open t
)
1610 (overlay-put overlay
'end-open t
)))))
1613 ;;; Modification of Basic Widgets.
1615 ;; We add extra properties to the basic widgets needed here. This is
1616 ;; fine, as long as we are careful to stay within out own namespace.
1618 ;; We want simple widgets to be displayed by default, but complex
1619 ;; widgets to be hidden.
1621 (widget-put (get 'item
'widget-type
) :custom-show t
)
1622 (widget-put (get 'editable-field
'widget-type
)
1623 :custom-show
(lambda (widget value
)
1624 (let ((pp (pp-to-string value
)))
1625 (cond ((string-match "\n" pp
)
1630 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1632 ;;; The `custom-manual' Widget.
1634 (define-widget 'custom-manual
'info-link
1635 "Link to the manual entry for this customization option."
1636 :help-echo
"Read the manual entry for this option."
1639 ;;; The `custom-magic' Widget.
1641 (defgroup custom-magic-faces nil
1642 "Faces used by the magic button."
1643 :group
'custom-faces
1644 :group
'custom-buffer
)
1646 (defface custom-invalid
'((((class color
))
1647 (:foreground
"yellow1" :background
"red1"))
1649 (:weight bold
:slant italic
:underline t
)))
1650 "Face used when the customize item is invalid."
1651 :group
'custom-magic-faces
)
1652 ;; backward-compatibility alias
1653 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1655 (defface custom-rogue
'((((class color
))
1656 (:foreground
"pink" :background
"black"))
1659 "Face used when the customize item is not defined for customization."
1660 :group
'custom-magic-faces
)
1661 ;; backward-compatibility alias
1662 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1664 (defface custom-modified
'((((min-colors 88) (class color
))
1665 (:foreground
"white" :background
"blue1"))
1667 (:foreground
"white" :background
"blue"))
1669 (:slant italic
:bold
)))
1670 "Face used when the customize item has been modified."
1671 :group
'custom-magic-faces
)
1672 ;; backward-compatibility alias
1673 (put 'custom-modified-face
'face-alias
'custom-modified
)
1675 (defface custom-set
'((((min-colors 88) (class color
))
1676 (:foreground
"blue1" :background
"white"))
1678 (:foreground
"blue" :background
"white"))
1681 "Face used when the customize item has been set."
1682 :group
'custom-magic-faces
)
1683 ;; backward-compatibility alias
1684 (put 'custom-set-face
'face-alias
'custom-set
)
1686 (defface custom-changed
'((((min-colors 88) (class color
))
1687 (:foreground
"white" :background
"blue1"))
1689 (:foreground
"white" :background
"blue"))
1692 "Face used when the customize item has been changed."
1693 :group
'custom-magic-faces
)
1694 ;; backward-compatibility alias
1695 (put 'custom-changed-face
'face-alias
'custom-changed
)
1697 (defface custom-saved
'((t (:underline t
)))
1698 "Face used when the customize item has been saved."
1699 :group
'custom-magic-faces
)
1700 ;; backward-compatibility alias
1701 (put 'custom-saved-face
'face-alias
'custom-saved
)
1703 (defconst custom-magic-alist
1704 '((nil "#" underline
"\
1705 UNINITIALIZED, you should not see this.")
1706 (unknown "?" italic
"\
1707 UNKNOWN, you should not see this.")
1708 (hidden "-" default
"\
1709 HIDDEN, invoke \"Show\" in the previous line to show." "\
1710 group now hidden, invoke \"Show\", above, to show contents.")
1711 (invalid "x" custom-invalid
"\
1712 INVALID, the displayed value cannot be set.")
1713 (modified "*" custom-modified
"\
1714 EDITED, shown value does not take effect until you set or save it." "\
1715 something in this group has been edited but not set.")
1716 (set "+" custom-set
"\
1717 SET for current session only." "\
1718 something in this group has been set but not saved.")
1719 (changed ":" custom-changed
"\
1720 CHANGED outside Customize; operating on it here may be unreliable." "\
1721 something in this group has been changed outside customize.")
1722 (saved "!" custom-saved
"\
1724 something in this group has been set and saved.")
1725 (rogue "@" custom-rogue
"\
1726 NO CUSTOMIZATION DATA; you should not see this." "\
1727 something in this group is not prepared for customization.")
1728 (standard " " nil
"\
1730 visible group members are all at standard settings."))
1731 "Alist of customize option states.
1732 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1734 STATE is one of the following symbols:
1737 For internal use, should never occur.
1739 For internal use, should never occur.
1741 This item is not being displayed.
1743 This item is modified, but has an invalid form.
1745 This item is modified, and has a valid form.
1747 This item has been set but not saved.
1749 The current value of this item has been changed outside Customize.
1751 This item is marked for saving.
1753 This item has no customization information.
1755 This item is unchanged from the standard setting.
1757 MAGIC is a string used to present that state.
1759 FACE is a face used to present the state.
1761 ITEM-DESC is a string describing the state for options.
1763 GROUP-DESC is a string describing the state for groups. If this is
1764 left out, ITEM-DESC will be used.
1766 The string %c in either description will be replaced with the
1767 category of the item. These are `group'. `option', and `face'.
1769 The list should be sorted most significant first.")
1771 (defcustom custom-magic-show
'long
1772 "If non-nil, show textual description of the state.
1773 If `long', show a full-line description, not just one word."
1774 :type
'(choice (const :tag
"no" nil
)
1776 (other :tag
"short" short
))
1777 :group
'custom-buffer
)
1779 (defcustom custom-magic-show-hidden
'(option face
)
1780 "Control whether the State button is shown for hidden items.
1781 The value should be a list with the custom categories where the State
1782 button should be visible. Possible categories are `group', `option',
1784 :type
'(set (const group
) (const option
) (const face
))
1785 :group
'custom-buffer
)
1787 (defcustom custom-magic-show-button nil
1788 "Show a \"magic\" button indicating the state of each customization option."
1790 :group
'custom-buffer
)
1792 (define-widget 'custom-magic
'default
1793 "Show and manipulate state for a customization option."
1795 :action
'widget-parent-action
1798 :value-create
'custom-magic-value-create
1799 :value-delete
'widget-children-value-delete
)
1801 (defun widget-magic-mouse-down-action (widget &optional event
)
1802 ;; Non-nil unless hidden.
1803 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1807 (defun custom-magic-value-create (widget)
1808 "Create compact status report for WIDGET."
1809 (let* ((parent (widget-get widget
:parent
))
1810 (state (widget-get parent
:custom-state
))
1811 (hidden (eq state
'hidden
))
1812 (entry (assq state custom-magic-alist
))
1813 (magic (nth 1 entry
))
1814 (face (nth 2 entry
))
1815 (category (widget-get parent
:custom-category
))
1816 (text (or (and (eq category
'group
)
1819 (form (widget-get parent
:custom-form
))
1821 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1822 (setq text
(concat (match-string 1 text
)
1823 (symbol-name category
)
1824 (match-string 2 text
))))
1825 (when (and custom-magic-show
1827 (memq category custom-magic-show-hidden
)))
1829 (when (and (eq category
'group
)
1830 (not (and (eq custom-buffer-style
'links
)
1831 (> (widget-get parent
:custom-level
) 1))))
1832 (insert-char ?\
(* custom-buffer-indent
1833 (widget-get parent
:custom-level
))))
1834 (push (widget-create-child-and-convert
1836 :help-echo
"Change the state of this item."
1837 :format
(if hidden
"%t" "%[%t%]")
1838 :button-prefix
'widget-push-button-prefix
1839 :button-suffix
'widget-push-button-suffix
1840 :mouse-down-action
'widget-magic-mouse-down-action
1844 (let ((start (point)))
1845 (if (eq custom-magic-show
'long
)
1847 (insert (symbol-name state
)))
1848 (cond ((eq form
'lisp
)
1850 ((eq form
'mismatch
)
1851 (insert " (mismatch)")))
1852 (put-text-property start
(point) 'face
'custom-state
))
1854 (when (and (eq category
'group
)
1855 (not (and (eq custom-buffer-style
'links
)
1856 (> (widget-get parent
:custom-level
) 1))))
1857 (insert-char ?\
(* custom-buffer-indent
1858 (widget-get parent
:custom-level
))))
1859 (when custom-magic-show-button
1860 (when custom-magic-show
1861 (let ((indent (widget-get parent
:indent
)))
1863 (insert-char ? indent
))))
1864 (push (widget-create-child-and-convert
1866 :mouse-down-action
'widget-magic-mouse-down-action
1870 :help-echo
"Change the state."
1871 :format
(if hidden
"%t" "%[%t%]")
1872 :tag
(if (memq form
'(lisp mismatch
))
1873 (concat "(" magic
")")
1874 (concat "[" magic
"]")))
1877 (widget-put widget
:children children
)))
1879 (defun custom-magic-reset (widget)
1880 "Redraw the :custom-magic property of WIDGET."
1881 (let ((magic (widget-get widget
:custom-magic
)))
1882 (widget-value-set magic
(widget-value magic
))))
1884 ;;; The `custom' Widget.
1886 (defface custom-button
1887 '((((type x w32 mac
) (class color
)) ; Like default modeline
1888 (:box
(:line-width
2 :style released-button
)
1889 :background
"lightgrey" :foreground
"black"))
1892 "Face used for buttons in customization buffers."
1894 :group
'custom-faces
)
1895 ;; backward-compatibility alias
1896 (put 'custom-button-face
'face-alias
'custom-button
)
1898 (defface custom-button-pressed
1899 '((((type x w32 mac
) (class color
))
1900 (:box
(:line-width
2 :style pressed-button
)
1901 :background
"lightgrey" :foreground
"black"))
1903 (:inverse-video t
)))
1904 "Face used for buttons in customization buffers."
1906 :group
'custom-faces
)
1907 ;; backward-compatibility alias
1908 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
1910 (defface custom-documentation nil
1911 "Face used for documentation strings in customization buffers."
1912 :group
'custom-faces
)
1913 ;; backward-compatibility alias
1914 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
1916 (defface custom-state
'((((class color
)
1918 (:foreground
"lime green"))
1921 (:foreground
"dark green"))
1923 "Face used for State descriptions in the customize buffer."
1924 :group
'custom-faces
)
1925 ;; backward-compatibility alias
1926 (put 'custom-state-face
'face-alias
'custom-state
)
1928 (define-widget 'custom
'default
1929 "Customize a user option."
1931 :convert-widget
'custom-convert-widget
1932 :notify
'custom-notify
1935 :custom-state
'hidden
1936 :documentation-property
'widget-subclass-responsibility
1937 :value-create
'widget-subclass-responsibility
1938 :value-delete
'widget-children-value-delete
1939 :value-get
'widget-value-value-get
1940 :validate
'widget-children-validate
1941 :match
(lambda (widget value
) (symbolp value
)))
1943 (defun custom-convert-widget (widget)
1944 "Initialize :value and :tag from :args in WIDGET."
1945 (let ((args (widget-get widget
:args
)))
1947 (widget-put widget
:value
(widget-apply widget
1948 :value-to-internal
(car args
)))
1949 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
1950 (widget-put widget
:args nil
)))
1953 (defun custom-notify (widget &rest args
)
1954 "Keep track of changes."
1955 (let ((state (widget-get widget
:custom-state
)))
1956 (unless (eq state
'modified
)
1957 (unless (memq state
'(nil unknown hidden
))
1958 (widget-put widget
:custom-state
'modified
))
1959 (custom-magic-reset widget
)
1960 (apply 'widget-default-notify widget args
))))
1962 (defun custom-redraw (widget)
1963 "Redraw WIDGET with current settings."
1964 (let ((line (count-lines (point-min) (point)))
1965 (column (current-column))
1967 (from (marker-position (widget-get widget
:from
)))
1968 (to (marker-position (widget-get widget
:to
))))
1970 (widget-value-set widget
(widget-value widget
))
1971 (custom-redraw-magic widget
))
1972 (when (and (>= pos from
) (<= pos to
))
1977 (goto-line (1+ line
)))
1978 (move-to-column column
))
1981 (defun custom-redraw-magic (widget)
1982 "Redraw WIDGET state with current settings."
1984 (let ((magic (widget-get widget
:custom-magic
)))
1986 (widget-value-set magic
(widget-value magic
))
1987 (when (setq widget
(widget-get widget
:group
))
1988 (custom-group-state-update widget
)))
1990 (setq widget nil
)))))
1993 (defun custom-show (widget value
)
1994 "Non-nil if WIDGET should be shown with VALUE by default."
1995 (let ((show (widget-get widget
:custom-show
)))
2001 (funcall show widget value
)))))
2003 (defun custom-load-widget (widget)
2004 "Load all dependencies for WIDGET."
2005 (custom-load-symbol (widget-value widget
)))
2007 (defun custom-unloaded-symbol-p (symbol)
2008 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2010 (loads (get symbol
'custom-loads
))
2013 (setq load
(car loads
)
2015 (cond ((symbolp load
)
2016 (unless (featurep load
)
2018 ((assoc load load-history
))
2019 ((assoc (locate-library load
) load-history
)
2025 (defun custom-unloaded-widget-p (widget)
2026 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2027 (custom-unloaded-symbol-p (widget-value widget
)))
2029 (defun custom-toggle-hide (widget)
2030 "Toggle visibility of WIDGET."
2031 (custom-load-widget widget
)
2032 (let ((state (widget-get widget
:custom-state
)))
2033 (cond ((memq state
'(invalid modified
))
2034 (error "There are unset changes"))
2036 (widget-put widget
:custom-state
'unknown
))
2038 (widget-put widget
:documentation-shown nil
)
2039 (widget-put widget
:custom-state
'hidden
)))
2040 (custom-redraw widget
)
2043 (defun custom-toggle-parent (widget &rest ignore
)
2044 "Toggle visibility of parent of WIDGET."
2045 (custom-toggle-hide (widget-get widget
:parent
)))
2047 (defun custom-add-see-also (widget &optional prefix
)
2048 "Add `See also ...' to WIDGET if there are any links.
2049 Insert PREFIX first if non-nil."
2050 (let* ((symbol (widget-get widget
:value
))
2051 (links (get symbol
'custom-links
))
2052 (many (> (length links
) 2))
2053 (buttons (widget-get widget
:buttons
))
2054 (indent (widget-get widget
:indent
)))
2057 (insert-char ?\ indent
))
2060 (insert "See also ")
2062 (push (widget-create-child-and-convert widget
(car links
))
2064 (setq links
(cdr links
))
2073 (widget-put widget
:buttons buttons
))))
2075 (defun custom-add-parent-links (widget &optional initial-string
)
2076 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2077 The value if non-nil if any parents were found.
2078 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2079 (let ((name (widget-value widget
))
2080 (type (widget-type widget
))
2081 (buttons (widget-get widget
:buttons
))
2084 (insert (or initial-string
"Parent groups:"))
2085 (mapatoms (lambda (symbol)
2086 (let ((entry (assq name
(get symbol
'custom-group
))))
2087 (when (eq (nth 1 entry
) type
)
2089 (push (widget-create-child-and-convert
2090 widget
'custom-group-link
2091 :tag
(custom-unlispify-tag-name symbol
)
2094 (setq parents
(cons symbol parents
))))))
2095 (and (null (get name
'custom-links
)) ;No links of its own.
2096 (= (length parents
) 1) ;A single parent.
2097 (let* ((links (get (car parents
) 'custom-links
))
2098 (many (> (length links
) 2)))
2100 (insert "\nParent documentation: ")
2102 (push (widget-create-child-and-convert widget
(car links
))
2104 (setq links
(cdr links
))
2115 (delete-region start
(point)))
2116 (widget-put widget
:buttons buttons
)
2119 ;;; The `custom-comment' Widget.
2121 ;; like the editable field
2122 (defface custom-comment
'((((class grayscale color
)
2124 (:background
"gray85"))
2125 (((class grayscale color
)
2127 (:background
"dim gray"))
2130 "Face used for comments on variables or faces"
2132 :group
'custom-faces
)
2133 ;; backward-compatibility alias
2134 (put 'custom-comment-face
'face-alias
'custom-comment
)
2136 ;; like font-lock-comment-face
2137 (defface custom-comment-tag
2138 '((((class color
) (background dark
)) (:foreground
"gray80"))
2139 (((class color
) (background light
)) (:foreground
"blue4"))
2140 (((class grayscale
) (background light
))
2141 (:foreground
"DimGray" :weight bold
:slant italic
))
2142 (((class grayscale
) (background dark
))
2143 (:foreground
"LightGray" :weight bold
:slant italic
))
2145 "Face used for variables or faces comment tags"
2146 :group
'custom-faces
)
2147 ;; backward-compatibility alias
2148 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2150 (define-widget 'custom-comment
'string
2153 :help-echo
"Edit a comment here."
2154 :sample-face
'custom-comment-tag-face
2155 :value-face
'custom-comment-face
2157 :create
'custom-comment-create
)
2159 (defun custom-comment-create (widget)
2160 (let* ((null-comment (equal "" (widget-value widget
))))
2161 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2163 (widget-default-create widget
)
2164 ;; `widget-default-delete' expects markers in these slots --
2165 ;; maybe it shouldn't.
2166 (widget-put widget
:from
(point-marker))
2167 (widget-put widget
:to
(point-marker)))))
2169 (defun custom-comment-hide (widget)
2170 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2172 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2173 ;; the global custom one
2174 (defun custom-comment-show (widget)
2175 (widget-put widget
:comment-shown t
)
2176 (custom-redraw widget
)
2179 (defun custom-comment-invisible-p (widget)
2180 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2182 (not (widget-get widget
:comment-shown
)))))
2184 ;;; The `custom-variable' Widget.
2186 ;; When this was underlined blue, users confused it with a
2187 ;; Mosaic-style hyperlink...
2188 (defface custom-variable-tag
2191 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2192 (((min-colors 88) (class color
)
2194 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2197 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2199 "Face used for unpushable variable tags."
2200 :group
'custom-faces
)
2201 ;; backward-compatibility alias
2202 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2204 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2205 "Face used for pushable variable tags."
2206 :group
'custom-faces
)
2207 ;; backward-compatibility alias
2208 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2210 (defcustom custom-variable-default-form
'edit
2211 "Default form of displaying variable values."
2212 :type
'(choice (const edit
)
2214 :group
'custom-buffer
2217 (defun custom-variable-documentation (variable)
2218 "Return documentation of VARIABLE for use in Custom buffer.
2219 Normally just return the docstring. But if VARIABLE automatically
2220 becomes buffer local when set, append a message to that effect."
2221 (if (and (local-variable-if-set-p variable
)
2222 (or (not (local-variable-p variable
))
2224 (local-variable-if-set-p variable
))))
2225 (concat (documentation-property variable
'variable-documentation
)
2227 This variable automatically becomes buffer-local when set outside Custom.
2228 However, setting it through Custom sets the default value.")
2229 (documentation-property variable
'variable-documentation
)))
2231 (define-widget 'custom-variable
'custom
2232 "Customize variable."
2234 :help-echo
"Set or reset this variable."
2235 :documentation-property
#'custom-variable-documentation
2236 :custom-category
'option
2238 :custom-menu
'custom-variable-menu-create
2239 :custom-form nil
; defaults to value of `custom-variable-default-form'
2240 :value-create
'custom-variable-value-create
2241 :action
'custom-variable-action
2242 :custom-set
'custom-variable-set
2243 :custom-save
'custom-variable-save
2244 :custom-reset-current
'custom-redraw
2245 :custom-reset-saved
'custom-variable-reset-saved
2246 :custom-reset-standard
'custom-variable-reset-standard
2247 :custom-standard-value
'custom-variable-standard-value
)
2249 (defun custom-variable-type (symbol)
2250 "Return a widget suitable for editing the value of SYMBOL.
2251 If SYMBOL has a `custom-type' property, use that.
2252 Otherwise, look up symbol in `custom-guess-type-alist'."
2253 (let* ((type (or (get symbol
'custom-type
)
2254 (and (not (get symbol
'standard-value
))
2255 (custom-guess-type symbol
))
2257 (options (get symbol
'custom-options
))
2258 (tmp (if (listp type
)
2259 (copy-sequence type
)
2262 (widget-put tmp
:options options
))
2265 (defun custom-variable-value-create (widget)
2266 "Here is where you edit the variable's value."
2267 (custom-load-widget widget
)
2268 (unless (widget-get widget
:custom-form
)
2269 (widget-put widget
:custom-form custom-variable-default-form
))
2270 (let* ((buttons (widget-get widget
:buttons
))
2271 (children (widget-get widget
:children
))
2272 (form (widget-get widget
:custom-form
))
2273 (state (widget-get widget
:custom-state
))
2274 (symbol (widget-get widget
:value
))
2275 (tag (widget-get widget
:tag
))
2276 (type (custom-variable-type symbol
))
2277 (conv (widget-convert type
))
2278 (get (or (get symbol
'custom-get
) 'default-value
))
2279 (prefix (widget-get widget
:custom-prefix
))
2280 (last (widget-get widget
:custom-last
))
2281 (value (if (default-boundp symbol
)
2282 (funcall get symbol
)
2283 (widget-get conv
:value
))))
2284 ;; If the widget is new, the child determines whether it is hidden.
2286 ((custom-show type value
)
2287 (setq state
'unknown
))
2289 (setq state
'hidden
)))
2290 ;; If we don't know the state, see if we need to edit it in lisp form.
2291 (when (eq state
'unknown
)
2292 (unless (widget-apply conv
:match value
)
2293 ;; (widget-apply (widget-convert type) :match value)
2294 (setq form
'mismatch
)))
2295 ;; Now we can create the child widget.
2296 (cond ((eq custom-buffer-style
'tree
)
2297 (insert prefix
(if last
" `--- " " |--- "))
2298 (push (widget-create-child-and-convert
2299 widget
'custom-browse-variable-tag
)
2301 (insert " " tag
"\n")
2302 (widget-put widget
:buttons buttons
))
2304 ;; Indicate hidden value.
2305 (push (widget-create-child-and-convert
2308 :sample-face
'custom-variable-tag-face
2312 (push (widget-create-child-and-convert
2314 :help-echo
"Show the value of this option."
2316 :action
'custom-toggle-parent
2319 ((memq form
'(lisp mismatch
))
2320 ;; In lisp mode edit the saved value when possible.
2321 (let* ((value (cond ((get symbol
'saved-value
)
2322 (car (get symbol
'saved-value
)))
2323 ((get symbol
'standard-value
)
2324 (car (get symbol
'standard-value
)))
2325 ((default-boundp symbol
)
2326 (custom-quote (funcall get symbol
)))
2328 (custom-quote (widget-get conv
:value
))))))
2329 (insert (symbol-name symbol
) ": ")
2330 (push (widget-create-child-and-convert
2332 :help-echo
"Hide the value of this option."
2335 :action
'custom-toggle-parent
2339 (push (widget-create-child-and-convert
2341 :button-face
'custom-variable-button-face
2343 :tag
(symbol-name symbol
)
2349 (let* ((format (widget-get type
:format
))
2350 tag-format value-format
)
2351 (unless (string-match ":" format
)
2352 (error "Bad format"))
2353 (setq tag-format
(substring format
0 (match-end 0)))
2354 (setq value-format
(substring format
(match-end 0)))
2355 (push (widget-create-child-and-convert
2358 :action
'custom-tag-action
2359 :help-echo
"Change value of this option."
2360 :mouse-down-action
'custom-tag-mouse-down-action
2361 :button-face
'custom-variable-button-face
2362 :sample-face
'custom-variable-tag-face
2366 (push (widget-create-child-and-convert
2368 :help-echo
"Hide the value of this option."
2371 :action
'custom-toggle-parent
2374 (push (widget-create-child-and-convert
2376 :format value-format
2379 (unless (eq custom-buffer-style
'tree
)
2380 (unless (eq (preceding-char) ?
\n)
2381 (widget-insert "\n"))
2382 ;; Create the magic button.
2383 (let ((magic (widget-create-child-and-convert
2384 widget
'custom-magic nil
)))
2385 (widget-put widget
:custom-magic magic
)
2386 (push magic buttons
))
2387 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2388 ;; before the call to `widget-default-format-handler'. Otherwise, I
2389 ;; loose my current `buttons'. This function shouldn't be called like
2390 ;; this anyway. The doc string widget should be added like the others.
2392 (widget-put widget
:buttons buttons
)
2394 ;; Insert documentation.
2395 (widget-default-format-handler widget ?h
)
2397 ;; The comment field
2398 (unless (eq state
'hidden
)
2399 (let* ((comment (get symbol
'variable-comment
))
2401 (widget-create-child-and-convert
2402 widget
'custom-comment
2404 :value
(or comment
""))))
2405 (widget-put widget
:comment-widget comment-widget
)
2406 ;; Don't push it !!! Custom assumes that the first child is the
2408 (setq children
(append children
(list comment-widget
)))))
2409 ;; Update the rest of the properties properties.
2410 (widget-put widget
:custom-form form
)
2411 (widget-put widget
:children children
)
2412 ;; Now update the state.
2413 (if (eq state
'hidden
)
2414 (widget-put widget
:custom-state state
)
2415 (custom-variable-state-set widget
))
2417 (unless (eq state
'hidden
)
2418 (when (eq (widget-get widget
:custom-level
) 1)
2419 (custom-add-parent-links widget
))
2420 (custom-add-see-also widget
)))))
2422 (defun custom-tag-action (widget &rest args
)
2423 "Pass :action to first child of WIDGET's parent."
2424 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2427 (defun custom-tag-mouse-down-action (widget &rest args
)
2428 "Pass :mouse-down-action to first child of WIDGET's parent."
2429 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2430 :mouse-down-action args
))
2432 (defun custom-variable-state-set (widget)
2433 "Set the state of WIDGET."
2434 (let* ((symbol (widget-value widget
))
2435 (get (or (get symbol
'custom-get
) 'default-value
))
2436 (value (if (default-boundp symbol
)
2437 (funcall get symbol
)
2438 (widget-get widget
:value
)))
2439 (comment (get symbol
'variable-comment
))
2442 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2444 (get symbol
'customized-variable-comment
))
2446 (if (condition-case nil
2447 (and (equal value
(eval (car tmp
)))
2448 (equal comment temp
))
2452 ((progn (setq tmp
(get symbol
'saved-value
))
2453 (setq temp
(get symbol
'saved-variable-comment
))
2455 (if (condition-case nil
2456 (and (equal value
(eval (car tmp
)))
2457 (equal comment temp
))
2461 ((setq tmp
(get symbol
'standard-value
))
2462 (if (condition-case nil
2463 (and (equal value
(eval (car tmp
)))
2464 (equal comment nil
))
2469 (widget-put widget
:custom-state state
)))
2471 (defun custom-variable-standard-value (widget)
2472 (get (widget-value widget
) 'standard-value
))
2474 (defvar custom-variable-menu
2475 '(("Set for Current Session" custom-variable-set
2477 (eq (widget-get widget
:custom-state
) 'modified
)))
2478 ("Save for Future Sessions" custom-variable-save
2480 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))
2481 ("Reset to Current" custom-redraw
2483 (and (default-boundp (widget-value widget
))
2484 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2485 ("Reset to Saved" custom-variable-reset-saved
2487 (and (or (get (widget-value widget
) 'saved-value
)
2488 (get (widget-value widget
) 'saved-variable-comment
))
2489 (memq (widget-get widget
:custom-state
)
2490 '(modified set changed rogue
)))))
2491 ("Erase Customization" custom-variable-reset-standard
2493 (and (get (widget-value widget
) 'standard-value
)
2494 (memq (widget-get widget
:custom-state
)
2495 '(modified set changed saved rogue
)))))
2496 ("Use Backup Value" custom-variable-reset-backup
2498 (get (widget-value widget
) 'backup-value
)))
2499 ("---" ignore ignore
)
2500 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2501 ("---" ignore ignore
)
2502 ("Don't show as Lisp expression" custom-variable-edit
2504 (eq (widget-get widget
:custom-form
) 'lisp
)))
2505 ("Show initial Lisp expression" custom-variable-edit-lisp
2507 (eq (widget-get widget
:custom-form
) 'edit
))))
2508 "Alist of actions for the `custom-variable' widget.
2509 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2510 the menu entry, ACTION is the function to call on the widget when the
2511 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2512 widget as an argument, and returns non-nil if ACTION is valid on that
2513 widget. If FILTER is nil, ACTION is always valid.")
2515 (defun custom-variable-action (widget &optional event
)
2516 "Show the menu for `custom-variable' WIDGET.
2517 Optional EVENT is the location for the menu."
2518 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2519 (custom-toggle-hide widget
)
2520 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2521 (custom-variable-state-set widget
))
2522 (custom-redraw-magic widget
)
2523 (let* ((completion-ignore-case t
)
2524 (answer (widget-choose (concat "Operation on "
2525 (custom-unlispify-tag-name
2526 (widget-get widget
:value
)))
2527 (custom-menu-filter custom-variable-menu
2531 (funcall answer widget
)))))
2533 (defun custom-variable-edit (widget)
2534 "Edit value of WIDGET."
2535 (widget-put widget
:custom-state
'unknown
)
2536 (widget-put widget
:custom-form
'edit
)
2537 (custom-redraw widget
))
2539 (defun custom-variable-edit-lisp (widget)
2540 "Edit the Lisp representation of the value of WIDGET."
2541 (widget-put widget
:custom-state
'unknown
)
2542 (widget-put widget
:custom-form
'lisp
)
2543 (custom-redraw widget
))
2545 (defun custom-variable-set (widget)
2546 "Set the current value for the variable being edited by WIDGET."
2547 (let* ((form (widget-get widget
:custom-form
))
2548 (state (widget-get widget
:custom-state
))
2549 (child (car (widget-get widget
:children
)))
2550 (symbol (widget-value widget
))
2551 (set (or (get symbol
'custom-set
) 'set-default
))
2552 (comment-widget (widget-get widget
:comment-widget
))
2553 (comment (widget-value comment-widget
))
2555 (cond ((eq state
'hidden
)
2556 (error "Cannot set hidden variable"))
2557 ((setq val
(widget-apply child
:validate
))
2558 (goto-char (widget-get val
:from
))
2559 (error "%s" (widget-get val
:error
)))
2560 ((memq form
'(lisp mismatch
))
2561 (when (equal comment
"")
2563 ;; Make the comment invisible by hand if it's empty
2564 (custom-comment-hide comment-widget
))
2565 (custom-variable-backup-value widget
)
2566 (funcall set symbol
(eval (setq val
(widget-value child
))))
2567 (put symbol
'customized-value
(list val
))
2568 (put symbol
'variable-comment comment
)
2569 (put symbol
'customized-variable-comment comment
))
2571 (when (equal comment
"")
2573 ;; Make the comment invisible by hand if it's empty
2574 (custom-comment-hide comment-widget
))
2575 (custom-variable-backup-value widget
)
2576 (funcall set symbol
(setq val
(widget-value child
)))
2577 (put symbol
'customized-value
(list (custom-quote val
)))
2578 (put symbol
'variable-comment comment
)
2579 (put symbol
'customized-variable-comment comment
)))
2580 (custom-variable-state-set widget
)
2581 (custom-redraw-magic widget
)))
2583 (defun custom-variable-save (widget)
2584 "Set and save the value for the variable being edited by WIDGET."
2585 (let* ((form (widget-get widget
:custom-form
))
2586 (state (widget-get widget
:custom-state
))
2587 (child (car (widget-get widget
:children
)))
2588 (symbol (widget-value widget
))
2589 (set (or (get symbol
'custom-set
) 'set-default
))
2590 (comment-widget (widget-get widget
:comment-widget
))
2591 (comment (widget-value comment-widget
))
2593 (cond ((eq state
'hidden
)
2594 (error "Cannot set hidden variable"))
2595 ((setq val
(widget-apply child
:validate
))
2596 (goto-char (widget-get val
:from
))
2597 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2598 ((memq form
'(lisp mismatch
))
2599 (when (equal comment
"")
2601 ;; Make the comment invisible by hand if it's empty
2602 (custom-comment-hide comment-widget
))
2603 (put symbol
'saved-value
(list (widget-value child
)))
2604 (custom-push-theme 'theme-value symbol
'user
2605 'set
(list (widget-value child
)))
2606 (funcall set symbol
(eval (widget-value child
)))
2607 (put symbol
'variable-comment comment
)
2608 (put symbol
'saved-variable-comment comment
))
2610 (when (equal comment
"")
2612 ;; Make the comment invisible by hand if it's empty
2613 (custom-comment-hide comment-widget
))
2614 (put symbol
'saved-value
2615 (list (custom-quote (widget-value child
))))
2616 (custom-push-theme 'theme-value symbol
'user
2617 'set
(list (custom-quote (widget-value
2619 (funcall set symbol
(widget-value child
))
2620 (put symbol
'variable-comment comment
)
2621 (put symbol
'saved-variable-comment comment
)))
2622 (put symbol
'customized-value nil
)
2623 (put symbol
'customized-variable-comment nil
)
2625 (custom-variable-state-set widget
)
2626 (custom-redraw-magic widget
)))
2628 (defun custom-variable-reset-saved (widget)
2629 "Restore the saved value for the variable being edited by WIDGET.
2630 The value that was current before this operation
2631 becomes the backup value, so you can get it again."
2632 (let* ((symbol (widget-value widget
))
2633 (set (or (get symbol
'custom-set
) 'set-default
))
2634 (value (get symbol
'saved-value
))
2635 (comment (get symbol
'saved-variable-comment
)))
2636 (cond ((or value comment
)
2637 (put symbol
'variable-comment comment
)
2638 (custom-variable-backup-value widget
)
2640 (funcall set symbol
(eval (car value
)))
2643 (error "No saved value for %s" symbol
)))
2644 (put symbol
'customized-value nil
)
2645 (put symbol
'customized-variable-comment nil
)
2646 (widget-put widget
:custom-state
'unknown
)
2647 ;; This call will possibly make the comment invisible
2648 (custom-redraw widget
)))
2650 (defun custom-variable-reset-standard (widget)
2651 "Restore the standard setting for the variable being edited by WIDGET.
2652 This operation eliminates any saved setting for the variable,
2653 restoring it to the state of a variable that has never been customized.
2654 The value that was current before this operation
2655 becomes the backup value, so you can get it again."
2656 (let* ((symbol (widget-value widget
))
2657 (set (or (get symbol
'custom-set
) 'set-default
)))
2658 (if (get symbol
'standard-value
)
2660 (custom-variable-backup-value widget
)
2661 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2662 (error "No standard setting known for %S" symbol
))
2663 (put symbol
'variable-comment nil
)
2664 (put symbol
'customized-value nil
)
2665 (put symbol
'customized-variable-comment nil
)
2666 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2667 (put symbol
'saved-value nil
)
2668 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2669 ;; As a special optimizations we do not (explictly)
2670 ;; save resets to standard when no theme set the value.
2671 (if (null (cdr (get symbol
'theme-value
)))
2672 (put symbol
'theme-value nil
))
2673 (put symbol
'saved-variable-comment nil
)
2675 (widget-put widget
:custom-state
'unknown
)
2676 ;; This call will possibly make the comment invisible
2677 (custom-redraw widget
)))
2679 (defun custom-variable-backup-value (widget)
2680 "Back up the current value for WIDGET's variable.
2681 The backup value is kept in the car of the `backup-value' property."
2682 (let* ((symbol (widget-value widget
))
2683 (get (or (get symbol
'custom-get
) 'default-value
))
2684 (type (custom-variable-type symbol
))
2685 (conv (widget-convert type
))
2686 (value (if (default-boundp symbol
)
2687 (funcall get symbol
)
2688 (widget-get conv
:value
))))
2689 (put symbol
'backup-value
(list value
))))
2691 (defun custom-variable-reset-backup (widget)
2692 "Restore the backup value for the variable being edited by WIDGET.
2693 The value that was current before this operation
2694 becomes the backup value, so you can use this operation repeatedly
2695 to switch between two values."
2696 (let* ((symbol (widget-value widget
))
2697 (set (or (get symbol
'custom-set
) 'set-default
))
2698 (value (get symbol
'backup-value
))
2699 (comment-widget (widget-get widget
:comment-widget
))
2700 (comment (widget-value comment-widget
)))
2703 (custom-variable-backup-value widget
)
2705 (funcall set symbol
(car value
))
2707 (error "No backup value for %s" symbol
))
2708 (put symbol
'customized-value
(list (car value
)))
2709 (put symbol
'variable-comment comment
)
2710 (put symbol
'customized-variable-comment comment
)
2711 (custom-variable-state-set widget
)
2712 ;; This call will possibly make the comment invisible
2713 (custom-redraw widget
)))
2715 ;;; The `custom-face-edit' Widget.
2717 (define-widget 'custom-face-edit
'checklist
2718 "Edit face attributes."
2722 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2723 :value-to-internal
'custom-face-edit-fix-value
2724 :match
(lambda (widget value
)
2725 (widget-checklist-match widget
2726 (custom-face-edit-fix-value widget value
)))
2727 :convert-widget
'custom-face-edit-convert-widget
2728 :args
(mapcar (lambda (att)
2731 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2732 (list 'const
:format
"" :value
(nth 0 att
))
2734 custom-face-attributes
))
2736 (defun custom-face-edit-fix-value (widget value
)
2737 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2738 Also change :reverse-video to :inverse-video."
2742 (let ((key (car value
))
2743 (val (car (cdr value
))))
2744 (cond ((eq key
:italic
)
2745 (push :slant result
)
2746 (push (if val
'italic
'normal
) result
))
2748 (push :weight result
)
2749 (push (if val
'bold
'normal
) result
))
2750 ((eq key
:reverse-video
)
2751 (push :inverse-video result
)
2755 (push val result
))))
2756 (setq value
(cdr (cdr value
))))
2757 (setq result
(nreverse result
))
2761 (defun custom-face-edit-convert-widget (widget)
2762 "Convert :args as widget types in WIDGET."
2765 :args
(mapcar (lambda (arg)
2767 :deactivate
'custom-face-edit-deactivate
2768 :activate
'custom-face-edit-activate
2769 :delete
'custom-face-edit-delete
))
2770 (widget-get widget
:args
)))
2773 (defun custom-face-edit-deactivate (widget)
2774 "Make face widget WIDGET inactive for user modifications."
2775 (unless (widget-get widget
:inactive
)
2776 (let ((tag (custom-face-edit-attribute-tag widget
))
2777 (from (copy-marker (widget-get widget
:from
)))
2778 (value (widget-value widget
))
2779 (inhibit-read-only t
)
2780 (inhibit-modification-hooks t
))
2783 (widget-default-delete widget
)
2784 (insert tag
": *\n")
2785 (widget-put widget
:inactive
2786 (cons value
(cons from
(- (point) from
))))))))
2788 (defun custom-face-edit-activate (widget)
2789 "Make face widget WIDGET inactive for user modifications."
2790 (let ((inactive (widget-get widget
:inactive
))
2791 (inhibit-read-only t
)
2792 (inhibit-modification-hooks t
))
2793 (when (consp inactive
)
2795 (goto-char (car (cdr inactive
)))
2796 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2797 (widget-put widget
:inactive nil
)
2798 (widget-apply widget
:create
)
2799 (widget-value-set widget
(car inactive
))
2802 (defun custom-face-edit-delete (widget)
2803 "Remove WIDGET from the buffer."
2804 (let ((inactive (widget-get widget
:inactive
))
2805 (inhibit-read-only t
)
2806 (inhibit-modification-hooks t
))
2808 ;; Widget is alive, we don't have to do anything special
2809 (widget-default-delete widget
)
2810 ;; WIDGET is already deleted because we did so to inactivate it;
2811 ;; now just get rid of the label we put in its place.
2812 (delete-region (car (cdr inactive
))
2813 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2814 (widget-put widget
:inactive nil
))))
2817 (defun custom-face-edit-attribute-tag (widget)
2818 "Returns the first :tag property in WIDGET or one of its children."
2819 (let ((tag (widget-get widget
:tag
)))
2820 (or (and (not (equal tag
"")) tag
)
2821 (let ((children (widget-get widget
:children
)))
2822 (while (and (null tag
) children
)
2823 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2826 ;;; The `custom-display' Widget.
2828 (define-widget 'custom-display
'menu-choice
2829 "Select a display type."
2832 :help-echo
"Specify frames where the face attributes should be used."
2833 :args
'((const :tag
"all" t
)
2834 (const :tag
"defaults" default
)
2838 :args
((group :sibling-args
(:help-echo
"\
2839 Only match the specified window systems.")
2840 (const :format
"Type: "
2842 (checklist :inline t
2845 :sibling-args
(:help-echo
"\
2846 The X11 Window System.")
2848 (const :format
"PM "
2849 :sibling-args
(:help-echo
"\
2850 OS/2 Presentation Manager.")
2852 (const :format
"W32 "
2853 :sibling-args
(:help-echo
"\
2856 (const :format
"MAC "
2857 :sibling-args
(:help-echo
"\
2860 (const :format
"DOS "
2861 :sibling-args
(:help-echo
"\
2864 (const :format
"TTY%n"
2865 :sibling-args
(:help-echo
"\
2866 Plain text terminals.")
2868 (group :sibling-args
(:help-echo
"\
2869 Only match the frames with the specified color support.")
2870 (const :format
"Class: "
2872 (checklist :inline t
2874 (const :format
"Color "
2875 :sibling-args
(:help-echo
"\
2876 Match color frames.")
2878 (const :format
"Grayscale "
2879 :sibling-args
(:help-echo
"\
2880 Match grayscale frames.")
2882 (const :format
"Monochrome%n"
2883 :sibling-args
(:help-echo
"\
2884 Match frames with no color support.")
2886 (group :sibling-args
(:help-echo
"\
2887 The minimum number of colors the frame should support.")
2888 (const :format
"" min-colors
)
2889 (integer :tag
"Minimum number of colors" ))
2890 (group :sibling-args
(:help-echo
"\
2891 Only match frames with the specified intensity.")
2893 Background brightness: "
2895 (checklist :inline t
2897 (const :format
"Light "
2898 :sibling-args
(:help-echo
"\
2899 Match frames with light backgrounds.")
2901 (const :format
"Dark\n"
2902 :sibling-args
(:help-echo
"\
2903 Match frames with dark backgrounds.")
2905 (group :sibling-args
(:help-echo
"\
2906 Only match frames that support the specified face attributes.")
2907 (const :format
"Supports attributes:" supports
)
2908 (custom-face-edit :inline t
:format
"%n%v"))))))
2910 ;;; The `custom-face' Widget.
2912 (defface custom-face-tag
2913 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
2914 "Face used for face tags."
2915 :group
'custom-faces
)
2916 ;; backward-compatibility alias
2917 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
2919 (defcustom custom-face-default-form
'selected
2920 "Default form of displaying face definition."
2921 :type
'(choice (const all
)
2924 :group
'custom-buffer
2927 (define-widget 'custom-face
'custom
2929 :sample-face
'custom-face-tag-face
2930 :help-echo
"Set or reset this face."
2931 :documentation-property
#'face-doc-string
2932 :value-create
'custom-face-value-create
2933 :action
'custom-face-action
2934 :custom-category
'face
2935 :custom-form nil
; defaults to value of `custom-face-default-form'
2936 :custom-set
'custom-face-set
2937 :custom-save
'custom-face-save
2938 :custom-reset-current
'custom-redraw
2939 :custom-reset-saved
'custom-face-reset-saved
2940 :custom-reset-standard
'custom-face-reset-standard
2941 :custom-standard-value
'custom-face-standard-value
2942 :custom-menu
'custom-face-menu-create
)
2944 (define-widget 'custom-face-all
'editable-list
2945 "An editable list of display specifications and attributes."
2946 :entry-format
"%i %d %v"
2947 :insert-button-args
'(:help-echo
"Insert new display specification here.")
2948 :append-button-args
'(:help-echo
"Append new display specification here.")
2949 :delete-button-args
'(:help-echo
"Delete this display specification.")
2950 :args
'((group :format
"%v" custom-display custom-face-edit
)))
2952 (defconst custom-face-all
(widget-convert 'custom-face-all
)
2953 "Converted version of the `custom-face-all' widget.")
2955 (define-widget 'custom-display-unselected
'item
2956 "A display specification that doesn't match the selected display."
2957 :match
'custom-display-unselected-match
)
2959 (defun custom-display-unselected-match (widget value
)
2960 "Non-nil if VALUE is an unselected display specification."
2961 (not (face-spec-set-match-display value
(selected-frame))))
2963 (define-widget 'custom-face-selected
'group
2964 "Edit the attributes of the selected display in a face specification."
2965 :args
'((choice :inline t
2966 (group :tag
"With Defaults" :inline t
2967 (group (const :tag
"" default
)
2968 (custom-face-edit :tag
" Default\n Attributes"))
2971 (group custom-display-unselected sexp
))
2972 (group (sexp :format
"")
2973 (custom-face-edit :tag
" Overriding\n Attributes"))
2977 (group :tag
"No Defaults" :inline t
2980 (group custom-display-unselected sexp
))
2981 (group (sexp :format
"")
2982 (custom-face-edit :tag
"\n Attributes"))
2989 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
2990 "Converted version of the `custom-face-selected' widget.")
2992 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
2993 "Return a canonicalized version of SPEC using.
2994 FILTER-INDEX is the index in the entry for each attribute in
2995 `custom-face-attributes' at which the appropriate filter function can be
2996 found, and DEFAULT-FILTER is the filter to apply for attributes that
2998 (mapcar (lambda (entry)
2999 ;; Filter a single face-spec entry
3000 (let ((tests (car entry
))
3002 ;; Handle both old- and new-style attribute syntax
3003 (if (listp (car (cdr entry
)))
3006 (filtered-attrs nil
))
3007 ;; Filter each face attribute
3008 (while unfiltered-attrs
3009 (let* ((attr (pop unfiltered-attrs
))
3010 (pre-filtered-value (pop unfiltered-attrs
))
3012 (or (nth filter-index
(assq attr custom-face-attributes
))
3016 (funcall filter pre-filtered-value
)
3017 pre-filtered-value
)))
3018 (push filtered-value filtered-attrs
)
3019 (push attr filtered-attrs
)))
3021 (list tests filtered-attrs
)))
3024 (defun custom-pre-filter-face-spec (spec)
3025 "Return SPEC changed as necessary for editing by the face customization widget.
3026 SPEC must be a full face spec."
3027 (custom-filter-face-spec spec
2))
3029 (defun custom-post-filter-face-spec (spec)
3030 "Return the customized SPEC in a form suitable for setting the face."
3031 (custom-filter-face-spec spec
3))
3033 (defun custom-face-value-create (widget)
3034 "Create a list of the display specifications for WIDGET."
3035 (let ((buttons (widget-get widget
:buttons
))
3037 (symbol (widget-get widget
:value
))
3038 (tag (widget-get widget
:tag
))
3039 (state (widget-get widget
:custom-state
))
3041 (is-last (widget-get widget
:custom-last
))
3042 (prefix (widget-get widget
:custom-prefix
)))
3044 (setq tag
(prin1-to-string symbol
)))
3045 (cond ((eq custom-buffer-style
'tree
)
3046 (insert prefix
(if is-last
" `--- " " |--- "))
3047 (push (widget-create-child-and-convert
3048 widget
'custom-browse-face-tag
)
3050 (insert " " tag
"\n")
3051 (widget-put widget
:buttons buttons
))
3055 (widget-specify-sample widget begin
(point))
3056 (if (eq custom-buffer-style
'face
)
3058 (if (string-match "face\\'" tag
)
3060 (insert " face: ")))
3062 (push (widget-create-child-and-convert widget
'item
3069 (push (widget-create-child-and-convert
3071 :help-echo
"Hide or show this face."
3074 :action
'custom-toggle-parent
3075 (not (eq state
'hidden
)))
3079 (let ((magic (widget-create-child-and-convert
3080 widget
'custom-magic nil
)))
3081 (widget-put widget
:custom-magic magic
)
3082 (push magic buttons
))
3084 (widget-put widget
:buttons buttons
)
3085 ;; Insert documentation.
3086 (widget-default-format-handler widget ?h
)
3087 ;; The comment field
3088 (unless (eq state
'hidden
)
3089 (let* ((comment (get symbol
'face-comment
))
3091 (widget-create-child-and-convert
3092 widget
'custom-comment
3094 :value
(or comment
""))))
3095 (widget-put widget
:comment-widget comment-widget
)
3096 (push comment-widget children
)))
3098 (unless (eq state
'hidden
)
3099 (when (eq (widget-get widget
:custom-level
) 1)
3100 (custom-add-parent-links widget
))
3101 (custom-add-see-also widget
))
3103 (unless (eq (preceding-char) ?
\n)
3105 (unless (eq state
'hidden
)
3106 (message "Creating face editor...")
3107 (custom-load-widget widget
)
3108 (unless (widget-get widget
:custom-form
)
3109 (widget-put widget
:custom-form custom-face-default-form
))
3110 (let* ((symbol (widget-value widget
))
3111 (spec (or (get symbol
'customized-face
)
3112 (get symbol
'saved-face
)
3113 (get symbol
'face-defface-spec
)
3114 ;; Attempt to construct it.
3115 (list (list t
(custom-face-attributes-get
3116 symbol
(selected-frame))))))
3117 (form (widget-get widget
:custom-form
))
3118 (indent (widget-get widget
:indent
))
3120 ;; If the user has changed this face in some other way,
3121 ;; edit it as the user has specified it.
3122 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3123 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3124 (setq spec
(custom-pre-filter-face-spec spec
))
3125 (setq edit
(widget-create-child-and-convert
3127 (cond ((and (eq form
'selected
)
3128 (widget-apply custom-face-selected
3130 (when indent
(insert-char ?\ indent
))
3131 'custom-face-selected
)
3132 ((and (not (eq form
'lisp
))
3133 (widget-apply custom-face-all
3137 (when indent
(insert-char ?\ indent
))
3140 (custom-face-state-set widget
)
3141 (push edit children
)
3142 (widget-put widget
:children children
))
3143 (message "Creating face editor...done"))))))
3145 (defvar custom-face-menu
3146 '(("Set for Current Session" custom-face-set
)
3147 ("Save for Future Sessions" custom-face-save-command
)
3148 ("Reset to Saved" custom-face-reset-saved
3150 (or (get (widget-value widget
) 'saved-face
)
3151 (get (widget-value widget
) 'saved-face-comment
))))
3152 ("Erase Customization" custom-face-reset-standard
3154 (get (widget-value widget
) 'face-defface-spec
)))
3155 ("---" ignore ignore
)
3156 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3157 ("---" ignore ignore
)
3158 ("Show all display specs" custom-face-edit-all
3160 (not (eq (widget-get widget
:custom-form
) 'all
))))
3161 ("Just current attributes" custom-face-edit-selected
3163 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3164 ("Show as Lisp expression" custom-face-edit-lisp
3166 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3167 "Alist of actions for the `custom-face' widget.
3168 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3169 the menu entry, ACTION is the function to call on the widget when the
3170 menu is selected, and FILTER is a predicate which takes a `custom-face'
3171 widget as an argument, and returns non-nil if ACTION is valid on that
3172 widget. If FILTER is nil, ACTION is always valid.")
3174 (defun custom-face-edit-selected (widget)
3175 "Edit selected attributes of the value of WIDGET."
3176 (widget-put widget
:custom-state
'unknown
)
3177 (widget-put widget
:custom-form
'selected
)
3178 (custom-redraw widget
))
3180 (defun custom-face-edit-all (widget)
3181 "Edit all attributes of the value of WIDGET."
3182 (widget-put widget
:custom-state
'unknown
)
3183 (widget-put widget
:custom-form
'all
)
3184 (custom-redraw widget
))
3186 (defun custom-face-edit-lisp (widget)
3187 "Edit the Lisp representation of the value of WIDGET."
3188 (widget-put widget
:custom-state
'unknown
)
3189 (widget-put widget
:custom-form
'lisp
)
3190 (custom-redraw widget
))
3192 (defun custom-face-state-set (widget)
3193 "Set the state of WIDGET."
3194 (let* ((symbol (widget-value widget
))
3195 (comment (get symbol
'face-comment
))
3199 (setq tmp
(get symbol
'customized-face
))
3200 (setq temp
(get symbol
'customized-face-comment
))
3202 (if (equal temp comment
)
3206 (setq tmp
(get symbol
'saved-face
))
3207 (setq temp
(get symbol
'saved-face-comment
))
3209 (if (equal temp comment
)
3212 ((get symbol
'face-defface-spec
)
3213 (if (equal comment nil
)
3218 ;; If the user called set-face-attribute to change the default
3219 ;; for new frames, this face is "set outside of Customize".
3220 (if (and (not (eq state
'rogue
))
3221 (get symbol
'face-modified
))
3222 (setq state
'changed
))
3223 (widget-put widget
:custom-state state
)))
3225 (defun custom-face-action (widget &optional event
)
3226 "Show the menu for `custom-face' WIDGET.
3227 Optional EVENT is the location for the menu."
3228 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3229 (custom-toggle-hide widget
)
3230 (let* ((completion-ignore-case t
)
3231 (symbol (widget-get widget
:value
))
3232 (answer (widget-choose (concat "Operation on "
3233 (custom-unlispify-tag-name symbol
))
3234 (custom-menu-filter custom-face-menu
3238 (funcall answer widget
)))))
3240 (defun custom-face-set (widget)
3241 "Make the face attributes in WIDGET take effect."
3242 (let* ((symbol (widget-value widget
))
3243 (child (car (widget-get widget
:children
)))
3244 (value (custom-post-filter-face-spec (widget-value child
)))
3245 (comment-widget (widget-get widget
:comment-widget
))
3246 (comment (widget-value comment-widget
)))
3247 (when (equal comment
"")
3249 ;; Make the comment invisible by hand if it's empty
3250 (custom-comment-hide comment-widget
))
3251 (put symbol
'customized-face value
)
3252 (if (face-spec-choose value
)
3253 (face-spec-set symbol value
)
3254 ;; face-set-spec ignores empty attribute lists, so just give it
3255 ;; something harmless instead.
3256 (face-spec-set symbol
'((t :foreground unspecified
))))
3257 (put symbol
'customized-face-comment comment
)
3258 (put symbol
'face-comment comment
)
3259 (custom-face-state-set widget
)
3260 (custom-redraw-magic widget
)))
3262 (defun custom-face-save-command (widget)
3263 "Save in `.emacs' the face attributes in WIDGET."
3264 (custom-face-save widget
)
3267 (defun custom-face-save (widget)
3268 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3269 (let* ((symbol (widget-value widget
))
3270 (child (car (widget-get widget
:children
)))
3271 (value (custom-post-filter-face-spec (widget-value child
)))
3272 (comment-widget (widget-get widget
:comment-widget
))
3273 (comment (widget-value comment-widget
)))
3274 (when (equal comment
"")
3276 ;; Make the comment invisible by hand if it's empty
3277 (custom-comment-hide comment-widget
))
3278 (if (face-spec-choose value
)
3279 (face-spec-set symbol value
)
3280 ;; face-set-spec ignores empty attribute lists, so just give it
3281 ;; something harmless instead.
3282 (face-spec-set symbol
'((t :foreground unspecified
))))
3283 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3284 (put symbol
'saved-face value
))
3285 (custom-push-theme 'theme-face symbol
'user
'set value
)
3286 (put symbol
'customized-face nil
)
3287 (put symbol
'face-comment comment
)
3288 (put symbol
'customized-face-comment nil
)
3289 (put symbol
'saved-face-comment comment
)
3291 (custom-face-state-set widget
)
3292 (custom-redraw-magic widget
)))
3294 (defun custom-face-reset-saved (widget)
3295 "Restore WIDGET to the face's default attributes."
3296 (let* ((symbol (widget-value widget
))
3297 (child (car (widget-get widget
:children
)))
3298 (value (get symbol
'saved-face
))
3299 (comment (get symbol
'saved-face-comment
))
3300 (comment-widget (widget-get widget
:comment-widget
)))
3301 (unless (or value comment
)
3302 (error "No saved value for this face"))
3303 (put symbol
'customized-face nil
)
3304 (put symbol
'customized-face-comment nil
)
3305 (face-spec-set symbol value
)
3306 (put symbol
'face-comment comment
)
3307 (widget-value-set child value
)
3308 ;; This call manages the comment visibility
3309 (widget-value-set comment-widget
(or comment
""))
3310 (custom-face-state-set widget
)
3311 (custom-redraw-magic widget
)))
3313 (defun custom-face-standard-value (widget)
3314 (get (widget-value widget
) 'face-defface-spec
))
3316 (defun custom-face-reset-standard (widget)
3317 "Restore WIDGET to the face's standard settings.
3318 This operation eliminates any saved setting for the face,
3319 restoring it to the state of a face that has never been customized."
3320 (let* ((symbol (widget-value widget
))
3321 (child (car (widget-get widget
:children
)))
3322 (value (get symbol
'face-defface-spec
))
3323 (comment-widget (widget-get widget
:comment-widget
)))
3325 (error "No standard setting for this face"))
3326 (put symbol
'customized-face nil
)
3327 (put symbol
'customized-face-comment nil
)
3328 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3329 (put symbol
'saved-face nil
)
3330 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3331 ;; Do not explictly save resets to standards without themes.
3332 (if (null (cdr (get symbol
'theme-face
)))
3333 (put symbol
'theme-face nil
))
3334 (put symbol
'saved-face-comment nil
)
3336 (face-spec-set symbol value
)
3337 (put symbol
'face-comment nil
)
3338 (widget-value-set child value
)
3339 ;; This call manages the comment visibility
3340 (widget-value-set comment-widget
"")
3341 (custom-face-state-set widget
)
3342 (custom-redraw-magic widget
)))
3344 ;;; The `face' Widget.
3346 (defvar widget-face-prompt-value-history nil
3347 "History of input to `widget-face-prompt-value'.")
3349 (define-widget 'face
'symbol
3350 "A Lisp face name (with sample)."
3351 :format
"%t: (%{sample%}) %v"
3354 :sample-face-get
'widget-face-sample-face-get
3355 :notify
'widget-face-notify
3356 :match
(lambda (widget value
) (facep value
))
3357 :complete-function
(lambda ()
3359 (lisp-complete-symbol 'facep
))
3360 :prompt-match
'facep
3361 :prompt-history
'widget-face-prompt-value-history
3362 :validate
(lambda (widget)
3363 (unless (facep (widget-value widget
))
3365 :error
(format "Invalid face: %S"
3366 (widget-value widget
)))
3369 (defun widget-face-sample-face-get (widget)
3370 (let ((value (widget-value widget
)))
3375 (defun widget-face-notify (widget child
&optional event
)
3376 "Update the sample, and notify the parent."
3377 (overlay-put (widget-get widget
:sample-overlay
)
3378 'face
(widget-apply widget
:sample-face-get
))
3379 (widget-default-notify widget child event
))
3382 ;;; The `hook' Widget.
3384 (define-widget 'hook
'list
3386 :value-to-internal
(lambda (widget value
)
3387 (if (and value
(symbolp value
))
3390 :match
(lambda (widget value
)
3392 (widget-group-match widget value
)))
3393 ;; Avoid adding undefined functions to the hook, especially for
3394 ;; things like `find-file-hook' or even more basic ones, to avoid
3396 :set
(lambda (symbol value
)
3399 (add-hook symbol elt
))))
3400 :convert-widget
'custom-hook-convert-widget
3403 (defun custom-hook-convert-widget (widget)
3404 ;; Handle `:options'.
3405 (let* ((options (widget-get widget
:options
))
3406 (other `(editable-list :inline t
3407 :entry-format
"%i %d%v"
3408 (function :format
" %v")))
3410 (list `(checklist :inline t
3411 ,@(mapcar (lambda (entry)
3412 `(function-item ,entry
))
3416 (widget-put widget
:args args
)
3419 ;;; The `custom-group-link' Widget.
3421 (define-widget 'custom-group-link
'link
3422 "Show parent in other window when activated."
3423 :help-echo
"Create customization buffer for this group."
3424 :action
'custom-group-link-action
)
3426 (defun custom-group-link-action (widget &rest ignore
)
3427 (customize-group (widget-value widget
)))
3429 ;;; The `custom-group' Widget.
3431 (defcustom custom-group-tag-faces nil
3432 ;; In XEmacs, this ought to play games with font size.
3433 ;; Fixme: make it do so in Emacs.
3434 "Face used for group tags.
3435 The first member is used for level 1 groups, the second for level 2,
3436 and so forth. The remaining group tags are shown with `custom-group-tag'."
3437 :type
'(repeat face
)
3438 :group
'custom-faces
)
3440 (defface custom-group-tag-1
3443 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3444 (((min-colors 88) (class color
)
3446 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3449 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3451 "Face used for group tags."
3452 :group
'custom-faces
)
3453 ;; backward-compatibility alias
3454 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3456 (defface custom-group-tag
3459 (:foreground
"light blue" :weight bold
:height
1.2))
3460 (((min-colors 88) (class color
)
3462 (:foreground
"blue1" :weight bold
:height
1.2))
3465 (:foreground
"blue" :weight bold
:height
1.2))
3467 "Face used for low level group tags."
3468 :group
'custom-faces
)
3469 ;; backward-compatibility alias
3470 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3472 (define-widget 'custom-group
'custom
3475 :sample-face-get
'custom-group-sample-face-get
3476 :documentation-property
'group-documentation
3477 :help-echo
"Set or reset all members of this group."
3478 :value-create
'custom-group-value-create
3479 :action
'custom-group-action
3480 :custom-category
'group
3481 :custom-set
'custom-group-set
3482 :custom-save
'custom-group-save
3483 :custom-reset-current
'custom-group-reset-current
3484 :custom-reset-saved
'custom-group-reset-saved
3485 :custom-reset-standard
'custom-group-reset-standard
3486 :custom-menu
'custom-group-menu-create
)
3488 (defun custom-group-sample-face-get (widget)
3489 ;; Use :sample-face.
3490 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3493 (define-widget 'custom-group-visibility
'visibility
3494 "An indicator and manipulator for hidden group contents."
3495 :create
'custom-group-visibility-create
)
3497 (defun custom-group-visibility-create (widget)
3498 (let ((visible (widget-value widget
)))
3500 (insert "--------")))
3501 (widget-default-create widget
))
3503 (defun custom-group-members (symbol groups-only
)
3504 "Return SYMBOL's custom group members.
3505 If GROUPS-ONLY non-nil, return only those members that are groups."
3506 (if (not groups-only
)
3507 (get symbol
'custom-group
)
3509 (dolist (entry (get symbol
'custom-group
))
3510 (when (eq (nth 1 entry
) 'custom-group
)
3511 (push entry members
)))
3512 (nreverse members
))))
3514 (defun custom-group-value-create (widget)
3515 "Insert a customize group for WIDGET in the current buffer."
3516 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3517 (custom-load-widget widget
))
3518 (let* ((state (widget-get widget
:custom-state
))
3519 (level (widget-get widget
:custom-level
))
3520 ;; (indent (widget-get widget :indent))
3521 (prefix (widget-get widget
:custom-prefix
))
3522 (buttons (widget-get widget
:buttons
))
3523 (tag (widget-get widget
:tag
))
3524 (symbol (widget-value widget
))
3525 (members (custom-group-members symbol
3526 (and (eq custom-buffer-style
'tree
)
3527 custom-browse-only-groups
))))
3528 (cond ((and (eq custom-buffer-style
'tree
)
3530 (or members
(custom-unloaded-widget-p widget
)))
3531 (custom-browse-insert-prefix prefix
)
3532 (push (widget-create-child-and-convert
3533 widget
'custom-browse-visibility
3534 ;; :tag-glyph "plus"
3538 ;; (widget-glyph-insert nil "-- " "horizontal")
3539 (push (widget-create-child-and-convert
3540 widget
'custom-browse-group-tag
)
3542 (insert " " tag
"\n")
3543 (widget-put widget
:buttons buttons
))
3544 ((and (eq custom-buffer-style
'tree
)
3545 (zerop (length members
)))
3546 (custom-browse-insert-prefix prefix
)
3548 ;; (widget-glyph-insert nil "[ ]" "empty")
3549 ;; (widget-glyph-insert nil "-- " "horizontal")
3550 (push (widget-create-child-and-convert
3551 widget
'custom-browse-group-tag
)
3553 (insert " " tag
"\n")
3554 (widget-put widget
:buttons buttons
))
3555 ((eq custom-buffer-style
'tree
)
3556 (custom-browse-insert-prefix prefix
)
3557 (if (zerop (length members
))
3559 (custom-browse-insert-prefix prefix
)
3561 ;; (widget-glyph-insert nil "[ ]" "empty")
3562 ;; (widget-glyph-insert nil "-- " "horizontal")
3563 (push (widget-create-child-and-convert
3564 widget
'custom-browse-group-tag
)
3566 (insert " " tag
"\n")
3567 (widget-put widget
:buttons buttons
))
3568 (push (widget-create-child-and-convert
3569 widget
'custom-browse-visibility
3570 ;; :tag-glyph "minus"
3574 ;; (widget-glyph-insert nil "-\\ " "top")
3575 (push (widget-create-child-and-convert
3576 widget
'custom-browse-group-tag
)
3578 (insert " " tag
"\n")
3579 (widget-put widget
:buttons buttons
)
3580 (message "Creating group...")
3581 (let* ((members (custom-sort-items members
3582 custom-browse-sort-alphabetically
3583 custom-browse-order-groups
))
3584 (prefixes (widget-get widget
:custom-prefixes
))
3585 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3586 (extra-prefix (if (widget-get widget
:custom-last
)
3589 (prefix (concat prefix extra-prefix
))
3592 (setq entry
(car members
)
3593 members
(cdr members
))
3594 (push (widget-create-child-and-convert
3595 widget
(nth 1 entry
)
3597 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3598 :custom-prefixes custom-prefix-list
3599 :custom-level
(1+ level
)
3600 :custom-last
(null members
)
3601 :value
(nth 0 entry
)
3602 :custom-prefix prefix
)
3604 (widget-put widget
:children
(reverse children
)))
3605 (message "Creating group...done")))
3608 ;; Create level indicator.
3609 (unless (eq custom-buffer-style
'links
)
3610 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3613 (let ((begin (point)))
3615 (widget-specify-sample widget begin
(point)))
3617 ;; Create link/visibility indicator.
3618 (if (eq custom-buffer-style
'links
)
3619 (push (widget-create-child-and-convert
3620 widget
'custom-group-link
3624 (push (widget-create-child-and-convert
3625 widget
'custom-group-visibility
3626 :help-echo
"Show members of this group."
3627 :action
'custom-toggle-parent
3628 (not (eq state
'hidden
)))
3631 ;; Create magic button.
3632 (let ((magic (widget-create-child-and-convert
3633 widget
'custom-magic nil
)))
3634 (widget-put widget
:custom-magic magic
)
3635 (push magic buttons
))
3637 (widget-put widget
:buttons buttons
)
3638 ;; Insert documentation.
3639 (if (and (eq custom-buffer-style
'links
) (> level
1))
3640 (widget-put widget
:documentation-indent
0))
3641 (widget-default-format-handler widget ?h
))
3644 ;; Add parent groups references above the group.
3645 (if t
;;; This should test that the buffer
3646 ;;; was made to display a group.
3648 (if (custom-add-parent-links widget
3649 "Go to parent group:")
3651 ;; Create level indicator.
3652 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3655 (let ((start (point)))
3657 (widget-specify-sample widget start
(point)))
3659 ;; Create visibility indicator.
3660 (unless (eq custom-buffer-style
'links
)
3662 (push (widget-create-child-and-convert
3664 :help-echo
"Hide members of this group."
3665 :action
'custom-toggle-parent
3666 (not (eq state
'hidden
)))
3669 ;; Create more dashes.
3670 ;; Use 76 instead of 75 to compensate for the temporary "<"
3671 ;; added by `widget-insert'.
3672 (insert-char ?-
(- 76 (current-column)
3673 (* custom-buffer-indent level
)))
3675 ;; Create magic button.
3676 (let ((magic (widget-create-child-and-convert
3677 widget
'custom-magic
3680 (widget-put widget
:custom-magic magic
)
3681 (push magic buttons
))
3683 (widget-put widget
:buttons buttons
)
3684 ;; Insert documentation.
3685 (widget-default-format-handler widget ?h
)
3687 (if nil
;;; This should test that the buffer
3688 ;;; was not made to display a group.
3690 (insert-char ?\ custom-buffer-indent
)
3691 (custom-add-parent-links widget
)))
3692 (custom-add-see-also widget
3693 (make-string (* custom-buffer-indent level
)
3696 (message "Creating group...")
3697 (let* ((members (custom-sort-items members
3698 custom-buffer-sort-alphabetically
3699 custom-buffer-order-groups
))
3700 (prefixes (widget-get widget
:custom-prefixes
))
3701 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3702 (length (length members
))
3704 (children (mapcar (lambda (entry)
3705 (widget-insert "\n")
3707 Creating group members... %2d%%"
3708 (/ (* 100.0 count
) length
))
3709 (setq count
(1+ count
))
3711 (widget-create-child-and-convert
3712 widget
(nth 1 entry
)
3714 :tag
(custom-unlispify-tag-name
3716 :custom-prefixes custom-prefix-list
3717 :custom-level
(1+ level
)
3718 :value
(nth 0 entry
))
3719 (unless (eq (preceding-char) ?
\n)
3720 (widget-insert "\n"))))
3722 (message "Creating group magic...")
3723 (mapc 'custom-magic-reset children
)
3724 (message "Creating group state...")
3725 (widget-put widget
:children children
)
3726 (custom-group-state-update widget
)
3727 (message "Creating group... done"))
3730 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3731 (insert "\\- " (widget-get widget
:tag
) " group end ")
3732 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3735 (defvar custom-group-menu
3736 '(("Set for Current Session" custom-group-set
3738 (eq (widget-get widget
:custom-state
) 'modified
)))
3739 ("Save for Future Sessions" custom-group-save
3741 (memq (widget-get widget
:custom-state
) '(modified set
))))
3742 ("Reset to Current" custom-group-reset-current
3744 (memq (widget-get widget
:custom-state
) '(modified))))
3745 ("Reset to Saved" custom-group-reset-saved
3747 (memq (widget-get widget
:custom-state
) '(modified set
))))
3748 ("Reset to standard setting" custom-group-reset-standard
3750 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))
3751 "Alist of actions for the `custom-group' widget.
3752 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3753 the menu entry, ACTION is the function to call on the widget when the
3754 menu is selected, and FILTER is a predicate which takes a `custom-group'
3755 widget as an argument, and returns non-nil if ACTION is valid on that
3756 widget. If FILTER is nil, ACTION is always valid.")
3758 (defun custom-group-action (widget &optional event
)
3759 "Show the menu for `custom-group' WIDGET.
3760 Optional EVENT is the location for the menu."
3761 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3762 (custom-toggle-hide widget
)
3763 (let* ((completion-ignore-case t
)
3764 (answer (widget-choose (concat "Operation on "
3765 (custom-unlispify-tag-name
3766 (widget-get widget
:value
)))
3767 (custom-menu-filter custom-group-menu
3771 (funcall answer widget
)))))
3773 (defun custom-group-set (widget)
3774 "Set changes in all modified group members."
3775 (let ((children (widget-get widget
:children
)))
3776 (mapc (lambda (child)
3777 (when (eq (widget-get child
:custom-state
) 'modified
)
3778 (widget-apply child
:custom-set
)))
3781 (defun custom-group-save (widget)
3782 "Save all modified group members."
3783 (let ((children (widget-get widget
:children
)))
3784 (mapc (lambda (child)
3785 (when (memq (widget-get child
:custom-state
) '(modified set
))
3786 (widget-apply child
:custom-save
)))
3789 (defun custom-group-reset-current (widget)
3790 "Reset all modified group members."
3791 (let ((children (widget-get widget
:children
)))
3792 (mapc (lambda (child)
3793 (when (eq (widget-get child
:custom-state
) 'modified
)
3794 (widget-apply child
:custom-reset-current
)))
3797 (defun custom-group-reset-saved (widget)
3798 "Reset all modified or set group members."
3799 (let ((children (widget-get widget
:children
)))
3800 (mapc (lambda (child)
3801 (when (memq (widget-get child
:custom-state
) '(modified set
))
3802 (widget-apply child
:custom-reset-saved
)))
3805 (defun custom-group-reset-standard (widget)
3806 "Reset all modified, set, or saved group members."
3807 (let ((children (widget-get widget
:children
)))
3808 (mapc (lambda (child)
3809 (when (memq (widget-get child
:custom-state
)
3810 '(modified set saved
))
3811 (widget-apply child
:custom-reset-standard
)))
3814 (defun custom-group-state-update (widget)
3816 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3817 (let* ((children (widget-get widget
:children
))
3818 (states (mapcar (lambda (child)
3819 (widget-get child
:custom-state
))
3821 (magics custom-magic-alist
)
3824 (let ((magic (car (car magics
))))
3825 (if (and (not (eq magic
'hidden
))
3826 (memq magic states
))
3829 (setq magics
(cdr magics
)))))
3830 (widget-put widget
:custom-state found
)))
3831 (custom-magic-reset widget
))
3833 ;;; The `custom-save-all' Function.
3835 (defcustom custom-file nil
3836 "File used for storing customization information.
3837 The default is nil, which means to use your init file
3838 as specified by `user-init-file'. If the value is not nil,
3839 it should be an absolute file name.
3841 You can set this option through Custom, if you carefully read the
3842 last paragraph below. However, usually it is simpler to write
3843 something like the following in your init file:
3845 \(setq custom-file \"~/.emacs-custom.el\")
3848 Note that both lines are necessary: the first line tells Custom to
3849 save all customizations in this file, but does not load it.
3851 When you change this variable outside Custom, look in the
3852 previous custom file \(usually your init file) for the
3853 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3854 and copy them (whichever ones you find) to the new custom file.
3855 This will preserve your existing customizations.
3857 If you save this option using Custom, Custom will write all
3858 currently saved customizations, including the new one for this
3859 option itself, into the file you specify, overwriting any
3860 `custom-set-variables' and `custom-set-faces' forms already
3861 present in that file. It will not delete any customizations from
3862 the old custom file. You should do that manually if that is what you
3863 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3864 in your init file, where CUSTOM-FILE is the actual name of the
3865 file. Otherwise, Emacs will not load the file when it starts up,
3866 and hence will not set `custom-file' to that file either."
3867 :type
'(choice (const :tag
"Your Emacs init file" nil
)
3868 (file :format
"%t:%v%d"
3870 "Please read entire docstring below before setting \
3871 this through Custom.
3872 Click om \"More\" \(or position point there and press RETURN)
3873 if only the first line of the docstring is shown."))
3876 (defun custom-file ()
3877 "Return the file name for saving customizations."
3880 (let ((user-init-file user-init-file
)
3882 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3883 (when (null user-init-file
)
3884 (if (or (file-exists-p default-init-file
)
3885 (and (eq system-type
'windows-nt
)
3886 (file-exists-p "~/_emacs")))
3887 ;; Started with -q, i.e. the file containing
3888 ;; Custom settings hasn't been read. Saving
3889 ;; settings there would overwrite other settings.
3890 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3891 (setq user-init-file default-init-file
))
3894 (defun custom-save-delete (symbol)
3895 "Visit `custom-file' and delete all calls to SYMBOL from it.
3896 Leave point at the old location of the first such call,
3897 or (if there were none) at the end of the buffer."
3898 (let ((default-major-mode 'emacs-lisp-mode
))
3899 (set-buffer (find-file-noselect (custom-file))))
3900 (goto-char (point-min))
3901 ;; Skip all whitespace and comments.
3902 (while (forward-comment 1))
3904 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
3907 (while t
;; We exit this loop only via throw.
3908 ;; Skip all whitespace and comments.
3909 (while (forward-comment 1))
3910 (let ((start (point))
3911 (sexp (condition-case nil
3912 (read (current-buffer))
3913 (end-of-file (throw 'found nil
)))))
3914 (when (and (listp sexp
)
3915 (eq (car sexp
) symbol
))
3916 (delete-region start
(point))
3918 (setq first
(point)))))))
3921 ;; Move in front of local variables, otherwise long Custom
3922 ;; entries would make them ineffective.
3923 (let ((pos (point-max))
3924 (case-fold-search t
))
3926 (goto-char (point-max))
3927 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
3929 (when (search-forward "Local Variables:" nil t
)
3930 (setq pos
(line-beginning-position))))
3933 (defun custom-save-variables ()
3934 "Save all customized variables in `custom-file'."
3936 (custom-save-delete 'custom-load-themes
)
3937 (custom-save-delete 'custom-reset-variables
)
3938 (custom-save-delete 'custom-set-variables
)
3939 (custom-save-loaded-themes)
3940 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
3941 (let ((standard-output (current-buffer))
3942 (saved-list (make-list 1 0))
3944 ;; First create a sorted list of saved variables.
3947 (if (get symbol
'saved-value
)
3948 (nconc saved-list
(list symbol
)))))
3949 (setq saved-list
(sort (cdr saved-list
) 'string
<))
3952 (princ "(custom-set-variables
3953 ;; custom-set-variables was added by Custom.
3954 ;; If you edit it by hand, you could mess it up, so be careful.
3955 ;; Your init file should contain only one such instance.
3956 ;; If there is more than one, they won't work right.\n")
3957 (dolist (symbol saved-list
)
3958 (let ((spec (car-safe (get symbol
'theme-value
)))
3959 (value (get symbol
'saved-value
))
3960 (requests (get symbol
'custom-requests
))
3961 (now (not (or (custom-variable-p symbol
)
3962 (and (not (boundp symbol
))
3963 (not (eq (get symbol
'force-value
)
3965 (comment (get symbol
'saved-variable-comment
)))
3966 ;; Check `requests'.
3967 (dolist (request requests
)
3968 (when (and (symbolp request
) (not (featurep request
)))
3969 (message "Unknown requested feature: %s" request
)
3970 (setq requests
(delq request requests
))))
3972 (eq (nth 0 spec
) 'user
)
3973 (eq (nth 1 spec
) 'set
))
3975 (and (null spec
) (get symbol
'saved-value
)))
3982 (when (or now requests comment
)
3985 (when (or requests comment
)
3995 (unless (looking-at "\n")
3998 (defun custom-save-faces ()
3999 "Save all customized faces in `custom-file'."
4001 (custom-save-delete 'custom-reset-faces
)
4002 (custom-save-delete 'custom-set-faces
)
4003 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
4004 (let ((standard-output (current-buffer))
4005 (saved-list (make-list 1 0))
4007 ;; First create a sorted list of saved faces.
4010 (if (get symbol
'saved-face
)
4011 (nconc saved-list
(list symbol
)))))
4012 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4013 ;; The default face must be first, since it affects the others.
4014 (if (memq 'default saved-list
)
4015 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4018 (princ "(custom-set-faces
4019 ;; custom-set-faces was added by Custom.
4020 ;; If you edit it by hand, you could mess it up, so be careful.
4021 ;; Your init file should contain only one such instance.
4022 ;; If there is more than one, they won't work right.\n")
4023 (dolist (symbol saved-list
)
4024 (let ((spec (car-safe (get symbol
'theme-face
)))
4025 (value (get symbol
'saved-face
))
4026 (now (not (or (get symbol
'face-defface-spec
)
4027 (and (not (custom-facep symbol
))
4028 (not (get symbol
'force-face
))))))
4029 (comment (get symbol
'saved-face-comment
)))
4031 (eq (nth 0 spec
) 'user
)
4032 (eq (nth 1 spec
) 'set
))
4034 (and (null spec
) (get symbol
'saved-face
)))
4035 ;; Don't print default face here.
4042 (when (or now comment
)
4052 (unless (looking-at "\n")
4055 (defun custom-save-resets (property setter special
)
4056 (let (started-writing ignored-special
)
4057 ;; (custom-save-delete setter) Done by caller
4058 (let ((standard-output (current-buffer))
4059 (mapper `(lambda (object)
4060 (let ((spec (car-safe (get object
(quote ,property
)))))
4061 (when (and (not (memq object ignored-special
))
4062 (eq (nth 0 spec
) 'user
)
4063 (eq (nth 1 spec
) 'reset
))
4064 ;; Do not write reset statements unless necessary.
4065 (unless started-writing
4066 (setq started-writing t
)
4070 (princ (quote ,setter
))
4074 (prin1 (nth 3 spec
))
4076 (mapc mapper special
)
4077 (setq ignored-special special
)
4079 (when started-writing
4082 (defun custom-save-loaded-themes ()
4083 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
4084 (standard-output (current-buffer)))
4086 (unless (bolp) (princ "\n"))
4087 (princ "(custom-load-themes")
4088 (mapc (lambda (theme)
4090 (prin1 theme
)) themes
)
4094 (defun customize-save-customized ()
4095 "Save all user options which have been set in this session."
4097 (mapatoms (lambda (symbol)
4098 (let ((face (get symbol
'customized-face
))
4099 (value (get symbol
'customized-value
))
4100 (face-comment (get symbol
'customized-face-comment
))
4102 (get symbol
'customized-variable-comment
)))
4104 (put symbol
'saved-face face
)
4105 (custom-push-theme 'theme-face symbol
'user
'set value
)
4106 (put symbol
'customized-face nil
))
4108 (put symbol
'saved-value value
)
4109 (custom-push-theme 'theme-value symbol
'user
'set value
)
4110 (put symbol
'customized-value nil
))
4111 (when variable-comment
4112 (put symbol
'saved-variable-comment variable-comment
)
4113 (put symbol
'customized-variable-comment nil
))
4115 (put symbol
'saved-face-comment face-comment
)
4116 (put symbol
'customized-face-comment nil
)))))
4117 ;; We really should update all custom buffers here.
4121 (defun custom-save-all ()
4122 "Save all customizations in `custom-file'."
4123 (let ((inhibit-read-only t
))
4124 (custom-save-variables)
4127 (let ((default-major-mode nil
))
4128 (set-buffer (find-file-noselect (custom-file))))
4129 (let ((file-precious-flag t
))
4132 ;;; The Customize Menu.
4136 (defcustom custom-menu-nesting
2
4137 "Maximum nesting in custom menus."
4139 :group
'custom-menu
)
4141 (defun custom-face-menu-create (widget symbol
)
4142 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4143 (vector (custom-unlispify-menu-entry symbol
)
4144 `(customize-face ',symbol
)
4147 (defun custom-variable-menu-create (widget symbol
)
4148 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4149 (let ((type (get symbol
'custom-type
)))
4150 (unless (listp type
)
4151 (setq type
(list type
)))
4152 (if (and type
(widget-get type
:custom-menu
))
4153 (widget-apply type
:custom-menu symbol
)
4154 (vector (custom-unlispify-menu-entry symbol
)
4155 `(customize-variable ',symbol
)
4158 ;; Add checkboxes to boolean variable entries.
4159 (widget-put (get 'boolean
'widget-type
)
4160 :custom-menu
(lambda (widget symbol
)
4161 (vector (custom-unlispify-menu-entry symbol
)
4162 `(customize-variable ',symbol
)
4164 ':selected symbol
)))
4166 (defun custom-group-menu-create (widget symbol
)
4167 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4168 `( ,(custom-unlispify-menu-entry symbol t
)
4169 :filter
(lambda (&rest junk
)
4170 (let ((menu (custom-menu-create ',symbol
)))
4171 (if (consp menu
) (cdr menu
) menu
)))))
4174 (defun custom-menu-create (symbol)
4175 "Create menu for customization group SYMBOL.
4176 The menu is in a format applicable to `easy-menu-define'."
4177 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4178 `(customize-group ',symbol
)
4180 (if (and (or (not (boundp 'custom-menu-nesting
))
4181 (>= custom-menu-nesting
0))
4183 (custom-load-symbol symbol
)
4184 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4185 (let ((custom-prefix-list (custom-prefix-add symbol
4186 custom-prefix-list
))
4187 (members (custom-sort-items (get symbol
'custom-group
)
4188 custom-menu-sort-alphabetically
4189 custom-menu-order-groups
)))
4190 `(,(custom-unlispify-menu-entry symbol t
)
4193 ,@(mapcar (lambda (entry)
4194 (widget-apply (if (listp (nth 1 entry
))
4196 (list (nth 1 entry
)))
4197 :custom-menu
(nth 0 entry
)))
4202 (defun customize-menu-create (symbol &optional name
)
4203 "Return a customize menu for customization group SYMBOL.
4204 If optional NAME is given, use that as the name of the menu.
4205 Otherwise the menu will be named `Customize'.
4206 The format is suitable for use with `easy-menu-define'."
4208 (setq name
"Customize"))
4210 :filter
(lambda (&rest junk
)
4211 (let ((menu (custom-menu-create ',symbol
)))
4212 (if (consp menu
) (cdr menu
) menu
)))))
4214 ;;; The Custom Mode.
4216 (defvar custom-mode-map
4217 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4218 ;; "\r" bindings from the parent map.
4219 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4220 (let ((map (make-keymap)))
4221 (set-keymap-parent map widget-keymap
)
4222 (suppress-keymap map
)
4223 (define-key map
" " 'scroll-up
)
4224 (define-key map
"\177" 'scroll-down
)
4225 (define-key map
"\C-x\C-s" 'Custom-save
)
4226 (define-key map
"q" 'Custom-buffer-done
)
4227 (define-key map
"u" 'Custom-goto-parent
)
4228 (define-key map
"n" 'widget-forward
)
4229 (define-key map
"p" 'widget-backward
)
4230 (define-key map
[mouse-1
] 'Custom-move-and-invoke
)
4232 "Keymap for `custom-mode'.")
4234 (defun Custom-move-and-invoke (event)
4235 "Move to where you click, and if it is an active field, invoke it."
4237 (mouse-set-point event
)
4238 (if (widget-event-point event
)
4239 (let* ((pos (widget-event-point event
))
4240 (button (get-char-property pos
'button
)))
4242 (widget-button-click event
)))))
4244 (easy-menu-define Custom-mode-menu
4246 "Menu used in customization buffers."
4248 ,(customize-menu-create 'customize
)
4249 ["Set" Custom-set t
]
4250 ["Save" Custom-save t
]
4251 ["Reset to Current" Custom-reset-current t
]
4252 ["Reset to Saved" Custom-reset-saved t
]
4253 ["Reset to Standard Settings" Custom-reset-standard t
]
4254 ["Info" (Info-goto-node "(emacs)Easy Customization") t
]))
4256 (defun Custom-goto-parent ()
4257 "Go to the parent group listed at the top of this buffer.
4258 If several parents are listed, go to the first of them."
4261 (goto-char (point-min))
4262 (if (search-forward "\nGo to parent group: " nil t
)
4263 (let* ((button (get-char-property (point) 'button
))
4264 (parent (downcase (widget-get button
:tag
))))
4265 (customize-group parent
)))))
4267 (defcustom custom-mode-hook nil
4268 "Hook called when entering Custom mode."
4270 :group
'custom-buffer
)
4272 (defun custom-state-buffer-message (widget)
4273 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4274 (message "To install your edits, invoke [State] and choose the Set operation")))
4276 (defun custom-mode ()
4277 "Major mode for editing customization buffers.
4279 The following commands are available:
4281 Move to next button or editable field. \\[widget-forward]
4282 Move to previous button or editable field. \\[widget-backward]
4283 \\<widget-field-keymap>\
4284 Complete content of editable text field. \\[widget-complete]
4285 \\<custom-mode-map>\
4286 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4287 Invoke button under point. \\[widget-button-press]
4288 Set all modifications. \\[Custom-set]
4289 Make all modifications default. \\[Custom-save]
4290 Reset all modified options. \\[Custom-reset-current]
4291 Reset all modified or set options. \\[Custom-reset-saved]
4292 Reset all options. \\[Custom-reset-standard]
4294 Entry to this mode calls the value of `custom-mode-hook'
4295 if that value is non-nil."
4296 (kill-all-local-variables)
4297 (setq major-mode
'custom-mode
4299 (use-local-map custom-mode-map
)
4300 (easy-menu-add Custom-mode-menu
)
4301 (make-local-variable 'custom-options
)
4302 (make-local-variable 'custom-local-buffer
)
4303 (make-local-variable 'widget-documentation-face
)
4304 (setq widget-documentation-face
'custom-documentation
)
4305 (make-local-variable 'widget-button-face
)
4306 (setq widget-button-face
'custom-button
)
4307 (set (make-local-variable 'widget-button-pressed-face
) 'custom-button-pressed
)
4308 (set (make-local-variable 'widget-mouse-face
)
4309 'custom-button-pressed
) ; buttons `depress' when moused
4310 ;; When possible, use relief for buttons, not bracketing. This test
4311 ;; may not be optimal.
4312 (when custom-raised-buttons
4313 (set (make-local-variable 'widget-push-button-prefix
) "")
4314 (set (make-local-variable 'widget-push-button-suffix
) "")
4315 (set (make-local-variable 'widget-link-prefix
) "")
4316 (set (make-local-variable 'widget-link-suffix
) ""))
4317 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4318 (run-mode-hooks 'custom-mode-hook
))
4320 (put 'custom-mode
'mode-class
'special
)
4323 'debug-ignored-errors
4324 "^No user options have changed defaults in recent Emacs versions$")
4330 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4331 ;;; cus-edit.el ends here