1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996-1997, 1999-2012 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 "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 "Reading and posting to newsgroups."
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 "Interfaces, assistants, and emulators for 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-command
)
446 (define-key map
"\177" 'scroll-down-command
)
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 (if custom-unlispify-remove-prefixes
548 (let ((prefixes custom-prefix-list
)
551 (setq prefix
(car prefixes
))
552 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
555 (delete-region (point-min) (point)))
556 (setq prefixes
(cdr prefixes
))))))
557 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
558 (capitalize-region (point-min) (point-max))
560 (goto-char (point-max))
564 (defcustom custom-unlispify-tag-names t
565 "Display tag names as words instead of symbols if non-nil."
566 :group
'custom-buffer
569 (defun custom-unlispify-tag-name (symbol)
570 "Convert SYMBOL into a menu entry."
571 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
572 (custom-unlispify-menu-entry symbol t
)))
574 (defun custom-prefix-add (symbol prefixes
)
575 "Add SYMBOL to list of ignored PREFIXES."
576 (cons (or (get symbol
'custom-prefix
)
577 (concat (symbol-name symbol
) "-"))
582 (defcustom custom-guess-name-alist
588 ("-function\\'" function
)
589 ("-functions\\'" (repeat function
))
590 ("-list\\'" (repeat sexp
))
591 ("-alist\\'" (alist :key-type sexp
:value-type sexp
)))
592 "Alist of (MATCH TYPE).
594 MATCH should be a regexp matching the name of a symbol, and TYPE should
595 be a widget suitable for editing the value of that symbol. The TYPE
596 of the first entry where MATCH matches the name of the symbol will be
599 This is used for guessing the type of variables not declared with
601 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
602 :group
'custom-buffer
)
604 (defcustom custom-guess-doc-alist
605 '(("\\`\\*?Non-nil " boolean
))
606 "Alist of (MATCH TYPE).
608 MATCH should be a regexp matching a documentation string, and TYPE
609 should be a widget suitable for editing the value of a variable with
610 that documentation string. The TYPE of the first entry where MATCH
611 matches the name of the symbol will be used.
613 This is used for guessing the type of variables not declared with
615 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
616 :group
'custom-buffer
)
618 (defun custom-guess-type (symbol)
619 "Guess a widget suitable for editing the value of SYMBOL.
620 This is done by matching SYMBOL with `custom-guess-name-alist' and
621 if that fails, the doc string with `custom-guess-doc-alist'."
622 (let ((name (symbol-name symbol
))
623 (names custom-guess-name-alist
)
626 (setq current
(car names
)
628 (when (string-match (nth 0 current
) name
)
629 (setq found
(nth 1 current
)
632 (let ((doc (documentation-property symbol
'variable-documentation
))
633 (docs custom-guess-doc-alist
))
636 (setq current
(car docs
)
638 (when (string-match (nth 0 current
) doc
)
639 (setq found
(nth 1 current
)
646 (defcustom custom-browse-sort-alphabetically nil
647 "If non-nil, sort customization group alphabetically in `custom-browse'."
649 :group
'custom-browse
)
651 (defcustom custom-browse-order-groups nil
652 "If non-nil, order group members within each customization group.
653 If `first', order groups before non-groups.
654 If `last', order groups after non-groups."
655 :type
'(choice (const first
)
657 (const :tag
"none" nil
))
658 :group
'custom-browse
)
660 (defcustom custom-browse-only-groups nil
661 "If non-nil, show group members only within each customization group."
663 :group
'custom-browse
)
666 (defcustom custom-buffer-sort-alphabetically t
667 "Whether to sort customization groups alphabetically in Custom buffer."
669 :group
'custom-buffer
672 (defcustom custom-buffer-order-groups
'last
673 "If non-nil, order group members within each customization group.
674 If `first', order groups before non-groups.
675 If `last', order groups after non-groups."
676 :type
'(choice (const first
)
678 (const :tag
"none" nil
))
679 :group
'custom-buffer
)
682 (defcustom custom-menu-sort-alphabetically nil
683 "If non-nil, sort each customization group alphabetically in menus."
687 (defcustom custom-menu-order-groups
'first
688 "If non-nil, order group members within each customization group.
689 If `first', order groups before non-groups.
690 If `last', order groups after non-groups."
691 :type
'(choice (const first
)
693 (const :tag
"none" nil
))
696 (defun custom-sort-items (items sort-alphabetically order-groups
)
697 "Return a sorted copy of ITEMS.
698 ITEMS should be a `custom-group' property.
699 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
700 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
701 groups after non-groups, if nil do not order groups at all."
702 (sort (copy-sequence items
)
704 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
705 (namea (nth 0 a
)) (nameb (nth 0 b
)))
706 (cond ((not order-groups
)
707 ;; Since we don't care about A and B order, maybe sort.
708 (when sort-alphabetically
709 (string-lessp namea nameb
)))
710 ((eq typea
'custom-group
)
711 ;; If B is also a group, maybe sort. Otherwise, order A and B.
712 (if (eq typeb
'custom-group
)
713 (when sort-alphabetically
714 (string-lessp namea nameb
))
715 (eq order-groups
'first
)))
716 ((eq typeb
'custom-group
)
717 ;; Since A cannot be a group, order A and B.
718 (eq order-groups
'last
))
720 ;; Since A and B cannot be groups, sort.
721 (string-lessp namea nameb
)))))))
723 ;;; Custom Mode Commands.
725 ;; This variable is used by `custom-tool-bar-map', or directly by
726 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
728 (defvar custom-commands
729 '((" Apply " Custom-set t
730 "Apply settings (for the current session only)"
733 (" Apply and Save " Custom-save
734 (or custom-file user-init-file
)
735 "Apply settings and save for future sessions."
738 (" Undo Edits " Custom-reset-current t
739 "Restore customization buffer to reflect existing settings."
742 (" Reset Customizations " Custom-reset-saved t
743 "Undo any settings applied only for the current session."
746 (" Erase Customizations " Custom-reset-standard
747 (or custom-file user-init-file
)
748 "Un-customize settings in this and future sessions."
751 (" Help for Customize " Custom-help t
752 "Get help for using Customize."
755 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
757 (defun Custom-help ()
758 "Read the node on Easy Customization in the Emacs manual."
760 (info "(emacs)Easy Customization"))
762 (defvar custom-reset-menu
763 '(("Undo Edits in Customization Buffer" . Custom-reset-current
)
764 ("Revert This Session's Customizations" . Custom-reset-saved
)
765 ("Erase Customizations" . Custom-reset-standard
))
766 "Alist of actions for the `Reset' button.
767 The key is a string containing the name of the action, the value is a
768 Lisp function taking the widget as an element which will be called
769 when the action is chosen.")
771 (defvar custom-options nil
772 "Customization widgets in the current buffer.")
774 (defun custom-command-apply (fun query
&optional strong-query
)
775 "Call function FUN on all widgets in `custom-options'.
776 If there is more than one widget, ask user for confirmation using
777 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
778 and `yes-or-no-p' otherwise."
779 (if (or (and (= 1 (length custom-options
))
780 (memq (widget-type (car custom-options
))
781 '(custom-variable custom-face
)))
782 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
783 (progn (mapc fun custom-options
) t
)
787 (defun Custom-set (&rest _ignore
)
788 "Set the current value of all edited settings in the buffer."
790 (custom-command-apply
792 (when (eq (widget-get child
:custom-state
) 'modified
)
793 (widget-apply child
:custom-set
)))
794 "Set all values according to this buffer? "))
796 (defun Custom-save (&rest _ignore
)
797 "Set all edited settings, then save all settings that have been set.
798 If a setting was edited and set before, this saves it. If a
799 setting was merely edited before, this sets it then saves it."
801 (when (custom-command-apply
803 (when (memq (widget-get child
:custom-state
)
804 '(modified set changed rogue
))
805 (widget-apply child
:custom-mark-to-save
)))
806 "Save all settings in this buffer? " t
)
807 ;; Save changes to buffer and redraw.
809 (dolist (child custom-options
)
810 (widget-apply child
:custom-state-set-and-redraw
))))
812 (defun custom-reset (_widget &optional event
)
813 "Select item from reset menu."
814 (let* ((completion-ignore-case t
)
815 (answer (widget-choose "Reset settings"
821 (defun Custom-reset-current (&rest _ignore
)
822 "Reset all edited settings in the buffer to show their current values."
824 (custom-command-apply
826 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
827 (widget-apply widget
:custom-reset-current
)))
828 "Reset all settings' buffer text to show current values? "))
830 (defun Custom-reset-saved (&rest _ignore
)
831 "Reset all edited or set settings in the buffer to their saved value.
832 This also shows the saved values in the buffer."
834 (custom-command-apply
836 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
837 (widget-apply widget
:custom-reset-saved
)))
838 "Reset all settings (current values and buffer text) to saved values? "))
840 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
841 ;; and `custom-group-reset-standard'. If these variables are nil, both
842 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
843 ;; save, reset and redraw the handled widget immediately. Otherwise,
844 ;; they add the widget to the corresponding list and leave it to
845 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
846 (defvar custom-reset-standard-variables-list nil
)
847 (defvar custom-reset-standard-faces-list nil
)
849 ;; The next function was excerpted from `custom-variable-reset-standard'
850 ;; and `custom-face-reset-standard' and is used to avoid calling
851 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
852 ;; one) when erasing all customizations.
853 (defun custom-reset-standard-save-and-update ()
854 "Save settings and redraw after erasing customizations."
855 (when (or (and custom-reset-standard-variables-list
856 (not (eq custom-reset-standard-variables-list
'(t))))
857 (and custom-reset-standard-faces-list
858 (not (eq custom-reset-standard-faces-list
'(t)))))
859 ;; Save settings to file.
861 ;; Set state of and redraw variables.
862 (dolist (widget custom-reset-standard-variables-list
)
863 (unless (eq widget t
)
864 (widget-put widget
:custom-state
'unknown
)
865 (custom-redraw widget
)))
866 ;; Set state of and redraw faces.
867 (dolist (widget custom-reset-standard-faces-list
)
868 (unless (eq widget t
)
869 (let* ((symbol (widget-value widget
))
870 (child (car (widget-get widget
:children
)))
871 (comment-widget (widget-get widget
:comment-widget
)))
872 (put symbol
'face-comment nil
)
873 (widget-value-set child
874 (custom-pre-filter-face-spec
875 (list (list t
(custom-face-attributes-get
877 ;; This call manages the comment visibility
878 (widget-value-set comment-widget
"")
879 (custom-face-state-set widget
)
880 (custom-redraw-magic widget
))))))
882 (defun Custom-reset-standard (&rest _ignore
)
883 "Erase all customizations (either current or saved) in current buffer.
884 The immediate result is to restore them to their standard values.
885 This operation eliminates any saved values for the group members,
886 making them as if they had never been customized at all."
888 ;; Bind these temporarily.
889 (let ((custom-reset-standard-variables-list '(t))
890 (custom-reset-standard-faces-list '(t)))
891 (custom-command-apply
893 (and (or (null (widget-get widget
:custom-standard-value
))
894 (widget-apply widget
:custom-standard-value
))
895 (memq (widget-get widget
:custom-state
)
896 '(modified set changed saved rogue
))
897 (widget-apply widget
:custom-mark-to-reset-standard
)))
898 "The settings will revert to their default values, in this
899 and future sessions. Really erase customizations? " t
)
900 (custom-reset-standard-save-and-update)))
902 ;;; The Customize Commands
904 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
905 "Prompt for a variable and a value and return them as a list.
906 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
907 prompt for the value. The %s escape in PROMPT-VAL is replaced with
908 the name of the variable.
910 If the variable has a `variable-interactive' property, that is used as if
911 it were the arg to `interactive' (which see) to interactively read the value.
913 If the variable has a `custom-type' property, it must be a widget and the
914 `:prompt-value' property of that widget will be used for reading the value.
915 If the variable also has a `custom-get' property, that is used for finding
916 the current value of the variable, otherwise `symbol-value' is used.
918 If optional COMMENT argument is non-nil, also prompt for a comment and return
919 it as the third element in the list."
920 (let* ((var (read-variable prompt-var
))
921 (minibuffer-help-form '(describe-variable var
))
923 (let ((prop (get var
'variable-interactive
))
924 (type (get var
'custom-type
))
925 (prompt (format prompt-val var
)))
927 (setq type
(list type
)))
929 ;; Use VAR's `variable-interactive' property
930 ;; as an interactive spec for prompting.
931 (call-interactively `(lambda (arg)
935 (widget-prompt-value type
939 (or (get var
'custom-get
) 'symbol-value
)
943 (eval-minibuffer prompt
))))))
946 (read-string "Comment: " (get var
'variable-comment
)))
950 (defun customize-set-value (variable value
&optional comment
)
951 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
953 If VARIABLE has a `variable-interactive' property, that is used as if
954 it were the arg to `interactive' (which see) to interactively read the value.
956 If VARIABLE has a `custom-type' property, it must be a widget and the
957 `:prompt-value' property of that widget will be used for reading the value.
959 If given a prefix (or a COMMENT argument), also prompt for a comment."
960 (interactive (custom-prompt-variable "Set variable: "
964 (cond ((string= comment
"")
965 (put variable
'variable-comment nil
))
967 (put variable
'variable-comment comment
)))
968 (set variable value
))
971 (defun customize-set-variable (variable value
&optional comment
)
972 "Set the default for VARIABLE to VALUE, and return VALUE.
973 VALUE is a Lisp object.
975 If VARIABLE has a `custom-set' property, that is used for setting
976 VARIABLE, otherwise `set-default' is used.
978 If VARIABLE has a `variable-interactive' property, that is used as if
979 it were the arg to `interactive' (which see) to interactively read the value.
981 If VARIABLE has a `custom-type' property, it must be a widget and the
982 `:prompt-value' property of that widget will be used for reading the value.
984 If given a prefix (or a COMMENT argument), also prompt for a comment."
985 (interactive (custom-prompt-variable "Set variable: "
986 "Set customized value for %s to: "
988 (custom-load-symbol variable
)
989 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
990 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
991 (put variable
'customized-value
(list (custom-quote value
)))
992 (cond ((string= comment
"")
993 (put variable
'variable-comment nil
)
994 (put variable
'customized-variable-comment nil
))
996 (put variable
'variable-comment comment
)
997 (put variable
'customized-variable-comment comment
)))
1001 (defun customize-save-variable (variable value
&optional comment
)
1002 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1005 If VARIABLE has a `custom-set' property, that is used for setting
1006 VARIABLE, otherwise `set-default' is used.
1008 If VARIABLE has a `variable-interactive' property, that is used as if
1009 it were the arg to `interactive' (which see) to interactively read the value.
1011 If VARIABLE has a `custom-type' property, it must be a widget and the
1012 `:prompt-value' property of that widget will be used for reading the value.
1014 If given a prefix (or a COMMENT argument), also prompt for a comment."
1015 (interactive (custom-prompt-variable "Set and save variable: "
1016 "Set and save value for %s as: "
1017 current-prefix-arg
))
1018 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1019 (put variable
'saved-value
(list (custom-quote value
)))
1020 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1021 (cond ((string= comment
"")
1022 (put variable
'variable-comment nil
)
1023 (put variable
'saved-variable-comment nil
))
1025 (put variable
'variable-comment comment
)
1026 (put variable
'saved-variable-comment comment
)))
1027 (put variable
'customized-value nil
)
1028 (put variable
'customized-variable-comment nil
)
1031 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1033 (set variable value
))
1036 ;; Some parts of Emacs might prompt the user to save customizations,
1037 ;; during startup before customizations are loaded. This function
1038 ;; handles this corner case by avoiding calling `custom-save-variable'
1039 ;; too early, which could wipe out existing customizations.
1042 (defun customize-push-and-save (list-var elts
)
1043 "Add ELTS to LIST-VAR and save for future sessions, safely.
1044 ELTS should be a list. This function adds each entry to the
1045 value of LIST-VAR using `add-to-list'.
1047 If Emacs is initialized, call `customize-save-variable' to save
1048 the resulting list value now. Otherwise, add an entry to
1049 `after-init-hook' to save it after initialization."
1050 (dolist (entry elts
)
1051 (add-to-list list-var entry
))
1053 (let ((coding-system-for-read nil
))
1054 (customize-save-variable list-var
(eval list-var
)))
1055 (add-hook 'after-init-hook
1057 (customize-push-and-save ',list-var
',elts
)))))
1061 "Select a customization buffer which you can use to set user options.
1062 User options are structured into \"groups\".
1063 Initially the top-level group `Emacs' and its immediate subgroups
1064 are shown; the contents of those subgroups are initially hidden."
1066 (customize-group 'emacs
))
1069 (defun customize-mode (mode)
1070 "Customize options related to the current major mode.
1071 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1072 then prompt for the MODE to customize."
1075 (let ((completion-regexp-list '("-mode\\'"))
1076 (group (custom-group-of-mode major-mode
)))
1077 (if (and group
(not current-prefix-arg
))
1080 (completing-read (if group
1081 (format "Major mode (default %s): " major-mode
)
1084 'custom-group-of-mode
1085 t nil nil
(if group
(symbol-name major-mode
))))))))
1086 (customize-group (custom-group-of-mode mode
)))
1088 (defun customize-read-group ()
1089 (let ((completion-ignore-case t
))
1090 (completing-read "Customize group (default emacs): "
1093 (or (and (get symbol
'custom-loads
)
1094 (not (get symbol
'custom-autoload
)))
1095 (get symbol
'custom-group
)))
1099 (defun customize-group (&optional group other-window
)
1100 "Customize GROUP, which must be a customization group.
1101 If OTHER-WINDOW is non-nil, display in another window."
1102 (interactive (list (customize-read-group)))
1103 (when (stringp group
)
1104 (if (string-equal "" group
)
1106 (setq group
(intern group
))))
1107 (let ((name (format "*Customize Group: %s*"
1108 (custom-unlispify-tag-name group
))))
1110 ((null (get-buffer name
))
1111 (funcall (if other-window
1112 'custom-buffer-create-other-window
1113 'custom-buffer-create
)
1114 (list (list group
'custom-group
))
1116 (concat " for group "
1117 (custom-unlispify-tag-name group
))))
1119 (switch-to-buffer-other-window name
))
1121 (pop-to-buffer-same-window name
)))))
1124 (defun customize-group-other-window (&optional group
)
1125 "Customize GROUP, which must be a customization group, in another window."
1126 (interactive (list (customize-read-group)))
1127 (customize-group group t
))
1130 (defalias 'customize-variable
'customize-option
)
1133 (defun customize-option (symbol)
1134 "Customize SYMBOL, which must be a user option."
1135 (interactive (custom-variable-prompt))
1137 (error "No variable specified"))
1138 (let ((basevar (indirect-variable symbol
)))
1139 (custom-buffer-create (list (list basevar
'custom-variable
))
1140 (format "*Customize Option: %s*"
1141 (custom-unlispify-tag-name basevar
)))
1142 (unless (eq symbol basevar
)
1143 (message "`%s' is an alias for `%s'" symbol basevar
))))
1146 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1149 (defun customize-option-other-window (symbol)
1150 "Customize SYMBOL, which must be a user option.
1151 Show the buffer in another window, but don't select it."
1152 (interactive (custom-variable-prompt))
1154 (error "No variable specified"))
1155 (let ((basevar (indirect-variable symbol
)))
1156 (custom-buffer-create-other-window
1157 (list (list basevar
'custom-variable
))
1158 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1159 (unless (eq symbol basevar
)
1160 (message "`%s' is an alias for `%s'" symbol basevar
))))
1162 (defvar customize-changed-options-previous-release
"23.1"
1163 "Version for `customize-changed-options' to refer back to by default.")
1165 ;; Packages will update this variable, so make it available.
1167 (defvar customize-package-emacs-version-alist nil
1168 "Alist mapping versions of a package to Emacs versions.
1169 We use this for packages that have their own names, but are released
1170 as part of Emacs itself.
1172 Each elements looks like this:
1174 (PACKAGE (PVERSION . EVERSION)...)
1176 Here PACKAGE is the name of a package, as a symbol. After
1177 PACKAGE come one or more elements, each associating a
1178 package version PVERSION with the first Emacs version
1179 EVERSION in which it (or a subsequent version of PACKAGE)
1180 was first released. Both PVERSION and EVERSION are strings.
1181 PVERSION should be a string that this package used in
1182 the :package-version keyword for `defcustom', `defgroup',
1185 For example, the MH-E package updates this alist as follows:
1187 (add-to-list 'customize-package-emacs-version-alist
1188 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1189 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1190 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1191 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1193 The value of PACKAGE needs to be unique and it needs to match the
1194 PACKAGE value appearing in the :package-version keyword. Since
1195 the user might see the value in a error message, a good choice is
1196 the official name of the package, such as MH-E or Gnus.")
1199 (defalias 'customize-changed
'customize-changed-options
)
1202 (defun customize-changed-options (&optional since-version
)
1203 "Customize all settings whose meanings have changed in Emacs itself.
1204 This includes new user options and faces, and new customization
1205 groups, as well as older options and faces whose meanings or
1206 default values have changed since the previous major Emacs
1209 With argument SINCE-VERSION (a string), customize all settings
1210 that were added or redefined since that version."
1214 (read-from-minibuffer
1215 (format "Customize options changed, since version (default %s): "
1216 customize-changed-options-previous-release
))))
1217 (if (equal since-version
"")
1218 (setq since-version nil
)
1219 (unless (condition-case nil
1220 (numberp (read since-version
))
1222 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1223 (unless since-version
1224 (setq since-version customize-changed-options-previous-release
))
1226 ;; Load the information for versions since since-version. We use
1227 ;; custom-load-symbol for this.
1228 (put 'custom-versions-load-alist
'custom-loads nil
)
1229 (dolist (elt custom-versions-load-alist
)
1230 (if (customize-version-lessp since-version
(car elt
))
1231 (dolist (load (cdr elt
))
1232 (custom-add-load 'custom-versions-load-alist load
))))
1233 (custom-load-symbol 'custom-versions-load-alist
)
1234 (put 'custom-versions-load-alist
'custom-loads nil
)
1239 (let* ((package-version (get symbol
'custom-package-version
))
1241 (or (and package-version
1242 (customize-package-emacs-version symbol
1244 (get symbol
'custom-version
))))
1246 (when (customize-version-lessp since-version version
)
1247 (if (or (get symbol
'custom-group
)
1248 (get symbol
'group-documentation
))
1249 (push (list symbol
'custom-group
) found
))
1250 (if (custom-variable-p symbol
)
1251 (push (list symbol
'custom-variable
) found
))
1252 (if (custom-facep symbol
)
1253 (push (list symbol
'custom-face
) found
)))))))
1255 (custom-buffer-create (custom-sort-items found t
'first
)
1256 "*Customize Changed Options*")
1257 (user-error "No user option defaults have been changed since Emacs %s"
1260 (defun customize-package-emacs-version (symbol package-version
)
1261 "Return the Emacs version in which SYMBOL's meaning last changed.
1262 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1263 `customize-package-emacs-version-alist' to find the version of
1264 Emacs that is associated with version VERSION of PACKAGE."
1265 (let (package-versions emacs-version
)
1266 ;; Use message instead of error since we want user to be able to
1267 ;; see the rest of the symbols even if a package author has
1268 ;; botched things up.
1269 (cond ((not (listp package-version
))
1270 (message "Invalid package-version value for %s" symbol
))
1271 ((setq package-versions
(assq (car package-version
)
1272 customize-package-emacs-version-alist
))
1274 (cdr (assoc (cdr package-version
) package-versions
)))
1275 (unless emacs-version
1276 (message "%s version %s not found in %s" symbol
1277 (cdr package-version
)
1278 "customize-package-emacs-version-alist")))
1280 (message "Package %s version %s lists no corresponding Emacs version"
1281 (car package-version
)
1282 (cdr package-version
))))
1285 (defun customize-version-lessp (version1 version2
)
1286 ;; Why are the versions strings, and given that they are, why aren't
1287 ;; they converted to numbers and compared as such here? -- fx
1289 ;; In case someone made a mistake and left out the quotes
1290 ;; in the :version value.
1291 (if (numberp version2
)
1292 (setq version2
(prin1-to-string version2
)))
1293 (let (major1 major2 minor1 minor2
)
1294 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1295 (setq major1
(read (or (match-string 1 version1
)
1297 (setq minor1
(read (or (match-string 3 version1
)
1299 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1300 (setq major2
(read (or (match-string 1 version2
)
1302 (setq minor2
(read (or (match-string 3 version2
)
1304 (or (< major1 major2
)
1305 (and (= major1 major2
)
1306 (< minor1 minor2
)))))
1309 (defun customize-face (&optional face other-window
)
1310 "Customize FACE, which should be a face name or nil.
1311 If FACE is nil, customize all faces. If FACE is actually a
1312 face-alias, customize the face it is aliased to.
1314 If OTHER-WINDOW is non-nil, display in another window.
1316 Interactively, when point is on text which has a face specified,
1317 suggest to customize that face, if it's customizable."
1318 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1319 (if (member face
'(nil ""))
1320 (setq face
(face-list)))
1321 (if (and (listp face
) (null (cdr face
)))
1322 (setq face
(car face
)))
1323 (let ((display-fun (if other-window
1324 'custom-buffer-create-other-window
1325 'custom-buffer-create
)))
1327 (funcall display-fun
1329 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1331 "*Customize Faces*")
1332 ;; If FACE is actually an alias, customize the face it is aliased to.
1333 (if (get face
'face-alias
)
1334 (setq face
(get face
'face-alias
)))
1335 (unless (facep face
)
1336 (error "Invalid face %S" face
))
1337 (funcall display-fun
1338 (list (list face
'custom-face
))
1339 (format "*Customize Face: %s*"
1340 (custom-unlispify-tag-name face
))))))
1343 (defun customize-face-other-window (&optional face
)
1344 "Show customization buffer for face FACE in other window.
1345 If FACE is actually a face-alias, customize the face it is aliased to.
1347 Interactively, when point is on text which has a face specified,
1348 suggest to customize that face, if it's customizable."
1349 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1350 (customize-face face t
))
1352 (defalias 'customize-customized
'customize-unsaved
)
1355 (defun customize-unsaved ()
1356 "Customize all options and faces set in this session but not saved."
1359 (mapatoms (lambda (symbol)
1360 (and (or (get symbol
'customized-face
)
1361 (get symbol
'customized-face-comment
))
1362 (custom-facep symbol
)
1363 (push (list symbol
'custom-face
) found
))
1364 (and (or (get symbol
'customized-value
)
1365 (get symbol
'customized-variable-comment
))
1367 (push (list symbol
'custom-variable
) found
))))
1369 (error "No user options are set but unsaved")
1370 (custom-buffer-create (custom-sort-items found t nil
)
1371 "*Customize Unsaved*"))))
1374 (defun customize-rogue ()
1375 "Customize all user variables modified outside customize."
1378 (mapatoms (lambda (symbol)
1379 (let ((cval (or (get symbol
'customized-value
)
1380 (get symbol
'saved-value
)
1381 (get symbol
'standard-value
))))
1382 (when (and cval
;Declared with defcustom.
1383 (default-boundp symbol
) ;Has a value.
1384 (not (equal (eval (car cval
))
1385 ;; Which does not match customize.
1386 (default-value symbol
))))
1387 (push (list symbol
'custom-variable
) found
)))))
1389 (user-error "No rogue user options")
1390 (custom-buffer-create (custom-sort-items found t nil
)
1391 "*Customize Rogue*"))))
1393 (defun customize-saved ()
1394 "Customize all saved options and faces."
1397 (mapatoms (lambda (symbol)
1398 (and (or (get symbol
'saved-face
)
1399 (get symbol
'saved-face-comment
))
1400 (custom-facep symbol
)
1401 (push (list symbol
'custom-face
) found
))
1402 (and (or (get symbol
'saved-value
)
1403 (get symbol
'saved-variable-comment
))
1405 (push (list symbol
'custom-variable
) found
))))
1407 (user-error "No saved user options")
1408 (custom-buffer-create (custom-sort-items found t nil
)
1409 "*Customize Saved*"))))
1411 (declare-function apropos-parse-pattern
"apropos" (pattern))
1414 (defun customize-apropos (pattern &optional type
)
1415 "Customize loaded options, faces and groups matching PATTERN.
1416 PATTERN can be a word, a list of words (separated by spaces),
1417 or a regexp (using some regexp special characters). If it is a word,
1418 search for matches for that word as a substring. If it is a list of words,
1419 search for matches for any two (or more) of those words.
1421 If TYPE is `options', include only options.
1422 If TYPE is `faces', include only faces.
1423 If TYPE is `groups', include only groups."
1424 (interactive (list (apropos-read-pattern "symbol") nil
))
1426 (unless (memq type
'(nil options faces groups
))
1427 (error "Invalid setting type %s" (symbol-name type
)))
1428 (apropos-parse-pattern pattern
)
1432 (when (string-match apropos-regexp
(symbol-name symbol
))
1433 ,(if (memq type
'(nil groups
))
1434 '(if (get symbol
'custom-group
)
1435 (push (list symbol
'custom-group
) found
)))
1436 ,(if (memq type
'(nil faces
))
1437 '(if (custom-facep symbol
)
1438 (push (list symbol
'custom-face
) found
)))
1439 ,(if (memq type
'(nil options
))
1440 `(if (and (boundp symbol
)
1441 (eq (indirect-variable symbol
) symbol
)
1442 (or (get symbol
'saved-value
)
1443 (custom-variable-p symbol
)))
1444 (push (list symbol
'custom-variable
) found
))))))
1446 (error "No customizable %s matching %s" (symbol-name type
) pattern
))
1447 (custom-buffer-create
1448 (custom-sort-items found t custom-buffer-order-groups
)
1449 "*Customize Apropos*")))
1452 (defun customize-apropos-options (regexp &optional ignored
)
1453 "Customize all loaded customizable options matching REGEXP."
1454 (interactive (list (apropos-read-pattern "options")))
1455 (customize-apropos regexp
'options
))
1458 (defun customize-apropos-faces (regexp)
1459 "Customize all loaded faces matching REGEXP."
1460 (interactive (list (apropos-read-pattern "faces")))
1461 (customize-apropos regexp
'faces
))
1464 (defun customize-apropos-groups (regexp)
1465 "Customize all loaded groups matching REGEXP."
1466 (interactive (list (apropos-read-pattern "groups")))
1467 (customize-apropos regexp
'groups
))
1471 (defcustom custom-buffer-style
'links
1472 "Control the presentation style for customization buffers.
1473 The value should be a symbol, one of:
1475 brackets: groups nest within each other with big horizontal brackets.
1476 links: groups have links to subgroups."
1477 :type
'(radio (const brackets
)
1479 :group
'custom-buffer
)
1481 (defcustom custom-buffer-done-kill nil
1482 "Non-nil means exiting a Custom buffer should kill it."
1485 :group
'custom-buffer
)
1487 (defcustom custom-buffer-indent
3
1488 "Number of spaces to indent nested groups."
1490 :group
'custom-buffer
)
1492 (defun custom-get-fresh-buffer (name)
1493 "Get a fresh new buffer with name NAME.
1494 If the buffer already exist, clean it up to be like new.
1495 Beware: it's not quite like new. Good enough for custom, but maybe
1497 ;; To be more complete, we should also kill all permanent-local variables,
1498 ;; but it's not needed for custom.
1499 (let ((buf (get-buffer name
)))
1500 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1501 ;; This will check if the file is not saved.
1505 (get-buffer-create name
)
1506 (with-current-buffer buf
1507 (kill-all-local-variables)
1508 (run-hooks 'kill-buffer-hook
)
1509 ;; Delete overlays before erasing the buffer so the overlay hooks
1510 ;; don't get run spuriously when we erase the buffer.
1511 (let ((ols (overlay-lists)))
1512 (dolist (ol (nconc (car ols
) (cdr ols
)))
1513 (delete-overlay ol
)))
1518 (defun custom-buffer-create (options &optional name description
)
1519 "Create a buffer containing OPTIONS.
1520 Optional NAME is the name of the buffer.
1521 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1522 SYMBOL is a customization option, and WIDGET is a widget for editing
1524 (pop-to-buffer-same-window (custom-get-fresh-buffer (or name
"*Customization*")))
1525 (custom-buffer-create-internal options description
))
1528 (defun custom-buffer-create-other-window (options &optional name description
)
1529 "Create a buffer containing OPTIONS, and display it in another window.
1530 The result includes selecting that window.
1531 Optional NAME is the name of the buffer.
1532 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1533 SYMBOL is a customization option, and WIDGET is a widget for editing
1535 (unless name
(setq name
"*Customization*"))
1536 (switch-to-buffer-other-window (custom-get-fresh-buffer name
))
1537 (custom-buffer-create-internal options description
))
1539 (defcustom custom-reset-button-menu t
1540 "If non-nil, only show a single reset button in customize buffers.
1541 This button will have a menu with all three reset operations."
1543 :group
'custom-buffer
1546 (defcustom custom-buffer-verbose-help t
1547 "If non-nil, include explanatory text in the customization buffer."
1549 :group
'custom-buffer
)
1551 (defun Custom-buffer-done (&rest _ignore
)
1552 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1554 (quit-window custom-buffer-done-kill
))
1556 (defvar custom-button nil
1557 "Face used for buttons in customization buffers.")
1559 (defvar custom-button-mouse nil
1560 "Mouse face used for buttons in customization buffers.")
1562 (defvar custom-button-pressed nil
1563 "Face used for pressed buttons in customization buffers.")
1565 (defcustom custom-search-field t
1566 "If non-nil, show a search field in Custom buffers."
1569 :group
'custom-buffer
)
1571 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1572 '(("unspecified" . unspecified
))))
1573 "If non-nil, indicate active buttons in a `raised-button' style.
1574 Otherwise use brackets."
1577 :group
'custom-buffer
1578 :set
(lambda (variable value
)
1579 (custom-set-default variable value
)
1581 (if value
'custom-button
'custom-button-unraised
))
1582 (setq custom-button-mouse
1583 (if value
'custom-button-mouse
'highlight
))
1584 (setq custom-button-pressed
1586 'custom-button-pressed
1587 'custom-button-pressed-unraised
))))
1589 (defun custom-buffer-create-internal (options &optional _description
)
1591 (let ((init-file (or custom-file user-init-file
)))
1592 ;; Insert verbose help at the top of the custom buffer.
1593 (when custom-buffer-verbose-help
1595 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1596 (widget-insert "For help using this buffer, see ")
1597 (widget-create 'custom-manual
1598 :tag
"Easy Customization"
1599 "(emacs)Easy Customization")
1600 (widget-insert " in the ")
1601 (widget-create 'custom-manual
1603 :help-echo
"Read the Emacs manual."
1605 (widget-insert "."))
1606 (widget-insert "\n")
1608 ;; Insert the search field.
1609 (when custom-search-field
1610 (widget-insert "\n")
1611 (let* ((echo "Search for custom items.
1612 You can enter one or more words separated by spaces,
1613 or a regular expression.")
1617 :size
40 :help-echo echo
1618 :action
`(lambda (widget &optional event
)
1619 (customize-apropos (split-string (widget-value widget
)))))))
1621 (widget-create-child-and-convert
1622 search-widget
'push-button
1624 :help-echo echo
:action
1625 (lambda (widget &optional _event
)
1626 (customize-apropos (split-string (widget-value (widget-get widget
:parent
))))))
1627 (widget-insert "\n")))
1629 ;; The custom command buttons are also in the toolbar, so for a
1630 ;; time they were not inserted in the buffer if the toolbar was in use.
1631 ;; But it can be a little confusing for the buffer layout to
1632 ;; change according to whether or nor the toolbar is on, not to
1633 ;; mention that a custom buffer can in theory be created in a
1634 ;; frame with a toolbar, then later viewed in one without.
1635 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1636 (if custom-buffer-verbose-help
1638 Operate on all settings in this buffer:\n"))
1639 (let ((button (lambda (tag action active help _icon _label
)
1642 (widget-create 'push-button
:tag tag
1643 :help-echo help
:action action
))))
1644 (commands custom-commands
))
1645 (if custom-reset-button-menu
1647 (widget-create 'push-button
1649 :help-echo
"Show a menu with reset operations."
1650 :mouse-down-action
'ignore
1651 :action
'custom-reset
)
1652 (apply button
(pop commands
)) ; Apply
1653 (apply button
(pop commands
))) ; Apply and Save
1654 (apply button
(pop commands
)) ; Apply
1655 (apply button
(pop commands
)) ; Apply and Save
1656 (widget-insert "\n")
1657 (apply button
(pop commands
)) ; Undo
1658 (apply button
(pop commands
)) ; Reset
1659 (apply button
(pop commands
)) ; Erase
1661 (pop commands
) ; Help (omitted)
1662 (apply button
(pop commands
)))) ; Exit
1663 (widget-insert "\n\n"))
1665 ;; Now populate the custom buffer.
1666 (message "Creating customization items...")
1667 (buffer-disable-undo)
1668 (setq custom-options
1669 (if (= (length options
) 1)
1670 (mapcar (lambda (entry)
1671 (widget-create (nth 1 entry
)
1672 :documentation-shown t
1673 :custom-state
'unknown
1674 :tag
(custom-unlispify-tag-name
1676 :value
(nth 0 entry
)))
1679 (length (length options
)))
1680 (mapcar (lambda (entry)
1682 (message "Creating customization items ...%2d%%"
1683 (/ (* 100.0 count
) length
))
1684 (widget-create (nth 1 entry
)
1685 :tag
(custom-unlispify-tag-name
1687 :value
(nth 0 entry
))
1688 (setq count
(1+ count
))
1689 (unless (eq (preceding-char) ?
\n)
1690 (widget-insert "\n"))
1691 (widget-insert "\n")))
1693 (unless (eq (preceding-char) ?
\n)
1694 (widget-insert "\n"))
1695 (message "Creating customization items ...done")
1696 (message "Resetting customization items...")
1697 (unless (eq custom-buffer-style
'tree
)
1698 (mapc 'custom-magic-reset custom-options
))
1699 (message "Resetting customization items...done")
1700 (message "Creating customization setup...")
1702 (buffer-enable-undo)
1703 (goto-char (point-min))
1704 (message "Creating customization setup...done"))
1706 ;;; The Tree Browser.
1709 (defun customize-browse (&optional group
)
1710 "Create a tree browser for the customize hierarchy."
1713 (setq group
'emacs
))
1714 (let ((name "*Customize Browser*"))
1715 (pop-to-buffer-same-window (custom-get-fresh-buffer name
)))
1717 (widget-insert (format "\
1718 %s buttons; type RET or click mouse-1
1719 on a button to invoke its action.
1720 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1721 (if custom-raised-buttons
1722 "`Raised' text indicates"
1723 "Square brackets indicate")))
1726 (if custom-browse-only-groups
1728 Invoke the [Group] button below to edit that item in another window.\n\n")
1729 (widget-insert "Invoke the ")
1730 (widget-create 'item
1733 :tag-glyph
"folder")
1734 (widget-insert ", ")
1735 (widget-create 'item
1739 (widget-insert ", and ")
1740 (widget-create 'item
1743 :tag-glyph
"option")
1744 (widget-insert " buttons below to edit that
1745 item in another window.\n\n"))
1746 (let ((custom-buffer-style 'tree
))
1747 (widget-create 'custom-group
1749 :custom-state
'unknown
1750 :tag
(custom-unlispify-tag-name group
)
1753 (goto-char (point-min)))
1755 (define-widget 'custom-browse-visibility
'item
1756 "Control visibility of items in the customize tree browser."
1758 :action
'custom-browse-visibility-action
)
1760 (defun custom-browse-visibility-action (widget &rest _ignore
)
1761 (let ((custom-buffer-style 'tree
))
1762 (custom-toggle-parent widget
)))
1764 (define-widget 'custom-browse-group-tag
'custom-group-link
1765 "Show parent in other window when activated."
1768 :action
'custom-browse-group-tag-action
)
1770 (defun custom-browse-group-tag-action (widget &rest _ignore
)
1771 (let ((parent (widget-get widget
:parent
)))
1772 (customize-group-other-window (widget-value parent
))))
1774 (define-widget 'custom-browse-variable-tag
'custom-group-link
1775 "Show parent in other window when activated."
1778 :action
'custom-browse-variable-tag-action
)
1780 (defun custom-browse-variable-tag-action (widget &rest _ignore
)
1781 (let ((parent (widget-get widget
:parent
)))
1782 (customize-variable-other-window (widget-value parent
))))
1784 (define-widget 'custom-browse-face-tag
'custom-group-link
1785 "Show parent in other window when activated."
1788 :action
'custom-browse-face-tag-action
)
1790 (defun custom-browse-face-tag-action (widget &rest _ignore
)
1791 (let ((parent (widget-get widget
:parent
)))
1792 (customize-face-other-window (widget-value parent
))))
1794 (defconst custom-browse-alist
'((" " "space")
1800 (defun custom-browse-insert-prefix (prefix)
1801 "Insert PREFIX. On XEmacs convert it to line graphics."
1802 ;; Fixme: do graphics.
1803 (if nil
; (featurep 'xemacs)
1806 (while (not (string-equal prefix
""))
1807 (let ((entry (substring prefix
0 3)))
1808 (setq prefix
(substring prefix
3))
1809 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1810 (name (nth 1 (assoc entry custom-browse-alist
))))
1811 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1812 (overlay-put overlay
'start-open t
)
1813 (overlay-put overlay
'end-open t
)))))
1816 ;;; Modification of Basic Widgets.
1818 ;; We add extra properties to the basic widgets needed here. This is
1819 ;; fine, as long as we are careful to stay within our own namespace.
1821 ;; We want simple widgets to be displayed by default, but complex
1822 ;; widgets to be hidden.
1824 ;; This widget type is obsolete as of Emacs 24.1.
1825 (widget-put (get 'item
'widget-type
) :custom-show t
)
1826 (widget-put (get 'editable-field
'widget-type
)
1827 :custom-show
(lambda (_widget value
)
1828 (let ((pp (pp-to-string value
)))
1829 (cond ((string-match "\n" pp
)
1834 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1836 ;;; The `custom-manual' Widget.
1838 (define-widget 'custom-manual
'info-link
1839 "Link to the manual entry for this customization option."
1840 :help-echo
"Read the manual entry for this option."
1841 :keymap custom-mode-link-map
1842 :follow-link
'mouse-face
1843 :button-face
'custom-link
1844 :mouse-face
'highlight
1845 :pressed-face
'highlight
1848 ;;; The `custom-magic' Widget.
1850 (defgroup custom-magic-faces nil
1851 "Faces used by the magic button."
1852 :group
'custom-faces
1853 :group
'custom-buffer
)
1855 (defface custom-invalid
'((((class color
))
1856 (:foreground
"yellow1" :background
"red1"))
1858 (:weight bold
:slant italic
:underline t
)))
1859 "Face used when the customize item is invalid."
1860 :group
'custom-magic-faces
)
1861 (define-obsolete-face-alias 'custom-invalid-face
'custom-invalid
"22.1")
1863 (defface custom-rogue
'((((class color
))
1864 (:foreground
"pink" :background
"black"))
1867 "Face used when the customize item is not defined for customization."
1868 :group
'custom-magic-faces
)
1869 (define-obsolete-face-alias 'custom-rogue-face
'custom-rogue
"22.1")
1871 (defface custom-modified
'((((min-colors 88) (class color
))
1872 (:foreground
"white" :background
"blue1"))
1874 (:foreground
"white" :background
"blue"))
1876 (:slant italic
:bold
)))
1877 "Face used when the customize item has been modified."
1878 :group
'custom-magic-faces
)
1879 (define-obsolete-face-alias 'custom-modified-face
'custom-modified
"22.1")
1881 (defface custom-set
'((((min-colors 88) (class color
))
1882 (:foreground
"blue1" :background
"white"))
1884 (:foreground
"blue" :background
"white"))
1887 "Face used when the customize item has been set."
1888 :group
'custom-magic-faces
)
1889 (define-obsolete-face-alias 'custom-set-face
'custom-set
"22.1")
1891 (defface custom-changed
'((((min-colors 88) (class color
))
1892 (:foreground
"white" :background
"blue1"))
1894 (:foreground
"white" :background
"blue"))
1897 "Face used when the customize item has been changed."
1898 :group
'custom-magic-faces
)
1899 (define-obsolete-face-alias 'custom-changed-face
'custom-changed
"22.1")
1901 (defface custom-themed
'((((min-colors 88) (class color
))
1902 (:foreground
"white" :background
"blue1"))
1904 (:foreground
"white" :background
"blue"))
1907 "Face used when the customize item has been set by a theme."
1908 :group
'custom-magic-faces
)
1910 (defface custom-saved
'((t (:underline t
)))
1911 "Face used when the customize item has been saved."
1912 :group
'custom-magic-faces
)
1913 (define-obsolete-face-alias 'custom-saved-face
'custom-saved
"22.1")
1915 (defconst custom-magic-alist
1916 '((nil "#" underline
"\
1917 UNINITIALIZED, you should not see this.")
1918 (unknown "?" italic
"\
1919 UNKNOWN, you should not see this.")
1920 (hidden "-" default
"\
1921 HIDDEN, invoke \"Show\" in the previous line to show." "\
1922 group now hidden, invoke \"Show\", above, to show contents.")
1923 (invalid "x" custom-invalid
"\
1924 INVALID, the displayed value cannot be set.")
1925 (modified "*" custom-modified
"\
1926 EDITED, shown value does not take effect until you set or save it." "\
1927 something in this group has been edited but not set.")
1928 (set "+" custom-set
"\
1929 SET for current session only." "\
1930 something in this group has been set but not saved.")
1931 (changed ":" custom-changed
"\
1932 CHANGED outside Customize." "\
1933 something in this group has been changed outside customize.")
1934 (saved "!" custom-saved
"\
1936 something in this group has been set and saved.")
1937 (themed "o" custom-themed
"\
1939 visible group members are all at standard values.")
1940 (rogue "@" custom-rogue
"\
1941 NO CUSTOMIZATION DATA; not intended to be customized." "\
1942 something in this group is not prepared for customization.")
1943 (standard " " nil
"\
1945 visible group members are all at standard values."))
1946 "Alist of customize option states.
1947 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1949 STATE is one of the following symbols:
1952 For internal use, should never occur.
1954 For internal use, should never occur.
1956 This item is not being displayed.
1958 This item is modified, but has an invalid form.
1960 This item is modified, and has a valid form.
1962 This item has been set but not saved.
1964 The current value of this item has been changed outside Customize.
1966 This item is marked for saving.
1968 This item has no customization information.
1970 This item is unchanged from the standard setting.
1972 MAGIC is a string used to present that state.
1974 FACE is a face used to present the state.
1976 ITEM-DESC is a string describing the state for options.
1978 GROUP-DESC is a string describing the state for groups. If this is
1979 left out, ITEM-DESC will be used.
1981 The string %c in either description will be replaced with the
1982 category of the item. These are `group'. `option', and `face'.
1984 The list should be sorted most significant first.")
1986 (defcustom custom-magic-show
'long
1987 "If non-nil, show textual description of the state.
1988 If `long', show a full-line description, not just one word."
1989 :type
'(choice (const :tag
"no" nil
)
1991 (other :tag
"short" short
))
1992 :group
'custom-buffer
)
1994 (defcustom custom-magic-show-hidden
'(option face
)
1995 "Control whether the State button is shown for hidden items.
1996 The value should be a list with the custom categories where the State
1997 button should be visible. Possible categories are `group', `option',
1999 :type
'(set (const group
) (const option
) (const face
))
2000 :group
'custom-buffer
)
2002 (defcustom custom-magic-show-button nil
2003 "Show a \"magic\" button indicating the state of each customization option."
2005 :group
'custom-buffer
)
2007 (define-widget 'custom-magic
'default
2008 "Show and manipulate state for a customization option."
2010 :action
'widget-parent-action
2013 :value-create
'custom-magic-value-create
2014 :value-delete
'widget-children-value-delete
)
2016 (defun widget-magic-mouse-down-action (widget &optional _event
)
2017 ;; Non-nil unless hidden.
2018 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2022 (defun custom-magic-value-create (widget)
2023 "Create compact status report for WIDGET."
2024 (let* ((parent (widget-get widget
:parent
))
2025 (state (widget-get parent
:custom-state
))
2026 (hidden (eq state
'hidden
))
2027 (entry (assq state custom-magic-alist
))
2028 (magic (nth 1 entry
))
2029 (face (nth 2 entry
))
2030 (category (widget-get parent
:custom-category
))
2031 (text (or (and (eq category
'group
)
2034 (form (widget-get parent
:custom-form
))
2036 (unless (eq state
'hidden
)
2037 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2038 (setq text
(concat (match-string 1 text
)
2039 (symbol-name category
)
2040 (match-string 2 text
))))
2041 (when (and custom-magic-show
2043 (memq category custom-magic-show-hidden
)))
2045 (when (and (eq category
'group
)
2046 (not (and (eq custom-buffer-style
'links
)
2047 (> (widget-get parent
:custom-level
) 1))))
2048 (insert-char ?\
(* custom-buffer-indent
2049 (widget-get parent
:custom-level
))))
2050 (push (widget-create-child-and-convert
2052 :help-echo
"Change the state of this item."
2053 :format
(if hidden
"%t" "%[%t%]")
2054 :button-prefix
'widget-push-button-prefix
2055 :button-suffix
'widget-push-button-suffix
2056 :mouse-down-action
'widget-magic-mouse-down-action
2060 (let ((start (point)))
2061 (if (eq custom-magic-show
'long
)
2063 (insert (symbol-name state
)))
2064 (cond ((eq form
'lisp
)
2066 ((eq form
'mismatch
)
2067 (insert " (mismatch)")))
2068 (put-text-property start
(point) 'face
'custom-state
))
2070 (when (and (eq category
'group
)
2071 (not (and (eq custom-buffer-style
'links
)
2072 (> (widget-get parent
:custom-level
) 1))))
2073 (insert-char ?\
(* custom-buffer-indent
2074 (widget-get parent
:custom-level
))))
2075 (when custom-magic-show-button
2076 (when custom-magic-show
2077 (let ((indent (widget-get parent
:indent
)))
2079 (insert-char ? indent
))))
2080 (push (widget-create-child-and-convert
2082 :mouse-down-action
'widget-magic-mouse-down-action
2086 :help-echo
"Change the state."
2087 :format
(if hidden
"%t" "%[%t%]")
2088 :tag
(if (memq form
'(lisp mismatch
))
2089 (concat "(" magic
")")
2090 (concat "[" magic
"]")))
2093 (widget-put widget
:children children
))))
2095 (defun custom-magic-reset (widget)
2096 "Redraw the :custom-magic property of WIDGET."
2097 (let ((magic (widget-get widget
:custom-magic
)))
2099 (widget-value-set magic
(widget-value magic
)))))
2101 ;;; The `custom' Widget.
2103 (defface custom-button
2104 '((((type x w32 ns
) (class color
)) ; Like default modeline
2105 (:box
(:line-width
2 :style released-button
)
2106 :background
"lightgrey" :foreground
"black"))
2109 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2111 :group
'custom-faces
)
2112 (define-obsolete-face-alias 'custom-button-face
'custom-button
"22.1")
2114 (defface custom-button-mouse
2115 '((((type x w32 ns
) (class color
))
2116 (:box
(:line-width
2 :style released-button
)
2117 :background
"grey90" :foreground
"black"))
2119 ;; This is for text terminals that support mouse, like GPM mouse
2120 ;; or the MS-DOS terminal: inverse-video makes the button stand
2121 ;; out on mouse-over.
2122 (:inverse-video t
)))
2123 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2125 :group
'custom-faces
)
2127 (defface custom-button-unraised
2128 '((t :inherit underline
))
2129 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2131 :group
'custom-faces
)
2134 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2136 (setq custom-button-mouse
2137 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2139 (defface custom-button-pressed
2140 '((((type x w32 ns
) (class color
))
2141 (:box
(:line-width
2 :style pressed-button
)
2142 :background
"lightgrey" :foreground
"black"))
2144 (:inverse-video t
)))
2145 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2147 :group
'custom-faces
)
2148 (define-obsolete-face-alias 'custom-button-pressed-face
2149 'custom-button-pressed
"22.1")
2151 (defface custom-button-pressed-unraised
2152 '((default :inherit custom-button-unraised
)
2153 (((class color
) (background light
)) :foreground
"magenta4")
2154 (((class color
) (background dark
)) :foreground
"violet"))
2155 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2157 :group
'custom-faces
)
2159 (setq custom-button-pressed
2160 (if custom-raised-buttons
2161 'custom-button-pressed
2162 'custom-button-pressed-unraised
))
2164 (defface custom-documentation
'((t nil
))
2165 "Face used for documentation strings in customization buffers."
2166 :group
'custom-faces
)
2167 (define-obsolete-face-alias 'custom-documentation-face
2168 'custom-documentation
"22.1")
2170 (defface custom-state
'((((class color
)
2172 (:foreground
"lime green"))
2175 (:foreground
"dark green"))
2177 "Face used for State descriptions in the customize buffer."
2178 :group
'custom-faces
)
2179 (define-obsolete-face-alias 'custom-state-face
'custom-state
"22.1")
2181 (defface custom-link
2182 '((t :inherit link
))
2183 "Face for links in customization buffers."
2185 :group
'custom-faces
)
2187 (define-widget 'custom
'default
2188 "Customize a user option."
2190 :convert-widget
'custom-convert-widget
2191 :notify
'custom-notify
2194 :custom-state
'hidden
2195 :documentation-property
'widget-subclass-responsibility
2196 :value-create
'widget-subclass-responsibility
2197 :value-delete
'widget-children-value-delete
2198 :value-get
'widget-value-value-get
2199 :validate
'widget-children-validate
2200 :match
(lambda (_widget value
) (symbolp value
)))
2202 (defun custom-convert-widget (widget)
2203 "Initialize :value and :tag from :args in WIDGET."
2204 (let ((args (widget-get widget
:args
)))
2206 (widget-put widget
:value
(widget-apply widget
2207 :value-to-internal
(car args
)))
2208 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2209 (widget-put widget
:args nil
)))
2212 (defun custom-notify (widget &rest args
)
2213 "Keep track of changes."
2214 (let ((state (widget-get widget
:custom-state
)))
2215 (unless (eq state
'modified
)
2216 (unless (memq state
'(nil unknown hidden
))
2217 (widget-put widget
:custom-state
'modified
))
2218 (custom-magic-reset widget
)
2219 (apply 'widget-default-notify widget args
))))
2221 (defun custom-redraw (widget)
2222 "Redraw WIDGET with current settings."
2223 (let ((line (count-lines (point-min) (point)))
2224 (column (current-column))
2226 (from (marker-position (widget-get widget
:from
)))
2227 (to (marker-position (widget-get widget
:to
))))
2229 (widget-value-set widget
(widget-value widget
))
2230 (custom-redraw-magic widget
))
2231 (when (and (>= pos from
) (<= pos to
))
2234 (goto-char (point-min))
2235 (forward-line (if (> column
0)
2238 (move-to-column column
))
2241 (defun custom-redraw-magic (widget)
2242 "Redraw WIDGET state with current settings."
2244 (let ((magic (widget-get widget
:custom-magic
)))
2246 (widget-value-set magic
(widget-value magic
))
2247 (when (setq widget
(widget-get widget
:group
))
2248 (custom-group-state-update widget
)))
2250 (setq widget nil
)))))
2253 (make-obsolete 'custom-show
"this widget type is no longer supported." "24.1")
2254 (defun custom-show (widget value
)
2255 "Non-nil if WIDGET should be shown with VALUE by default."
2256 (let ((show (widget-get widget
:custom-show
)))
2257 (if (functionp show
)
2258 (funcall show widget value
)
2261 (defun custom-load-widget (widget)
2262 "Load all dependencies for WIDGET."
2263 (custom-load-symbol (widget-value widget
)))
2265 (defun custom-unloaded-symbol-p (symbol)
2266 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2268 (loads (get symbol
'custom-loads
))
2271 (setq load
(car loads
)
2273 (cond ((symbolp load
)
2274 (unless (featurep load
)
2276 ((assoc load load-history
))
2277 ((assoc (locate-library load
) load-history
)
2283 (defun custom-unloaded-widget-p (widget)
2284 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2285 (custom-unloaded-symbol-p (widget-value widget
)))
2287 (defun custom-toggle-hide (widget)
2288 "Toggle visibility of WIDGET."
2289 (custom-load-widget widget
)
2290 (let ((state (widget-get widget
:custom-state
)))
2291 (cond ((memq state
'(invalid modified set
))
2292 (error "There are unsaved changes"))
2294 (widget-put widget
:custom-state
'unknown
))
2296 (widget-put widget
:documentation-shown nil
)
2297 (widget-put widget
:custom-state
'hidden
)))
2298 (custom-redraw widget
)
2301 (defun custom-toggle-parent (widget &rest _ignore
)
2302 "Toggle visibility of parent of WIDGET."
2303 (custom-toggle-hide (widget-get widget
:parent
)))
2305 (defun custom-add-see-also (widget &optional prefix
)
2306 "Add `See also ...' to WIDGET if there are any links.
2307 Insert PREFIX first if non-nil."
2308 (let* ((symbol (widget-get widget
:value
))
2309 (links (get symbol
'custom-links
))
2310 (many (> (length links
) 2))
2311 (buttons (widget-get widget
:buttons
))
2312 (indent (widget-get widget
:indent
)))
2315 (insert-char ?\ indent
))
2318 (insert "See also ")
2320 (push (widget-create-child-and-convert
2322 :button-face
'custom-link
2323 :mouse-face
'highlight
2324 :pressed-face
'highlight
)
2326 (setq links
(cdr links
))
2335 (widget-put widget
:buttons buttons
))))
2337 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string
)
2338 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2339 The value is non-nil if any parents were found.
2340 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2341 (let ((name (widget-value widget
))
2342 (type (widget-type widget
))
2343 (buttons (widget-get widget
:buttons
))
2346 (insert (or initial-string
"Groups:"))
2347 (mapatoms (lambda (symbol)
2348 (when (member (list name type
) (get symbol
'custom-group
))
2350 (push (widget-create-child-and-convert
2351 widget
'custom-group-link
2352 :tag
(custom-unlispify-tag-name symbol
)
2355 (setq parents
(cons symbol parents
)))))
2358 (delete-region start
(point)))
2359 (widget-put widget
:buttons buttons
)
2362 ;;; The `custom-comment' Widget.
2364 ;; like the editable field
2365 (defface custom-comment
'((((type tty
))
2366 :background
"yellow3"
2367 :foreground
"black")
2368 (((class grayscale color
)
2370 :background
"gray85")
2371 (((class grayscale color
)
2373 :background
"dim gray")
2376 "Face used for comments on variables or faces."
2378 :group
'custom-faces
)
2379 (define-obsolete-face-alias 'custom-comment-face
'custom-comment
"22.1")
2381 ;; like font-lock-comment-face
2382 (defface custom-comment-tag
2383 '((((class color
) (background dark
)) (:foreground
"gray80"))
2384 (((class color
) (background light
)) (:foreground
"blue4"))
2385 (((class grayscale
) (background light
))
2386 (:foreground
"DimGray" :weight bold
:slant italic
))
2387 (((class grayscale
) (background dark
))
2388 (:foreground
"LightGray" :weight bold
:slant italic
))
2390 "Face used for the comment tag on variables or faces."
2391 :group
'custom-faces
)
2392 (define-obsolete-face-alias 'custom-comment-tag-face
'custom-comment-tag
"22.1")
2394 (define-widget 'custom-comment
'string
2397 :help-echo
"Edit a comment here."
2398 :sample-face
'custom-comment-tag
2399 :value-face
'custom-comment
2401 :create
'custom-comment-create
)
2403 (defun custom-comment-create (widget)
2404 (let* ((null-comment (equal "" (widget-value widget
))))
2405 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2407 (widget-default-create widget
)
2408 ;; `widget-default-delete' expects markers in these slots --
2409 ;; maybe it shouldn't.
2410 (widget-put widget
:from
(point-marker))
2411 (widget-put widget
:to
(point-marker)))))
2413 (defun custom-comment-hide (widget)
2414 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2416 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2417 ;; the global custom one
2418 (defun custom-comment-show (widget)
2419 (widget-put widget
:comment-shown t
)
2420 (custom-redraw widget
)
2423 (defun custom-comment-invisible-p (widget)
2424 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2426 (not (widget-get widget
:comment-shown
)))))
2428 ;;; The `custom-variable' Widget.
2430 (defface custom-variable-tag
2433 (:foreground
"light blue" :weight bold
))
2434 (((min-colors 88) (class color
)
2436 (:foreground
"blue1" :weight bold
))
2439 (:foreground
"blue" :weight bold
))
2441 "Face used for unpushable variable tags."
2442 :group
'custom-faces
)
2443 (define-obsolete-face-alias 'custom-variable-tag-face
2444 'custom-variable-tag
"22.1")
2446 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2447 "Face used for pushable variable tags."
2448 :group
'custom-faces
)
2449 (define-obsolete-face-alias 'custom-variable-button-face
2450 'custom-variable-button
"22.1")
2452 (defcustom custom-variable-default-form
'edit
2453 "Default form of displaying variable values."
2454 :type
'(choice (const edit
)
2456 :group
'custom-buffer
2459 (defun custom-variable-documentation (variable)
2460 "Return documentation of VARIABLE for use in Custom buffer.
2461 Normally just return the docstring. But if VARIABLE automatically
2462 becomes buffer local when set, append a message to that effect."
2463 (format "%s%s" (documentation-property variable
'variable-documentation
)
2464 (if (and (local-variable-if-set-p variable
)
2465 (or (not (local-variable-p variable
))
2467 (local-variable-if-set-p variable
))))
2469 This variable automatically becomes buffer-local when set outside Custom.
2470 However, setting it through Custom sets the default value."
2473 (define-widget 'custom-variable
'custom
2474 "A widget for displaying a Custom variable.
2475 The following properties have special meanings for this widget:
2477 :hidden-states should be a list of widget states for which the
2478 widget's initial contents are to be hidden.
2480 :custom-form should be a symbol describing how to display and
2481 edit the variable---either `edit' (using edit widgets),
2482 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2483 if nil, use the return value of `custom-variable-default-form'.
2485 :shown-value, if non-nil, should be a list whose `car' is the
2486 variable value to display in place of the current value.
2488 :custom-style describes the widget interface style; nil is the
2489 default style, while `simple' means a simpler interface that
2490 inhibits the magic custom-state widget."
2492 :help-echo
"Set or reset this variable."
2493 :documentation-property
#'custom-variable-documentation
2494 :custom-category
'option
2496 :custom-menu
'custom-variable-menu-create
2498 :value-create
'custom-variable-value-create
2499 :action
'custom-variable-action
2500 :hidden-states
'(standard)
2501 :custom-set
'custom-variable-set
2502 :custom-mark-to-save
'custom-variable-mark-to-save
2503 :custom-reset-current
'custom-redraw
2504 :custom-reset-saved
'custom-variable-reset-saved
2505 :custom-reset-standard
'custom-variable-reset-standard
2506 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2507 :custom-standard-value
'custom-variable-standard-value
2508 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2510 (defun custom-variable-type (symbol)
2511 "Return a widget suitable for editing the value of SYMBOL.
2512 If SYMBOL has a `custom-type' property, use that.
2513 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2514 try matching its doc string against `custom-guess-doc-alist'."
2515 (let* ((type (or (get symbol
'custom-type
)
2516 (and (not (get symbol
'standard-value
))
2517 (custom-guess-type symbol
))
2519 (options (get symbol
'custom-options
))
2520 (tmp (if (listp type
)
2521 (copy-sequence type
)
2524 (widget-put tmp
:options options
))
2527 (defun custom-variable-value-create (widget)
2528 "Here is where you edit the variable's value."
2529 (custom-load-widget widget
)
2530 (unless (widget-get widget
:custom-form
)
2531 (widget-put widget
:custom-form custom-variable-default-form
))
2532 (let* ((buttons (widget-get widget
:buttons
))
2533 (children (widget-get widget
:children
))
2534 (form (widget-get widget
:custom-form
))
2535 (symbol (widget-get widget
:value
))
2536 (tag (widget-get widget
:tag
))
2537 (type (custom-variable-type symbol
))
2538 (conv (widget-convert type
))
2539 (get (or (get symbol
'custom-get
) 'default-value
))
2540 (prefix (widget-get widget
:custom-prefix
))
2541 (last (widget-get widget
:custom-last
))
2542 (style (widget-get widget
:custom-style
))
2543 (value (let ((shown-value (widget-get widget
:shown-value
)))
2546 ((default-boundp symbol
)
2547 (funcall get symbol
))
2548 (t (widget-get conv
:value
)))))
2549 (state (or (widget-get widget
:custom-state
)
2550 (if (memq (custom-variable-state symbol value
)
2551 (widget-get widget
:hidden-states
))
2554 ;; If we don't know the state, see if we need to edit it in lisp form.
2556 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2557 (when (eq state
'unknown
)
2558 (unless (widget-apply conv
:match value
)
2559 (setq form
'mismatch
)))
2560 ;; Now we can create the child widget.
2561 (cond ((eq custom-buffer-style
'tree
)
2562 (insert prefix
(if last
" `--- " " |--- "))
2563 (push (widget-create-child-and-convert
2564 widget
'custom-browse-variable-tag
)
2566 (insert " " tag
"\n")
2567 (widget-put widget
:buttons buttons
))
2569 ;; Indicate hidden value.
2570 (push (widget-create-child-and-convert
2571 widget
'custom-visibility
2572 :help-echo
"Show the value of this option."
2577 :action
'custom-toggle-hide-variable
2581 (push (widget-create-child-and-convert
2584 :sample-face
'custom-variable-tag
2588 ((memq form
'(lisp mismatch
))
2589 (push (widget-create-child-and-convert
2590 widget
'custom-visibility
2591 :help-echo
"Hide the value of this option."
2596 :action
'custom-toggle-hide-variable
2600 ;; This used to try presenting the saved value or the
2601 ;; standard value, but it seems more intuitive to present
2602 ;; the current value (Bug#7600).
2603 (let* ((value (cond ((default-boundp symbol
)
2604 (custom-quote (funcall get symbol
)))
2606 (custom-quote (widget-get conv
:value
))))))
2607 (insert (symbol-name symbol
) ": ")
2608 (push (widget-create-child-and-convert
2610 :button-face
'custom-variable-button-face
2612 :tag
(symbol-name symbol
)
2618 (push (widget-create-child-and-convert
2619 widget
'custom-visibility
2620 :help-echo
"Hide or show this option."
2625 :action
'custom-toggle-hide-variable
2629 (let* ((format (widget-get type
:format
))
2630 tag-format value-format
)
2631 (unless (string-match ":" format
)
2632 (error "Bad format"))
2633 (setq tag-format
(substring format
0 (match-end 0)))
2634 (setq value-format
(substring format
(match-end 0)))
2635 (push (widget-create-child-and-convert
2638 :action
'custom-tag-action
2639 :help-echo
"Change value of this option."
2640 :mouse-down-action
'custom-tag-mouse-down-action
2641 :button-face
'custom-variable-button
2642 :sample-face
'custom-variable-tag
2645 (push (widget-create-child-and-convert
2647 :format value-format
2650 (unless (eq custom-buffer-style
'tree
)
2651 (unless (eq (preceding-char) ?
\n)
2652 (widget-insert "\n"))
2653 ;; Create the magic button.
2654 (unless (eq style
'simple
)
2655 (let ((magic (widget-create-child-and-convert
2656 widget
'custom-magic nil
)))
2657 (widget-put widget
:custom-magic magic
)
2658 (push magic buttons
)))
2659 (widget-put widget
:buttons buttons
)
2660 ;; Insert documentation.
2661 (widget-put widget
:documentation-indent
3)
2662 (unless (and (eq style
'simple
)
2664 (widget-add-documentation-string-button
2665 widget
:visibility-widget
'custom-visibility
))
2667 ;; The comment field
2668 (unless (eq state
'hidden
)
2669 (let* ((comment (get symbol
'variable-comment
))
2671 (widget-create-child-and-convert
2672 widget
'custom-comment
2674 :value
(or comment
""))))
2675 (widget-put widget
:comment-widget comment-widget
)
2676 ;; Don't push it !!! Custom assumes that the first child is the
2678 (setq children
(append children
(list comment-widget
)))))
2679 ;; Update the rest of the properties.
2680 (widget-put widget
:custom-form form
)
2681 (widget-put widget
:children children
)
2682 ;; Now update the state.
2683 (if (eq state
'hidden
)
2684 (widget-put widget
:custom-state state
)
2685 (custom-variable-state-set widget
))
2687 (unless (eq state
'hidden
)
2688 (when (eq (widget-get widget
:custom-level
) 1)
2689 (custom-add-parent-links widget
))
2690 (custom-add-see-also widget
)))))
2692 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore
)
2693 "Toggle the visibility of a `custom-variable' parent widget.
2694 By default, this signals an error if the parent has unsaved
2695 changes. If the parent has a `simple' :custom-style property,
2696 the present value is saved to its :shown-value property instead."
2697 (let ((widget (widget-get visibility-widget
:parent
)))
2698 (unless (eq (widget-type widget
) 'custom-variable
)
2699 (error "Invalid widget type"))
2700 (custom-load-widget widget
)
2701 (let ((state (widget-get widget
:custom-state
)))
2702 (if (eq state
'hidden
)
2703 (widget-put widget
:custom-state
'unknown
)
2704 ;; In normal interface, widget can't be hidden if modified.
2705 (when (memq state
'(invalid modified set
))
2706 (if (eq (widget-get widget
:custom-style
) 'simple
)
2707 (widget-put widget
:shown-value
2710 (widget-get widget
:children
)))))
2711 (error "There are unsaved changes")))
2712 (widget-put widget
:documentation-shown nil
)
2713 (widget-put widget
:custom-state
'hidden
))
2714 (custom-redraw widget
)
2717 (defun custom-tag-action (widget &rest args
)
2718 "Pass :action to first child of WIDGET's parent."
2719 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2722 (defun custom-tag-mouse-down-action (widget &rest args
)
2723 "Pass :mouse-down-action to first child of WIDGET's parent."
2724 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2725 :mouse-down-action args
))
2727 (defun custom-variable-state (symbol val
)
2728 "Return the state of SYMBOL if its value is VAL.
2729 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2730 Possible return values are `standard', `saved', `set', `themed',
2731 `changed', and `rogue'."
2732 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2733 (value (if (default-boundp symbol
)
2734 (funcall get symbol
)
2736 (comment (get symbol
'variable-comment
))
2739 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2741 (get symbol
'customized-variable-comment
))
2743 (if (condition-case nil
2744 (and (equal value
(eval (car tmp
)))
2745 (equal comment temp
))
2749 ((progn (setq tmp
(get symbol
'theme-value
))
2750 (setq temp
(get symbol
'saved-variable-comment
))
2752 (if (condition-case nil
2753 (and (equal comment temp
)
2756 (car (custom-variable-theme-value
2760 ((eq (caar tmp
) 'user
) 'saved
)
2761 ((eq (caar tmp
) 'changed
)
2762 (if (condition-case nil
2766 (car (get symbol
'standard-value
)))))
2768 ;; The value was originally set outside
2769 ;; custom, but it was set to the standard
2770 ;; value (probably an autoloaded defcustom).
2775 ((setq tmp
(get symbol
'standard-value
))
2776 (if (condition-case nil
2777 (and (equal value
(eval (car tmp
)))
2778 (equal comment nil
))
2784 (defun custom-variable-state-set (widget &optional state
)
2785 "Set the state of WIDGET to STATE.
2786 If STATE is nil, the value is computed by `custom-variable-state'."
2787 (widget-put widget
:custom-state
2788 (or state
(custom-variable-state (widget-value widget
)
2789 (widget-get widget
:value
)))))
2791 (defun custom-variable-standard-value (widget)
2792 (get (widget-value widget
) 'standard-value
))
2794 (defvar custom-variable-menu
2795 `(("Set for Current Session" custom-variable-set
2797 (eq (widget-get widget
:custom-state
) 'modified
)))
2798 ;; Note that in all the backquoted code in this file, we test
2799 ;; init-file-user rather than user-init-file. This is in case
2800 ;; cus-edit is loaded by something in site-start.el, because
2801 ;; user-init-file is not set at that stage.
2802 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2803 ,@(when (or custom-file init-file-user
)
2804 '(("Save for Future Sessions" custom-variable-save
2806 (memq (widget-get widget
:custom-state
)
2807 '(modified set changed rogue
))))))
2808 ("Undo Edits" custom-redraw
2810 (and (default-boundp (widget-value widget
))
2811 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2812 ("Revert This Session's Customization" custom-variable-reset-saved
2814 (memq (widget-get widget
:custom-state
)
2815 '(modified set changed rogue
))))
2816 ,@(when (or custom-file init-file-user
)
2817 '(("Erase Customization" custom-variable-reset-standard
2819 (and (get (widget-value widget
) 'standard-value
)
2820 (memq (widget-get widget
:custom-state
)
2821 '(modified set changed saved rogue
)))))))
2822 ("Set to Backup Value" custom-variable-reset-backup
2824 (get (widget-value widget
) 'backup-value
)))
2825 ("---" ignore ignore
)
2826 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2827 ("---" ignore ignore
)
2828 ("Show Current Value" custom-variable-edit
2830 (eq (widget-get widget
:custom-form
) 'lisp
)))
2831 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2833 (eq (widget-get widget
:custom-form
) 'edit
))))
2834 "Alist of actions for the `custom-variable' widget.
2835 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2836 the menu entry, ACTION is the function to call on the widget when the
2837 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2838 widget as an argument, and returns non-nil if ACTION is valid on that
2839 widget. If FILTER is nil, ACTION is always valid.")
2841 (defun custom-variable-action (widget &optional event
)
2842 "Show the menu for `custom-variable' WIDGET.
2843 Optional EVENT is the location for the menu."
2844 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2845 (custom-toggle-hide widget
)
2846 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2847 (custom-variable-state-set widget
))
2848 (custom-redraw-magic widget
)
2849 (let* ((completion-ignore-case t
)
2850 (answer (widget-choose (concat "Operation on "
2851 (custom-unlispify-tag-name
2852 (widget-get widget
:value
)))
2853 (custom-menu-filter custom-variable-menu
2857 (funcall answer widget
)))))
2859 (defun custom-variable-edit (widget)
2860 "Edit value of WIDGET."
2861 (widget-put widget
:custom-state
'unknown
)
2862 (widget-put widget
:custom-form
'edit
)
2863 (custom-redraw widget
))
2865 (defun custom-variable-edit-lisp (widget)
2866 "Edit the Lisp representation of the value of WIDGET."
2867 (widget-put widget
:custom-state
'unknown
)
2868 (widget-put widget
:custom-form
'lisp
)
2869 (custom-redraw widget
))
2871 (defun custom-variable-set (widget)
2872 "Set the current value for the variable being edited by WIDGET."
2873 (let* ((form (widget-get widget
:custom-form
))
2874 (state (widget-get widget
:custom-state
))
2875 (child (car (widget-get widget
:children
)))
2876 (symbol (widget-value widget
))
2877 (set (or (get symbol
'custom-set
) 'set-default
))
2878 (comment-widget (widget-get widget
:comment-widget
))
2879 (comment (widget-value comment-widget
))
2881 (cond ((eq state
'hidden
)
2882 (user-error "Cannot set hidden variable"))
2883 ((setq val
(widget-apply child
:validate
))
2884 (goto-char (widget-get val
:from
))
2885 (error "%s" (widget-get val
:error
)))
2886 ((memq form
'(lisp mismatch
))
2887 (when (equal comment
"")
2889 ;; Make the comment invisible by hand if it's empty
2890 (custom-comment-hide comment-widget
))
2891 (custom-variable-backup-value widget
)
2892 (custom-push-theme 'theme-value symbol
'user
2893 'set
(custom-quote (widget-value child
)))
2894 (funcall set symbol
(eval (setq val
(widget-value child
))))
2895 (put symbol
'customized-value
(list val
))
2896 (put symbol
'variable-comment comment
)
2897 (put symbol
'customized-variable-comment comment
))
2899 (when (equal comment
"")
2901 ;; Make the comment invisible by hand if it's empty
2902 (custom-comment-hide comment-widget
))
2903 (custom-variable-backup-value widget
)
2904 (custom-push-theme 'theme-value symbol
'user
2905 'set
(custom-quote (widget-value child
)))
2906 (funcall set symbol
(setq val
(widget-value child
)))
2907 (put symbol
'customized-value
(list (custom-quote val
)))
2908 (put symbol
'variable-comment comment
)
2909 (put symbol
'customized-variable-comment comment
)))
2910 (custom-variable-state-set widget
)
2911 (custom-redraw-magic widget
)))
2913 (defun custom-variable-mark-to-save (widget)
2914 "Set value and mark for saving the variable edited by WIDGET."
2915 (let* ((form (widget-get widget
:custom-form
))
2916 (state (widget-get widget
:custom-state
))
2917 (child (car (widget-get widget
:children
)))
2918 (symbol (widget-value widget
))
2919 (set (or (get symbol
'custom-set
) 'set-default
))
2920 (comment-widget (widget-get widget
:comment-widget
))
2921 (comment (widget-value comment-widget
))
2923 (cond ((eq state
'hidden
)
2924 (user-error "Cannot set hidden variable"))
2925 ((setq val
(widget-apply child
:validate
))
2926 (goto-char (widget-get val
:from
))
2927 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2928 ((memq form
'(lisp mismatch
))
2929 (when (equal comment
"")
2931 ;; Make the comment invisible by hand if it's empty
2932 (custom-comment-hide comment-widget
))
2933 (put symbol
'saved-value
(list (widget-value child
)))
2934 (custom-push-theme 'theme-value symbol
'user
2935 'set
(custom-quote (widget-value child
)))
2936 (funcall set symbol
(eval (widget-value child
)))
2937 (put symbol
'variable-comment comment
)
2938 (put symbol
'saved-variable-comment comment
))
2940 (when (equal comment
"")
2942 ;; Make the comment invisible by hand if it's empty
2943 (custom-comment-hide comment-widget
))
2944 (put symbol
'saved-value
2945 (list (custom-quote (widget-value child
))))
2946 (custom-push-theme 'theme-value symbol
'user
2947 'set
(custom-quote (widget-value child
)))
2948 (funcall set symbol
(widget-value child
))
2949 (put symbol
'variable-comment comment
)
2950 (put symbol
'saved-variable-comment comment
)))
2951 (put symbol
'customized-value nil
)
2952 (put symbol
'customized-variable-comment nil
)))
2954 (defsubst custom-variable-state-set-and-redraw
(widget)
2955 "Set state of variable widget WIDGET and redraw with current settings."
2956 (custom-variable-state-set widget
)
2957 (custom-redraw-magic widget
))
2959 (defun custom-variable-save (widget)
2960 "Save value of variable edited by widget WIDGET."
2961 (custom-variable-mark-to-save widget
)
2963 (custom-variable-state-set-and-redraw widget
))
2965 (defun custom-variable-reset-saved (widget)
2966 "Restore the value of the variable being edited by WIDGET.
2967 If there is a saved value, restore it; otherwise reset to the
2968 uncustomized (themed or standard) value.
2970 Update the widget to show that value. The value that was current
2971 before this operation becomes the backup value."
2972 (let* ((symbol (widget-value widget
))
2973 (saved-value (get symbol
'saved-value
))
2974 (comment (get symbol
'saved-variable-comment
)))
2975 (custom-variable-backup-value widget
)
2976 (if (not (or saved-value comment
))
2977 ;; If there is no saved value, remove the setting.
2978 (custom-push-theme 'theme-value symbol
'user
'reset
)
2979 ;; Otherwise, apply the saved value.
2980 (put symbol
'variable-comment comment
)
2981 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe saved-value
))
2983 (funcall (or (get symbol
'custom-set
) 'set-default
)
2984 symbol
(eval (car saved-value
)))))
2985 (put symbol
'customized-value nil
)
2986 (put symbol
'customized-variable-comment nil
)
2987 (widget-put widget
:custom-state
'unknown
)
2988 ;; This call will possibly make the comment invisible
2989 (custom-redraw widget
)))
2991 (defun custom-variable-mark-to-reset-standard (widget)
2992 "Mark to restore standard setting for the variable edited by widget WIDGET.
2993 If `custom-reset-standard-variables-list' is nil, save, reset and
2994 redraw the widget immediately."
2995 (let* ((symbol (widget-value widget
)))
2996 (if (get symbol
'standard-value
)
2997 (custom-variable-backup-value widget
)
2998 (user-error "No standard setting known for %S" symbol
))
2999 (put symbol
'variable-comment nil
)
3000 (put symbol
'customized-value nil
)
3001 (put symbol
'customized-variable-comment nil
)
3002 (custom-push-theme 'theme-value symbol
'user
'reset
)
3003 (custom-theme-recalc-variable symbol
)
3004 (if (and custom-reset-standard-variables-list
3005 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
3007 (put symbol
'saved-value nil
)
3008 (put symbol
'saved-variable-comment nil
)
3009 ;; Append this to `custom-reset-standard-variables-list' to
3010 ;; have `custom-reset-standard-save-and-update' save setting
3011 ;; to the file, update the widget's state, and redraw it.
3012 (setq custom-reset-standard-variables-list
3013 (cons widget custom-reset-standard-variables-list
)))
3014 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
3015 (put symbol
'saved-value nil
)
3016 (put symbol
'saved-variable-comment nil
)
3018 (widget-put widget
:custom-state
'unknown
)
3019 ;; This call will possibly make the comment invisible
3020 (custom-redraw widget
))))
3022 (defun custom-variable-reset-standard (widget)
3023 "Restore standard setting for the variable edited by WIDGET.
3024 This operation eliminates any saved setting for the variable,
3025 restoring it to the state of a variable that has never been customized.
3026 The value that was current before this operation
3027 becomes the backup value, so you can get it again."
3028 (let (custom-reset-standard-variables-list)
3029 (custom-variable-mark-to-reset-standard widget
)))
3031 (defun custom-variable-backup-value (widget)
3032 "Back up the current value for WIDGET's variable.
3033 The backup value is kept in the car of the `backup-value' property."
3034 (let* ((symbol (widget-value widget
))
3035 (get (or (get symbol
'custom-get
) 'default-value
))
3036 (type (custom-variable-type symbol
))
3037 (conv (widget-convert type
))
3038 (value (if (default-boundp symbol
)
3039 (funcall get symbol
)
3040 (widget-get conv
:value
))))
3041 (put symbol
'backup-value
(list value
))))
3043 (defun custom-variable-reset-backup (widget)
3044 "Restore the backup value for the variable being edited by WIDGET.
3045 The value that was current before this operation
3046 becomes the backup value, so you can use this operation repeatedly
3047 to switch between two values."
3048 (let* ((symbol (widget-value widget
))
3049 (set (or (get symbol
'custom-set
) 'set-default
))
3050 (value (get symbol
'backup-value
))
3051 (comment-widget (widget-get widget
:comment-widget
))
3052 (comment (widget-value comment-widget
)))
3055 (custom-variable-backup-value widget
)
3056 (custom-push-theme 'theme-value symbol
'user
'set value
)
3058 (funcall set symbol
(car value
))
3060 (user-error "No backup value for %s" symbol
))
3061 (put symbol
'customized-value
(list (custom-quote (car value
))))
3062 (put symbol
'variable-comment comment
)
3063 (put symbol
'customized-variable-comment comment
)
3064 (custom-variable-state-set widget
)
3065 ;; This call will possibly make the comment invisible
3066 (custom-redraw widget
)))
3068 ;;; The `custom-visibility' Widget
3070 (define-widget 'custom-visibility
'visibility
3071 "Show or hide a documentation string."
3072 :button-face
'custom-visibility
3073 :pressed-face
'custom-visibility
3074 :mouse-face
'highlight
3075 :pressed-face
'highlight
3079 (defface custom-visibility
3080 '((t :height
0.8 :inherit link
))
3081 "Face for the `custom-visibility' widget."
3083 :group
'custom-faces
)
3085 ;;; The `custom-face-edit' Widget.
3087 (define-widget 'custom-face-edit
'checklist
3088 "Widget for editing face attributes.
3089 The following properties have special meanings for this widget:
3091 :value is a plist of face attributes.
3093 :default-face-attributes, if non-nil, is a plist of defaults for
3094 face attributes (as specified by a `default' defface entry)."
3097 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3098 :value-to-internal
'custom-face-edit-fix-value
3099 :match
(lambda (widget value
)
3100 (widget-checklist-match widget
3101 (custom-face-edit-fix-value widget value
)))
3102 :value-create
'custom-face-edit-value-create
3103 :convert-widget
'custom-face-edit-convert-widget
3104 :args
(mapcar (lambda (att)
3105 (list 'group
:inline t
3106 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3107 (list 'const
:format
"" :value
(nth 0 att
))
3109 custom-face-attributes
))
3111 (defun custom-face-edit-value-create (widget)
3112 (let* ((alist (widget-checklist-match-find
3113 widget
(widget-get widget
:value
)))
3114 (args (widget-get widget
:args
))
3115 (show-all (widget-get widget
:show-all-attributes
))
3116 (buttons (widget-get widget
:buttons
))
3117 (defaults (widget-checklist-match-find
3119 (widget-get widget
:default-face-attributes
)))
3121 (unless (looking-back "^ *")
3123 (insert-char ?\s
(widget-get widget
:extra-offset
))
3124 (if (or alist defaults show-all
)
3126 (setq entry
(or (assq prop alist
)
3127 (assq prop defaults
)))
3128 (if (or entry show-all
)
3129 (widget-checklist-add-item widget prop entry
)))
3130 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3131 (let ((indent (widget-get widget
:indent
)))
3132 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3133 (push (widget-create-child-and-convert
3135 :help-echo
"Show or hide all face attributes."
3136 :button-face
'custom-visibility
3137 :pressed-face
'custom-visibility
3138 :mouse-face
'highlight
3139 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3140 :on-glyph nil
:off-glyph nil
3142 :action
'custom-face-edit-value-visibility-action
3146 (widget-put widget
:buttons buttons
)
3147 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3149 (defun custom-face-edit-value-visibility-action (widget &rest _ignore
)
3150 ;; Toggle hiding of face attributes.
3151 (let ((parent (widget-get widget
:parent
)))
3152 (widget-put parent
:show-all-attributes
3153 (not (widget-get parent
:show-all-attributes
)))
3154 (custom-redraw parent
)))
3156 (defun custom-face-edit-fix-value (_widget value
)
3157 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3158 Also change :reverse-video to :inverse-video."
3159 (custom-fix-face-spec value
))
3161 (defun custom-face-edit-convert-widget (widget)
3162 "Convert :args as widget types in WIDGET."
3165 :args
(mapcar (lambda (arg)
3167 :deactivate
'custom-face-edit-deactivate
3168 :activate
'custom-face-edit-activate
3169 :delete
'custom-face-edit-delete
))
3170 (widget-get widget
:args
)))
3173 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3174 "Converted version of the `custom-face-edit' widget.")
3176 (defun custom-face-edit-deactivate (widget)
3177 "Make face widget WIDGET inactive for user modifications."
3178 (unless (widget-get widget
:inactive
)
3179 (let ((tag (custom-face-edit-attribute-tag widget
))
3180 (from (copy-marker (widget-get widget
:from
)))
3181 (value (widget-value widget
))
3182 (inhibit-read-only t
)
3183 (inhibit-modification-hooks t
))
3186 (widget-default-delete widget
)
3187 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3188 (widget-put widget
:inactive
3189 (cons value
(cons from
(- (point) from
))))))))
3191 (defun custom-face-edit-activate (widget)
3192 "Make face widget WIDGET active for user modifications."
3193 (let ((inactive (widget-get widget
:inactive
))
3194 (inhibit-read-only t
)
3195 (inhibit-modification-hooks t
))
3196 (when (consp inactive
)
3198 (goto-char (car (cdr inactive
)))
3199 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3200 (widget-put widget
:inactive nil
)
3201 (widget-apply widget
:create
)
3202 (widget-value-set widget
(car inactive
))
3205 (defun custom-face-edit-delete (widget)
3206 "Remove WIDGET from the buffer."
3207 (let ((inactive (widget-get widget
:inactive
))
3208 (inhibit-read-only t
)
3209 (inhibit-modification-hooks t
))
3211 ;; Widget is alive, we don't have to do anything special
3212 (widget-default-delete widget
)
3213 ;; WIDGET is already deleted because we did so to deactivate it;
3214 ;; now just get rid of the label we put in its place.
3215 (delete-region (car (cdr inactive
))
3216 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3217 (widget-put widget
:inactive nil
))))
3220 (defun custom-face-edit-attribute-tag (widget)
3221 "Return the first :tag property in WIDGET or one of its children."
3222 (let ((tag (widget-get widget
:tag
)))
3223 (or (and (not (equal tag
"")) tag
)
3224 (let ((children (widget-get widget
:children
)))
3225 (while (and (null tag
) children
)
3226 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3229 ;;; The `custom-display' Widget.
3231 (define-widget 'custom-display
'menu-choice
3232 "Select a display type."
3235 :help-echo
"Specify frames where the face attributes should be used."
3236 :args
'((const :tag
"all" t
)
3237 (const :tag
"defaults" default
)
3239 :tag
"specific display"
3242 :args
((group :sibling-args
(:help-echo
"\
3243 Only match the specified window systems.")
3244 (const :format
"Type: "
3246 (checklist :inline t
3249 :sibling-args
(:help-echo
"\
3250 The X11 Window System.")
3252 (const :format
"PM "
3253 :sibling-args
(:help-echo
"\
3254 OS/2 Presentation Manager.")
3256 (const :format
"W32 "
3257 :sibling-args
(:help-echo
"\
3260 (const :format
"NS "
3261 :sibling-args
(:help-echo
"\
3262 GNUstep or Macintosh OS Cocoa interface.")
3264 (const :format
"DOS "
3265 :sibling-args
(:help-echo
"\
3268 (const :format
"TTY%n"
3269 :sibling-args
(:help-echo
"\
3270 Plain text terminals.")
3272 (group :sibling-args
(:help-echo
"\
3273 Only match the frames with the specified color support.")
3274 (const :format
"Class: "
3276 (checklist :inline t
3278 (const :format
"Color "
3279 :sibling-args
(:help-echo
"\
3280 Match color frames.")
3282 (const :format
"Grayscale "
3283 :sibling-args
(:help-echo
"\
3284 Match grayscale frames.")
3286 (const :format
"Monochrome%n"
3287 :sibling-args
(:help-echo
"\
3288 Match frames with no color support.")
3290 (group :sibling-args
(:help-echo
"\
3291 The minimum number of colors the frame should support.")
3292 (const :format
"" min-colors
)
3293 (integer :tag
"Minimum number of colors" ))
3294 (group :sibling-args
(:help-echo
"\
3295 Only match frames with the specified intensity.")
3297 Background brightness: "
3299 (checklist :inline t
3301 (const :format
"Light "
3302 :sibling-args
(:help-echo
"\
3303 Match frames with light backgrounds.")
3305 (const :format
"Dark\n"
3306 :sibling-args
(:help-echo
"\
3307 Match frames with dark backgrounds.")
3309 (group :sibling-args
(:help-echo
"\
3310 Only match frames that support the specified face attributes.")
3311 (const :format
"Supports attributes:" supports
)
3312 (custom-face-edit :inline t
:format
"%n%v"))))))
3314 ;;; The `custom-face' Widget.
3316 (defface custom-face-tag
3317 `((t :inherit custom-variable-tag
))
3318 "Face used for face tags."
3319 :group
'custom-faces
)
3320 (define-obsolete-face-alias 'custom-face-tag-face
'custom-face-tag
"22.1")
3322 (defcustom custom-face-default-form
'selected
3323 "Default form of displaying face definition."
3324 :type
'(choice (const all
)
3327 :group
'custom-buffer
3330 (define-widget 'custom-face
'custom
3331 "Widget for customizing a face.
3332 The following properties have special meanings for this widget:
3334 :value is the face name (a symbol).
3336 :custom-form should be a symbol describing how to display and
3337 edit the face attributes---either `selected' (attributes for
3338 selected display only), `all' (all attributes), `lisp' (as a
3339 Lisp sexp), or `mismatch' (should not happen); if nil, use
3340 the return value of `custom-face-default-form'.
3342 :custom-style describes the widget interface style; nil is the
3343 default style, while `simple' means a simpler interface that
3344 inhibits the magic custom-state widget.
3346 :sample-indent, if non-nil, is the number of columns to which to
3347 indent the face sample (an integer).
3349 :shown-value, if non-nil, is the face spec to display as the value
3350 of the widget, instead of the current face spec."
3351 :sample-face
'custom-face-tag
3352 :help-echo
"Set or reset this face."
3353 :documentation-property
#'face-doc-string
3354 :value-create
'custom-face-value-create
3355 :action
'custom-face-action
3356 :custom-category
'face
3358 :custom-set
'custom-face-set
3359 :custom-mark-to-save
'custom-face-mark-to-save
3360 :custom-reset-current
'custom-redraw
3361 :custom-reset-saved
'custom-face-reset-saved
3362 :custom-reset-standard
'custom-face-reset-standard
3363 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3364 :custom-standard-value
'custom-face-standard-value
3365 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3366 :custom-menu
'custom-face-menu-create
)
3368 (define-widget 'custom-face-all
'editable-list
3369 "An editable list of display specifications and attributes."
3370 :entry-format
"%i %d %v"
3371 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3372 :append-button-args
'(:help-echo
"Append new display specification here.")
3373 :delete-button-args
'(:help-echo
"Delete this display specification.")
3374 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3376 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3377 "Converted version of the `custom-face-all' widget.")
3379 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3380 "Return a canonicalized version of SPEC using.
3381 FILTER-INDEX is the index in the entry for each attribute in
3382 `custom-face-attributes' at which the appropriate filter function can be
3383 found, and DEFAULT-FILTER is the filter to apply for attributes that
3385 (mapcar (lambda (entry)
3386 ;; Filter a single face-spec entry
3387 (let ((tests (car entry
))
3389 ;; Handle both old- and new-style attribute syntax
3390 (if (listp (car (cdr entry
)))
3393 (filtered-attrs nil
))
3394 ;; Filter each face attribute
3395 (while unfiltered-attrs
3396 (let* ((attr (pop unfiltered-attrs
))
3397 (pre-filtered-value (pop unfiltered-attrs
))
3399 (or (nth filter-index
(assq attr custom-face-attributes
))
3403 (funcall filter pre-filtered-value
)
3404 pre-filtered-value
)))
3405 (push filtered-value filtered-attrs
)
3406 (push attr filtered-attrs
)))
3408 (list tests filtered-attrs
)))
3411 (defun custom-pre-filter-face-spec (spec)
3412 "Return SPEC changed as necessary for editing by the face customization widget.
3413 SPEC must be a full face spec."
3414 (custom-filter-face-spec spec
2))
3416 (defun custom-post-filter-face-spec (spec)
3417 "Return the customized SPEC in a form suitable for setting the face."
3418 (custom-filter-face-spec spec
3))
3420 (defun custom-face-widget-to-spec (widget)
3421 "Return a face spec corresponding to WIDGET.
3422 WIDGET should be a `custom-face' widget."
3423 (unless (eq (widget-type widget
) 'custom-face
)
3424 (error "Invalid widget"))
3425 (let ((child (car (widget-get widget
:children
))))
3426 (custom-post-filter-face-spec
3427 (if (eq (widget-type child
) 'custom-face-edit
)
3428 `((t ,(widget-value child
)))
3429 (widget-value child
)))))
3431 (defun custom-face-get-current-spec (face)
3432 (let ((spec (or (get face
'customized-face
)
3433 (get face
'saved-face
)
3434 (get face
'face-defface-spec
)
3435 ;; Attempt to construct it.
3436 `((t ,(custom-face-attributes-get
3437 face
(selected-frame)))))))
3438 ;; If the user has changed this face in some other way,
3439 ;; edit it as the user has specified it.
3440 (if (not (face-spec-match-p face spec
(selected-frame)))
3441 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3442 (custom-pre-filter-face-spec spec
)))
3444 (defun custom-toggle-hide-face (visibility-widget &rest _ignore
)
3445 "Toggle the visibility of a `custom-face' parent widget.
3446 By default, this signals an error if the parent has unsaved
3447 changes. If the parent has a `simple' :custom-style property,
3448 the present value is saved to its :shown-value property instead."
3449 (let ((widget (widget-get visibility-widget
:parent
)))
3450 (unless (eq (widget-type widget
) 'custom-face
)
3451 (error "Invalid widget type"))
3452 (custom-load-widget widget
)
3453 (let ((state (widget-get widget
:custom-state
)))
3454 (if (eq state
'hidden
)
3455 (widget-put widget
:custom-state
'unknown
)
3456 ;; In normal interface, widget can't be hidden if modified.
3457 (when (memq state
'(invalid modified set
))
3458 (if (eq (widget-get widget
:custom-style
) 'simple
)
3459 (widget-put widget
:shown-value
3460 (custom-face-widget-to-spec widget
))
3461 (error "There are unsaved changes")))
3462 (widget-put widget
:documentation-shown nil
)
3463 (widget-put widget
:custom-state
'hidden
))
3464 (custom-redraw widget
)
3467 (defun custom-face-value-create (widget)
3468 "Create a list of the display specifications for WIDGET."
3469 (let* ((buttons (widget-get widget
:buttons
))
3470 (symbol (widget-get widget
:value
))
3471 (tag (or (widget-get widget
:tag
)
3472 (prin1-to-string symbol
)))
3473 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3474 (style (widget-get widget
:custom-style
))
3477 (if (eq custom-buffer-style
'tree
)
3479 ;; Draw a tree-style `custom-face' widget
3481 (insert (widget-get widget
:custom-prefix
)
3482 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3483 (push (widget-create-child-and-convert
3484 widget
'custom-browse-face-tag
)
3486 (insert " " tag
"\n")
3487 (widget-put widget
:buttons buttons
))
3489 ;; Draw an ordinary `custom-face' widget
3490 (let ((opoint (point)))
3491 ;; Visibility indicator.
3492 (push (widget-create-child-and-convert
3493 widget
'custom-visibility
3494 :help-echo
"Hide or show this face."
3495 :on
"Hide" :off
"Show"
3496 :on-glyph
"down" :off-glyph
"right"
3497 :action
'custom-toggle-hide-face
3502 (widget-specify-sample widget opoint
(point)))
3504 (cond ((eq custom-buffer-style
'face
) " ")
3505 ((string-match "face\\'" tag
) ":")
3509 (let ((sample-indent (widget-get widget
:sample-indent
))
3510 (indent-tabs-mode nil
))
3512 (<= (current-column) sample-indent
)
3513 (indent-to-column sample-indent
)))
3514 (push (widget-create-child-and-convert
3517 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3518 (if spec
(face-spec-choose spec
) symbol
))
3524 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3525 (let ((magic (widget-create-child-and-convert
3526 widget
'custom-magic nil
)))
3527 (widget-put widget
:custom-magic magic
)
3528 (push magic buttons
)))
3531 (widget-put widget
:buttons buttons
)
3533 ;; Insert documentation.
3534 (unless (and hiddenp
(eq style
'simple
))
3535 (widget-put widget
:documentation-indent
3)
3536 (widget-add-documentation-string-button
3537 widget
:visibility-widget
'custom-visibility
)
3538 ;; The comment field
3540 (let* ((comment (get symbol
'face-comment
))
3542 (widget-create-child-and-convert
3543 widget
'custom-comment
3545 :value
(or comment
""))))
3546 (widget-put widget
:comment-widget comment-widget
)
3547 (push comment-widget children
))))
3550 (unless (eq (preceding-char) ?
\n)
3553 (custom-load-widget widget
)
3554 (unless (widget-get widget
:custom-form
)
3555 (widget-put widget
:custom-form custom-face-default-form
))
3557 (let* ((spec (or (widget-get widget
:shown-value
)
3558 (custom-face-get-current-spec symbol
)))
3559 (form (widget-get widget
:custom-form
))
3560 (indent (widget-get widget
:indent
))
3561 face-alist face-entry spec-default spec-match editor
)
3563 ;; Find a display in SPEC matching the selected display.
3564 ;; This will use the usual face customization interface.
3565 (setq face-alist spec
)
3566 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3567 (setq spec-default
(pop face-alist
)))
3569 (while (and face-alist
(listp face-alist
) (null spec-match
))
3570 (setq face-entry
(car face-alist
))
3571 (and (listp face-entry
)
3572 (face-spec-set-match-display (car face-entry
)
3574 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3575 (setq spec-match face-entry
))
3576 (setq face-alist
(cdr face-alist
)))
3578 ;; Insert the appropriate editing widget.
3581 ((and (eq form
'selected
)
3582 (or spec-match spec-default
))
3583 (when indent
(insert-char ?\s indent
))
3584 (widget-create-child-and-convert
3585 widget
'custom-face-edit
3586 :value
(cadr spec-match
)
3587 :default-face-attributes
(cadr spec-default
)))
3588 ((and (not (eq form
'lisp
))
3589 (widget-apply custom-face-all
:match spec
))
3590 (widget-create-child-and-convert
3591 widget
'custom-face-all
:value spec
))
3594 (insert-char ?\s indent
))
3595 (widget-create-child-and-convert
3596 widget
'sexp
:value spec
))))
3597 (custom-face-state-set widget
)
3598 (push editor children
)
3599 (widget-put widget
:children children
))))))
3601 (defvar custom-face-menu
3602 `(("Set for Current Session" custom-face-set
)
3603 ,@(when (or custom-file init-file-user
)
3604 '(("Save for Future Sessions" custom-face-save
)))
3605 ("Undo Edits" custom-redraw
3607 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3608 ("Revert This Session's Customization" custom-face-reset-saved
3610 (memq (widget-get widget
:custom-state
) '(modified set changed
))))
3611 ,@(when (or custom-file init-file-user
)
3612 '(("Erase Customization" custom-face-reset-standard
3614 (get (widget-value widget
) 'face-defface-spec
)))))
3615 ("---" ignore ignore
)
3616 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3617 ("---" ignore ignore
)
3618 ("For Current Display" custom-face-edit-selected
3620 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3621 ("For All Kinds of Displays" custom-face-edit-all
3623 (not (eq (widget-get widget
:custom-form
) 'all
))))
3624 ("Show Lisp Expression" custom-face-edit-lisp
3626 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3627 "Alist of actions for the `custom-face' widget.
3628 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3629 the menu entry, ACTION is the function to call on the widget when the
3630 menu is selected, and FILTER is a predicate which takes a `custom-face'
3631 widget as an argument, and returns non-nil if ACTION is valid on that
3632 widget. If FILTER is nil, ACTION is always valid.")
3634 (defun custom-face-edit-selected (widget)
3635 "Edit selected attributes of the value of WIDGET."
3636 (widget-put widget
:custom-state
'unknown
)
3637 (widget-put widget
:custom-form
'selected
)
3638 (custom-redraw widget
))
3640 (defun custom-face-edit-all (widget)
3641 "Edit all attributes of the value of WIDGET."
3642 (widget-put widget
:custom-state
'unknown
)
3643 (widget-put widget
:custom-form
'all
)
3644 (custom-redraw widget
))
3646 (defun custom-face-edit-lisp (widget)
3647 "Edit the Lisp representation of the value of WIDGET."
3648 (widget-put widget
:custom-state
'unknown
)
3649 (widget-put widget
:custom-form
'lisp
)
3650 (custom-redraw widget
))
3652 (defun custom-face-state (face)
3653 "Return the current state of the face FACE.
3654 This is one of `set', `saved', `changed', `themed', or `rogue'."
3655 (let* ((comment (get face
'face-comment
))
3658 ((or (get face
'customized-face
)
3659 (get face
'customized-face-comment
))
3660 (if (equal (get face
'customized-face-comment
) comment
)
3663 ((or (get face
'saved-face
)
3664 (get face
'saved-face-comment
))
3665 (cond ((not (equal (get face
'saved-face-comment
) comment
))
3667 ((eq 'user
(caar (get face
'theme-face
)))
3669 ((eq 'changed
(caar (get face
'theme-face
)))
3672 ((get face
'face-defface-spec
)
3673 (cond (comment 'changed
)
3674 ((get face
'theme-face
) 'themed
)
3677 ;; If the user called set-face-attribute to change the default for
3678 ;; new frames, this face is "set outside of Customize".
3679 (if (and (not (eq state
'rogue
))
3680 (get face
'face-modified
))
3684 (defun custom-face-state-set (widget)
3685 "Set the state of WIDGET."
3686 (widget-put widget
:custom-state
3687 (custom-face-state (widget-value widget
))))
3689 (defun custom-face-action (widget &optional event
)
3690 "Show the menu for `custom-face' WIDGET.
3691 Optional EVENT is the location for the menu."
3692 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3693 (custom-toggle-hide widget
)
3694 (let* ((completion-ignore-case t
)
3695 (symbol (widget-get widget
:value
))
3696 (answer (widget-choose (concat "Operation on "
3697 (custom-unlispify-tag-name symbol
))
3698 (custom-menu-filter custom-face-menu
3702 (funcall answer widget
)))))
3704 (defun custom-face-set (widget)
3705 "Make the face attributes in WIDGET take effect."
3706 (let* ((symbol (widget-value widget
))
3707 (value (custom-face-widget-to-spec widget
))
3708 (comment-widget (widget-get widget
:comment-widget
))
3709 (comment (widget-value comment-widget
)))
3710 (when (equal comment
"")
3712 ;; Make the comment invisible by hand if it's empty
3713 (custom-comment-hide comment-widget
))
3714 (put symbol
'customized-face value
)
3715 (custom-push-theme 'theme-face symbol
'user
'set value
)
3716 (if (face-spec-choose value
)
3717 (face-spec-set symbol value t
)
3718 ;; face-set-spec ignores empty attribute lists, so just give it
3719 ;; something harmless instead.
3720 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3721 (put symbol
'customized-face-comment comment
)
3722 (put symbol
'face-comment comment
)
3723 (custom-face-state-set widget
)
3724 (custom-redraw-magic widget
)))
3726 (defun custom-face-mark-to-save (widget)
3727 "Mark for saving the face edited by WIDGET."
3728 (let* ((symbol (widget-value widget
))
3729 (value (custom-face-widget-to-spec widget
))
3730 (comment-widget (widget-get widget
:comment-widget
))
3731 (comment (widget-value comment-widget
)))
3732 (when (equal comment
"")
3734 ;; Make the comment invisible by hand if it's empty
3735 (custom-comment-hide comment-widget
))
3736 (custom-push-theme 'theme-face symbol
'user
'set value
)
3737 (if (face-spec-choose value
)
3738 (face-spec-set symbol value t
)
3739 ;; face-set-spec ignores empty attribute lists, so just give it
3740 ;; something harmless instead.
3741 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3742 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3743 (put symbol
'saved-face value
))
3744 (put symbol
'customized-face nil
)
3745 (put symbol
'face-comment comment
)
3746 (put symbol
'customized-face-comment nil
)
3747 (put symbol
'saved-face-comment comment
)))
3749 (defsubst custom-face-state-set-and-redraw
(widget)
3750 "Set state of face widget WIDGET and redraw with current settings."
3751 (custom-face-state-set widget
)
3752 (custom-redraw-magic widget
))
3754 (defun custom-face-save (widget)
3755 "Save the face edited by WIDGET."
3756 (custom-face-mark-to-save widget
)
3758 (custom-face-state-set-and-redraw widget
))
3760 ;; For backward compatibility.
3761 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3764 (defun custom-face-reset-saved (widget)
3765 "Restore WIDGET to the face's default attributes.
3766 If there is a saved face, restore it; otherwise reset to the
3767 uncustomized (themed or standard) face."
3768 (let* ((face (widget-value widget
))
3769 (child (car (widget-get widget
:children
)))
3770 (saved-face (get face
'saved-face
))
3771 (comment (get face
'saved-face-comment
))
3772 (comment-widget (widget-get widget
:comment-widget
)))
3773 (put face
'customized-face nil
)
3774 (put face
'customized-face-comment nil
)
3775 (custom-push-theme 'theme-face face
'user
3776 (if saved-face
'set
'reset
)
3778 (face-spec-set face saved-face t
)
3779 (put face
'face-comment comment
)
3780 (widget-value-set child saved-face
)
3781 ;; This call manages the comment visibility
3782 (widget-value-set comment-widget
(or comment
""))
3783 (custom-face-state-set widget
)
3784 (custom-redraw widget
)))
3786 (defun custom-face-standard-value (widget)
3787 (get (widget-value widget
) 'face-defface-spec
))
3789 (defun custom-face-mark-to-reset-standard (widget)
3790 "Restore widget WIDGET to the face's standard attribute values.
3791 If `custom-reset-standard-faces-list' is nil, save, reset and
3792 redraw the widget immediately."
3793 (let* ((symbol (widget-value widget
))
3794 (child (car (widget-get widget
:children
)))
3795 (value (get symbol
'face-defface-spec
))
3796 (comment-widget (widget-get widget
:comment-widget
)))
3798 (user-error "No standard setting for this face"))
3799 (put symbol
'customized-face nil
)
3800 (put symbol
'customized-face-comment nil
)
3801 (custom-push-theme 'theme-face symbol
'user
'reset
)
3802 (face-spec-set symbol value t
)
3803 (custom-theme-recalc-face symbol
)
3804 (if (and custom-reset-standard-faces-list
3805 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3808 (put symbol
'saved-face nil
)
3809 (put symbol
'saved-face-comment nil
)
3810 ;; Append this to `custom-reset-standard-faces-list' and have
3811 ;; `custom-reset-standard-save-and-update' save setting to the
3812 ;; file, update the widget's state, and redraw it.
3813 (setq custom-reset-standard-faces-list
3814 (cons widget custom-reset-standard-faces-list
)))
3815 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3816 (put symbol
'saved-face nil
)
3817 (put symbol
'saved-face-comment nil
)
3819 (put symbol
'face-comment nil
)
3820 (widget-value-set child
3821 (custom-pre-filter-face-spec
3822 (list (list t
(custom-face-attributes-get
3824 ;; This call manages the comment visibility
3825 (widget-value-set comment-widget
"")
3826 (custom-face-state-set widget
)
3827 (custom-redraw-magic widget
))))
3829 (defun custom-face-reset-standard (widget)
3830 "Restore WIDGET to the face's standard attribute values.
3831 This operation eliminates any saved attributes for the face,
3832 restoring it to the state of a face that has never been customized."
3833 (let (custom-reset-standard-faces-list)
3834 (custom-face-mark-to-reset-standard widget
)))
3836 ;;; The `face' Widget.
3838 (defvar widget-face-prompt-value-history nil
3839 "History of input to `widget-face-prompt-value'.")
3841 (define-widget 'face
'symbol
3842 "A Lisp face name (with sample)."
3843 :format
"%{%t%}: (%{sample%}) %v"
3846 :sample-face-get
'widget-face-sample-face-get
3847 :notify
'widget-face-notify
3848 :match
(lambda (_widget value
) (facep value
))
3849 :completions
(apply-partially #'completion-table-with-predicate
3850 obarray
#'facep
'strict
)
3851 :prompt-match
'facep
3852 :prompt-history
'widget-face-prompt-value-history
3853 :validate
(lambda (widget)
3854 (unless (facep (widget-value widget
))
3856 :error
(format "Invalid face: %S"
3857 (widget-value widget
)))
3860 (defun widget-face-sample-face-get (widget)
3861 (let ((value (widget-value widget
)))
3866 (defun widget-face-notify (widget child
&optional event
)
3867 "Update the sample, and notify the parent."
3868 (overlay-put (widget-get widget
:sample-overlay
)
3869 'face
(widget-apply widget
:sample-face-get
))
3870 (widget-default-notify widget child event
))
3873 ;;; The `hook' Widget.
3875 (define-widget 'hook
'list
3876 "An Emacs Lisp hook."
3877 :value-to-internal
(lambda (_widget value
)
3878 (if (and value
(symbolp value
))
3881 :match
(lambda (widget value
)
3883 (widget-group-match widget value
)))
3884 ;; Avoid adding undefined functions to the hook, especially for
3885 ;; things like `find-file-hook' or even more basic ones, to avoid
3887 :set
(lambda (symbol value
)
3890 (add-hook symbol elt
))))
3891 :convert-widget
'custom-hook-convert-widget
3894 (defun custom-hook-convert-widget (widget)
3895 ;; Handle `:options'.
3896 (let* ((options (widget-get widget
:options
))
3897 (other `(editable-list :inline t
3898 :entry-format
"%i %d%v"
3899 (function :format
" %v")))
3901 (list `(checklist :inline t
3902 ,@(mapcar (lambda (entry)
3903 `(function-item ,entry
))
3907 (widget-put widget
:args args
)
3910 ;;; The `custom-group-link' Widget.
3912 (define-widget 'custom-group-link
'link
3913 "Show parent in other window when activated."
3914 :button-face
'custom-link
3915 :mouse-face
'highlight
3916 :pressed-face
'highlight
3917 :help-echo
"Create customization buffer for this group."
3918 :keymap custom-mode-link-map
3919 :follow-link
'mouse-face
3920 :action
'custom-group-link-action
)
3922 (defun custom-group-link-action (widget &rest _ignore
)
3923 (customize-group (widget-value widget
)))
3925 ;;; The `custom-group' Widget.
3927 (defcustom custom-group-tag-faces nil
3928 "Face used for group tags.
3929 The first member is used for level 1 groups, the second for level 2,
3930 and so forth. The remaining group tags are shown with `custom-group-tag'."
3931 :type
'(repeat face
)
3932 :group
'custom-faces
)
3934 (defface custom-group-tag-1
3937 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3938 (((min-colors 88) (class color
)
3940 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3943 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3945 "Face used for group tags."
3946 :group
'custom-faces
)
3947 (define-obsolete-face-alias 'custom-group-tag-face-1
'custom-group-tag-1
"22.1")
3949 (defface custom-group-tag
3952 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3953 (((min-colors 88) (class color
)
3955 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3958 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3960 "Face used for low level group tags."
3961 :group
'custom-faces
)
3962 (define-obsolete-face-alias 'custom-group-tag-face
'custom-group-tag
"22.1")
3964 (defface custom-group-subtitle
3965 `((t (:weight bold
)))
3966 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3967 :group
'custom-faces
)
3969 (defvar custom-group-doc-align-col
20)
3971 (define-widget 'custom-group
'custom
3974 :sample-face-get
'custom-group-sample-face-get
3975 :documentation-property
'group-documentation
3976 :help-echo
"Set or reset all members of this group."
3977 :value-create
'custom-group-value-create
3978 :action
'custom-group-action
3979 :custom-category
'group
3980 :custom-set
'custom-group-set
3981 :custom-mark-to-save
'custom-group-mark-to-save
3982 :custom-reset-current
'custom-group-reset-current
3983 :custom-reset-saved
'custom-group-reset-saved
3984 :custom-reset-standard
'custom-group-reset-standard
3985 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3986 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3987 :custom-menu
'custom-group-menu-create
)
3989 (defun custom-group-sample-face-get (widget)
3990 ;; Use :sample-face.
3991 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3994 (define-widget 'custom-group-visibility
'visibility
3995 "An indicator and manipulator for hidden group contents."
3996 :create
'custom-group-visibility-create
)
3998 (defun custom-group-visibility-create (widget)
3999 (let ((visible (widget-value widget
)))
4001 (insert "--------")))
4002 (widget-default-create widget
))
4004 (defun custom-group-members (symbol groups-only
)
4005 "Return SYMBOL's custom group members.
4006 If GROUPS-ONLY non-nil, return only those members that are groups."
4007 (if (not groups-only
)
4008 (get symbol
'custom-group
)
4010 (dolist (entry (get symbol
'custom-group
))
4011 (when (eq (nth 1 entry
) 'custom-group
)
4012 (push entry members
)))
4013 (nreverse members
))))
4015 (defun custom-group-value-create (widget)
4016 "Insert a customize group for WIDGET in the current buffer."
4017 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4018 (custom-load-widget widget
))
4019 (let* ((state (widget-get widget
:custom-state
))
4020 (level (widget-get widget
:custom-level
))
4021 ;; (indent (widget-get widget :indent))
4022 (prefix (widget-get widget
:custom-prefix
))
4023 (buttons (widget-get widget
:buttons
))
4024 (tag (widget-get widget
:tag
))
4025 (symbol (widget-value widget
))
4026 (members (custom-group-members symbol
4027 (and (eq custom-buffer-style
'tree
)
4028 custom-browse-only-groups
)))
4029 (doc (widget-docstring widget
)))
4030 (cond ((and (eq custom-buffer-style
'tree
)
4032 (or members
(custom-unloaded-widget-p widget
)))
4033 (custom-browse-insert-prefix prefix
)
4034 (push (widget-create-child-and-convert
4035 widget
'custom-browse-visibility
4039 (push (widget-create-child-and-convert
4040 widget
'custom-browse-group-tag
)
4042 (insert " " tag
"\n")
4043 (widget-put widget
:buttons buttons
))
4044 ((and (eq custom-buffer-style
'tree
)
4045 (zerop (length members
)))
4046 (custom-browse-insert-prefix prefix
)
4048 (push (widget-create-child-and-convert
4049 widget
'custom-browse-group-tag
)
4051 (insert " " tag
"\n")
4052 (widget-put widget
:buttons buttons
))
4053 ((eq custom-buffer-style
'tree
)
4054 (custom-browse-insert-prefix prefix
)
4055 (if (zerop (length members
))
4057 (custom-browse-insert-prefix prefix
)
4059 ;; (widget-glyph-insert nil "[ ]" "empty")
4060 ;; (widget-glyph-insert nil "-- " "horizontal")
4061 (push (widget-create-child-and-convert
4062 widget
'custom-browse-group-tag
)
4064 (insert " " tag
"\n")
4065 (widget-put widget
:buttons buttons
))
4066 (push (widget-create-child-and-convert
4067 widget
'custom-browse-visibility
4068 ;; :tag-glyph "minus"
4072 ;; (widget-glyph-insert nil "-\\ " "top")
4073 (push (widget-create-child-and-convert
4074 widget
'custom-browse-group-tag
)
4076 (insert " " tag
"\n")
4077 (widget-put widget
:buttons buttons
)
4078 (message "Creating group...")
4079 (let* ((members (custom-sort-items
4081 ;; Never sort the top-level custom group.
4082 (unless (eq symbol
'emacs
)
4083 custom-browse-sort-alphabetically
)
4084 custom-browse-order-groups
))
4085 (prefixes (widget-get widget
:custom-prefixes
))
4086 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4087 (extra-prefix (if (widget-get widget
:custom-last
)
4090 (prefix (concat prefix extra-prefix
))
4093 (setq entry
(car members
)
4094 members
(cdr members
))
4095 (push (widget-create-child-and-convert
4096 widget
(nth 1 entry
)
4098 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4099 :custom-prefixes custom-prefix-list
4100 :custom-level
(1+ level
)
4101 :custom-last
(null members
)
4102 :value
(nth 0 entry
)
4103 :custom-prefix prefix
)
4105 (widget-put widget
:children
(reverse children
)))
4106 (message "Creating group...done")))
4109 ;; Create level indicator.
4111 (if (eq custom-buffer-style
'links
)
4112 (push (widget-create-child-and-convert
4113 widget
'custom-group-link
4117 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4119 (push (widget-create-child-and-convert
4120 widget
'custom-group-visibility
4121 :help-echo
"Show members of this group."
4122 :action
'custom-toggle-parent
4123 (not (eq state
'hidden
)))
4125 (if (>= (current-column) custom-group-doc-align-col
)
4127 ;; Create magic button.
4128 (let ((magic (widget-create-child-and-convert
4129 widget
'custom-magic nil
)))
4130 (widget-put widget
:custom-magic magic
)
4131 (push magic buttons
))
4133 (widget-put widget
:buttons buttons
)
4134 ;; Insert documentation.
4135 (if (and (eq custom-buffer-style
'links
) (> level
1))
4136 (widget-put widget
:documentation-indent
4137 custom-group-doc-align-col
))
4138 (widget-add-documentation-string-button
4139 widget
:visibility-widget
'custom-visibility
))
4143 ;; Draw a horizontal line (this works for both graphical
4144 ;; and text displays):
4147 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4148 (overlay-put (make-overlay p
(1+ p
))
4150 (propertize "\n" 'face
'(:underline t
)
4151 'display
'(space :align-to
999))))
4153 ;; Add parent groups references above the group.
4155 (if (custom-add-parent-links widget
"Parent groups:")
4157 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4159 (let ((start (point)))
4160 (insert tag
" group: ")
4161 (widget-specify-sample widget start
(point)))
4164 (insert " Group definition missing. "))
4165 ((< (length doc
) 50)
4167 ;; Create visibility indicator.
4168 (unless (eq custom-buffer-style
'links
)
4170 (push (widget-create-child-and-convert
4172 :help-echo
"Hide members of this group."
4173 :action
'custom-toggle-parent
4174 (not (eq state
'hidden
)))
4178 ;; Create magic button.
4179 (let ((magic (widget-create-child-and-convert
4180 widget
'custom-magic
4183 (widget-put widget
:custom-magic magic
)
4184 (push magic buttons
))
4186 (widget-put widget
:buttons buttons
)
4187 ;; Insert documentation.
4188 (when (and doc
(>= (length doc
) 50))
4189 (widget-add-documentation-string-button
4190 widget
:visibility-widget
'custom-visibility
))
4193 (if nil
;;; This should test that the buffer
4194 ;;; was not made to display a group.
4196 (insert-char ?\ custom-buffer-indent
)
4197 (custom-add-parent-links widget
)))
4198 (custom-add-see-also widget
4199 (make-string (* custom-buffer-indent level
)
4202 (message "Creating group...")
4203 (let* ((members (custom-sort-items
4205 ;; Never sort the top-level custom group.
4206 (unless (eq symbol
'emacs
)
4207 custom-buffer-sort-alphabetically
)
4208 custom-buffer-order-groups
))
4209 (prefixes (widget-get widget
:custom-prefixes
))
4210 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4211 (len (length members
))
4213 (reporter (make-progress-reporter
4214 "Creating group entries..." 0 len
))
4215 (have-subtitle (and (not (eq symbol
'emacs
))
4216 (eq custom-buffer-order-groups
'last
)))
4220 (dolist (entry members
)
4221 (unless (eq prev-type
'custom-group
)
4222 (widget-insert "\n"))
4223 (progress-reporter-update reporter
(setq count
(1+ count
)))
4224 (let ((sym (nth 0 entry
))
4225 (type (nth 1 entry
)))
4226 (when (and have-subtitle
(eq type
'custom-group
))
4227 (setq have-subtitle nil
)
4229 (propertize "Subgroups:\n" 'face
'custom-group-subtitle
)))
4230 (setq prev-type type
)
4231 (push (widget-create-child-and-convert
4234 :tag
(custom-unlispify-tag-name sym
)
4235 :custom-prefixes custom-prefix-list
4236 :custom-level
(1+ level
)
4239 (unless (eq (preceding-char) ?
\n)
4240 (widget-insert "\n"))))
4242 (setq children
(nreverse children
))
4243 (mapc 'custom-magic-reset children
)
4244 (widget-put widget
:children children
)
4245 (custom-group-state-update widget
)
4246 (progress-reporter-done reporter
))
4248 (let ((p (1+ (point))))
4250 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4251 (overlay-put (make-overlay p
(1+ p
))
4253 (propertize "\n" 'face
'(:underline t
)
4254 'display
'(space :align-to
999))))))))
4256 (defvar custom-group-menu
4257 `(("Set for Current Session" custom-group-set
4259 (eq (widget-get widget
:custom-state
) 'modified
)))
4260 ,@(when (or custom-file init-file-user
)
4261 '(("Save for Future Sessions" custom-group-save
4263 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4264 ("Undo Edits" custom-group-reset-current
4266 (memq (widget-get widget
:custom-state
) '(modified))))
4267 ("Revert This Session's Customizations" custom-group-reset-saved
4269 (memq (widget-get widget
:custom-state
) '(modified set
))))
4270 ,@(when (or custom-file init-file-user
)
4271 '(("Erase Customization" custom-group-reset-standard
4273 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4274 "Alist of actions for the `custom-group' widget.
4275 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4276 the menu entry, ACTION is the function to call on the widget when the
4277 menu is selected, and FILTER is a predicate which takes a `custom-group'
4278 widget as an argument, and returns non-nil if ACTION is valid on that
4279 widget. If FILTER is nil, ACTION is always valid.")
4281 (defun custom-group-action (widget &optional event
)
4282 "Show the menu for `custom-group' WIDGET.
4283 Optional EVENT is the location for the menu."
4284 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4285 (custom-toggle-hide widget
)
4286 (let* ((completion-ignore-case t
)
4287 (answer (widget-choose (concat "Operation on "
4288 (custom-unlispify-tag-name
4289 (widget-get widget
:value
)))
4290 (custom-menu-filter custom-group-menu
4294 (funcall answer widget
)))))
4296 (defun custom-group-set (widget)
4297 "Set changes in all modified group members."
4298 (dolist (child (widget-get widget
:children
))
4299 (when (eq (widget-get child
:custom-state
) 'modified
)
4300 (widget-apply child
:custom-set
))))
4302 (defun custom-group-mark-to-save (widget)
4303 "Mark all modified group members for saving."
4304 (dolist (child (widget-get widget
:children
))
4305 (when (memq (widget-get child
:custom-state
) '(modified set
))
4306 (widget-apply child
:custom-mark-to-save
))))
4308 (defsubst custom-group-state-set-and-redraw
(widget)
4309 "Set state of group widget WIDGET and redraw with current settings."
4310 (dolist (child (widget-get widget
:children
))
4311 (when (memq (widget-get child
:custom-state
) '(modified set
))
4312 (widget-apply child
:custom-state-set-and-redraw
))))
4314 (defun custom-group-save (widget)
4315 "Save all modified group members."
4316 (custom-group-mark-to-save widget
)
4318 (custom-group-state-set-and-redraw widget
))
4320 (defun custom-group-reset-current (widget)
4321 "Reset all modified group members."
4322 (dolist (child (widget-get widget
:children
))
4323 (when (eq (widget-get child
:custom-state
) 'modified
)
4324 (widget-apply child
:custom-reset-current
))))
4326 (defun custom-group-reset-saved (widget)
4327 "Reset all modified or set group members."
4328 (dolist (child (widget-get widget
:children
))
4329 (when (memq (widget-get child
:custom-state
) '(modified set
))
4330 (widget-apply child
:custom-reset-saved
))))
4332 (defun custom-group-reset-standard (widget)
4333 "Reset all modified, set, or saved group members."
4334 (let ((custom-reset-standard-variables-list '(t))
4335 (custom-reset-standard-faces-list '(t)))
4336 (custom-group-mark-to-reset-standard widget
)
4337 (custom-reset-standard-save-and-update)))
4339 (defun custom-group-mark-to-reset-standard (widget)
4340 "Mark to reset all modified, set, or saved group members."
4341 (dolist (child (widget-get widget
:children
))
4342 (when (memq (widget-get child
:custom-state
)
4343 '(modified set saved
))
4344 (widget-apply child
:custom-mark-to-reset-standard
))))
4346 (defun custom-group-state-update (widget)
4348 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4349 (let* ((children (widget-get widget
:children
))
4350 (states (mapcar (lambda (child)
4351 (widget-get child
:custom-state
))
4353 (magics custom-magic-alist
)
4356 (let ((magic (car (car magics
))))
4357 (if (and (not (eq magic
'hidden
))
4358 (memq magic states
))
4361 (setq magics
(cdr magics
)))))
4362 (widget-put widget
:custom-state found
)))
4363 (custom-magic-reset widget
))
4365 ;;; Reading and writing the custom file.
4368 (defcustom custom-file nil
4369 "File used for storing customization information.
4370 The default is nil, which means to use your init file
4371 as specified by `user-init-file'. If the value is not nil,
4372 it should be an absolute file name.
4374 You can set this option through Custom, if you carefully read the
4375 last paragraph below. However, usually it is simpler to write
4376 something like the following in your init file:
4378 \(setq custom-file \"~/.emacs-custom.el\")
4381 Note that both lines are necessary: the first line tells Custom to
4382 save all customizations in this file, but does not load it.
4384 When you change this variable outside Custom, look in the
4385 previous custom file \(usually your init file) for the
4386 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4387 and copy them (whichever ones you find) to the new custom file.
4388 This will preserve your existing customizations.
4390 If you save this option using Custom, Custom will write all
4391 currently saved customizations, including the new one for this
4392 option itself, into the file you specify, overwriting any
4393 `custom-set-variables' and `custom-set-faces' forms already
4394 present in that file. It will not delete any customizations from
4395 the old custom file. You should do that manually if that is what you
4396 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4397 in your init file, where CUSTOM-FILE is the actual name of the
4398 file. Otherwise, Emacs will not load the file when it starts up,
4399 and hence will not set `custom-file' to that file either."
4400 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4401 (file :format
"%t:%v%d"
4403 "Please read entire docstring below before setting \
4404 this through Custom.
4405 Click on \"More\" \(or position point there and press RETURN)
4406 if only the first line of the docstring is shown."))
4409 (defun custom-file (&optional no-error
)
4410 "Return the file name for saving customizations."
4411 (if (null user-init-file
)
4412 ;; Started with -q, i.e. the file containing Custom settings
4413 ;; hasn't been read. Saving settings there won't make much
4417 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4418 (file-chase-links (or custom-file user-init-file
))))
4420 ;; If recentf-mode is non-nil, this is defined.
4421 (declare-function recentf-expand-file-name
"recentf" (name))
4424 (defun custom-save-all ()
4425 "Save all customizations in `custom-file'."
4426 (when (and (null custom-file
) init-file-had-error
)
4427 (error "Cannot save customizations; init file was not fully loaded"))
4428 (let* ((filename (custom-file))
4433 (recentf-expand-file-name (custom-file)))
4436 (old-buffer (find-buffer-visiting filename
))
4439 (with-current-buffer (let ((find-file-visit-truename t
))
4440 (or old-buffer
(find-file-noselect filename
)))
4441 ;; We'll save using file-precious-flag, so avoid destroying
4442 ;; symlinks. (If we're not already visiting the buffer, this is
4443 ;; handled by find-file-visit-truename, above.)
4445 (setq old-buffer-name
(buffer-file-name))
4446 (set-visited-file-name (file-chase-links filename
)))
4448 (unless (eq major-mode
'emacs-lisp-mode
)
4450 (let ((inhibit-read-only t
)
4453 (custom-save-variables)
4454 (custom-save-faces))
4455 (let ((file-precious-flag t
))
4459 (set-visited-file-name old-buffer-name
)
4460 (set-buffer-modified-p nil
))
4461 (kill-buffer (current-buffer))))))
4464 (defun customize-save-customized ()
4465 "Save all user options which have been set in this session."
4467 (mapatoms (lambda (symbol)
4468 (let ((face (get symbol
'customized-face
))
4469 (value (get symbol
'customized-value
))
4470 (face-comment (get symbol
'customized-face-comment
))
4472 (get symbol
'customized-variable-comment
)))
4474 (put symbol
'saved-face face
)
4475 (custom-push-theme 'theme-face symbol
'user
'set value
)
4476 (put symbol
'customized-face nil
))
4478 (put symbol
'saved-value value
)
4479 (custom-push-theme 'theme-value symbol
'user
'set value
)
4480 (put symbol
'customized-value nil
))
4481 (when variable-comment
4482 (put symbol
'saved-variable-comment variable-comment
)
4483 (put symbol
'customized-variable-comment nil
))
4485 (put symbol
'saved-face-comment face-comment
)
4486 (put symbol
'customized-face-comment nil
)))))
4487 ;; We really should update all custom buffers here.
4490 ;; Editing the custom file contents in a buffer.
4492 (defun custom-save-delete (symbol)
4493 "Delete all calls to SYMBOL from the contents of the current buffer.
4494 Leave point at the old location of the first such call,
4495 or (if there were none) at the end of the buffer.
4497 This function does not save the buffer."
4498 (goto-char (point-min))
4499 ;; Skip all whitespace and comments.
4500 (while (forward-comment 1))
4502 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4505 (while t
;; We exit this loop only via throw.
4506 ;; Skip all whitespace and comments.
4507 (while (forward-comment 1))
4508 (let ((start (point))
4509 (sexp (condition-case nil
4510 (read (current-buffer))
4511 (end-of-file (throw 'found nil
)))))
4512 (when (and (listp sexp
)
4513 (eq (car sexp
) symbol
))
4514 (delete-region start
(point))
4516 (setq first
(point)))))))
4519 ;; Move in front of local variables, otherwise long Custom
4520 ;; entries would make them ineffective.
4521 (let ((pos (point-max))
4522 (case-fold-search t
))
4524 (goto-char (point-max))
4525 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4527 (when (search-forward "Local Variables:" nil t
)
4528 (setq pos
(line-beginning-position))))
4531 (defvar sort-fold-case
) ; defined in sort.el
4533 (defun custom-save-variables ()
4534 "Save all customized variables in `custom-file'."
4536 (custom-save-delete 'custom-set-variables
)
4537 (let ((standard-output (current-buffer))
4538 (saved-list (make-list 1 0))
4540 ;; First create a sorted list of saved variables.
4543 (if (and (get symbol
'saved-value
)
4544 ;; ignore theme values
4545 (or (null (get symbol
'theme-value
))
4546 (eq 'user
(caar (get symbol
'theme-value
)))))
4547 (nconc saved-list
(list symbol
)))))
4548 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4551 (princ "(custom-set-variables
4552 ;; custom-set-variables was added by Custom.
4553 ;; If you edit it by hand, you could mess it up, so be careful.
4554 ;; Your init file should contain only one such instance.
4555 ;; If there is more than one, they won't work right.\n")
4556 (dolist (symbol saved-list
)
4557 (let ((spec (car-safe (get symbol
'theme-value
)))
4558 (value (get symbol
'saved-value
))
4559 (requests (get symbol
'custom-requests
))
4560 (now (and (not (custom-variable-p symbol
))
4562 (eq (get symbol
'force-value
)
4564 (comment (get symbol
'saved-variable-comment
)))
4565 ;; Check REQUESTS for validity.
4566 (dolist (request requests
)
4567 (when (and (symbolp request
) (not (featurep request
)))
4568 (message "Unknown requested feature: %s" request
)
4569 (setq requests
(delq request requests
))))
4570 ;; Is there anything customized about this variable?
4571 (when (or (and spec
(eq (car spec
) 'user
))
4573 (and (null spec
) (get symbol
'saved-value
)))
4574 ;; Output an element for this variable.
4575 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4576 ;; SYMBOL is the variable name.
4577 ;; VALUE-FORM is an expression to return the customized value.
4578 ;; NOW if non-nil means always set the variable immediately
4579 ;; when the customizations are reloaded. This is used
4580 ;; for rogue variables
4581 ;; REQUESTS is a list of packages to load before setting the
4582 ;; variable. Each element of it will be passed to `require'.
4583 ;; COMMENT is whatever comment the user has specified
4584 ;; with the customize facility.
4591 (when (or now requests comment
)
4594 (when (or requests comment
)
4604 (unless (looking-at "\n")
4607 (defun custom-save-faces ()
4608 "Save all customized faces in `custom-file'."
4610 (custom-save-delete 'custom-reset-faces
)
4611 (custom-save-delete 'custom-set-faces
)
4612 (let ((standard-output (current-buffer))
4613 (saved-list (make-list 1 0))
4615 ;; First create a sorted list of saved faces.
4618 (if (and (get symbol
'saved-face
)
4619 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4620 (nconc saved-list
(list symbol
)))))
4621 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4622 ;; The default face must be first, since it affects the others.
4623 (if (memq 'default saved-list
)
4624 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4627 (princ "(custom-set-faces
4628 ;; custom-set-faces was added by Custom.
4629 ;; If you edit it by hand, you could mess it up, so be careful.
4630 ;; Your init file should contain only one such instance.
4631 ;; If there is more than one, they won't work right.\n")
4632 (dolist (symbol saved-list
)
4633 (let ((spec (car-safe (get symbol
'theme-face
)))
4634 (value (get symbol
'saved-face
))
4635 (now (not (or (get symbol
'face-defface-spec
)
4636 (and (not (custom-facep symbol
))
4637 (not (get symbol
'force-face
))))))
4638 (comment (get symbol
'saved-face-comment
)))
4639 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4641 (and (null spec
) (get symbol
'saved-face
)))
4642 ;; Don't print default face here.
4649 (when (or now comment
)
4659 (unless (looking-at "\n")
4662 ;;; The Customize Menu.
4666 (defcustom custom-menu-nesting
2
4667 "Maximum nesting in custom menus."
4669 :group
'custom-menu
)
4671 (defun custom-face-menu-create (_widget symbol
)
4672 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4673 (vector (custom-unlispify-menu-entry symbol
)
4674 `(customize-face ',symbol
)
4677 (defun custom-variable-menu-create (_widget symbol
)
4678 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4679 (let ((type (get symbol
'custom-type
)))
4680 (unless (listp type
)
4681 (setq type
(list type
)))
4682 (if (and type
(widget-get type
:custom-menu
))
4683 (widget-apply type
:custom-menu symbol
)
4684 (vector (custom-unlispify-menu-entry symbol
)
4685 `(customize-variable ',symbol
)
4688 ;; Add checkboxes to boolean variable entries.
4689 (widget-put (get 'boolean
'widget-type
)
4690 :custom-menu
(lambda (_widget symbol
)
4691 (vector (custom-unlispify-menu-entry symbol
)
4692 `(customize-variable ',symbol
)
4694 ':selected symbol
)))
4696 (defun custom-group-menu-create (_widget symbol
)
4697 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4698 `( ,(custom-unlispify-menu-entry symbol t
)
4699 :filter
(lambda (&rest junk
)
4700 (let* ((menu (custom-menu-create ',symbol
)))
4701 (if (consp menu
) (cdr menu
) menu
)))))
4704 (defun custom-menu-create (symbol)
4705 "Create menu for customization group SYMBOL.
4706 The menu is in a format applicable to `easy-menu-define'."
4707 (let* ((deactivate-mark nil
)
4708 (item (vector (custom-unlispify-menu-entry symbol
)
4709 `(customize-group ',symbol
)
4711 (if (and (or (not (boundp 'custom-menu-nesting
))
4712 (>= custom-menu-nesting
0))
4714 (custom-load-symbol symbol
)
4715 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4716 (let ((custom-prefix-list (custom-prefix-add symbol
4717 custom-prefix-list
))
4718 (members (custom-sort-items (get symbol
'custom-group
)
4719 custom-menu-sort-alphabetically
4720 custom-menu-order-groups
)))
4721 `(,(custom-unlispify-menu-entry symbol t
)
4724 ,@(mapcar (lambda (entry)
4725 (widget-apply (if (listp (nth 1 entry
))
4727 (list (nth 1 entry
)))
4728 :custom-menu
(nth 0 entry
)))
4733 (defun customize-menu-create (symbol &optional name
)
4734 "Return a customize menu for customization group SYMBOL.
4735 If optional NAME is given, use that as the name of the menu.
4736 Otherwise the menu will be named `Customize'.
4737 The format is suitable for use with `easy-menu-define'."
4739 (setq name
"Customize"))
4741 :filter
(lambda (&rest junk
)
4742 (let ((menu (custom-menu-create ',symbol
)))
4743 (if (consp menu
) (cdr menu
) menu
)))))
4745 ;;; Toolbar and menubar support
4748 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4749 "Menu used in customization buffers."
4750 (nconc (list "Custom"
4751 (customize-menu-create 'customize
))
4752 (mapcar (lambda (arg)
4753 (let ((tag (nth 0 arg
))
4754 (command (nth 1 arg
))
4755 (active (nth 2 arg
))
4757 (vector tag command
:active
(eval active
) :help help
)))
4760 (defvar tool-bar-map
)
4762 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4763 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4764 ;;; we set this up lazily in `Custom-mode'.
4765 (defvar custom-tool-bar-map nil
4766 "Keymap for toolbar in Custom mode.")
4768 ;;; The Custom Mode.
4770 (defun Custom-no-edit (_pos &optional _event
)
4771 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4773 (error "You can't edit this part of the Custom buffer"))
4775 (defun Custom-newline (pos &optional event
)
4776 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4778 (let ((button (get-char-property pos
'button
)))
4779 ;; If there is no button at point, then use the one at the start
4780 ;; of the line, if it is a custom-group-link (bug#2298).
4782 (if (setq button
(get-char-property (line-beginning-position) 'button
))
4783 (or (eq (widget-type button
) 'custom-group-link
)
4784 (setq button nil
))))
4786 (widget-apply-action button event
)
4787 (error "You can't edit this part of the Custom buffer"))))
4789 (defun Custom-goto-parent ()
4790 "Go to the parent group listed at the top of this buffer.
4791 If several parents are listed, go to the first of them."
4794 (goto-char (point-min))
4795 (if (search-forward "\nParent groups: " nil t
)
4796 (let* ((button (get-char-property (point) 'button
))
4797 (parent (downcase (widget-get button
:tag
))))
4798 (customize-group parent
)))))
4800 (defcustom Custom-mode-hook nil
4801 "Hook called when entering Custom mode."
4803 :group
'custom-buffer
)
4805 (defun custom-state-buffer-message (widget)
4806 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4807 (message "To install your edits, invoke [State] and choose the Set operation")))
4809 (defun custom--initialize-widget-variables ()
4810 (set (make-local-variable 'widget-documentation-face
) 'custom-documentation
)
4811 (set (make-local-variable 'widget-button-face
) custom-button
)
4812 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4813 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4814 ;; We need this because of the "More" button on docstrings.
4815 ;; Otherwise clicking on "More" can push point offscreen, which
4816 ;; causes the window to recenter on point, which pushes the
4817 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4818 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4819 ;; When possible, use relief for buttons, not bracketing. This test
4820 ;; may not be optimal.
4821 (when custom-raised-buttons
4822 (set (make-local-variable 'widget-push-button-prefix
) "")
4823 (set (make-local-variable 'widget-push-button-suffix
) "")
4824 (set (make-local-variable 'widget-link-prefix
) "")
4825 (set (make-local-variable 'widget-link-suffix
) ""))
4826 (setq show-trailing-whitespace nil
))
4828 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4829 (define-derived-mode Custom-mode nil
"Custom"
4830 "Major mode for editing customization buffers.
4832 The following commands are available:
4835 Move to next button, link or editable field. \\[widget-forward]
4836 Move to previous button, link or editable field. \\[widget-backward]
4837 \\<custom-field-keymap>\
4838 Complete content of editable text field. \\[widget-complete]
4839 \\<custom-mode-map>\
4840 Invoke button under the mouse pointer. \\[widget-button-click]
4841 Invoke button under point. \\[widget-button-press]
4842 Set all options from current text. \\[Custom-set]
4843 Make values in current text permanent. \\[Custom-save]
4844 Make text match actual option values. \\[Custom-reset-current]
4845 Reset options to permanent settings. \\[Custom-reset-saved]
4846 Erase customizations; set options
4847 and buffer text to the standard values. \\[Custom-reset-standard]
4849 Entry to this mode calls the value of `Custom-mode-hook'
4850 if that value is non-nil."
4851 (use-local-map custom-mode-map
)
4852 (easy-menu-add Custom-mode-menu
)
4853 (set (make-local-variable 'tool-bar-map
)
4854 (or custom-tool-bar-map
4855 ;; Set up `custom-tool-bar-map'.
4856 (let ((map (make-sparse-keymap)))
4859 (tool-bar-local-item-from-menu
4860 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4861 :label
(nth 5 arg
)))
4863 (setq custom-tool-bar-map map
))))
4864 (make-local-variable 'custom-options
)
4865 (make-local-variable 'custom-local-buffer
)
4866 (custom--initialize-widget-variables)
4867 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4869 (put 'Custom-mode
'mode-class
'special
)
4871 ;; backward-compatibility
4872 (defun custom-mode ()
4873 "Non-interactive variant of `Custom-mode'."
4875 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4876 (put 'custom-mode
'mode-class
'special
)
4878 (add-to-list 'debug-ignored-errors
"^Invalid face:? ")
4884 ;;; cus-edit.el ends here