1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
)) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link
'(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag
"Storage Allocation"
388 "Undoing changes in buffers."
389 :link
'(custom-manual "(emacs)Undo")
392 (defgroup modeline nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controling the behavior of the minibuffer."
426 :link
'(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidential loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link
'(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link
'(custom-manual "(emacs)Mac OS")
471 (defun custom-quote (sexp)
472 "Quote SEXP iff it is not self quoting."
473 (if (or (memq sexp
'(t nil
))
476 (memq (car sexp
) '(lambda)))
480 ;;; (and (fboundp 'characterp)
481 ;;; (characterp sexp))
486 (defun custom-split-regexp-maybe (regexp)
487 "If REGEXP is a string, split it to a list at `\\|'.
488 You can get the original back with from the result with:
489 (mapconcat 'identity result \"\\|\")
491 IF REGEXP is not a string, return it unchanged."
495 (while (string-match "\\\\|" regexp start
)
496 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
497 start
(match-end 0)))
498 (nreverse (cons (substring regexp start
) all
)))
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
506 (enable-recursive-minibuffers t
)
508 (setq val
(completing-read
509 (if default
(format "Customize variable (default %s): " default
)
510 "Customize variable: ")
511 obarray
'custom-variable-p t nil nil default
))
512 (list (if (equal val
"")
513 (if (symbolp v
) v nil
)
516 (defun custom-menu-filter (menu widget
)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
521 current name action filter
)
523 (setq current
(car menu
)
525 action
(nth 1 current
)
526 filter
(nth 2 current
)
528 (if (or (null filter
) (funcall filter widget
))
529 (push (cons name action
) result
)
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non nil."
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
546 :group
'custom-buffer
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries
)
552 (symbol-name symbol
))
553 ((get symbol
'custom-tag
)
555 (get symbol
'custom-tag
)
556 (concat (get symbol
'custom-tag
) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
560 (princ symbol
(current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list
)
572 (setq prefix
(car prefixes
))
573 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
576 (delete-region (point-min) (point)))
577 (setq prefixes
(cdr prefixes
))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
579 (capitalize-region (point-min) (point-max))
581 (goto-char (point-max))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non nil."
587 :group
'custom-buffer
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
593 (custom-unlispify-menu-entry symbol t
)))
595 (defun custom-prefix-add (symbol prefixes
)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol
'custom-prefix
)
598 (concat (symbol-name symbol
) "-"))
603 (defcustom custom-guess-name-alist
608 ("-function\\'" function
)
609 ("-functions\\'" (repeat function
))
610 ("-list\\'" (repeat sexp
))
611 ("-alist\\'" (repeat (cons sexp sexp
))))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching the name of a symbol, and TYPE should
615 be a widget suitable for editing the value of that symbol. The TYPE
616 of the first entry where MATCH matches the name of the symbol will be
619 This is used for guessing the type of variables not declared with
621 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
622 :group
'custom-buffer
)
624 (defcustom custom-guess-doc-alist
625 '(("\\`\\*?Non-nil " boolean
))
626 "Alist of (MATCH TYPE).
628 MATCH should be a regexp matching a documentation string, and TYPE
629 should be a widget suitable for editing the value of a variable with
630 that documentation string. The TYPE of the first entry where MATCH
631 matches the name of the symbol will be used.
633 This is used for guessing the type of variables not declared with
635 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
636 :group
'custom-buffer
)
638 (defun custom-guess-type (symbol)
639 "Guess a widget suitable for editing the value of SYMBOL.
640 This is done by matching SYMBOL with `custom-guess-name-alist' and
641 if that fails, the doc string with `custom-guess-doc-alist'."
642 (let ((name (symbol-name symbol
))
643 (names custom-guess-name-alist
)
646 (setq current
(car names
)
648 (when (string-match (nth 0 current
) name
)
649 (setq found
(nth 1 current
)
652 (let ((doc (documentation-property symbol
'variable-documentation
))
653 (docs custom-guess-doc-alist
))
656 (setq current
(car docs
)
658 (when (string-match (nth 0 current
) doc
)
659 (setq found
(nth 1 current
)
665 (defcustom custom-browse-sort-alphabetically nil
666 "If non-nil, sort members of each customization group alphabetically."
668 :group
'custom-browse
)
670 (defcustom custom-browse-order-groups nil
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type
'(choice (const first
)
676 (const :tag
"none" nil
))
677 :group
'custom-browse
)
679 (defcustom custom-browse-only-groups nil
680 "If non-nil, show group members only within each customization group."
682 :group
'custom-browse
)
684 (defcustom custom-buffer-sort-alphabetically nil
685 "If non-nil, sort members of each customization group alphabetically."
687 :group
'custom-buffer
)
689 (defcustom custom-buffer-order-groups
'last
690 "If non-nil, order group members within each customization group.
691 If `first', order groups before non-groups.
692 If `last', order groups after non-groups."
693 :type
'(choice (const first
)
695 (const :tag
"none" nil
))
696 :group
'custom-buffer
)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort members of each customization group alphabetically."
703 (defcustom custom-menu-order-groups
'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups
)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items
)
722 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
723 (namea (nth 0 a
)) (nameb (nth 0 b
)))
724 (cond ((not order-groups
)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb
)))
728 ((eq typea
'custom-group
)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb
'custom-group
)
731 (when sort-alphabetically
732 (string-lessp namea nameb
))
733 (eq order-groups
'first
)))
734 ((eq typeb
'custom-group
)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups
'last
))
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb
)))))))
741 ;;; Custom Mode Commands.
743 (defvar custom-options nil
744 "Customization widgets in the current buffer.")
747 "Set the current value of all edited settings in the buffer."
749 (if (y-or-n-p "Set all values according to this buffer? ")
750 (let ((children custom-options
))
751 (mapc (lambda (child)
752 (when (eq (widget-get child
:custom-state
) 'modified
)
753 (widget-apply child
:custom-set
)))
755 (message "Aborted")))
757 (defun Custom-save ()
758 "Set all edited settings, then save all settings that have been set.
759 If a setting was edited and set before, this saves it.
760 If a setting was merely edited before, this sets it then saves it."
762 (if (yes-or-no-p "Save all settings in this buffer? ")
763 (let ((children custom-options
))
764 (mapc (lambda (child)
765 (when (memq (widget-get child
:custom-state
)
766 '(modified set changed rogue
))
767 (widget-apply child
:custom-save
)))
770 (message "Aborted")))
772 (defvar custom-reset-menu
773 '(("Reset to current settings" . Custom-reset-current
)
774 ("Reset to saved settings" . Custom-reset-saved
)
775 ("Erase Customization (use standard values)" . Custom-reset-standard
))
776 "Alist of actions for the `Reset' button.
777 The key is a string containing the name of the action, the value is a
778 Lisp function taking the widget as an element which will be called
779 when the action is chosen.")
781 (defun custom-reset (event)
782 "Select item from reset menu."
783 (let* ((completion-ignore-case t
)
784 (answer (widget-choose "Reset settings"
790 (defun Custom-reset-current (&rest ignore
)
791 "Reset all edited settings in the buffer to show their current values."
793 (if (y-or-n-p "Reset all settings' buffer text to show current values? ")
794 (let ((children custom-options
))
795 (mapc (lambda (widget)
796 (if (memq (widget-get widget
:custom-state
)
798 (widget-apply widget
:custom-reset-current
)))
800 (message "Aborted")))
802 (defun Custom-reset-saved (&rest ignore
)
803 "Reset all edited or set settings in the buffer to their saved value.
804 This also shows the saved values in the buffer."
806 (if (y-or-n-p "Reset all settings (current values and buffer text) to saved values? ")
807 (let ((children custom-options
))
808 (mapc (lambda (widget)
809 (if (memq (widget-get widget
:custom-state
)
810 '(modified set changed rogue
))
811 (widget-apply widget
:custom-reset-saved
)))
813 (message "Aborted")))
815 (defun Custom-reset-standard (&rest ignore
)
816 "Erase all customization (either current or saved) for the group members.
817 The immediate result is to restore them to their standard values.
818 This operation eliminates any saved values for the group members,
819 making them as if they had never been customized at all."
821 (let ((children custom-options
))
822 (if (or (and (= 1 (length children
))
823 (memq (widget-type (car children
))
824 '(custom-variable custom-face
)))
825 (yes-or-no-p "Erase all customizations for settings in this buffer? "))
826 (mapc (lambda (widget)
827 (and (if (widget-get widget
:custom-standard-value
)
828 (widget-apply widget
:custom-standard-value
)
830 (memq (widget-get widget
:custom-state
)
831 '(modified set changed saved rogue
))
832 (widget-apply widget
:custom-reset-standard
)))
834 (message "Aborted"))))
836 ;;; The Customize Commands
838 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
839 "Prompt for a variable and a value and return them as a list.
840 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
841 prompt for the value. The %s escape in PROMPT-VAL is replaced with
842 the name of the variable.
844 If the variable has a `variable-interactive' property, that is used as if
845 it were the arg to `interactive' (which see) to interactively read the value.
847 If the variable has a `custom-type' property, it must be a widget and the
848 `:prompt-value' property of that widget will be used for reading the value.
850 If optional COMMENT argument is non nil, also prompt for a comment and return
851 it as the third element in the list."
852 (let* ((var (read-variable prompt-var
))
853 (minibuffer-help-form '(describe-variable var
))
855 (let ((prop (get var
'variable-interactive
))
856 (type (get var
'custom-type
))
857 (prompt (format prompt-val var
)))
859 (setq type
(list type
)))
861 ;; Use VAR's `variable-interactive' property
862 ;; as an interactive spec for prompting.
863 (call-interactively (list 'lambda
'(arg)
864 (list 'interactive prop
)
867 (widget-prompt-value type
873 (eval-minibuffer prompt
))))))
876 (read-string "Comment: " (get var
'variable-comment
)))
880 (defun customize-set-value (variable value
&optional comment
)
881 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
883 If VARIABLE has a `variable-interactive' property, that is used as if
884 it were the arg to `interactive' (which see) to interactively read the value.
886 If VARIABLE has a `custom-type' property, it must be a widget and the
887 `:prompt-value' property of that widget will be used for reading the value.
889 If given a prefix (or a COMMENT argument), also prompt for a comment."
890 (interactive (custom-prompt-variable "Set variable: "
894 (cond ((string= comment
"")
895 (put variable
'variable-comment nil
))
897 (put variable
'variable-comment comment
)))
898 (set variable value
))
901 (defun customize-set-variable (variable value
&optional comment
)
902 "Set the default for VARIABLE to VALUE, and return VALUE.
903 VALUE is a Lisp object.
905 If VARIABLE has a `custom-set' property, that is used for setting
906 VARIABLE, otherwise `set-default' is used.
908 The `customized-value' property of the VARIABLE will be set to a list
909 with a quoted VALUE as its sole list member.
911 If VARIABLE has a `variable-interactive' property, that is used as if
912 it were the arg to `interactive' (which see) to interactively read the value.
914 If VARIABLE has a `custom-type' property, it must be a widget and the
915 `:prompt-value' property of that widget will be used for reading the value.
917 If given a prefix (or a COMMENT argument), also prompt for a comment."
918 (interactive (custom-prompt-variable "Set variable: "
919 "Set customized value for %s to: "
921 (custom-load-symbol variable
)
922 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
923 (put variable
'customized-value
(list (custom-quote value
)))
924 (cond ((string= comment
"")
925 (put variable
'variable-comment nil
)
926 (put variable
'customized-variable-comment nil
))
928 (put variable
'variable-comment comment
)
929 (put variable
'customized-variable-comment comment
)))
933 (defun customize-save-variable (variable value
&optional comment
)
934 "Set the default for VARIABLE to VALUE, and save it for future sessions.
937 If VARIABLE has a `custom-set' property, that is used for setting
938 VARIABLE, otherwise `set-default' is used.
940 The `customized-value' property of the VARIABLE will be set to a list
941 with a quoted VALUE as its sole list member.
943 If VARIABLE has a `variable-interactive' property, that is used as if
944 it were the arg to `interactive' (which see) to interactively read the value.
946 If VARIABLE has a `custom-type' property, it must be a widget and the
947 `:prompt-value' property of that widget will be used for reading the value.
949 If given a prefix (or a COMMENT argument), also prompt for a comment."
950 (interactive (custom-prompt-variable "Set and save variable: "
951 "Set and save value for %s as: "
953 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
954 (put variable
'saved-value
(list (custom-quote value
)))
955 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
956 (cond ((string= comment
"")
957 (put variable
'variable-comment nil
)
958 (put variable
'saved-variable-comment nil
))
960 (put variable
'variable-comment comment
)
961 (put variable
'saved-variable-comment comment
)))
967 "Select a customization buffer which you can use to set user options.
968 User options are structured into \"groups\".
969 Initially the top-level group `Emacs' and its immediate subgroups
970 are shown; the contents of those subgroups are initially hidden."
972 (customize-group 'emacs
))
975 (defun customize-mode (mode)
976 "Customize options related to the current major mode.
977 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
978 then prompt for the MODE to customize."
981 (let ((completion-regexp-list '("-mode\\'"))
982 (group (custom-group-of-mode major-mode
)))
983 (if (and group
(not current-prefix-arg
))
986 (completing-read (if group
987 (format "Major mode (default %s): " major-mode
)
990 'custom-group-of-mode
991 t nil nil
(if group
(symbol-name major-mode
))))))))
992 (customize-group (custom-group-of-mode mode
)))
996 (defun customize-group (group)
997 "Customize GROUP, which must be a customization group."
999 (list (let ((completion-ignore-case t
))
1000 (completing-read "Customize group (default emacs): "
1003 (or (and (get symbol
'custom-loads
)
1004 (not (get symbol
'custom-autoload
)))
1005 (get symbol
'custom-group
)))
1007 (when (stringp group
)
1008 (if (string-equal "" group
)
1010 (setq group
(intern group
))))
1011 (let ((name (format "*Customize Group: %s*"
1012 (custom-unlispify-tag-name group
))))
1013 (if (get-buffer name
)
1014 (pop-to-buffer name
)
1015 (custom-buffer-create (list (list group
'custom-group
))
1017 (concat " for group "
1018 (custom-unlispify-tag-name group
))))))
1021 (defun customize-group-other-window (group)
1022 "Customize GROUP, which must be a customization group."
1024 (list (let ((completion-ignore-case t
))
1025 (completing-read "Customize group (default emacs): "
1028 (or (and (get symbol
'custom-loads
)
1029 (not (get symbol
'custom-autoload
)))
1030 (get symbol
'custom-group
)))
1032 (when (stringp group
)
1033 (if (string-equal "" group
)
1035 (setq group
(intern group
))))
1036 (let ((name (format "*Customize Group: %s*"
1037 (custom-unlispify-tag-name group
))))
1038 (if (get-buffer name
)
1040 ;; Copied from `custom-buffer-create-other-window'.
1042 (same-window-buffer-names nil
)
1043 (same-window-regexps nil
))
1044 (pop-to-buffer name
))
1045 (custom-buffer-create-other-window
1046 (list (list group
'custom-group
))
1048 (concat " for group "
1049 (custom-unlispify-tag-name group
))))))
1052 (defalias 'customize-variable
'customize-option
)
1055 (defun customize-option (symbol)
1056 "Customize SYMBOL, which must be a user option variable."
1057 (interactive (custom-variable-prompt))
1058 (let ((basevar (indirect-variable symbol
)))
1059 (custom-buffer-create (list (list basevar
'custom-variable
))
1060 (format "*Customize Option: %s*"
1061 (custom-unlispify-tag-name basevar
)))
1062 (unless (eq symbol basevar
)
1063 (message "`%s' is an alias for `%s'" symbol basevar
))))
1066 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1069 (defun customize-option-other-window (symbol)
1070 "Customize SYMBOL, which must be a user option variable.
1071 Show the buffer in another window, but don't select it."
1072 (interactive (custom-variable-prompt))
1073 (let ((basevar (indirect-variable symbol
)))
1074 (custom-buffer-create-other-window
1075 (list (list basevar
'custom-variable
))
1076 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1077 (unless (eq symbol basevar
)
1078 (message "`%s' is an alias for `%s'" symbol basevar
))))
1080 (defvar customize-changed-options-previous-release
"21.1"
1081 "Version for `customize-changed-options' to refer back to by default.")
1084 (defalias 'customize-changed
'customize-changed-options
)
1087 (defun customize-changed-options (since-version)
1088 "Customize all settings whose meanings have changed in Emacs itself.
1089 This includes new user option variables and faces, and new
1090 customization groups, as well as older options and faces whose meanings
1091 or default values have changed since the previous major Emacs release.
1093 With argument SINCE-VERSION (a string), customize all settings
1094 that were added or redefined since that version."
1096 (interactive "sCustomize options changed, since version (default all versions): ")
1097 (if (equal since-version
"")
1098 (setq since-version nil
)
1099 (unless (condition-case nil
1100 (numberp (read since-version
))
1102 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1103 (unless since-version
1104 (setq since-version customize-changed-options-previous-release
))
1106 ;; Load the information for versions since since-version. We use
1107 ;; custom-load-symbol for this.
1108 (put 'custom-versions-load-alist
'custom-loads nil
)
1109 (dolist (elt custom-versions-load-alist
)
1110 (if (customize-version-lessp since-version
(car elt
))
1111 (dolist (load (cdr elt
))
1112 (custom-add-load 'custom-versions-load-alist load
))))
1113 (custom-load-symbol 'custom-versions-load-alist
)
1114 (put 'custom-versions-load-alist
'custom-loads nil
)
1119 (let ((version (get symbol
'custom-version
)))
1121 (when (customize-version-lessp since-version version
)
1122 (if (or (get symbol
'custom-group
)
1123 (get symbol
'group-documentation
))
1124 (push (list symbol
'custom-group
) found
))
1125 (if (custom-variable-p symbol
)
1126 (push (list symbol
'custom-variable
) found
))
1127 (if (custom-facep symbol
)
1128 (push (list symbol
'custom-face
) found
)))))))
1130 (custom-buffer-create (custom-sort-items found t
'first
)
1131 "*Customize Changed Options*")
1132 (error "No user option defaults have been changed since Emacs %s"
1135 (defun customize-version-lessp (version1 version2
)
1136 ;; Why are the versions strings, and given that they are, why aren't
1137 ;; they converted to numbers and compared as such here? -- fx
1139 ;; In case someone made a mistake and left out the quotes
1140 ;; in the :version value.
1141 (if (numberp version2
)
1142 (setq version2
(prin1-to-string version2
)))
1143 (let (major1 major2 minor1 minor2
)
1144 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1145 (setq major1
(read (or (match-string 1 version1
)
1147 (setq minor1
(read (or (match-string 3 version1
)
1149 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1150 (setq major2
(read (or (match-string 1 version2
)
1152 (setq minor2
(read (or (match-string 3 version2
)
1154 (or (< major1 major2
)
1155 (and (= major1 major2
)
1156 (< minor1 minor2
)))))
1159 (defun customize-face (&optional face
)
1160 "Customize FACE, which should be a face name or nil.
1161 If FACE is nil, customize all faces. If FACE is actually a
1162 face-alias, customize the face it is aliased to.
1164 Interactively, when point is on text which has a face specified,
1165 suggest to customize that face, if it's customizable."
1167 (list (read-face-name "Customize face" "all faces" t
)))
1168 (if (member face
'(nil ""))
1169 (setq face
(face-list)))
1170 (if (and (listp face
) (null (cdr face
)))
1171 (setq face
(car face
)))
1173 (custom-buffer-create (custom-sort-items
1175 (list s
'custom-face
))
1178 "*Customize Faces*")
1179 ;; If FACE is actually an alias, customize the face it is aliased to.
1180 (if (get face
'face-alias
)
1181 (setq face
(get face
'face-alias
)))
1182 (unless (facep face
)
1183 (error "Invalid face %S" face
))
1184 (custom-buffer-create (list (list face
'custom-face
))
1185 (format "*Customize Face: %s*"
1186 (custom-unlispify-tag-name face
)))))
1189 (defun customize-face-other-window (&optional face
)
1190 "Show customization buffer for face FACE in other window.
1191 If FACE is actually a face-alias, customize the face it is aliased to.
1193 Interactively, when point is on text which has a face specified,
1194 suggest to customize that face, if it's customizable."
1196 (list (read-face-name "Customize face" "all faces" t
)))
1197 (if (member face
'(nil ""))
1198 (setq face
(face-list)))
1199 (if (and (listp face
) (null (cdr face
)))
1200 (setq face
(car face
)))
1202 (custom-buffer-create-other-window
1205 (list s
'custom-face
))
1208 "*Customize Faces*")
1209 (if (get face
'face-alias
)
1210 (setq face
(get face
'face-alias
)))
1211 (unless (facep face
)
1212 (error "Invalid face %S" face
))
1213 (custom-buffer-create-other-window
1214 (list (list face
'custom-face
))
1215 (format "*Customize Face: %s*"
1216 (custom-unlispify-tag-name face
)))))
1219 (defun customize-customized ()
1220 "Customize all user options set since the last save in this session."
1223 (mapatoms (lambda (symbol)
1224 (and (or (get symbol
'customized-face
)
1225 (get symbol
'customized-face-comment
))
1226 (custom-facep symbol
)
1227 (push (list symbol
'custom-face
) found
))
1228 (and (or (get symbol
'customized-value
)
1229 (get symbol
'customized-variable-comment
))
1231 (push (list symbol
'custom-variable
) found
))))
1233 (error "No customized user options")
1234 (custom-buffer-create (custom-sort-items found t nil
)
1235 "*Customize Customized*"))))
1238 (defun customize-rogue ()
1239 "Customize all user variable modified outside customize."
1242 (mapatoms (lambda (symbol)
1243 (let ((cval (or (get symbol
'customized-value
)
1244 (get symbol
'saved-value
)
1245 (get symbol
'standard-value
))))
1246 (when (and cval
;Declared with defcustom.
1247 (default-boundp symbol
) ;Has a value.
1248 (not (equal (eval (car cval
))
1249 ;; Which does not match customize.
1250 (default-value symbol
))))
1251 (push (list symbol
'custom-variable
) found
)))))
1253 (error "No rogue user options")
1254 (custom-buffer-create (custom-sort-items found t nil
)
1255 "*Customize Rogue*"))))
1257 (defun customize-saved ()
1258 "Customize all already saved user options."
1261 (mapatoms (lambda (symbol)
1262 (and (or (get symbol
'saved-face
)
1263 (get symbol
'saved-face-comment
))
1264 (custom-facep symbol
)
1265 (push (list symbol
'custom-face
) found
))
1266 (and (or (get symbol
'saved-value
)
1267 (get symbol
'saved-variable-comment
))
1269 (push (list symbol
'custom-variable
) found
))))
1271 (error "No saved user options")
1272 (custom-buffer-create (custom-sort-items found t nil
)
1273 "*Customize Saved*"))))
1276 (defun customize-apropos (regexp &optional all
)
1277 "Customize all loaded options, faces and groups matching REGEXP.
1278 If ALL is `options', include only options.
1279 If ALL is `faces', include only faces.
1280 If ALL is `groups', include only groups.
1281 If ALL is t (interactively, with prefix arg), include variables
1282 that are not customizable options, as well as faces and groups
1283 \(but we recommend using `apropos-variable' instead)."
1284 (interactive "sCustomize regexp: \nP")
1286 (mapatoms (lambda (symbol)
1287 (when (string-match regexp
(symbol-name symbol
))
1288 (when (and (not (memq all
'(faces options
)))
1289 (get symbol
'custom-group
))
1290 (push (list symbol
'custom-group
) found
))
1291 (when (and (not (memq all
'(options groups
)))
1292 (custom-facep symbol
))
1293 (push (list symbol
'custom-face
) found
))
1294 (when (and (not (memq all
'(groups faces
)))
1296 (eq (indirect-variable symbol
) symbol
)
1297 (or (get symbol
'saved-value
)
1298 (custom-variable-p symbol
)
1299 (and (not (memq all
'(nil options
)))
1300 (get symbol
'variable-documentation
))))
1301 (push (list symbol
'custom-variable
) found
)))))
1303 (error "No matches")
1304 (custom-buffer-create (custom-sort-items found t
1305 custom-buffer-order-groups
)
1306 "*Customize Apropos*"))))
1309 (defun customize-apropos-options (regexp &optional arg
)
1310 "Customize all loaded customizable options matching REGEXP.
1311 With prefix arg, include variables that are not customizable options
1312 \(but we recommend using `apropos-variable' instead)."
1313 (interactive "sCustomize regexp: \nP")
1314 (customize-apropos regexp
(or arg
'options
)))
1317 (defun customize-apropos-faces (regexp)
1318 "Customize all loaded faces matching REGEXP."
1319 (interactive "sCustomize regexp: \n")
1320 (customize-apropos regexp
'faces
))
1323 (defun customize-apropos-groups (regexp)
1324 "Customize all loaded groups matching REGEXP."
1325 (interactive "sCustomize regexp: \n")
1326 (customize-apropos regexp
'groups
))
1330 (defcustom custom-buffer-style
'links
1331 "Control the presentation style for customization buffers.
1332 The value should be a symbol, one of:
1334 brackets: groups nest within each other with big horizontal brackets.
1335 links: groups have links to subgroups."
1336 :type
'(radio (const brackets
)
1338 :group
'custom-buffer
)
1340 (defcustom custom-buffer-done-kill nil
1341 "*Non-nil means exiting a Custom buffer should kill it."
1344 :group
'custom-buffer
)
1346 (defcustom custom-buffer-indent
3
1347 "Number of spaces to indent nested groups."
1349 :group
'custom-buffer
)
1351 (defun custom-get-fresh-buffer (name)
1352 "Get a fresh new buffer with name NAME.
1353 If the buffer already exist, clean it up to be like new.
1354 Beware: it's not quite like new. Good enough for custom, but maybe
1356 ;; To be more complete, we should also kill all permanent-local variables,
1357 ;; but it's not needed for custom.
1358 (let ((buf (get-buffer name
)))
1359 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1360 ;; This will check if the file is not saved.
1364 (get-buffer-create name
)
1365 (with-current-buffer buf
1366 (kill-all-local-variables)
1367 (run-hooks 'kill-buffer-hook
)
1368 ;; Delete overlays before erasing the buffer so the overlay hooks
1369 ;; don't get run spuriously when we erase the buffer.
1370 (let ((ols (overlay-lists)))
1371 (dolist (ol (nconc (car ols
) (cdr ols
)))
1372 (delete-overlay ol
)))
1377 (defun custom-buffer-create (options &optional name description
)
1378 "Create a buffer containing OPTIONS.
1379 Optional NAME is the name of the buffer.
1380 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1381 SYMBOL is a customization option, and WIDGET is a widget for editing
1383 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1384 (custom-buffer-create-internal options description
))
1387 (defun custom-buffer-create-other-window (options &optional name description
)
1388 "Create a buffer containing OPTIONS, and display it in another window.
1389 The result includes selecting that window.
1390 Optional NAME is the name of the buffer.
1391 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1392 SYMBOL is a customization option, and WIDGET is a widget for editing
1394 (unless name
(setq name
"*Customization*"))
1395 (let ((pop-up-windows t
)
1396 (same-window-buffer-names nil
)
1397 (same-window-regexps nil
))
1398 (pop-to-buffer (custom-get-fresh-buffer name
))
1399 (custom-buffer-create-internal options description
)))
1401 (defcustom custom-reset-button-menu nil
1402 "If non-nil, only show a single reset button in customize buffers.
1403 This button will have a menu with all three reset operations."
1405 :group
'custom-buffer
)
1407 (defcustom custom-buffer-verbose-help t
1408 "If non-nil, include explanatory text in the customization buffer."
1410 :group
'custom-buffer
)
1412 (defun Custom-buffer-done (&rest ignore
)
1413 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1415 (quit-window custom-buffer-done-kill
))
1417 (defvar custom-button nil
1418 "Face used for buttons in customization buffers.")
1420 (defvar custom-button-mouse nil
1421 "Mouse face used for buttons in customization buffers.")
1423 (defvar custom-button-pressed nil
1424 "Face used for pressed buttons in customization buffers.")
1426 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1427 '(("unspecified" . unspecified
))))
1428 "If non-nil, indicate active buttons in a `raised-button' style.
1429 Otherwise use brackets."
1432 :group
'custom-buffer
1433 :set
(lambda (variable value
)
1434 (custom-set-default variable value
)
1436 (if value
'custom-button
'custom-button-unraised
))
1437 (setq custom-button-mouse
1438 (if value
'custom-button-mouse
'highlight
))
1439 (setq custom-button-pressed
1441 'custom-button-pressed
1442 'custom-button-pressed-unraised
))))
1444 (defun custom-buffer-create-internal (options &optional description
)
1446 (if custom-buffer-verbose-help
1448 (widget-insert "This is a customization buffer")
1450 (widget-insert description
))
1451 (widget-insert (format ".
1452 %s buttons; type RET or click mouse-1 to actuate one.
1453 Editing a setting changes only the text in the buffer.
1454 Use the setting's State button to set it or save changes in it.
1455 Saving a change normally works by editing your Emacs init file.
1457 (if custom-raised-buttons
1458 "`Raised' text indicates"
1459 "Square brackets indicate")))
1460 (widget-create 'info-link
1462 :button-face
'custom-link
1463 :mouse-face
'highlight
1464 "(emacs)Saving Customizations")
1466 " for information on how to save in a different file.\n
1468 (widget-create 'info-link
1470 :button-face
'custom-link
1471 :mouse-face
'highlight
1472 :help-echo
"Read the online help."
1473 "(emacs)Easy Customization")
1474 (widget-insert " for more information.\n\n")
1475 (widget-insert "Operate on everything in this buffer:\n "))
1476 (widget-insert " "))
1477 (widget-create 'push-button
1478 :tag
"Set for Current Session"
1480 Make your editing in this buffer take effect for this session."
1481 :action
(lambda (widget &optional event
)
1483 (if (not custom-buffer-verbose-help
)
1486 (widget-create 'info-link
1488 :button-face
'custom-link
1489 :mouse-face
'highlight
1490 :help-echo
"Read the online help."
1491 "(emacs)Easy Customization")))
1492 (when (or custom-file user-init-file
)
1494 (widget-create 'push-button
1495 :tag
"Save for Future Sessions"
1497 Make your editing in this buffer take effect for future Emacs sessions.
1498 This updates your Emacs initialization file or creates a new one."
1499 :action
(lambda (widget &optional event
)
1501 (if custom-reset-button-menu
1504 (widget-create 'push-button
1506 :help-echo
"Show a menu with reset operations."
1507 :mouse-down-action
(lambda (&rest junk
) t
)
1508 :action
(lambda (widget &optional event
)
1509 (custom-reset event
))))
1510 (widget-insert "\n ")
1511 (widget-create 'push-button
1512 :tag
"Reset to Current"
1514 Reset all edited text in this buffer to reflect current values."
1515 :action
'Custom-reset-current
)
1517 (widget-create 'push-button
1518 :tag
"Reset to Saved"
1520 Reset all settings in this buffer to their saved values."
1521 :action
'Custom-reset-saved
)
1523 (when (or custom-file user-init-file
)
1524 (widget-create 'push-button
1525 :tag
"Erase Customization"
1527 Un-customize all settings in this buffer and save them with standard values."
1528 :action
'Custom-reset-standard
)))
1530 (widget-create 'push-button
1533 (lambda (&rest ignore
)
1534 (if custom-buffer-done-kill
1536 "Bury this buffer"))
1537 :action
#'Custom-buffer-done
)
1538 (widget-insert "\n\n")
1539 (message "Creating customization items...")
1540 (buffer-disable-undo)
1541 (setq custom-options
1542 (if (= (length options
) 1)
1543 (mapcar (lambda (entry)
1544 (widget-create (nth 1 entry
)
1545 :documentation-shown t
1546 :custom-state
'unknown
1547 :tag
(custom-unlispify-tag-name
1549 :value
(nth 0 entry
)))
1552 (length (length options
)))
1553 (mapcar (lambda (entry)
1555 (message "Creating customization items ...%2d%%"
1556 (/ (* 100.0 count
) length
))
1557 (widget-create (nth 1 entry
)
1558 :tag
(custom-unlispify-tag-name
1560 :value
(nth 0 entry
))
1561 (setq count
(1+ count
))
1562 (unless (eq (preceding-char) ?
\n)
1563 (widget-insert "\n"))
1564 (widget-insert "\n")))
1566 (unless (eq (preceding-char) ?
\n)
1567 (widget-insert "\n"))
1568 (message "Creating customization items ...done")
1569 (message "Resetting customization items...")
1570 (unless (eq custom-buffer-style
'tree
)
1571 (mapc 'custom-magic-reset custom-options
))
1572 (message "Resetting customization items...done")
1573 (message "Creating customization setup...")
1575 (buffer-enable-undo)
1576 (goto-char (point-min))
1577 (message "Creating customization setup...done"))
1579 ;;; The Tree Browser.
1582 (defun customize-browse (&optional group
)
1583 "Create a tree browser for the customize hierarchy."
1586 (setq group
'emacs
))
1587 (let ((name "*Customize Browser*"))
1588 (pop-to-buffer (custom-get-fresh-buffer name
)))
1590 (widget-insert (format "\
1591 %s buttons; type RET or click mouse-1
1592 on a button to invoke its action.
1593 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1594 (if custom-raised-buttons
1595 "`Raised' text indicates"
1596 "Square brackets indicate")))
1599 (if custom-browse-only-groups
1601 Invoke the [Group] button below to edit that item in another window.\n\n")
1602 (widget-insert "Invoke the ")
1603 (widget-create 'item
1606 :tag-glyph
"folder")
1607 (widget-insert ", ")
1608 (widget-create 'item
1612 (widget-insert ", and ")
1613 (widget-create 'item
1616 :tag-glyph
"option")
1617 (widget-insert " buttons below to edit that
1618 item in another window.\n\n"))
1619 (let ((custom-buffer-style 'tree
))
1620 (widget-create 'custom-group
1622 :custom-state
'unknown
1623 :tag
(custom-unlispify-tag-name group
)
1626 (goto-char (point-min)))
1628 (define-widget 'custom-browse-visibility
'item
1629 "Control visibility of items in the customize tree browser."
1631 :action
'custom-browse-visibility-action
)
1633 (defun custom-browse-visibility-action (widget &rest ignore
)
1634 (let ((custom-buffer-style 'tree
))
1635 (custom-toggle-parent widget
)))
1637 (define-widget 'custom-browse-group-tag
'push-button
1638 "Show parent in other window when activated."
1641 :action
'custom-browse-group-tag-action
)
1643 (defun custom-browse-group-tag-action (widget &rest ignore
)
1644 (let ((parent (widget-get widget
:parent
)))
1645 (customize-group-other-window (widget-value parent
))))
1647 (define-widget 'custom-browse-variable-tag
'push-button
1648 "Show parent in other window when activated."
1651 :action
'custom-browse-variable-tag-action
)
1653 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1654 (let ((parent (widget-get widget
:parent
)))
1655 (customize-variable-other-window (widget-value parent
))))
1657 (define-widget 'custom-browse-face-tag
'push-button
1658 "Show parent in other window when activated."
1661 :action
'custom-browse-face-tag-action
)
1663 (defun custom-browse-face-tag-action (widget &rest ignore
)
1664 (let ((parent (widget-get widget
:parent
)))
1665 (customize-face-other-window (widget-value parent
))))
1667 (defconst custom-browse-alist
'((" " "space")
1673 (defun custom-browse-insert-prefix (prefix)
1674 "Insert PREFIX. On XEmacs convert it to line graphics."
1675 ;; Fixme: do graphics.
1676 (if nil
; (string-match "XEmacs" emacs-version)
1679 (while (not (string-equal prefix
""))
1680 (let ((entry (substring prefix
0 3)))
1681 (setq prefix
(substring prefix
3))
1682 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1683 (name (nth 1 (assoc entry custom-browse-alist
))))
1684 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1685 (overlay-put overlay
'start-open t
)
1686 (overlay-put overlay
'end-open t
)))))
1689 ;;; Modification of Basic Widgets.
1691 ;; We add extra properties to the basic widgets needed here. This is
1692 ;; fine, as long as we are careful to stay within out own namespace.
1694 ;; We want simple widgets to be displayed by default, but complex
1695 ;; widgets to be hidden.
1697 (widget-put (get 'item
'widget-type
) :custom-show t
)
1698 (widget-put (get 'editable-field
'widget-type
)
1699 :custom-show
(lambda (widget value
)
1700 (let ((pp (pp-to-string value
)))
1701 (cond ((string-match "\n" pp
)
1706 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1708 ;;; The `custom-manual' Widget.
1710 (define-widget 'custom-manual
'info-link
1711 "Link to the manual entry for this customization option."
1712 :help-echo
"Read the manual entry for this option."
1713 :button-face
'custom-link
1714 :mouse-face
'highlight
1717 ;;; The `custom-magic' Widget.
1719 (defgroup custom-magic-faces nil
1720 "Faces used by the magic button."
1721 :group
'custom-faces
1722 :group
'custom-buffer
)
1724 (defface custom-invalid
'((((class color
))
1725 (:foreground
"yellow1" :background
"red1"))
1727 (:weight bold
:slant italic
:underline t
)))
1728 "Face used when the customize item is invalid."
1729 :group
'custom-magic-faces
)
1730 ;; backward-compatibility alias
1731 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1733 (defface custom-rogue
'((((class color
))
1734 (:foreground
"pink" :background
"black"))
1737 "Face used when the customize item is not defined for customization."
1738 :group
'custom-magic-faces
)
1739 ;; backward-compatibility alias
1740 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1742 (defface custom-modified
'((((min-colors 88) (class color
))
1743 (:foreground
"white" :background
"blue1"))
1745 (:foreground
"white" :background
"blue"))
1747 (:slant italic
:bold
)))
1748 "Face used when the customize item has been modified."
1749 :group
'custom-magic-faces
)
1750 ;; backward-compatibility alias
1751 (put 'custom-modified-face
'face-alias
'custom-modified
)
1753 (defface custom-set
'((((min-colors 88) (class color
))
1754 (:foreground
"blue1" :background
"white"))
1756 (:foreground
"blue" :background
"white"))
1759 "Face used when the customize item has been set."
1760 :group
'custom-magic-faces
)
1761 ;; backward-compatibility alias
1762 (put 'custom-set-face
'face-alias
'custom-set
)
1764 (defface custom-changed
'((((min-colors 88) (class color
))
1765 (:foreground
"white" :background
"blue1"))
1767 (:foreground
"white" :background
"blue"))
1770 "Face used when the customize item has been changed."
1771 :group
'custom-magic-faces
)
1772 ;; backward-compatibility alias
1773 (put 'custom-changed-face
'face-alias
'custom-changed
)
1775 (defface custom-themed
'((((min-colors 88) (class color
))
1776 (:foreground
"white" :background
"blue1"))
1778 (:foreground
"white" :background
"blue"))
1781 "Face used when the customize item has been set by a theme."
1782 :group
'custom-magic-faces
)
1784 (defface custom-saved
'((t (:underline t
)))
1785 "Face used when the customize item has been saved."
1786 :group
'custom-magic-faces
)
1787 ;; backward-compatibility alias
1788 (put 'custom-saved-face
'face-alias
'custom-saved
)
1790 (defconst custom-magic-alist
1791 '((nil "#" underline
"\
1792 UNINITIALIZED, you should not see this.")
1793 (unknown "?" italic
"\
1794 UNKNOWN, you should not see this.")
1795 (hidden "-" default
"\
1796 HIDDEN, invoke \"Show\" in the previous line to show." "\
1797 group now hidden, invoke \"Show\", above, to show contents.")
1798 (invalid "x" custom-invalid
"\
1799 INVALID, the displayed value cannot be set.")
1800 (modified "*" custom-modified
"\
1801 EDITED, shown value does not take effect until you set or save it." "\
1802 something in this group has been edited but not set.")
1803 (set "+" custom-set
"\
1804 SET for current session only." "\
1805 something in this group has been set but not saved.")
1806 (changed ":" custom-changed
"\
1807 CHANGED outside Customize; operating on it here may be unreliable." "\
1808 something in this group has been changed outside customize.")
1809 (saved "!" custom-saved
"\
1811 something in this group has been set and saved.")
1812 (themed "o" custom-themed
"\
1814 visible group members are all at standard values.")
1815 (rogue "@" custom-rogue
"\
1816 NO CUSTOMIZATION DATA; not intended to be customized." "\
1817 something in this group is not prepared for customization.")
1818 (standard " " nil
"\
1820 visible group members are all at standard values."))
1821 "Alist of customize option states.
1822 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1824 STATE is one of the following symbols:
1827 For internal use, should never occur.
1829 For internal use, should never occur.
1831 This item is not being displayed.
1833 This item is modified, but has an invalid form.
1835 This item is modified, and has a valid form.
1837 This item has been set but not saved.
1839 The current value of this item has been changed outside Customize.
1841 This item is marked for saving.
1843 This item has no customization information.
1845 This item is unchanged from the standard setting.
1847 MAGIC is a string used to present that state.
1849 FACE is a face used to present the state.
1851 ITEM-DESC is a string describing the state for options.
1853 GROUP-DESC is a string describing the state for groups. If this is
1854 left out, ITEM-DESC will be used.
1856 The string %c in either description will be replaced with the
1857 category of the item. These are `group'. `option', and `face'.
1859 The list should be sorted most significant first.")
1861 (defcustom custom-magic-show
'long
1862 "If non-nil, show textual description of the state.
1863 If `long', show a full-line description, not just one word."
1864 :type
'(choice (const :tag
"no" nil
)
1866 (other :tag
"short" short
))
1867 :group
'custom-buffer
)
1869 (defcustom custom-magic-show-hidden
'(option face
)
1870 "Control whether the State button is shown for hidden items.
1871 The value should be a list with the custom categories where the State
1872 button should be visible. Possible categories are `group', `option',
1874 :type
'(set (const group
) (const option
) (const face
))
1875 :group
'custom-buffer
)
1877 (defcustom custom-magic-show-button nil
1878 "Show a \"magic\" button indicating the state of each customization option."
1880 :group
'custom-buffer
)
1882 (define-widget 'custom-magic
'default
1883 "Show and manipulate state for a customization option."
1885 :action
'widget-parent-action
1888 :value-create
'custom-magic-value-create
1889 :value-delete
'widget-children-value-delete
)
1891 (defun widget-magic-mouse-down-action (widget &optional event
)
1892 ;; Non-nil unless hidden.
1893 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1897 (defun custom-magic-value-create (widget)
1898 "Create compact status report for WIDGET."
1899 (let* ((parent (widget-get widget
:parent
))
1900 (state (widget-get parent
:custom-state
))
1901 (hidden (eq state
'hidden
))
1902 (entry (assq state custom-magic-alist
))
1903 (magic (nth 1 entry
))
1904 (face (nth 2 entry
))
1905 (category (widget-get parent
:custom-category
))
1906 (text (or (and (eq category
'group
)
1909 (form (widget-get parent
:custom-form
))
1911 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1912 (setq text
(concat (match-string 1 text
)
1913 (symbol-name category
)
1914 (match-string 2 text
))))
1915 (when (and custom-magic-show
1917 (memq category custom-magic-show-hidden
)))
1919 (when (and (eq category
'group
)
1920 (not (and (eq custom-buffer-style
'links
)
1921 (> (widget-get parent
:custom-level
) 1))))
1922 (insert-char ?\
(* custom-buffer-indent
1923 (widget-get parent
:custom-level
))))
1924 (push (widget-create-child-and-convert
1926 :help-echo
"Change the state of this item."
1927 :format
(if hidden
"%t" "%[%t%]")
1928 :button-prefix
'widget-push-button-prefix
1929 :button-suffix
'widget-push-button-suffix
1930 :mouse-down-action
'widget-magic-mouse-down-action
1934 (let ((start (point)))
1935 (if (eq custom-magic-show
'long
)
1937 (insert (symbol-name state
)))
1938 (cond ((eq form
'lisp
)
1940 ((eq form
'mismatch
)
1941 (insert " (mismatch)")))
1942 (put-text-property start
(point) 'face
'custom-state
))
1944 (when (and (eq category
'group
)
1945 (not (and (eq custom-buffer-style
'links
)
1946 (> (widget-get parent
:custom-level
) 1))))
1947 (insert-char ?\
(* custom-buffer-indent
1948 (widget-get parent
:custom-level
))))
1949 (when custom-magic-show-button
1950 (when custom-magic-show
1951 (let ((indent (widget-get parent
:indent
)))
1953 (insert-char ? indent
))))
1954 (push (widget-create-child-and-convert
1956 :mouse-down-action
'widget-magic-mouse-down-action
1960 :help-echo
"Change the state."
1961 :format
(if hidden
"%t" "%[%t%]")
1962 :tag
(if (memq form
'(lisp mismatch
))
1963 (concat "(" magic
")")
1964 (concat "[" magic
"]")))
1967 (widget-put widget
:children children
)))
1969 (defun custom-magic-reset (widget)
1970 "Redraw the :custom-magic property of WIDGET."
1971 (let ((magic (widget-get widget
:custom-magic
)))
1972 (widget-value-set magic
(widget-value magic
))))
1974 ;;; The `custom' Widget.
1976 (defface custom-button
1977 '((((type x w32 mac
) (class color
)) ; Like default modeline
1978 (:box
(:line-width
2 :style released-button
)
1979 :background
"lightgrey" :foreground
"black"))
1982 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1984 :group
'custom-faces
)
1985 ;; backward-compatibility alias
1986 (put 'custom-button-face
'face-alias
'custom-button
)
1988 (defface custom-button-mouse
1989 '((((type x w32 mac
) (class color
))
1990 (:box
(:line-width
2 :style released-button
)
1991 :background
"grey90" :foreground
"black"))
1994 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1996 :group
'custom-faces
)
1998 (defface custom-button-unraised
2000 (class color
) (background light
)) :foreground
"blue1" :underline t
)
2001 (((class color
) (background light
)) :foreground
"blue" :underline t
)
2003 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
2004 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
2006 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2008 :group
'custom-faces
)
2011 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2013 (setq custom-button-mouse
2014 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2016 (defface custom-button-pressed
2017 '((((type x w32 mac
) (class color
))
2018 (:box
(:line-width
2 :style pressed-button
)
2019 :background
"lightgrey" :foreground
"black"))
2021 (:inverse-video t
)))
2022 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2024 :group
'custom-faces
)
2025 ;; backward-compatibility alias
2026 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2028 (defface custom-button-pressed-unraised
2029 '((default :inherit custom-button-unraised
)
2030 (((class color
) (background light
)) :foreground
"magenta4")
2031 (((class color
) (background dark
)) :foreground
"violet"))
2032 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2034 :group
'custom-faces
)
2036 (setq custom-button-pressed
2037 (if custom-raised-buttons
2038 'custom-button-pressed
2039 'custom-button-pressed-unraised
))
2041 (defface custom-documentation nil
2042 "Face used for documentation strings in customization buffers."
2043 :group
'custom-faces
)
2044 ;; backward-compatibility alias
2045 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2047 (defface custom-state
'((((class color
)
2049 (:foreground
"lime green"))
2052 (:foreground
"dark green"))
2054 "Face used for State descriptions in the customize buffer."
2055 :group
'custom-faces
)
2056 ;; backward-compatibility alias
2057 (put 'custom-state-face
'face-alias
'custom-state
)
2059 (defface custom-link
2061 (class color
) (background light
)) :foreground
"blue1" :underline t
)
2062 (((class color
) (background light
)) :foreground
"blue" :underline t
)
2064 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
2065 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
2067 "Face for Info links in customization buffers."
2070 (define-widget 'custom
'default
2071 "Customize a user option."
2073 :convert-widget
'custom-convert-widget
2074 :notify
'custom-notify
2077 :custom-state
'hidden
2078 :documentation-property
'widget-subclass-responsibility
2079 :value-create
'widget-subclass-responsibility
2080 :value-delete
'widget-children-value-delete
2081 :value-get
'widget-value-value-get
2082 :validate
'widget-children-validate
2083 :match
(lambda (widget value
) (symbolp value
)))
2085 (defun custom-convert-widget (widget)
2086 "Initialize :value and :tag from :args in WIDGET."
2087 (let ((args (widget-get widget
:args
)))
2089 (widget-put widget
:value
(widget-apply widget
2090 :value-to-internal
(car args
)))
2091 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2092 (widget-put widget
:args nil
)))
2095 (defun custom-notify (widget &rest args
)
2096 "Keep track of changes."
2097 (let ((state (widget-get widget
:custom-state
)))
2098 (unless (eq state
'modified
)
2099 (unless (memq state
'(nil unknown hidden
))
2100 (widget-put widget
:custom-state
'modified
))
2101 (custom-magic-reset widget
)
2102 (apply 'widget-default-notify widget args
))))
2104 (defun custom-redraw (widget)
2105 "Redraw WIDGET with current settings."
2106 (let ((line (count-lines (point-min) (point)))
2107 (column (current-column))
2109 (from (marker-position (widget-get widget
:from
)))
2110 (to (marker-position (widget-get widget
:to
))))
2112 (widget-value-set widget
(widget-value widget
))
2113 (custom-redraw-magic widget
))
2114 (when (and (>= pos from
) (<= pos to
))
2119 (goto-line (1+ line
)))
2120 (move-to-column column
))
2123 (defun custom-redraw-magic (widget)
2124 "Redraw WIDGET state with current settings."
2126 (let ((magic (widget-get widget
:custom-magic
)))
2128 (widget-value-set magic
(widget-value magic
))
2129 (when (setq widget
(widget-get widget
:group
))
2130 (custom-group-state-update widget
)))
2132 (setq widget nil
)))))
2135 (defun custom-show (widget value
)
2136 "Non-nil if WIDGET should be shown with VALUE by default."
2137 (let ((show (widget-get widget
:custom-show
)))
2143 (funcall show widget value
)))))
2145 (defun custom-load-widget (widget)
2146 "Load all dependencies for WIDGET."
2147 (custom-load-symbol (widget-value widget
)))
2149 (defun custom-unloaded-symbol-p (symbol)
2150 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2152 (loads (get symbol
'custom-loads
))
2155 (setq load
(car loads
)
2157 (cond ((symbolp load
)
2158 (unless (featurep load
)
2160 ((assoc load load-history
))
2161 ((assoc (locate-library load
) load-history
)
2167 (defun custom-unloaded-widget-p (widget)
2168 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2169 (custom-unloaded-symbol-p (widget-value widget
)))
2171 (defun custom-toggle-hide (widget)
2172 "Toggle visibility of WIDGET."
2173 (custom-load-widget widget
)
2174 (let ((state (widget-get widget
:custom-state
)))
2175 (cond ((memq state
'(invalid modified
))
2176 (error "There are unset changes"))
2178 (widget-put widget
:custom-state
'unknown
))
2180 (widget-put widget
:documentation-shown nil
)
2181 (widget-put widget
:custom-state
'hidden
)))
2182 (custom-redraw widget
)
2185 (defun custom-toggle-parent (widget &rest ignore
)
2186 "Toggle visibility of parent of WIDGET."
2187 (custom-toggle-hide (widget-get widget
:parent
)))
2189 (defun custom-add-see-also (widget &optional prefix
)
2190 "Add `See also ...' to WIDGET if there are any links.
2191 Insert PREFIX first if non-nil."
2192 (let* ((symbol (widget-get widget
:value
))
2193 (links (get symbol
'custom-links
))
2194 (many (> (length links
) 2))
2195 (buttons (widget-get widget
:buttons
))
2196 (indent (widget-get widget
:indent
)))
2199 (insert-char ?\ indent
))
2202 (insert "See also ")
2204 (push (widget-create-child-and-convert widget
(car links
))
2206 (setq links
(cdr links
))
2215 (widget-put widget
:buttons buttons
))))
2217 (defun custom-add-parent-links (widget &optional initial-string
)
2218 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2219 The value is non-nil if any parents were found.
2220 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2221 (let ((name (widget-value widget
))
2222 (type (widget-type widget
))
2223 (buttons (widget-get widget
:buttons
))
2226 (insert (or initial-string
"Parent groups:"))
2227 (mapatoms (lambda (symbol)
2228 (when (member (list name type
) (get symbol
'custom-group
))
2230 (push (widget-create-child-and-convert
2231 widget
'custom-group-link
2232 :button-face
'custom-link
2233 :mouse-face
'highlight
2234 :tag
(custom-unlispify-tag-name symbol
)
2237 (setq parents
(cons symbol parents
)))))
2238 (and (null (get name
'custom-links
)) ;No links of its own.
2239 (= (length parents
) 1) ;A single parent.
2240 (let* ((links (delq nil
(mapcar (lambda (w)
2241 (unless (eq (widget-type w
)
2244 (get (car parents
) 'custom-links
))))
2245 (many (> (length links
) 2)))
2247 (insert "\nParent documentation: ")
2249 (push (widget-create-child-and-convert widget
(car links
))
2251 (setq links
(cdr links
))
2262 (delete-region start
(point)))
2263 (widget-put widget
:buttons buttons
)
2266 ;;; The `custom-comment' Widget.
2268 ;; like the editable field
2269 (defface custom-comment
'((((type tty
))
2270 :background
"yellow3"
2271 :foreground
"black")
2272 (((class grayscale color
)
2274 :background
"gray85")
2275 (((class grayscale color
)
2277 :background
"dim gray")
2280 "Face used for comments on variables or faces"
2282 :group
'custom-faces
)
2283 ;; backward-compatibility alias
2284 (put 'custom-comment-face
'face-alias
'custom-comment
)
2286 ;; like font-lock-comment-face
2287 (defface custom-comment-tag
2288 '((((class color
) (background dark
)) (:foreground
"gray80"))
2289 (((class color
) (background light
)) (:foreground
"blue4"))
2290 (((class grayscale
) (background light
))
2291 (:foreground
"DimGray" :weight bold
:slant italic
))
2292 (((class grayscale
) (background dark
))
2293 (:foreground
"LightGray" :weight bold
:slant italic
))
2295 "Face used for variables or faces comment tags"
2296 :group
'custom-faces
)
2297 ;; backward-compatibility alias
2298 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2300 (define-widget 'custom-comment
'string
2303 :help-echo
"Edit a comment here."
2304 :sample-face
'custom-comment-tag-face
2305 :value-face
'custom-comment-face
2307 :create
'custom-comment-create
)
2309 (defun custom-comment-create (widget)
2310 (let* ((null-comment (equal "" (widget-value widget
))))
2311 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2313 (widget-default-create widget
)
2314 ;; `widget-default-delete' expects markers in these slots --
2315 ;; maybe it shouldn't.
2316 (widget-put widget
:from
(point-marker))
2317 (widget-put widget
:to
(point-marker)))))
2319 (defun custom-comment-hide (widget)
2320 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2322 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2323 ;; the global custom one
2324 (defun custom-comment-show (widget)
2325 (widget-put widget
:comment-shown t
)
2326 (custom-redraw widget
)
2329 (defun custom-comment-invisible-p (widget)
2330 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2332 (not (widget-get widget
:comment-shown
)))))
2334 ;;; The `custom-variable' Widget.
2336 ;; When this was underlined blue, users confused it with a
2337 ;; Mosaic-style hyperlink...
2338 (defface custom-variable-tag
2341 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2342 (((min-colors 88) (class color
)
2344 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2347 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2349 "Face used for unpushable variable tags."
2350 :group
'custom-faces
)
2351 ;; backward-compatibility alias
2352 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2354 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2355 "Face used for pushable variable tags."
2356 :group
'custom-faces
)
2357 ;; backward-compatibility alias
2358 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2360 (defcustom custom-variable-default-form
'edit
2361 "Default form of displaying variable values."
2362 :type
'(choice (const edit
)
2364 :group
'custom-buffer
2367 (defun custom-variable-documentation (variable)
2368 "Return documentation of VARIABLE for use in Custom buffer.
2369 Normally just return the docstring. But if VARIABLE automatically
2370 becomes buffer local when set, append a message to that effect."
2371 (if (and (local-variable-if-set-p variable
)
2372 (or (not (local-variable-p variable
))
2374 (local-variable-if-set-p variable
))))
2375 (concat (documentation-property variable
'variable-documentation
)
2377 This variable automatically becomes buffer-local when set outside Custom.
2378 However, setting it through Custom sets the default value.")
2379 (documentation-property variable
'variable-documentation
)))
2381 (define-widget 'custom-variable
'custom
2382 "Customize variable."
2384 :help-echo
"Set or reset this variable."
2385 :documentation-property
#'custom-variable-documentation
2386 :custom-category
'option
2388 :custom-menu
'custom-variable-menu-create
2389 :custom-form nil
; defaults to value of `custom-variable-default-form'
2390 :value-create
'custom-variable-value-create
2391 :action
'custom-variable-action
2392 :custom-set
'custom-variable-set
2393 :custom-save
'custom-variable-save
2394 :custom-reset-current
'custom-redraw
2395 :custom-reset-saved
'custom-variable-reset-saved
2396 :custom-reset-standard
'custom-variable-reset-standard
2397 :custom-standard-value
'custom-variable-standard-value
)
2399 (defun custom-variable-type (symbol)
2400 "Return a widget suitable for editing the value of SYMBOL.
2401 If SYMBOL has a `custom-type' property, use that.
2402 Otherwise, look up symbol in `custom-guess-type-alist'."
2403 (let* ((type (or (get symbol
'custom-type
)
2404 (and (not (get symbol
'standard-value
))
2405 (custom-guess-type symbol
))
2407 (options (get symbol
'custom-options
))
2408 (tmp (if (listp type
)
2409 (copy-sequence type
)
2412 (widget-put tmp
:options options
))
2415 (defun custom-variable-value-create (widget)
2416 "Here is where you edit the variable's value."
2417 (custom-load-widget widget
)
2418 (unless (widget-get widget
:custom-form
)
2419 (widget-put widget
:custom-form custom-variable-default-form
))
2420 (let* ((buttons (widget-get widget
:buttons
))
2421 (children (widget-get widget
:children
))
2422 (form (widget-get widget
:custom-form
))
2423 (state (widget-get widget
:custom-state
))
2424 (symbol (widget-get widget
:value
))
2425 (tag (widget-get widget
:tag
))
2426 (type (custom-variable-type symbol
))
2427 (conv (widget-convert type
))
2428 (get (or (get symbol
'custom-get
) 'default-value
))
2429 (prefix (widget-get widget
:custom-prefix
))
2430 (last (widget-get widget
:custom-last
))
2431 (value (if (default-boundp symbol
)
2432 (funcall get symbol
)
2433 (widget-get conv
:value
))))
2434 ;; If the widget is new, the child determines whether it is hidden.
2436 ((custom-show type value
)
2437 (setq state
'unknown
))
2439 (setq state
'hidden
)))
2440 ;; If we don't know the state, see if we need to edit it in lisp form.
2441 (when (eq state
'unknown
)
2442 (unless (widget-apply conv
:match value
)
2443 ;; (widget-apply (widget-convert type) :match value)
2444 (setq form
'mismatch
)))
2445 ;; Now we can create the child widget.
2446 (cond ((eq custom-buffer-style
'tree
)
2447 (insert prefix
(if last
" `--- " " |--- "))
2448 (push (widget-create-child-and-convert
2449 widget
'custom-browse-variable-tag
)
2451 (insert " " tag
"\n")
2452 (widget-put widget
:buttons buttons
))
2454 ;; Indicate hidden value.
2455 (push (widget-create-child-and-convert
2458 :sample-face
'custom-variable-tag-face
2462 (push (widget-create-child-and-convert
2464 :help-echo
"Show the value of this option."
2466 :action
'custom-toggle-parent
2469 ((memq form
'(lisp mismatch
))
2470 ;; In lisp mode edit the saved value when possible.
2471 (let* ((value (cond ((get symbol
'saved-value
)
2472 (car (get symbol
'saved-value
)))
2473 ((get symbol
'standard-value
)
2474 (car (get symbol
'standard-value
)))
2475 ((default-boundp symbol
)
2476 (custom-quote (funcall get symbol
)))
2478 (custom-quote (widget-get conv
:value
))))))
2479 (insert (symbol-name symbol
) ": ")
2480 (push (widget-create-child-and-convert
2482 :help-echo
"Hide the value of this option."
2485 :action
'custom-toggle-parent
2489 (push (widget-create-child-and-convert
2491 :button-face
'custom-variable-button-face
2493 :tag
(symbol-name symbol
)
2499 (let* ((format (widget-get type
:format
))
2500 tag-format value-format
)
2501 (unless (string-match ":" format
)
2502 (error "Bad format"))
2503 (setq tag-format
(substring format
0 (match-end 0)))
2504 (setq value-format
(substring format
(match-end 0)))
2505 (push (widget-create-child-and-convert
2508 :action
'custom-tag-action
2509 :help-echo
"Change value of this option."
2510 :mouse-down-action
'custom-tag-mouse-down-action
2511 :button-face
'custom-variable-button-face
2512 :sample-face
'custom-variable-tag-face
2516 (push (widget-create-child-and-convert
2518 :help-echo
"Hide the value of this option."
2521 :action
'custom-toggle-parent
2524 (push (widget-create-child-and-convert
2526 :format value-format
2529 (unless (eq custom-buffer-style
'tree
)
2530 (unless (eq (preceding-char) ?
\n)
2531 (widget-insert "\n"))
2532 ;; Create the magic button.
2533 (let ((magic (widget-create-child-and-convert
2534 widget
'custom-magic nil
)))
2535 (widget-put widget
:custom-magic magic
)
2536 (push magic buttons
))
2537 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2538 ;; before the call to `widget-default-format-handler'. Otherwise, I
2539 ;; loose my current `buttons'. This function shouldn't be called like
2540 ;; this anyway. The doc string widget should be added like the others.
2542 (widget-put widget
:buttons buttons
)
2544 ;; Insert documentation.
2545 (widget-default-format-handler widget ?h
)
2547 ;; The comment field
2548 (unless (eq state
'hidden
)
2549 (let* ((comment (get symbol
'variable-comment
))
2551 (widget-create-child-and-convert
2552 widget
'custom-comment
2554 :value
(or comment
""))))
2555 (widget-put widget
:comment-widget comment-widget
)
2556 ;; Don't push it !!! Custom assumes that the first child is the
2558 (setq children
(append children
(list comment-widget
)))))
2559 ;; Update the rest of the properties properties.
2560 (widget-put widget
:custom-form form
)
2561 (widget-put widget
:children children
)
2562 ;; Now update the state.
2563 (if (eq state
'hidden
)
2564 (widget-put widget
:custom-state state
)
2565 (custom-variable-state-set widget
))
2567 (unless (eq state
'hidden
)
2568 (when (eq (widget-get widget
:custom-level
) 1)
2569 (custom-add-parent-links widget
))
2570 (custom-add-see-also widget
)))))
2572 (defun custom-tag-action (widget &rest args
)
2573 "Pass :action to first child of WIDGET's parent."
2574 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2577 (defun custom-tag-mouse-down-action (widget &rest args
)
2578 "Pass :mouse-down-action to first child of WIDGET's parent."
2579 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2580 :mouse-down-action args
))
2582 (defun custom-variable-state-set (widget)
2583 "Set the state of WIDGET."
2584 (let* ((symbol (widget-value widget
))
2585 (get (or (get symbol
'custom-get
) 'default-value
))
2586 (value (if (default-boundp symbol
)
2587 (funcall get symbol
)
2588 (widget-get widget
:value
)))
2589 (comment (get symbol
'variable-comment
))
2592 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2594 (get symbol
'customized-variable-comment
))
2596 (if (condition-case nil
2597 (and (equal value
(eval (car tmp
)))
2598 (equal comment temp
))
2602 ((progn (setq tmp
(get symbol
'theme-value
))
2603 (setq temp
(get symbol
'saved-variable-comment
))
2605 (if (condition-case nil
2606 (and (equal comment temp
)
2609 (car (custom-variable-theme-value
2613 ((eq (caar tmp
) 'user
) 'saved
)
2614 ((eq (caar tmp
) 'changed
) 'changed
)
2617 ((setq tmp
(get symbol
'standard-value
))
2618 (if (condition-case nil
2619 (and (equal value
(eval (car tmp
)))
2620 (equal comment nil
))
2625 (widget-put widget
:custom-state state
)))
2627 (defun custom-variable-standard-value (widget)
2628 (get (widget-value widget
) 'standard-value
))
2630 (defvar custom-variable-menu
2631 `(("Set for current session" custom-variable-set
2633 (eq (widget-get widget
:custom-state
) 'modified
)))
2634 ,@(when (or custom-file user-init-file
)
2635 '(("Save for future sessions" custom-variable-save
2637 (memq (widget-get widget
:custom-state
)
2638 '(modified set changed rogue
))))))
2639 ("---" ignore ignore
)
2640 ("Reset to current value" custom-redraw
2642 (and (default-boundp (widget-value widget
))
2643 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2644 ("Reset to saved value" custom-variable-reset-saved
2646 (and (or (get (widget-value widget
) 'saved-value
)
2647 (get (widget-value widget
) 'saved-variable-comment
))
2648 (memq (widget-get widget
:custom-state
)
2649 '(modified set changed rogue
)))))
2650 ("Reset to backup value" custom-variable-reset-backup
2652 (get (widget-value widget
) 'backup-value
)))
2653 ,@(when (or custom-file user-init-file
)
2654 '(("Erase customization" custom-variable-reset-standard
2656 (and (get (widget-value widget
) 'standard-value
)
2657 (memq (widget-get widget
:custom-state
)
2658 '(modified set changed saved rogue
)))))))
2659 ("---" ignore ignore
)
2660 ("Add comment" custom-comment-show custom-comment-invisible-p
)
2661 ("Show value widget" custom-variable-edit
2663 (eq (widget-get widget
:custom-form
) 'lisp
)))
2664 ("Show Lisp expression" custom-variable-edit-lisp
2666 (eq (widget-get widget
:custom-form
) 'edit
))))
2667 "Alist of actions for the `custom-variable' widget.
2668 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2669 the menu entry, ACTION is the function to call on the widget when the
2670 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2671 widget as an argument, and returns non-nil if ACTION is valid on that
2672 widget. If FILTER is nil, ACTION is always valid.")
2674 (defun custom-variable-action (widget &optional event
)
2675 "Show the menu for `custom-variable' WIDGET.
2676 Optional EVENT is the location for the menu."
2677 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2678 (custom-toggle-hide widget
)
2679 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2680 (custom-variable-state-set widget
))
2681 (custom-redraw-magic widget
)
2682 (let* ((completion-ignore-case t
)
2683 (answer (widget-choose (concat "Operation on "
2684 (custom-unlispify-tag-name
2685 (widget-get widget
:value
)))
2686 (custom-menu-filter custom-variable-menu
2690 (funcall answer widget
)))))
2692 (defun custom-variable-edit (widget)
2693 "Edit value of WIDGET."
2694 (widget-put widget
:custom-state
'unknown
)
2695 (widget-put widget
:custom-form
'edit
)
2696 (custom-redraw widget
))
2698 (defun custom-variable-edit-lisp (widget)
2699 "Edit the Lisp representation of the value of WIDGET."
2700 (widget-put widget
:custom-state
'unknown
)
2701 (widget-put widget
:custom-form
'lisp
)
2702 (custom-redraw widget
))
2704 (defun custom-variable-set (widget)
2705 "Set the current value for the variable being edited by WIDGET."
2706 (let* ((form (widget-get widget
:custom-form
))
2707 (state (widget-get widget
:custom-state
))
2708 (child (car (widget-get widget
:children
)))
2709 (symbol (widget-value widget
))
2710 (set (or (get symbol
'custom-set
) 'set-default
))
2711 (comment-widget (widget-get widget
:comment-widget
))
2712 (comment (widget-value comment-widget
))
2714 (cond ((eq state
'hidden
)
2715 (error "Cannot set hidden variable"))
2716 ((setq val
(widget-apply child
:validate
))
2717 (goto-char (widget-get val
:from
))
2718 (error "%s" (widget-get val
:error
)))
2719 ((memq form
'(lisp mismatch
))
2720 (when (equal comment
"")
2722 ;; Make the comment invisible by hand if it's empty
2723 (custom-comment-hide comment-widget
))
2724 (custom-variable-backup-value widget
)
2725 (custom-push-theme 'theme-value symbol
'user
2726 'set
(custom-quote (widget-value child
)))
2727 (funcall set symbol
(eval (setq val
(widget-value child
))))
2728 (put symbol
'customized-value
(list val
))
2729 (put symbol
'variable-comment comment
)
2730 (put symbol
'customized-variable-comment comment
))
2732 (when (equal comment
"")
2734 ;; Make the comment invisible by hand if it's empty
2735 (custom-comment-hide comment-widget
))
2736 (custom-variable-backup-value widget
)
2737 (custom-push-theme 'theme-value symbol
'user
2738 'set
(custom-quote (widget-value child
)))
2739 (funcall set symbol
(setq val
(widget-value child
)))
2740 (put symbol
'customized-value
(list (custom-quote val
)))
2741 (put symbol
'variable-comment comment
)
2742 (put symbol
'customized-variable-comment comment
)))
2743 (custom-variable-state-set widget
)
2744 (custom-redraw-magic widget
)))
2746 (defun custom-variable-save (widget)
2747 "Set and save the value for the variable being edited by WIDGET."
2748 (let* ((form (widget-get widget
:custom-form
))
2749 (state (widget-get widget
:custom-state
))
2750 (child (car (widget-get widget
:children
)))
2751 (symbol (widget-value widget
))
2752 (set (or (get symbol
'custom-set
) 'set-default
))
2753 (comment-widget (widget-get widget
:comment-widget
))
2754 (comment (widget-value comment-widget
))
2756 (cond ((eq state
'hidden
)
2757 (error "Cannot set hidden variable"))
2758 ((setq val
(widget-apply child
:validate
))
2759 (goto-char (widget-get val
:from
))
2760 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2761 ((memq form
'(lisp mismatch
))
2762 (when (equal comment
"")
2764 ;; Make the comment invisible by hand if it's empty
2765 (custom-comment-hide comment-widget
))
2766 (put symbol
'saved-value
(list (widget-value child
)))
2767 (custom-push-theme 'theme-value symbol
'user
2768 'set
(custom-quote (widget-value child
)))
2769 (funcall set symbol
(eval (widget-value child
)))
2770 (put symbol
'variable-comment comment
)
2771 (put symbol
'saved-variable-comment comment
))
2773 (when (equal comment
"")
2775 ;; Make the comment invisible by hand if it's empty
2776 (custom-comment-hide comment-widget
))
2777 (put symbol
'saved-value
2778 (list (custom-quote (widget-value child
))))
2779 (custom-push-theme 'theme-value symbol
'user
2780 'set
(custom-quote (widget-value child
)))
2781 (funcall set symbol
(widget-value child
))
2782 (put symbol
'variable-comment comment
)
2783 (put symbol
'saved-variable-comment comment
)))
2784 (put symbol
'customized-value nil
)
2785 (put symbol
'customized-variable-comment nil
)
2787 (custom-variable-state-set widget
)
2788 (custom-redraw-magic widget
)))
2790 (defun custom-variable-reset-saved (widget)
2791 "Restore the saved value for the variable being edited by WIDGET.
2792 This also updates the buffer to show that value.
2793 The value that was current before this operation
2794 becomes the backup value, so you can get it again."
2795 (let* ((symbol (widget-value widget
))
2796 (set (or (get symbol
'custom-set
) 'set-default
))
2797 (value (get symbol
'saved-value
))
2798 (comment (get symbol
'saved-variable-comment
)))
2799 (cond ((or value comment
)
2800 (put symbol
'variable-comment comment
)
2801 (custom-variable-backup-value widget
)
2802 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2804 (funcall set symbol
(eval (car value
)))
2807 (error "No saved value for %s" symbol
)))
2808 (put symbol
'customized-value nil
)
2809 (put symbol
'customized-variable-comment nil
)
2810 (widget-put widget
:custom-state
'unknown
)
2811 ;; This call will possibly make the comment invisible
2812 (custom-redraw widget
)))
2814 (defun custom-variable-reset-standard (widget)
2815 "Restore the standard setting for the variable being edited by WIDGET.
2816 This operation eliminates any saved setting for the variable,
2817 restoring it to the state of a variable that has never been customized.
2818 The value that was current before this operation
2819 becomes the backup value, so you can get it again."
2820 (let* ((symbol (widget-value widget
)))
2821 (if (get symbol
'standard-value
)
2822 (custom-variable-backup-value widget
)
2823 (error "No standard setting known for %S" symbol
))
2824 (put symbol
'variable-comment nil
)
2825 (put symbol
'customized-value nil
)
2826 (put symbol
'customized-variable-comment nil
)
2827 (custom-push-theme 'theme-value symbol
'user
'reset
)
2828 (custom-theme-recalc-variable symbol
)
2829 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2830 (put symbol
'saved-value nil
)
2831 (put symbol
'saved-variable-comment nil
)
2833 (widget-put widget
:custom-state
'unknown
)
2834 ;; This call will possibly make the comment invisible
2835 (custom-redraw widget
)))
2837 (defun custom-variable-backup-value (widget)
2838 "Back up the current value for WIDGET's variable.
2839 The backup value is kept in the car of the `backup-value' property."
2840 (let* ((symbol (widget-value widget
))
2841 (get (or (get symbol
'custom-get
) 'default-value
))
2842 (type (custom-variable-type symbol
))
2843 (conv (widget-convert type
))
2844 (value (if (default-boundp symbol
)
2845 (funcall get symbol
)
2846 (widget-get conv
:value
))))
2847 (put symbol
'backup-value
(list value
))))
2849 (defun custom-variable-reset-backup (widget)
2850 "Restore the backup value for the variable being edited by WIDGET.
2851 The value that was current before this operation
2852 becomes the backup value, so you can use this operation repeatedly
2853 to switch between two values."
2854 (let* ((symbol (widget-value widget
))
2855 (set (or (get symbol
'custom-set
) 'set-default
))
2856 (value (get symbol
'backup-value
))
2857 (comment-widget (widget-get widget
:comment-widget
))
2858 (comment (widget-value comment-widget
)))
2861 (custom-variable-backup-value widget
)
2862 (custom-push-theme 'theme-value symbol
'user
'set value
)
2864 (funcall set symbol
(car value
))
2866 (error "No backup value for %s" symbol
))
2867 (put symbol
'customized-value
(list (car value
)))
2868 (put symbol
'variable-comment comment
)
2869 (put symbol
'customized-variable-comment comment
)
2870 (custom-variable-state-set widget
)
2871 ;; This call will possibly make the comment invisible
2872 (custom-redraw widget
)))
2874 ;;; The `custom-face-edit' Widget.
2876 (define-widget 'custom-face-edit
'checklist
2877 "Edit face attributes."
2881 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2882 :value-to-internal
'custom-face-edit-fix-value
2883 :match
(lambda (widget value
)
2884 (widget-checklist-match widget
2885 (custom-face-edit-fix-value widget value
)))
2886 :convert-widget
'custom-face-edit-convert-widget
2887 :args
(mapcar (lambda (att)
2890 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2891 (list 'const
:format
"" :value
(nth 0 att
))
2893 custom-face-attributes
))
2895 (defun custom-face-edit-fix-value (widget value
)
2896 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2897 Also change :reverse-video to :inverse-video."
2901 (let ((key (car value
))
2902 (val (car (cdr value
))))
2903 (cond ((eq key
:italic
)
2904 (push :slant result
)
2905 (push (if val
'italic
'normal
) result
))
2907 (push :weight result
)
2908 (push (if val
'bold
'normal
) result
))
2909 ((eq key
:reverse-video
)
2910 (push :inverse-video result
)
2914 (push val result
))))
2915 (setq value
(cdr (cdr value
))))
2916 (setq result
(nreverse result
))
2920 (defun custom-face-edit-convert-widget (widget)
2921 "Convert :args as widget types in WIDGET."
2924 :args
(mapcar (lambda (arg)
2926 :deactivate
'custom-face-edit-deactivate
2927 :activate
'custom-face-edit-activate
2928 :delete
'custom-face-edit-delete
))
2929 (widget-get widget
:args
)))
2932 (defun custom-face-edit-deactivate (widget)
2933 "Make face widget WIDGET inactive for user modifications."
2934 (unless (widget-get widget
:inactive
)
2935 (let ((tag (custom-face-edit-attribute-tag widget
))
2936 (from (copy-marker (widget-get widget
:from
)))
2937 (value (widget-value widget
))
2938 (inhibit-read-only t
)
2939 (inhibit-modification-hooks t
))
2942 (widget-default-delete widget
)
2943 (insert tag
": *\n")
2944 (widget-put widget
:inactive
2945 (cons value
(cons from
(- (point) from
))))))))
2947 (defun custom-face-edit-activate (widget)
2948 "Make face widget WIDGET inactive for user modifications."
2949 (let ((inactive (widget-get widget
:inactive
))
2950 (inhibit-read-only t
)
2951 (inhibit-modification-hooks t
))
2952 (when (consp inactive
)
2954 (goto-char (car (cdr inactive
)))
2955 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2956 (widget-put widget
:inactive nil
)
2957 (widget-apply widget
:create
)
2958 (widget-value-set widget
(car inactive
))
2961 (defun custom-face-edit-delete (widget)
2962 "Remove WIDGET from the buffer."
2963 (let ((inactive (widget-get widget
:inactive
))
2964 (inhibit-read-only t
)
2965 (inhibit-modification-hooks t
))
2967 ;; Widget is alive, we don't have to do anything special
2968 (widget-default-delete widget
)
2969 ;; WIDGET is already deleted because we did so to inactivate it;
2970 ;; now just get rid of the label we put in its place.
2971 (delete-region (car (cdr inactive
))
2972 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2973 (widget-put widget
:inactive nil
))))
2976 (defun custom-face-edit-attribute-tag (widget)
2977 "Returns the first :tag property in WIDGET or one of its children."
2978 (let ((tag (widget-get widget
:tag
)))
2979 (or (and (not (equal tag
"")) tag
)
2980 (let ((children (widget-get widget
:children
)))
2981 (while (and (null tag
) children
)
2982 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2985 ;;; The `custom-display' Widget.
2987 (define-widget 'custom-display
'menu-choice
2988 "Select a display type."
2991 :help-echo
"Specify frames where the face attributes should be used."
2992 :args
'((const :tag
"all" t
)
2993 (const :tag
"defaults" default
)
2997 :args
((group :sibling-args
(:help-echo
"\
2998 Only match the specified window systems.")
2999 (const :format
"Type: "
3001 (checklist :inline t
3004 :sibling-args
(:help-echo
"\
3005 The X11 Window System.")
3007 (const :format
"PM "
3008 :sibling-args
(:help-echo
"\
3009 OS/2 Presentation Manager.")
3011 (const :format
"W32 "
3012 :sibling-args
(:help-echo
"\
3015 (const :format
"MAC "
3016 :sibling-args
(:help-echo
"\
3019 (const :format
"DOS "
3020 :sibling-args
(:help-echo
"\
3023 (const :format
"TTY%n"
3024 :sibling-args
(:help-echo
"\
3025 Plain text terminals.")
3027 (group :sibling-args
(:help-echo
"\
3028 Only match the frames with the specified color support.")
3029 (const :format
"Class: "
3031 (checklist :inline t
3033 (const :format
"Color "
3034 :sibling-args
(:help-echo
"\
3035 Match color frames.")
3037 (const :format
"Grayscale "
3038 :sibling-args
(:help-echo
"\
3039 Match grayscale frames.")
3041 (const :format
"Monochrome%n"
3042 :sibling-args
(:help-echo
"\
3043 Match frames with no color support.")
3045 (group :sibling-args
(:help-echo
"\
3046 The minimum number of colors the frame should support.")
3047 (const :format
"" min-colors
)
3048 (integer :tag
"Minimum number of colors" ))
3049 (group :sibling-args
(:help-echo
"\
3050 Only match frames with the specified intensity.")
3052 Background brightness: "
3054 (checklist :inline t
3056 (const :format
"Light "
3057 :sibling-args
(:help-echo
"\
3058 Match frames with light backgrounds.")
3060 (const :format
"Dark\n"
3061 :sibling-args
(:help-echo
"\
3062 Match frames with dark backgrounds.")
3064 (group :sibling-args
(:help-echo
"\
3065 Only match frames that support the specified face attributes.")
3066 (const :format
"Supports attributes:" supports
)
3067 (custom-face-edit :inline t
:format
"%n%v"))))))
3069 ;;; The `custom-face' Widget.
3071 (defface custom-face-tag
3072 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3073 "Face used for face tags."
3074 :group
'custom-faces
)
3075 ;; backward-compatibility alias
3076 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3078 (defcustom custom-face-default-form
'selected
3079 "Default form of displaying face definition."
3080 :type
'(choice (const all
)
3083 :group
'custom-buffer
3086 (define-widget 'custom-face
'custom
3088 :sample-face
'custom-face-tag-face
3089 :help-echo
"Set or reset this face."
3090 :documentation-property
#'face-doc-string
3091 :value-create
'custom-face-value-create
3092 :action
'custom-face-action
3093 :custom-category
'face
3094 :custom-form nil
; defaults to value of `custom-face-default-form'
3095 :custom-set
'custom-face-set
3096 :custom-save
'custom-face-save
3097 :custom-reset-current
'custom-redraw
3098 :custom-reset-saved
'custom-face-reset-saved
3099 :custom-reset-standard
'custom-face-reset-standard
3100 :custom-standard-value
'custom-face-standard-value
3101 :custom-menu
'custom-face-menu-create
)
3103 (define-widget 'custom-face-all
'editable-list
3104 "An editable list of display specifications and attributes."
3105 :entry-format
"%i %d %v"
3106 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3107 :append-button-args
'(:help-echo
"Append new display specification here.")
3108 :delete-button-args
'(:help-echo
"Delete this display specification.")
3109 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3111 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3112 "Converted version of the `custom-face-all' widget.")
3114 (define-widget 'custom-display-unselected
'item
3115 "A display specification that doesn't match the selected display."
3116 :match
'custom-display-unselected-match
)
3118 (defun custom-display-unselected-match (widget value
)
3119 "Non-nil if VALUE is an unselected display specification."
3120 (not (face-spec-set-match-display value
(selected-frame))))
3122 (define-widget 'custom-face-selected
'group
3123 "Edit the attributes of the selected display in a face specification."
3124 :args
'((choice :inline t
3125 (group :tag
"With Defaults" :inline t
3126 (group (const :tag
"" default
)
3127 (custom-face-edit :tag
" Default\n Attributes"))
3130 (group custom-display-unselected sexp
))
3131 (group (sexp :format
"")
3132 (custom-face-edit :tag
" Overriding\n Attributes"))
3136 (group :tag
"No Defaults" :inline t
3139 (group custom-display-unselected sexp
))
3140 (group (sexp :format
"")
3141 (custom-face-edit :tag
"\n Attributes"))
3148 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3149 "Converted version of the `custom-face-selected' widget.")
3151 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3152 "Return a canonicalized version of SPEC using.
3153 FILTER-INDEX is the index in the entry for each attribute in
3154 `custom-face-attributes' at which the appropriate filter function can be
3155 found, and DEFAULT-FILTER is the filter to apply for attributes that
3157 (mapcar (lambda (entry)
3158 ;; Filter a single face-spec entry
3159 (let ((tests (car entry
))
3161 ;; Handle both old- and new-style attribute syntax
3162 (if (listp (car (cdr entry
)))
3165 (filtered-attrs nil
))
3166 ;; Filter each face attribute
3167 (while unfiltered-attrs
3168 (let* ((attr (pop unfiltered-attrs
))
3169 (pre-filtered-value (pop unfiltered-attrs
))
3171 (or (nth filter-index
(assq attr custom-face-attributes
))
3175 (funcall filter pre-filtered-value
)
3176 pre-filtered-value
)))
3177 (push filtered-value filtered-attrs
)
3178 (push attr filtered-attrs
)))
3180 (list tests filtered-attrs
)))
3183 (defun custom-pre-filter-face-spec (spec)
3184 "Return SPEC changed as necessary for editing by the face customization widget.
3185 SPEC must be a full face spec."
3186 (custom-filter-face-spec spec
2))
3188 (defun custom-post-filter-face-spec (spec)
3189 "Return the customized SPEC in a form suitable for setting the face."
3190 (custom-filter-face-spec spec
3))
3192 (defun custom-face-value-create (widget)
3193 "Create a list of the display specifications for WIDGET."
3194 (let ((buttons (widget-get widget
:buttons
))
3196 (symbol (widget-get widget
:value
))
3197 (tag (widget-get widget
:tag
))
3198 (state (widget-get widget
:custom-state
))
3200 (is-last (widget-get widget
:custom-last
))
3201 (prefix (widget-get widget
:custom-prefix
)))
3203 (setq tag
(prin1-to-string symbol
)))
3204 (cond ((eq custom-buffer-style
'tree
)
3205 (insert prefix
(if is-last
" `--- " " |--- "))
3206 (push (widget-create-child-and-convert
3207 widget
'custom-browse-face-tag
)
3209 (insert " " tag
"\n")
3210 (widget-put widget
:buttons buttons
))
3214 (widget-specify-sample widget begin
(point))
3215 (if (eq custom-buffer-style
'face
)
3217 (if (string-match "face\\'" tag
)
3219 (insert " face: ")))
3221 (push (widget-create-child-and-convert widget
'item
3228 (push (widget-create-child-and-convert
3230 :help-echo
"Hide or show this face."
3233 :action
'custom-toggle-parent
3234 (not (eq state
'hidden
)))
3238 (let ((magic (widget-create-child-and-convert
3239 widget
'custom-magic nil
)))
3240 (widget-put widget
:custom-magic magic
)
3241 (push magic buttons
))
3243 (widget-put widget
:buttons buttons
)
3244 ;; Insert documentation.
3245 (widget-default-format-handler widget ?h
)
3246 ;; The comment field
3247 (unless (eq state
'hidden
)
3248 (let* ((comment (get symbol
'face-comment
))
3250 (widget-create-child-and-convert
3251 widget
'custom-comment
3253 :value
(or comment
""))))
3254 (widget-put widget
:comment-widget comment-widget
)
3255 (push comment-widget children
)))
3257 (unless (eq state
'hidden
)
3258 (when (eq (widget-get widget
:custom-level
) 1)
3259 (custom-add-parent-links widget
))
3260 (custom-add-see-also widget
))
3262 (unless (eq (preceding-char) ?
\n)
3264 (unless (eq state
'hidden
)
3265 (message "Creating face editor...")
3266 (custom-load-widget widget
)
3267 (unless (widget-get widget
:custom-form
)
3268 (widget-put widget
:custom-form custom-face-default-form
))
3269 (let* ((symbol (widget-value widget
))
3270 (spec (or (get symbol
'customized-face
)
3271 (get symbol
'saved-face
)
3272 (get symbol
'face-defface-spec
)
3273 ;; Attempt to construct it.
3274 (list (list t
(custom-face-attributes-get
3275 symbol
(selected-frame))))))
3276 (form (widget-get widget
:custom-form
))
3277 (indent (widget-get widget
:indent
))
3279 ;; If the user has changed this face in some other way,
3280 ;; edit it as the user has specified it.
3281 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3282 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3283 (setq spec
(custom-pre-filter-face-spec spec
))
3284 (setq edit
(widget-create-child-and-convert
3286 (cond ((and (eq form
'selected
)
3287 (widget-apply custom-face-selected
3289 (when indent
(insert-char ?\ indent
))
3290 'custom-face-selected
)
3291 ((and (not (eq form
'lisp
))
3292 (widget-apply custom-face-all
3296 (when indent
(insert-char ?\ indent
))
3299 (custom-face-state-set widget
)
3300 (push edit children
)
3301 (widget-put widget
:children children
))
3302 (message "Creating face editor...done"))))))
3304 (defvar custom-face-menu
3305 `(("Set for current session" custom-face-set
)
3306 ,@(when (or custom-file user-init-file
)
3307 '(("Save for future sessions" custom-face-save-command
)))
3308 ("---" ignore ignore
)
3309 ("Reset to saved face" custom-face-reset-saved
3311 (or (get (widget-value widget
) 'saved-face
)
3312 (get (widget-value widget
) 'saved-face-comment
))))
3313 ,@(when (or custom-file user-init-file
)
3314 '(("Erase customization" custom-face-reset-standard
3316 (get (widget-value widget
) 'face-defface-spec
)))))
3317 ("---" ignore ignore
)
3318 ("Add comment" custom-comment-show custom-comment-invisible-p
)
3319 ("Show all attributes" custom-face-edit-all
3321 (not (eq (widget-get widget
:custom-form
) 'all
))))
3322 ("Show current attributes" custom-face-edit-selected
3324 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3325 ("Show Lisp expression" custom-face-edit-lisp
3327 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3328 "Alist of actions for the `custom-face' widget.
3329 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3330 the menu entry, ACTION is the function to call on the widget when the
3331 menu is selected, and FILTER is a predicate which takes a `custom-face'
3332 widget as an argument, and returns non-nil if ACTION is valid on that
3333 widget. If FILTER is nil, ACTION is always valid.")
3335 (defun custom-face-edit-selected (widget)
3336 "Edit selected attributes of the value of WIDGET."
3337 (widget-put widget
:custom-state
'unknown
)
3338 (widget-put widget
:custom-form
'selected
)
3339 (custom-redraw widget
))
3341 (defun custom-face-edit-all (widget)
3342 "Edit all attributes of the value of WIDGET."
3343 (widget-put widget
:custom-state
'unknown
)
3344 (widget-put widget
:custom-form
'all
)
3345 (custom-redraw widget
))
3347 (defun custom-face-edit-lisp (widget)
3348 "Edit the Lisp representation of the value of WIDGET."
3349 (widget-put widget
:custom-state
'unknown
)
3350 (widget-put widget
:custom-form
'lisp
)
3351 (custom-redraw widget
))
3353 (defun custom-face-state-set (widget)
3354 "Set the state of WIDGET."
3355 (let* ((symbol (widget-value widget
))
3356 (comment (get symbol
'face-comment
))
3360 (setq tmp
(get symbol
'customized-face
))
3361 (setq temp
(get symbol
'customized-face-comment
))
3363 (if (equal temp comment
)
3367 (setq tmp
(get symbol
'saved-face
))
3368 (setq temp
(get symbol
'saved-face-comment
))
3370 (if (equal temp comment
)
3372 ((eq 'user
(caar (get symbol
'theme-face
)))
3374 ((eq 'changed
(caar (get symbol
'theme-face
)))
3378 ((get symbol
'face-defface-spec
)
3379 (if (equal comment nil
)
3384 ;; If the user called set-face-attribute to change the default
3385 ;; for new frames, this face is "set outside of Customize".
3386 (if (and (not (eq state
'rogue
))
3387 (get symbol
'face-modified
))
3388 (setq state
'changed
))
3389 (widget-put widget
:custom-state state
)))
3391 (defun custom-face-action (widget &optional event
)
3392 "Show the menu for `custom-face' WIDGET.
3393 Optional EVENT is the location for the menu."
3394 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3395 (custom-toggle-hide widget
)
3396 (let* ((completion-ignore-case t
)
3397 (symbol (widget-get widget
:value
))
3398 (answer (widget-choose (concat "Operation on "
3399 (custom-unlispify-tag-name symbol
))
3400 (custom-menu-filter custom-face-menu
3404 (funcall answer widget
)))))
3406 (defun custom-face-set (widget)
3407 "Make the face attributes in WIDGET take effect."
3408 (let* ((symbol (widget-value widget
))
3409 (child (car (widget-get widget
:children
)))
3410 (value (custom-post-filter-face-spec (widget-value child
)))
3411 (comment-widget (widget-get widget
:comment-widget
))
3412 (comment (widget-value comment-widget
)))
3413 (when (equal comment
"")
3415 ;; Make the comment invisible by hand if it's empty
3416 (custom-comment-hide comment-widget
))
3417 (put symbol
'customized-face value
)
3418 (if (face-spec-choose value
)
3419 (face-spec-set symbol value
)
3420 ;; face-set-spec ignores empty attribute lists, so just give it
3421 ;; something harmless instead.
3422 (face-spec-set symbol
'((t :foreground unspecified
))))
3423 (custom-push-theme 'theme-face symbol
'user
'set value
)
3424 (put symbol
'customized-face-comment comment
)
3425 (put symbol
'face-comment comment
)
3426 (custom-face-state-set widget
)
3427 (custom-redraw-magic widget
)))
3429 (defun custom-face-save-command (widget)
3430 "Save in `.emacs' the face attributes in WIDGET."
3431 (custom-face-save widget
)
3434 (defun custom-face-save (widget)
3435 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3436 (let* ((symbol (widget-value widget
))
3437 (child (car (widget-get widget
:children
)))
3438 (value (custom-post-filter-face-spec (widget-value child
)))
3439 (comment-widget (widget-get widget
:comment-widget
))
3440 (comment (widget-value comment-widget
)))
3441 (when (equal comment
"")
3443 ;; Make the comment invisible by hand if it's empty
3444 (custom-comment-hide comment-widget
))
3445 (custom-push-theme 'theme-face symbol
'user
'set value
)
3446 (if (face-spec-choose value
)
3447 (face-spec-set symbol value
)
3448 ;; face-set-spec ignores empty attribute lists, so just give it
3449 ;; something harmless instead.
3450 (face-spec-set symbol
'((t :foreground unspecified
))))
3451 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3452 (put symbol
'saved-face value
))
3453 (put symbol
'customized-face nil
)
3454 (put symbol
'face-comment comment
)
3455 (put symbol
'customized-face-comment nil
)
3456 (put symbol
'saved-face-comment comment
)
3458 (custom-face-state-set widget
)
3459 (custom-redraw-magic widget
)))
3461 (defun custom-face-reset-saved (widget)
3462 "Restore WIDGET to the face's default attributes."
3463 (let* ((symbol (widget-value widget
))
3464 (child (car (widget-get widget
:children
)))
3465 (value (get symbol
'saved-face
))
3466 (comment (get symbol
'saved-face-comment
))
3467 (comment-widget (widget-get widget
:comment-widget
)))
3468 (unless (or value comment
)
3469 (error "No saved value for this face"))
3470 (put symbol
'customized-face nil
)
3471 (put symbol
'customized-face-comment nil
)
3472 (custom-push-theme 'theme-face symbol
'user
'set value
)
3473 (face-spec-set symbol value
)
3474 (put symbol
'face-comment comment
)
3475 (widget-value-set child value
)
3476 ;; This call manages the comment visibility
3477 (widget-value-set comment-widget
(or comment
""))
3478 (custom-face-state-set widget
)
3479 (custom-redraw-magic widget
)))
3481 (defun custom-face-standard-value (widget)
3482 (get (widget-value widget
) 'face-defface-spec
))
3484 (defun custom-face-reset-standard (widget)
3485 "Restore WIDGET to the face's standard attribute values.
3486 This operation eliminates any saved attributes for the face,
3487 restoring it to the state of a face that has never been customized."
3488 (let* ((symbol (widget-value widget
))
3489 (child (car (widget-get widget
:children
)))
3490 (value (get symbol
'face-defface-spec
))
3491 (comment-widget (widget-get widget
:comment-widget
)))
3493 (error "No standard setting for this face"))
3494 (put symbol
'customized-face nil
)
3495 (put symbol
'customized-face-comment nil
)
3496 (custom-push-theme 'theme-face symbol
'user
'reset
)
3497 (custom-theme-recalc-face symbol
)
3498 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3499 (put symbol
'saved-face nil
)
3500 (put symbol
'saved-face-comment nil
)
3502 (put symbol
'face-comment nil
)
3503 (widget-value-set child value
)
3504 ;; This call manages the comment visibility
3505 (widget-value-set comment-widget
"")
3506 (custom-face-state-set widget
)
3507 (custom-redraw-magic widget
)))
3509 ;;; The `face' Widget.
3511 (defvar widget-face-prompt-value-history nil
3512 "History of input to `widget-face-prompt-value'.")
3514 (define-widget 'face
'symbol
3515 "A Lisp face name (with sample)."
3516 :format
"%{%t%}: (%{sample%}) %v"
3519 :sample-face-get
'widget-face-sample-face-get
3520 :notify
'widget-face-notify
3521 :match
(lambda (widget value
) (facep value
))
3522 :complete-function
(lambda ()
3524 (lisp-complete-symbol 'facep
))
3525 :prompt-match
'facep
3526 :prompt-history
'widget-face-prompt-value-history
3527 :validate
(lambda (widget)
3528 (unless (facep (widget-value widget
))
3530 :error
(format "Invalid face: %S"
3531 (widget-value widget
)))
3534 (defun widget-face-sample-face-get (widget)
3535 (let ((value (widget-value widget
)))
3540 (defun widget-face-notify (widget child
&optional event
)
3541 "Update the sample, and notify the parent."
3542 (overlay-put (widget-get widget
:sample-overlay
)
3543 'face
(widget-apply widget
:sample-face-get
))
3544 (widget-default-notify widget child event
))
3547 ;;; The `hook' Widget.
3549 (define-widget 'hook
'list
3551 :value-to-internal
(lambda (widget value
)
3552 (if (and value
(symbolp value
))
3555 :match
(lambda (widget value
)
3557 (widget-group-match widget value
)))
3558 ;; Avoid adding undefined functions to the hook, especially for
3559 ;; things like `find-file-hook' or even more basic ones, to avoid
3561 :set
(lambda (symbol value
)
3564 (add-hook symbol elt
))))
3565 :convert-widget
'custom-hook-convert-widget
3568 (defun custom-hook-convert-widget (widget)
3569 ;; Handle `:options'.
3570 (let* ((options (widget-get widget
:options
))
3571 (other `(editable-list :inline t
3572 :entry-format
"%i %d%v"
3573 (function :format
" %v")))
3575 (list `(checklist :inline t
3576 ,@(mapcar (lambda (entry)
3577 `(function-item ,entry
))
3581 (widget-put widget
:args args
)
3584 ;;; The `custom-group-link' Widget.
3586 (define-widget 'custom-group-link
'link
3587 "Show parent in other window when activated."
3588 :help-echo
"Create customization buffer for this group."
3589 :action
'custom-group-link-action
)
3591 (defun custom-group-link-action (widget &rest ignore
)
3592 (customize-group (widget-value widget
)))
3594 ;;; The `custom-group' Widget.
3596 (defcustom custom-group-tag-faces nil
3597 ;; In XEmacs, this ought to play games with font size.
3598 ;; Fixme: make it do so in Emacs.
3599 "Face used for group tags.
3600 The first member is used for level 1 groups, the second for level 2,
3601 and so forth. The remaining group tags are shown with `custom-group-tag'."
3602 :type
'(repeat face
)
3603 :group
'custom-faces
)
3605 (defface custom-group-tag-1
3608 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3609 (((min-colors 88) (class color
)
3611 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3614 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3616 "Face used for group tags."
3617 :group
'custom-faces
)
3618 ;; backward-compatibility alias
3619 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3621 (defface custom-group-tag
3624 (:foreground
"light blue" :weight bold
:height
1.2))
3625 (((min-colors 88) (class color
)
3627 (:foreground
"blue1" :weight bold
:height
1.2))
3630 (:foreground
"blue" :weight bold
:height
1.2))
3632 "Face used for low level group tags."
3633 :group
'custom-faces
)
3634 ;; backward-compatibility alias
3635 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3637 (define-widget 'custom-group
'custom
3640 :sample-face-get
'custom-group-sample-face-get
3641 :documentation-property
'group-documentation
3642 :help-echo
"Set or reset all members of this group."
3643 :value-create
'custom-group-value-create
3644 :action
'custom-group-action
3645 :custom-category
'group
3646 :custom-set
'custom-group-set
3647 :custom-save
'custom-group-save
3648 :custom-reset-current
'custom-group-reset-current
3649 :custom-reset-saved
'custom-group-reset-saved
3650 :custom-reset-standard
'custom-group-reset-standard
3651 :custom-menu
'custom-group-menu-create
)
3653 (defun custom-group-sample-face-get (widget)
3654 ;; Use :sample-face.
3655 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3658 (define-widget 'custom-group-visibility
'visibility
3659 "An indicator and manipulator for hidden group contents."
3660 :create
'custom-group-visibility-create
)
3662 (defun custom-group-visibility-create (widget)
3663 (let ((visible (widget-value widget
)))
3665 (insert "--------")))
3666 (widget-default-create widget
))
3668 (defun custom-group-members (symbol groups-only
)
3669 "Return SYMBOL's custom group members.
3670 If GROUPS-ONLY non-nil, return only those members that are groups."
3671 (if (not groups-only
)
3672 (get symbol
'custom-group
)
3674 (dolist (entry (get symbol
'custom-group
))
3675 (when (eq (nth 1 entry
) 'custom-group
)
3676 (push entry members
)))
3677 (nreverse members
))))
3679 (defun custom-group-value-create (widget)
3680 "Insert a customize group for WIDGET in the current buffer."
3681 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3682 (custom-load-widget widget
))
3683 (let* ((state (widget-get widget
:custom-state
))
3684 (level (widget-get widget
:custom-level
))
3685 ;; (indent (widget-get widget :indent))
3686 (prefix (widget-get widget
:custom-prefix
))
3687 (buttons (widget-get widget
:buttons
))
3688 (tag (widget-get widget
:tag
))
3689 (symbol (widget-value widget
))
3690 (members (custom-group-members symbol
3691 (and (eq custom-buffer-style
'tree
)
3692 custom-browse-only-groups
))))
3693 (cond ((and (eq custom-buffer-style
'tree
)
3695 (or members
(custom-unloaded-widget-p widget
)))
3696 (custom-browse-insert-prefix prefix
)
3697 (push (widget-create-child-and-convert
3698 widget
'custom-browse-visibility
3699 ;; :tag-glyph "plus"
3703 ;; (widget-glyph-insert nil "-- " "horizontal")
3704 (push (widget-create-child-and-convert
3705 widget
'custom-browse-group-tag
)
3707 (insert " " tag
"\n")
3708 (widget-put widget
:buttons buttons
))
3709 ((and (eq custom-buffer-style
'tree
)
3710 (zerop (length members
)))
3711 (custom-browse-insert-prefix prefix
)
3713 ;; (widget-glyph-insert nil "[ ]" "empty")
3714 ;; (widget-glyph-insert nil "-- " "horizontal")
3715 (push (widget-create-child-and-convert
3716 widget
'custom-browse-group-tag
)
3718 (insert " " tag
"\n")
3719 (widget-put widget
:buttons buttons
))
3720 ((eq custom-buffer-style
'tree
)
3721 (custom-browse-insert-prefix prefix
)
3722 (if (zerop (length members
))
3724 (custom-browse-insert-prefix prefix
)
3726 ;; (widget-glyph-insert nil "[ ]" "empty")
3727 ;; (widget-glyph-insert nil "-- " "horizontal")
3728 (push (widget-create-child-and-convert
3729 widget
'custom-browse-group-tag
)
3731 (insert " " tag
"\n")
3732 (widget-put widget
:buttons buttons
))
3733 (push (widget-create-child-and-convert
3734 widget
'custom-browse-visibility
3735 ;; :tag-glyph "minus"
3739 ;; (widget-glyph-insert nil "-\\ " "top")
3740 (push (widget-create-child-and-convert
3741 widget
'custom-browse-group-tag
)
3743 (insert " " tag
"\n")
3744 (widget-put widget
:buttons buttons
)
3745 (message "Creating group...")
3746 (let* ((members (custom-sort-items members
3747 custom-browse-sort-alphabetically
3748 custom-browse-order-groups
))
3749 (prefixes (widget-get widget
:custom-prefixes
))
3750 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3751 (extra-prefix (if (widget-get widget
:custom-last
)
3754 (prefix (concat prefix extra-prefix
))
3757 (setq entry
(car members
)
3758 members
(cdr members
))
3759 (push (widget-create-child-and-convert
3760 widget
(nth 1 entry
)
3762 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3763 :custom-prefixes custom-prefix-list
3764 :custom-level
(1+ level
)
3765 :custom-last
(null members
)
3766 :value
(nth 0 entry
)
3767 :custom-prefix prefix
)
3769 (widget-put widget
:children
(reverse children
)))
3770 (message "Creating group...done")))
3773 ;; Create level indicator.
3774 (unless (eq custom-buffer-style
'links
)
3775 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3778 (let ((begin (point)))
3780 (widget-specify-sample widget begin
(point)))
3782 ;; Create link/visibility indicator.
3783 (if (eq custom-buffer-style
'links
)
3784 (push (widget-create-child-and-convert
3785 widget
'custom-group-link
3786 :button-face
'custom-link
3787 :mouse-face
'highlight
3791 (push (widget-create-child-and-convert
3792 widget
'custom-group-visibility
3793 :help-echo
"Show members of this group."
3794 :action
'custom-toggle-parent
3795 (not (eq state
'hidden
)))
3798 ;; Create magic button.
3799 (let ((magic (widget-create-child-and-convert
3800 widget
'custom-magic nil
)))
3801 (widget-put widget
:custom-magic magic
)
3802 (push magic buttons
))
3804 (widget-put widget
:buttons buttons
)
3805 ;; Insert documentation.
3806 (if (and (eq custom-buffer-style
'links
) (> level
1))
3807 (widget-put widget
:documentation-indent
0))
3808 (widget-default-format-handler widget ?h
))
3811 ;; Add parent groups references above the group.
3812 (if t
;;; This should test that the buffer
3813 ;;; was made to display a group.
3815 (if (custom-add-parent-links widget
3816 "Go to parent group:")
3818 ;; Create level indicator.
3819 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3822 (let ((start (point)))
3824 (widget-specify-sample widget start
(point)))
3826 ;; Create visibility indicator.
3827 (unless (eq custom-buffer-style
'links
)
3829 (push (widget-create-child-and-convert
3831 :help-echo
"Hide members of this group."
3832 :action
'custom-toggle-parent
3833 (not (eq state
'hidden
)))
3836 ;; Create more dashes.
3837 ;; Use 76 instead of 75 to compensate for the temporary "<"
3838 ;; added by `widget-insert'.
3839 (insert-char ?-
(- 76 (current-column)
3840 (* custom-buffer-indent level
)))
3842 ;; Create magic button.
3843 (let ((magic (widget-create-child-and-convert
3844 widget
'custom-magic
3847 (widget-put widget
:custom-magic magic
)
3848 (push magic buttons
))
3850 (widget-put widget
:buttons buttons
)
3851 ;; Insert documentation.
3852 (widget-default-format-handler widget ?h
)
3854 (if nil
;;; This should test that the buffer
3855 ;;; was not made to display a group.
3857 (insert-char ?\ custom-buffer-indent
)
3858 (custom-add-parent-links widget
)))
3859 (custom-add-see-also widget
3860 (make-string (* custom-buffer-indent level
)
3863 (message "Creating group...")
3864 (let* ((members (custom-sort-items members
3865 custom-buffer-sort-alphabetically
3866 custom-buffer-order-groups
))
3867 (prefixes (widget-get widget
:custom-prefixes
))
3868 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3869 (length (length members
))
3871 (children (mapcar (lambda (entry)
3872 (widget-insert "\n")
3874 Creating group members... %2d%%"
3875 (/ (* 100.0 count
) length
))
3876 (setq count
(1+ count
))
3878 (widget-create-child-and-convert
3879 widget
(nth 1 entry
)
3881 :tag
(custom-unlispify-tag-name
3883 :custom-prefixes custom-prefix-list
3884 :custom-level
(1+ level
)
3885 :value
(nth 0 entry
))
3886 (unless (eq (preceding-char) ?
\n)
3887 (widget-insert "\n"))))
3889 (message "Creating group magic...")
3890 (mapc 'custom-magic-reset children
)
3891 (message "Creating group state...")
3892 (widget-put widget
:children children
)
3893 (custom-group-state-update widget
)
3894 (message "Creating group... done"))
3897 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3898 (insert "\\- " (widget-get widget
:tag
) " group end ")
3899 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3902 (defvar custom-group-menu
3903 `(("Set for current session" custom-group-set
3905 (eq (widget-get widget
:custom-state
) 'modified
)))
3906 ,@(when (or custom-file user-init-file
)
3907 '(("Save for future sessions" custom-group-save
3909 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3910 ("---" ignore ignore
)
3911 ("Reset to current settings" custom-group-reset-current
3913 (memq (widget-get widget
:custom-state
) '(modified))))
3914 ("Reset to saved settings" custom-group-reset-saved
3916 (memq (widget-get widget
:custom-state
) '(modified set
))))
3917 ,@(when (or custom-file user-init-file
)
3918 '(("Reset to standard settings" custom-group-reset-standard
3920 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
3921 "Alist of actions for the `custom-group' widget.
3922 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3923 the menu entry, ACTION is the function to call on the widget when the
3924 menu is selected, and FILTER is a predicate which takes a `custom-group'
3925 widget as an argument, and returns non-nil if ACTION is valid on that
3926 widget. If FILTER is nil, ACTION is always valid.")
3928 (defun custom-group-action (widget &optional event
)
3929 "Show the menu for `custom-group' WIDGET.
3930 Optional EVENT is the location for the menu."
3931 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3932 (custom-toggle-hide widget
)
3933 (let* ((completion-ignore-case t
)
3934 (answer (widget-choose (concat "Operation on "
3935 (custom-unlispify-tag-name
3936 (widget-get widget
:value
)))
3937 (custom-menu-filter custom-group-menu
3941 (funcall answer widget
)))))
3943 (defun custom-group-set (widget)
3944 "Set changes in all modified group members."
3945 (let ((children (widget-get widget
:children
)))
3946 (mapc (lambda (child)
3947 (when (eq (widget-get child
:custom-state
) 'modified
)
3948 (widget-apply child
:custom-set
)))
3951 (defun custom-group-save (widget)
3952 "Save all modified group members."
3953 (let ((children (widget-get widget
:children
)))
3954 (mapc (lambda (child)
3955 (when (memq (widget-get child
:custom-state
) '(modified set
))
3956 (widget-apply child
:custom-save
)))
3959 (defun custom-group-reset-current (widget)
3960 "Reset all modified group members."
3961 (let ((children (widget-get widget
:children
)))
3962 (mapc (lambda (child)
3963 (when (eq (widget-get child
:custom-state
) 'modified
)
3964 (widget-apply child
:custom-reset-current
)))
3967 (defun custom-group-reset-saved (widget)
3968 "Reset all modified or set group members."
3969 (let ((children (widget-get widget
:children
)))
3970 (mapc (lambda (child)
3971 (when (memq (widget-get child
:custom-state
) '(modified set
))
3972 (widget-apply child
:custom-reset-saved
)))
3975 (defun custom-group-reset-standard (widget)
3976 "Reset all modified, set, or saved group members."
3977 (let ((children (widget-get widget
:children
)))
3978 (mapc (lambda (child)
3979 (when (memq (widget-get child
:custom-state
)
3980 '(modified set saved
))
3981 (widget-apply child
:custom-reset-standard
)))
3984 (defun custom-group-state-update (widget)
3986 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3987 (let* ((children (widget-get widget
:children
))
3988 (states (mapcar (lambda (child)
3989 (widget-get child
:custom-state
))
3991 (magics custom-magic-alist
)
3994 (let ((magic (car (car magics
))))
3995 (if (and (not (eq magic
'hidden
))
3996 (memq magic states
))
3999 (setq magics
(cdr magics
)))))
4000 (widget-put widget
:custom-state found
)))
4001 (custom-magic-reset widget
))
4003 ;;; Reading and writing the custom file.
4006 (defcustom custom-file nil
4007 "File used for storing customization information.
4008 The default is nil, which means to use your init file
4009 as specified by `user-init-file'. If the value is not nil,
4010 it should be an absolute file name.
4012 You can set this option through Custom, if you carefully read the
4013 last paragraph below. However, usually it is simpler to write
4014 something like the following in your init file:
4016 \(setq custom-file \"~/.emacs-custom.el\")
4019 Note that both lines are necessary: the first line tells Custom to
4020 save all customizations in this file, but does not load it.
4022 When you change this variable outside Custom, look in the
4023 previous custom file \(usually your init file) for the
4024 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4025 and copy them (whichever ones you find) to the new custom file.
4026 This will preserve your existing customizations.
4028 If you save this option using Custom, Custom will write all
4029 currently saved customizations, including the new one for this
4030 option itself, into the file you specify, overwriting any
4031 `custom-set-variables' and `custom-set-faces' forms already
4032 present in that file. It will not delete any customizations from
4033 the old custom file. You should do that manually if that is what you
4034 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4035 in your init file, where CUSTOM-FILE is the actual name of the
4036 file. Otherwise, Emacs will not load the file when it starts up,
4037 and hence will not set `custom-file' to that file either."
4038 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4039 (file :format
"%t:%v%d"
4041 "Please read entire docstring below before setting \
4042 this through Custom.
4043 Click om \"More\" \(or position point there and press RETURN)
4044 if only the first line of the docstring is shown."))
4047 (defun custom-file ()
4048 "Return the file name for saving customizations."
4051 (let ((user-init-file user-init-file
)
4053 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4054 (when (null user-init-file
)
4055 (if (or (file-exists-p default-init-file
)
4056 (and (eq system-type
'windows-nt
)
4057 (file-exists-p "~/_emacs")))
4058 ;; Started with -q, i.e. the file containing
4059 ;; Custom settings hasn't been read. Saving
4060 ;; settings there would overwrite other settings.
4061 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4062 (setq user-init-file default-init-file
))
4066 (defun custom-save-all ()
4067 "Save all customizations in `custom-file'."
4068 (let* ((filename (custom-file))
4069 (recentf-exclude (if recentf-mode
4071 (regexp-quote (custom-file))
4074 (old-buffer (find-buffer-visiting filename
)))
4075 (with-current-buffer (or old-buffer
(find-file-noselect filename
))
4076 (let ((inhibit-read-only t
))
4077 (custom-save-variables)
4078 (custom-save-faces))
4079 (let ((file-precious-flag t
))
4082 (kill-buffer (current-buffer))))))
4085 (defun customize-save-customized ()
4086 "Save all user options which have been set in this session."
4088 (mapatoms (lambda (symbol)
4089 (let ((face (get symbol
'customized-face
))
4090 (value (get symbol
'customized-value
))
4091 (face-comment (get symbol
'customized-face-comment
))
4093 (get symbol
'customized-variable-comment
)))
4095 (put symbol
'saved-face face
)
4096 (custom-push-theme 'theme-face symbol
'user
'set value
)
4097 (put symbol
'customized-face nil
))
4099 (put symbol
'saved-value value
)
4100 (custom-push-theme 'theme-value symbol
'user
'set value
)
4101 (put symbol
'customized-value nil
))
4102 (when variable-comment
4103 (put symbol
'saved-variable-comment variable-comment
)
4104 (put symbol
'customized-variable-comment nil
))
4106 (put symbol
'saved-face-comment face-comment
)
4107 (put symbol
'customized-face-comment nil
)))))
4108 ;; We really should update all custom buffers here.
4111 ;; Editing the custom file contents in a buffer.
4113 (defun custom-save-delete (symbol)
4114 "Delete all calls to SYMBOL from the contents of the current buffer.
4115 Leave point at the old location of the first such call,
4116 or (if there were none) at the end of the buffer.
4118 This function does not save the buffer."
4119 (goto-char (point-min))
4120 ;; Skip all whitespace and comments.
4121 (while (forward-comment 1))
4123 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4126 (while t
;; We exit this loop only via throw.
4127 ;; Skip all whitespace and comments.
4128 (while (forward-comment 1))
4129 (let ((start (point))
4130 (sexp (condition-case nil
4131 (read (current-buffer))
4132 (end-of-file (throw 'found nil
)))))
4133 (when (and (listp sexp
)
4134 (eq (car sexp
) symbol
))
4135 (delete-region start
(point))
4137 (setq first
(point)))))))
4140 ;; Move in front of local variables, otherwise long Custom
4141 ;; entries would make them ineffective.
4142 (let ((pos (point-max))
4143 (case-fold-search t
))
4145 (goto-char (point-max))
4146 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4148 (when (search-forward "Local Variables:" nil t
)
4149 (setq pos
(line-beginning-position))))
4152 (defun custom-save-variables ()
4153 "Save all customized variables in `custom-file'."
4155 (custom-save-delete 'custom-set-variables
)
4156 (let ((standard-output (current-buffer))
4157 (saved-list (make-list 1 0))
4159 ;; First create a sorted list of saved variables.
4162 (if (and (get symbol
'saved-value
)
4163 (eq 'user
(car (car-safe (get symbol
'theme-value
)))))
4164 (nconc saved-list
(list symbol
)))))
4165 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4168 (princ "(custom-set-variables
4169 ;; custom-set-variables was added by Custom.
4170 ;; If you edit it by hand, you could mess it up, so be careful.
4171 ;; Your init file should contain only one such instance.
4172 ;; If there is more than one, they won't work right.\n")
4173 (dolist (symbol saved-list
)
4174 (let ((spec (car-safe (get symbol
'theme-value
)))
4175 (value (get symbol
'saved-value
))
4176 (requests (get symbol
'custom-requests
))
4177 (now (not (or (custom-variable-p symbol
)
4178 (and (not (boundp symbol
))
4179 (not (eq (get symbol
'force-value
)
4181 (comment (get symbol
'saved-variable-comment
)))
4182 ;; Check `requests'.
4183 (dolist (request requests
)
4184 (when (and (symbolp request
) (not (featurep request
)))
4185 (message "Unknown requested feature: %s" request
)
4186 (setq requests
(delq request requests
))))
4187 (when (or (and spec
(eq (car spec
) 'user
))
4189 (and (null spec
) (get symbol
'saved-value
)))
4196 (when (or now requests comment
)
4199 (when (or requests comment
)
4209 (unless (looking-at "\n")
4212 (defun custom-save-faces ()
4213 "Save all customized faces in `custom-file'."
4215 (custom-save-delete 'custom-reset-faces
)
4216 (custom-save-delete 'custom-set-faces
)
4217 (let ((standard-output (current-buffer))
4218 (saved-list (make-list 1 0))
4220 ;; First create a sorted list of saved faces.
4223 (if (and (get symbol
'saved-face
)
4224 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4225 (nconc saved-list
(list symbol
)))))
4226 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4227 ;; The default face must be first, since it affects the others.
4228 (if (memq 'default saved-list
)
4229 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4232 (princ "(custom-set-faces
4233 ;; custom-set-faces was added by Custom.
4234 ;; If you edit it by hand, you could mess it up, so be careful.
4235 ;; Your init file should contain only one such instance.
4236 ;; If there is more than one, they won't work right.\n")
4237 (dolist (symbol saved-list
)
4238 (let ((spec (car-safe (get symbol
'theme-face
)))
4239 (value (get symbol
'saved-face
))
4240 (now (not (or (get symbol
'face-defface-spec
)
4241 (and (not (custom-facep symbol
))
4242 (not (get symbol
'force-face
))))))
4243 (comment (get symbol
'saved-face-comment
)))
4244 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4246 (and (null spec
) (get symbol
'saved-face
)))
4247 ;; Don't print default face here.
4254 (when (or now comment
)
4264 (unless (looking-at "\n")
4267 ;;; The Customize Menu.
4271 (defcustom custom-menu-nesting
2
4272 "Maximum nesting in custom menus."
4274 :group
'custom-menu
)
4276 (defun custom-face-menu-create (widget symbol
)
4277 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4278 (vector (custom-unlispify-menu-entry symbol
)
4279 `(customize-face ',symbol
)
4282 (defun custom-variable-menu-create (widget symbol
)
4283 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4284 (let ((type (get symbol
'custom-type
)))
4285 (unless (listp type
)
4286 (setq type
(list type
)))
4287 (if (and type
(widget-get type
:custom-menu
))
4288 (widget-apply type
:custom-menu symbol
)
4289 (vector (custom-unlispify-menu-entry symbol
)
4290 `(customize-variable ',symbol
)
4293 ;; Add checkboxes to boolean variable entries.
4294 (widget-put (get 'boolean
'widget-type
)
4295 :custom-menu
(lambda (widget symbol
)
4296 (vector (custom-unlispify-menu-entry symbol
)
4297 `(customize-variable ',symbol
)
4299 ':selected symbol
)))
4301 (defun custom-group-menu-create (widget symbol
)
4302 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4303 `( ,(custom-unlispify-menu-entry symbol t
)
4304 :filter
(lambda (&rest junk
)
4305 (let ((menu (custom-menu-create ',symbol
)))
4306 (if (consp menu
) (cdr menu
) menu
)))))
4309 (defun custom-menu-create (symbol)
4310 "Create menu for customization group SYMBOL.
4311 The menu is in a format applicable to `easy-menu-define'."
4312 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4313 `(customize-group ',symbol
)
4315 (if (and (or (not (boundp 'custom-menu-nesting
))
4316 (>= custom-menu-nesting
0))
4318 (custom-load-symbol symbol
)
4319 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4320 (let ((custom-prefix-list (custom-prefix-add symbol
4321 custom-prefix-list
))
4322 (members (custom-sort-items (get symbol
'custom-group
)
4323 custom-menu-sort-alphabetically
4324 custom-menu-order-groups
)))
4325 `(,(custom-unlispify-menu-entry symbol t
)
4328 ,@(mapcar (lambda (entry)
4329 (widget-apply (if (listp (nth 1 entry
))
4331 (list (nth 1 entry
)))
4332 :custom-menu
(nth 0 entry
)))
4337 (defun customize-menu-create (symbol &optional name
)
4338 "Return a customize menu for customization group SYMBOL.
4339 If optional NAME is given, use that as the name of the menu.
4340 Otherwise the menu will be named `Customize'.
4341 The format is suitable for use with `easy-menu-define'."
4343 (setq name
"Customize"))
4345 :filter
(lambda (&rest junk
)
4346 (let ((menu (custom-menu-create ',symbol
)))
4347 (if (consp menu
) (cdr menu
) menu
)))))
4349 ;;; The Custom Mode.
4351 (defvar custom-mode-map
4352 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4353 ;; "\r" bindings from the parent map.
4354 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4355 (let ((map (make-keymap)))
4356 (set-keymap-parent map widget-keymap
)
4357 (suppress-keymap map
)
4358 (define-key map
" " 'scroll-up
)
4359 (define-key map
"\177" 'scroll-down
)
4360 (define-key map
"\C-c\C-c" 'Custom-set
)
4361 (define-key map
"\C-x\C-s" 'Custom-save
)
4362 (define-key map
"q" 'Custom-buffer-done
)
4363 (define-key map
"u" 'Custom-goto-parent
)
4364 (define-key map
"n" 'widget-forward
)
4365 (define-key map
"p" 'widget-backward
)
4366 (define-key map
[mouse-1
] 'widget-move-and-invoke
)
4368 "Keymap for `custom-mode'.")
4370 (easy-menu-define Custom-mode-menu
4372 "Menu used in customization buffers."
4374 ,(customize-menu-create 'customize
)
4375 ["Set" Custom-set t
]
4376 ["Save" Custom-save t
]
4377 ["Reset to current settings" Custom-reset-current t
]
4378 ["Reset to saved settings" Custom-reset-saved t
]
4379 ["Erase customizations" Custom-reset-standard t
]
4380 ["Info" (info "(emacs)Easy Customization") t
]))
4382 (defun Custom-goto-parent ()
4383 "Go to the parent group listed at the top of this buffer.
4384 If several parents are listed, go to the first of them."
4387 (goto-char (point-min))
4388 (if (search-forward "\nGo to parent group: " nil t
)
4389 (let* ((button (get-char-property (point) 'button
))
4390 (parent (downcase (widget-get button
:tag
))))
4391 (customize-group parent
)))))
4393 (defcustom custom-mode-hook nil
4394 "Hook called when entering Custom mode."
4396 :group
'custom-buffer
)
4398 (defun custom-state-buffer-message (widget)
4399 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4400 (message "To install your edits, invoke [State] and choose the Set operation")))
4402 (defun custom-mode ()
4403 "Major mode for editing customization buffers.
4405 The following commands are available:
4407 Move to next button or editable field. \\[widget-forward]
4408 Move to previous button or editable field. \\[widget-backward]
4409 \\<widget-field-keymap>\
4410 Complete content of editable text field. \\[widget-complete]
4411 \\<custom-mode-map>\
4412 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4413 Invoke button under point. \\[widget-button-press]
4414 Set all options from current text. \\[Custom-set]
4415 Make values in current text permanent. \\[Custom-save]
4416 Make text match actual option values. \\[Custom-reset-current]
4417 Reset options to permanent settings. \\[Custom-reset-saved]
4418 Erase customizations; set options
4419 and buffer text to the standard values. \\[Custom-reset-standard]
4421 Entry to this mode calls the value of `custom-mode-hook'
4422 if that value is non-nil."
4423 (kill-all-local-variables)
4424 (setq major-mode
'custom-mode
4426 (use-local-map custom-mode-map
)
4427 (easy-menu-add Custom-mode-menu
)
4428 (make-local-variable 'custom-options
)
4429 (make-local-variable 'custom-local-buffer
)
4430 (make-local-variable 'widget-documentation-face
)
4431 (setq widget-documentation-face
'custom-documentation
)
4432 (make-local-variable 'widget-button-face
)
4433 (setq widget-button-face custom-button
)
4434 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4435 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4437 ;; When possible, use relief for buttons, not bracketing. This test
4438 ;; may not be optimal.
4439 (when custom-raised-buttons
4440 (set (make-local-variable 'widget-push-button-prefix
) "")
4441 (set (make-local-variable 'widget-push-button-suffix
) "")
4442 (set (make-local-variable 'widget-link-prefix
) "")
4443 (set (make-local-variable 'widget-link-suffix
) ""))
4444 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4445 (run-mode-hooks 'custom-mode-hook
))
4447 (put 'custom-mode
'mode-class
'special
)
4450 'debug-ignored-errors
4451 "^No user options have changed defaults in recent Emacs versions$")
4457 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4458 ;;; cus-edit.el ends here