1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996-1997, 1999-2011 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; 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 3 of the License, or
15 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file implements the code to create and edit customize buffers.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
35 ;; The identity of a customize option is represented by a Lisp symbol.
36 ;; The following values are associated with an option.
38 ;; 0. The current value.
40 ;; This is the value of the option as seen by "the rest of Emacs".
42 ;; Usually extracted by 'default-value', but can be extracted with
43 ;; different means if the option symbol has the 'custom-get'
44 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; 1. The widget value.
49 ;; This is the value shown in the widget in a customize buffer.
51 ;; 2. The customized value.
53 ;; This is the last value given to the option through customize.
55 ;; It is stored in the 'customized-value' property of the option, in a
56 ;; cons-cell whose car evaluates to the customized value.
58 ;; 3. The saved value.
60 ;; This is last value saved from customize.
62 ;; It is stored in the 'saved-value' property of the option, in a
63 ;; cons-cell whose car evaluates to the saved value.
65 ;; 4. The standard value.
67 ;; This is the value given in the 'defcustom' declaration.
69 ;; It is stored in the 'standard-value' property of the option, in a
70 ;; cons-cell whose car evaluates to the standard value.
72 ;; 5. The "think" value.
74 ;; This is what customize thinks the current value should be.
76 ;; This is the customized value, if any such value exists, otherwise
77 ;; the saved value, if that exists, and as a last resort the standard
80 ;; The reason for storing values unevaluated: This is so you can have
81 ;; values that depend on the environment. For example, you can have a
82 ;; variable that has one value when Emacs is running under a window
83 ;; system, and another value on a tty. Since the evaluation is only done
84 ;; when the variable is first initialized, this is only relevant for the
85 ;; saved (and standard) values, but affect others values for
88 ;; You can see (and modify and save) this unevaluated value by selecting
89 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
90 ;; give you the unevaluated saved value, if any, otherwise the
91 ;; unevaluated standard value.
93 ;; The possible states for a customize widget are:
97 ;; The state has not been determined yet.
101 ;; The widget value is different from the current value.
105 ;; The current value is different from the "think" value.
109 ;; The "think" value is the customized value.
113 ;; The "think" value is the saved value.
117 ;; The "think" value is the standard value.
121 ;; There is no standard value. This means that the variable was
122 ;; not defined with defcustom, nor handled in cus-start.el. Most
123 ;; standard interactive Custom commands do not let you create a
124 ;; Custom buffer containing such variables. However, such Custom
125 ;; buffers can be created, for instance, by calling
126 ;; `customize-apropos' with a prefix arg or by calling
127 ;; `customize-option' non-interactively.
131 ;; There is no widget value.
135 ;; The widget value is not valid member of the :type specified for the
143 (defvar custom-versions-load-alist
) ; from cus-load
144 (defvar recentf-exclude
) ; from recentf.el
154 (put 'custom-define-hook
'custom-type
'hook
)
155 (put 'custom-define-hook
'standard-value
'(nil))
156 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link
'(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
169 (defgroup convenience nil
170 "Convenience features for faster editing."
174 "Support for editing files."
178 "Support for editing text files."
183 "Support for editing binary data files."
187 "Abbreviation handling, typing shortcuts, macros."
191 (defgroup matching nil
192 "Various sorts of searching and matching."
195 (defgroup emulations nil
196 "Emulations of other editors."
197 :link
'(custom-manual "(emacs)Emulation")
204 (defgroup outlines nil
205 "Support for hierarchical outlining."
208 (defgroup external nil
209 "Interfacing to external utilities."
213 "Communications, networking, and remote access to files."
217 (defgroup processes nil
218 "Process, subshell, compilation, and job control support."
221 (defgroup programming nil
222 "Support for programming in other languages."
225 (defgroup languages nil
226 "Specialized modes for editing programming languages."
230 "Lisp support, including Emacs Lisp."
231 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
236 "Support for the C language and related languages."
237 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
238 :link
'(custom-manual "(ccmode)")
245 (defgroup applications nil
246 "Applications written in Emacs."
249 (defgroup calendar nil
250 "Calendar and time management support."
251 :group
'applications
)
254 "Modes for electronic-mail handling."
255 :group
'applications
)
258 "Support for netnews reading and posting."
259 :link
'(custom-manual "(gnus)")
260 :group
'applications
)
263 "Games, jokes and amusements."
264 :group
'applications
)
266 (defgroup development nil
267 "Support for further development of Emacs."
271 "Support for Emacs documentation."
274 (defgroup extensions nil
275 "Emacs Lisp language extensions."
278 (defgroup internal nil
279 "Code for Emacs internals, build process, defaults."
283 "Maintenance aids for the Emacs development group."
287 (defgroup environment nil
288 "Fitting Emacs with its environment."
291 (defgroup hardware nil
292 "Support for interfacing with miscellaneous hardware."
295 (defgroup terminals nil
296 "Support for terminal types."
300 "Front-ends/assistants for, or emulators of, UNIX features."
304 "Internationalization and alternate character-set support."
305 :link
'(custom-manual "(emacs)International")
310 "The X Window system."
314 "Support for Emacs frames and window systems."
318 "Code related to the TeX formatter."
319 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
323 "Support for multiple fonts."
327 "Support for on-line help systems."
330 (defgroup multimedia nil
331 "Non-textual support, specifically images and sound."
335 "Code local to your site."
338 (defgroup customize
'((widgets custom-group
))
339 "Customization of the Customization support."
343 (defgroup custom-faces nil
344 "Faces used by customize."
348 (defgroup custom-browse nil
349 "Control customize browser."
353 (defgroup custom-buffer nil
354 "Control customize buffers."
358 (defgroup custom-menu nil
359 "Control customize menus."
364 "Storage allocation and gc for GNU Emacs Lisp interpreter."
365 :tag
"Storage Allocation"
369 "Undoing changes in buffers."
370 :link
'(custom-manual "(emacs)Undo")
373 (defgroup mode-line nil
374 "Content of the modeline."
377 (defgroup editing-basics nil
378 "Most basic editing facilities."
381 (defgroup display nil
382 "How characters are displayed in buffers."
385 (defgroup execute nil
386 "Executing external commands."
389 (defgroup installation nil
390 "The Emacs installation."
398 "Internal Emacs limits."
402 "Debugging Emacs itself."
405 (defgroup keyboard nil
406 "Input from the keyboard."
410 "Input from the mouse."
414 "Input from the menus."
418 "Handling data from drag and drop."
421 (defgroup auto-save nil
422 "Preventing accidental loss of data."
425 (defgroup processes-basics nil
426 "Basic stuff dealing with processes."
430 "MULE Emacs internationalization."
433 (defgroup windows nil
434 "Windows within a frame."
435 :link
'(custom-manual "(emacs)Windows")
438 ;;; Custom mode keymaps
440 (defvar custom-mode-map
441 (let ((map (make-keymap)))
442 (set-keymap-parent map widget-keymap
)
443 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
444 (define-key map
"\^m" 'Custom-newline
)
445 (define-key map
" " 'scroll-up
)
446 (define-key map
"\177" 'scroll-down
)
447 (define-key map
"\C-c\C-c" 'Custom-set
)
448 (define-key map
"\C-x\C-s" 'Custom-save
)
449 (define-key map
"q" 'Custom-buffer-done
)
450 (define-key map
"u" 'Custom-goto-parent
)
451 (define-key map
"n" 'widget-forward
)
452 (define-key map
"p" 'widget-backward
)
454 "Keymap for `Custom-mode'.")
456 (defvar custom-mode-link-map
457 (let ((map (make-keymap)))
458 (set-keymap-parent map custom-mode-map
)
459 (define-key map
[down-mouse-2
] nil
)
460 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
461 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
463 "Local keymap for links in `Custom-mode'.")
465 (defvar custom-field-keymap
466 (let ((map (copy-keymap widget-field-keymap
)))
467 (define-key map
"\C-c\C-c" 'Custom-set
)
468 (define-key map
"\C-x\C-s" 'Custom-save
)
470 "Keymap used inside editable fields in customization buffers.")
472 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
476 (defun custom-split-regexp-maybe (regexp)
477 "If REGEXP is a string, split it to a list at `\\|'.
478 You can get the original back from the result with:
479 (mapconcat 'identity result \"\\|\")
481 IF REGEXP is not a string, return it unchanged."
483 (split-string regexp
"\\\\|")
486 (defun custom-variable-prompt ()
487 "Prompt for a custom variable, defaulting to the variable at point.
488 Return a list suitable for use in `interactive'."
489 (let* ((v (variable-at-point))
490 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
491 (enable-recursive-minibuffers t
)
493 (setq val
(completing-read
494 (if default
(format "Customize variable (default %s): " default
)
495 "Customize variable: ")
496 obarray
'custom-variable-p t nil nil default
))
497 (list (if (equal val
"")
498 (if (symbolp v
) v nil
)
501 (defun custom-menu-filter (menu widget
)
502 "Convert MENU to the form used by `widget-choose'.
503 MENU should be in the same format as `custom-variable-menu'.
504 WIDGET is the widget to apply the filter entries of MENU on."
506 current name action filter
)
508 (setq current
(car menu
)
510 action
(nth 1 current
)
511 filter
(nth 2 current
)
513 (if (or (null filter
) (funcall filter widget
))
514 (push (cons name action
) result
)
520 (defvar custom-prefix-list nil
521 "List of prefixes that should be ignored by `custom-unlispify'.")
523 (defcustom custom-unlispify-menu-entries t
524 "Display menu entries as words instead of symbols if non-nil."
528 (defcustom custom-unlispify-remove-prefixes nil
529 "Non-nil means remove group prefixes from option names in buffer."
531 :group
'custom-buffer
534 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
535 "Convert SYMBOL into a menu entry."
536 (cond ((not custom-unlispify-menu-entries
)
537 (symbol-name symbol
))
538 ((get symbol
'custom-tag
)
540 (get symbol
'custom-tag
)
541 (concat (get symbol
'custom-tag
) "...")))
543 (with-current-buffer (get-buffer-create " *Custom-Work*")
545 (princ symbol
(current-buffer))
546 (goto-char (point-min))
547 ;; FIXME: Boolean variables are not predicates, so they shouldn't
548 ;; end with `-p'. -stef
549 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
550 ;; (re-search-forward "-p\\'" nil t))
551 ;; (replace-match "" t t)
552 ;; (goto-char (point-min)))
553 (if custom-unlispify-remove-prefixes
554 (let ((prefixes custom-prefix-list
)
557 (setq prefix
(car prefixes
))
558 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
561 (delete-region (point-min) (point)))
562 (setq prefixes
(cdr prefixes
))))))
563 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
564 (capitalize-region (point-min) (point-max))
566 (goto-char (point-max))
570 (defcustom custom-unlispify-tag-names t
571 "Display tag names as words instead of symbols if non-nil."
572 :group
'custom-buffer
575 (defun custom-unlispify-tag-name (symbol)
576 "Convert SYMBOL into a menu entry."
577 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
578 (custom-unlispify-menu-entry symbol t
)))
580 (defun custom-prefix-add (symbol prefixes
)
581 "Add SYMBOL to list of ignored PREFIXES."
582 (cons (or (get symbol
'custom-prefix
)
583 (concat (symbol-name symbol
) "-"))
588 (defcustom custom-guess-name-alist
594 ("-function\\'" function
)
595 ("-functions\\'" (repeat function
))
596 ("-list\\'" (repeat sexp
))
597 ("-alist\\'" (repeat (cons sexp sexp
))))
598 "Alist of (MATCH TYPE).
600 MATCH should be a regexp matching the name of a symbol, and TYPE should
601 be a widget suitable for editing the value of that symbol. The TYPE
602 of the first entry where MATCH matches the name of the symbol will be
605 This is used for guessing the type of variables not declared with
607 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
608 :group
'custom-buffer
)
610 (defcustom custom-guess-doc-alist
611 '(("\\`\\*?Non-nil " boolean
))
612 "Alist of (MATCH TYPE).
614 MATCH should be a regexp matching a documentation string, and TYPE
615 should be a widget suitable for editing the value of a variable with
616 that documentation string. The TYPE of the first entry where MATCH
617 matches the name of the symbol will be used.
619 This is used for guessing the type of variables not declared with
621 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
622 :group
'custom-buffer
)
624 (defun custom-guess-type (symbol)
625 "Guess a widget suitable for editing the value of SYMBOL.
626 This is done by matching SYMBOL with `custom-guess-name-alist' and
627 if that fails, the doc string with `custom-guess-doc-alist'."
628 (let ((name (symbol-name symbol
))
629 (names custom-guess-name-alist
)
632 (setq current
(car names
)
634 (when (string-match (nth 0 current
) name
)
635 (setq found
(nth 1 current
)
638 (let ((doc (documentation-property symbol
'variable-documentation
))
639 (docs custom-guess-doc-alist
))
642 (setq current
(car docs
)
644 (when (string-match (nth 0 current
) doc
)
645 (setq found
(nth 1 current
)
652 (defcustom custom-browse-sort-alphabetically nil
653 "If non-nil, sort customization group alphabetically in `custom-browse'."
655 :group
'custom-browse
)
657 (defcustom custom-browse-order-groups nil
658 "If non-nil, order group members within each customization group.
659 If `first', order groups before non-groups.
660 If `last', order groups after non-groups."
661 :type
'(choice (const first
)
663 (const :tag
"none" nil
))
664 :group
'custom-browse
)
666 (defcustom custom-browse-only-groups nil
667 "If non-nil, show group members only within each customization group."
669 :group
'custom-browse
)
672 (defcustom custom-buffer-sort-alphabetically t
673 "Whether to sort customization groups alphabetically in Custom buffer."
675 :group
'custom-buffer
678 (defcustom custom-buffer-order-groups
'last
679 "If non-nil, order group members within each customization group.
680 If `first', order groups before non-groups.
681 If `last', order groups after non-groups."
682 :type
'(choice (const first
)
684 (const :tag
"none" nil
))
685 :group
'custom-buffer
)
688 (defcustom custom-menu-sort-alphabetically nil
689 "If non-nil, sort each customization group alphabetically in menus."
693 (defcustom custom-menu-order-groups
'first
694 "If non-nil, order group members within each customization group.
695 If `first', order groups before non-groups.
696 If `last', order groups after non-groups."
697 :type
'(choice (const first
)
699 (const :tag
"none" nil
))
702 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\`\\*Customiz.*\\*\\'"))
704 (defun custom-sort-items (items sort-alphabetically order-groups
)
705 "Return a sorted copy of ITEMS.
706 ITEMS should be a `custom-group' property.
707 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
708 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
709 groups after non-groups, if nil do not order groups at all."
710 (sort (copy-sequence items
)
712 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
713 (namea (nth 0 a
)) (nameb (nth 0 b
)))
714 (cond ((not order-groups
)
715 ;; Since we don't care about A and B order, maybe sort.
716 (when sort-alphabetically
717 (string-lessp namea nameb
)))
718 ((eq typea
'custom-group
)
719 ;; If B is also a group, maybe sort. Otherwise, order A and B.
720 (if (eq typeb
'custom-group
)
721 (when sort-alphabetically
722 (string-lessp namea nameb
))
723 (eq order-groups
'first
)))
724 ((eq typeb
'custom-group
)
725 ;; Since A cannot be a group, order A and B.
726 (eq order-groups
'last
))
728 ;; Since A and B cannot be groups, sort.
729 (string-lessp namea nameb
)))))))
731 ;;; Custom Mode Commands.
733 ;; This variable is used by `custom-tool-bar-map', or directly by
734 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
736 (defvar custom-commands
737 '((" Set for current session " Custom-set t
738 "Apply all settings in this buffer to the current session"
741 (" Save for future sessions " Custom-save
742 (or custom-file user-init-file
)
743 "Apply all settings in this buffer and save them for future Emacs sessions."
746 (" Undo edits " Custom-reset-current t
747 "Restore all settings in this buffer to reflect their current values."
750 (" Reset to saved " Custom-reset-saved t
751 "Restore all settings in this buffer to their saved values (if any)."
754 (" Erase customizations " Custom-reset-standard
755 (or custom-file user-init-file
)
756 "Un-customize all settings in this buffer and save them with standard values."
759 (" Help for Customize " Custom-help t
760 "Get help for using Customize."
763 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
765 (defun Custom-help ()
766 "Read the node on Easy Customization in the Emacs manual."
768 (info "(emacs)Easy Customization"))
770 (defvar custom-reset-menu
771 '(("Undo Edits" . Custom-reset-current
)
772 ("Reset to Saved" . Custom-reset-saved
)
773 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
774 "Alist of actions for the `Reset' button.
775 The key is a string containing the name of the action, the value is a
776 Lisp function taking the widget as an element which will be called
777 when the action is chosen.")
779 (defvar custom-options nil
780 "Customization widgets in the current buffer.")
782 (defun custom-command-apply (fun query
&optional strong-query
)
783 "Call function FUN on all widgets in `custom-options'.
784 If there is more than one widget, ask user for confirmation using
785 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
786 and `yes-or-no-p' otherwise."
787 (if (or (and (= 1 (length custom-options
))
788 (memq (widget-type (car custom-options
))
789 '(custom-variable custom-face
)))
790 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
791 (progn (mapc fun custom-options
) t
)
795 (defun Custom-set (&rest ignore
)
796 "Set the current value of all edited settings in the buffer."
798 (custom-command-apply
800 (when (eq (widget-get child
:custom-state
) 'modified
)
801 (widget-apply child
:custom-set
)))
802 "Set all values according to this buffer? "))
804 (defun Custom-save (&rest ignore
)
805 "Set all edited settings, then save all settings that have been set.
806 If a setting was edited and set before, this saves it. If a
807 setting was merely edited before, this sets it then saves it."
809 (when (custom-command-apply
811 (when (memq (widget-get child
:custom-state
)
812 '(modified set changed rogue
))
813 (widget-apply child
:custom-mark-to-save
)))
814 "Save all settings in this buffer? " t
)
815 ;; Save changes to buffer and redraw.
817 (dolist (child custom-options
)
818 (widget-apply child
:custom-state-set-and-redraw
))))
820 (defun custom-reset (widget &optional event
)
821 "Select item from reset menu."
822 (let* ((completion-ignore-case t
)
823 (answer (widget-choose "Reset settings"
829 (defun Custom-reset-current (&rest ignore
)
830 "Reset all edited settings in the buffer to show their current values."
832 (custom-command-apply
834 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
835 (widget-apply widget
:custom-reset-current
)))
836 "Reset all settings' buffer text to show current values? "))
838 (defun Custom-reset-saved (&rest ignore
)
839 "Reset all edited or set settings in the buffer to their saved value.
840 This also shows the saved values in the buffer."
842 (custom-command-apply
844 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
845 (widget-apply widget
:custom-reset-saved
)))
846 "Reset all settings (current values and buffer text) to saved values? "))
848 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
849 ;; and `custom-group-reset-standard'. If these variables are nil, both
850 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
851 ;; save, reset and redraw the handled widget immediately. Otherwise,
852 ;; they add the widget to the corresponding list and leave it to
853 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
854 (defvar custom-reset-standard-variables-list nil
)
855 (defvar custom-reset-standard-faces-list nil
)
857 ;; The next function was excerpted from `custom-variable-reset-standard'
858 ;; and `custom-face-reset-standard' and is used to avoid calling
859 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
860 ;; one) when erasing all customizations.
861 (defun custom-reset-standard-save-and-update ()
862 "Save settings and redraw after erasing customizations."
863 (when (or (and custom-reset-standard-variables-list
864 (not (eq custom-reset-standard-variables-list
'(t))))
865 (and custom-reset-standard-faces-list
866 (not (eq custom-reset-standard-faces-list
'(t)))))
867 ;; Save settings to file.
869 ;; Set state of and redraw variables.
870 (dolist (widget custom-reset-standard-variables-list
)
871 (unless (eq widget t
)
872 (widget-put widget
:custom-state
'unknown
)
873 (custom-redraw widget
)))
874 ;; Set state of and redraw faces.
875 (dolist (widget custom-reset-standard-faces-list
)
876 (unless (eq widget t
)
877 (let* ((symbol (widget-value widget
))
878 (child (car (widget-get widget
:children
)))
879 (value (get symbol
'face-defface-spec
))
880 (comment-widget (widget-get widget
:comment-widget
)))
881 (put symbol
'face-comment nil
)
882 (widget-value-set child
883 (custom-pre-filter-face-spec
884 (list (list t
(custom-face-attributes-get
886 ;; This call manages the comment visibility
887 (widget-value-set comment-widget
"")
888 (custom-face-state-set widget
)
889 (custom-redraw-magic widget
))))))
891 (defun Custom-reset-standard (&rest ignore
)
892 "Erase all customizations (either current or saved) in current buffer.
893 The immediate result is to restore them to their standard values.
894 This operation eliminates any saved values for the group members,
895 making them as if they had never been customized at all."
897 ;; Bind these temporarily.
898 (let ((custom-reset-standard-variables-list '(t))
899 (custom-reset-standard-faces-list '(t)))
900 (custom-command-apply
902 (and (or (null (widget-get widget
:custom-standard-value
))
903 (widget-apply widget
:custom-standard-value
))
904 (memq (widget-get widget
:custom-state
)
905 '(modified set changed saved rogue
))
906 (widget-apply widget
:custom-mark-to-reset-standard
)))
907 "Erase all customizations for settings in this buffer? " t
)
908 (custom-reset-standard-save-and-update)))
910 ;;; The Customize Commands
912 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
913 "Prompt for a variable and a value and return them as a list.
914 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
915 prompt for the value. The %s escape in PROMPT-VAL is replaced with
916 the name of the variable.
918 If the variable has a `variable-interactive' property, that is used as if
919 it were the arg to `interactive' (which see) to interactively read the value.
921 If the variable has a `custom-type' property, it must be a widget and the
922 `:prompt-value' property of that widget will be used for reading the value.
924 If optional COMMENT argument is non-nil, also prompt for a comment and return
925 it as the third element in the list."
926 (let* ((var (read-variable prompt-var
))
927 (minibuffer-help-form '(describe-variable var
))
929 (let ((prop (get var
'variable-interactive
))
930 (type (get var
'custom-type
))
931 (prompt (format prompt-val var
)))
933 (setq type
(list type
)))
935 ;; Use VAR's `variable-interactive' property
936 ;; as an interactive spec for prompting.
937 (call-interactively `(lambda (arg)
941 (widget-prompt-value type
947 (eval-minibuffer prompt
))))))
950 (read-string "Comment: " (get var
'variable-comment
)))
954 (defun customize-set-value (variable value
&optional comment
)
955 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
957 If VARIABLE has a `variable-interactive' property, that is used as if
958 it were the arg to `interactive' (which see) to interactively read the value.
960 If VARIABLE has a `custom-type' property, it must be a widget and the
961 `:prompt-value' property of that widget will be used for reading the value.
963 If given a prefix (or a COMMENT argument), also prompt for a comment."
964 (interactive (custom-prompt-variable "Set variable: "
968 (cond ((string= comment
"")
969 (put variable
'variable-comment nil
))
971 (put variable
'variable-comment comment
)))
972 (set variable value
))
975 (defun customize-set-variable (variable value
&optional comment
)
976 "Set the default for VARIABLE to VALUE, and return VALUE.
977 VALUE is a Lisp object.
979 If VARIABLE has a `custom-set' property, that is used for setting
980 VARIABLE, otherwise `set-default' is used.
982 If VARIABLE has a `variable-interactive' property, that is used as if
983 it were the arg to `interactive' (which see) to interactively read the value.
985 If VARIABLE has a `custom-type' property, it must be a widget and the
986 `:prompt-value' property of that widget will be used for reading the value.
988 If given a prefix (or a COMMENT argument), also prompt for a comment."
989 (interactive (custom-prompt-variable "Set variable: "
990 "Set customized value for %s to: "
992 (custom-load-symbol variable
)
993 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
994 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
995 (put variable
'customized-value
(list (custom-quote value
)))
996 (cond ((string= comment
"")
997 (put variable
'variable-comment nil
)
998 (put variable
'customized-variable-comment nil
))
1000 (put variable
'variable-comment comment
)
1001 (put variable
'customized-variable-comment comment
)))
1005 (defun customize-save-variable (variable value
&optional comment
)
1006 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1009 If VARIABLE has a `custom-set' property, that is used for setting
1010 VARIABLE, otherwise `set-default' is used.
1012 If VARIABLE has a `variable-interactive' property, that is used as if
1013 it were the arg to `interactive' (which see) to interactively read the value.
1015 If VARIABLE has a `custom-type' property, it must be a widget and the
1016 `:prompt-value' property of that widget will be used for reading the value.
1018 If given a prefix (or a COMMENT argument), also prompt for a comment."
1019 (interactive (custom-prompt-variable "Set and save variable: "
1020 "Set and save value for %s as: "
1021 current-prefix-arg
))
1022 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1023 (put variable
'saved-value
(list (custom-quote value
)))
1024 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1025 (cond ((string= comment
"")
1026 (put variable
'variable-comment nil
)
1027 (put variable
'saved-variable-comment nil
))
1029 (put variable
'variable-comment comment
)
1030 (put variable
'saved-variable-comment comment
)))
1031 (put variable
'customized-value nil
)
1032 (put variable
'customized-variable-comment nil
)
1038 "Select a customization buffer which you can use to set user options.
1039 User options are structured into \"groups\".
1040 Initially the top-level group `Emacs' and its immediate subgroups
1041 are shown; the contents of those subgroups are initially hidden."
1043 (customize-group 'emacs
))
1046 (defun customize-mode (mode)
1047 "Customize options related to the current major mode.
1048 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1049 then prompt for the MODE to customize."
1052 (let ((completion-regexp-list '("-mode\\'"))
1053 (group (custom-group-of-mode major-mode
)))
1054 (if (and group
(not current-prefix-arg
))
1057 (completing-read (if group
1058 (format "Major mode (default %s): " major-mode
)
1061 'custom-group-of-mode
1062 t nil nil
(if group
(symbol-name major-mode
))))))))
1063 (customize-group (custom-group-of-mode mode
)))
1065 (defun customize-read-group ()
1066 (let ((completion-ignore-case t
))
1067 (completing-read "Customize group (default emacs): "
1070 (or (and (get symbol
'custom-loads
)
1071 (not (get symbol
'custom-autoload
)))
1072 (get symbol
'custom-group
)))
1076 (defun customize-group (&optional group
)
1077 "Customize GROUP, which must be a customization group."
1078 (interactive (list (customize-read-group)))
1079 (when (stringp group
)
1080 (if (string-equal "" group
)
1082 (setq group
(intern group
))))
1083 (let ((name (format "*Customize Group: %s*"
1084 (custom-unlispify-tag-name group
))))
1085 (if (get-buffer name
)
1086 (pop-to-buffer name
)
1087 (custom-buffer-create
1088 (list (list group
'custom-group
))
1090 (concat " for group "
1091 (custom-unlispify-tag-name group
))))))
1094 (defun customize-group-other-window (&optional group
)
1095 "Customize GROUP, which must be a customization group, in another window."
1096 (interactive (list (customize-read-group)))
1097 (let ((pop-up-windows t
)
1098 (same-window-buffer-names nil
)
1099 (same-window-regexps nil
))
1100 (customize-group group
)))
1103 (defalias 'customize-variable
'customize-option
)
1106 (defun customize-option (symbol)
1107 "Customize SYMBOL, which must be a user option variable."
1108 (interactive (custom-variable-prompt))
1110 (error "No variable specified"))
1111 (let ((basevar (indirect-variable symbol
)))
1112 (custom-buffer-create (list (list basevar
'custom-variable
))
1113 (format "*Customize Option: %s*"
1114 (custom-unlispify-tag-name basevar
)))
1115 (unless (eq symbol basevar
)
1116 (message "`%s' is an alias for `%s'" symbol basevar
))))
1119 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1122 (defun customize-option-other-window (symbol)
1123 "Customize SYMBOL, which must be a user option variable.
1124 Show the buffer in another window, but don't select it."
1125 (interactive (custom-variable-prompt))
1127 (error "No variable specified"))
1128 (let ((basevar (indirect-variable symbol
)))
1129 (custom-buffer-create-other-window
1130 (list (list basevar
'custom-variable
))
1131 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1132 (unless (eq symbol basevar
)
1133 (message "`%s' is an alias for `%s'" symbol basevar
))))
1135 (defvar customize-changed-options-previous-release
"23.1"
1136 "Version for `customize-changed-options' to refer back to by default.")
1138 ;; Packages will update this variable, so make it available.
1140 (defvar customize-package-emacs-version-alist nil
1141 "Alist mapping versions of a package to Emacs versions.
1142 We use this for packages that have their own names, but are released
1143 as part of Emacs itself.
1145 Each elements looks like this:
1147 (PACKAGE (PVERSION . EVERSION)...)
1149 Here PACKAGE is the name of a package, as a symbol. After
1150 PACKAGE come one or more elements, each associating a
1151 package version PVERSION with the first Emacs version
1152 EVERSION in which it (or a subsequent version of PACKAGE)
1153 was first released. Both PVERSION and EVERSION are strings.
1154 PVERSION should be a string that this package used in
1155 the :package-version keyword for `defcustom', `defgroup',
1158 For example, the MH-E package updates this alist as follows:
1160 (add-to-list 'customize-package-emacs-version-alist
1161 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1162 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1163 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1164 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1166 The value of PACKAGE needs to be unique and it needs to match the
1167 PACKAGE value appearing in the :package-version keyword. Since
1168 the user might see the value in a error message, a good choice is
1169 the official name of the package, such as MH-E or Gnus.")
1172 (defalias 'customize-changed
'customize-changed-options
)
1175 (defun customize-changed-options (&optional since-version
)
1176 "Customize all settings whose meanings have changed in Emacs itself.
1177 This includes new user option variables and faces, and new
1178 customization groups, as well as older options and faces whose meanings
1179 or default values have changed since the previous major Emacs release.
1181 With argument SINCE-VERSION (a string), customize all settings
1182 that were added or redefined since that version."
1186 (read-from-minibuffer
1187 (format "Customize options changed, since version (default %s): "
1188 customize-changed-options-previous-release
))))
1189 (if (equal since-version
"")
1190 (setq since-version nil
)
1191 (unless (condition-case nil
1192 (numberp (read since-version
))
1194 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1195 (unless since-version
1196 (setq since-version customize-changed-options-previous-release
))
1198 ;; Load the information for versions since since-version. We use
1199 ;; custom-load-symbol for this.
1200 (put 'custom-versions-load-alist
'custom-loads nil
)
1201 (dolist (elt custom-versions-load-alist
)
1202 (if (customize-version-lessp since-version
(car elt
))
1203 (dolist (load (cdr elt
))
1204 (custom-add-load 'custom-versions-load-alist load
))))
1205 (custom-load-symbol 'custom-versions-load-alist
)
1206 (put 'custom-versions-load-alist
'custom-loads nil
)
1211 (let* ((package-version (get symbol
'custom-package-version
))
1213 (or (and package-version
1214 (customize-package-emacs-version symbol
1216 (get symbol
'custom-version
))))
1218 (when (customize-version-lessp since-version version
)
1219 (if (or (get symbol
'custom-group
)
1220 (get symbol
'group-documentation
))
1221 (push (list symbol
'custom-group
) found
))
1222 (if (custom-variable-p symbol
)
1223 (push (list symbol
'custom-variable
) found
))
1224 (if (custom-facep symbol
)
1225 (push (list symbol
'custom-face
) found
)))))))
1227 (custom-buffer-create (custom-sort-items found t
'first
)
1228 "*Customize Changed Options*")
1229 (error "No user option defaults have been changed since Emacs %s"
1232 (defun customize-package-emacs-version (symbol package-version
)
1233 "Return the Emacs version in which SYMBOL's meaning last changed.
1234 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1235 `customize-package-emacs-version-alist' to find the version of
1236 Emacs that is associated with version VERSION of PACKAGE."
1237 (let (package-versions emacs-version
)
1238 ;; Use message instead of error since we want user to be able to
1239 ;; see the rest of the symbols even if a package author has
1240 ;; botched things up.
1241 (cond ((not (listp package-version
))
1242 (message "Invalid package-version value for %s" symbol
))
1243 ((setq package-versions
(assq (car package-version
)
1244 customize-package-emacs-version-alist
))
1246 (cdr (assoc (cdr package-version
) package-versions
)))
1247 (unless emacs-version
1248 (message "%s version %s not found in %s" symbol
1249 (cdr package-version
)
1250 "customize-package-emacs-version-alist")))
1252 (message "Package %s version %s lists no corresponding Emacs version"
1253 (car package-version
)
1254 (cdr package-version
))))
1257 (defun customize-version-lessp (version1 version2
)
1258 ;; Why are the versions strings, and given that they are, why aren't
1259 ;; they converted to numbers and compared as such here? -- fx
1261 ;; In case someone made a mistake and left out the quotes
1262 ;; in the :version value.
1263 (if (numberp version2
)
1264 (setq version2
(prin1-to-string version2
)))
1265 (let (major1 major2 minor1 minor2
)
1266 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1267 (setq major1
(read (or (match-string 1 version1
)
1269 (setq minor1
(read (or (match-string 3 version1
)
1271 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1272 (setq major2
(read (or (match-string 1 version2
)
1274 (setq minor2
(read (or (match-string 3 version2
)
1276 (or (< major1 major2
)
1277 (and (= major1 major2
)
1278 (< minor1 minor2
)))))
1281 (defun customize-face (&optional face
)
1282 "Customize FACE, which should be a face name or nil.
1283 If FACE is nil, customize all faces. If FACE is actually a
1284 face-alias, customize the face it is aliased to.
1286 Interactively, when point is on text which has a face specified,
1287 suggest to customize that face, if it's customizable."
1288 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1289 (if (member face
'(nil ""))
1290 (setq face
(face-list)))
1291 (if (and (listp face
) (null (cdr face
)))
1292 (setq face
(car face
)))
1294 (custom-buffer-create
1296 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1298 "*Customize Faces*")
1299 ;; If FACE is actually an alias, customize the face it is aliased to.
1300 (if (get face
'face-alias
)
1301 (setq face
(get face
'face-alias
)))
1302 (unless (facep face
)
1303 (error "Invalid face %S" face
))
1304 (custom-buffer-create
1305 (list (list face
'custom-face
))
1306 (format "*Customize Face: %s*"
1307 (custom-unlispify-tag-name face
)))))
1310 (defun customize-face-other-window (&optional face
)
1311 "Show customization buffer for face FACE in other window.
1312 If FACE is actually a face-alias, customize the face it is aliased to.
1314 Interactively, when point is on text which has a face specified,
1315 suggest to customize that face, if it's customizable."
1316 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1317 (let ((pop-up-windows t
)
1318 (same-window-buffer-names nil
)
1319 (same-window-regexps nil
))
1320 (customize-face face
)))
1322 (defalias 'customize-customized
'customize-unsaved
)
1325 (defun customize-unsaved ()
1326 "Customize all user options set in this session but not saved."
1329 (mapatoms (lambda (symbol)
1330 (and (or (get symbol
'customized-face
)
1331 (get symbol
'customized-face-comment
))
1332 (custom-facep symbol
)
1333 (push (list symbol
'custom-face
) found
))
1334 (and (or (get symbol
'customized-value
)
1335 (get symbol
'customized-variable-comment
))
1337 (push (list symbol
'custom-variable
) found
))))
1339 (error "No user options are set but unsaved")
1340 (custom-buffer-create (custom-sort-items found t nil
)
1341 "*Customize Unsaved*"))))
1344 (defun customize-rogue ()
1345 "Customize all user variables modified outside customize."
1348 (mapatoms (lambda (symbol)
1349 (let ((cval (or (get symbol
'customized-value
)
1350 (get symbol
'saved-value
)
1351 (get symbol
'standard-value
))))
1352 (when (and cval
;Declared with defcustom.
1353 (default-boundp symbol
) ;Has a value.
1354 (not (equal (eval (car cval
))
1355 ;; Which does not match customize.
1356 (default-value symbol
))))
1357 (push (list symbol
'custom-variable
) found
)))))
1359 (error "No rogue user options")
1360 (custom-buffer-create (custom-sort-items found t nil
)
1361 "*Customize Rogue*"))))
1363 (defun customize-saved ()
1364 "Customize all already saved user options."
1367 (mapatoms (lambda (symbol)
1368 (and (or (get symbol
'saved-face
)
1369 (get symbol
'saved-face-comment
))
1370 (custom-facep symbol
)
1371 (push (list symbol
'custom-face
) found
))
1372 (and (or (get symbol
'saved-value
)
1373 (get symbol
'saved-variable-comment
))
1375 (push (list symbol
'custom-variable
) found
))))
1377 (error "No saved user options")
1378 (custom-buffer-create (custom-sort-items found t nil
)
1379 "*Customize Saved*"))))
1381 (declare-function apropos-parse-pattern
"apropos" (pattern))
1384 (defun customize-apropos (pattern &optional type
)
1385 "Customize all loaded options, faces and groups matching PATTERN.
1386 PATTERN can be a word, a list of words (separated by spaces),
1387 or a regexp (using some regexp special characters). If it is a word,
1388 search for matches for that word as a substring. If it is a list of words,
1389 search for matches for any two (or more) of those words.
1391 If TYPE is `options', include only options.
1392 If TYPE is `faces', include only faces.
1393 If TYPE is `groups', include only groups.
1394 If TYPE is t (interactively, with prefix arg), include variables
1395 that are not customizable options, as well as faces and groups
1396 \(but we recommend using `apropos-variable' instead)."
1397 (interactive (list (apropos-read-pattern "symbol") current-prefix-arg
))
1399 (apropos-parse-pattern pattern
)
1403 (when (string-match apropos-regexp
(symbol-name symbol
))
1404 ,(if (not (memq type
'(faces options
)))
1405 '(if (get symbol
'custom-group
)
1406 (push (list symbol
'custom-group
) found
)))
1407 ,(if (not (memq type
'(options groups
)))
1408 '(if (custom-facep symbol
)
1409 (push (list symbol
'custom-face
) found
)))
1410 ,(if (not (memq type
'(groups faces
)))
1411 `(if (and (boundp symbol
)
1412 (eq (indirect-variable symbol
) symbol
)
1413 (or (get symbol
'saved-value
)
1414 (custom-variable-p symbol
)
1415 ,(if (not (memq type
'(nil options
)))
1416 '(get symbol
'variable-documentation
))))
1417 (push (list symbol
'custom-variable
) found
))))))
1419 (error "No %s matching %s"
1422 (format "customizable %s"
1423 (if (memq type
'(options faces groups
))
1427 (custom-buffer-create
1428 (custom-sort-items found t custom-buffer-order-groups
)
1429 "*Customize Apropos*"))))
1432 (defun customize-apropos-options (regexp &optional arg
)
1433 "Customize all loaded customizable options matching REGEXP.
1434 With prefix ARG, include variables that are not customizable options
1435 \(but it is better to use `apropos-variable' if you want to find those)."
1436 (interactive "sCustomize options (regexp): \nP")
1437 (customize-apropos regexp
(or arg
'options
)))
1440 (defun customize-apropos-faces (regexp)
1441 "Customize all loaded faces matching REGEXP."
1442 (interactive "sCustomize faces (regexp): \n")
1443 (customize-apropos regexp
'faces
))
1446 (defun customize-apropos-groups (regexp)
1447 "Customize all loaded groups matching REGEXP."
1448 (interactive "sCustomize groups (regexp): \n")
1449 (customize-apropos regexp
'groups
))
1453 (defcustom custom-buffer-style
'links
1454 "Control the presentation style for customization buffers.
1455 The value should be a symbol, one of:
1457 brackets: groups nest within each other with big horizontal brackets.
1458 links: groups have links to subgroups."
1459 :type
'(radio (const brackets
)
1461 :group
'custom-buffer
)
1463 (defcustom custom-buffer-done-kill nil
1464 "Non-nil means exiting a Custom buffer should kill it."
1467 :group
'custom-buffer
)
1469 (defcustom custom-buffer-indent
3
1470 "Number of spaces to indent nested groups."
1472 :group
'custom-buffer
)
1474 (defun custom-get-fresh-buffer (name)
1475 "Get a fresh new buffer with name NAME.
1476 If the buffer already exist, clean it up to be like new.
1477 Beware: it's not quite like new. Good enough for custom, but maybe
1479 ;; To be more complete, we should also kill all permanent-local variables,
1480 ;; but it's not needed for custom.
1481 (let ((buf (get-buffer name
)))
1482 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1483 ;; This will check if the file is not saved.
1487 (get-buffer-create name
)
1488 (with-current-buffer buf
1489 (kill-all-local-variables)
1490 (run-hooks 'kill-buffer-hook
)
1491 ;; Delete overlays before erasing the buffer so the overlay hooks
1492 ;; don't get run spuriously when we erase the buffer.
1493 (let ((ols (overlay-lists)))
1494 (dolist (ol (nconc (car ols
) (cdr ols
)))
1495 (delete-overlay ol
)))
1500 (defun custom-buffer-create (options &optional name description
)
1501 "Create a buffer containing OPTIONS.
1502 Optional NAME is the name of the buffer.
1503 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1504 SYMBOL is a customization option, and WIDGET is a widget for editing
1506 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1507 (custom-buffer-create-internal options description
))
1510 (defun custom-buffer-create-other-window (options &optional name description
)
1511 "Create a buffer containing OPTIONS, and display it in another window.
1512 The result includes selecting that window.
1513 Optional NAME is the name of the buffer.
1514 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1515 SYMBOL is a customization option, and WIDGET is a widget for editing
1517 (unless name
(setq name
"*Customization*"))
1518 (let ((pop-up-windows t
)
1519 (same-window-buffer-names nil
)
1520 (same-window-regexps nil
))
1521 (pop-to-buffer (custom-get-fresh-buffer name
))
1522 (custom-buffer-create-internal options description
)))
1524 (defcustom custom-reset-button-menu nil
1525 "If non-nil, only show a single reset button in customize buffers.
1526 This button will have a menu with all three reset operations."
1528 :group
'custom-buffer
)
1530 (defcustom custom-buffer-verbose-help t
1531 "If non-nil, include explanatory text in the customization buffer."
1533 :group
'custom-buffer
)
1535 (defun Custom-buffer-done (&rest ignore
)
1536 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1538 (quit-window custom-buffer-done-kill
))
1540 (defvar custom-button nil
1541 "Face used for buttons in customization buffers.")
1543 (defvar custom-button-mouse nil
1544 "Mouse face used for buttons in customization buffers.")
1546 (defvar custom-button-pressed nil
1547 "Face used for pressed buttons in customization buffers.")
1549 (defcustom custom-search-field t
1550 "If non-nil, show a search field in Custom buffers."
1553 :group
'custom-buffer
)
1555 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1556 '(("unspecified" . unspecified
))))
1557 "If non-nil, indicate active buttons in a `raised-button' style.
1558 Otherwise use brackets."
1561 :group
'custom-buffer
1562 :set
(lambda (variable value
)
1563 (custom-set-default variable value
)
1565 (if value
'custom-button
'custom-button-unraised
))
1566 (setq custom-button-mouse
1567 (if value
'custom-button-mouse
'highlight
))
1568 (setq custom-button-pressed
1570 'custom-button-pressed
1571 'custom-button-pressed-unraised
))))
1573 (defun custom-buffer-create-internal (options &optional description
)
1575 (let ((init-file (or custom-file user-init-file
)))
1576 ;; Insert verbose help at the top of the custom buffer.
1577 (when custom-buffer-verbose-help
1578 (widget-insert (if init-file
1579 "To apply changes, use the Save or Set buttons."
1580 "Custom settings cannot be saved; maybe you started Emacs with `-q'.")
1581 "\nFor details, see ")
1582 (widget-create 'custom-manual
1583 :tag
"Saving Customizations"
1584 "(emacs)Saving Customizations")
1585 (widget-insert " in the ")
1586 (widget-create 'custom-manual
1588 :help-echo
"Read the Emacs manual."
1590 (widget-insert "."))
1591 (widget-insert "\n")
1593 ;; Insert the search field.
1594 (when custom-search-field
1595 (widget-insert "\n")
1596 (let* ((echo "Search for custom items")
1600 :size
40 :help-echo echo
1601 :action
`(lambda (widget &optional event
)
1602 (customize-apropos (split-string (widget-value widget
)))))))
1604 (widget-create-child-and-convert
1605 search-widget
'push-button
1607 :help-echo echo
:action
1608 (lambda (widget &optional event
)
1609 (customize-apropos (widget-value (widget-get widget
:parent
)))))
1610 (widget-insert "\n")))
1612 ;; The custom command buttons are also in the toolbar, so for a
1613 ;; time they were not inserted in the buffer if the toolbar was in use.
1614 ;; But it can be a little confusing for the buffer layout to
1615 ;; change according to whether or nor the toolbar is on, not to
1616 ;; mention that a custom buffer can in theory be created in a
1617 ;; frame with a toolbar, then later viewed in one without.
1618 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1619 (if custom-buffer-verbose-help
1621 Operate on all settings in this buffer:\n"))
1622 (let ((button (lambda (tag action active help icon label
)
1625 (widget-create 'push-button
:tag tag
1626 :help-echo help
:action action
))))
1627 (commands custom-commands
))
1628 (apply button
(pop commands
)) ; Set for current session
1629 (apply button
(pop commands
)) ; Save for future sessions
1630 (if custom-reset-button-menu
1633 (widget-create 'push-button
1635 :help-echo
"Show a menu with reset operations."
1636 :mouse-down-action
'ignore
1637 :action
'custom-reset
))
1638 (widget-insert "\n")
1639 (apply button
(pop commands
)) ; Undo edits
1640 (apply button
(pop commands
)) ; Reset to saved
1641 (apply button
(pop commands
)) ; Erase customization
1643 (pop commands
) ; Help (omitted)
1644 (apply button
(pop commands
)))) ; Exit
1645 (widget-insert "\n\n"))
1647 ;; Now populate the custom buffer.
1648 (message "Creating customization items...")
1649 (buffer-disable-undo)
1650 (setq custom-options
1651 (if (= (length options
) 1)
1652 (mapcar (lambda (entry)
1653 (widget-create (nth 1 entry
)
1654 :documentation-shown t
1655 :custom-state
'unknown
1656 :tag
(custom-unlispify-tag-name
1658 :value
(nth 0 entry
)))
1661 (length (length options
)))
1662 (mapcar (lambda (entry)
1664 (message "Creating customization items ...%2d%%"
1665 (/ (* 100.0 count
) length
))
1666 (widget-create (nth 1 entry
)
1667 :tag
(custom-unlispify-tag-name
1669 :value
(nth 0 entry
))
1670 (setq count
(1+ count
))
1671 (unless (eq (preceding-char) ?
\n)
1672 (widget-insert "\n"))
1673 (widget-insert "\n")))
1675 (unless (eq (preceding-char) ?
\n)
1676 (widget-insert "\n"))
1677 (message "Creating customization items ...done")
1678 (message "Resetting customization items...")
1679 (unless (eq custom-buffer-style
'tree
)
1680 (mapc 'custom-magic-reset custom-options
))
1681 (message "Resetting customization items...done")
1682 (message "Creating customization setup...")
1684 (buffer-enable-undo)
1685 (goto-char (point-min))
1686 (message "Creating customization setup...done"))
1688 ;;; The Tree Browser.
1691 (defun customize-browse (&optional group
)
1692 "Create a tree browser for the customize hierarchy."
1695 (setq group
'emacs
))
1696 (let ((name "*Customize Browser*"))
1697 (pop-to-buffer (custom-get-fresh-buffer name
)))
1699 (widget-insert (format "\
1700 %s buttons; type RET or click mouse-1
1701 on a button to invoke its action.
1702 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1703 (if custom-raised-buttons
1704 "`Raised' text indicates"
1705 "Square brackets indicate")))
1708 (if custom-browse-only-groups
1710 Invoke the [Group] button below to edit that item in another window.\n\n")
1711 (widget-insert "Invoke the ")
1712 (widget-create 'item
1715 :tag-glyph
"folder")
1716 (widget-insert ", ")
1717 (widget-create 'item
1721 (widget-insert ", and ")
1722 (widget-create 'item
1725 :tag-glyph
"option")
1726 (widget-insert " buttons below to edit that
1727 item in another window.\n\n"))
1728 (let ((custom-buffer-style 'tree
))
1729 (widget-create 'custom-group
1731 :custom-state
'unknown
1732 :tag
(custom-unlispify-tag-name group
)
1735 (goto-char (point-min)))
1737 (define-widget 'custom-browse-visibility
'item
1738 "Control visibility of items in the customize tree browser."
1740 :action
'custom-browse-visibility-action
)
1742 (defun custom-browse-visibility-action (widget &rest ignore
)
1743 (let ((custom-buffer-style 'tree
))
1744 (custom-toggle-parent widget
)))
1746 (define-widget 'custom-browse-group-tag
'custom-group-link
1747 "Show parent in other window when activated."
1750 :action
'custom-browse-group-tag-action
)
1752 (defun custom-browse-group-tag-action (widget &rest ignore
)
1753 (let ((parent (widget-get widget
:parent
)))
1754 (customize-group-other-window (widget-value parent
))))
1756 (define-widget 'custom-browse-variable-tag
'custom-group-link
1757 "Show parent in other window when activated."
1760 :action
'custom-browse-variable-tag-action
)
1762 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1763 (let ((parent (widget-get widget
:parent
)))
1764 (customize-variable-other-window (widget-value parent
))))
1766 (define-widget 'custom-browse-face-tag
'custom-group-link
1767 "Show parent in other window when activated."
1770 :action
'custom-browse-face-tag-action
)
1772 (defun custom-browse-face-tag-action (widget &rest ignore
)
1773 (let ((parent (widget-get widget
:parent
)))
1774 (customize-face-other-window (widget-value parent
))))
1776 (defconst custom-browse-alist
'((" " "space")
1782 (defun custom-browse-insert-prefix (prefix)
1783 "Insert PREFIX. On XEmacs convert it to line graphics."
1784 ;; Fixme: do graphics.
1785 (if nil
; (featurep 'xemacs)
1788 (while (not (string-equal prefix
""))
1789 (let ((entry (substring prefix
0 3)))
1790 (setq prefix
(substring prefix
3))
1791 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1792 (name (nth 1 (assoc entry custom-browse-alist
))))
1793 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1794 (overlay-put overlay
'start-open t
)
1795 (overlay-put overlay
'end-open t
)))))
1798 ;;; Modification of Basic Widgets.
1800 ;; We add extra properties to the basic widgets needed here. This is
1801 ;; fine, as long as we are careful to stay within our own namespace.
1803 ;; We want simple widgets to be displayed by default, but complex
1804 ;; widgets to be hidden.
1806 (widget-put (get 'item
'widget-type
) :custom-show t
)
1807 (widget-put (get 'editable-field
'widget-type
)
1808 :custom-show
(lambda (widget value
)
1809 (let ((pp (pp-to-string value
)))
1810 (cond ((string-match "\n" pp
)
1815 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1817 ;;; The `custom-manual' Widget.
1819 (define-widget 'custom-manual
'info-link
1820 "Link to the manual entry for this customization option."
1821 :help-echo
"Read the manual entry for this option."
1822 :keymap custom-mode-link-map
1823 :follow-link
'mouse-face
1824 :button-face
'custom-link
1825 :mouse-face
'highlight
1826 :pressed-face
'highlight
1829 ;;; The `custom-magic' Widget.
1831 (defgroup custom-magic-faces nil
1832 "Faces used by the magic button."
1833 :group
'custom-faces
1834 :group
'custom-buffer
)
1836 (defface custom-invalid
'((((class color
))
1837 (:foreground
"yellow1" :background
"red1"))
1839 (:weight bold
:slant italic
:underline t
)))
1840 "Face used when the customize item is invalid."
1841 :group
'custom-magic-faces
)
1842 (define-obsolete-face-alias 'custom-invalid-face
'custom-invalid
"22.1")
1844 (defface custom-rogue
'((((class color
))
1845 (:foreground
"pink" :background
"black"))
1848 "Face used when the customize item is not defined for customization."
1849 :group
'custom-magic-faces
)
1850 (define-obsolete-face-alias 'custom-rogue-face
'custom-rogue
"22.1")
1852 (defface custom-modified
'((((min-colors 88) (class color
))
1853 (:foreground
"white" :background
"blue1"))
1855 (:foreground
"white" :background
"blue"))
1857 (:slant italic
:bold
)))
1858 "Face used when the customize item has been modified."
1859 :group
'custom-magic-faces
)
1860 (define-obsolete-face-alias 'custom-modified-face
'custom-modified
"22.1")
1862 (defface custom-set
'((((min-colors 88) (class color
))
1863 (:foreground
"blue1" :background
"white"))
1865 (:foreground
"blue" :background
"white"))
1868 "Face used when the customize item has been set."
1869 :group
'custom-magic-faces
)
1870 (define-obsolete-face-alias 'custom-set-face
'custom-set
"22.1")
1872 (defface custom-changed
'((((min-colors 88) (class color
))
1873 (:foreground
"white" :background
"blue1"))
1875 (:foreground
"white" :background
"blue"))
1878 "Face used when the customize item has been changed."
1879 :group
'custom-magic-faces
)
1880 (define-obsolete-face-alias 'custom-changed-face
'custom-changed
"22.1")
1882 (defface custom-themed
'((((min-colors 88) (class color
))
1883 (:foreground
"white" :background
"blue1"))
1885 (:foreground
"white" :background
"blue"))
1888 "Face used when the customize item has been set by a theme."
1889 :group
'custom-magic-faces
)
1891 (defface custom-saved
'((t (:underline t
)))
1892 "Face used when the customize item has been saved."
1893 :group
'custom-magic-faces
)
1894 (define-obsolete-face-alias 'custom-saved-face
'custom-saved
"22.1")
1896 (defconst custom-magic-alist
1897 '((nil "#" underline
"\
1898 UNINITIALIZED, you should not see this.")
1899 (unknown "?" italic
"\
1900 UNKNOWN, you should not see this.")
1901 (hidden "-" default
"\
1902 HIDDEN, invoke \"Show\" in the previous line to show." "\
1903 group now hidden, invoke \"Show\", above, to show contents.")
1904 (invalid "x" custom-invalid
"\
1905 INVALID, the displayed value cannot be set.")
1906 (modified "*" custom-modified
"\
1907 EDITED, shown value does not take effect until you set or save it." "\
1908 something in this group has been edited but not set.")
1909 (set "+" custom-set
"\
1910 SET for current session only." "\
1911 something in this group has been set but not saved.")
1912 (changed ":" custom-changed
"\
1913 CHANGED outside Customize." "\
1914 something in this group has been changed outside customize.")
1915 (saved "!" custom-saved
"\
1917 something in this group has been set and saved.")
1918 (themed "o" custom-themed
"\
1920 visible group members are all at standard values.")
1921 (rogue "@" custom-rogue
"\
1922 NO CUSTOMIZATION DATA; not intended to be customized." "\
1923 something in this group is not prepared for customization.")
1924 (standard " " nil
"\
1926 visible group members are all at standard values."))
1927 "Alist of customize option states.
1928 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1930 STATE is one of the following symbols:
1933 For internal use, should never occur.
1935 For internal use, should never occur.
1937 This item is not being displayed.
1939 This item is modified, but has an invalid form.
1941 This item is modified, and has a valid form.
1943 This item has been set but not saved.
1945 The current value of this item has been changed outside Customize.
1947 This item is marked for saving.
1949 This item has no customization information.
1951 This item is unchanged from the standard setting.
1953 MAGIC is a string used to present that state.
1955 FACE is a face used to present the state.
1957 ITEM-DESC is a string describing the state for options.
1959 GROUP-DESC is a string describing the state for groups. If this is
1960 left out, ITEM-DESC will be used.
1962 The string %c in either description will be replaced with the
1963 category of the item. These are `group'. `option', and `face'.
1965 The list should be sorted most significant first.")
1967 (defcustom custom-magic-show
'long
1968 "If non-nil, show textual description of the state.
1969 If `long', show a full-line description, not just one word."
1970 :type
'(choice (const :tag
"no" nil
)
1972 (other :tag
"short" short
))
1973 :group
'custom-buffer
)
1975 (defcustom custom-magic-show-hidden
'(option face
)
1976 "Control whether the State button is shown for hidden items.
1977 The value should be a list with the custom categories where the State
1978 button should be visible. Possible categories are `group', `option',
1980 :type
'(set (const group
) (const option
) (const face
))
1981 :group
'custom-buffer
)
1983 (defcustom custom-magic-show-button nil
1984 "Show a \"magic\" button indicating the state of each customization option."
1986 :group
'custom-buffer
)
1988 (define-widget 'custom-magic
'default
1989 "Show and manipulate state for a customization option."
1991 :action
'widget-parent-action
1994 :value-create
'custom-magic-value-create
1995 :value-delete
'widget-children-value-delete
)
1997 (defun widget-magic-mouse-down-action (widget &optional event
)
1998 ;; Non-nil unless hidden.
1999 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2003 (defun custom-magic-value-create (widget)
2004 "Create compact status report for WIDGET."
2005 (let* ((parent (widget-get widget
:parent
))
2006 (state (widget-get parent
:custom-state
))
2007 (hidden (eq state
'hidden
))
2008 (entry (assq state custom-magic-alist
))
2009 (magic (nth 1 entry
))
2010 (face (nth 2 entry
))
2011 (category (widget-get parent
:custom-category
))
2012 (text (or (and (eq category
'group
)
2015 (form (widget-get parent
:custom-form
))
2017 (unless (eq state
'hidden
)
2018 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2019 (setq text
(concat (match-string 1 text
)
2020 (symbol-name category
)
2021 (match-string 2 text
))))
2022 (when (and custom-magic-show
2024 (memq category custom-magic-show-hidden
)))
2026 (when (and (eq category
'group
)
2027 (not (and (eq custom-buffer-style
'links
)
2028 (> (widget-get parent
:custom-level
) 1))))
2029 (insert-char ?\
(* custom-buffer-indent
2030 (widget-get parent
:custom-level
))))
2031 (push (widget-create-child-and-convert
2033 :help-echo
"Change the state of this item."
2034 :format
(if hidden
"%t" "%[%t%]")
2035 :button-prefix
'widget-push-button-prefix
2036 :button-suffix
'widget-push-button-suffix
2037 :mouse-down-action
'widget-magic-mouse-down-action
2041 (let ((start (point)))
2042 (if (eq custom-magic-show
'long
)
2044 (insert (symbol-name state
)))
2045 (cond ((eq form
'lisp
)
2047 ((eq form
'mismatch
)
2048 (insert " (mismatch)")))
2049 (put-text-property start
(point) 'face
'custom-state
))
2051 (when (and (eq category
'group
)
2052 (not (and (eq custom-buffer-style
'links
)
2053 (> (widget-get parent
:custom-level
) 1))))
2054 (insert-char ?\
(* custom-buffer-indent
2055 (widget-get parent
:custom-level
))))
2056 (when custom-magic-show-button
2057 (when custom-magic-show
2058 (let ((indent (widget-get parent
:indent
)))
2060 (insert-char ? indent
))))
2061 (push (widget-create-child-and-convert
2063 :mouse-down-action
'widget-magic-mouse-down-action
2067 :help-echo
"Change the state."
2068 :format
(if hidden
"%t" "%[%t%]")
2069 :tag
(if (memq form
'(lisp mismatch
))
2070 (concat "(" magic
")")
2071 (concat "[" magic
"]")))
2074 (widget-put widget
:children children
))))
2076 (defun custom-magic-reset (widget)
2077 "Redraw the :custom-magic property of WIDGET."
2078 (let ((magic (widget-get widget
:custom-magic
)))
2080 (widget-value-set magic
(widget-value magic
)))))
2082 ;;; The `custom' Widget.
2084 (defface custom-button
2085 '((((type x w32 ns
) (class color
)) ; Like default modeline
2086 (:box
(:line-width
2 :style released-button
)
2087 :background
"lightgrey" :foreground
"black"))
2090 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2092 :group
'custom-faces
)
2093 (define-obsolete-face-alias 'custom-button-face
'custom-button
"22.1")
2095 (defface custom-button-mouse
2096 '((((type x w32 ns
) (class color
))
2097 (:box
(:line-width
2 :style released-button
)
2098 :background
"grey90" :foreground
"black"))
2100 ;; This is for text terminals that support mouse, like GPM mouse
2101 ;; or the MS-DOS terminal: inverse-video makes the button stand
2102 ;; out on mouse-over.
2103 (:inverse-video t
)))
2104 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2106 :group
'custom-faces
)
2108 (defface custom-button-unraised
2109 '((t :inherit underline
))
2110 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2112 :group
'custom-faces
)
2115 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2117 (setq custom-button-mouse
2118 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2120 (defface custom-button-pressed
2121 '((((type x w32 ns
) (class color
))
2122 (:box
(:line-width
2 :style pressed-button
)
2123 :background
"lightgrey" :foreground
"black"))
2125 (:inverse-video t
)))
2126 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2128 :group
'custom-faces
)
2129 (define-obsolete-face-alias 'custom-button-pressed-face
2130 'custom-button-pressed
"22.1")
2132 (defface custom-button-pressed-unraised
2133 '((default :inherit custom-button-unraised
)
2134 (((class color
) (background light
)) :foreground
"magenta4")
2135 (((class color
) (background dark
)) :foreground
"violet"))
2136 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2138 :group
'custom-faces
)
2140 (setq custom-button-pressed
2141 (if custom-raised-buttons
2142 'custom-button-pressed
2143 'custom-button-pressed-unraised
))
2145 (defface custom-documentation
'((t nil
))
2146 "Face used for documentation strings in customization buffers."
2147 :group
'custom-faces
)
2148 (define-obsolete-face-alias 'custom-documentation-face
2149 'custom-documentation
"22.1")
2151 (defface custom-state
'((((class color
)
2153 (:foreground
"lime green"))
2156 (:foreground
"dark green"))
2158 "Face used for State descriptions in the customize buffer."
2159 :group
'custom-faces
)
2160 (define-obsolete-face-alias 'custom-state-face
'custom-state
"22.1")
2162 (defface custom-link
2163 '((t :inherit link
))
2164 "Face for links in customization buffers."
2166 :group
'custom-faces
)
2168 (define-widget 'custom
'default
2169 "Customize a user option."
2171 :convert-widget
'custom-convert-widget
2172 :notify
'custom-notify
2175 :custom-state
'hidden
2176 :documentation-property
'widget-subclass-responsibility
2177 :value-create
'widget-subclass-responsibility
2178 :value-delete
'widget-children-value-delete
2179 :value-get
'widget-value-value-get
2180 :validate
'widget-children-validate
2181 :match
(lambda (widget value
) (symbolp value
)))
2183 (defun custom-convert-widget (widget)
2184 "Initialize :value and :tag from :args in WIDGET."
2185 (let ((args (widget-get widget
:args
)))
2187 (widget-put widget
:value
(widget-apply widget
2188 :value-to-internal
(car args
)))
2189 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2190 (widget-put widget
:args nil
)))
2193 (defun custom-notify (widget &rest args
)
2194 "Keep track of changes."
2195 (let ((state (widget-get widget
:custom-state
)))
2196 (unless (eq state
'modified
)
2197 (unless (memq state
'(nil unknown hidden
))
2198 (widget-put widget
:custom-state
'modified
))
2199 (custom-magic-reset widget
)
2200 (apply 'widget-default-notify widget args
))))
2202 (defun custom-redraw (widget)
2203 "Redraw WIDGET with current settings."
2204 (let ((line (count-lines (point-min) (point)))
2205 (column (current-column))
2207 (from (marker-position (widget-get widget
:from
)))
2208 (to (marker-position (widget-get widget
:to
))))
2210 (widget-value-set widget
(widget-value widget
))
2211 (custom-redraw-magic widget
))
2212 (when (and (>= pos from
) (<= pos to
))
2215 (goto-char (point-min))
2216 (forward-line (if (> column
0)
2219 (move-to-column column
))
2222 (defun custom-redraw-magic (widget)
2223 "Redraw WIDGET state with current settings."
2225 (let ((magic (widget-get widget
:custom-magic
)))
2227 (widget-value-set magic
(widget-value magic
))
2228 (when (setq widget
(widget-get widget
:group
))
2229 (custom-group-state-update widget
)))
2231 (setq widget nil
)))))
2234 (defun custom-show (widget value
)
2235 "Non-nil if WIDGET should be shown with VALUE by default."
2236 (let ((show (widget-get widget
:custom-show
)))
2237 (if (functionp show
)
2238 (funcall show widget value
)
2241 (defun custom-load-widget (widget)
2242 "Load all dependencies for WIDGET."
2243 (custom-load-symbol (widget-value widget
)))
2245 (defun custom-unloaded-symbol-p (symbol)
2246 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2248 (loads (get symbol
'custom-loads
))
2251 (setq load
(car loads
)
2253 (cond ((symbolp load
)
2254 (unless (featurep load
)
2256 ((assoc load load-history
))
2257 ((assoc (locate-library load
) load-history
)
2263 (defun custom-unloaded-widget-p (widget)
2264 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2265 (custom-unloaded-symbol-p (widget-value widget
)))
2267 (defun custom-toggle-hide (widget)
2268 "Toggle visibility of WIDGET."
2269 (custom-load-widget widget
)
2270 (let ((state (widget-get widget
:custom-state
)))
2271 (cond ((memq state
'(invalid modified set
))
2272 (error "There are unsaved changes"))
2274 (widget-put widget
:custom-state
'unknown
))
2276 (widget-put widget
:documentation-shown nil
)
2277 (widget-put widget
:custom-state
'hidden
)))
2278 (custom-redraw widget
)
2281 (defun custom-toggle-parent (widget &rest ignore
)
2282 "Toggle visibility of parent of WIDGET."
2283 (custom-toggle-hide (widget-get widget
:parent
)))
2285 (defun custom-add-see-also (widget &optional prefix
)
2286 "Add `See also ...' to WIDGET if there are any links.
2287 Insert PREFIX first if non-nil."
2288 (let* ((symbol (widget-get widget
:value
))
2289 (links (get symbol
'custom-links
))
2290 (many (> (length links
) 2))
2291 (buttons (widget-get widget
:buttons
))
2292 (indent (widget-get widget
:indent
)))
2295 (insert-char ?\ indent
))
2298 (insert "See also ")
2300 (push (widget-create-child-and-convert
2302 :button-face
'custom-link
2303 :mouse-face
'highlight
2304 :pressed-face
'highlight
)
2306 (setq links
(cdr links
))
2315 (widget-put widget
:buttons buttons
))))
2317 (defun custom-add-parent-links (widget &optional initial-string doc-initial-string
)
2318 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2319 The value is non-nil if any parents were found.
2320 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2321 (let ((name (widget-value widget
))
2322 (type (widget-type widget
))
2323 (buttons (widget-get widget
:buttons
))
2326 (insert (or initial-string
"Groups:"))
2327 (mapatoms (lambda (symbol)
2328 (when (member (list name type
) (get symbol
'custom-group
))
2330 (push (widget-create-child-and-convert
2331 widget
'custom-group-link
2332 :tag
(custom-unlispify-tag-name symbol
)
2335 (setq parents
(cons symbol parents
)))))
2338 (delete-region start
(point)))
2339 (widget-put widget
:buttons buttons
)
2342 ;;; The `custom-comment' Widget.
2344 ;; like the editable field
2345 (defface custom-comment
'((((type tty
))
2346 :background
"yellow3"
2347 :foreground
"black")
2348 (((class grayscale color
)
2350 :background
"gray85")
2351 (((class grayscale color
)
2353 :background
"dim gray")
2356 "Face used for comments on variables or faces."
2358 :group
'custom-faces
)
2359 (define-obsolete-face-alias 'custom-comment-face
'custom-comment
"22.1")
2361 ;; like font-lock-comment-face
2362 (defface custom-comment-tag
2363 '((((class color
) (background dark
)) (:foreground
"gray80"))
2364 (((class color
) (background light
)) (:foreground
"blue4"))
2365 (((class grayscale
) (background light
))
2366 (:foreground
"DimGray" :weight bold
:slant italic
))
2367 (((class grayscale
) (background dark
))
2368 (:foreground
"LightGray" :weight bold
:slant italic
))
2370 "Face used for the comment tag on variables or faces."
2371 :group
'custom-faces
)
2372 (define-obsolete-face-alias 'custom-comment-tag-face
'custom-comment-tag
"22.1")
2374 (define-widget 'custom-comment
'string
2377 :help-echo
"Edit a comment here."
2378 :sample-face
'custom-comment-tag
2379 :value-face
'custom-comment
2381 :create
'custom-comment-create
)
2383 (defun custom-comment-create (widget)
2384 (let* ((null-comment (equal "" (widget-value widget
))))
2385 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2387 (widget-default-create widget
)
2388 ;; `widget-default-delete' expects markers in these slots --
2389 ;; maybe it shouldn't.
2390 (widget-put widget
:from
(point-marker))
2391 (widget-put widget
:to
(point-marker)))))
2393 (defun custom-comment-hide (widget)
2394 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2396 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2397 ;; the global custom one
2398 (defun custom-comment-show (widget)
2399 (widget-put widget
:comment-shown t
)
2400 (custom-redraw widget
)
2403 (defun custom-comment-invisible-p (widget)
2404 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2406 (not (widget-get widget
:comment-shown
)))))
2408 ;;; The `custom-variable' Widget.
2410 (defface custom-variable-tag
2413 (:foreground
"light blue" :weight bold
))
2414 (((min-colors 88) (class color
)
2416 (:foreground
"blue1" :weight bold
))
2419 (:foreground
"blue" :weight bold
))
2421 "Face used for unpushable variable tags."
2422 :group
'custom-faces
)
2423 (define-obsolete-face-alias 'custom-variable-tag-face
2424 'custom-variable-tag
"22.1")
2426 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2427 "Face used for pushable variable tags."
2428 :group
'custom-faces
)
2429 (define-obsolete-face-alias 'custom-variable-button-face
2430 'custom-variable-button
"22.1")
2432 (defcustom custom-variable-default-form
'edit
2433 "Default form of displaying variable values."
2434 :type
'(choice (const edit
)
2436 :group
'custom-buffer
2439 (defun custom-variable-documentation (variable)
2440 "Return documentation of VARIABLE for use in Custom buffer.
2441 Normally just return the docstring. But if VARIABLE automatically
2442 becomes buffer local when set, append a message to that effect."
2443 (if (and (local-variable-if-set-p variable
)
2444 (or (not (local-variable-p variable
))
2446 (local-variable-if-set-p variable
))))
2447 (concat (documentation-property variable
'variable-documentation
)
2449 This variable automatically becomes buffer-local when set outside Custom.
2450 However, setting it through Custom sets the default value.")
2451 (documentation-property variable
'variable-documentation
)))
2453 (define-widget 'custom-variable
'custom
2454 "A widget for displaying a Custom variable.
2455 The following properties have special meanings for this widget:
2457 :hidden-states should be a list of widget states for which the
2458 widget's initial contents are to be hidden.
2460 :custom-form should be a symbol describing how to display and
2461 edit the variable---either `edit' (using edit widgets),
2462 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2463 if nil, use the return value of `custom-variable-default-form'.
2465 :shown-value, if non-nil, should be a list whose `car' is the
2466 variable value to display in place of the current value.
2468 :custom-style describes the widget interface style; nil is the
2469 default style, while `simple' means a simpler interface that
2470 inhibits the magic custom-state widget."
2472 :help-echo
"Set or reset this variable."
2473 :documentation-property
#'custom-variable-documentation
2474 :custom-category
'option
2476 :custom-menu
'custom-variable-menu-create
2478 :value-create
'custom-variable-value-create
2479 :action
'custom-variable-action
2480 :hidden-states
'(standard)
2481 :custom-set
'custom-variable-set
2482 :custom-mark-to-save
'custom-variable-mark-to-save
2483 :custom-reset-current
'custom-redraw
2484 :custom-reset-saved
'custom-variable-reset-saved
2485 :custom-reset-standard
'custom-variable-reset-standard
2486 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2487 :custom-standard-value
'custom-variable-standard-value
2488 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2490 (defun custom-variable-type (symbol)
2491 "Return a widget suitable for editing the value of SYMBOL.
2492 If SYMBOL has a `custom-type' property, use that.
2493 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2494 try matching its doc string against `custom-guess-doc-alist'."
2495 (let* ((type (or (get symbol
'custom-type
)
2496 (and (not (get symbol
'standard-value
))
2497 (custom-guess-type symbol
))
2499 (options (get symbol
'custom-options
))
2500 (tmp (if (listp type
)
2501 (copy-sequence type
)
2504 (widget-put tmp
:options options
))
2507 (defun custom-variable-value-create (widget)
2508 "Here is where you edit the variable's value."
2509 (custom-load-widget widget
)
2510 (unless (widget-get widget
:custom-form
)
2511 (widget-put widget
:custom-form custom-variable-default-form
))
2512 (let* ((buttons (widget-get widget
:buttons
))
2513 (children (widget-get widget
:children
))
2514 (form (widget-get widget
:custom-form
))
2515 (symbol (widget-get widget
:value
))
2516 (tag (widget-get widget
:tag
))
2517 (type (custom-variable-type symbol
))
2518 (conv (widget-convert type
))
2519 (get (or (get symbol
'custom-get
) 'default-value
))
2520 (prefix (widget-get widget
:custom-prefix
))
2521 (last (widget-get widget
:custom-last
))
2522 (style (widget-get widget
:custom-style
))
2523 (value (let ((shown-value (widget-get widget
:shown-value
)))
2526 ((default-boundp symbol
)
2527 (funcall get symbol
))
2528 (t (widget-get conv
:value
)))))
2529 (state (or (widget-get widget
:custom-state
)
2530 (if (memq (custom-variable-state symbol value
)
2531 (widget-get widget
:hidden-states
))
2534 ;; If we don't know the state, see if we need to edit it in lisp form.
2536 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2537 (when (eq state
'unknown
)
2538 (unless (widget-apply conv
:match value
)
2539 (setq form
'mismatch
)))
2540 ;; Now we can create the child widget.
2541 (cond ((eq custom-buffer-style
'tree
)
2542 (insert prefix
(if last
" `--- " " |--- "))
2543 (push (widget-create-child-and-convert
2544 widget
'custom-browse-variable-tag
)
2546 (insert " " tag
"\n")
2547 (widget-put widget
:buttons buttons
))
2549 ;; Indicate hidden value.
2550 (push (widget-create-child-and-convert
2551 widget
'custom-visibility
2552 :help-echo
"Show the value of this option."
2557 :action
'custom-toggle-hide-variable
2561 (push (widget-create-child-and-convert
2564 :sample-face
'custom-variable-tag
2568 ((memq form
'(lisp mismatch
))
2569 ;; In lisp mode edit the saved value when possible.
2570 (push (widget-create-child-and-convert
2571 widget
'custom-visibility
2572 :help-echo
"Hide the value of this option."
2577 :action
'custom-toggle-hide-variable
2581 (let* ((value (cond ((get symbol
'saved-value
)
2582 (car (get symbol
'saved-value
)))
2583 ((get symbol
'standard-value
)
2584 (car (get symbol
'standard-value
)))
2585 ((default-boundp symbol
)
2586 (custom-quote (funcall get symbol
)))
2588 (custom-quote (widget-get conv
:value
))))))
2589 (insert (symbol-name symbol
) ": ")
2590 (push (widget-create-child-and-convert
2592 :button-face
'custom-variable-button-face
2594 :tag
(symbol-name symbol
)
2600 (push (widget-create-child-and-convert
2601 widget
'custom-visibility
2602 :help-echo
"Hide or show this option."
2607 :action
'custom-toggle-hide-variable
2611 (let* ((format (widget-get type
:format
))
2612 tag-format value-format
)
2613 (unless (string-match ":" format
)
2614 (error "Bad format"))
2615 (setq tag-format
(substring format
0 (match-end 0)))
2616 (setq value-format
(substring format
(match-end 0)))
2617 (push (widget-create-child-and-convert
2620 :action
'custom-tag-action
2621 :help-echo
"Change value of this option."
2622 :mouse-down-action
'custom-tag-mouse-down-action
2623 :button-face
'custom-variable-button
2624 :sample-face
'custom-variable-tag
2627 (push (widget-create-child-and-convert
2629 :format value-format
2632 (unless (eq custom-buffer-style
'tree
)
2633 (unless (eq (preceding-char) ?
\n)
2634 (widget-insert "\n"))
2635 ;; Create the magic button.
2636 (unless (eq style
'simple
)
2637 (let ((magic (widget-create-child-and-convert
2638 widget
'custom-magic nil
)))
2639 (widget-put widget
:custom-magic magic
)
2640 (push magic buttons
)))
2641 (widget-put widget
:buttons buttons
)
2642 ;; Insert documentation.
2643 (widget-put widget
:documentation-indent
3)
2644 (unless (and (eq style
'simple
)
2646 (widget-add-documentation-string-button
2647 widget
:visibility-widget
'custom-visibility
))
2649 ;; The comment field
2650 (unless (eq state
'hidden
)
2651 (let* ((comment (get symbol
'variable-comment
))
2653 (widget-create-child-and-convert
2654 widget
'custom-comment
2656 :value
(or comment
""))))
2657 (widget-put widget
:comment-widget comment-widget
)
2658 ;; Don't push it !!! Custom assumes that the first child is the
2660 (setq children
(append children
(list comment-widget
)))))
2661 ;; Update the rest of the properties.
2662 (widget-put widget
:custom-form form
)
2663 (widget-put widget
:children children
)
2664 ;; Now update the state.
2665 (if (eq state
'hidden
)
2666 (widget-put widget
:custom-state state
)
2667 (custom-variable-state-set widget
))
2669 (unless (eq state
'hidden
)
2670 (when (eq (widget-get widget
:custom-level
) 1)
2671 (custom-add-parent-links widget
))
2672 (custom-add-see-also widget
)))))
2674 (defun custom-toggle-hide-variable (visibility-widget &rest ignore
)
2675 "Toggle the visibility of a `custom-variable' parent widget.
2676 By default, this signals an error if the parent has unsaved
2677 changes. If the parent has a `simple' :custom-style property,
2678 the present value is saved to its :shown-value property instead."
2679 (let ((widget (widget-get visibility-widget
:parent
)))
2680 (unless (eq (widget-type widget
) 'custom-variable
)
2681 (error "Invalid widget type"))
2682 (custom-load-widget widget
)
2683 (let ((state (widget-get widget
:custom-state
)))
2684 (if (eq state
'hidden
)
2685 (widget-put widget
:custom-state
'unknown
)
2686 ;; In normal interface, widget can't be hidden if modified.
2687 (when (memq state
'(invalid modified set
))
2688 (if (eq (widget-get widget
:custom-style
) 'simple
)
2689 (widget-put widget
:shown-value
2692 (widget-get widget
:children
)))))
2693 (error "There are unsaved changes")))
2694 (widget-put widget
:documentation-shown nil
)
2695 (widget-put widget
:custom-state
'hidden
))
2696 (custom-redraw widget
)
2699 (defun custom-tag-action (widget &rest args
)
2700 "Pass :action to first child of WIDGET's parent."
2701 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2704 (defun custom-tag-mouse-down-action (widget &rest args
)
2705 "Pass :mouse-down-action to first child of WIDGET's parent."
2706 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2707 :mouse-down-action args
))
2709 (defun custom-variable-state (symbol val
)
2710 "Return the state of SYMBOL if its value is VAL.
2711 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2712 Possible return values are `standard', `saved', `set', `themed',
2713 `changed', and `rogue'."
2714 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2715 (value (if (default-boundp symbol
)
2716 (funcall get symbol
)
2718 (comment (get symbol
'variable-comment
))
2721 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2723 (get symbol
'customized-variable-comment
))
2725 (if (condition-case nil
2726 (and (equal value
(eval (car tmp
)))
2727 (equal comment temp
))
2731 ((progn (setq tmp
(get symbol
'theme-value
))
2732 (setq temp
(get symbol
'saved-variable-comment
))
2734 (if (condition-case nil
2735 (and (equal comment temp
)
2738 (car (custom-variable-theme-value
2742 ((eq (caar tmp
) 'user
) 'saved
)
2743 ((eq (caar tmp
) 'changed
)
2744 (if (condition-case nil
2748 (car (get symbol
'standard-value
)))))
2750 ;; The value was originally set outside
2751 ;; custom, but it was set to the standard
2752 ;; value (probably an autoloaded defcustom).
2757 ((setq tmp
(get symbol
'standard-value
))
2758 (if (condition-case nil
2759 (and (equal value
(eval (car tmp
)))
2760 (equal comment nil
))
2766 (defun custom-variable-state-set (widget &optional state
)
2767 "Set the state of WIDGET to STATE.
2768 If STATE is nil, the value is computed by `custom-variable-state'."
2769 (widget-put widget
:custom-state
2770 (or state
(custom-variable-state (widget-value widget
)
2771 (widget-get widget
:value
)))))
2773 (defun custom-variable-standard-value (widget)
2774 (get (widget-value widget
) 'standard-value
))
2776 (defvar custom-variable-menu
2777 `(("Set for Current Session" custom-variable-set
2779 (eq (widget-get widget
:custom-state
) 'modified
)))
2780 ;; Note that in all the backquoted code in this file, we test
2781 ;; init-file-user rather than user-init-file. This is in case
2782 ;; cus-edit is loaded by something in site-start.el, because
2783 ;; user-init-file is not set at that stage.
2784 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2785 ,@(when (or custom-file init-file-user
)
2786 '(("Save for Future Sessions" custom-variable-save
2788 (memq (widget-get widget
:custom-state
)
2789 '(modified set changed rogue
))))))
2790 ("Undo Edits" custom-redraw
2792 (and (default-boundp (widget-value widget
))
2793 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2794 ("Reset to Saved" custom-variable-reset-saved
2796 (and (or (get (widget-value widget
) 'saved-value
)
2797 (get (widget-value widget
) 'saved-variable-comment
))
2798 (memq (widget-get widget
:custom-state
)
2799 '(modified set changed rogue
)))))
2800 ,@(when (or custom-file init-file-user
)
2801 '(("Erase Customization" custom-variable-reset-standard
2803 (and (get (widget-value widget
) 'standard-value
)
2804 (memq (widget-get widget
:custom-state
)
2805 '(modified set changed saved rogue
)))))))
2806 ("Set to Backup Value" custom-variable-reset-backup
2808 (get (widget-value widget
) 'backup-value
)))
2809 ("---" ignore ignore
)
2810 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2811 ("---" ignore ignore
)
2812 ("Show Current Value" custom-variable-edit
2814 (eq (widget-get widget
:custom-form
) 'lisp
)))
2815 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2817 (eq (widget-get widget
:custom-form
) 'edit
))))
2818 "Alist of actions for the `custom-variable' widget.
2819 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2820 the menu entry, ACTION is the function to call on the widget when the
2821 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2822 widget as an argument, and returns non-nil if ACTION is valid on that
2823 widget. If FILTER is nil, ACTION is always valid.")
2825 (defun custom-variable-action (widget &optional event
)
2826 "Show the menu for `custom-variable' WIDGET.
2827 Optional EVENT is the location for the menu."
2828 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2829 (custom-toggle-hide widget
)
2830 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2831 (custom-variable-state-set widget
))
2832 (custom-redraw-magic widget
)
2833 (let* ((completion-ignore-case t
)
2834 (answer (widget-choose (concat "Operation on "
2835 (custom-unlispify-tag-name
2836 (widget-get widget
:value
)))
2837 (custom-menu-filter custom-variable-menu
2841 (funcall answer widget
)))))
2843 (defun custom-variable-edit (widget)
2844 "Edit value of WIDGET."
2845 (widget-put widget
:custom-state
'unknown
)
2846 (widget-put widget
:custom-form
'edit
)
2847 (custom-redraw widget
))
2849 (defun custom-variable-edit-lisp (widget)
2850 "Edit the Lisp representation of the value of WIDGET."
2851 (widget-put widget
:custom-state
'unknown
)
2852 (widget-put widget
:custom-form
'lisp
)
2853 (custom-redraw widget
))
2855 (defun custom-variable-set (widget)
2856 "Set the current value for the variable being edited by WIDGET."
2857 (let* ((form (widget-get widget
:custom-form
))
2858 (state (widget-get widget
:custom-state
))
2859 (child (car (widget-get widget
:children
)))
2860 (symbol (widget-value widget
))
2861 (set (or (get symbol
'custom-set
) 'set-default
))
2862 (comment-widget (widget-get widget
:comment-widget
))
2863 (comment (widget-value comment-widget
))
2865 (cond ((eq state
'hidden
)
2866 (error "Cannot set hidden variable"))
2867 ((setq val
(widget-apply child
:validate
))
2868 (goto-char (widget-get val
:from
))
2869 (error "%s" (widget-get val
:error
)))
2870 ((memq form
'(lisp mismatch
))
2871 (when (equal comment
"")
2873 ;; Make the comment invisible by hand if it's empty
2874 (custom-comment-hide comment-widget
))
2875 (custom-variable-backup-value widget
)
2876 (custom-push-theme 'theme-value symbol
'user
2877 'set
(custom-quote (widget-value child
)))
2878 (funcall set symbol
(eval (setq val
(widget-value child
))))
2879 (put symbol
'customized-value
(list val
))
2880 (put symbol
'variable-comment comment
)
2881 (put symbol
'customized-variable-comment comment
))
2883 (when (equal comment
"")
2885 ;; Make the comment invisible by hand if it's empty
2886 (custom-comment-hide comment-widget
))
2887 (custom-variable-backup-value widget
)
2888 (custom-push-theme 'theme-value symbol
'user
2889 'set
(custom-quote (widget-value child
)))
2890 (funcall set symbol
(setq val
(widget-value child
)))
2891 (put symbol
'customized-value
(list (custom-quote val
)))
2892 (put symbol
'variable-comment comment
)
2893 (put symbol
'customized-variable-comment comment
)))
2894 (custom-variable-state-set widget
)
2895 (custom-redraw-magic widget
)))
2897 (defun custom-variable-mark-to-save (widget)
2898 "Set value and mark for saving the variable edited by WIDGET."
2899 (let* ((form (widget-get widget
:custom-form
))
2900 (state (widget-get widget
:custom-state
))
2901 (child (car (widget-get widget
:children
)))
2902 (symbol (widget-value widget
))
2903 (set (or (get symbol
'custom-set
) 'set-default
))
2904 (comment-widget (widget-get widget
:comment-widget
))
2905 (comment (widget-value comment-widget
))
2907 (cond ((eq state
'hidden
)
2908 (error "Cannot set hidden variable"))
2909 ((setq val
(widget-apply child
:validate
))
2910 (goto-char (widget-get val
:from
))
2911 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2912 ((memq form
'(lisp mismatch
))
2913 (when (equal comment
"")
2915 ;; Make the comment invisible by hand if it's empty
2916 (custom-comment-hide comment-widget
))
2917 (put symbol
'saved-value
(list (widget-value child
)))
2918 (custom-push-theme 'theme-value symbol
'user
2919 'set
(custom-quote (widget-value child
)))
2920 (funcall set symbol
(eval (widget-value child
)))
2921 (put symbol
'variable-comment comment
)
2922 (put symbol
'saved-variable-comment comment
))
2924 (when (equal comment
"")
2926 ;; Make the comment invisible by hand if it's empty
2927 (custom-comment-hide comment-widget
))
2928 (put symbol
'saved-value
2929 (list (custom-quote (widget-value child
))))
2930 (custom-push-theme 'theme-value symbol
'user
2931 'set
(custom-quote (widget-value child
)))
2932 (funcall set symbol
(widget-value child
))
2933 (put symbol
'variable-comment comment
)
2934 (put symbol
'saved-variable-comment comment
)))
2935 (put symbol
'customized-value nil
)
2936 (put symbol
'customized-variable-comment nil
)))
2938 (defsubst custom-variable-state-set-and-redraw
(widget)
2939 "Set state of variable widget WIDGET and redraw with current settings."
2940 (custom-variable-state-set widget
)
2941 (custom-redraw-magic widget
))
2943 (defun custom-variable-save (widget)
2944 "Save value of variable edited by widget WIDGET."
2945 (custom-variable-mark-to-save widget
)
2947 (custom-variable-state-set-and-redraw widget
))
2949 (defun custom-variable-reset-saved (widget)
2950 "Restore the saved value for the variable being edited by WIDGET.
2951 This also updates the buffer to show that value.
2952 The value that was current before this operation
2953 becomes the backup value, so you can get it again."
2954 (let* ((symbol (widget-value widget
))
2955 (set (or (get symbol
'custom-set
) 'set-default
))
2956 (value (get symbol
'saved-value
))
2957 (comment (get symbol
'saved-variable-comment
)))
2958 (cond ((or value comment
)
2959 (put symbol
'variable-comment comment
)
2960 (custom-variable-backup-value widget
)
2961 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2963 (funcall set symbol
(eval (car value
)))
2966 (error "No saved value for %s" symbol
)))
2967 (put symbol
'customized-value nil
)
2968 (put symbol
'customized-variable-comment nil
)
2969 (widget-put widget
:custom-state
'unknown
)
2970 ;; This call will possibly make the comment invisible
2971 (custom-redraw widget
)))
2973 (defun custom-variable-mark-to-reset-standard (widget)
2974 "Mark to restore standard setting for the variable edited by widget WIDGET.
2975 If `custom-reset-standard-variables-list' is nil, save, reset and
2976 redraw the widget immediately."
2977 (let* ((symbol (widget-value widget
)))
2978 (if (get symbol
'standard-value
)
2979 (custom-variable-backup-value widget
)
2980 (error "No standard setting known for %S" symbol
))
2981 (put symbol
'variable-comment nil
)
2982 (put symbol
'customized-value nil
)
2983 (put symbol
'customized-variable-comment nil
)
2984 (custom-push-theme 'theme-value symbol
'user
'reset
)
2985 (custom-theme-recalc-variable symbol
)
2986 (if (and custom-reset-standard-variables-list
2987 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2989 (put symbol
'saved-value nil
)
2990 (put symbol
'saved-variable-comment nil
)
2991 ;; Append this to `custom-reset-standard-variables-list' to
2992 ;; have `custom-reset-standard-save-and-update' save setting
2993 ;; to the file, update the widget's state, and redraw it.
2994 (setq custom-reset-standard-variables-list
2995 (cons widget custom-reset-standard-variables-list
)))
2996 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2997 (put symbol
'saved-value nil
)
2998 (put symbol
'saved-variable-comment nil
)
3000 (widget-put widget
:custom-state
'unknown
)
3001 ;; This call will possibly make the comment invisible
3002 (custom-redraw widget
))))
3004 (defun custom-variable-reset-standard (widget)
3005 "Restore standard setting for the variable edited by WIDGET.
3006 This operation eliminates any saved setting for the variable,
3007 restoring it to the state of a variable that has never been customized.
3008 The value that was current before this operation
3009 becomes the backup value, so you can get it again."
3010 (let (custom-reset-standard-variables-list)
3011 (custom-variable-mark-to-reset-standard widget
)))
3013 (defun custom-variable-backup-value (widget)
3014 "Back up the current value for WIDGET's variable.
3015 The backup value is kept in the car of the `backup-value' property."
3016 (let* ((symbol (widget-value widget
))
3017 (get (or (get symbol
'custom-get
) 'default-value
))
3018 (type (custom-variable-type symbol
))
3019 (conv (widget-convert type
))
3020 (value (if (default-boundp symbol
)
3021 (funcall get symbol
)
3022 (widget-get conv
:value
))))
3023 (put symbol
'backup-value
(list value
))))
3025 (defun custom-variable-reset-backup (widget)
3026 "Restore the backup value for the variable being edited by WIDGET.
3027 The value that was current before this operation
3028 becomes the backup value, so you can use this operation repeatedly
3029 to switch between two values."
3030 (let* ((symbol (widget-value widget
))
3031 (set (or (get symbol
'custom-set
) 'set-default
))
3032 (value (get symbol
'backup-value
))
3033 (comment-widget (widget-get widget
:comment-widget
))
3034 (comment (widget-value comment-widget
)))
3037 (custom-variable-backup-value widget
)
3038 (custom-push-theme 'theme-value symbol
'user
'set value
)
3040 (funcall set symbol
(car value
))
3042 (error "No backup value for %s" symbol
))
3043 (put symbol
'customized-value
(list (car value
)))
3044 (put symbol
'variable-comment comment
)
3045 (put symbol
'customized-variable-comment comment
)
3046 (custom-variable-state-set widget
)
3047 ;; This call will possibly make the comment invisible
3048 (custom-redraw widget
)))
3050 ;;; The `custom-visibility' Widget
3052 (define-widget 'custom-visibility
'visibility
3053 "Show or hide a documentation string."
3054 :button-face
'custom-visibility
3055 :pressed-face
'custom-visibility
3056 :mouse-face
'highlight
3057 :pressed-face
'highlight
3061 (defface custom-visibility
3062 '((t :height
0.8 :inherit link
))
3063 "Face for the `custom-visibility' widget."
3065 :group
'custom-faces
)
3067 ;;; The `custom-face-edit' Widget.
3069 (define-widget 'custom-face-edit
'checklist
3070 "Widget for editing face attributes.
3071 The following properties have special meanings for this widget:
3073 :value is a plist of face attributes.
3075 :default-face-attributes, if non-nil, is a plist of defaults for
3076 face attributes (as specified by a `default' defface entry)."
3079 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3080 :value-to-internal
'custom-face-edit-fix-value
3081 :match
(lambda (widget value
)
3082 (widget-checklist-match widget
3083 (custom-face-edit-fix-value widget value
)))
3084 :value-create
'custom-face-edit-value-create
3085 :convert-widget
'custom-face-edit-convert-widget
3086 :args
(mapcar (lambda (att)
3087 (list 'group
:inline t
3088 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3089 (list 'const
:format
"" :value
(nth 0 att
))
3091 custom-face-attributes
))
3093 (defun custom-face-edit-value-create (widget)
3094 (let* ((alist (widget-checklist-match-find
3095 widget
(widget-get widget
:value
)))
3096 (args (widget-get widget
:args
))
3097 (show-all (widget-get widget
:show-all-attributes
))
3098 (buttons (widget-get widget
:buttons
))
3099 (defaults (widget-checklist-match-find
3101 (widget-get widget
:default-face-attributes
)))
3103 (unless (looking-back "^ *")
3105 (insert-char ?\s
(widget-get widget
:extra-offset
))
3106 (if (or alist defaults show-all
)
3108 (setq entry
(or (assq prop alist
)
3109 (assq prop defaults
)))
3110 (if (or entry show-all
)
3111 (widget-checklist-add-item widget prop entry
)))
3112 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3113 (let ((indent (widget-get widget
:indent
)))
3114 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3115 (push (widget-create-child-and-convert
3117 :help-echo
"Show or hide all face attributes."
3118 :button-face
'custom-visibility
3119 :pressed-face
'custom-visibility
3120 :mouse-face
'highlight
3121 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3122 :on-glyph nil
:off-glyph nil
3124 :action
'custom-face-edit-value-visibility-action
3128 (widget-put widget
:buttons buttons
)
3129 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3131 (defun custom-face-edit-value-visibility-action (widget &rest ignore
)
3132 ;; Toggle hiding of face attributes.
3133 (let ((parent (widget-get widget
:parent
)))
3134 (widget-put parent
:show-all-attributes
3135 (not (widget-get parent
:show-all-attributes
)))
3136 (custom-redraw parent
)))
3138 (defun custom-face-edit-fix-value (widget value
)
3139 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3140 Also change :reverse-video to :inverse-video."
3141 (custom-fix-face-spec value
))
3143 (defun custom-face-edit-convert-widget (widget)
3144 "Convert :args as widget types in WIDGET."
3147 :args
(mapcar (lambda (arg)
3149 :deactivate
'custom-face-edit-deactivate
3150 :activate
'custom-face-edit-activate
3151 :delete
'custom-face-edit-delete
))
3152 (widget-get widget
:args
)))
3155 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3156 "Converted version of the `custom-face-edit' widget.")
3158 (defun custom-face-edit-deactivate (widget)
3159 "Make face widget WIDGET inactive for user modifications."
3160 (unless (widget-get widget
:inactive
)
3161 (let ((tag (custom-face-edit-attribute-tag widget
))
3162 (from (copy-marker (widget-get widget
:from
)))
3163 (value (widget-value widget
))
3164 (inhibit-read-only t
)
3165 (inhibit-modification-hooks t
))
3168 (widget-default-delete widget
)
3169 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3170 (widget-put widget
:inactive
3171 (cons value
(cons from
(- (point) from
))))))))
3173 (defun custom-face-edit-activate (widget)
3174 "Make face widget WIDGET active for user modifications."
3175 (let ((inactive (widget-get widget
:inactive
))
3176 (inhibit-read-only t
)
3177 (inhibit-modification-hooks t
))
3178 (when (consp inactive
)
3180 (goto-char (car (cdr inactive
)))
3181 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3182 (widget-put widget
:inactive nil
)
3183 (widget-apply widget
:create
)
3184 (widget-value-set widget
(car inactive
))
3187 (defun custom-face-edit-delete (widget)
3188 "Remove WIDGET from the buffer."
3189 (let ((inactive (widget-get widget
:inactive
))
3190 (inhibit-read-only t
)
3191 (inhibit-modification-hooks t
))
3193 ;; Widget is alive, we don't have to do anything special
3194 (widget-default-delete widget
)
3195 ;; WIDGET is already deleted because we did so to inactivate it;
3196 ;; now just get rid of the label we put in its place.
3197 (delete-region (car (cdr inactive
))
3198 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3199 (widget-put widget
:inactive nil
))))
3202 (defun custom-face-edit-attribute-tag (widget)
3203 "Return the first :tag property in WIDGET or one of its children."
3204 (let ((tag (widget-get widget
:tag
)))
3205 (or (and (not (equal tag
"")) tag
)
3206 (let ((children (widget-get widget
:children
)))
3207 (while (and (null tag
) children
)
3208 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3211 ;;; The `custom-display' Widget.
3213 (define-widget 'custom-display
'menu-choice
3214 "Select a display type."
3217 :help-echo
"Specify frames where the face attributes should be used."
3218 :args
'((const :tag
"all" t
)
3219 (const :tag
"defaults" default
)
3223 :args
((group :sibling-args
(:help-echo
"\
3224 Only match the specified window systems.")
3225 (const :format
"Type: "
3227 (checklist :inline t
3230 :sibling-args
(:help-echo
"\
3231 The X11 Window System.")
3233 (const :format
"PM "
3234 :sibling-args
(:help-echo
"\
3235 OS/2 Presentation Manager.")
3237 (const :format
"W32 "
3238 :sibling-args
(:help-echo
"\
3241 (const :format
"NS "
3242 :sibling-args
(:help-echo
"\
3243 GNUstep or Macintosh OS Cocoa interface.")
3245 (const :format
"DOS "
3246 :sibling-args
(:help-echo
"\
3249 (const :format
"TTY%n"
3250 :sibling-args
(:help-echo
"\
3251 Plain text terminals.")
3253 (group :sibling-args
(:help-echo
"\
3254 Only match the frames with the specified color support.")
3255 (const :format
"Class: "
3257 (checklist :inline t
3259 (const :format
"Color "
3260 :sibling-args
(:help-echo
"\
3261 Match color frames.")
3263 (const :format
"Grayscale "
3264 :sibling-args
(:help-echo
"\
3265 Match grayscale frames.")
3267 (const :format
"Monochrome%n"
3268 :sibling-args
(:help-echo
"\
3269 Match frames with no color support.")
3271 (group :sibling-args
(:help-echo
"\
3272 The minimum number of colors the frame should support.")
3273 (const :format
"" min-colors
)
3274 (integer :tag
"Minimum number of colors" ))
3275 (group :sibling-args
(:help-echo
"\
3276 Only match frames with the specified intensity.")
3278 Background brightness: "
3280 (checklist :inline t
3282 (const :format
"Light "
3283 :sibling-args
(:help-echo
"\
3284 Match frames with light backgrounds.")
3286 (const :format
"Dark\n"
3287 :sibling-args
(:help-echo
"\
3288 Match frames with dark backgrounds.")
3290 (group :sibling-args
(:help-echo
"\
3291 Only match frames that support the specified face attributes.")
3292 (const :format
"Supports attributes:" supports
)
3293 (custom-face-edit :inline t
:format
"%n%v"))))))
3295 ;;; The `custom-face' Widget.
3297 (defface custom-face-tag
3298 `((t :inherit custom-variable-tag
))
3299 "Face used for face tags."
3300 :group
'custom-faces
)
3301 (define-obsolete-face-alias 'custom-face-tag-face
'custom-face-tag
"22.1")
3303 (defcustom custom-face-default-form
'selected
3304 "Default form of displaying face definition."
3305 :type
'(choice (const all
)
3308 :group
'custom-buffer
3311 (define-widget 'custom-face
'custom
3312 "Widget for customizing a face.
3313 The following properties have special meanings for this widget:
3315 :value is the face name (a symbol).
3317 :custom-form should be a symbol describing how to display and
3318 edit the face attributes---either `selected' (attributes for
3319 selected display only), `all' (all attributes), `lisp' (as a
3320 Lisp sexp), or `mismatch' (should not happen); if nil, use
3321 the return value of `custom-face-default-form'.
3323 :custom-style describes the widget interface style; nil is the
3324 default style, while `simple' means a simpler interface that
3325 inhibits the magic custom-state widget.
3327 :sample-indent, if non-nil, is the number of columns to which to
3328 indent the face sample (an integer).
3330 :shown-value, if non-nil, is the face spec to display as the value
3331 of the widget, instead of the current face spec."
3332 :sample-face
'custom-face-tag
3333 :help-echo
"Set or reset this face."
3334 :documentation-property
#'face-doc-string
3335 :value-create
'custom-face-value-create
3336 :action
'custom-face-action
3337 :custom-category
'face
3339 :custom-set
'custom-face-set
3340 :custom-mark-to-save
'custom-face-mark-to-save
3341 :custom-reset-current
'custom-redraw
3342 :custom-reset-saved
'custom-face-reset-saved
3343 :custom-reset-standard
'custom-face-reset-standard
3344 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3345 :custom-standard-value
'custom-face-standard-value
3346 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3347 :custom-menu
'custom-face-menu-create
)
3349 (define-widget 'custom-face-all
'editable-list
3350 "An editable list of display specifications and attributes."
3351 :entry-format
"%i %d %v"
3352 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3353 :append-button-args
'(:help-echo
"Append new display specification here.")
3354 :delete-button-args
'(:help-echo
"Delete this display specification.")
3355 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3357 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3358 "Converted version of the `custom-face-all' widget.")
3360 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3361 "Return a canonicalized version of SPEC using.
3362 FILTER-INDEX is the index in the entry for each attribute in
3363 `custom-face-attributes' at which the appropriate filter function can be
3364 found, and DEFAULT-FILTER is the filter to apply for attributes that
3366 (mapcar (lambda (entry)
3367 ;; Filter a single face-spec entry
3368 (let ((tests (car entry
))
3370 ;; Handle both old- and new-style attribute syntax
3371 (if (listp (car (cdr entry
)))
3374 (filtered-attrs nil
))
3375 ;; Filter each face attribute
3376 (while unfiltered-attrs
3377 (let* ((attr (pop unfiltered-attrs
))
3378 (pre-filtered-value (pop unfiltered-attrs
))
3380 (or (nth filter-index
(assq attr custom-face-attributes
))
3384 (funcall filter pre-filtered-value
)
3385 pre-filtered-value
)))
3386 (push filtered-value filtered-attrs
)
3387 (push attr filtered-attrs
)))
3389 (list tests filtered-attrs
)))
3392 (defun custom-pre-filter-face-spec (spec)
3393 "Return SPEC changed as necessary for editing by the face customization widget.
3394 SPEC must be a full face spec."
3395 (custom-filter-face-spec spec
2))
3397 (defun custom-post-filter-face-spec (spec)
3398 "Return the customized SPEC in a form suitable for setting the face."
3399 (custom-filter-face-spec spec
3))
3401 (defun custom-face-widget-to-spec (widget)
3402 "Return a face spec corresponding to WIDGET.
3403 WIDGET should be a `custom-face' widget."
3404 (unless (eq (widget-type widget
) 'custom-face
)
3405 (error "Invalid widget"))
3406 (let ((child (car (widget-get widget
:children
))))
3407 (custom-post-filter-face-spec
3408 (if (eq (widget-type child
) 'custom-face-edit
)
3409 `((t ,(widget-value child
)))
3410 (widget-value child
)))))
3412 (defun custom-face-get-current-spec (face)
3413 (let ((spec (or (get face
'customized-face
)
3414 (get face
'saved-face
)
3415 (get face
'face-defface-spec
)
3416 ;; Attempt to construct it.
3417 `((t ,(custom-face-attributes-get
3418 face
(selected-frame)))))))
3419 ;; If the user has changed this face in some other way,
3420 ;; edit it as the user has specified it.
3421 (if (not (face-spec-match-p face spec
(selected-frame)))
3422 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3423 (custom-pre-filter-face-spec spec
)))
3425 (defun custom-toggle-hide-face (visibility-widget &rest ignore
)
3426 "Toggle the visibility of a `custom-face' parent widget.
3427 By default, this signals an error if the parent has unsaved
3428 changes. If the parent has a `simple' :custom-style property,
3429 the present value is saved to its :shown-value property instead."
3430 (let ((widget (widget-get visibility-widget
:parent
)))
3431 (unless (eq (widget-type widget
) 'custom-face
)
3432 (error "Invalid widget type"))
3433 (custom-load-widget widget
)
3434 (let ((state (widget-get widget
:custom-state
)))
3435 (if (eq state
'hidden
)
3436 (widget-put widget
:custom-state
'unknown
)
3437 ;; In normal interface, widget can't be hidden if modified.
3438 (when (memq state
'(invalid modified set
))
3439 (if (eq (widget-get widget
:custom-style
) 'simple
)
3440 (widget-put widget
:shown-value
3441 (custom-face-widget-to-spec widget
))
3442 (error "There are unsaved changes")))
3443 (widget-put widget
:documentation-shown nil
)
3444 (widget-put widget
:custom-state
'hidden
))
3445 (custom-redraw widget
)
3448 (defun custom-face-value-create (widget)
3449 "Create a list of the display specifications for WIDGET."
3450 (let* ((buttons (widget-get widget
:buttons
))
3451 (symbol (widget-get widget
:value
))
3452 (tag (or (widget-get widget
:tag
)
3453 (prin1-to-string symbol
)))
3454 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3455 (style (widget-get widget
:custom-style
))
3458 (if (eq custom-buffer-style
'tree
)
3460 ;; Draw a tree-style `custom-face' widget
3462 (insert (widget-get widget
:custom-prefix
)
3463 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3464 (push (widget-create-child-and-convert
3465 widget
'custom-browse-face-tag
)
3467 (insert " " tag
"\n")
3468 (widget-put widget
:buttons buttons
))
3470 ;; Draw an ordinary `custom-face' widget
3471 (let ((opoint (point)))
3472 ;; Visibility indicator.
3473 (push (widget-create-child-and-convert
3474 widget
'custom-visibility
3475 :help-echo
"Hide or show this face."
3476 :on
"Hide" :off
"Show"
3477 :on-glyph
"down" :off-glyph
"right"
3478 :action
'custom-toggle-hide-face
3483 (widget-specify-sample widget opoint
(point)))
3485 (cond ((eq custom-buffer-style
'face
) " ")
3486 ((string-match "face\\'" tag
) ":")
3490 (let ((sample-indent (widget-get widget
:sample-indent
))
3491 (indent-tabs-mode nil
))
3493 (<= (current-column) sample-indent
)
3494 (indent-to-column sample-indent
)))
3495 (push (widget-create-child-and-convert
3498 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3499 (if spec
(face-spec-choose spec
) symbol
))
3505 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3506 (let ((magic (widget-create-child-and-convert
3507 widget
'custom-magic nil
)))
3508 (widget-put widget
:custom-magic magic
)
3509 (push magic buttons
)))
3512 (widget-put widget
:buttons buttons
)
3514 ;; Insert documentation.
3515 (unless (and hiddenp
(eq style
'simple
))
3516 (widget-put widget
:documentation-indent
3)
3517 (widget-add-documentation-string-button
3518 widget
:visibility-widget
'custom-visibility
)
3519 ;; The comment field
3521 (let* ((comment (get symbol
'face-comment
))
3523 (widget-create-child-and-convert
3524 widget
'custom-comment
3526 :value
(or comment
""))))
3527 (widget-put widget
:comment-widget comment-widget
)
3528 (push comment-widget children
))))
3531 (unless (eq (preceding-char) ?
\n)
3534 (custom-load-widget widget
)
3535 (unless (widget-get widget
:custom-form
)
3536 (widget-put widget
:custom-form custom-face-default-form
))
3538 (let* ((spec (or (widget-get widget
:shown-value
)
3539 (custom-face-get-current-spec symbol
)))
3540 (form (widget-get widget
:custom-form
))
3541 (indent (widget-get widget
:indent
))
3542 face-alist face-entry spec-default spec-match editor
)
3544 ;; Find a display in SPEC matching the selected display.
3545 ;; This will use the usual face customization interface.
3546 (setq face-alist spec
)
3547 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3548 (setq spec-default
(pop face-alist
)))
3550 (while (and face-alist
(listp face-alist
) (null spec-match
))
3551 (setq face-entry
(car face-alist
))
3552 (and (listp face-entry
)
3553 (face-spec-set-match-display (car face-entry
)
3555 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3556 (setq spec-match face-entry
))
3557 (setq face-alist
(cdr face-alist
)))
3559 ;; Insert the appropriate editing widget.
3562 ((and (eq form
'selected
)
3563 (or spec-match spec-default
))
3564 (when indent
(insert-char ?\s indent
))
3565 (widget-create-child-and-convert
3566 widget
'custom-face-edit
3567 :value
(cadr spec-match
)
3568 :default-face-attributes
(cadr spec-default
)))
3569 ((and (not (eq form
'lisp
))
3570 (widget-apply custom-face-all
:match spec
))
3571 (widget-create-child-and-convert
3572 widget
'custom-face-all
:value spec
))
3575 (insert-char ?\s indent
))
3576 (widget-create-child-and-convert
3577 widget
'sexp
:value spec
))))
3578 (custom-face-state-set widget
)
3579 (push editor children
)
3580 (widget-put widget
:children children
))))))
3582 (defvar custom-face-menu
3583 `(("Set for Current Session" custom-face-set
)
3584 ,@(when (or custom-file init-file-user
)
3585 '(("Save for Future Sessions" custom-face-save
)))
3586 ("Undo Edits" custom-redraw
3588 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3589 ("Reset to Saved" custom-face-reset-saved
3591 (or (get (widget-value widget
) 'saved-face
)
3592 (get (widget-value widget
) 'saved-face-comment
))))
3593 ,@(when (or custom-file init-file-user
)
3594 '(("Erase Customization" custom-face-reset-standard
3596 (get (widget-value widget
) 'face-defface-spec
)))))
3597 ("---" ignore ignore
)
3598 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3599 ("---" ignore ignore
)
3600 ("For Current Display" custom-face-edit-selected
3602 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3603 ("For All Kinds of Displays" custom-face-edit-all
3605 (not (eq (widget-get widget
:custom-form
) 'all
))))
3606 ("Show Lisp Expression" custom-face-edit-lisp
3608 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3609 "Alist of actions for the `custom-face' widget.
3610 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3611 the menu entry, ACTION is the function to call on the widget when the
3612 menu is selected, and FILTER is a predicate which takes a `custom-face'
3613 widget as an argument, and returns non-nil if ACTION is valid on that
3614 widget. If FILTER is nil, ACTION is always valid.")
3616 (defun custom-face-edit-selected (widget)
3617 "Edit selected attributes of the value of WIDGET."
3618 (widget-put widget
:custom-state
'unknown
)
3619 (widget-put widget
:custom-form
'selected
)
3620 (custom-redraw widget
))
3622 (defun custom-face-edit-all (widget)
3623 "Edit all attributes of the value of WIDGET."
3624 (widget-put widget
:custom-state
'unknown
)
3625 (widget-put widget
:custom-form
'all
)
3626 (custom-redraw widget
))
3628 (defun custom-face-edit-lisp (widget)
3629 "Edit the Lisp representation of the value of WIDGET."
3630 (widget-put widget
:custom-state
'unknown
)
3631 (widget-put widget
:custom-form
'lisp
)
3632 (custom-redraw widget
))
3634 (defun custom-face-state (face)
3635 "Return the current state of the face FACE.
3636 This is one of `set', `saved', `changed', `themed', or `rogue'."
3637 (let* ((comment (get face
'face-comment
))
3640 ((or (get face
'customized-face
)
3641 (get face
'customized-face-comment
))
3642 (if (equal (get face
'customized-face-comment
) comment
)
3645 ((or (get face
'saved-face
)
3646 (get face
'saved-face-comment
))
3647 (if (equal (get face
'saved-face-comment
) comment
)
3649 ((eq 'user
(caar (get face
'theme-face
)))
3651 ((eq 'changed
(caar (get face
'theme-face
)))
3655 ((get face
'face-defface-spec
)
3656 (if (equal comment nil
)
3660 ;; If the user called set-face-attribute to change the default for
3661 ;; new frames, this face is "set outside of Customize".
3662 (if (and (not (eq state
'rogue
))
3663 (get face
'face-modified
))
3667 (defun custom-face-state-set (widget)
3668 "Set the state of WIDGET."
3669 (widget-put widget
:custom-state
3670 (custom-face-state (widget-value widget
))))
3672 (defun custom-face-action (widget &optional event
)
3673 "Show the menu for `custom-face' WIDGET.
3674 Optional EVENT is the location for the menu."
3675 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3676 (custom-toggle-hide widget
)
3677 (let* ((completion-ignore-case t
)
3678 (symbol (widget-get widget
:value
))
3679 (answer (widget-choose (concat "Operation on "
3680 (custom-unlispify-tag-name symbol
))
3681 (custom-menu-filter custom-face-menu
3685 (funcall answer widget
)))))
3687 (defun custom-face-set (widget)
3688 "Make the face attributes in WIDGET take effect."
3689 (let* ((symbol (widget-value widget
))
3690 (value (custom-face-widget-to-spec widget
))
3691 (comment-widget (widget-get widget
:comment-widget
))
3692 (comment (widget-value comment-widget
)))
3693 (when (equal comment
"")
3695 ;; Make the comment invisible by hand if it's empty
3696 (custom-comment-hide comment-widget
))
3697 (put symbol
'customized-face value
)
3698 (custom-push-theme 'theme-face symbol
'user
'set value
)
3699 (if (face-spec-choose value
)
3700 (face-spec-set symbol value t
)
3701 ;; face-set-spec ignores empty attribute lists, so just give it
3702 ;; something harmless instead.
3703 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3704 (put symbol
'customized-face-comment comment
)
3705 (put symbol
'face-comment comment
)
3706 (custom-face-state-set widget
)
3707 (custom-redraw-magic widget
)))
3709 (defun custom-face-mark-to-save (widget)
3710 "Mark for saving the face edited by WIDGET."
3711 (let* ((symbol (widget-value widget
))
3712 (value (custom-face-widget-to-spec widget
))
3713 (comment-widget (widget-get widget
:comment-widget
))
3714 (comment (widget-value comment-widget
)))
3715 (when (equal comment
"")
3717 ;; Make the comment invisible by hand if it's empty
3718 (custom-comment-hide comment-widget
))
3719 (custom-push-theme 'theme-face symbol
'user
'set value
)
3720 (if (face-spec-choose value
)
3721 (face-spec-set symbol value t
)
3722 ;; face-set-spec ignores empty attribute lists, so just give it
3723 ;; something harmless instead.
3724 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3725 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3726 (put symbol
'saved-face value
))
3727 (put symbol
'customized-face nil
)
3728 (put symbol
'face-comment comment
)
3729 (put symbol
'customized-face-comment nil
)
3730 (put symbol
'saved-face-comment comment
)))
3732 (defsubst custom-face-state-set-and-redraw
(widget)
3733 "Set state of face widget WIDGET and redraw with current settings."
3734 (custom-face-state-set widget
)
3735 (custom-redraw-magic widget
))
3737 (defun custom-face-save (widget)
3738 "Save the face edited by WIDGET."
3739 (custom-face-mark-to-save widget
)
3741 (custom-face-state-set-and-redraw widget
))
3743 ;; For backward compatibility.
3744 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3747 (defun custom-face-reset-saved (widget)
3748 "Restore WIDGET to the face's default attributes."
3749 (let* ((symbol (widget-value widget
))
3750 (child (car (widget-get widget
:children
)))
3751 (value (get symbol
'saved-face
))
3752 (comment (get symbol
'saved-face-comment
))
3753 (comment-widget (widget-get widget
:comment-widget
)))
3754 (unless (or value comment
)
3755 (error "No saved value for this face"))
3756 (put symbol
'customized-face nil
)
3757 (put symbol
'customized-face-comment nil
)
3758 (custom-push-theme 'theme-face symbol
'user
'set value
)
3759 (face-spec-set symbol value t
)
3760 (put symbol
'face-comment comment
)
3761 (widget-value-set child value
)
3762 ;; This call manages the comment visibility
3763 (widget-value-set comment-widget
(or comment
""))
3764 (custom-face-state-set widget
)
3765 (custom-redraw-magic widget
)))
3767 (defun custom-face-standard-value (widget)
3768 (get (widget-value widget
) 'face-defface-spec
))
3770 (defun custom-face-mark-to-reset-standard (widget)
3771 "Restore widget WIDGET to the face's standard attribute values.
3772 If `custom-reset-standard-faces-list' is nil, save, reset and
3773 redraw the widget immediately."
3774 (let* ((symbol (widget-value widget
))
3775 (child (car (widget-get widget
:children
)))
3776 (value (get symbol
'face-defface-spec
))
3777 (comment-widget (widget-get widget
:comment-widget
)))
3779 (error "No standard setting for this face"))
3780 (put symbol
'customized-face nil
)
3781 (put symbol
'customized-face-comment nil
)
3782 (custom-push-theme 'theme-face symbol
'user
'reset
)
3783 (face-spec-set symbol value t
)
3784 (custom-theme-recalc-face symbol
)
3785 (if (and custom-reset-standard-faces-list
3786 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3789 (put symbol
'saved-face nil
)
3790 (put symbol
'saved-face-comment nil
)
3791 ;; Append this to `custom-reset-standard-faces-list' and have
3792 ;; `custom-reset-standard-save-and-update' save setting to the
3793 ;; file, update the widget's state, and redraw it.
3794 (setq custom-reset-standard-faces-list
3795 (cons widget custom-reset-standard-faces-list
)))
3796 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3797 (put symbol
'saved-face nil
)
3798 (put symbol
'saved-face-comment nil
)
3800 (put symbol
'face-comment nil
)
3801 (widget-value-set child
3802 (custom-pre-filter-face-spec
3803 (list (list t
(custom-face-attributes-get
3805 ;; This call manages the comment visibility
3806 (widget-value-set comment-widget
"")
3807 (custom-face-state-set widget
)
3808 (custom-redraw-magic widget
))))
3810 (defun custom-face-reset-standard (widget)
3811 "Restore WIDGET to the face's standard attribute values.
3812 This operation eliminates any saved attributes for the face,
3813 restoring it to the state of a face that has never been customized."
3814 (let (custom-reset-standard-faces-list)
3815 (custom-face-mark-to-reset-standard widget
)))
3817 ;;; The `face' Widget.
3819 (defvar widget-face-prompt-value-history nil
3820 "History of input to `widget-face-prompt-value'.")
3822 (define-widget 'face
'symbol
3823 "A Lisp face name (with sample)."
3824 :format
"%{%t%}: (%{sample%}) %v"
3827 :sample-face-get
'widget-face-sample-face-get
3828 :notify
'widget-face-notify
3829 :match
(lambda (widget value
) (facep value
))
3830 :complete-function
(lambda ()
3832 (lisp-complete-symbol 'facep
))
3833 :prompt-match
'facep
3834 :prompt-history
'widget-face-prompt-value-history
3835 :validate
(lambda (widget)
3836 (unless (facep (widget-value widget
))
3838 :error
(format "Invalid face: %S"
3839 (widget-value widget
)))
3842 (defun widget-face-sample-face-get (widget)
3843 (let ((value (widget-value widget
)))
3848 (defun widget-face-notify (widget child
&optional event
)
3849 "Update the sample, and notify the parent."
3850 (overlay-put (widget-get widget
:sample-overlay
)
3851 'face
(widget-apply widget
:sample-face-get
))
3852 (widget-default-notify widget child event
))
3855 ;;; The `hook' Widget.
3857 (define-widget 'hook
'list
3858 "An Emacs Lisp hook."
3859 :value-to-internal
(lambda (widget value
)
3860 (if (and value
(symbolp value
))
3863 :match
(lambda (widget value
)
3865 (widget-group-match widget value
)))
3866 ;; Avoid adding undefined functions to the hook, especially for
3867 ;; things like `find-file-hook' or even more basic ones, to avoid
3869 :set
(lambda (symbol value
)
3872 (add-hook symbol elt
))))
3873 :convert-widget
'custom-hook-convert-widget
3876 (defun custom-hook-convert-widget (widget)
3877 ;; Handle `:options'.
3878 (let* ((options (widget-get widget
:options
))
3879 (other `(editable-list :inline t
3880 :entry-format
"%i %d%v"
3881 (function :format
" %v")))
3883 (list `(checklist :inline t
3884 ,@(mapcar (lambda (entry)
3885 `(function-item ,entry
))
3889 (widget-put widget
:args args
)
3892 ;;; The `custom-group-link' Widget.
3894 (define-widget 'custom-group-link
'link
3895 "Show parent in other window when activated."
3896 :button-face
'custom-link
3897 :mouse-face
'highlight
3898 :pressed-face
'highlight
3899 :help-echo
"Create customization buffer for this group."
3900 :keymap custom-mode-link-map
3901 :follow-link
'mouse-face
3902 :action
'custom-group-link-action
)
3904 (defun custom-group-link-action (widget &rest ignore
)
3905 (customize-group (widget-value widget
)))
3907 ;;; The `custom-group' Widget.
3909 (defcustom custom-group-tag-faces nil
3910 ;; In XEmacs, this ought to play games with font size.
3911 ;; Fixme: make it do so in Emacs.
3912 "Face used for group tags.
3913 The first member is used for level 1 groups, the second for level 2,
3914 and so forth. The remaining group tags are shown with `custom-group-tag'."
3915 :type
'(repeat face
)
3916 :group
'custom-faces
)
3918 (defface custom-group-tag-1
3921 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3922 (((min-colors 88) (class color
)
3924 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3927 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3929 "Face used for group tags."
3930 :group
'custom-faces
)
3931 (define-obsolete-face-alias 'custom-group-tag-face-1
'custom-group-tag-1
"22.1")
3933 (defface custom-group-tag
3936 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3937 (((min-colors 88) (class color
)
3939 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3942 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3944 "Face used for low level group tags."
3945 :group
'custom-faces
)
3946 (define-obsolete-face-alias 'custom-group-tag-face
'custom-group-tag
"22.1")
3948 (define-widget 'custom-group
'custom
3951 :sample-face-get
'custom-group-sample-face-get
3952 :documentation-property
'group-documentation
3953 :help-echo
"Set or reset all members of this group."
3954 :value-create
'custom-group-value-create
3955 :action
'custom-group-action
3956 :custom-category
'group
3957 :custom-set
'custom-group-set
3958 :custom-mark-to-save
'custom-group-mark-to-save
3959 :custom-reset-current
'custom-group-reset-current
3960 :custom-reset-saved
'custom-group-reset-saved
3961 :custom-reset-standard
'custom-group-reset-standard
3962 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3963 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3964 :custom-menu
'custom-group-menu-create
)
3966 (defun custom-group-sample-face-get (widget)
3967 ;; Use :sample-face.
3968 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3971 (define-widget 'custom-group-visibility
'visibility
3972 "An indicator and manipulator for hidden group contents."
3973 :create
'custom-group-visibility-create
)
3975 (defun custom-group-visibility-create (widget)
3976 (let ((visible (widget-value widget
)))
3978 (insert "--------")))
3979 (widget-default-create widget
))
3981 (defun custom-group-members (symbol groups-only
)
3982 "Return SYMBOL's custom group members.
3983 If GROUPS-ONLY non-nil, return only those members that are groups."
3984 (if (not groups-only
)
3985 (get symbol
'custom-group
)
3987 (dolist (entry (get symbol
'custom-group
))
3988 (when (eq (nth 1 entry
) 'custom-group
)
3989 (push entry members
)))
3990 (nreverse members
))))
3992 (defun custom-group-value-create (widget)
3993 "Insert a customize group for WIDGET in the current buffer."
3994 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3995 (custom-load-widget widget
))
3996 (let* ((state (widget-get widget
:custom-state
))
3997 (level (widget-get widget
:custom-level
))
3998 ;; (indent (widget-get widget :indent))
3999 (prefix (widget-get widget
:custom-prefix
))
4000 (buttons (widget-get widget
:buttons
))
4001 (tag (widget-get widget
:tag
))
4002 (symbol (widget-value widget
))
4003 (members (custom-group-members symbol
4004 (and (eq custom-buffer-style
'tree
)
4005 custom-browse-only-groups
)))
4006 (doc (widget-docstring widget
)))
4007 (cond ((and (eq custom-buffer-style
'tree
)
4009 (or members
(custom-unloaded-widget-p widget
)))
4010 (custom-browse-insert-prefix prefix
)
4011 (push (widget-create-child-and-convert
4012 widget
'custom-browse-visibility
4013 ;; :tag-glyph "plus"
4017 ;; (widget-glyph-insert nil "-- " "horizontal")
4018 (push (widget-create-child-and-convert
4019 widget
'custom-browse-group-tag
)
4021 (insert " " tag
"\n")
4022 (widget-put widget
:buttons buttons
))
4023 ((and (eq custom-buffer-style
'tree
)
4024 (zerop (length members
)))
4025 (custom-browse-insert-prefix prefix
)
4027 ;; (widget-glyph-insert nil "[ ]" "empty")
4028 ;; (widget-glyph-insert nil "-- " "horizontal")
4029 (push (widget-create-child-and-convert
4030 widget
'custom-browse-group-tag
)
4032 (insert " " tag
"\n")
4033 (widget-put widget
:buttons buttons
))
4034 ((eq custom-buffer-style
'tree
)
4035 (custom-browse-insert-prefix prefix
)
4036 (if (zerop (length members
))
4038 (custom-browse-insert-prefix prefix
)
4040 ;; (widget-glyph-insert nil "[ ]" "empty")
4041 ;; (widget-glyph-insert nil "-- " "horizontal")
4042 (push (widget-create-child-and-convert
4043 widget
'custom-browse-group-tag
)
4045 (insert " " tag
"\n")
4046 (widget-put widget
:buttons buttons
))
4047 (push (widget-create-child-and-convert
4048 widget
'custom-browse-visibility
4049 ;; :tag-glyph "minus"
4053 ;; (widget-glyph-insert nil "-\\ " "top")
4054 (push (widget-create-child-and-convert
4055 widget
'custom-browse-group-tag
)
4057 (insert " " tag
"\n")
4058 (widget-put widget
:buttons buttons
)
4059 (message "Creating group...")
4060 (let* ((members (custom-sort-items
4062 ;; Never sort the top-level custom group.
4063 (unless (eq symbol
'emacs
)
4064 custom-browse-sort-alphabetically
)
4065 custom-browse-order-groups
))
4066 (prefixes (widget-get widget
:custom-prefixes
))
4067 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4068 (extra-prefix (if (widget-get widget
:custom-last
)
4071 (prefix (concat prefix extra-prefix
))
4074 (setq entry
(car members
)
4075 members
(cdr members
))
4076 (push (widget-create-child-and-convert
4077 widget
(nth 1 entry
)
4079 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4080 :custom-prefixes custom-prefix-list
4081 :custom-level
(1+ level
)
4082 :custom-last
(null members
)
4083 :value
(nth 0 entry
)
4084 :custom-prefix prefix
)
4086 (widget-put widget
:children
(reverse children
)))
4087 (message "Creating group...done")))
4090 ;; Create level indicator.
4092 (if (eq custom-buffer-style
'links
)
4093 (push (widget-create-child-and-convert
4094 widget
'custom-group-link
4098 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4100 (push (widget-create-child-and-convert
4101 widget
'custom-group-visibility
4102 :help-echo
"Show members of this group."
4103 :action
'custom-toggle-parent
4104 (not (eq state
'hidden
)))
4107 ;; Create magic button.
4108 (let ((magic (widget-create-child-and-convert
4109 widget
'custom-magic nil
)))
4110 (widget-put widget
:custom-magic magic
)
4111 (push magic buttons
))
4113 (widget-put widget
:buttons buttons
)
4114 ;; Insert documentation.
4115 (if (and (eq custom-buffer-style
'links
) (> level
1))
4116 (widget-put widget
:documentation-indent
0))
4117 (widget-add-documentation-string-button
4118 widget
:visibility-widget
'custom-visibility
))
4122 ;; Draw a horizontal line (this works for both graphical
4123 ;; and text displays):
4126 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4127 (overlay-put (make-overlay p
(1+ p
))
4129 (propertize "\n" 'face
'(:underline t
)
4130 'display
'(space :align-to
999))))
4132 ;; Add parent groups references above the group.
4134 (if (custom-add-parent-links widget
"Parent groups:")
4136 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4138 (let ((start (point)))
4139 (insert tag
" group: ")
4140 (widget-specify-sample widget start
(point)))
4143 (insert " Group definition missing. "))
4144 ((< (length doc
) 50)
4146 ;; Create visibility indicator.
4147 (unless (eq custom-buffer-style
'links
)
4149 (push (widget-create-child-and-convert
4151 :help-echo
"Hide members of this group."
4152 :action
'custom-toggle-parent
4153 (not (eq state
'hidden
)))
4157 ;; Create magic button.
4158 (let ((magic (widget-create-child-and-convert
4159 widget
'custom-magic
4162 (widget-put widget
:custom-magic magic
)
4163 (push magic buttons
))
4165 (widget-put widget
:buttons buttons
)
4166 ;; Insert documentation.
4167 (when (and doc
(>= (length doc
) 50))
4168 (widget-add-documentation-string-button
4169 widget
:visibility-widget
'custom-visibility
))
4172 (if nil
;;; This should test that the buffer
4173 ;;; was not made to display a group.
4175 (insert-char ?\ custom-buffer-indent
)
4176 (custom-add-parent-links widget
)))
4177 (custom-add-see-also widget
4178 (make-string (* custom-buffer-indent level
)
4181 (message "Creating group...")
4182 (let* ((members (custom-sort-items
4184 ;; Never sort the top-level custom group.
4185 (unless (eq symbol
'emacs
)
4186 custom-buffer-sort-alphabetically
)
4187 custom-buffer-order-groups
))
4188 (prefixes (widget-get widget
:custom-prefixes
))
4189 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4190 (len (length members
))
4192 (reporter (make-progress-reporter
4193 "Creating group entries..." 0 len
))
4198 (widget-insert "\n")
4199 (progress-reporter-update reporter
(setq count
(1+ count
)))
4200 (let ((sym (nth 0 entry
))
4201 (type (nth 1 entry
))
4204 (widget-create-child-and-convert
4207 :tag
(custom-unlispify-tag-name sym
)
4208 :custom-prefixes custom-prefix-list
4209 :custom-level
(1+ level
)
4211 (unless (eq (preceding-char) ?
\n)
4212 (widget-insert "\n")))))
4214 (mapc 'custom-magic-reset children
)
4215 (widget-put widget
:children children
)
4216 (custom-group-state-update widget
)
4217 (progress-reporter-done reporter
))
4219 (let ((p (1+ (point))))
4221 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4222 (overlay-put (make-overlay p
(1+ p
))
4224 (propertize "\n" 'face
'(:underline t
)
4225 'display
'(space :align-to
999))))))))
4227 (defvar custom-group-menu
4228 `(("Set for Current Session" custom-group-set
4230 (eq (widget-get widget
:custom-state
) 'modified
)))
4231 ,@(when (or custom-file init-file-user
)
4232 '(("Save for Future Sessions" custom-group-save
4234 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4235 ("Undo Edits" custom-group-reset-current
4237 (memq (widget-get widget
:custom-state
) '(modified))))
4238 ("Reset to Saved" custom-group-reset-saved
4240 (memq (widget-get widget
:custom-state
) '(modified set
))))
4241 ,@(when (or custom-file init-file-user
)
4242 '(("Erase Customization" custom-group-reset-standard
4244 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4245 "Alist of actions for the `custom-group' widget.
4246 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4247 the menu entry, ACTION is the function to call on the widget when the
4248 menu is selected, and FILTER is a predicate which takes a `custom-group'
4249 widget as an argument, and returns non-nil if ACTION is valid on that
4250 widget. If FILTER is nil, ACTION is always valid.")
4252 (defun custom-group-action (widget &optional event
)
4253 "Show the menu for `custom-group' WIDGET.
4254 Optional EVENT is the location for the menu."
4255 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4256 (custom-toggle-hide widget
)
4257 (let* ((completion-ignore-case t
)
4258 (answer (widget-choose (concat "Operation on "
4259 (custom-unlispify-tag-name
4260 (widget-get widget
:value
)))
4261 (custom-menu-filter custom-group-menu
4265 (funcall answer widget
)))))
4267 (defun custom-group-set (widget)
4268 "Set changes in all modified group members."
4269 (dolist (child (widget-get widget
:children
))
4270 (when (eq (widget-get child
:custom-state
) 'modified
)
4271 (widget-apply child
:custom-set
))))
4273 (defun custom-group-mark-to-save (widget)
4274 "Mark all modified group members for saving."
4275 (dolist (child (widget-get widget
:children
))
4276 (when (memq (widget-get child
:custom-state
) '(modified set
))
4277 (widget-apply child
:custom-mark-to-save
))))
4279 (defsubst custom-group-state-set-and-redraw
(widget)
4280 "Set state of group widget WIDGET and redraw with current settings."
4281 (dolist (child (widget-get widget
:children
))
4282 (when (memq (widget-get child
:custom-state
) '(modified set
))
4283 (widget-apply child
:custom-state-set-and-redraw
))))
4285 (defun custom-group-save (widget)
4286 "Save all modified group members."
4287 (custom-group-mark-to-save widget
)
4289 (custom-group-state-set-and-redraw widget
))
4291 (defun custom-group-reset-current (widget)
4292 "Reset all modified group members."
4293 (dolist (child (widget-get widget
:children
))
4294 (when (eq (widget-get child
:custom-state
) 'modified
)
4295 (widget-apply child
:custom-reset-current
))))
4297 (defun custom-group-reset-saved (widget)
4298 "Reset all modified or set group members."
4299 (dolist (child (widget-get widget
:children
))
4300 (when (memq (widget-get child
:custom-state
) '(modified set
))
4301 (widget-apply child
:custom-reset-saved
))))
4303 (defun custom-group-reset-standard (widget)
4304 "Reset all modified, set, or saved group members."
4305 (let ((custom-reset-standard-variables-list '(t))
4306 (custom-reset-standard-faces-list '(t)))
4307 (custom-group-mark-to-reset-standard widget
)
4308 (custom-reset-standard-save-and-update)))
4310 (defun custom-group-mark-to-reset-standard (widget)
4311 "Mark to reset all modified, set, or saved group members."
4312 (dolist (child (widget-get widget
:children
))
4313 (when (memq (widget-get child
:custom-state
)
4314 '(modified set saved
))
4315 (widget-apply child
:custom-mark-to-reset-standard
))))
4317 (defun custom-group-state-update (widget)
4319 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4320 (let* ((children (widget-get widget
:children
))
4321 (states (mapcar (lambda (child)
4322 (widget-get child
:custom-state
))
4324 (magics custom-magic-alist
)
4327 (let ((magic (car (car magics
))))
4328 (if (and (not (eq magic
'hidden
))
4329 (memq magic states
))
4332 (setq magics
(cdr magics
)))))
4333 (widget-put widget
:custom-state found
)))
4334 (custom-magic-reset widget
))
4336 ;;; Reading and writing the custom file.
4339 (defcustom custom-file nil
4340 "File used for storing customization information.
4341 The default is nil, which means to use your init file
4342 as specified by `user-init-file'. If the value is not nil,
4343 it should be an absolute file name.
4345 You can set this option through Custom, if you carefully read the
4346 last paragraph below. However, usually it is simpler to write
4347 something like the following in your init file:
4349 \(setq custom-file \"~/.emacs-custom.el\")
4352 Note that both lines are necessary: the first line tells Custom to
4353 save all customizations in this file, but does not load it.
4355 When you change this variable outside Custom, look in the
4356 previous custom file \(usually your init file) for the
4357 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4358 and copy them (whichever ones you find) to the new custom file.
4359 This will preserve your existing customizations.
4361 If you save this option using Custom, Custom will write all
4362 currently saved customizations, including the new one for this
4363 option itself, into the file you specify, overwriting any
4364 `custom-set-variables' and `custom-set-faces' forms already
4365 present in that file. It will not delete any customizations from
4366 the old custom file. You should do that manually if that is what you
4367 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4368 in your init file, where CUSTOM-FILE is the actual name of the
4369 file. Otherwise, Emacs will not load the file when it starts up,
4370 and hence will not set `custom-file' to that file either."
4371 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4372 (file :format
"%t:%v%d"
4374 "Please read entire docstring below before setting \
4375 this through Custom.
4376 Click on \"More\" \(or position point there and press RETURN)
4377 if only the first line of the docstring is shown."))
4380 (defun custom-file ()
4381 "Return the file name for saving customizations."
4384 (let ((user-init-file user-init-file
)
4386 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4387 (when (null user-init-file
)
4388 (if (or (file-exists-p default-init-file
)
4389 (and (eq system-type
'windows-nt
)
4390 (file-exists-p "~/_emacs")))
4391 ;; Started with -q, i.e. the file containing
4392 ;; Custom settings hasn't been read. Saving
4393 ;; settings there would overwrite other settings.
4394 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4395 (setq user-init-file default-init-file
))
4398 ;; If recentf-mode is non-nil, this is defined.
4399 (declare-function recentf-expand-file-name
"recentf" (name))
4402 (defun custom-save-all ()
4403 "Save all customizations in `custom-file'."
4404 (when (and (null custom-file
) init-file-had-error
)
4405 (error "Cannot save customizations; init file was not fully loaded"))
4406 (let* ((filename (custom-file))
4411 (recentf-expand-file-name (custom-file)))
4414 (old-buffer (find-buffer-visiting filename
))
4417 (with-current-buffer (let ((find-file-visit-truename t
))
4418 (or old-buffer
(find-file-noselect filename
)))
4419 ;; We'll save using file-precious-flag, so avoid destroying
4420 ;; symlinks. (If we're not already visiting the buffer, this is
4421 ;; handled by find-file-visit-truename, above.)
4423 (setq old-buffer-name
(buffer-file-name))
4424 (set-visited-file-name (file-chase-links filename
)))
4426 (unless (eq major-mode
'emacs-lisp-mode
)
4428 (let ((inhibit-read-only t
)
4431 (custom-save-variables)
4432 (custom-save-faces))
4433 (let ((file-precious-flag t
))
4437 (set-visited-file-name old-buffer-name
)
4438 (set-buffer-modified-p nil
))
4439 (kill-buffer (current-buffer))))))
4442 (defun customize-save-customized ()
4443 "Save all user options which have been set in this session."
4445 (mapatoms (lambda (symbol)
4446 (let ((face (get symbol
'customized-face
))
4447 (value (get symbol
'customized-value
))
4448 (face-comment (get symbol
'customized-face-comment
))
4450 (get symbol
'customized-variable-comment
)))
4452 (put symbol
'saved-face face
)
4453 (custom-push-theme 'theme-face symbol
'user
'set value
)
4454 (put symbol
'customized-face nil
))
4456 (put symbol
'saved-value value
)
4457 (custom-push-theme 'theme-value symbol
'user
'set value
)
4458 (put symbol
'customized-value nil
))
4459 (when variable-comment
4460 (put symbol
'saved-variable-comment variable-comment
)
4461 (put symbol
'customized-variable-comment nil
))
4463 (put symbol
'saved-face-comment face-comment
)
4464 (put symbol
'customized-face-comment nil
)))))
4465 ;; We really should update all custom buffers here.
4468 ;; Editing the custom file contents in a buffer.
4470 (defun custom-save-delete (symbol)
4471 "Delete all calls to SYMBOL from the contents of the current buffer.
4472 Leave point at the old location of the first such call,
4473 or (if there were none) at the end of the buffer.
4475 This function does not save the buffer."
4476 (goto-char (point-min))
4477 ;; Skip all whitespace and comments.
4478 (while (forward-comment 1))
4480 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4483 (while t
;; We exit this loop only via throw.
4484 ;; Skip all whitespace and comments.
4485 (while (forward-comment 1))
4486 (let ((start (point))
4487 (sexp (condition-case nil
4488 (read (current-buffer))
4489 (end-of-file (throw 'found nil
)))))
4490 (when (and (listp sexp
)
4491 (eq (car sexp
) symbol
))
4492 (delete-region start
(point))
4494 (setq first
(point)))))))
4497 ;; Move in front of local variables, otherwise long Custom
4498 ;; entries would make them ineffective.
4499 (let ((pos (point-max))
4500 (case-fold-search t
))
4502 (goto-char (point-max))
4503 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4505 (when (search-forward "Local Variables:" nil t
)
4506 (setq pos
(line-beginning-position))))
4509 (defun custom-save-variables ()
4510 "Save all customized variables in `custom-file'."
4512 (custom-save-delete 'custom-set-variables
)
4513 (let ((standard-output (current-buffer))
4514 (saved-list (make-list 1 0))
4516 ;; First create a sorted list of saved variables.
4519 (if (and (get symbol
'saved-value
)
4520 ;; ignore theme values
4521 (or (null (get symbol
'theme-value
))
4522 (eq 'user
(caar (get symbol
'theme-value
)))))
4523 (nconc saved-list
(list symbol
)))))
4524 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4527 (princ "(custom-set-variables
4528 ;; custom-set-variables was added by Custom.
4529 ;; If you edit it by hand, you could mess it up, so be careful.
4530 ;; Your init file should contain only one such instance.
4531 ;; If there is more than one, they won't work right.\n")
4532 (dolist (symbol saved-list
)
4533 (let ((spec (car-safe (get symbol
'theme-value
)))
4534 (value (get symbol
'saved-value
))
4535 (requests (get symbol
'custom-requests
))
4536 (now (and (not (custom-variable-p symbol
))
4538 (eq (get symbol
'force-value
)
4540 (comment (get symbol
'saved-variable-comment
)))
4541 ;; Check REQUESTS for validity.
4542 (dolist (request requests
)
4543 (when (and (symbolp request
) (not (featurep request
)))
4544 (message "Unknown requested feature: %s" request
)
4545 (setq requests
(delq request requests
))))
4546 ;; Is there anything customized about this variable?
4547 (when (or (and spec
(eq (car spec
) 'user
))
4549 (and (null spec
) (get symbol
'saved-value
)))
4550 ;; Output an element for this variable.
4551 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4552 ;; SYMBOL is the variable name.
4553 ;; VALUE-FORM is an expression to return the customized value.
4554 ;; NOW if non-nil means always set the variable immediately
4555 ;; when the customizations are reloaded. This is used
4556 ;; for rogue variables
4557 ;; REQUESTS is a list of packages to load before setting the
4558 ;; variable. Each element of it will be passed to `require'.
4559 ;; COMMENT is whatever comment the user has specified
4560 ;; with the customize facility.
4567 (when (or now requests comment
)
4570 (when (or requests comment
)
4580 (unless (looking-at "\n")
4583 (defun custom-save-faces ()
4584 "Save all customized faces in `custom-file'."
4586 (custom-save-delete 'custom-reset-faces
)
4587 (custom-save-delete 'custom-set-faces
)
4588 (let ((standard-output (current-buffer))
4589 (saved-list (make-list 1 0))
4591 ;; First create a sorted list of saved faces.
4594 (if (and (get symbol
'saved-face
)
4595 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4596 (nconc saved-list
(list symbol
)))))
4597 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4598 ;; The default face must be first, since it affects the others.
4599 (if (memq 'default saved-list
)
4600 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4603 (princ "(custom-set-faces
4604 ;; custom-set-faces was added by Custom.
4605 ;; If you edit it by hand, you could mess it up, so be careful.
4606 ;; Your init file should contain only one such instance.
4607 ;; If there is more than one, they won't work right.\n")
4608 (dolist (symbol saved-list
)
4609 (let ((spec (car-safe (get symbol
'theme-face
)))
4610 (value (get symbol
'saved-face
))
4611 (now (not (or (get symbol
'face-defface-spec
)
4612 (and (not (custom-facep symbol
))
4613 (not (get symbol
'force-face
))))))
4614 (comment (get symbol
'saved-face-comment
)))
4615 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4617 (and (null spec
) (get symbol
'saved-face
)))
4618 ;; Don't print default face here.
4625 (when (or now comment
)
4635 (unless (looking-at "\n")
4638 ;;; The Customize Menu.
4642 (defcustom custom-menu-nesting
2
4643 "Maximum nesting in custom menus."
4645 :group
'custom-menu
)
4647 (defun custom-face-menu-create (widget symbol
)
4648 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4649 (vector (custom-unlispify-menu-entry symbol
)
4650 `(customize-face ',symbol
)
4653 (defun custom-variable-menu-create (widget symbol
)
4654 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4655 (let ((type (get symbol
'custom-type
)))
4656 (unless (listp type
)
4657 (setq type
(list type
)))
4658 (if (and type
(widget-get type
:custom-menu
))
4659 (widget-apply type
:custom-menu symbol
)
4660 (vector (custom-unlispify-menu-entry symbol
)
4661 `(customize-variable ',symbol
)
4664 ;; Add checkboxes to boolean variable entries.
4665 (widget-put (get 'boolean
'widget-type
)
4666 :custom-menu
(lambda (widget symbol
)
4667 (vector (custom-unlispify-menu-entry symbol
)
4668 `(customize-variable ',symbol
)
4670 ':selected symbol
)))
4672 (defun custom-group-menu-create (widget symbol
)
4673 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4674 `( ,(custom-unlispify-menu-entry symbol t
)
4675 :filter
(lambda (&rest junk
)
4676 (let* ((menu (custom-menu-create ',symbol
)))
4677 (if (consp menu
) (cdr menu
) menu
)))))
4680 (defun custom-menu-create (symbol)
4681 "Create menu for customization group SYMBOL.
4682 The menu is in a format applicable to `easy-menu-define'."
4683 (let* ((deactivate-mark nil
)
4684 (item (vector (custom-unlispify-menu-entry symbol
)
4685 `(customize-group ',symbol
)
4687 (if (and (or (not (boundp 'custom-menu-nesting
))
4688 (>= custom-menu-nesting
0))
4690 (custom-load-symbol symbol
)
4691 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4692 (let ((custom-prefix-list (custom-prefix-add symbol
4693 custom-prefix-list
))
4694 (members (custom-sort-items (get symbol
'custom-group
)
4695 custom-menu-sort-alphabetically
4696 custom-menu-order-groups
)))
4697 `(,(custom-unlispify-menu-entry symbol t
)
4700 ,@(mapcar (lambda (entry)
4701 (widget-apply (if (listp (nth 1 entry
))
4703 (list (nth 1 entry
)))
4704 :custom-menu
(nth 0 entry
)))
4709 (defun customize-menu-create (symbol &optional name
)
4710 "Return a customize menu for customization group SYMBOL.
4711 If optional NAME is given, use that as the name of the menu.
4712 Otherwise the menu will be named `Customize'.
4713 The format is suitable for use with `easy-menu-define'."
4715 (setq name
"Customize"))
4717 :filter
(lambda (&rest junk
)
4718 (let ((menu (custom-menu-create ',symbol
)))
4719 (if (consp menu
) (cdr menu
) menu
)))))
4721 ;;; Toolbar and menubar support
4724 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4725 "Menu used in customization buffers."
4726 (nconc (list "Custom"
4727 (customize-menu-create 'customize
))
4728 (mapcar (lambda (arg)
4729 (let ((tag (nth 0 arg
))
4730 (command (nth 1 arg
))
4731 (active (nth 2 arg
))
4733 (vector tag command
:active
(eval active
) :help help
)))
4736 (defvar tool-bar-map
)
4738 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4739 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4740 ;;; we set this up lazily in `Custom-mode'.
4741 (defvar custom-tool-bar-map nil
4742 "Keymap for toolbar in Custom mode.")
4744 ;;; The Custom Mode.
4746 (defun Custom-no-edit (pos &optional event
)
4747 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4749 (error "You can't edit this part of the Custom buffer"))
4751 (defun Custom-newline (pos &optional event
)
4752 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4754 (let ((button (get-char-property pos
'button
)))
4756 (widget-apply-action button event
)
4757 (error "You can't edit this part of the Custom buffer"))))
4759 (defun Custom-goto-parent ()
4760 "Go to the parent group listed at the top of this buffer.
4761 If several parents are listed, go to the first of them."
4764 (goto-char (point-min))
4765 (if (search-forward "\nParent groups: " nil t
)
4766 (let* ((button (get-char-property (point) 'button
))
4767 (parent (downcase (widget-get button
:tag
))))
4768 (customize-group parent
)))))
4770 (defcustom Custom-mode-hook nil
4771 "Hook called when entering Custom mode."
4773 :group
'custom-buffer
)
4775 (defun custom-state-buffer-message (widget)
4776 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4777 (message "To install your edits, invoke [State] and choose the Set operation")))
4779 (defun custom--initialize-widget-variables ()
4780 (set (make-local-variable 'widget-documentation-face
) 'custom-documentation
)
4781 (set (make-local-variable 'widget-button-face
) custom-button
)
4782 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4783 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4784 ;; We need this because of the "More" button on docstrings.
4785 ;; Otherwise clicking on "More" can push point offscreen, which
4786 ;; causes the window to recenter on point, which pushes the
4787 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4788 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4789 ;; When possible, use relief for buttons, not bracketing. This test
4790 ;; may not be optimal.
4791 (when custom-raised-buttons
4792 (set (make-local-variable 'widget-push-button-prefix
) "")
4793 (set (make-local-variable 'widget-push-button-suffix
) "")
4794 (set (make-local-variable 'widget-link-prefix
) "")
4795 (set (make-local-variable 'widget-link-suffix
) ""))
4796 (setq show-trailing-whitespace nil
))
4798 (define-derived-mode Custom-mode nil
"Custom"
4799 "Major mode for editing customization buffers.
4801 The following commands are available:
4804 Move to next button, link or editable field. \\[widget-forward]
4805 Move to previous button, link or editable field. \\[widget-backward]
4806 \\<custom-field-keymap>\
4807 Complete content of editable text field. \\[widget-complete]
4808 \\<custom-mode-map>\
4809 Invoke button under the mouse pointer. \\[widget-button-click]
4810 Invoke button under point. \\[widget-button-press]
4811 Set all options from current text. \\[Custom-set]
4812 Make values in current text permanent. \\[Custom-save]
4813 Make text match actual option values. \\[Custom-reset-current]
4814 Reset options to permanent settings. \\[Custom-reset-saved]
4815 Erase customizations; set options
4816 and buffer text to the standard values. \\[Custom-reset-standard]
4818 Entry to this mode calls the value of `Custom-mode-hook'
4819 if that value is non-nil."
4820 (use-local-map custom-mode-map
)
4821 (easy-menu-add Custom-mode-menu
)
4822 (set (make-local-variable 'tool-bar-map
)
4823 (or custom-tool-bar-map
4824 ;; Set up `custom-tool-bar-map'.
4825 (let ((map (make-sparse-keymap)))
4828 (tool-bar-local-item-from-menu
4829 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4830 :label
(nth 5 arg
)))
4832 (setq custom-tool-bar-map map
))))
4833 (make-local-variable 'custom-options
)
4834 (make-local-variable 'custom-local-buffer
)
4835 (custom--initialize-widget-variables)
4836 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4838 (put 'Custom-mode
'mode-class
'special
)
4840 ;; backward-compatibility
4841 (defun custom-mode ()
4842 "Non-interactive variant of `Custom-mode'."
4844 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4845 (put 'custom-mode
'mode-class
'special
)
4846 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4849 '("^No user option defaults have been changed since Emacs "
4851 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4852 "^No customizable items matching "
4853 "^There are unset changes"
4854 "^Cannot set hidden variable"
4855 "^No \\(?:saved\\|backup\\) value for "
4856 "^No standard setting known for "
4857 "^No standard setting for this face"
4858 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4859 (add-to-list 'debug-ignored-errors regexp
))
4865 ;;; cus-edit.el ends here