1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show initial Lisp expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
)) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
377 (defgroup abbrev-mode nil
378 "Word abbreviations mode."
379 :link
'(custom-manual "(emacs)Abbrevs")
383 "Storage allocation and gc for GNU Emacs Lisp interpreter."
384 :tag
"Storage Allocation"
388 "Undoing changes in buffers."
389 :link
'(custom-manual "(emacs)Undo")
392 (defgroup modeline nil
393 "Content of the modeline."
396 (defgroup editing-basics nil
397 "Most basic editing facilities."
400 (defgroup display nil
401 "How characters are displayed in buffers."
404 (defgroup execute nil
405 "Executing external commands."
408 (defgroup installation nil
409 "The Emacs installation."
417 "Internal Emacs limits."
421 "Debugging Emacs itself."
424 (defgroup minibuffer nil
425 "Controling the behavior of the minibuffer."
426 :link
'(custom-manual "(emacs)Minibuffer")
429 (defgroup keyboard nil
430 "Input from the keyboard."
434 "Input from the mouse."
438 "Input from the menus."
442 "Handling data from drag and drop."
445 (defgroup auto-save nil
446 "Preventing accidential loss of data."
449 (defgroup processes-basics nil
450 "Basic stuff dealing with processes."
454 "MULE Emacs internationalization."
457 (defgroup windows nil
458 "Windows within a frame."
459 :link
'(custom-manual "(emacs)Windows")
463 "Mac specific features."
464 :link
'(custom-manual "(emacs)Mac OS")
471 (defun custom-quote (sexp)
472 "Quote SEXP iff it is not self quoting."
473 (if (or (memq sexp
'(t nil
))
476 (memq (car sexp
) '(lambda)))
480 ;;; (and (fboundp 'characterp)
481 ;;; (characterp sexp))
486 (defun custom-split-regexp-maybe (regexp)
487 "If REGEXP is a string, split it to a list at `\\|'.
488 You can get the original back with from the result with:
489 (mapconcat 'identity result \"\\|\")
491 IF REGEXP is not a string, return it unchanged."
495 (while (string-match "\\\\|" regexp start
)
496 (setq all
(cons (substring regexp start
(match-beginning 0)) all
)
497 start
(match-end 0)))
498 (nreverse (cons (substring regexp start
) all
)))
501 (defun custom-variable-prompt ()
502 "Prompt for a custom variable, defaulting to the variable at point.
503 Return a list suitable for use in `interactive'."
504 (let* ((v (variable-at-point))
505 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
506 (enable-recursive-minibuffers t
)
508 (setq val
(completing-read
509 (if default
(format "Customize variable (default %s): " default
)
510 "Customize variable: ")
511 obarray
'custom-variable-p t nil nil default
))
512 (list (if (equal val
"")
513 (if (symbolp v
) v nil
)
516 (defun custom-menu-filter (menu widget
)
517 "Convert MENU to the form used by `widget-choose'.
518 MENU should be in the same format as `custom-variable-menu'.
519 WIDGET is the widget to apply the filter entries of MENU on."
521 current name action filter
)
523 (setq current
(car menu
)
525 action
(nth 1 current
)
526 filter
(nth 2 current
)
528 (if (or (null filter
) (funcall filter widget
))
529 (push (cons name action
) result
)
535 (defvar custom-prefix-list nil
536 "List of prefixes that should be ignored by `custom-unlispify'.")
538 (defcustom custom-unlispify-menu-entries t
539 "Display menu entries as words instead of symbols if non nil."
543 (defcustom custom-unlispify-remove-prefixes nil
544 "Non-nil means remove group prefixes from option names in buffer."
546 :group
'custom-buffer
549 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
550 "Convert SYMBOL into a menu entry."
551 (cond ((not custom-unlispify-menu-entries
)
552 (symbol-name symbol
))
553 ((get symbol
'custom-tag
)
555 (get symbol
'custom-tag
)
556 (concat (get symbol
'custom-tag
) "...")))
558 (with-current-buffer (get-buffer-create " *Custom-Work*")
560 (princ symbol
(current-buffer))
561 (goto-char (point-min))
562 ;; FIXME: Boolean variables are not predicates, so they shouldn't
563 ;; end with `-p'. -stef
564 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
565 ;; (re-search-forward "-p\\'" nil t))
566 ;; (replace-match "" t t)
567 ;; (goto-char (point-min)))
568 (if custom-unlispify-remove-prefixes
569 (let ((prefixes custom-prefix-list
)
572 (setq prefix
(car prefixes
))
573 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
576 (delete-region (point-min) (point)))
577 (setq prefixes
(cdr prefixes
))))))
578 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
579 (capitalize-region (point-min) (point-max))
581 (goto-char (point-max))
585 (defcustom custom-unlispify-tag-names t
586 "Display tag names as words instead of symbols if non nil."
587 :group
'custom-buffer
590 (defun custom-unlispify-tag-name (symbol)
591 "Convert SYMBOL into a menu entry."
592 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
593 (custom-unlispify-menu-entry symbol t
)))
595 (defun custom-prefix-add (symbol prefixes
)
596 "Add SYMBOL to list of ignored PREFIXES."
597 (cons (or (get symbol
'custom-prefix
)
598 (concat (symbol-name symbol
) "-"))
603 (defcustom custom-guess-name-alist
608 ("-function\\'" function
)
609 ("-functions\\'" (repeat function
))
610 ("-list\\'" (repeat sexp
))
611 ("-alist\\'" (repeat (cons sexp sexp
))))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching the name of a symbol, and TYPE should
615 be a widget suitable for editing the value of that symbol. The TYPE
616 of the first entry where MATCH matches the name of the symbol will be
619 This is used for guessing the type of variables not declared with
621 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
624 (defcustom custom-guess-doc-alist
625 '(("\\`\\*?Non-nil " boolean
))
626 "Alist of (MATCH TYPE).
628 MATCH should be a regexp matching a documentation string, and TYPE
629 should be a widget suitable for editing the value of a variable with
630 that documentation string. The TYPE of the first entry where MATCH
631 matches the name of the symbol will be used.
633 This is used for guessing the type of variables not declared with
635 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
638 (defun custom-guess-type (symbol)
639 "Guess a widget suitable for editing the value of SYMBOL.
640 This is done by matching SYMBOL with `custom-guess-name-alist' and
641 if that fails, the doc string with `custom-guess-doc-alist'."
642 (let ((name (symbol-name symbol
))
643 (names custom-guess-name-alist
)
646 (setq current
(car names
)
648 (when (string-match (nth 0 current
) name
)
649 (setq found
(nth 1 current
)
652 (let ((doc (documentation-property symbol
'variable-documentation
))
653 (docs custom-guess-doc-alist
))
656 (setq current
(car docs
)
658 (when (string-match (nth 0 current
) doc
)
659 (setq found
(nth 1 current
)
665 (defcustom custom-browse-sort-alphabetically nil
666 "If non-nil, sort members of each customization group alphabetically."
668 :group
'custom-browse
)
670 (defcustom custom-browse-order-groups nil
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type
'(choice (const first
)
676 (const :tag
"none" nil
))
677 :group
'custom-browse
)
679 (defcustom custom-browse-only-groups nil
680 "If non-nil, show group members only within each customization group."
682 :group
'custom-browse
)
684 (defcustom custom-buffer-sort-alphabetically nil
685 "If non-nil, sort members of each customization group alphabetically."
687 :group
'custom-buffer
)
689 (defcustom custom-buffer-order-groups
'last
690 "If non-nil, order group members within each customization group.
691 If `first', order groups before non-groups.
692 If `last', order groups after non-groups."
693 :type
'(choice (const first
)
695 (const :tag
"none" nil
))
696 :group
'custom-buffer
)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort members of each customization group alphabetically."
703 (defcustom custom-menu-order-groups
'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups
)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items
)
722 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
723 (namea (nth 0 a
)) (nameb (nth 0 b
)))
724 (cond ((not order-groups
)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb
)))
728 ((eq typea
'custom-group
)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb
'custom-group
)
731 (when sort-alphabetically
732 (string-lessp namea nameb
))
733 (eq order-groups
'first
)))
734 ((eq typeb
'custom-group
)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups
'last
))
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb
)))))))
741 ;;; Custom Mode Commands.
743 (defvar custom-options nil
744 "Customization widgets in the current buffer.")
747 "Set changes in all modified options."
749 (let ((children custom-options
))
750 (mapc (lambda (child)
751 (when (eq (widget-get child
:custom-state
) 'modified
)
752 (widget-apply child
:custom-set
)))
755 (defun Custom-save ()
756 "Set all modified group members and save them."
758 (let ((children custom-options
))
759 (mapc (lambda (child)
760 (when (memq (widget-get child
:custom-state
)
761 '(modified set changed rogue
))
762 (widget-apply child
:custom-save
)))
766 (defvar custom-reset-menu
767 '(("Current" . Custom-reset-current
)
768 ("Saved" . Custom-reset-saved
)
769 ("Erase Customization (use standard values)" . Custom-reset-standard
))
770 "Alist of actions for the `Reset' button.
771 The key is a string containing the name of the action, the value is a
772 Lisp function taking the widget as an element which will be called
773 when the action is chosen.")
775 (defun custom-reset (event)
776 "Select item from reset menu."
777 (let* ((completion-ignore-case t
)
778 (answer (widget-choose "Reset to"
784 (defun Custom-reset-current (&rest ignore
)
785 "Reset all modified group members to their current value."
787 (let ((children custom-options
))
788 (mapc (lambda (widget)
789 (if (memq (widget-get widget
:custom-state
)
791 (widget-apply widget
:custom-reset-current
)))
794 (defun Custom-reset-saved (&rest ignore
)
795 "Reset all modified or set group members to their saved value."
797 (let ((children custom-options
))
798 (mapc (lambda (widget)
799 (if (memq (widget-get widget
:custom-state
)
800 '(modified set changed rogue
))
801 (widget-apply widget
:custom-reset-saved
)))
804 (defun Custom-reset-standard (&rest ignore
)
805 "Erase all customization (either current or saved) for the group members.
806 The immediate result is to restore them to their standard values.
807 This operation eliminates any saved values for the group members,
808 making them as if they had never been customized at all."
810 (let ((children custom-options
))
811 (when (or (and (= 1 (length children
))
812 (memq (widget-type (car children
))
813 '(custom-variable custom-face
)))
814 (yes-or-no-p "Really erase all customizations in this buffer? "))
815 (mapc (lambda (widget)
816 (and (if (widget-get widget
:custom-standard-value
)
817 (widget-apply widget
:custom-standard-value
)
819 (memq (widget-get widget
:custom-state
)
820 '(modified set changed saved rogue
))
821 (widget-apply widget
:custom-reset-standard
)))
824 ;;; The Customize Commands
826 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
827 "Prompt for a variable and a value and return them as a list.
828 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
829 prompt for the value. The %s escape in PROMPT-VAL is replaced with
830 the name of the variable.
832 If the variable has a `variable-interactive' property, that is used as if
833 it were the arg to `interactive' (which see) to interactively read the value.
835 If the variable has a `custom-type' property, it must be a widget and the
836 `:prompt-value' property of that widget will be used for reading the value.
838 If optional COMMENT argument is non nil, also prompt for a comment and return
839 it as the third element in the list."
840 (let* ((var (read-variable prompt-var
))
841 (minibuffer-help-form '(describe-variable var
))
843 (let ((prop (get var
'variable-interactive
))
844 (type (get var
'custom-type
))
845 (prompt (format prompt-val var
)))
847 (setq type
(list type
)))
849 ;; Use VAR's `variable-interactive' property
850 ;; as an interactive spec for prompting.
851 (call-interactively (list 'lambda
'(arg)
852 (list 'interactive prop
)
855 (widget-prompt-value type
861 (eval-minibuffer prompt
))))))
864 (read-string "Comment: " (get var
'variable-comment
)))
868 (defun customize-set-value (variable value
&optional comment
)
869 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
871 If VARIABLE has a `variable-interactive' property, that is used as if
872 it were the arg to `interactive' (which see) to interactively read the value.
874 If VARIABLE has a `custom-type' property, it must be a widget and the
875 `:prompt-value' property of that widget will be used for reading the value.
877 If given a prefix (or a COMMENT argument), also prompt for a comment."
878 (interactive (custom-prompt-variable "Set variable: "
882 (cond ((string= comment
"")
883 (put variable
'variable-comment nil
))
885 (put variable
'variable-comment comment
)))
886 (set variable value
))
889 (defun customize-set-variable (variable value
&optional comment
)
890 "Set the default for VARIABLE to VALUE, and return VALUE.
891 VALUE is a Lisp object.
893 If VARIABLE has a `custom-set' property, that is used for setting
894 VARIABLE, otherwise `set-default' is used.
896 The `customized-value' property of the VARIABLE will be set to a list
897 with a quoted VALUE as its sole list member.
899 If VARIABLE has a `variable-interactive' property, that is used as if
900 it were the arg to `interactive' (which see) to interactively read the value.
902 If VARIABLE has a `custom-type' property, it must be a widget and the
903 `:prompt-value' property of that widget will be used for reading the value.
905 If given a prefix (or a COMMENT argument), also prompt for a comment."
906 (interactive (custom-prompt-variable "Set variable: "
907 "Set customized value for %s to: "
909 (custom-load-symbol variable
)
910 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
911 (put variable
'customized-value
(list (custom-quote value
)))
912 (cond ((string= comment
"")
913 (put variable
'variable-comment nil
)
914 (put variable
'customized-variable-comment nil
))
916 (put variable
'variable-comment comment
)
917 (put variable
'customized-variable-comment comment
)))
921 (defun customize-save-variable (variable value
&optional comment
)
922 "Set the default for VARIABLE to VALUE, and save it for future sessions.
925 If VARIABLE has a `custom-set' property, that is used for setting
926 VARIABLE, otherwise `set-default' is used.
928 The `customized-value' property of the VARIABLE will be set to a list
929 with a quoted VALUE as its sole list member.
931 If VARIABLE has a `variable-interactive' property, that is used as if
932 it were the arg to `interactive' (which see) to interactively read the value.
934 If VARIABLE has a `custom-type' property, it must be a widget and the
935 `:prompt-value' property of that widget will be used for reading the value.
937 If given a prefix (or a COMMENT argument), also prompt for a comment."
938 (interactive (custom-prompt-variable "Set and save variable: "
939 "Set and save value for %s as: "
941 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
942 (put variable
'saved-value
(list (custom-quote value
)))
943 (custom-push-theme 'theme-value variable
'user
'set
(list (custom-quote value
)))
944 (cond ((string= comment
"")
945 (put variable
'variable-comment nil
)
946 (put variable
'saved-variable-comment nil
))
948 (put variable
'variable-comment comment
)
949 (put variable
'saved-variable-comment comment
)))
955 "Select a customization buffer which you can use to set user options.
956 User options are structured into \"groups\".
957 Initially the top-level group `Emacs' and its immediate subgroups
958 are shown; the contents of those subgroups are initially hidden."
960 (customize-group 'emacs
))
963 (defun customize-mode (mode)
964 "Customize options related to the current major mode.
965 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
966 then prompt for the MODE to customize."
969 (let ((completion-regexp-list '("-mode\\'"))
970 (group (custom-group-of-mode major-mode
)))
971 (if (and group
(not current-prefix-arg
))
974 (completing-read (if group
975 (format "Major mode (default %s): " major-mode
)
978 'custom-group-of-mode
979 t nil nil
(if group
(symbol-name major-mode
))))))))
980 (customize-group (custom-group-of-mode mode
)))
984 (defun customize-group (group)
985 "Customize GROUP, which must be a customization group."
987 (list (let ((completion-ignore-case t
))
988 (completing-read "Customize group (default emacs): "
991 (or (and (get symbol
'custom-loads
)
992 (not (get symbol
'custom-autoload
)))
993 (get symbol
'custom-group
)))
995 (when (stringp group
)
996 (if (string-equal "" group
)
998 (setq group
(intern group
))))
999 (let ((name (format "*Customize Group: %s*"
1000 (custom-unlispify-tag-name group
))))
1001 (if (get-buffer name
)
1002 (pop-to-buffer name
)
1003 (custom-buffer-create (list (list group
'custom-group
))
1005 (concat " for group "
1006 (custom-unlispify-tag-name group
))))))
1009 (defun customize-group-other-window (group)
1010 "Customize GROUP, which must be a customization group."
1012 (list (let ((completion-ignore-case t
))
1013 (completing-read "Customize group (default emacs): "
1016 (or (and (get symbol
'custom-loads
)
1017 (not (get symbol
'custom-autoload
)))
1018 (get symbol
'custom-group
)))
1020 (when (stringp group
)
1021 (if (string-equal "" group
)
1023 (setq group
(intern group
))))
1024 (let ((name (format "*Customize Group: %s*"
1025 (custom-unlispify-tag-name group
))))
1026 (if (get-buffer name
)
1028 ;; Copied from `custom-buffer-create-other-window'.
1030 (same-window-buffer-names nil
)
1031 (same-window-regexps nil
))
1032 (pop-to-buffer name
))
1033 (custom-buffer-create-other-window
1034 (list (list group
'custom-group
))
1036 (concat " for group "
1037 (custom-unlispify-tag-name group
))))))
1040 (defalias 'customize-variable
'customize-option
)
1043 (defun customize-option (symbol)
1044 "Customize SYMBOL, which must be a user option variable."
1045 (interactive (custom-variable-prompt))
1046 (let ((basevar (indirect-variable symbol
)))
1047 (custom-buffer-create (list (list basevar
'custom-variable
))
1048 (format "*Customize Option: %s*"
1049 (custom-unlispify-tag-name basevar
)))
1050 (unless (eq symbol basevar
)
1051 (message "`%s' is an alias for `%s'" symbol basevar
))))
1054 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1057 (defun customize-option-other-window (symbol)
1058 "Customize SYMBOL, which must be a user option variable.
1059 Show the buffer in another window, but don't select it."
1060 (interactive (custom-variable-prompt))
1061 (let ((basevar (indirect-variable symbol
)))
1062 (custom-buffer-create-other-window
1063 (list (list basevar
'custom-variable
))
1064 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1065 (unless (eq symbol basevar
)
1066 (message "`%s' is an alias for `%s'" symbol basevar
))))
1068 (defvar customize-changed-options-previous-release
"21.1"
1069 "Version for `customize-changed-options' to refer back to by default.")
1072 (defalias 'customize-changed
'customize-changed-options
)
1075 (defun customize-changed-options (since-version)
1076 "Customize all settings whose meanings have changed in Emacs itself.
1077 This includes new user option variables and faces, and new
1078 customization groups, as well as older options and faces whose meanings
1079 or default values have changed since the previous major Emacs release.
1081 With argument SINCE-VERSION (a string), customize all settings
1082 that were added or redefined since that version."
1084 (interactive "sCustomize options changed, since version (default all versions): ")
1085 (if (equal since-version
"")
1086 (setq since-version nil
)
1087 (unless (condition-case nil
1088 (numberp (read since-version
))
1090 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1091 (unless since-version
1092 (setq since-version customize-changed-options-previous-release
))
1094 ;; Load the information for versions since since-version. We use
1095 ;; custom-load-symbol for this.
1096 (put 'custom-versions-load-alist
'custom-loads nil
)
1097 (dolist (elt custom-versions-load-alist
)
1098 (if (customize-version-lessp since-version
(car elt
))
1099 (dolist (load (cdr elt
))
1100 (custom-add-load 'custom-versions-load-alist load
))))
1101 (custom-load-symbol 'custom-versions-load-alist
)
1102 (put 'custom-versions-load-alist
'custom-loads nil
)
1107 (let ((version (get symbol
'custom-version
)))
1109 (when (customize-version-lessp since-version version
)
1110 (if (or (get symbol
'custom-group
)
1111 (get symbol
'group-documentation
))
1112 (push (list symbol
'custom-group
) found
))
1113 (if (custom-variable-p symbol
)
1114 (push (list symbol
'custom-variable
) found
))
1115 (if (custom-facep symbol
)
1116 (push (list symbol
'custom-face
) found
)))))))
1118 (custom-buffer-create (custom-sort-items found t
'first
)
1119 "*Customize Changed Options*")
1120 (error "No user option defaults have been changed since Emacs %s"
1123 (defun customize-version-lessp (version1 version2
)
1124 ;; Why are the versions strings, and given that they are, why aren't
1125 ;; they converted to numbers and compared as such here? -- fx
1127 ;; In case someone made a mistake and left out the quotes
1128 ;; in the :version value.
1129 (if (numberp version2
)
1130 (setq version2
(prin1-to-string version2
)))
1131 (let (major1 major2 minor1 minor2
)
1132 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1133 (setq major1
(read (or (match-string 1 version1
)
1135 (setq minor1
(read (or (match-string 3 version1
)
1137 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1138 (setq major2
(read (or (match-string 1 version2
)
1140 (setq minor2
(read (or (match-string 3 version2
)
1142 (or (< major1 major2
)
1143 (and (= major1 major2
)
1144 (< minor1 minor2
)))))
1147 (defun customize-face (&optional face
)
1148 "Customize FACE, which should be a face name or nil.
1149 If FACE is nil, customize all faces. If FACE is actually a
1150 face-alias, customize the face it is aliased to.
1152 Interactively, when point is on text which has a face specified,
1153 suggest to customize that face, if it's customizable."
1155 (list (read-face-name "Customize face" "all faces" t
)))
1156 (if (member face
'(nil ""))
1157 (setq face
(face-list)))
1158 (if (and (listp face
) (null (cdr face
)))
1159 (setq face
(car face
)))
1161 (custom-buffer-create (custom-sort-items
1163 (list s
'custom-face
))
1166 "*Customize Faces*")
1167 ;; If FACE is actually an alias, customize the face it is aliased to.
1168 (if (get face
'face-alias
)
1169 (setq face
(get face
'face-alias
)))
1170 (unless (facep face
)
1171 (error "Invalid face %S" face
))
1172 (custom-buffer-create (list (list face
'custom-face
))
1173 (format "*Customize Face: %s*"
1174 (custom-unlispify-tag-name face
)))))
1177 (defun customize-face-other-window (&optional face
)
1178 "Show customization buffer for face FACE in other window.
1179 If FACE is actually a face-alias, customize the face it is aliased to.
1181 Interactively, when point is on text which has a face specified,
1182 suggest to customize that face, if it's customizable."
1184 (list (read-face-name "Customize face" "all faces" t
)))
1185 (if (member face
'(nil ""))
1186 (setq face
(face-list)))
1187 (if (and (listp face
) (null (cdr face
)))
1188 (setq face
(car face
)))
1190 (custom-buffer-create-other-window
1193 (list s
'custom-face
))
1196 "*Customize Faces*")
1197 (if (get face
'face-alias
)
1198 (setq face
(get face
'face-alias
)))
1199 (unless (facep face
)
1200 (error "Invalid face %S" face
))
1201 (custom-buffer-create-other-window
1202 (list (list face
'custom-face
))
1203 (format "*Customize Face: %s*"
1204 (custom-unlispify-tag-name face
)))))
1207 (defun customize-customized ()
1208 "Customize all user options set since the last save in this session."
1211 (mapatoms (lambda (symbol)
1212 (and (or (get symbol
'customized-face
)
1213 (get symbol
'customized-face-comment
))
1214 (custom-facep symbol
)
1215 (push (list symbol
'custom-face
) found
))
1216 (and (or (get symbol
'customized-value
)
1217 (get symbol
'customized-variable-comment
))
1219 (push (list symbol
'custom-variable
) found
))))
1221 (error "No customized user options")
1222 (custom-buffer-create (custom-sort-items found t nil
)
1223 "*Customize Customized*"))))
1226 (defun customize-rogue ()
1227 "Customize all user variable modified outside customize."
1230 (mapatoms (lambda (symbol)
1231 (let ((cval (or (get symbol
'customized-value
)
1232 (get symbol
'saved-value
)
1233 (get symbol
'standard-value
))))
1234 (when (and cval
;Declared with defcustom.
1235 (default-boundp symbol
) ;Has a value.
1236 (not (equal (eval (car cval
))
1237 ;; Which does not match customize.
1238 (default-value symbol
))))
1239 (push (list symbol
'custom-variable
) found
)))))
1241 (error "No rogue user options")
1242 (custom-buffer-create (custom-sort-items found t nil
)
1243 "*Customize Rogue*"))))
1245 (defun customize-saved ()
1246 "Customize all already saved user options."
1249 (mapatoms (lambda (symbol)
1250 (and (or (get symbol
'saved-face
)
1251 (get symbol
'saved-face-comment
))
1252 (custom-facep symbol
)
1253 (push (list symbol
'custom-face
) found
))
1254 (and (or (get symbol
'saved-value
)
1255 (get symbol
'saved-variable-comment
))
1257 (push (list symbol
'custom-variable
) found
))))
1259 (error "No saved user options")
1260 (custom-buffer-create (custom-sort-items found t nil
)
1261 "*Customize Saved*"))))
1264 (defun customize-apropos (regexp &optional all
)
1265 "Customize all loaded options, faces and groups matching REGEXP.
1266 If ALL is `options', include only options.
1267 If ALL is `faces', include only faces.
1268 If ALL is `groups', include only groups.
1269 If ALL is t (interactively, with prefix arg), include variables
1270 that are not customizable options, as well as faces and groups
1271 \(but we recommend using `apropos-variable' instead)."
1272 (interactive "sCustomize regexp: \nP")
1274 (mapatoms (lambda (symbol)
1275 (when (string-match regexp
(symbol-name symbol
))
1276 (when (and (not (memq all
'(faces options
)))
1277 (get symbol
'custom-group
))
1278 (push (list symbol
'custom-group
) found
))
1279 (when (and (not (memq all
'(options groups
)))
1280 (custom-facep symbol
))
1281 (push (list symbol
'custom-face
) found
))
1282 (when (and (not (memq all
'(groups faces
)))
1284 (eq (indirect-variable symbol
) symbol
)
1285 (or (get symbol
'saved-value
)
1286 (custom-variable-p symbol
)
1287 (and (not (memq all
'(nil options
)))
1288 (get symbol
'variable-documentation
))))
1289 (push (list symbol
'custom-variable
) found
)))))
1291 (error "No matches")
1292 (custom-buffer-create (custom-sort-items found t
1293 custom-buffer-order-groups
)
1294 "*Customize Apropos*"))))
1297 (defun customize-apropos-options (regexp &optional arg
)
1298 "Customize all loaded customizable options matching REGEXP.
1299 With prefix arg, include variables that are not customizable options
1300 \(but we recommend using `apropos-variable' instead)."
1301 (interactive "sCustomize regexp: \nP")
1302 (customize-apropos regexp
(or arg
'options
)))
1305 (defun customize-apropos-faces (regexp)
1306 "Customize all loaded faces matching REGEXP."
1307 (interactive "sCustomize regexp: \n")
1308 (customize-apropos regexp
'faces
))
1311 (defun customize-apropos-groups (regexp)
1312 "Customize all loaded groups matching REGEXP."
1313 (interactive "sCustomize regexp: \n")
1314 (customize-apropos regexp
'groups
))
1318 (defcustom custom-buffer-style
'links
1319 "Control the presentation style for customization buffers.
1320 The value should be a symbol, one of:
1322 brackets: groups nest within each other with big horizontal brackets.
1323 links: groups have links to subgroups."
1324 :type
'(radio (const brackets
)
1326 :group
'custom-buffer
)
1328 (defcustom custom-buffer-done-kill nil
1329 "*Non-nil means exiting a Custom buffer should kill it."
1332 :group
'custom-buffer
)
1334 (defcustom custom-buffer-indent
3
1335 "Number of spaces to indent nested groups."
1337 :group
'custom-buffer
)
1339 (defun custom-get-fresh-buffer (name)
1340 "Get a fresh new buffer with name NAME.
1341 If the buffer already exist, clean it up to be like new.
1342 Beware: it's not quite like new. Good enough for custom, but maybe
1344 ;; To be more complete, we should also kill all permanent-local variables,
1345 ;; but it's not needed for custom.
1346 (let ((buf (get-buffer name
)))
1347 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1348 ;; This will check if the file is not saved.
1352 (get-buffer-create name
)
1353 (with-current-buffer buf
1354 (kill-all-local-variables)
1355 (run-hooks 'kill-buffer-hook
)
1356 ;; Delete overlays before erasing the buffer so the overlay hooks
1357 ;; don't get run spuriously when we erase the buffer.
1358 (let ((ols (overlay-lists)))
1359 (dolist (ol (nconc (car ols
) (cdr ols
)))
1360 (delete-overlay ol
)))
1365 (defun custom-buffer-create (options &optional name description
)
1366 "Create a buffer containing OPTIONS.
1367 Optional NAME is the name of the buffer.
1368 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1369 SYMBOL is a customization option, and WIDGET is a widget for editing
1371 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1372 (custom-buffer-create-internal options description
))
1375 (defun custom-buffer-create-other-window (options &optional name description
)
1376 "Create a buffer containing OPTIONS, and display it in another window.
1377 The result includes selecting that window.
1378 Optional NAME is the name of the buffer.
1379 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1380 SYMBOL is a customization option, and WIDGET is a widget for editing
1382 (unless name
(setq name
"*Customization*"))
1383 (let ((pop-up-windows t
)
1384 (same-window-buffer-names nil
)
1385 (same-window-regexps nil
))
1386 (pop-to-buffer (custom-get-fresh-buffer name
))
1387 (custom-buffer-create-internal options description
)))
1389 (defcustom custom-reset-button-menu nil
1390 "If non-nil, only show a single reset button in customize buffers.
1391 This button will have a menu with all three reset operations."
1393 :group
'custom-buffer
)
1395 (defcustom custom-buffer-verbose-help t
1396 "If non-nil, include explanatory text in the customization buffer."
1398 :group
'custom-buffer
)
1400 (defun Custom-buffer-done (&rest ignore
)
1401 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1403 (quit-window custom-buffer-done-kill
))
1405 (defvar custom-button nil
1406 "Face used for buttons in customization buffers.")
1408 (defvar custom-button-pressed nil
1409 "Face used for pressed buttons in customization buffers.")
1411 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1412 '(("unspecified" . unspecified
))))
1413 "If non-nil, indicate active buttons in a `raised-button' style.
1414 Otherwise use brackets."
1417 :group
'custom-buffer
1418 :set
(lambda (variable value
)
1419 (custom-set-default variable value
)
1421 (if value
'custom-button
'custom-button-unraised
))
1422 (setq custom-button-pressed
1424 'custom-button-pressed
1425 'custom-button-pressed-unraised
))))
1427 (defun custom-buffer-create-internal (options &optional description
)
1429 (if custom-buffer-verbose-help
1431 (widget-insert "This is a customization buffer")
1433 (widget-insert description
))
1434 (widget-insert (format ".
1435 %s buttons; type RET or click mouse-1 to actuate one.
1436 Editing a setting changes only the text in the buffer.
1437 Use the setting's State button to set it or save changes in it.
1438 Saving a change normally works by editing your Emacs init file.
1440 (if custom-raised-buttons
1441 "`Raised' text indicates"
1442 "Square brackets indicate")))
1443 (widget-create 'info-link
1445 "(emacs)Saving Customizations")
1447 " for information on how to save in a different file.\n
1449 (widget-create 'info-link
1451 :help-echo
"Read the online help."
1452 "(emacs)Easy Customization")
1453 (widget-insert " for more information.\n\n")
1454 (widget-insert "Operate on everything in this buffer:\n "))
1455 (widget-insert " "))
1456 (widget-create 'push-button
1457 :tag
"Set for Current Session"
1459 Make your editing in this buffer take effect for this session."
1460 :action
(lambda (widget &optional event
)
1462 (when (or custom-file user-init-file
)
1464 (widget-create 'push-button
1465 :tag
"Save for Future Sessions"
1467 Make your editing in this buffer take effect for future Emacs sessions.
1468 This updates your Emacs initialization file or creates a new one."
1469 :action
(lambda (widget &optional event
)
1471 (if custom-reset-button-menu
1474 (widget-create 'push-button
1476 :help-echo
"Show a menu with reset operations."
1477 :mouse-down-action
(lambda (&rest junk
) t
)
1478 :action
(lambda (widget &optional event
)
1479 (custom-reset event
))))
1480 (widget-insert "\n ")
1481 (widget-create 'push-button
1482 :tag
"Reset to Current"
1484 Reset all edited text in this buffer to reflect current values."
1485 :action
'Custom-reset-current
)
1487 (widget-create 'push-button
1488 :tag
"Reset to Saved"
1490 Reset all settings in this buffer to their saved values."
1491 :action
'Custom-reset-saved
)
1493 (when (or custom-file user-init-file
)
1494 (widget-create 'push-button
1495 :tag
"Erase Customization"
1497 Un-customize all settings in this buffer--save them with standard values."
1498 :action
'Custom-reset-standard
)))
1499 (if (not custom-buffer-verbose-help
)
1502 (widget-create 'info-link
1504 :help-echo
"Read the online help."
1505 "(emacs)Easy Customization")))
1507 (widget-create 'push-button
1510 (lambda (&rest ignore
)
1511 (if custom-buffer-done-kill
1513 "Bury this buffer"))
1514 :action
#'Custom-buffer-done
)
1515 (widget-insert "\n\n")
1516 (message "Creating customization items...")
1517 (buffer-disable-undo)
1518 (setq custom-options
1519 (if (= (length options
) 1)
1520 (mapcar (lambda (entry)
1521 (widget-create (nth 1 entry
)
1522 :documentation-shown t
1523 :custom-state
'unknown
1524 :tag
(custom-unlispify-tag-name
1526 :value
(nth 0 entry
)))
1529 (length (length options
)))
1530 (mapcar (lambda (entry)
1532 (message "Creating customization items ...%2d%%"
1533 (/ (* 100.0 count
) length
))
1534 (widget-create (nth 1 entry
)
1535 :tag
(custom-unlispify-tag-name
1537 :value
(nth 0 entry
))
1538 (setq count
(1+ count
))
1539 (unless (eq (preceding-char) ?
\n)
1540 (widget-insert "\n"))
1541 (widget-insert "\n")))
1543 (unless (eq (preceding-char) ?
\n)
1544 (widget-insert "\n"))
1545 (message "Creating customization items ...done")
1546 (message "Resetting customization items...")
1547 (unless (eq custom-buffer-style
'tree
)
1548 (mapc 'custom-magic-reset custom-options
))
1549 (message "Resetting customization items...done")
1550 (message "Creating customization setup...")
1552 (buffer-enable-undo)
1553 (goto-char (point-min))
1554 (message "Creating customization setup...done"))
1556 ;;; The Tree Browser.
1559 (defun customize-browse (&optional group
)
1560 "Create a tree browser for the customize hierarchy."
1563 (setq group
'emacs
))
1564 (let ((name "*Customize Browser*"))
1565 (pop-to-buffer (custom-get-fresh-buffer name
)))
1567 (widget-insert (format "\
1568 %s buttons; type RET or click mouse-1
1569 on a button to invoke its action.
1570 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1571 (if custom-raised-buttons
1572 "`Raised' text indicates"
1573 "Square brackets indicate")))
1576 (if custom-browse-only-groups
1578 Invoke the [Group] button below to edit that item in another window.\n\n")
1579 (widget-insert "Invoke the ")
1580 (widget-create 'item
1583 :tag-glyph
"folder")
1584 (widget-insert ", ")
1585 (widget-create 'item
1589 (widget-insert ", and ")
1590 (widget-create 'item
1593 :tag-glyph
"option")
1594 (widget-insert " buttons below to edit that
1595 item in another window.\n\n"))
1596 (let ((custom-buffer-style 'tree
))
1597 (widget-create 'custom-group
1599 :custom-state
'unknown
1600 :tag
(custom-unlispify-tag-name group
)
1603 (goto-char (point-min)))
1605 (define-widget 'custom-browse-visibility
'item
1606 "Control visibility of items in the customize tree browser."
1608 :action
'custom-browse-visibility-action
)
1610 (defun custom-browse-visibility-action (widget &rest ignore
)
1611 (let ((custom-buffer-style 'tree
))
1612 (custom-toggle-parent widget
)))
1614 (define-widget 'custom-browse-group-tag
'push-button
1615 "Show parent in other window when activated."
1618 :action
'custom-browse-group-tag-action
)
1620 (defun custom-browse-group-tag-action (widget &rest ignore
)
1621 (let ((parent (widget-get widget
:parent
)))
1622 (customize-group-other-window (widget-value parent
))))
1624 (define-widget 'custom-browse-variable-tag
'push-button
1625 "Show parent in other window when activated."
1628 :action
'custom-browse-variable-tag-action
)
1630 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1631 (let ((parent (widget-get widget
:parent
)))
1632 (customize-variable-other-window (widget-value parent
))))
1634 (define-widget 'custom-browse-face-tag
'push-button
1635 "Show parent in other window when activated."
1638 :action
'custom-browse-face-tag-action
)
1640 (defun custom-browse-face-tag-action (widget &rest ignore
)
1641 (let ((parent (widget-get widget
:parent
)))
1642 (customize-face-other-window (widget-value parent
))))
1644 (defconst custom-browse-alist
'((" " "space")
1650 (defun custom-browse-insert-prefix (prefix)
1651 "Insert PREFIX. On XEmacs convert it to line graphics."
1652 ;; Fixme: do graphics.
1653 (if nil
; (string-match "XEmacs" emacs-version)
1656 (while (not (string-equal prefix
""))
1657 (let ((entry (substring prefix
0 3)))
1658 (setq prefix
(substring prefix
3))
1659 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1660 (name (nth 1 (assoc entry custom-browse-alist
))))
1661 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1662 (overlay-put overlay
'start-open t
)
1663 (overlay-put overlay
'end-open t
)))))
1666 ;;; Modification of Basic Widgets.
1668 ;; We add extra properties to the basic widgets needed here. This is
1669 ;; fine, as long as we are careful to stay within out own namespace.
1671 ;; We want simple widgets to be displayed by default, but complex
1672 ;; widgets to be hidden.
1674 (widget-put (get 'item
'widget-type
) :custom-show t
)
1675 (widget-put (get 'editable-field
'widget-type
)
1676 :custom-show
(lambda (widget value
)
1677 (let ((pp (pp-to-string value
)))
1678 (cond ((string-match "\n" pp
)
1683 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1685 ;;; The `custom-manual' Widget.
1687 (define-widget 'custom-manual
'info-link
1688 "Link to the manual entry for this customization option."
1689 :help-echo
"Read the manual entry for this option."
1692 ;;; The `custom-magic' Widget.
1694 (defgroup custom-magic-faces nil
1695 "Faces used by the magic button."
1696 :group
'custom-faces
1697 :group
'custom-buffer
)
1699 (defface custom-invalid
'((((class color
))
1700 (:foreground
"yellow1" :background
"red1"))
1702 (:weight bold
:slant italic
:underline t
)))
1703 "Face used when the customize item is invalid."
1704 :group
'custom-magic-faces
)
1705 ;; backward-compatibility alias
1706 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1708 (defface custom-rogue
'((((class color
))
1709 (:foreground
"pink" :background
"black"))
1712 "Face used when the customize item is not defined for customization."
1713 :group
'custom-magic-faces
)
1714 ;; backward-compatibility alias
1715 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1717 (defface custom-modified
'((((min-colors 88) (class color
))
1718 (:foreground
"white" :background
"blue1"))
1720 (:foreground
"white" :background
"blue"))
1722 (:slant italic
:bold
)))
1723 "Face used when the customize item has been modified."
1724 :group
'custom-magic-faces
)
1725 ;; backward-compatibility alias
1726 (put 'custom-modified-face
'face-alias
'custom-modified
)
1728 (defface custom-set
'((((min-colors 88) (class color
))
1729 (:foreground
"blue1" :background
"white"))
1731 (:foreground
"blue" :background
"white"))
1734 "Face used when the customize item has been set."
1735 :group
'custom-magic-faces
)
1736 ;; backward-compatibility alias
1737 (put 'custom-set-face
'face-alias
'custom-set
)
1739 (defface custom-changed
'((((min-colors 88) (class color
))
1740 (:foreground
"white" :background
"blue1"))
1742 (:foreground
"white" :background
"blue"))
1745 "Face used when the customize item has been changed."
1746 :group
'custom-magic-faces
)
1747 ;; backward-compatibility alias
1748 (put 'custom-changed-face
'face-alias
'custom-changed
)
1750 (defface custom-saved
'((t (:underline t
)))
1751 "Face used when the customize item has been saved."
1752 :group
'custom-magic-faces
)
1753 ;; backward-compatibility alias
1754 (put 'custom-saved-face
'face-alias
'custom-saved
)
1756 (defconst custom-magic-alist
1757 '((nil "#" underline
"\
1758 UNINITIALIZED, you should not see this.")
1759 (unknown "?" italic
"\
1760 UNKNOWN, you should not see this.")
1761 (hidden "-" default
"\
1762 HIDDEN, invoke \"Show\" in the previous line to show." "\
1763 group now hidden, invoke \"Show\", above, to show contents.")
1764 (invalid "x" custom-invalid
"\
1765 INVALID, the displayed value cannot be set.")
1766 (modified "*" custom-modified
"\
1767 EDITED, shown value does not take effect until you set or save it." "\
1768 something in this group has been edited but not set.")
1769 (set "+" custom-set
"\
1770 SET for current session only." "\
1771 something in this group has been set but not saved.")
1772 (changed ":" custom-changed
"\
1773 CHANGED outside Customize; operating on it here may be unreliable." "\
1774 something in this group has been changed outside customize.")
1775 (saved "!" custom-saved
"\
1777 something in this group has been set and saved.")
1778 (rogue "@" custom-rogue
"\
1779 NO CUSTOMIZATION DATA; not intended to be customized." "\
1780 something in this group is not prepared for customization.")
1781 (standard " " nil
"\
1783 visible group members are all at standard values."))
1784 "Alist of customize option states.
1785 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1787 STATE is one of the following symbols:
1790 For internal use, should never occur.
1792 For internal use, should never occur.
1794 This item is not being displayed.
1796 This item is modified, but has an invalid form.
1798 This item is modified, and has a valid form.
1800 This item has been set but not saved.
1802 The current value of this item has been changed outside Customize.
1804 This item is marked for saving.
1806 This item has no customization information.
1808 This item is unchanged from the standard setting.
1810 MAGIC is a string used to present that state.
1812 FACE is a face used to present the state.
1814 ITEM-DESC is a string describing the state for options.
1816 GROUP-DESC is a string describing the state for groups. If this is
1817 left out, ITEM-DESC will be used.
1819 The string %c in either description will be replaced with the
1820 category of the item. These are `group'. `option', and `face'.
1822 The list should be sorted most significant first.")
1824 (defcustom custom-magic-show
'long
1825 "If non-nil, show textual description of the state.
1826 If `long', show a full-line description, not just one word."
1827 :type
'(choice (const :tag
"no" nil
)
1829 (other :tag
"short" short
))
1830 :group
'custom-buffer
)
1832 (defcustom custom-magic-show-hidden
'(option face
)
1833 "Control whether the State button is shown for hidden items.
1834 The value should be a list with the custom categories where the State
1835 button should be visible. Possible categories are `group', `option',
1837 :type
'(set (const group
) (const option
) (const face
))
1838 :group
'custom-buffer
)
1840 (defcustom custom-magic-show-button nil
1841 "Show a \"magic\" button indicating the state of each customization option."
1843 :group
'custom-buffer
)
1845 (define-widget 'custom-magic
'default
1846 "Show and manipulate state for a customization option."
1848 :action
'widget-parent-action
1851 :value-create
'custom-magic-value-create
1852 :value-delete
'widget-children-value-delete
)
1854 (defun widget-magic-mouse-down-action (widget &optional event
)
1855 ;; Non-nil unless hidden.
1856 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1860 (defun custom-magic-value-create (widget)
1861 "Create compact status report for WIDGET."
1862 (let* ((parent (widget-get widget
:parent
))
1863 (state (widget-get parent
:custom-state
))
1864 (hidden (eq state
'hidden
))
1865 (entry (assq state custom-magic-alist
))
1866 (magic (nth 1 entry
))
1867 (face (nth 2 entry
))
1868 (category (widget-get parent
:custom-category
))
1869 (text (or (and (eq category
'group
)
1872 (form (widget-get parent
:custom-form
))
1874 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1875 (setq text
(concat (match-string 1 text
)
1876 (symbol-name category
)
1877 (match-string 2 text
))))
1878 (when (and custom-magic-show
1880 (memq category custom-magic-show-hidden
)))
1882 (when (and (eq category
'group
)
1883 (not (and (eq custom-buffer-style
'links
)
1884 (> (widget-get parent
:custom-level
) 1))))
1885 (insert-char ?\
(* custom-buffer-indent
1886 (widget-get parent
:custom-level
))))
1887 (push (widget-create-child-and-convert
1889 :help-echo
"Change the state of this item."
1890 :format
(if hidden
"%t" "%[%t%]")
1891 :button-prefix
'widget-push-button-prefix
1892 :button-suffix
'widget-push-button-suffix
1893 :mouse-down-action
'widget-magic-mouse-down-action
1897 (let ((start (point)))
1898 (if (eq custom-magic-show
'long
)
1900 (insert (symbol-name state
)))
1901 (cond ((eq form
'lisp
)
1903 ((eq form
'mismatch
)
1904 (insert " (mismatch)")))
1905 (put-text-property start
(point) 'face
'custom-state
))
1907 (when (and (eq category
'group
)
1908 (not (and (eq custom-buffer-style
'links
)
1909 (> (widget-get parent
:custom-level
) 1))))
1910 (insert-char ?\
(* custom-buffer-indent
1911 (widget-get parent
:custom-level
))))
1912 (when custom-magic-show-button
1913 (when custom-magic-show
1914 (let ((indent (widget-get parent
:indent
)))
1916 (insert-char ? indent
))))
1917 (push (widget-create-child-and-convert
1919 :mouse-down-action
'widget-magic-mouse-down-action
1923 :help-echo
"Change the state."
1924 :format
(if hidden
"%t" "%[%t%]")
1925 :tag
(if (memq form
'(lisp mismatch
))
1926 (concat "(" magic
")")
1927 (concat "[" magic
"]")))
1930 (widget-put widget
:children children
)))
1932 (defun custom-magic-reset (widget)
1933 "Redraw the :custom-magic property of WIDGET."
1934 (let ((magic (widget-get widget
:custom-magic
)))
1935 (widget-value-set magic
(widget-value magic
))))
1937 ;;; The `custom' Widget.
1939 (defface custom-button
1940 '((((type x w32 mac
) (class color
)) ; Like default modeline
1941 (:box
(:line-width
2 :style released-button
)
1942 :background
"lightgrey" :foreground
"black"))
1945 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
1947 :group
'custom-faces
)
1948 ;; backward-compatibility alias
1949 (put 'custom-button-face
'face-alias
'custom-button
)
1951 (defface custom-button-unraised
1953 (class color
) (background light
)) :foreground
"blue1" :underline t
)
1954 (((class color
) (background light
)) :foreground
"blue" :underline t
)
1956 (class color
) (background dark
)) :foreground
"cyan1" :underline t
)
1957 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
1959 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
1961 :group
'custom-faces
)
1964 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
1966 (defface custom-button-pressed
1967 '((((type x w32 mac
) (class color
))
1968 (:box
(:line-width
2 :style pressed-button
)
1969 :background
"lightgrey" :foreground
"black"))
1971 (:inverse-video t
)))
1972 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
1974 :group
'custom-faces
)
1975 ;; backward-compatibility alias
1976 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
1978 (defface custom-button-pressed-unraised
1979 '((default :inherit custom-button-unraised
)
1980 (((class color
) (background light
)) :foreground
"magenta4")
1981 (((class color
) (background dark
)) :foreground
"violet"))
1982 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
1984 :group
'custom-faces
)
1986 (setq custom-button-pressed
1987 (if custom-raised-buttons
1988 'custom-button-pressed
1989 'custom-button-pressed-unraised
))
1991 (defface custom-documentation nil
1992 "Face used for documentation strings in customization buffers."
1993 :group
'custom-faces
)
1994 ;; backward-compatibility alias
1995 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
1997 (defface custom-state
'((((class color
)
1999 (:foreground
"lime green"))
2002 (:foreground
"dark green"))
2004 "Face used for State descriptions in the customize buffer."
2005 :group
'custom-faces
)
2006 ;; backward-compatibility alias
2007 (put 'custom-state-face
'face-alias
'custom-state
)
2009 (define-widget 'custom
'default
2010 "Customize a user option."
2012 :convert-widget
'custom-convert-widget
2013 :notify
'custom-notify
2016 :custom-state
'hidden
2017 :documentation-property
'widget-subclass-responsibility
2018 :value-create
'widget-subclass-responsibility
2019 :value-delete
'widget-children-value-delete
2020 :value-get
'widget-value-value-get
2021 :validate
'widget-children-validate
2022 :match
(lambda (widget value
) (symbolp value
)))
2024 (defun custom-convert-widget (widget)
2025 "Initialize :value and :tag from :args in WIDGET."
2026 (let ((args (widget-get widget
:args
)))
2028 (widget-put widget
:value
(widget-apply widget
2029 :value-to-internal
(car args
)))
2030 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2031 (widget-put widget
:args nil
)))
2034 (defun custom-notify (widget &rest args
)
2035 "Keep track of changes."
2036 (let ((state (widget-get widget
:custom-state
)))
2037 (unless (eq state
'modified
)
2038 (unless (memq state
'(nil unknown hidden
))
2039 (widget-put widget
:custom-state
'modified
))
2040 (custom-magic-reset widget
)
2041 (apply 'widget-default-notify widget args
))))
2043 (defun custom-redraw (widget)
2044 "Redraw WIDGET with current settings."
2045 (let ((line (count-lines (point-min) (point)))
2046 (column (current-column))
2048 (from (marker-position (widget-get widget
:from
)))
2049 (to (marker-position (widget-get widget
:to
))))
2051 (widget-value-set widget
(widget-value widget
))
2052 (custom-redraw-magic widget
))
2053 (when (and (>= pos from
) (<= pos to
))
2058 (goto-line (1+ line
)))
2059 (move-to-column column
))
2062 (defun custom-redraw-magic (widget)
2063 "Redraw WIDGET state with current settings."
2065 (let ((magic (widget-get widget
:custom-magic
)))
2067 (widget-value-set magic
(widget-value magic
))
2068 (when (setq widget
(widget-get widget
:group
))
2069 (custom-group-state-update widget
)))
2071 (setq widget nil
)))))
2074 (defun custom-show (widget value
)
2075 "Non-nil if WIDGET should be shown with VALUE by default."
2076 (let ((show (widget-get widget
:custom-show
)))
2082 (funcall show widget value
)))))
2084 (defun custom-load-widget (widget)
2085 "Load all dependencies for WIDGET."
2086 (custom-load-symbol (widget-value widget
)))
2088 (defun custom-unloaded-symbol-p (symbol)
2089 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2091 (loads (get symbol
'custom-loads
))
2094 (setq load
(car loads
)
2096 (cond ((symbolp load
)
2097 (unless (featurep load
)
2099 ((assoc load load-history
))
2100 ((assoc (locate-library load
) load-history
)
2106 (defun custom-unloaded-widget-p (widget)
2107 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2108 (custom-unloaded-symbol-p (widget-value widget
)))
2110 (defun custom-toggle-hide (widget)
2111 "Toggle visibility of WIDGET."
2112 (custom-load-widget widget
)
2113 (let ((state (widget-get widget
:custom-state
)))
2114 (cond ((memq state
'(invalid modified
))
2115 (error "There are unset changes"))
2117 (widget-put widget
:custom-state
'unknown
))
2119 (widget-put widget
:documentation-shown nil
)
2120 (widget-put widget
:custom-state
'hidden
)))
2121 (custom-redraw widget
)
2124 (defun custom-toggle-parent (widget &rest ignore
)
2125 "Toggle visibility of parent of WIDGET."
2126 (custom-toggle-hide (widget-get widget
:parent
)))
2128 (defun custom-add-see-also (widget &optional prefix
)
2129 "Add `See also ...' to WIDGET if there are any links.
2130 Insert PREFIX first if non-nil."
2131 (let* ((symbol (widget-get widget
:value
))
2132 (links (get symbol
'custom-links
))
2133 (many (> (length links
) 2))
2134 (buttons (widget-get widget
:buttons
))
2135 (indent (widget-get widget
:indent
)))
2138 (insert-char ?\ indent
))
2141 (insert "See also ")
2143 (push (widget-create-child-and-convert widget
(car links
))
2145 (setq links
(cdr links
))
2154 (widget-put widget
:buttons buttons
))))
2156 (defun custom-add-parent-links (widget &optional initial-string
)
2157 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2158 The value is non-nil if any parents were found.
2159 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2160 (let ((name (widget-value widget
))
2161 (type (widget-type widget
))
2162 (buttons (widget-get widget
:buttons
))
2165 (insert (or initial-string
"Parent groups:"))
2166 (mapatoms (lambda (symbol)
2167 (when (member (list name type
) (get symbol
'custom-group
))
2169 (push (widget-create-child-and-convert
2170 widget
'custom-group-link
2171 :tag
(custom-unlispify-tag-name symbol
)
2174 (setq parents
(cons symbol parents
)))))
2175 (and (null (get name
'custom-links
)) ;No links of its own.
2176 (= (length parents
) 1) ;A single parent.
2177 (let* ((links (delq nil
(mapcar (lambda (w)
2178 (unless (eq (widget-type w
)
2181 (get (car parents
) 'custom-links
))))
2182 (many (> (length links
) 2)))
2184 (insert "\nParent documentation: ")
2186 (push (widget-create-child-and-convert widget
(car links
))
2188 (setq links
(cdr links
))
2199 (delete-region start
(point)))
2200 (widget-put widget
:buttons buttons
)
2203 ;;; The `custom-comment' Widget.
2205 ;; like the editable field
2206 (defface custom-comment
'((((class grayscale color
)
2208 (:background
"gray85"))
2209 (((class grayscale color
)
2211 (:background
"dim gray"))
2214 "Face used for comments on variables or faces"
2216 :group
'custom-faces
)
2217 ;; backward-compatibility alias
2218 (put 'custom-comment-face
'face-alias
'custom-comment
)
2220 ;; like font-lock-comment-face
2221 (defface custom-comment-tag
2222 '((((class color
) (background dark
)) (:foreground
"gray80"))
2223 (((class color
) (background light
)) (:foreground
"blue4"))
2224 (((class grayscale
) (background light
))
2225 (:foreground
"DimGray" :weight bold
:slant italic
))
2226 (((class grayscale
) (background dark
))
2227 (:foreground
"LightGray" :weight bold
:slant italic
))
2229 "Face used for variables or faces comment tags"
2230 :group
'custom-faces
)
2231 ;; backward-compatibility alias
2232 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2234 (define-widget 'custom-comment
'string
2237 :help-echo
"Edit a comment here."
2238 :sample-face
'custom-comment-tag-face
2239 :value-face
'custom-comment-face
2241 :create
'custom-comment-create
)
2243 (defun custom-comment-create (widget)
2244 (let* ((null-comment (equal "" (widget-value widget
))))
2245 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2247 (widget-default-create widget
)
2248 ;; `widget-default-delete' expects markers in these slots --
2249 ;; maybe it shouldn't.
2250 (widget-put widget
:from
(point-marker))
2251 (widget-put widget
:to
(point-marker)))))
2253 (defun custom-comment-hide (widget)
2254 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2256 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2257 ;; the global custom one
2258 (defun custom-comment-show (widget)
2259 (widget-put widget
:comment-shown t
)
2260 (custom-redraw widget
)
2263 (defun custom-comment-invisible-p (widget)
2264 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2266 (not (widget-get widget
:comment-shown
)))))
2268 ;;; The `custom-variable' Widget.
2270 ;; When this was underlined blue, users confused it with a
2271 ;; Mosaic-style hyperlink...
2272 (defface custom-variable-tag
2275 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2276 (((min-colors 88) (class color
)
2278 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
2281 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
2283 "Face used for unpushable variable tags."
2284 :group
'custom-faces
)
2285 ;; backward-compatibility alias
2286 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2288 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2289 "Face used for pushable variable tags."
2290 :group
'custom-faces
)
2291 ;; backward-compatibility alias
2292 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2294 (defcustom custom-variable-default-form
'edit
2295 "Default form of displaying variable values."
2296 :type
'(choice (const edit
)
2298 :group
'custom-buffer
2301 (defun custom-variable-documentation (variable)
2302 "Return documentation of VARIABLE for use in Custom buffer.
2303 Normally just return the docstring. But if VARIABLE automatically
2304 becomes buffer local when set, append a message to that effect."
2305 (if (and (local-variable-if-set-p variable
)
2306 (or (not (local-variable-p variable
))
2308 (local-variable-if-set-p variable
))))
2309 (concat (documentation-property variable
'variable-documentation
)
2311 This variable automatically becomes buffer-local when set outside Custom.
2312 However, setting it through Custom sets the default value.")
2313 (documentation-property variable
'variable-documentation
)))
2315 (define-widget 'custom-variable
'custom
2316 "Customize variable."
2318 :help-echo
"Set or reset this variable."
2319 :documentation-property
#'custom-variable-documentation
2320 :custom-category
'option
2322 :custom-menu
'custom-variable-menu-create
2323 :custom-form nil
; defaults to value of `custom-variable-default-form'
2324 :value-create
'custom-variable-value-create
2325 :action
'custom-variable-action
2326 :custom-set
'custom-variable-set
2327 :custom-save
'custom-variable-save
2328 :custom-reset-current
'custom-redraw
2329 :custom-reset-saved
'custom-variable-reset-saved
2330 :custom-reset-standard
'custom-variable-reset-standard
2331 :custom-standard-value
'custom-variable-standard-value
)
2333 (defun custom-variable-type (symbol)
2334 "Return a widget suitable for editing the value of SYMBOL.
2335 If SYMBOL has a `custom-type' property, use that.
2336 Otherwise, look up symbol in `custom-guess-type-alist'."
2337 (let* ((type (or (get symbol
'custom-type
)
2338 (and (not (get symbol
'standard-value
))
2339 (custom-guess-type symbol
))
2341 (options (get symbol
'custom-options
))
2342 (tmp (if (listp type
)
2343 (copy-sequence type
)
2346 (widget-put tmp
:options options
))
2349 (defun custom-variable-value-create (widget)
2350 "Here is where you edit the variable's value."
2351 (custom-load-widget widget
)
2352 (unless (widget-get widget
:custom-form
)
2353 (widget-put widget
:custom-form custom-variable-default-form
))
2354 (let* ((buttons (widget-get widget
:buttons
))
2355 (children (widget-get widget
:children
))
2356 (form (widget-get widget
:custom-form
))
2357 (state (widget-get widget
:custom-state
))
2358 (symbol (widget-get widget
:value
))
2359 (tag (widget-get widget
:tag
))
2360 (type (custom-variable-type symbol
))
2361 (conv (widget-convert type
))
2362 (get (or (get symbol
'custom-get
) 'default-value
))
2363 (prefix (widget-get widget
:custom-prefix
))
2364 (last (widget-get widget
:custom-last
))
2365 (value (if (default-boundp symbol
)
2366 (funcall get symbol
)
2367 (widget-get conv
:value
))))
2368 ;; If the widget is new, the child determines whether it is hidden.
2370 ((custom-show type value
)
2371 (setq state
'unknown
))
2373 (setq state
'hidden
)))
2374 ;; If we don't know the state, see if we need to edit it in lisp form.
2375 (when (eq state
'unknown
)
2376 (unless (widget-apply conv
:match value
)
2377 ;; (widget-apply (widget-convert type) :match value)
2378 (setq form
'mismatch
)))
2379 ;; Now we can create the child widget.
2380 (cond ((eq custom-buffer-style
'tree
)
2381 (insert prefix
(if last
" `--- " " |--- "))
2382 (push (widget-create-child-and-convert
2383 widget
'custom-browse-variable-tag
)
2385 (insert " " tag
"\n")
2386 (widget-put widget
:buttons buttons
))
2388 ;; Indicate hidden value.
2389 (push (widget-create-child-and-convert
2392 :sample-face
'custom-variable-tag-face
2396 (push (widget-create-child-and-convert
2398 :help-echo
"Show the value of this option."
2400 :action
'custom-toggle-parent
2403 ((memq form
'(lisp mismatch
))
2404 ;; In lisp mode edit the saved value when possible.
2405 (let* ((value (cond ((get symbol
'saved-value
)
2406 (car (get symbol
'saved-value
)))
2407 ((get symbol
'standard-value
)
2408 (car (get symbol
'standard-value
)))
2409 ((default-boundp symbol
)
2410 (custom-quote (funcall get symbol
)))
2412 (custom-quote (widget-get conv
:value
))))))
2413 (insert (symbol-name symbol
) ": ")
2414 (push (widget-create-child-and-convert
2416 :help-echo
"Hide the value of this option."
2419 :action
'custom-toggle-parent
2423 (push (widget-create-child-and-convert
2425 :button-face
'custom-variable-button-face
2427 :tag
(symbol-name symbol
)
2433 (let* ((format (widget-get type
:format
))
2434 tag-format value-format
)
2435 (unless (string-match ":" format
)
2436 (error "Bad format"))
2437 (setq tag-format
(substring format
0 (match-end 0)))
2438 (setq value-format
(substring format
(match-end 0)))
2439 (push (widget-create-child-and-convert
2442 :action
'custom-tag-action
2443 :help-echo
"Change value of this option."
2444 :mouse-down-action
'custom-tag-mouse-down-action
2445 :button-face
'custom-variable-button-face
2446 :sample-face
'custom-variable-tag-face
2450 (push (widget-create-child-and-convert
2452 :help-echo
"Hide the value of this option."
2455 :action
'custom-toggle-parent
2458 (push (widget-create-child-and-convert
2460 :format value-format
2463 (unless (eq custom-buffer-style
'tree
)
2464 (unless (eq (preceding-char) ?
\n)
2465 (widget-insert "\n"))
2466 ;; Create the magic button.
2467 (let ((magic (widget-create-child-and-convert
2468 widget
'custom-magic nil
)))
2469 (widget-put widget
:custom-magic magic
)
2470 (push magic buttons
))
2471 ;; ### NOTE: this is ugly!!!! I need to update the :buttons property
2472 ;; before the call to `widget-default-format-handler'. Otherwise, I
2473 ;; loose my current `buttons'. This function shouldn't be called like
2474 ;; this anyway. The doc string widget should be added like the others.
2476 (widget-put widget
:buttons buttons
)
2478 ;; Insert documentation.
2479 (widget-default-format-handler widget ?h
)
2481 ;; The comment field
2482 (unless (eq state
'hidden
)
2483 (let* ((comment (get symbol
'variable-comment
))
2485 (widget-create-child-and-convert
2486 widget
'custom-comment
2488 :value
(or comment
""))))
2489 (widget-put widget
:comment-widget comment-widget
)
2490 ;; Don't push it !!! Custom assumes that the first child is the
2492 (setq children
(append children
(list comment-widget
)))))
2493 ;; Update the rest of the properties properties.
2494 (widget-put widget
:custom-form form
)
2495 (widget-put widget
:children children
)
2496 ;; Now update the state.
2497 (if (eq state
'hidden
)
2498 (widget-put widget
:custom-state state
)
2499 (custom-variable-state-set widget
))
2501 (unless (eq state
'hidden
)
2502 (when (eq (widget-get widget
:custom-level
) 1)
2503 (custom-add-parent-links widget
))
2504 (custom-add-see-also widget
)))))
2506 (defun custom-tag-action (widget &rest args
)
2507 "Pass :action to first child of WIDGET's parent."
2508 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2511 (defun custom-tag-mouse-down-action (widget &rest args
)
2512 "Pass :mouse-down-action to first child of WIDGET's parent."
2513 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2514 :mouse-down-action args
))
2516 (defun custom-variable-state-set (widget)
2517 "Set the state of WIDGET."
2518 (let* ((symbol (widget-value widget
))
2519 (get (or (get symbol
'custom-get
) 'default-value
))
2520 (value (if (default-boundp symbol
)
2521 (funcall get symbol
)
2522 (widget-get widget
:value
)))
2523 (comment (get symbol
'variable-comment
))
2526 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2528 (get symbol
'customized-variable-comment
))
2530 (if (condition-case nil
2531 (and (equal value
(eval (car tmp
)))
2532 (equal comment temp
))
2536 ((progn (setq tmp
(get symbol
'saved-value
))
2537 (setq temp
(get symbol
'saved-variable-comment
))
2539 (if (condition-case nil
2540 (and (equal value
(eval (car tmp
)))
2541 (equal comment temp
))
2545 ((setq tmp
(get symbol
'standard-value
))
2546 (if (condition-case nil
2547 (and (equal value
(eval (car tmp
)))
2548 (equal comment nil
))
2553 (widget-put widget
:custom-state state
)))
2555 (defun custom-variable-standard-value (widget)
2556 (get (widget-value widget
) 'standard-value
))
2558 (defvar custom-variable-menu
2559 `(("Set for Current Session" custom-variable-set
2561 (eq (widget-get widget
:custom-state
) 'modified
)))
2562 ,@(when (or custom-file user-init-file
)
2563 '(("Save for Future Sessions" custom-variable-save
2565 (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))))))
2566 ("Reset to Current" custom-redraw
2568 (and (default-boundp (widget-value widget
))
2569 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2570 ("Reset to Saved" custom-variable-reset-saved
2572 (and (or (get (widget-value widget
) 'saved-value
)
2573 (get (widget-value widget
) 'saved-variable-comment
))
2574 (memq (widget-get widget
:custom-state
)
2575 '(modified set changed rogue
)))))
2576 ,@(when (or custom-file user-init-file
)
2577 '(("Erase Customization" custom-variable-reset-standard
2579 (and (get (widget-value widget
) 'standard-value
)
2580 (memq (widget-get widget
:custom-state
)
2581 '(modified set changed saved rogue
)))))))
2582 ("Use Backup Value" custom-variable-reset-backup
2584 (get (widget-value widget
) 'backup-value
)))
2585 ("---" ignore ignore
)
2586 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2587 ("---" ignore ignore
)
2588 ("Don't show as Lisp expression" custom-variable-edit
2590 (eq (widget-get widget
:custom-form
) 'lisp
)))
2591 ("Show initial Lisp expression" custom-variable-edit-lisp
2593 (eq (widget-get widget
:custom-form
) 'edit
))))
2594 "Alist of actions for the `custom-variable' widget.
2595 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2596 the menu entry, ACTION is the function to call on the widget when the
2597 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2598 widget as an argument, and returns non-nil if ACTION is valid on that
2599 widget. If FILTER is nil, ACTION is always valid.")
2601 (defun custom-variable-action (widget &optional event
)
2602 "Show the menu for `custom-variable' WIDGET.
2603 Optional EVENT is the location for the menu."
2604 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2605 (custom-toggle-hide widget
)
2606 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2607 (custom-variable-state-set widget
))
2608 (custom-redraw-magic widget
)
2609 (let* ((completion-ignore-case t
)
2610 (answer (widget-choose (concat "Operation on "
2611 (custom-unlispify-tag-name
2612 (widget-get widget
:value
)))
2613 (custom-menu-filter custom-variable-menu
2617 (funcall answer widget
)))))
2619 (defun custom-variable-edit (widget)
2620 "Edit value of WIDGET."
2621 (widget-put widget
:custom-state
'unknown
)
2622 (widget-put widget
:custom-form
'edit
)
2623 (custom-redraw widget
))
2625 (defun custom-variable-edit-lisp (widget)
2626 "Edit the Lisp representation of the value of WIDGET."
2627 (widget-put widget
:custom-state
'unknown
)
2628 (widget-put widget
:custom-form
'lisp
)
2629 (custom-redraw widget
))
2631 (defun custom-variable-set (widget)
2632 "Set the current value for the variable being edited by WIDGET."
2633 (let* ((form (widget-get widget
:custom-form
))
2634 (state (widget-get widget
:custom-state
))
2635 (child (car (widget-get widget
:children
)))
2636 (symbol (widget-value widget
))
2637 (set (or (get symbol
'custom-set
) 'set-default
))
2638 (comment-widget (widget-get widget
:comment-widget
))
2639 (comment (widget-value comment-widget
))
2641 (cond ((eq state
'hidden
)
2642 (error "Cannot set hidden variable"))
2643 ((setq val
(widget-apply child
:validate
))
2644 (goto-char (widget-get val
:from
))
2645 (error "%s" (widget-get val
:error
)))
2646 ((memq form
'(lisp mismatch
))
2647 (when (equal comment
"")
2649 ;; Make the comment invisible by hand if it's empty
2650 (custom-comment-hide comment-widget
))
2651 (custom-variable-backup-value widget
)
2652 (funcall set symbol
(eval (setq val
(widget-value child
))))
2653 (put symbol
'customized-value
(list val
))
2654 (put symbol
'variable-comment comment
)
2655 (put symbol
'customized-variable-comment comment
))
2657 (when (equal comment
"")
2659 ;; Make the comment invisible by hand if it's empty
2660 (custom-comment-hide comment-widget
))
2661 (custom-variable-backup-value widget
)
2662 (funcall set symbol
(setq val
(widget-value child
)))
2663 (put symbol
'customized-value
(list (custom-quote val
)))
2664 (put symbol
'variable-comment comment
)
2665 (put symbol
'customized-variable-comment comment
)))
2666 (custom-variable-state-set widget
)
2667 (custom-redraw-magic widget
)))
2669 (defun custom-variable-save (widget)
2670 "Set and save the value for the variable being edited by WIDGET."
2671 (let* ((form (widget-get widget
:custom-form
))
2672 (state (widget-get widget
:custom-state
))
2673 (child (car (widget-get widget
:children
)))
2674 (symbol (widget-value widget
))
2675 (set (or (get symbol
'custom-set
) 'set-default
))
2676 (comment-widget (widget-get widget
:comment-widget
))
2677 (comment (widget-value comment-widget
))
2679 (cond ((eq state
'hidden
)
2680 (error "Cannot set hidden variable"))
2681 ((setq val
(widget-apply child
:validate
))
2682 (goto-char (widget-get val
:from
))
2683 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2684 ((memq form
'(lisp mismatch
))
2685 (when (equal comment
"")
2687 ;; Make the comment invisible by hand if it's empty
2688 (custom-comment-hide comment-widget
))
2689 (put symbol
'saved-value
(list (widget-value child
)))
2690 (custom-push-theme 'theme-value symbol
'user
2691 'set
(list (widget-value child
)))
2692 (funcall set symbol
(eval (widget-value child
)))
2693 (put symbol
'variable-comment comment
)
2694 (put symbol
'saved-variable-comment comment
))
2696 (when (equal comment
"")
2698 ;; Make the comment invisible by hand if it's empty
2699 (custom-comment-hide comment-widget
))
2700 (put symbol
'saved-value
2701 (list (custom-quote (widget-value child
))))
2702 (custom-push-theme 'theme-value symbol
'user
2703 'set
(list (custom-quote (widget-value
2705 (funcall set symbol
(widget-value child
))
2706 (put symbol
'variable-comment comment
)
2707 (put symbol
'saved-variable-comment comment
)))
2708 (put symbol
'customized-value nil
)
2709 (put symbol
'customized-variable-comment nil
)
2711 (custom-variable-state-set widget
)
2712 (custom-redraw-magic widget
)))
2714 (defun custom-variable-reset-saved (widget)
2715 "Restore the saved value for the variable being edited by WIDGET.
2716 The value that was current before this operation
2717 becomes the backup value, so you can get it again."
2718 (let* ((symbol (widget-value widget
))
2719 (set (or (get symbol
'custom-set
) 'set-default
))
2720 (value (get symbol
'saved-value
))
2721 (comment (get symbol
'saved-variable-comment
)))
2722 (cond ((or value comment
)
2723 (put symbol
'variable-comment comment
)
2724 (custom-variable-backup-value widget
)
2726 (funcall set symbol
(eval (car value
)))
2729 (error "No saved value for %s" symbol
)))
2730 (put symbol
'customized-value nil
)
2731 (put symbol
'customized-variable-comment nil
)
2732 (widget-put widget
:custom-state
'unknown
)
2733 ;; This call will possibly make the comment invisible
2734 (custom-redraw widget
)))
2736 (defun custom-variable-reset-standard (widget)
2737 "Restore the standard setting for the variable being edited by WIDGET.
2738 This operation eliminates any saved setting for the variable,
2739 restoring it to the state of a variable that has never been customized.
2740 The value that was current before this operation
2741 becomes the backup value, so you can get it again."
2742 (let* ((symbol (widget-value widget
))
2743 (set (or (get symbol
'custom-set
) 'set-default
)))
2744 (if (get symbol
'standard-value
)
2746 (custom-variable-backup-value widget
)
2747 (funcall set symbol
(eval (car (get symbol
'standard-value
)))))
2748 (error "No standard setting known for %S" symbol
))
2749 (put symbol
'variable-comment nil
)
2750 (put symbol
'customized-value nil
)
2751 (put symbol
'customized-variable-comment nil
)
2752 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2753 (put symbol
'saved-value nil
)
2754 (custom-push-theme 'theme-value symbol
'user
'reset
'standard
)
2755 ;; As a special optimizations we do not (explictly)
2756 ;; save resets to standard when no theme set the value.
2757 (if (null (cdr (get symbol
'theme-value
)))
2758 (put symbol
'theme-value nil
))
2759 (put symbol
'saved-variable-comment nil
)
2761 (widget-put widget
:custom-state
'unknown
)
2762 ;; This call will possibly make the comment invisible
2763 (custom-redraw widget
)))
2765 (defun custom-variable-backup-value (widget)
2766 "Back up the current value for WIDGET's variable.
2767 The backup value is kept in the car of the `backup-value' property."
2768 (let* ((symbol (widget-value widget
))
2769 (get (or (get symbol
'custom-get
) 'default-value
))
2770 (type (custom-variable-type symbol
))
2771 (conv (widget-convert type
))
2772 (value (if (default-boundp symbol
)
2773 (funcall get symbol
)
2774 (widget-get conv
:value
))))
2775 (put symbol
'backup-value
(list value
))))
2777 (defun custom-variable-reset-backup (widget)
2778 "Restore the backup value for the variable being edited by WIDGET.
2779 The value that was current before this operation
2780 becomes the backup value, so you can use this operation repeatedly
2781 to switch between two values."
2782 (let* ((symbol (widget-value widget
))
2783 (set (or (get symbol
'custom-set
) 'set-default
))
2784 (value (get symbol
'backup-value
))
2785 (comment-widget (widget-get widget
:comment-widget
))
2786 (comment (widget-value comment-widget
)))
2789 (custom-variable-backup-value widget
)
2791 (funcall set symbol
(car value
))
2793 (error "No backup value for %s" symbol
))
2794 (put symbol
'customized-value
(list (car value
)))
2795 (put symbol
'variable-comment comment
)
2796 (put symbol
'customized-variable-comment comment
)
2797 (custom-variable-state-set widget
)
2798 ;; This call will possibly make the comment invisible
2799 (custom-redraw widget
)))
2801 ;;; The `custom-face-edit' Widget.
2803 (define-widget 'custom-face-edit
'checklist
2804 "Edit face attributes."
2808 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
2809 :value-to-internal
'custom-face-edit-fix-value
2810 :match
(lambda (widget value
)
2811 (widget-checklist-match widget
2812 (custom-face-edit-fix-value widget value
)))
2813 :convert-widget
'custom-face-edit-convert-widget
2814 :args
(mapcar (lambda (att)
2817 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
2818 (list 'const
:format
"" :value
(nth 0 att
))
2820 custom-face-attributes
))
2822 (defun custom-face-edit-fix-value (widget value
)
2823 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
2824 Also change :reverse-video to :inverse-video."
2828 (let ((key (car value
))
2829 (val (car (cdr value
))))
2830 (cond ((eq key
:italic
)
2831 (push :slant result
)
2832 (push (if val
'italic
'normal
) result
))
2834 (push :weight result
)
2835 (push (if val
'bold
'normal
) result
))
2836 ((eq key
:reverse-video
)
2837 (push :inverse-video result
)
2841 (push val result
))))
2842 (setq value
(cdr (cdr value
))))
2843 (setq result
(nreverse result
))
2847 (defun custom-face-edit-convert-widget (widget)
2848 "Convert :args as widget types in WIDGET."
2851 :args
(mapcar (lambda (arg)
2853 :deactivate
'custom-face-edit-deactivate
2854 :activate
'custom-face-edit-activate
2855 :delete
'custom-face-edit-delete
))
2856 (widget-get widget
:args
)))
2859 (defun custom-face-edit-deactivate (widget)
2860 "Make face widget WIDGET inactive for user modifications."
2861 (unless (widget-get widget
:inactive
)
2862 (let ((tag (custom-face-edit-attribute-tag widget
))
2863 (from (copy-marker (widget-get widget
:from
)))
2864 (value (widget-value widget
))
2865 (inhibit-read-only t
)
2866 (inhibit-modification-hooks t
))
2869 (widget-default-delete widget
)
2870 (insert tag
": *\n")
2871 (widget-put widget
:inactive
2872 (cons value
(cons from
(- (point) from
))))))))
2874 (defun custom-face-edit-activate (widget)
2875 "Make face widget WIDGET inactive for user modifications."
2876 (let ((inactive (widget-get widget
:inactive
))
2877 (inhibit-read-only t
)
2878 (inhibit-modification-hooks t
))
2879 (when (consp inactive
)
2881 (goto-char (car (cdr inactive
)))
2882 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
2883 (widget-put widget
:inactive nil
)
2884 (widget-apply widget
:create
)
2885 (widget-value-set widget
(car inactive
))
2888 (defun custom-face-edit-delete (widget)
2889 "Remove WIDGET from the buffer."
2890 (let ((inactive (widget-get widget
:inactive
))
2891 (inhibit-read-only t
)
2892 (inhibit-modification-hooks t
))
2894 ;; Widget is alive, we don't have to do anything special
2895 (widget-default-delete widget
)
2896 ;; WIDGET is already deleted because we did so to inactivate it;
2897 ;; now just get rid of the label we put in its place.
2898 (delete-region (car (cdr inactive
))
2899 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
2900 (widget-put widget
:inactive nil
))))
2903 (defun custom-face-edit-attribute-tag (widget)
2904 "Returns the first :tag property in WIDGET or one of its children."
2905 (let ((tag (widget-get widget
:tag
)))
2906 (or (and (not (equal tag
"")) tag
)
2907 (let ((children (widget-get widget
:children
)))
2908 (while (and (null tag
) children
)
2909 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
2912 ;;; The `custom-display' Widget.
2914 (define-widget 'custom-display
'menu-choice
2915 "Select a display type."
2918 :help-echo
"Specify frames where the face attributes should be used."
2919 :args
'((const :tag
"all" t
)
2920 (const :tag
"defaults" default
)
2924 :args
((group :sibling-args
(:help-echo
"\
2925 Only match the specified window systems.")
2926 (const :format
"Type: "
2928 (checklist :inline t
2931 :sibling-args
(:help-echo
"\
2932 The X11 Window System.")
2934 (const :format
"PM "
2935 :sibling-args
(:help-echo
"\
2936 OS/2 Presentation Manager.")
2938 (const :format
"W32 "
2939 :sibling-args
(:help-echo
"\
2942 (const :format
"MAC "
2943 :sibling-args
(:help-echo
"\
2946 (const :format
"DOS "
2947 :sibling-args
(:help-echo
"\
2950 (const :format
"TTY%n"
2951 :sibling-args
(:help-echo
"\
2952 Plain text terminals.")
2954 (group :sibling-args
(:help-echo
"\
2955 Only match the frames with the specified color support.")
2956 (const :format
"Class: "
2958 (checklist :inline t
2960 (const :format
"Color "
2961 :sibling-args
(:help-echo
"\
2962 Match color frames.")
2964 (const :format
"Grayscale "
2965 :sibling-args
(:help-echo
"\
2966 Match grayscale frames.")
2968 (const :format
"Monochrome%n"
2969 :sibling-args
(:help-echo
"\
2970 Match frames with no color support.")
2972 (group :sibling-args
(:help-echo
"\
2973 The minimum number of colors the frame should support.")
2974 (const :format
"" min-colors
)
2975 (integer :tag
"Minimum number of colors" ))
2976 (group :sibling-args
(:help-echo
"\
2977 Only match frames with the specified intensity.")
2979 Background brightness: "
2981 (checklist :inline t
2983 (const :format
"Light "
2984 :sibling-args
(:help-echo
"\
2985 Match frames with light backgrounds.")
2987 (const :format
"Dark\n"
2988 :sibling-args
(:help-echo
"\
2989 Match frames with dark backgrounds.")
2991 (group :sibling-args
(:help-echo
"\
2992 Only match frames that support the specified face attributes.")
2993 (const :format
"Supports attributes:" supports
)
2994 (custom-face-edit :inline t
:format
"%n%v"))))))
2996 ;;; The `custom-face' Widget.
2998 (defface custom-face-tag
2999 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3000 "Face used for face tags."
3001 :group
'custom-faces
)
3002 ;; backward-compatibility alias
3003 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3005 (defcustom custom-face-default-form
'selected
3006 "Default form of displaying face definition."
3007 :type
'(choice (const all
)
3010 :group
'custom-buffer
3013 (define-widget 'custom-face
'custom
3015 :sample-face
'custom-face-tag-face
3016 :help-echo
"Set or reset this face."
3017 :documentation-property
#'face-doc-string
3018 :value-create
'custom-face-value-create
3019 :action
'custom-face-action
3020 :custom-category
'face
3021 :custom-form nil
; defaults to value of `custom-face-default-form'
3022 :custom-set
'custom-face-set
3023 :custom-save
'custom-face-save
3024 :custom-reset-current
'custom-redraw
3025 :custom-reset-saved
'custom-face-reset-saved
3026 :custom-reset-standard
'custom-face-reset-standard
3027 :custom-standard-value
'custom-face-standard-value
3028 :custom-menu
'custom-face-menu-create
)
3030 (define-widget 'custom-face-all
'editable-list
3031 "An editable list of display specifications and attributes."
3032 :entry-format
"%i %d %v"
3033 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3034 :append-button-args
'(:help-echo
"Append new display specification here.")
3035 :delete-button-args
'(:help-echo
"Delete this display specification.")
3036 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3038 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3039 "Converted version of the `custom-face-all' widget.")
3041 (define-widget 'custom-display-unselected
'item
3042 "A display specification that doesn't match the selected display."
3043 :match
'custom-display-unselected-match
)
3045 (defun custom-display-unselected-match (widget value
)
3046 "Non-nil if VALUE is an unselected display specification."
3047 (not (face-spec-set-match-display value
(selected-frame))))
3049 (define-widget 'custom-face-selected
'group
3050 "Edit the attributes of the selected display in a face specification."
3051 :args
'((choice :inline t
3052 (group :tag
"With Defaults" :inline t
3053 (group (const :tag
"" default
)
3054 (custom-face-edit :tag
" Default\n Attributes"))
3057 (group custom-display-unselected sexp
))
3058 (group (sexp :format
"")
3059 (custom-face-edit :tag
" Overriding\n Attributes"))
3063 (group :tag
"No Defaults" :inline t
3066 (group custom-display-unselected sexp
))
3067 (group (sexp :format
"")
3068 (custom-face-edit :tag
"\n Attributes"))
3075 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3076 "Converted version of the `custom-face-selected' widget.")
3078 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3079 "Return a canonicalized version of SPEC using.
3080 FILTER-INDEX is the index in the entry for each attribute in
3081 `custom-face-attributes' at which the appropriate filter function can be
3082 found, and DEFAULT-FILTER is the filter to apply for attributes that
3084 (mapcar (lambda (entry)
3085 ;; Filter a single face-spec entry
3086 (let ((tests (car entry
))
3088 ;; Handle both old- and new-style attribute syntax
3089 (if (listp (car (cdr entry
)))
3092 (filtered-attrs nil
))
3093 ;; Filter each face attribute
3094 (while unfiltered-attrs
3095 (let* ((attr (pop unfiltered-attrs
))
3096 (pre-filtered-value (pop unfiltered-attrs
))
3098 (or (nth filter-index
(assq attr custom-face-attributes
))
3102 (funcall filter pre-filtered-value
)
3103 pre-filtered-value
)))
3104 (push filtered-value filtered-attrs
)
3105 (push attr filtered-attrs
)))
3107 (list tests filtered-attrs
)))
3110 (defun custom-pre-filter-face-spec (spec)
3111 "Return SPEC changed as necessary for editing by the face customization widget.
3112 SPEC must be a full face spec."
3113 (custom-filter-face-spec spec
2))
3115 (defun custom-post-filter-face-spec (spec)
3116 "Return the customized SPEC in a form suitable for setting the face."
3117 (custom-filter-face-spec spec
3))
3119 (defun custom-face-value-create (widget)
3120 "Create a list of the display specifications for WIDGET."
3121 (let ((buttons (widget-get widget
:buttons
))
3123 (symbol (widget-get widget
:value
))
3124 (tag (widget-get widget
:tag
))
3125 (state (widget-get widget
:custom-state
))
3127 (is-last (widget-get widget
:custom-last
))
3128 (prefix (widget-get widget
:custom-prefix
)))
3130 (setq tag
(prin1-to-string symbol
)))
3131 (cond ((eq custom-buffer-style
'tree
)
3132 (insert prefix
(if is-last
" `--- " " |--- "))
3133 (push (widget-create-child-and-convert
3134 widget
'custom-browse-face-tag
)
3136 (insert " " tag
"\n")
3137 (widget-put widget
:buttons buttons
))
3141 (widget-specify-sample widget begin
(point))
3142 (if (eq custom-buffer-style
'face
)
3144 (if (string-match "face\\'" tag
)
3146 (insert " face: ")))
3148 (push (widget-create-child-and-convert widget
'item
3155 (push (widget-create-child-and-convert
3157 :help-echo
"Hide or show this face."
3160 :action
'custom-toggle-parent
3161 (not (eq state
'hidden
)))
3165 (let ((magic (widget-create-child-and-convert
3166 widget
'custom-magic nil
)))
3167 (widget-put widget
:custom-magic magic
)
3168 (push magic buttons
))
3170 (widget-put widget
:buttons buttons
)
3171 ;; Insert documentation.
3172 (widget-default-format-handler widget ?h
)
3173 ;; The comment field
3174 (unless (eq state
'hidden
)
3175 (let* ((comment (get symbol
'face-comment
))
3177 (widget-create-child-and-convert
3178 widget
'custom-comment
3180 :value
(or comment
""))))
3181 (widget-put widget
:comment-widget comment-widget
)
3182 (push comment-widget children
)))
3184 (unless (eq state
'hidden
)
3185 (when (eq (widget-get widget
:custom-level
) 1)
3186 (custom-add-parent-links widget
))
3187 (custom-add-see-also widget
))
3189 (unless (eq (preceding-char) ?
\n)
3191 (unless (eq state
'hidden
)
3192 (message "Creating face editor...")
3193 (custom-load-widget widget
)
3194 (unless (widget-get widget
:custom-form
)
3195 (widget-put widget
:custom-form custom-face-default-form
))
3196 (let* ((symbol (widget-value widget
))
3197 (spec (or (get symbol
'customized-face
)
3198 (get symbol
'saved-face
)
3199 (get symbol
'face-defface-spec
)
3200 ;; Attempt to construct it.
3201 (list (list t
(custom-face-attributes-get
3202 symbol
(selected-frame))))))
3203 (form (widget-get widget
:custom-form
))
3204 (indent (widget-get widget
:indent
))
3206 ;; If the user has changed this face in some other way,
3207 ;; edit it as the user has specified it.
3208 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3209 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3210 (setq spec
(custom-pre-filter-face-spec spec
))
3211 (setq edit
(widget-create-child-and-convert
3213 (cond ((and (eq form
'selected
)
3214 (widget-apply custom-face-selected
3216 (when indent
(insert-char ?\ indent
))
3217 'custom-face-selected
)
3218 ((and (not (eq form
'lisp
))
3219 (widget-apply custom-face-all
3223 (when indent
(insert-char ?\ indent
))
3226 (custom-face-state-set widget
)
3227 (push edit children
)
3228 (widget-put widget
:children children
))
3229 (message "Creating face editor...done"))))))
3231 (defvar custom-face-menu
3232 `(("Set for Current Session" custom-face-set
)
3233 ,@(when (or custom-file user-init-file
)
3234 '(("Save for Future Sessions" custom-face-save-command
)))
3235 ("Reset to Saved" custom-face-reset-saved
3237 (or (get (widget-value widget
) 'saved-face
)
3238 (get (widget-value widget
) 'saved-face-comment
))))
3239 ,@(when (or custom-file user-init-file
)
3240 '(("Erase Customization" custom-face-reset-standard
3242 (get (widget-value widget
) 'face-defface-spec
)))))
3243 ("---" ignore ignore
)
3244 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3245 ("---" ignore ignore
)
3246 ("Show all display specs" custom-face-edit-all
3248 (not (eq (widget-get widget
:custom-form
) 'all
))))
3249 ("Just current attributes" custom-face-edit-selected
3251 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3252 ("Show as Lisp expression" custom-face-edit-lisp
3254 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3255 "Alist of actions for the `custom-face' widget.
3256 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3257 the menu entry, ACTION is the function to call on the widget when the
3258 menu is selected, and FILTER is a predicate which takes a `custom-face'
3259 widget as an argument, and returns non-nil if ACTION is valid on that
3260 widget. If FILTER is nil, ACTION is always valid.")
3262 (defun custom-face-edit-selected (widget)
3263 "Edit selected attributes of the value of WIDGET."
3264 (widget-put widget
:custom-state
'unknown
)
3265 (widget-put widget
:custom-form
'selected
)
3266 (custom-redraw widget
))
3268 (defun custom-face-edit-all (widget)
3269 "Edit all attributes of the value of WIDGET."
3270 (widget-put widget
:custom-state
'unknown
)
3271 (widget-put widget
:custom-form
'all
)
3272 (custom-redraw widget
))
3274 (defun custom-face-edit-lisp (widget)
3275 "Edit the Lisp representation of the value of WIDGET."
3276 (widget-put widget
:custom-state
'unknown
)
3277 (widget-put widget
:custom-form
'lisp
)
3278 (custom-redraw widget
))
3280 (defun custom-face-state-set (widget)
3281 "Set the state of WIDGET."
3282 (let* ((symbol (widget-value widget
))
3283 (comment (get symbol
'face-comment
))
3287 (setq tmp
(get symbol
'customized-face
))
3288 (setq temp
(get symbol
'customized-face-comment
))
3290 (if (equal temp comment
)
3294 (setq tmp
(get symbol
'saved-face
))
3295 (setq temp
(get symbol
'saved-face-comment
))
3297 (if (equal temp comment
)
3300 ((get symbol
'face-defface-spec
)
3301 (if (equal comment nil
)
3306 ;; If the user called set-face-attribute to change the default
3307 ;; for new frames, this face is "set outside of Customize".
3308 (if (and (not (eq state
'rogue
))
3309 (get symbol
'face-modified
))
3310 (setq state
'changed
))
3311 (widget-put widget
:custom-state state
)))
3313 (defun custom-face-action (widget &optional event
)
3314 "Show the menu for `custom-face' WIDGET.
3315 Optional EVENT is the location for the menu."
3316 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3317 (custom-toggle-hide widget
)
3318 (let* ((completion-ignore-case t
)
3319 (symbol (widget-get widget
:value
))
3320 (answer (widget-choose (concat "Operation on "
3321 (custom-unlispify-tag-name symbol
))
3322 (custom-menu-filter custom-face-menu
3326 (funcall answer widget
)))))
3328 (defun custom-face-set (widget)
3329 "Make the face attributes in WIDGET take effect."
3330 (let* ((symbol (widget-value widget
))
3331 (child (car (widget-get widget
:children
)))
3332 (value (custom-post-filter-face-spec (widget-value child
)))
3333 (comment-widget (widget-get widget
:comment-widget
))
3334 (comment (widget-value comment-widget
)))
3335 (when (equal comment
"")
3337 ;; Make the comment invisible by hand if it's empty
3338 (custom-comment-hide comment-widget
))
3339 (put symbol
'customized-face value
)
3340 (if (face-spec-choose value
)
3341 (face-spec-set symbol value
)
3342 ;; face-set-spec ignores empty attribute lists, so just give it
3343 ;; something harmless instead.
3344 (face-spec-set symbol
'((t :foreground unspecified
))))
3345 (put symbol
'customized-face-comment comment
)
3346 (put symbol
'face-comment comment
)
3347 (custom-face-state-set widget
)
3348 (custom-redraw-magic widget
)))
3350 (defun custom-face-save-command (widget)
3351 "Save in `.emacs' the face attributes in WIDGET."
3352 (custom-face-save widget
)
3355 (defun custom-face-save (widget)
3356 "Prepare for saving WIDGET's face attributes, but don't write `.emacs'."
3357 (let* ((symbol (widget-value widget
))
3358 (child (car (widget-get widget
:children
)))
3359 (value (custom-post-filter-face-spec (widget-value child
)))
3360 (comment-widget (widget-get widget
:comment-widget
))
3361 (comment (widget-value comment-widget
)))
3362 (when (equal comment
"")
3364 ;; Make the comment invisible by hand if it's empty
3365 (custom-comment-hide comment-widget
))
3366 (if (face-spec-choose value
)
3367 (face-spec-set symbol value
)
3368 ;; face-set-spec ignores empty attribute lists, so just give it
3369 ;; something harmless instead.
3370 (face-spec-set symbol
'((t :foreground unspecified
))))
3371 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3372 (put symbol
'saved-face value
))
3373 (custom-push-theme 'theme-face symbol
'user
'set value
)
3374 (put symbol
'customized-face nil
)
3375 (put symbol
'face-comment comment
)
3376 (put symbol
'customized-face-comment nil
)
3377 (put symbol
'saved-face-comment comment
)
3379 (custom-face-state-set widget
)
3380 (custom-redraw-magic widget
)))
3382 (defun custom-face-reset-saved (widget)
3383 "Restore WIDGET to the face's default attributes."
3384 (let* ((symbol (widget-value widget
))
3385 (child (car (widget-get widget
:children
)))
3386 (value (get symbol
'saved-face
))
3387 (comment (get symbol
'saved-face-comment
))
3388 (comment-widget (widget-get widget
:comment-widget
)))
3389 (unless (or value comment
)
3390 (error "No saved value for this face"))
3391 (put symbol
'customized-face nil
)
3392 (put symbol
'customized-face-comment nil
)
3393 (face-spec-set symbol value
)
3394 (put symbol
'face-comment comment
)
3395 (widget-value-set child value
)
3396 ;; This call manages the comment visibility
3397 (widget-value-set comment-widget
(or comment
""))
3398 (custom-face-state-set widget
)
3399 (custom-redraw-magic widget
)))
3401 (defun custom-face-standard-value (widget)
3402 (get (widget-value widget
) 'face-defface-spec
))
3404 (defun custom-face-reset-standard (widget)
3405 "Restore WIDGET to the face's standard attribute values.
3406 This operation eliminates any saved attributes for the face,
3407 restoring it to the state of a face that has never been customized."
3408 (let* ((symbol (widget-value widget
))
3409 (child (car (widget-get widget
:children
)))
3410 (value (get symbol
'face-defface-spec
))
3411 (comment-widget (widget-get widget
:comment-widget
)))
3413 (error "No standard setting for this face"))
3414 (put symbol
'customized-face nil
)
3415 (put symbol
'customized-face-comment nil
)
3416 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3417 (put symbol
'saved-face nil
)
3418 (custom-push-theme 'theme-face symbol
'user
'reset
'standard
)
3419 ;; Do not explictly save resets to standards without themes.
3420 (if (null (cdr (get symbol
'theme-face
)))
3421 (put symbol
'theme-face nil
))
3422 (put symbol
'saved-face-comment nil
)
3424 (face-spec-set symbol value
)
3425 (put symbol
'face-comment nil
)
3426 (widget-value-set child value
)
3427 ;; This call manages the comment visibility
3428 (widget-value-set comment-widget
"")
3429 (custom-face-state-set widget
)
3430 (custom-redraw-magic widget
)))
3432 ;;; The `face' Widget.
3434 (defvar widget-face-prompt-value-history nil
3435 "History of input to `widget-face-prompt-value'.")
3437 (define-widget 'face
'symbol
3438 "A Lisp face name (with sample)."
3439 :format
"%{%t%}: (%{sample%}) %v"
3442 :sample-face-get
'widget-face-sample-face-get
3443 :notify
'widget-face-notify
3444 :match
(lambda (widget value
) (facep value
))
3445 :complete-function
(lambda ()
3447 (lisp-complete-symbol 'facep
))
3448 :prompt-match
'facep
3449 :prompt-history
'widget-face-prompt-value-history
3450 :validate
(lambda (widget)
3451 (unless (facep (widget-value widget
))
3453 :error
(format "Invalid face: %S"
3454 (widget-value widget
)))
3457 (defun widget-face-sample-face-get (widget)
3458 (let ((value (widget-value widget
)))
3463 (defun widget-face-notify (widget child
&optional event
)
3464 "Update the sample, and notify the parent."
3465 (overlay-put (widget-get widget
:sample-overlay
)
3466 'face
(widget-apply widget
:sample-face-get
))
3467 (widget-default-notify widget child event
))
3470 ;;; The `hook' Widget.
3472 (define-widget 'hook
'list
3474 :value-to-internal
(lambda (widget value
)
3475 (if (and value
(symbolp value
))
3478 :match
(lambda (widget value
)
3480 (widget-group-match widget value
)))
3481 ;; Avoid adding undefined functions to the hook, especially for
3482 ;; things like `find-file-hook' or even more basic ones, to avoid
3484 :set
(lambda (symbol value
)
3487 (add-hook symbol elt
))))
3488 :convert-widget
'custom-hook-convert-widget
3491 (defun custom-hook-convert-widget (widget)
3492 ;; Handle `:options'.
3493 (let* ((options (widget-get widget
:options
))
3494 (other `(editable-list :inline t
3495 :entry-format
"%i %d%v"
3496 (function :format
" %v")))
3498 (list `(checklist :inline t
3499 ,@(mapcar (lambda (entry)
3500 `(function-item ,entry
))
3504 (widget-put widget
:args args
)
3507 ;;; The `custom-group-link' Widget.
3509 (define-widget 'custom-group-link
'link
3510 "Show parent in other window when activated."
3511 :help-echo
"Create customization buffer for this group."
3512 :action
'custom-group-link-action
)
3514 (defun custom-group-link-action (widget &rest ignore
)
3515 (customize-group (widget-value widget
)))
3517 ;;; The `custom-group' Widget.
3519 (defcustom custom-group-tag-faces nil
3520 ;; In XEmacs, this ought to play games with font size.
3521 ;; Fixme: make it do so in Emacs.
3522 "Face used for group tags.
3523 The first member is used for level 1 groups, the second for level 2,
3524 and so forth. The remaining group tags are shown with `custom-group-tag'."
3525 :type
'(repeat face
)
3526 :group
'custom-faces
)
3528 (defface custom-group-tag-1
3531 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3532 (((min-colors 88) (class color
)
3534 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3537 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3539 "Face used for group tags."
3540 :group
'custom-faces
)
3541 ;; backward-compatibility alias
3542 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3544 (defface custom-group-tag
3547 (:foreground
"light blue" :weight bold
:height
1.2))
3548 (((min-colors 88) (class color
)
3550 (:foreground
"blue1" :weight bold
:height
1.2))
3553 (:foreground
"blue" :weight bold
:height
1.2))
3555 "Face used for low level group tags."
3556 :group
'custom-faces
)
3557 ;; backward-compatibility alias
3558 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3560 (define-widget 'custom-group
'custom
3563 :sample-face-get
'custom-group-sample-face-get
3564 :documentation-property
'group-documentation
3565 :help-echo
"Set or reset all members of this group."
3566 :value-create
'custom-group-value-create
3567 :action
'custom-group-action
3568 :custom-category
'group
3569 :custom-set
'custom-group-set
3570 :custom-save
'custom-group-save
3571 :custom-reset-current
'custom-group-reset-current
3572 :custom-reset-saved
'custom-group-reset-saved
3573 :custom-reset-standard
'custom-group-reset-standard
3574 :custom-menu
'custom-group-menu-create
)
3576 (defun custom-group-sample-face-get (widget)
3577 ;; Use :sample-face.
3578 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3581 (define-widget 'custom-group-visibility
'visibility
3582 "An indicator and manipulator for hidden group contents."
3583 :create
'custom-group-visibility-create
)
3585 (defun custom-group-visibility-create (widget)
3586 (let ((visible (widget-value widget
)))
3588 (insert "--------")))
3589 (widget-default-create widget
))
3591 (defun custom-group-members (symbol groups-only
)
3592 "Return SYMBOL's custom group members.
3593 If GROUPS-ONLY non-nil, return only those members that are groups."
3594 (if (not groups-only
)
3595 (get symbol
'custom-group
)
3597 (dolist (entry (get symbol
'custom-group
))
3598 (when (eq (nth 1 entry
) 'custom-group
)
3599 (push entry members
)))
3600 (nreverse members
))))
3602 (defun custom-group-value-create (widget)
3603 "Insert a customize group for WIDGET in the current buffer."
3604 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3605 (custom-load-widget widget
))
3606 (let* ((state (widget-get widget
:custom-state
))
3607 (level (widget-get widget
:custom-level
))
3608 ;; (indent (widget-get widget :indent))
3609 (prefix (widget-get widget
:custom-prefix
))
3610 (buttons (widget-get widget
:buttons
))
3611 (tag (widget-get widget
:tag
))
3612 (symbol (widget-value widget
))
3613 (members (custom-group-members symbol
3614 (and (eq custom-buffer-style
'tree
)
3615 custom-browse-only-groups
))))
3616 (cond ((and (eq custom-buffer-style
'tree
)
3618 (or members
(custom-unloaded-widget-p widget
)))
3619 (custom-browse-insert-prefix prefix
)
3620 (push (widget-create-child-and-convert
3621 widget
'custom-browse-visibility
3622 ;; :tag-glyph "plus"
3626 ;; (widget-glyph-insert nil "-- " "horizontal")
3627 (push (widget-create-child-and-convert
3628 widget
'custom-browse-group-tag
)
3630 (insert " " tag
"\n")
3631 (widget-put widget
:buttons buttons
))
3632 ((and (eq custom-buffer-style
'tree
)
3633 (zerop (length members
)))
3634 (custom-browse-insert-prefix prefix
)
3636 ;; (widget-glyph-insert nil "[ ]" "empty")
3637 ;; (widget-glyph-insert nil "-- " "horizontal")
3638 (push (widget-create-child-and-convert
3639 widget
'custom-browse-group-tag
)
3641 (insert " " tag
"\n")
3642 (widget-put widget
:buttons buttons
))
3643 ((eq custom-buffer-style
'tree
)
3644 (custom-browse-insert-prefix prefix
)
3645 (if (zerop (length members
))
3647 (custom-browse-insert-prefix prefix
)
3649 ;; (widget-glyph-insert nil "[ ]" "empty")
3650 ;; (widget-glyph-insert nil "-- " "horizontal")
3651 (push (widget-create-child-and-convert
3652 widget
'custom-browse-group-tag
)
3654 (insert " " tag
"\n")
3655 (widget-put widget
:buttons buttons
))
3656 (push (widget-create-child-and-convert
3657 widget
'custom-browse-visibility
3658 ;; :tag-glyph "minus"
3662 ;; (widget-glyph-insert nil "-\\ " "top")
3663 (push (widget-create-child-and-convert
3664 widget
'custom-browse-group-tag
)
3666 (insert " " tag
"\n")
3667 (widget-put widget
:buttons buttons
)
3668 (message "Creating group...")
3669 (let* ((members (custom-sort-items members
3670 custom-browse-sort-alphabetically
3671 custom-browse-order-groups
))
3672 (prefixes (widget-get widget
:custom-prefixes
))
3673 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3674 (extra-prefix (if (widget-get widget
:custom-last
)
3677 (prefix (concat prefix extra-prefix
))
3680 (setq entry
(car members
)
3681 members
(cdr members
))
3682 (push (widget-create-child-and-convert
3683 widget
(nth 1 entry
)
3685 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3686 :custom-prefixes custom-prefix-list
3687 :custom-level
(1+ level
)
3688 :custom-last
(null members
)
3689 :value
(nth 0 entry
)
3690 :custom-prefix prefix
)
3692 (widget-put widget
:children
(reverse children
)))
3693 (message "Creating group...done")))
3696 ;; Create level indicator.
3697 (unless (eq custom-buffer-style
'links
)
3698 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3701 (let ((begin (point)))
3703 (widget-specify-sample widget begin
(point)))
3705 ;; Create link/visibility indicator.
3706 (if (eq custom-buffer-style
'links
)
3707 (push (widget-create-child-and-convert
3708 widget
'custom-group-link
3712 (push (widget-create-child-and-convert
3713 widget
'custom-group-visibility
3714 :help-echo
"Show members of this group."
3715 :action
'custom-toggle-parent
3716 (not (eq state
'hidden
)))
3719 ;; Create magic button.
3720 (let ((magic (widget-create-child-and-convert
3721 widget
'custom-magic nil
)))
3722 (widget-put widget
:custom-magic magic
)
3723 (push magic buttons
))
3725 (widget-put widget
:buttons buttons
)
3726 ;; Insert documentation.
3727 (if (and (eq custom-buffer-style
'links
) (> level
1))
3728 (widget-put widget
:documentation-indent
0))
3729 (widget-default-format-handler widget ?h
))
3732 ;; Add parent groups references above the group.
3733 (if t
;;; This should test that the buffer
3734 ;;; was made to display a group.
3736 (if (custom-add-parent-links widget
3737 "Go to parent group:")
3739 ;; Create level indicator.
3740 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3743 (let ((start (point)))
3745 (widget-specify-sample widget start
(point)))
3747 ;; Create visibility indicator.
3748 (unless (eq custom-buffer-style
'links
)
3750 (push (widget-create-child-and-convert
3752 :help-echo
"Hide members of this group."
3753 :action
'custom-toggle-parent
3754 (not (eq state
'hidden
)))
3757 ;; Create more dashes.
3758 ;; Use 76 instead of 75 to compensate for the temporary "<"
3759 ;; added by `widget-insert'.
3760 (insert-char ?-
(- 76 (current-column)
3761 (* custom-buffer-indent level
)))
3763 ;; Create magic button.
3764 (let ((magic (widget-create-child-and-convert
3765 widget
'custom-magic
3768 (widget-put widget
:custom-magic magic
)
3769 (push magic buttons
))
3771 (widget-put widget
:buttons buttons
)
3772 ;; Insert documentation.
3773 (widget-default-format-handler widget ?h
)
3775 (if nil
;;; This should test that the buffer
3776 ;;; was not made to display a group.
3778 (insert-char ?\ custom-buffer-indent
)
3779 (custom-add-parent-links widget
)))
3780 (custom-add-see-also widget
3781 (make-string (* custom-buffer-indent level
)
3784 (message "Creating group...")
3785 (let* ((members (custom-sort-items members
3786 custom-buffer-sort-alphabetically
3787 custom-buffer-order-groups
))
3788 (prefixes (widget-get widget
:custom-prefixes
))
3789 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3790 (length (length members
))
3792 (children (mapcar (lambda (entry)
3793 (widget-insert "\n")
3795 Creating group members... %2d%%"
3796 (/ (* 100.0 count
) length
))
3797 (setq count
(1+ count
))
3799 (widget-create-child-and-convert
3800 widget
(nth 1 entry
)
3802 :tag
(custom-unlispify-tag-name
3804 :custom-prefixes custom-prefix-list
3805 :custom-level
(1+ level
)
3806 :value
(nth 0 entry
))
3807 (unless (eq (preceding-char) ?
\n)
3808 (widget-insert "\n"))))
3810 (message "Creating group magic...")
3811 (mapc 'custom-magic-reset children
)
3812 (message "Creating group state...")
3813 (widget-put widget
:children children
)
3814 (custom-group-state-update widget
)
3815 (message "Creating group... done"))
3818 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3819 (insert "\\- " (widget-get widget
:tag
) " group end ")
3820 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
3823 (defvar custom-group-menu
3824 `(("Set for Current Session" custom-group-set
3826 (eq (widget-get widget
:custom-state
) 'modified
)))
3827 ,@(when (or custom-file user-init-file
)
3828 '(("Save for Future Sessions" custom-group-save
3830 (memq (widget-get widget
:custom-state
) '(modified set
))))))
3831 ("Reset to Current" custom-group-reset-current
3833 (memq (widget-get widget
:custom-state
) '(modified))))
3834 ("Reset to Saved" custom-group-reset-saved
3836 (memq (widget-get widget
:custom-state
) '(modified set
))))
3837 ,@(when (or custom-file user-init-file
)
3838 '(("Reset to standard setting" custom-group-reset-standard
3840 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
3841 "Alist of actions for the `custom-group' widget.
3842 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3843 the menu entry, ACTION is the function to call on the widget when the
3844 menu is selected, and FILTER is a predicate which takes a `custom-group'
3845 widget as an argument, and returns non-nil if ACTION is valid on that
3846 widget. If FILTER is nil, ACTION is always valid.")
3848 (defun custom-group-action (widget &optional event
)
3849 "Show the menu for `custom-group' WIDGET.
3850 Optional EVENT is the location for the menu."
3851 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3852 (custom-toggle-hide widget
)
3853 (let* ((completion-ignore-case t
)
3854 (answer (widget-choose (concat "Operation on "
3855 (custom-unlispify-tag-name
3856 (widget-get widget
:value
)))
3857 (custom-menu-filter custom-group-menu
3861 (funcall answer widget
)))))
3863 (defun custom-group-set (widget)
3864 "Set changes in all modified group members."
3865 (let ((children (widget-get widget
:children
)))
3866 (mapc (lambda (child)
3867 (when (eq (widget-get child
:custom-state
) 'modified
)
3868 (widget-apply child
:custom-set
)))
3871 (defun custom-group-save (widget)
3872 "Save all modified group members."
3873 (let ((children (widget-get widget
:children
)))
3874 (mapc (lambda (child)
3875 (when (memq (widget-get child
:custom-state
) '(modified set
))
3876 (widget-apply child
:custom-save
)))
3879 (defun custom-group-reset-current (widget)
3880 "Reset all modified group members."
3881 (let ((children (widget-get widget
:children
)))
3882 (mapc (lambda (child)
3883 (when (eq (widget-get child
:custom-state
) 'modified
)
3884 (widget-apply child
:custom-reset-current
)))
3887 (defun custom-group-reset-saved (widget)
3888 "Reset all modified or set group members."
3889 (let ((children (widget-get widget
:children
)))
3890 (mapc (lambda (child)
3891 (when (memq (widget-get child
:custom-state
) '(modified set
))
3892 (widget-apply child
:custom-reset-saved
)))
3895 (defun custom-group-reset-standard (widget)
3896 "Reset all modified, set, or saved group members."
3897 (let ((children (widget-get widget
:children
)))
3898 (mapc (lambda (child)
3899 (when (memq (widget-get child
:custom-state
)
3900 '(modified set saved
))
3901 (widget-apply child
:custom-reset-standard
)))
3904 (defun custom-group-state-update (widget)
3906 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3907 (let* ((children (widget-get widget
:children
))
3908 (states (mapcar (lambda (child)
3909 (widget-get child
:custom-state
))
3911 (magics custom-magic-alist
)
3914 (let ((magic (car (car magics
))))
3915 (if (and (not (eq magic
'hidden
))
3916 (memq magic states
))
3919 (setq magics
(cdr magics
)))))
3920 (widget-put widget
:custom-state found
)))
3921 (custom-magic-reset widget
))
3923 ;;; Reading and writing the custom file.
3926 (defcustom custom-file nil
3927 "File used for storing customization information.
3928 The default is nil, which means to use your init file
3929 as specified by `user-init-file'. If the value is not nil,
3930 it should be an absolute file name.
3932 You can set this option through Custom, if you carefully read the
3933 last paragraph below. However, usually it is simpler to write
3934 something like the following in your init file:
3936 \(setq custom-file \"~/.emacs-custom.el\")
3939 Note that both lines are necessary: the first line tells Custom to
3940 save all customizations in this file, but does not load it.
3942 When you change this variable outside Custom, look in the
3943 previous custom file \(usually your init file) for the
3944 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
3945 and copy them (whichever ones you find) to the new custom file.
3946 This will preserve your existing customizations.
3948 If you save this option using Custom, Custom will write all
3949 currently saved customizations, including the new one for this
3950 option itself, into the file you specify, overwriting any
3951 `custom-set-variables' and `custom-set-faces' forms already
3952 present in that file. It will not delete any customizations from
3953 the old custom file. You should do that manually if that is what you
3954 want. You also have to put something like `\(load \"CUSTOM-FILE\")
3955 in your init file, where CUSTOM-FILE is the actual name of the
3956 file. Otherwise, Emacs will not load the file when it starts up,
3957 and hence will not set `custom-file' to that file either."
3958 :type
'(choice (const :tag
"Your Emacs init file" nil
)
3959 (file :format
"%t:%v%d"
3961 "Please read entire docstring below before setting \
3962 this through Custom.
3963 Click om \"More\" \(or position point there and press RETURN)
3964 if only the first line of the docstring is shown."))
3967 (defun custom-file ()
3968 "Return the file name for saving customizations."
3971 (let ((user-init-file user-init-file
)
3973 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
3974 (when (null user-init-file
)
3975 (if (or (file-exists-p default-init-file
)
3976 (and (eq system-type
'windows-nt
)
3977 (file-exists-p "~/_emacs")))
3978 ;; Started with -q, i.e. the file containing
3979 ;; Custom settings hasn't been read. Saving
3980 ;; settings there would overwrite other settings.
3981 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
3982 (setq user-init-file default-init-file
))
3986 (defun custom-save-all ()
3987 "Save all customizations in `custom-file'."
3988 (let* ((filename (custom-file))
3989 (recentf-exclude (if recentf-mode
3991 (regexp-quote (custom-file))
3994 (old-buffer (find-buffer-visiting filename
)))
3995 (with-current-buffer (or old-buffer
(find-file-noselect filename
))
3996 (let ((inhibit-read-only t
))
3997 (custom-save-variables)
3998 (custom-save-faces))
3999 (let ((file-precious-flag t
))
4002 (kill-buffer (current-buffer))))))
4004 ;; Editing the custom file contents in a buffer.
4006 (defun custom-save-delete (symbol)
4007 "Delete all calls to SYMBOL from the contents of the current buffer.
4008 Leave point at the old location of the first such call,
4009 or (if there were none) at the end of the buffer.
4011 This function does not save the buffer."
4012 (goto-char (point-min))
4013 ;; Skip all whitespace and comments.
4014 (while (forward-comment 1))
4016 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4019 (while t
;; We exit this loop only via throw.
4020 ;; Skip all whitespace and comments.
4021 (while (forward-comment 1))
4022 (let ((start (point))
4023 (sexp (condition-case nil
4024 (read (current-buffer))
4025 (end-of-file (throw 'found nil
)))))
4026 (when (and (listp sexp
)
4027 (eq (car sexp
) symbol
))
4028 (delete-region start
(point))
4030 (setq first
(point)))))))
4033 ;; Move in front of local variables, otherwise long Custom
4034 ;; entries would make them ineffective.
4035 (let ((pos (point-max))
4036 (case-fold-search t
))
4038 (goto-char (point-max))
4039 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4041 (when (search-forward "Local Variables:" nil t
)
4042 (setq pos
(line-beginning-position))))
4045 (defun custom-save-variables ()
4046 "Save all customized variables in `custom-file'."
4048 (custom-save-delete 'custom-load-themes
)
4049 (custom-save-delete 'custom-reset-variables
)
4050 (custom-save-delete 'custom-set-variables
)
4051 (custom-save-loaded-themes)
4052 (custom-save-resets 'theme-value
'custom-reset-variables nil
)
4053 (let ((standard-output (current-buffer))
4054 (saved-list (make-list 1 0))
4056 ;; First create a sorted list of saved variables.
4059 (if (get symbol
'saved-value
)
4060 (nconc saved-list
(list symbol
)))))
4061 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4064 (princ "(custom-set-variables
4065 ;; custom-set-variables was added by Custom.
4066 ;; If you edit it by hand, you could mess it up, so be careful.
4067 ;; Your init file should contain only one such instance.
4068 ;; If there is more than one, they won't work right.\n")
4069 (dolist (symbol saved-list
)
4070 (let ((spec (car-safe (get symbol
'theme-value
)))
4071 (value (get symbol
'saved-value
))
4072 (requests (get symbol
'custom-requests
))
4073 (now (not (or (custom-variable-p symbol
)
4074 (and (not (boundp symbol
))
4075 (not (eq (get symbol
'force-value
)
4077 (comment (get symbol
'saved-variable-comment
)))
4078 ;; Check `requests'.
4079 (dolist (request requests
)
4080 (when (and (symbolp request
) (not (featurep request
)))
4081 (message "Unknown requested feature: %s" request
)
4082 (setq requests
(delq request requests
))))
4084 (eq (nth 0 spec
) 'user
)
4085 (eq (nth 1 spec
) 'set
))
4087 (and (null spec
) (get symbol
'saved-value
)))
4094 (when (or now requests comment
)
4097 (when (or requests comment
)
4107 (unless (looking-at "\n")
4110 (defun custom-save-faces ()
4111 "Save all customized faces in `custom-file'."
4113 (custom-save-delete 'custom-reset-faces
)
4114 (custom-save-delete 'custom-set-faces
)
4115 (custom-save-resets 'theme-face
'custom-reset-faces
'(default))
4116 (let ((standard-output (current-buffer))
4117 (saved-list (make-list 1 0))
4119 ;; First create a sorted list of saved faces.
4122 (if (get symbol
'saved-face
)
4123 (nconc saved-list
(list symbol
)))))
4124 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4125 ;; The default face must be first, since it affects the others.
4126 (if (memq 'default saved-list
)
4127 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4130 (princ "(custom-set-faces
4131 ;; custom-set-faces was added by Custom.
4132 ;; If you edit it by hand, you could mess it up, so be careful.
4133 ;; Your init file should contain only one such instance.
4134 ;; If there is more than one, they won't work right.\n")
4135 (dolist (symbol saved-list
)
4136 (let ((spec (car-safe (get symbol
'theme-face
)))
4137 (value (get symbol
'saved-face
))
4138 (now (not (or (get symbol
'face-defface-spec
)
4139 (and (not (custom-facep symbol
))
4140 (not (get symbol
'force-face
))))))
4141 (comment (get symbol
'saved-face-comment
)))
4143 (eq (nth 0 spec
) 'user
)
4144 (eq (nth 1 spec
) 'set
))
4146 (and (null spec
) (get symbol
'saved-face
)))
4147 ;; Don't print default face here.
4154 (when (or now comment
)
4164 (unless (looking-at "\n")
4167 (defun custom-save-resets (property setter special
)
4168 (let (started-writing ignored-special
)
4169 ;; (custom-save-delete setter) Done by caller
4170 (let ((standard-output (current-buffer))
4171 (mapper `(lambda (object)
4172 (let ((spec (car-safe (get object
(quote ,property
)))))
4173 (when (and (not (memq object ignored-special
))
4174 (eq (nth 0 spec
) 'user
)
4175 (eq (nth 1 spec
) 'reset
))
4176 ;; Do not write reset statements unless necessary.
4177 (unless started-writing
4178 (setq started-writing t
)
4182 (princ (quote ,setter
))
4186 (prin1 (nth 3 spec
))
4188 (mapc mapper special
)
4189 (setq ignored-special special
)
4191 (when started-writing
4194 (defun custom-save-loaded-themes ()
4195 (let ((themes (reverse (get 'user
'theme-loads-themes
)))
4196 (standard-output (current-buffer)))
4198 (unless (bolp) (princ "\n"))
4199 (princ "(custom-load-themes")
4200 (mapc (lambda (theme)
4202 (prin1 theme
)) themes
)
4206 (defun customize-save-customized ()
4207 "Save all user options which have been set in this session."
4209 (mapatoms (lambda (symbol)
4210 (let ((face (get symbol
'customized-face
))
4211 (value (get symbol
'customized-value
))
4212 (face-comment (get symbol
'customized-face-comment
))
4214 (get symbol
'customized-variable-comment
)))
4216 (put symbol
'saved-face face
)
4217 (custom-push-theme 'theme-face symbol
'user
'set value
)
4218 (put symbol
'customized-face nil
))
4220 (put symbol
'saved-value value
)
4221 (custom-push-theme 'theme-value symbol
'user
'set value
)
4222 (put symbol
'customized-value nil
))
4223 (when variable-comment
4224 (put symbol
'saved-variable-comment variable-comment
)
4225 (put symbol
'customized-variable-comment nil
))
4227 (put symbol
'saved-face-comment face-comment
)
4228 (put symbol
'customized-face-comment nil
)))))
4229 ;; We really should update all custom buffers here.
4232 ;;; The Customize Menu.
4236 (defcustom custom-menu-nesting
2
4237 "Maximum nesting in custom menus."
4239 :group
'custom-menu
)
4241 (defun custom-face-menu-create (widget symbol
)
4242 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4243 (vector (custom-unlispify-menu-entry symbol
)
4244 `(customize-face ',symbol
)
4247 (defun custom-variable-menu-create (widget symbol
)
4248 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4249 (let ((type (get symbol
'custom-type
)))
4250 (unless (listp type
)
4251 (setq type
(list type
)))
4252 (if (and type
(widget-get type
:custom-menu
))
4253 (widget-apply type
:custom-menu symbol
)
4254 (vector (custom-unlispify-menu-entry symbol
)
4255 `(customize-variable ',symbol
)
4258 ;; Add checkboxes to boolean variable entries.
4259 (widget-put (get 'boolean
'widget-type
)
4260 :custom-menu
(lambda (widget symbol
)
4261 (vector (custom-unlispify-menu-entry symbol
)
4262 `(customize-variable ',symbol
)
4264 ':selected symbol
)))
4266 (defun custom-group-menu-create (widget symbol
)
4267 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4268 `( ,(custom-unlispify-menu-entry symbol t
)
4269 :filter
(lambda (&rest junk
)
4270 (let ((menu (custom-menu-create ',symbol
)))
4271 (if (consp menu
) (cdr menu
) menu
)))))
4274 (defun custom-menu-create (symbol)
4275 "Create menu for customization group SYMBOL.
4276 The menu is in a format applicable to `easy-menu-define'."
4277 (let* ((item (vector (custom-unlispify-menu-entry symbol
)
4278 `(customize-group ',symbol
)
4280 (if (and (or (not (boundp 'custom-menu-nesting
))
4281 (>= custom-menu-nesting
0))
4283 (custom-load-symbol symbol
)
4284 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4285 (let ((custom-prefix-list (custom-prefix-add symbol
4286 custom-prefix-list
))
4287 (members (custom-sort-items (get symbol
'custom-group
)
4288 custom-menu-sort-alphabetically
4289 custom-menu-order-groups
)))
4290 `(,(custom-unlispify-menu-entry symbol t
)
4293 ,@(mapcar (lambda (entry)
4294 (widget-apply (if (listp (nth 1 entry
))
4296 (list (nth 1 entry
)))
4297 :custom-menu
(nth 0 entry
)))
4302 (defun customize-menu-create (symbol &optional name
)
4303 "Return a customize menu for customization group SYMBOL.
4304 If optional NAME is given, use that as the name of the menu.
4305 Otherwise the menu will be named `Customize'.
4306 The format is suitable for use with `easy-menu-define'."
4308 (setq name
"Customize"))
4310 :filter
(lambda (&rest junk
)
4311 (let ((menu (custom-menu-create ',symbol
)))
4312 (if (consp menu
) (cdr menu
) menu
)))))
4314 ;;; The Custom Mode.
4316 (defvar custom-mode-map
4317 ;; This keymap should be dense, but a dense keymap would prevent inheriting
4318 ;; "\r" bindings from the parent map.
4319 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
4320 (let ((map (make-keymap)))
4321 (set-keymap-parent map widget-keymap
)
4322 (suppress-keymap map
)
4323 (define-key map
" " 'scroll-up
)
4324 (define-key map
"\177" 'scroll-down
)
4325 (define-key map
"\C-c\C-c" 'Custom-set
)
4326 (define-key map
"\C-x\C-s" 'Custom-save
)
4327 (define-key map
"q" 'Custom-buffer-done
)
4328 (define-key map
"u" 'Custom-goto-parent
)
4329 (define-key map
"n" 'widget-forward
)
4330 (define-key map
"p" 'widget-backward
)
4331 (define-key map
[mouse-1
] 'widget-move-and-invoke
)
4333 "Keymap for `custom-mode'.")
4335 (easy-menu-define Custom-mode-menu
4337 "Menu used in customization buffers."
4339 ,(customize-menu-create 'customize
)
4340 ["Set" Custom-set t
]
4341 ["Save" Custom-save t
]
4342 ["Reset to Current" Custom-reset-current t
]
4343 ["Reset to Saved" Custom-reset-saved t
]
4344 ["Reset to Standard Values" Custom-reset-standard t
]
4345 ["Info" (info "(emacs)Easy Customization") t
]))
4347 (defun Custom-goto-parent ()
4348 "Go to the parent group listed at the top of this buffer.
4349 If several parents are listed, go to the first of them."
4352 (goto-char (point-min))
4353 (if (search-forward "\nGo to parent group: " nil t
)
4354 (let* ((button (get-char-property (point) 'button
))
4355 (parent (downcase (widget-get button
:tag
))))
4356 (customize-group parent
)))))
4358 (defcustom custom-mode-hook nil
4359 "Hook called when entering Custom mode."
4361 :group
'custom-buffer
)
4363 (defun custom-state-buffer-message (widget)
4364 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4365 (message "To install your edits, invoke [State] and choose the Set operation")))
4367 (defun custom-mode ()
4368 "Major mode for editing customization buffers.
4370 The following commands are available:
4372 Move to next button or editable field. \\[widget-forward]
4373 Move to previous button or editable field. \\[widget-backward]
4374 \\<widget-field-keymap>\
4375 Complete content of editable text field. \\[widget-complete]
4376 \\<custom-mode-map>\
4377 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
4378 Invoke button under point. \\[widget-button-press]
4379 Set all modifications. \\[Custom-set]
4380 Make all modifications default. \\[Custom-save]
4381 Reset all modified options. \\[Custom-reset-current]
4382 Reset all modified or set options. \\[Custom-reset-saved]
4383 Reset all options. \\[Custom-reset-standard]
4385 Entry to this mode calls the value of `custom-mode-hook'
4386 if that value is non-nil."
4387 (kill-all-local-variables)
4388 (setq major-mode
'custom-mode
4390 (use-local-map custom-mode-map
)
4391 (easy-menu-add Custom-mode-menu
)
4392 (make-local-variable 'custom-options
)
4393 (make-local-variable 'custom-local-buffer
)
4394 (make-local-variable 'widget-documentation-face
)
4395 (setq widget-documentation-face
'custom-documentation
)
4396 (make-local-variable 'widget-button-face
)
4397 (setq widget-button-face custom-button
)
4398 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4399 (if custom-raised-buttons
4400 (set (make-local-variable 'widget-mouse-face
) custom-button
))
4402 ;; When possible, use relief for buttons, not bracketing. This test
4403 ;; may not be optimal.
4404 (when custom-raised-buttons
4405 (set (make-local-variable 'widget-push-button-prefix
) "")
4406 (set (make-local-variable 'widget-push-button-suffix
) "")
4407 (set (make-local-variable 'widget-link-prefix
) "")
4408 (set (make-local-variable 'widget-link-suffix
) ""))
4409 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
)
4410 (run-mode-hooks 'custom-mode-hook
))
4412 (put 'custom-mode
'mode-class
'special
)
4415 'debug-ignored-errors
4416 "^No user options have changed defaults in recent Emacs versions$")
4422 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4423 ;;; cus-edit.el ends here