1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages -*- lexical-binding:t -*-
3 ;; Copyright (C) 1996-1997, 1999-2016 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: emacs-devel@gnu.org
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")
200 (defgroup outlines nil
201 "Support for hierarchical outlining."
204 (defgroup external nil
205 "Interfacing to external utilities."
209 "Communications, networking, and remote access to files."
213 (defgroup processes nil
214 "Process, subshell, compilation, and job control support."
217 (defgroup programming nil
218 "Support for programming in other languages."
221 (defgroup languages nil
222 "Modes for editing programming languages."
226 "Lisp support, including Emacs Lisp."
227 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
232 "Support for the C language and related languages."
233 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
234 :link
'(custom-manual "(ccmode)")
241 (defgroup applications nil
242 "Applications written in Emacs."
245 (defgroup calendar nil
246 "Calendar and time management support."
247 :group
'applications
)
250 "Modes for electronic-mail handling."
251 :group
'applications
)
254 "Reading and posting to newsgroups."
255 :link
'(custom-manual "(gnus)")
256 :group
'applications
)
259 "Games, jokes and amusements."
260 :group
'applications
)
262 (defgroup development nil
263 "Support for further development of Emacs."
267 "Support for Emacs documentation."
270 (defgroup extensions nil
271 "Emacs Lisp language extensions."
274 (defgroup internal nil
275 "Code for Emacs internals, build process, defaults."
279 "Maintenance aids for the Emacs development group."
283 (defgroup environment nil
284 "Fitting Emacs with its environment."
287 (defgroup hardware nil
288 "Support for interfacing with miscellaneous hardware."
291 (defgroup terminals nil
292 "Support for terminal types."
296 "Interfaces, assistants, and emulators for UNIX features."
300 "Internationalization and alternate character-set support."
301 :link
'(custom-manual "(emacs)International")
306 "The X Window system."
310 "Support for Emacs frames and window systems."
314 "Code related to the TeX formatter."
315 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
319 "Support for multiple fonts."
323 "Support for Emacs help systems."
326 (defgroup multimedia nil
327 "Non-textual support, specifically images and sound."
331 "Code local to your site."
334 (defgroup customize
'((widgets custom-group
))
335 "Customization of the Customization support."
339 (defgroup custom-faces nil
340 "Faces used by customize."
344 (defgroup custom-browse nil
345 "Control customize browser."
349 (defgroup custom-buffer nil
350 "Control customize buffers."
354 (defgroup custom-menu nil
355 "Control customize menus."
360 "Storage allocation and gc for GNU Emacs Lisp interpreter."
361 :tag
"Storage Allocation"
365 "Undoing changes in buffers."
366 :link
'(custom-manual "(emacs)Undo")
369 (defgroup mode-line nil
370 "Contents of the mode line."
373 (defgroup editing-basics nil
374 "Most basic editing facilities."
377 (defgroup display nil
378 "How characters are displayed in buffers."
381 (defgroup execute nil
382 "Executing external commands."
385 (defgroup installation nil
386 "The Emacs installation."
394 "Internal Emacs limits."
398 "Debugging Emacs itself."
401 (defgroup keyboard nil
402 "Input from the keyboard."
406 "Input from the menus."
410 "Handling data from drag and drop."
413 (defgroup auto-save nil
414 "Preventing accidental loss of data."
417 (defgroup processes-basics nil
418 "Basic stuff dealing with processes."
422 "MULE Emacs internationalization."
425 (defgroup windows nil
426 "Windows within a frame."
427 :link
'(custom-manual "(emacs)Windows")
430 ;;; Custom mode keymaps
432 (defvar custom-mode-map
433 (let ((map (make-keymap)))
434 (set-keymap-parent map widget-keymap
)
435 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
436 (define-key map
"\^m" 'Custom-newline
)
437 (define-key map
" " 'scroll-up-command
)
438 (define-key map
[?\S-\
] 'scroll-down-command
)
439 (define-key map
"\177" 'scroll-down-command
)
440 (define-key map
"\C-c\C-c" 'Custom-set
)
441 (define-key map
"\C-x\C-s" 'Custom-save
)
442 (define-key map
"q" 'Custom-buffer-done
)
443 (define-key map
"u" 'Custom-goto-parent
)
444 (define-key map
"n" 'widget-forward
)
445 (define-key map
"p" 'widget-backward
)
447 "Keymap for `Custom-mode'.")
449 (defvar custom-mode-link-map
450 (let ((map (make-keymap)))
451 (set-keymap-parent map custom-mode-map
)
452 (define-key map
[down-mouse-2
] nil
)
453 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
454 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
456 "Local keymap for links in `Custom-mode'.")
458 (defvar custom-field-keymap
459 (let ((map (copy-keymap widget-field-keymap
)))
460 (define-key map
"\C-c\C-c" 'Custom-set
)
461 (define-key map
"\C-x\C-s" 'Custom-save
)
463 "Keymap used inside editable fields in customization buffers.")
465 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
469 (defun custom-split-regexp-maybe (regexp)
470 "If REGEXP is a string, split it to a list at `\\|'.
471 You can get the original back from the result with:
472 (mapconcat \\='identity result \"\\|\")
474 IF REGEXP is not a string, return it unchanged."
476 (split-string regexp
"\\\\|")
479 (defun custom-variable-prompt ()
480 "Prompt for a custom variable, defaulting to the variable at point.
481 Return a list suitable for use in `interactive'."
482 (let* ((v (variable-at-point))
483 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
484 (enable-recursive-minibuffers t
)
486 (setq val
(completing-read
487 (if default
(format "Customize variable (default %s): " default
)
488 "Customize variable: ")
489 obarray
'custom-variable-p t nil nil default
))
490 (list (if (equal val
"")
491 (if (symbolp v
) v nil
)
494 (defun custom-menu-filter (menu widget
)
495 "Convert MENU to the form used by `widget-choose'.
496 MENU should be in the same format as `custom-variable-menu'.
497 WIDGET is the widget to apply the filter entries of MENU on."
499 current name action filter
)
501 (setq current
(car menu
)
503 action
(nth 1 current
)
504 filter
(nth 2 current
)
506 (if (or (null filter
) (funcall filter widget
))
507 (push (cons name action
) result
)
513 (defvar custom-prefix-list nil
514 "List of prefixes that should be ignored by `custom-unlispify'.")
516 (defcustom custom-unlispify-menu-entries t
517 "Display menu entries as words instead of symbols if non-nil."
521 (defcustom custom-unlispify-remove-prefixes nil
522 "Non-nil means remove group prefixes from option names in buffer.
523 Discarding prefixes often leads to confusing names for options
524 and faces in Customize buffers, so do not set this to a non-nil
525 value unless you are sure you know what it does."
527 :group
'custom-buffer
530 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
531 "Convert SYMBOL into a menu entry."
532 (cond ((not custom-unlispify-menu-entries
)
533 (symbol-name symbol
))
534 ((get symbol
'custom-tag
)
536 (get symbol
'custom-tag
)
537 (concat (get symbol
'custom-tag
) "...")))
539 (with-current-buffer (get-buffer-create " *Custom-Work*")
541 (princ symbol
(current-buffer))
542 (goto-char (point-min))
543 (if custom-unlispify-remove-prefixes
544 (let ((prefixes custom-prefix-list
)
547 (setq prefix
(car prefixes
))
548 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
551 (delete-region (point-min) (point)))
552 (setq prefixes
(cdr prefixes
))))))
553 (subst-char-in-region (point-min) (point-max) ?- ?\s t
)
554 (capitalize-region (point-min) (point-max))
556 (goto-char (point-max))
560 (defcustom custom-unlispify-tag-names t
561 "Display tag names as words instead of symbols if non-nil."
562 :group
'custom-buffer
565 (defun custom-unlispify-tag-name (symbol)
566 "Convert SYMBOL into a menu entry."
567 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
568 (custom-unlispify-menu-entry symbol t
)))
570 (defun custom-prefix-add (symbol prefixes
)
571 "Add SYMBOL to list of ignored PREFIXES."
572 (cons (or (get symbol
'custom-prefix
)
573 (concat (symbol-name symbol
) "-"))
578 (defcustom custom-guess-name-alist
584 ("-function\\'" function
)
585 ("-functions\\'" (repeat function
))
586 ("-list\\'" (repeat sexp
))
587 ("-alist\\'" (alist :key-type sexp
:value-type sexp
)))
588 "Alist of (MATCH TYPE).
590 MATCH should be a regexp matching the name of a symbol, and TYPE should
591 be a widget suitable for editing the value of that symbol. The TYPE
592 of the first entry where MATCH matches the name of the symbol will be
595 This is used for guessing the type of variables not declared with
597 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
598 :group
'custom-buffer
)
600 (defcustom custom-guess-doc-alist
601 '(("\\`\\*?Non-nil " boolean
))
602 "Alist of (MATCH TYPE).
604 MATCH should be a regexp matching a documentation string, and TYPE
605 should be a widget suitable for editing the value of a variable with
606 that documentation string. The TYPE of the first entry where MATCH
607 matches the name of the symbol will be used.
609 This is used for guessing the type of variables not declared with
611 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
612 :group
'custom-buffer
)
614 (defun custom-guess-type (symbol)
615 "Guess a widget suitable for editing the value of SYMBOL.
616 This is done by matching SYMBOL with `custom-guess-name-alist' and
617 if that fails, the doc string with `custom-guess-doc-alist'."
618 (let ((name (symbol-name symbol
))
619 (names custom-guess-name-alist
)
622 (setq current
(car names
)
624 (when (string-match-p (nth 0 current
) name
)
625 (setq found
(nth 1 current
)
628 (let ((doc (documentation-property symbol
'variable-documentation t
))
629 (docs custom-guess-doc-alist
))
632 (setq current
(car docs
)
634 (when (string-match-p (nth 0 current
) doc
)
635 (setq found
(nth 1 current
)
642 (defcustom custom-browse-sort-alphabetically nil
643 "If non-nil, sort customization group alphabetically in `custom-browse'."
645 :group
'custom-browse
)
647 (defcustom custom-browse-order-groups nil
648 "If non-nil, order group members within each customization group.
649 If `first', order groups before non-groups.
650 If `last', order groups after non-groups."
651 :type
'(choice (const first
)
653 (const :tag
"none" nil
))
654 :group
'custom-browse
)
656 (defcustom custom-browse-only-groups nil
657 "If non-nil, show group members only within each customization group."
659 :group
'custom-browse
)
662 (defcustom custom-buffer-sort-alphabetically t
663 "Whether to sort customization groups alphabetically in Custom buffer."
665 :group
'custom-buffer
668 (defcustom custom-buffer-order-groups
'last
669 "If non-nil, order group members within each customization group.
670 If `first', order groups before non-groups.
671 If `last', order groups after non-groups."
672 :type
'(choice (const first
)
674 (const :tag
"none" nil
))
675 :group
'custom-buffer
)
678 (defcustom custom-menu-sort-alphabetically nil
679 "If non-nil, sort each customization group alphabetically in menus."
683 (defcustom custom-menu-order-groups
'first
684 "If non-nil, order group members within each customization group.
685 If `first', order groups before non-groups.
686 If `last', order groups after non-groups."
687 :type
'(choice (const first
)
689 (const :tag
"none" nil
))
692 (defun custom-sort-items (items sort-alphabetically order-groups
)
693 "Return a sorted copy of ITEMS.
694 ITEMS should be a list of `custom-group' properties.
695 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
696 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
697 groups after non-groups, if nil do not order groups at all."
698 (sort (copy-sequence items
)
700 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
701 (namea (nth 0 a
)) (nameb (nth 0 b
)))
702 (cond ((not order-groups
)
703 ;; Since we don't care about A and B order, maybe sort.
704 (when sort-alphabetically
705 (string-lessp namea nameb
)))
706 ((eq typea
'custom-group
)
707 ;; If B is also a group, maybe sort. Otherwise, order A and B.
708 (if (eq typeb
'custom-group
)
709 (when sort-alphabetically
710 (string-lessp namea nameb
))
711 (eq order-groups
'first
)))
712 ((eq typeb
'custom-group
)
713 ;; Since A cannot be a group, order A and B.
714 (eq order-groups
'last
))
716 ;; Since A and B cannot be groups, sort.
717 (string-lessp namea nameb
)))))))
719 ;;; Custom Mode Commands.
721 ;; This variable is used by `custom-tool-bar-map', or directly by
722 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
724 (defvar custom-commands
725 '((" Apply " Custom-set t
726 "Apply settings (for the current session only)."
729 (" Apply and Save " Custom-save
730 (or custom-file user-init-file
)
731 "Apply settings and save for future sessions."
734 (" Undo Edits " Custom-reset-current t
735 "Restore customization buffer to reflect existing settings."
738 (" Reset Customizations " Custom-reset-saved t
739 "Undo any settings applied only for the current session."
742 (" Erase Customizations " Custom-reset-standard
743 (or custom-file user-init-file
)
744 "Un-customize settings in this and future sessions."
747 (" Help for Customize " Custom-help t
748 "Get help for using Customize."
751 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
753 (defun Custom-help ()
754 "Read the node on Easy Customization in the Emacs manual."
756 (info "(emacs)Easy Customization"))
758 (defvar custom-reset-menu
759 '(("Undo Edits in Customization Buffer" . Custom-reset-current
)
760 ("Revert This Session's Customizations" . Custom-reset-saved
)
761 ("Erase Customizations" . Custom-reset-standard
))
762 "Alist of actions for the `Reset' button.
763 The key is a string containing the name of the action, the value is a
764 Lisp function taking the widget as an element which will be called
765 when the action is chosen.")
767 (defvar custom-options nil
768 "Customization widgets in the current buffer.")
770 (defun custom-command-apply (fun query
&optional strong-query
)
771 "Call function FUN on all widgets in `custom-options'.
772 If there is more than one widget, ask user for confirmation using
773 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
774 and `yes-or-no-p' otherwise. Return non-nil if the functionality
775 has been executed, nil otherwise."
776 (if (or (and (= 1 (length custom-options
))
777 (memq (widget-type (car custom-options
))
778 '(custom-variable custom-face
)))
779 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
780 (progn (mapc fun custom-options
) t
)
784 (defun Custom-set (&rest _ignore
)
785 "Set the current value of all edited settings in the buffer."
787 (custom-command-apply
789 (when (eq (widget-get child
:custom-state
) 'modified
)
790 (widget-apply child
:custom-set
)))
791 "Set all values according to this buffer? "))
793 (defun Custom-save (&rest _ignore
)
794 "Set all edited settings, then save all settings that have been set.
795 If a setting was edited and set before, this saves it. If a
796 setting was merely edited before, this sets it then saves it."
798 (when (custom-command-apply
800 (when (memq (widget-get child
:custom-state
)
801 '(modified set changed rogue
))
802 (widget-apply child
:custom-mark-to-save
)))
803 "Save all settings in this buffer? " t
)
804 ;; Save changes to buffer and redraw.
806 (dolist (child custom-options
)
807 (widget-apply child
:custom-state-set-and-redraw
))))
809 (defun custom-reset (_widget &optional event
)
810 "Select item from reset menu."
811 (let* ((completion-ignore-case t
)
812 (answer (widget-choose "Reset settings"
818 (defun Custom-reset-current (&rest _ignore
)
819 "Reset all edited settings in the buffer to show their current values."
821 (custom-command-apply
823 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
824 (widget-apply widget
:custom-reset-current
)))
825 "Reset all settings' buffer text to show current values? "))
827 (defun Custom-reset-saved (&rest _ignore
)
828 "Reset all edited or set settings in the buffer to their saved value.
829 This also shows the saved values in the buffer."
831 (custom-command-apply
833 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
834 (widget-apply widget
:custom-reset-saved
)))
835 "Reset all settings (current values and buffer text) to saved values? "))
837 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
838 ;; and `custom-group-reset-standard'. If these variables are nil, both
839 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
840 ;; save, reset and redraw the handled widget immediately. Otherwise,
841 ;; they add the widget to the corresponding list and leave it to
842 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
843 (defvar custom-reset-standard-variables-list nil
)
844 (defvar custom-reset-standard-faces-list nil
)
846 ;; The next function was excerpted from `custom-variable-reset-standard'
847 ;; and `custom-face-reset-standard' and is used to avoid calling
848 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
849 ;; one) when erasing all customizations.
850 (defun custom-reset-standard-save-and-update ()
851 "Save settings and redraw after erasing customizations."
852 (when (or (and custom-reset-standard-variables-list
853 (not (eq custom-reset-standard-variables-list
'(t))))
854 (and custom-reset-standard-faces-list
855 (not (eq custom-reset-standard-faces-list
'(t)))))
856 ;; Save settings to file.
858 ;; Set state of and redraw variables.
859 (dolist (widget custom-reset-standard-variables-list
)
860 (unless (eq widget t
)
861 (widget-put widget
:custom-state
'unknown
)
862 (custom-redraw widget
)))
863 ;; Set state of and redraw faces.
864 (dolist (widget custom-reset-standard-faces-list
)
865 (unless (eq widget t
)
866 (let* ((symbol (widget-value widget
))
867 (child (car (widget-get widget
:children
)))
868 (comment-widget (widget-get widget
:comment-widget
)))
869 (put symbol
'face-comment nil
)
870 (widget-value-set child
871 (custom-pre-filter-face-spec
872 (list (list t
(custom-face-attributes-get
874 ;; This call manages the comment visibility
875 (widget-value-set comment-widget
"")
876 (custom-face-state-set widget
)
877 (custom-redraw-magic widget
))))))
879 (defun Custom-reset-standard (&rest _ignore
)
880 "Erase all customizations (either current or saved) in current buffer.
881 The immediate result is to restore them to their standard values.
882 This operation eliminates any saved values for the group members,
883 making them as if they had never been customized at all."
885 ;; Bind these temporarily.
886 (let ((custom-reset-standard-variables-list '(t))
887 (custom-reset-standard-faces-list '(t)))
888 (if (custom-command-apply
890 (and (or (null (widget-get widget
:custom-standard-value
))
891 (widget-apply widget
:custom-standard-value
))
892 (memq (widget-get widget
:custom-state
)
893 '(modified set changed saved rogue
))
894 (widget-apply widget
:custom-mark-to-reset-standard
)))
895 "The settings will revert to their default values, in this
896 and future sessions. Really erase customizations? " t
)
897 (custom-reset-standard-save-and-update))))
899 ;;; The Customize Commands
901 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
902 "Prompt for a variable and a value and return them as a list.
903 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
904 prompt for the value. The %s escape in PROMPT-VAL is replaced with
905 the name of the variable.
907 If the variable has a `variable-interactive' property, that is used as if
908 it were the arg to `interactive' (which see) to interactively read the value.
910 If the variable has a `custom-type' property, it must be a widget and the
911 `:prompt-value' property of that widget will be used for reading the value.
912 If the variable also has a `custom-get' property, that is used for finding
913 the current value of the variable, otherwise `symbol-value' is used.
915 If optional COMMENT argument is non-nil, also prompt for a comment and return
916 it as the third element in the list."
917 (let* ((var (read-variable prompt-var
))
918 (minibuffer-help-form '(describe-variable var
))
920 (let ((prop (get var
'variable-interactive
))
921 (type (get var
'custom-type
))
922 (prompt (format prompt-val var
)))
924 (setq type
(list type
)))
926 ;; Use VAR's `variable-interactive' property
927 ;; as an interactive spec for prompting.
928 (call-interactively `(lambda (arg)
932 (widget-prompt-value type
936 (or (get var
'custom-get
) 'symbol-value
)
940 (eval-minibuffer prompt
))))))
943 (read-string "Comment: " (get var
'variable-comment
)))
947 (defun customize-set-value (variable value
&optional comment
)
948 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
950 If VARIABLE has a `variable-interactive' property, that is used as if
951 it were the arg to `interactive' (which see) to interactively read the value.
953 If VARIABLE has a `custom-type' property, it must be a widget and the
954 `:prompt-value' property of that widget will be used for reading the value.
956 If given a prefix (or a COMMENT argument), also prompt for a comment."
957 (interactive (custom-prompt-variable "Set variable: "
961 (cond ((string= comment
"")
962 (put variable
'variable-comment nil
))
964 (put variable
'variable-comment comment
)))
965 (set variable value
))
968 (defun customize-set-variable (variable value
&optional comment
)
969 "Set the default for VARIABLE to VALUE, and return VALUE.
970 VALUE is a Lisp object.
972 If VARIABLE has a `custom-set' property, that is used for setting
973 VARIABLE, otherwise `set-default' is used.
975 If VARIABLE has a `variable-interactive' property, that is used as if
976 it were the arg to `interactive' (which see) to interactively read the value.
978 If VARIABLE has a `custom-type' property, it must be a widget and the
979 `:prompt-value' property of that widget will be used for reading the value.
981 If given a prefix (or a COMMENT argument), also prompt for a comment."
982 (interactive (custom-prompt-variable "Set variable: "
983 "Set customized value for %s to: "
985 (custom-load-symbol variable
)
986 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
987 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
988 (put variable
'customized-value
(list (custom-quote value
)))
989 (cond ((string= comment
"")
990 (put variable
'variable-comment nil
)
991 (put variable
'customized-variable-comment nil
))
993 (put variable
'variable-comment comment
)
994 (put variable
'customized-variable-comment comment
)))
998 (defun customize-save-variable (variable value
&optional comment
)
999 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1002 If VARIABLE has a `custom-set' property, that is used for setting
1003 VARIABLE, otherwise `set-default' is used.
1005 If VARIABLE has a `variable-interactive' property, that is used as if
1006 it were the arg to `interactive' (which see) to interactively read the value.
1008 If VARIABLE has a `custom-type' property, it must be a widget and the
1009 `:prompt-value' property of that widget will be used for reading the value.
1011 If given a prefix (or a COMMENT argument), also prompt for a comment."
1012 (interactive (custom-prompt-variable "Set and save variable: "
1013 "Set and save value for %s as: "
1014 current-prefix-arg
))
1015 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1016 (put variable
'saved-value
(list (custom-quote value
)))
1017 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1018 (cond ((string= comment
"")
1019 (put variable
'variable-comment nil
)
1020 (put variable
'saved-variable-comment nil
))
1022 (put variable
'variable-comment comment
)
1023 (put variable
'saved-variable-comment comment
)))
1024 (put variable
'customized-value nil
)
1025 (put variable
'customized-variable-comment nil
)
1028 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1030 (set variable value
))
1033 ;; Some parts of Emacs might prompt the user to save customizations,
1034 ;; during startup before customizations are loaded. This function
1035 ;; handles this corner case by avoiding calling `custom-save-variable'
1036 ;; too early, which could wipe out existing customizations.
1039 (defun customize-push-and-save (list-var elts
)
1040 "Add ELTS to LIST-VAR and save for future sessions, safely.
1041 ELTS should be a list. This function adds each entry to the
1042 value of LIST-VAR using `add-to-list'.
1044 If Emacs is initialized, call `customize-save-variable' to save
1045 the resulting list value now. Otherwise, add an entry to
1046 `after-init-hook' to save it after initialization."
1047 (dolist (entry elts
)
1048 (add-to-list list-var entry
))
1050 (let ((coding-system-for-read nil
))
1051 (customize-save-variable list-var
(eval list-var
)))
1052 (add-hook 'after-init-hook
1054 (customize-push-and-save list-var elts
)))))
1058 "Select a customization buffer which you can use to set user options.
1059 User options are structured into \"groups\".
1060 Initially the top-level group `Emacs' and its immediate subgroups
1061 are shown; the contents of those subgroups are initially hidden."
1063 (customize-group 'emacs
))
1066 (defun customize-mode (mode)
1067 "Customize options related to a major or minor mode.
1068 By default the current major mode is used. With a prefix
1069 argument or if the current major mode has no known group, prompt
1070 for the MODE to customize."
1073 (let ((completion-regexp-list '("-mode\\'"))
1074 (group (custom-group-of-mode major-mode
)))
1075 (if (and group
(not current-prefix-arg
))
1078 (completing-read (if group
1079 (format "Mode (default %s): " major-mode
)
1082 'custom-group-of-mode
1083 t nil nil
(if group
(symbol-name major-mode
))))))))
1084 (customize-group (custom-group-of-mode mode
)))
1086 (defun customize-read-group ()
1087 (let ((completion-ignore-case t
))
1088 (completing-read "Customize group (default emacs): "
1091 (or (and (get symbol
'custom-loads
)
1092 (not (get symbol
'custom-autoload
)))
1093 (get symbol
'custom-group
)))
1097 (defun customize-group (&optional group other-window
)
1098 "Customize GROUP, which must be a customization group.
1099 If OTHER-WINDOW is non-nil, display in another window."
1100 (interactive (list (customize-read-group)))
1101 (when (stringp group
)
1102 (if (string-equal "" group
)
1104 (setq group
(intern group
))))
1105 (let ((name (format "*Customize Group: %s*"
1106 (custom-unlispify-tag-name group
))))
1108 ((null (get-buffer name
))
1109 (funcall (if other-window
1110 'custom-buffer-create-other-window
1111 'custom-buffer-create
)
1112 (list (list group
'custom-group
))
1114 (concat " for group "
1115 (custom-unlispify-tag-name group
))))
1117 (switch-to-buffer-other-window name
))
1119 (pop-to-buffer-same-window name
)))))
1122 (defun customize-group-other-window (&optional group
)
1123 "Customize GROUP, which must be a customization group, in another window."
1124 (interactive (list (customize-read-group)))
1125 (customize-group group t
))
1128 (defalias 'customize-variable
'customize-option
)
1131 (defun customize-option (symbol)
1132 "Customize SYMBOL, which must be a user option."
1133 (interactive (custom-variable-prompt))
1135 (error "No variable specified"))
1136 (let ((basevar (indirect-variable symbol
)))
1137 (custom-buffer-create (list (list basevar
'custom-variable
))
1138 (format "*Customize Option: %s*"
1139 (custom-unlispify-tag-name basevar
)))
1140 (unless (eq symbol basevar
)
1141 (message "`%s' is an alias for `%s'" symbol basevar
))))
1144 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1147 (defun customize-option-other-window (symbol)
1148 "Customize SYMBOL, which must be a user option.
1149 Show the buffer in another window, but don't select it."
1150 (interactive (custom-variable-prompt))
1152 (error "No variable specified"))
1153 (let ((basevar (indirect-variable symbol
)))
1154 (custom-buffer-create-other-window
1155 (list (list basevar
'custom-variable
))
1156 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1157 (unless (eq symbol basevar
)
1158 (message "`%s' is an alias for `%s'" symbol basevar
))))
1160 (defvar customize-changed-options-previous-release
"24.5"
1161 "Version for `customize-changed-options' to refer back to by default.")
1163 ;; Packages will update this variable, so make it available.
1165 (defvar customize-package-emacs-version-alist nil
1166 "Alist mapping versions of a package to Emacs versions.
1167 We use this for packages that have their own names, but are released
1168 as part of Emacs itself.
1170 Each elements looks like this:
1172 (PACKAGE (PVERSION . EVERSION)...)
1174 Here PACKAGE is the name of a package, as a symbol. After
1175 PACKAGE come one or more elements, each associating a
1176 package version PVERSION with the first Emacs version
1177 EVERSION in which it (or a subsequent version of PACKAGE)
1178 was first released. Both PVERSION and EVERSION are strings.
1179 PVERSION should be a string that this package used in
1180 the :package-version keyword for `defcustom', `defgroup',
1183 For example, the MH-E package updates this alist as follows:
1185 (add-to-list \\='customize-package-emacs-version-alist
1186 \\='(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1187 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1188 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1189 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1191 The value of PACKAGE needs to be unique and it needs to match the
1192 PACKAGE value appearing in the :package-version keyword. Since
1193 the user might see the value in a error message, a good choice is
1194 the official name of the package, such as MH-E or Gnus.")
1197 (defalias 'customize-changed
'customize-changed-options
)
1200 (defun customize-changed-options (&optional since-version
)
1201 "Customize all settings whose meanings have changed in Emacs itself.
1202 This includes new user options and faces, and new customization
1203 groups, as well as older options and faces whose meanings or
1204 default values have changed since the previous major Emacs
1207 With argument SINCE-VERSION (a string), customize all settings
1208 that were added or redefined since that version."
1212 (read-from-minibuffer
1213 (format "Customize options changed, since version (default %s): "
1214 customize-changed-options-previous-release
))))
1215 (if (equal since-version
"")
1216 (setq since-version nil
)
1217 (unless (condition-case nil
1218 (numberp (read since-version
))
1220 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1221 (unless since-version
1222 (setq since-version customize-changed-options-previous-release
))
1224 ;; Load the information for versions since since-version. We use
1225 ;; custom-load-symbol for this.
1226 (put 'custom-versions-load-alist
'custom-loads nil
)
1227 (dolist (elt custom-versions-load-alist
)
1228 (if (customize-version-lessp since-version
(car elt
))
1229 (dolist (load (cdr elt
))
1230 (custom-add-load 'custom-versions-load-alist load
))))
1231 (custom-load-symbol 'custom-versions-load-alist
)
1232 (put 'custom-versions-load-alist
'custom-loads nil
)
1237 (let* ((package-version (get symbol
'custom-package-version
))
1239 (or (and package-version
1240 (customize-package-emacs-version symbol
1242 (get symbol
'custom-version
))))
1244 (when (customize-version-lessp since-version version
)
1245 (if (or (get symbol
'custom-group
)
1246 (get symbol
'group-documentation
))
1247 (push (list symbol
'custom-group
) found
))
1248 (if (custom-variable-p symbol
)
1249 (push (list symbol
'custom-variable
) found
))
1250 (if (custom-facep symbol
)
1251 (push (list symbol
'custom-face
) found
)))))))
1253 (custom-buffer-create (custom-sort-items found t
'first
)
1254 "*Customize Changed Options*")
1255 (user-error "No user option defaults have been changed since Emacs %s"
1258 (defun customize-package-emacs-version (symbol package-version
)
1259 "Return the Emacs version in which SYMBOL's meaning last changed.
1260 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1261 `customize-package-emacs-version-alist' to find the version of
1262 Emacs that is associated with version VERSION of PACKAGE."
1263 (let (package-versions emacs-version
)
1264 ;; Use message instead of error since we want user to be able to
1265 ;; see the rest of the symbols even if a package author has
1266 ;; botched things up.
1267 (cond ((not (listp package-version
))
1268 (message "Invalid package-version value for %s" symbol
))
1269 ((setq package-versions
(assq (car package-version
)
1270 customize-package-emacs-version-alist
))
1272 (cdr (assoc (cdr package-version
) package-versions
)))
1273 (unless emacs-version
1274 (message "%s version %s not found in %s" symbol
1275 (cdr package-version
)
1276 "customize-package-emacs-version-alist")))
1278 (message "Package %s version %s lists no corresponding Emacs version"
1279 (car package-version
)
1280 (cdr package-version
))))
1283 (defun customize-version-lessp (version1 version2
)
1284 ;; Why are the versions strings, and given that they are, why aren't
1285 ;; they converted to numbers and compared as such here? -- fx
1287 ;; In case someone made a mistake and left out the quotes
1288 ;; in the :version value.
1289 (if (numberp version2
)
1290 (setq version2
(prin1-to-string version2
)))
1291 (let (major1 major2 minor1 minor2
)
1292 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1293 (setq major1
(read (or (match-string 1 version1
)
1295 (setq minor1
(read (or (match-string 3 version1
)
1297 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1298 (setq major2
(read (or (match-string 1 version2
)
1300 (setq minor2
(read (or (match-string 3 version2
)
1302 (or (< major1 major2
)
1303 (and (= major1 major2
)
1304 (< minor1 minor2
)))))
1307 (defun customize-face (&optional face other-window
)
1308 "Customize FACE, which should be a face name or nil.
1309 If FACE is nil, customize all faces. If FACE is actually a
1310 face-alias, customize the face it is aliased to.
1312 If OTHER-WINDOW is non-nil, display in another window.
1314 Interactively, when point is on text which has a face specified,
1315 suggest to customize that face, if it's customizable."
1316 (interactive (list (read-face-name "Customize face"
1317 (or (face-at-point t t
) "all faces") t
)))
1318 (if (member face
'(nil ""))
1319 (setq face
(face-list)))
1320 (if (and (listp face
) (null (cdr face
)))
1321 (setq face
(car face
)))
1322 (let ((display-fun (if other-window
1323 'custom-buffer-create-other-window
1324 'custom-buffer-create
)))
1326 (funcall display-fun
1328 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1330 "*Customize Faces*")
1331 ;; If FACE is actually an alias, customize the face it is aliased to.
1332 (if (get face
'face-alias
)
1333 (setq face
(get face
'face-alias
)))
1334 (unless (facep face
)
1335 (error "Invalid face %S" face
))
1336 (funcall display-fun
1337 (list (list face
'custom-face
))
1338 (format "*Customize Face: %s*"
1339 (custom-unlispify-tag-name face
))))))
1342 (defun customize-face-other-window (&optional face
)
1343 "Show customization buffer for face FACE in other window.
1344 If FACE is actually a face-alias, customize the face it is aliased to.
1346 Interactively, when point is on text which has a face specified,
1347 suggest to customize that face, if it's customizable."
1348 (interactive (list (read-face-name "Customize face"
1349 (or (face-at-point t t
) "all faces") t
)))
1350 (customize-face face t
))
1352 (defun custom-unsaved-options ()
1353 "List of options and faces set in this session but not saved.
1354 Each entry is of the form (SYMBOL TYPE), where TYPE is one of the
1355 symbols `custom-face' or `custom-variable'."
1357 (mapatoms (lambda (symbol)
1358 (and (or (get symbol
'customized-face
)
1359 (get symbol
'customized-face-comment
))
1360 (custom-facep symbol
)
1361 (push (list symbol
'custom-face
) found
))
1362 (and (or (get symbol
'customized-value
)
1363 (get symbol
'customized-variable-comment
))
1365 (push (list symbol
'custom-variable
) found
))))
1368 (defalias 'customize-customized
'customize-unsaved
)
1371 (defun customize-unsaved ()
1372 "Customize all options and faces set in this session but not saved."
1374 (let ((found (custom-unsaved-options)))
1376 (error "No user options are set but unsaved")
1377 (custom-buffer-create (custom-sort-items found t nil
)
1378 "*Customize Unsaved*"))))
1381 (defun customize-rogue ()
1382 "Customize all user variables modified outside customize."
1385 (mapatoms (lambda (symbol)
1386 (let ((cval (or (get symbol
'customized-value
)
1387 (get symbol
'saved-value
)
1388 (get symbol
'standard-value
))))
1389 (when (and cval
;Declared with defcustom.
1390 (default-boundp symbol
) ;Has a value.
1391 (not (equal (eval (car cval
))
1392 ;; Which does not match customize.
1393 (default-value symbol
))))
1394 (push (list symbol
'custom-variable
) found
)))))
1396 (user-error "No rogue user options")
1397 (custom-buffer-create (custom-sort-items found t nil
)
1398 "*Customize Rogue*"))))
1400 (defun customize-saved ()
1401 "Customize all saved options and faces."
1404 (mapatoms (lambda (symbol)
1405 (and (or (get symbol
'saved-face
)
1406 (get symbol
'saved-face-comment
))
1407 (custom-facep symbol
)
1408 (push (list symbol
'custom-face
) found
))
1409 (and (or (get symbol
'saved-value
)
1410 (get symbol
'saved-variable-comment
))
1412 (push (list symbol
'custom-variable
) found
))))
1414 (user-error "No saved user options")
1415 (custom-buffer-create (custom-sort-items found t nil
)
1416 "*Customize Saved*"))))
1418 (declare-function apropos-parse-pattern
"apropos" (pattern))
1419 (defvar apropos-regexp
)
1422 (defun customize-apropos (pattern &optional type
)
1423 "Customize loaded options, faces and groups matching PATTERN.
1424 PATTERN can be a word, a list of words (separated by spaces),
1425 or a regexp (using some regexp special characters). If it is a word,
1426 search for matches for that word as a substring. If it is a list of
1427 words, search for matches for any two (or more) of those words.
1429 If TYPE is `options', include only options.
1430 If TYPE is `faces', include only faces.
1431 If TYPE is `groups', include only groups."
1432 (interactive (list (apropos-read-pattern "symbol") nil
))
1434 (unless (memq type
'(nil options faces groups
))
1435 (error "Invalid setting type %s" (symbol-name type
)))
1436 (apropos-parse-pattern pattern
) ;Sets apropos-regexp by side-effect: Yuck!
1440 (when (string-match-p apropos-regexp
(symbol-name symbol
))
1441 (if (memq type
'(nil groups
))
1442 (if (get symbol
'custom-group
)
1443 (push (list symbol
'custom-group
) found
)))
1444 (if (memq type
'(nil faces
))
1445 (if (custom-facep symbol
)
1446 (push (list symbol
'custom-face
) found
)))
1447 (if (memq type
'(nil options
))
1448 (if (and (boundp symbol
)
1449 (eq (indirect-variable symbol
) symbol
)
1450 (or (get symbol
'saved-value
)
1451 (custom-variable-p symbol
)))
1452 (push (list symbol
'custom-variable
) found
))))))
1454 (error "No customizable %s matching %s" (if (not type
)
1455 "group, face, or option"
1458 (custom-buffer-create
1459 (custom-sort-items found t custom-buffer-order-groups
)
1460 "*Customize Apropos*")))
1463 (defun customize-apropos-options (regexp &optional ignored
)
1464 "Customize all loaded customizable options matching REGEXP."
1465 (interactive (list (apropos-read-pattern "options")))
1466 (customize-apropos regexp
'options
))
1469 (defun customize-apropos-faces (regexp)
1470 "Customize all loaded faces matching REGEXP."
1471 (interactive (list (apropos-read-pattern "faces")))
1472 (customize-apropos regexp
'faces
))
1475 (defun customize-apropos-groups (regexp)
1476 "Customize all loaded groups matching REGEXP."
1477 (interactive (list (apropos-read-pattern "groups")))
1478 (customize-apropos regexp
'groups
))
1481 (defun custom-prompt-customize-unsaved-options ()
1482 "Prompt user to customize any unsaved customization options.
1483 Return non-nil if user chooses to customize, for use in
1484 `kill-emacs-query-functions'."
1485 (not (and (custom-unsaved-options)
1486 (yes-or-no-p "Some customized options have not been saved; Examine? ")
1492 (defcustom custom-buffer-style
'links
1493 "Control the presentation style for customization buffers.
1494 The value should be a symbol, one of:
1495 `brackets': groups nest within each other with big horizontal brackets.
1496 `links': groups have links to subgroups.
1497 `tree': display groups as trees."
1498 :type
'(radio (const brackets
)
1501 :group
'custom-buffer
)
1503 (defcustom custom-buffer-done-kill nil
1504 "Non-nil means exiting a Custom buffer should kill it."
1507 :group
'custom-buffer
)
1509 (defcustom custom-buffer-indent
3
1510 "Number of spaces to indent nested groups."
1512 :group
'custom-buffer
)
1514 (defun custom-get-fresh-buffer (name)
1515 "Get a fresh new buffer with name NAME.
1516 If the buffer already exist, clean it up to be like new.
1517 Beware: it's not quite like new. Good enough for custom, but maybe
1519 ;; To be more complete, we should also kill all permanent-local variables,
1520 ;; but it's not needed for custom.
1521 (let ((buf (get-buffer name
)))
1522 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1523 ;; This will check if the file is not saved.
1527 (get-buffer-create name
)
1528 (with-current-buffer buf
1529 (kill-all-local-variables)
1530 (run-hooks 'kill-buffer-hook
)
1531 ;; Delete overlays before erasing the buffer so the overlay hooks
1532 ;; don't get run spuriously when we erase the buffer.
1533 (let ((ols (overlay-lists)))
1534 (dolist (ol (nconc (car ols
) (cdr ols
)))
1535 (delete-overlay ol
)))
1540 (defun custom-buffer-create (options &optional name _description
)
1541 "Create a buffer containing OPTIONS.
1542 Optional NAME is the name of the buffer.
1543 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1544 SYMBOL is a customization option, and WIDGET is a widget for editing
1546 DESCRIPTION is unused."
1547 (pop-to-buffer-same-window
1548 (custom-get-fresh-buffer (or name
"*Customization*")))
1549 (custom-buffer-create-internal options
))
1552 (defun custom-buffer-create-other-window (options &optional name _description
)
1553 "Create a buffer containing OPTIONS, and display it in another window.
1554 The result includes selecting that window.
1555 Optional NAME is the name of the buffer.
1556 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1557 SYMBOL is a customization option, and WIDGET is a widget for editing
1559 DESCRIPTION is unused."
1560 (unless name
(setq name
"*Customization*"))
1561 (switch-to-buffer-other-window (custom-get-fresh-buffer name
))
1562 (custom-buffer-create-internal options
))
1564 (defcustom custom-reset-button-menu t
1565 "If non-nil, only show a single reset button in customize buffers.
1566 This button will have a menu with all three reset operations."
1568 :group
'custom-buffer
1571 (defcustom custom-buffer-verbose-help t
1572 "If non-nil, include explanatory text in the customization buffer."
1574 :group
'custom-buffer
)
1576 (defun Custom-buffer-done (&rest _ignore
)
1577 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1579 (quit-window custom-buffer-done-kill
))
1581 (defvar custom-button nil
1582 "Face used for buttons in customization buffers.")
1584 (defvar custom-button-mouse nil
1585 "Mouse face used for buttons in customization buffers.")
1587 (defvar custom-button-pressed nil
1588 "Face used for pressed buttons in customization buffers.")
1590 (defcustom custom-search-field t
1591 "If non-nil, show a search field in Custom buffers."
1594 :group
'custom-buffer
)
1596 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1597 '(("unspecified" . unspecified
))))
1598 "If non-nil, indicate active buttons in a raised-button style.
1599 Otherwise use brackets."
1602 :group
'custom-buffer
1603 :set
(lambda (variable value
)
1604 (custom-set-default variable value
)
1606 (if value
'custom-button
'custom-button-unraised
))
1607 (setq custom-button-mouse
1608 (if value
'custom-button-mouse
'highlight
))
1609 (setq custom-button-pressed
1611 'custom-button-pressed
1612 'custom-button-pressed-unraised
))))
1614 (defun custom-buffer-create-internal (options &optional _description
)
1616 (let ((init-file (or custom-file user-init-file
)))
1617 ;; Insert verbose help at the top of the custom buffer.
1618 (when custom-buffer-verbose-help
1620 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1621 (widget-insert "For help using this buffer, see ")
1622 (widget-create 'custom-manual
1623 :tag
"Easy Customization"
1624 "(emacs)Easy Customization")
1625 (widget-insert " in the ")
1626 (widget-create 'custom-manual
1628 :help-echo
"Read the Emacs manual."
1630 (widget-insert "."))
1631 (widget-insert "\n")
1633 ;; Insert the search field.
1634 (when custom-search-field
1635 (widget-insert "\n")
1636 (let* ((echo "Search for custom items.
1637 You can enter one or more words separated by spaces,
1638 or a regular expression.")
1642 :size
40 :help-echo echo
1643 :action
(lambda (widget &optional _event
)
1644 (customize-apropos (split-string (widget-value widget
)))))))
1646 (widget-create-child-and-convert
1647 search-widget
'push-button
1649 :help-echo echo
:action
1650 (lambda (widget &optional _event
)
1651 (customize-apropos (split-string (widget-value (widget-get widget
:parent
))))))
1652 (widget-insert "\n")))
1654 ;; The custom command buttons are also in the toolbar, so for a
1655 ;; time they were not inserted in the buffer if the toolbar was in use.
1656 ;; But it can be a little confusing for the buffer layout to
1657 ;; change according to whether or nor the toolbar is on, not to
1658 ;; mention that a custom buffer can in theory be created in a
1659 ;; frame with a toolbar, then later viewed in one without.
1660 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1661 (if custom-buffer-verbose-help
1663 Operate on all settings in this buffer:\n"))
1664 (let ((button (lambda (tag action active help _icon _label
)
1667 (widget-create 'push-button
:tag tag
1668 :help-echo help
:action action
))))
1669 (commands custom-commands
))
1670 (if custom-reset-button-menu
1672 (widget-create 'push-button
1674 :help-echo
"Show a menu with reset operations."
1675 :mouse-down-action
'ignore
1676 :action
'custom-reset
)
1677 (apply button
(pop commands
)) ; Apply
1678 (apply button
(pop commands
))) ; Apply and Save
1679 (apply button
(pop commands
)) ; Apply
1680 (apply button
(pop commands
)) ; Apply and Save
1681 (widget-insert "\n")
1682 (apply button
(pop commands
)) ; Undo
1683 (apply button
(pop commands
)) ; Reset
1684 (apply button
(pop commands
)) ; Erase
1686 (pop commands
) ; Help (omitted)
1687 (apply button
(pop commands
)))) ; Exit
1688 (widget-insert "\n\n"))
1690 ;; Now populate the custom buffer.
1691 (message "Creating customization items...")
1692 (buffer-disable-undo)
1693 (setq custom-options
1694 (if (= (length options
) 1)
1695 (mapcar (lambda (entry)
1696 (widget-create (nth 1 entry
)
1697 :documentation-shown t
1698 :custom-state
'unknown
1699 :tag
(custom-unlispify-tag-name
1701 :value
(nth 0 entry
)))
1704 (length (length options
)))
1705 (mapcar (lambda (entry)
1707 (message "Creating customization items ...%2d%%"
1708 (floor (* 100.0 count
) length
))
1709 (widget-create (nth 1 entry
)
1710 :tag
(custom-unlispify-tag-name
1712 :value
(nth 0 entry
))
1713 (setq count
(1+ count
))
1714 (unless (eq (preceding-char) ?
\n)
1715 (widget-insert "\n"))
1716 (widget-insert "\n")))
1718 (unless (eq (preceding-char) ?
\n)
1719 (widget-insert "\n"))
1720 (message "Creating customization items ...done")
1721 (message "Resetting customization items...")
1722 (unless (eq custom-buffer-style
'tree
)
1723 (mapc 'custom-magic-reset custom-options
))
1724 (message "Resetting customization items...done")
1725 (message "Creating customization setup...")
1727 (buffer-enable-undo)
1728 (goto-char (point-min))
1729 (message "Creating customization setup...done"))
1731 ;;; The Tree Browser.
1734 (defun customize-browse (&optional group
)
1735 "Create a tree browser for the customize hierarchy."
1738 (setq group
'emacs
))
1739 (let ((name "*Customize Browser*"))
1740 (pop-to-buffer-same-window (custom-get-fresh-buffer name
)))
1742 (widget-insert (format "\
1743 %s buttons; type RET or click mouse-1
1744 on a button to invoke its action.
1745 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1746 (if custom-raised-buttons
1747 "Raised text indicates"
1748 "Square brackets indicate")))
1751 (if custom-browse-only-groups
1753 Invoke the [Group] button below to edit that item in another window.\n\n")
1754 (widget-insert "Invoke the ")
1755 (widget-create 'item
1758 :tag-glyph
"folder")
1759 (widget-insert ", ")
1760 (widget-create 'item
1764 (widget-insert ", and ")
1765 (widget-create 'item
1768 :tag-glyph
"option")
1769 (widget-insert " buttons below to edit that
1770 item in another window.\n\n"))
1771 (let ((custom-buffer-style 'tree
))
1772 (widget-create 'custom-group
1774 :custom-state
'unknown
1775 :tag
(custom-unlispify-tag-name group
)
1778 (goto-char (point-min)))
1780 (define-widget 'custom-browse-visibility
'item
1781 "Control visibility of items in the customize tree browser."
1783 :action
'custom-browse-visibility-action
)
1785 (defun custom-browse-visibility-action (widget &rest _ignore
)
1786 (let ((custom-buffer-style 'tree
))
1787 (custom-toggle-parent widget
)))
1789 (define-widget 'custom-browse-group-tag
'custom-group-link
1790 "Show parent in other window when activated."
1793 :action
'custom-browse-group-tag-action
)
1795 (defun custom-browse-group-tag-action (widget &rest _ignore
)
1796 (let ((parent (widget-get widget
:parent
)))
1797 (customize-group-other-window (widget-value parent
))))
1799 (define-widget 'custom-browse-variable-tag
'custom-group-link
1800 "Show parent in other window when activated."
1803 :action
'custom-browse-variable-tag-action
)
1805 (defun custom-browse-variable-tag-action (widget &rest _ignore
)
1806 (let ((parent (widget-get widget
:parent
)))
1807 (customize-variable-other-window (widget-value parent
))))
1809 (define-widget 'custom-browse-face-tag
'custom-group-link
1810 "Show parent in other window when activated."
1813 :action
'custom-browse-face-tag-action
)
1815 (defun custom-browse-face-tag-action (widget &rest _ignore
)
1816 (let ((parent (widget-get widget
:parent
)))
1817 (customize-face-other-window (widget-value parent
))))
1819 (defconst custom-browse-alist
'((" " "space")
1825 (defun custom-browse-insert-prefix (prefix)
1826 "Insert PREFIX. On XEmacs convert it to line graphics."
1827 ;; Fixme: do graphics.
1828 (if nil
; (featurep 'xemacs)
1831 (while (not (string-equal prefix
""))
1832 (let ((entry (substring prefix
0 3)))
1833 (setq prefix
(substring prefix
3))
1834 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1835 (name (nth 1 (assoc entry custom-browse-alist
))))
1836 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1837 (overlay-put overlay
'start-open t
)
1838 (overlay-put overlay
'end-open t
)))))
1841 ;;; Modification of Basic Widgets.
1843 ;; We add extra properties to the basic widgets needed here. This is
1844 ;; fine, as long as we are careful to stay within our own namespace.
1846 ;; We want simple widgets to be displayed by default, but complex
1847 ;; widgets to be hidden.
1849 ;; This widget type is obsolete as of Emacs 24.1.
1850 (widget-put (get 'item
'widget-type
) :custom-show t
)
1851 (widget-put (get 'editable-field
'widget-type
)
1852 :custom-show
(lambda (_widget value
)
1853 (let ((pp (pp-to-string value
)))
1854 (cond ((string-match-p "\n" pp
)
1859 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1861 ;;; The `custom-manual' Widget.
1863 (define-widget 'custom-manual
'info-link
1864 "Link to the manual entry for this customization option."
1865 :help-echo
"Read the manual entry for this option."
1866 :keymap custom-mode-link-map
1867 :follow-link
'mouse-face
1868 :button-face
'custom-link
1869 :mouse-face
'highlight
1870 :pressed-face
'highlight
1873 ;;; The `custom-magic' Widget.
1875 (defgroup custom-magic-faces nil
1876 "Faces used by the magic button."
1877 :group
'custom-faces
1878 :group
'custom-buffer
)
1880 (defface custom-invalid
'((((class color
))
1881 :foreground
"yellow1" :background
"red1")
1882 (t :weight bold
:slant italic
:underline t
))
1883 "Face used when the customize item is invalid."
1884 :group
'custom-magic-faces
)
1886 (defface custom-rogue
'((((class color
))
1887 :foreground
"pink" :background
"black")
1889 "Face used when the customize item is not defined for customization."
1890 :group
'custom-magic-faces
)
1892 (defface custom-modified
'((((min-colors 88) (class color
))
1893 :foreground
"white" :background
"blue1")
1895 :foreground
"white" :background
"blue")
1897 "Face used when the customize item has been modified."
1898 :group
'custom-magic-faces
)
1900 (defface custom-set
'((((min-colors 88) (class color
))
1901 :foreground
"blue1" :background
"white")
1903 :foreground
"blue" :background
"white")
1905 "Face used when the customize item has been set."
1906 :group
'custom-magic-faces
)
1908 (defface custom-changed
'((((min-colors 88) (class color
))
1909 :foreground
"white" :background
"blue1")
1911 :foreground
"white" :background
"blue")
1913 "Face used when the customize item has been changed."
1914 :group
'custom-magic-faces
)
1916 (defface custom-themed
'((((min-colors 88) (class color
))
1917 :foreground
"white" :background
"blue1")
1919 :foreground
"white" :background
"blue")
1921 "Face used when the customize item has been set by a theme."
1922 :group
'custom-magic-faces
)
1924 (defface custom-saved
'((t :underline t
))
1925 "Face used when the customize item has been saved."
1926 :group
'custom-magic-faces
)
1928 (defconst custom-magic-alist
1929 '((nil "#" underline
"\
1930 UNINITIALIZED, you should not see this.")
1931 (unknown "?" italic
"\
1932 UNKNOWN, you should not see this.")
1933 (hidden "-" default
"\
1934 HIDDEN, invoke \"Show\" in the previous line to show." "\
1935 group now hidden, invoke \"Show\", above, to show contents.")
1936 (invalid "x" custom-invalid
"\
1937 INVALID, the displayed value cannot be set.")
1938 (modified "*" custom-modified
"\
1939 EDITED, shown value does not take effect until you set or save it." "\
1940 something in this group has been edited but not set.")
1941 (set "+" custom-set
"\
1942 SET for current session only." "\
1943 something in this group has been set but not saved.")
1944 (changed ":" custom-changed
"\
1945 CHANGED outside Customize." "\
1946 something in this group has been changed outside customize.")
1947 (saved "!" custom-saved
"\
1949 something in this group has been set and saved.")
1950 (themed "o" custom-themed
"\
1952 visible group members are set by enabled themes.")
1953 (rogue "@" custom-rogue
"\
1954 NO CUSTOMIZATION DATA; not intended to be customized." "\
1955 something in this group is not prepared for customization.")
1956 (standard " " nil
"\
1958 visible group members are all at standard values."))
1959 "Alist of customize option states.
1960 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1962 STATE is one of the following symbols:
1965 For internal use, should never occur.
1967 For internal use, should never occur.
1969 This item is not being displayed.
1971 This item is modified, but has an invalid form.
1973 This item is modified, and has a valid form.
1975 This item has been set but not saved.
1977 The current value of this item has been changed outside Customize.
1979 This item is marked for saving.
1981 This item has no customization information.
1983 This item was set by an enabled Custom theme.
1985 This item is unchanged from the standard setting.
1987 MAGIC is a string used to present that state.
1989 FACE is a face used to present the state.
1991 ITEM-DESC is a string describing the state for options.
1993 GROUP-DESC is a string describing the state for groups. If this is
1994 left out, ITEM-DESC will be used.
1996 The string %c in either description will be replaced with the
1997 category of the item. These are `group', `option', and `face'.
1999 The list should be sorted most significant first.")
2001 (defcustom custom-magic-show
'long
2002 "If non-nil, show textual description of the state.
2003 If `long', show a full-line description, not just one word."
2004 :type
'(choice (const :tag
"no" nil
)
2006 (other :tag
"short" short
))
2007 :group
'custom-buffer
)
2009 (defcustom custom-magic-show-hidden
'(option face
)
2010 "Control whether the State button is shown for hidden items.
2011 The value should be a list with the custom categories where the State
2012 button should be visible. Possible categories are `group', `option',
2014 :type
'(set (const group
) (const option
) (const face
))
2015 :group
'custom-buffer
)
2017 (defcustom custom-magic-show-button nil
2018 "Show a \"magic\" button indicating the state of each customization option."
2020 :group
'custom-buffer
)
2022 (define-widget 'custom-magic
'default
2023 "Show and manipulate state for a customization option."
2025 :action
'widget-parent-action
2028 :value-create
'custom-magic-value-create
2029 :value-delete
'widget-children-value-delete
)
2031 (defun widget-magic-mouse-down-action (widget &optional _event
)
2032 ;; Non-nil unless hidden.
2033 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2037 (defun custom-magic-value-create (widget)
2038 "Create compact status report for WIDGET."
2039 (let* ((parent (widget-get widget
:parent
))
2040 (state (widget-get parent
:custom-state
))
2041 (hidden (eq state
'hidden
))
2042 (entry (assq state custom-magic-alist
))
2043 (magic (nth 1 entry
))
2044 (face (nth 2 entry
))
2045 (category (widget-get parent
:custom-category
))
2046 (text (or (and (eq category
'group
)
2049 (form (widget-get parent
:custom-form
))
2051 (unless (eq state
'hidden
)
2052 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2053 (setq text
(concat (match-string 1 text
)
2054 (symbol-name category
)
2055 (match-string 2 text
))))
2056 (when (and custom-magic-show
2058 (memq category custom-magic-show-hidden
)))
2060 (when (and (eq category
'group
)
2061 (not (and (eq custom-buffer-style
'links
)
2062 (> (widget-get parent
:custom-level
) 1))))
2063 (insert-char ?\s
(* custom-buffer-indent
2064 (widget-get parent
:custom-level
))))
2065 (push (widget-create-child-and-convert
2067 :help-echo
"Change the state of this item."
2068 :format
(if hidden
"%t" "%[%t%]")
2069 :button-prefix
'widget-push-button-prefix
2070 :button-suffix
'widget-push-button-suffix
2071 :mouse-down-action
'widget-magic-mouse-down-action
2075 (let ((start (point)))
2076 (if (eq custom-magic-show
'long
)
2078 (insert (symbol-name state
)))
2079 (cond ((eq form
'lisp
)
2081 ((eq form
'mismatch
)
2082 (insert " (mismatch)")))
2083 (put-text-property start
(point) 'face
'custom-state
))
2085 (when (and (eq category
'group
)
2086 (not (and (eq custom-buffer-style
'links
)
2087 (> (widget-get parent
:custom-level
) 1))))
2088 (insert-char ?\s
(* custom-buffer-indent
2089 (widget-get parent
:custom-level
))))
2090 (when custom-magic-show-button
2091 (when custom-magic-show
2092 (let ((indent (widget-get parent
:indent
)))
2094 (insert-char ? indent
))))
2095 (push (widget-create-child-and-convert
2097 :mouse-down-action
'widget-magic-mouse-down-action
2101 :help-echo
"Change the state."
2102 :format
(if hidden
"%t" "%[%t%]")
2103 :tag
(if (memq form
'(lisp mismatch
))
2104 (concat "(" magic
")")
2105 (concat "[" magic
"]")))
2108 (widget-put widget
:children children
))))
2110 (defun custom-magic-reset (widget)
2111 "Redraw the :custom-magic property of WIDGET."
2112 (let ((magic (widget-get widget
:custom-magic
)))
2114 (widget-value-set magic
(widget-value magic
)))))
2116 ;;; The `custom' Widget.
2118 (defface custom-button
2119 '((((type x w32 ns
) (class color
)) ; Like default mode line
2120 :box
(:line-width
2 :style released-button
)
2121 :background
"lightgrey" :foreground
"black"))
2122 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2124 :group
'custom-faces
)
2126 (defface custom-button-mouse
2127 '((((type x w32 ns
) (class color
))
2128 :box
(:line-width
2 :style released-button
)
2129 :background
"grey90" :foreground
"black")
2131 ;; This is for text terminals that support mouse, like GPM mouse
2132 ;; or the MS-DOS terminal: inverse-video makes the button stand
2133 ;; out on mouse-over.
2135 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2137 :group
'custom-faces
)
2139 (defface custom-button-unraised
2140 '((t :inherit underline
))
2141 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2143 :group
'custom-faces
)
2146 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2148 (setq custom-button-mouse
2149 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2151 (defface custom-button-pressed
2152 '((((type x w32 ns
) (class color
))
2153 :box
(:line-width
2 :style pressed-button
)
2154 :background
"lightgrey" :foreground
"black")
2155 (t :inverse-video t
))
2156 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2158 :group
'custom-faces
)
2160 (defface custom-button-pressed-unraised
2161 '((default :inherit custom-button-unraised
)
2162 (((class color
) (background light
)) :foreground
"magenta4")
2163 (((class color
) (background dark
)) :foreground
"violet"))
2164 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2166 :group
'custom-faces
)
2168 (setq custom-button-pressed
2169 (if custom-raised-buttons
2170 'custom-button-pressed
2171 'custom-button-pressed-unraised
))
2173 (defface custom-documentation
'((t nil
))
2174 "Face used for documentation strings in customization buffers."
2175 :group
'custom-faces
)
2177 (defface custom-state
'((((class color
) (background dark
))
2178 :foreground
"lime green")
2179 (((class color
) (background light
))
2180 :foreground
"dark green"))
2181 "Face used for State descriptions in the customize buffer."
2182 :group
'custom-faces
)
2184 (defface custom-link
'((t :inherit link
))
2185 "Face for links in customization buffers."
2187 :group
'custom-faces
)
2189 (define-widget 'custom
'default
2190 "Customize a user option."
2192 :convert-widget
'custom-convert-widget
2193 :notify
'custom-notify
2196 :custom-state
'hidden
2197 :documentation-property
'widget-subclass-responsibility
2198 :value-create
'widget-subclass-responsibility
2199 :value-delete
'widget-children-value-delete
2200 :value-get
'widget-value-value-get
2201 :validate
'widget-children-validate
2202 :match
(lambda (_widget value
) (symbolp value
)))
2204 (defun custom-convert-widget (widget)
2205 "Initialize :value and :tag from :args in WIDGET."
2206 (let ((args (widget-get widget
:args
)))
2208 (widget-put widget
:value
(widget-apply widget
2209 :value-to-internal
(car args
)))
2210 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2211 (widget-put widget
:args nil
)))
2214 (defun custom-notify (widget &rest args
)
2215 "Keep track of changes."
2216 (let ((state (widget-get widget
:custom-state
)))
2217 (unless (eq state
'modified
)
2218 (unless (memq state
'(nil unknown hidden
))
2219 (widget-put widget
:custom-state
'modified
))
2220 (custom-magic-reset widget
)
2221 (apply 'widget-default-notify widget args
))))
2223 (defun custom-redraw (widget)
2224 "Redraw WIDGET with current settings."
2225 (let ((line (count-lines (point-min) (point)))
2226 (column (current-column))
2228 (from (marker-position (widget-get widget
:from
)))
2229 (to (marker-position (widget-get widget
:to
))))
2231 (widget-value-set widget
(widget-value widget
))
2232 (custom-redraw-magic widget
))
2233 (when (and (>= pos from
) (<= pos to
))
2236 (goto-char (point-min))
2237 (forward-line (if (> column
0)
2240 (move-to-column column
))
2243 (defun custom-redraw-magic (widget)
2244 "Redraw WIDGET state with current settings."
2246 (let ((magic (widget-get widget
:custom-magic
)))
2248 (widget-value-set magic
(widget-value magic
))
2249 (when (setq widget
(widget-get widget
:group
))
2250 (custom-group-state-update widget
)))
2252 (setq widget nil
)))))
2255 (defun custom-show (widget value
)
2256 "Non-nil if WIDGET should be shown with VALUE by default."
2257 (declare (obsolete "this widget type is no longer supported." "24.1"))
2258 (let ((show (widget-get widget
:custom-show
)))
2259 (if (functionp show
)
2260 (funcall show widget value
)
2263 (defun custom-load-widget (widget)
2264 "Load all dependencies for WIDGET."
2265 (custom-load-symbol (widget-value widget
)))
2267 (defun custom-unloaded-symbol-p (symbol)
2268 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2270 (loads (get symbol
'custom-loads
))
2273 (setq load
(car loads
)
2275 (cond ((symbolp load
)
2276 (unless (featurep load
)
2278 ((assoc load load-history
))
2279 ((assoc (locate-library load
) load-history
)
2285 (defun custom-unloaded-widget-p (widget)
2286 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2287 (custom-unloaded-symbol-p (widget-value widget
)))
2289 (defun custom-toggle-hide (widget)
2290 "Toggle visibility of WIDGET."
2291 (custom-load-widget widget
)
2292 (let ((state (widget-get widget
:custom-state
)))
2293 (cond ((memq state
'(invalid modified set
))
2294 (error "There are unsaved changes"))
2296 (widget-put widget
:custom-state
'unknown
))
2298 (widget-put widget
:documentation-shown nil
)
2299 (widget-put widget
:custom-state
'hidden
)))
2300 (custom-redraw widget
)
2303 (defun custom-toggle-parent (widget &rest _ignore
)
2304 "Toggle visibility of parent of WIDGET."
2305 (custom-toggle-hide (widget-get widget
:parent
)))
2307 (defun custom-add-see-also (widget &optional prefix
)
2308 "Add `See also ...' to WIDGET if there are any links.
2309 Insert PREFIX first if non-nil."
2310 (let* ((symbol (widget-get widget
:value
))
2311 (links (get symbol
'custom-links
))
2312 (many (> (length links
) 2))
2313 (buttons (widget-get widget
:buttons
))
2314 (indent (widget-get widget
:indent
)))
2317 (insert-char ?\s indent
))
2320 (insert "See also ")
2322 (push (widget-create-child-and-convert
2324 :button-face
'custom-link
2325 :mouse-face
'highlight
2326 :pressed-face
'highlight
)
2328 (setq links
(cdr links
))
2337 (widget-put widget
:buttons buttons
))))
2339 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string
)
2340 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2341 The value is non-nil if any parents were found.
2342 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2343 (let ((name (widget-value widget
))
2344 (type (widget-type widget
))
2345 (buttons (widget-get widget
:buttons
))
2348 (insert (or initial-string
"Groups:"))
2349 (mapatoms (lambda (symbol)
2350 (when (member (list name type
) (get symbol
'custom-group
))
2352 (push (widget-create-child-and-convert
2353 widget
'custom-group-link
2354 :tag
(custom-unlispify-tag-name symbol
)
2357 (setq parents
(cons symbol parents
)))))
2360 (delete-region start
(point)))
2361 (widget-put widget
:buttons buttons
)
2364 ;;; The `custom-comment' Widget.
2366 ;; like the editable field
2367 (defface custom-comment
'((((type tty
))
2368 :background
"yellow3"
2369 :foreground
"black")
2370 (((class grayscale color
)
2372 :background
"gray85")
2373 (((class grayscale color
)
2375 :background
"dim gray")
2378 "Face used for comments on variables or faces."
2380 :group
'custom-faces
)
2382 ;; like font-lock-comment-face
2383 (defface custom-comment-tag
2384 '((((class color
) (background dark
)) :foreground
"gray80")
2385 (((class color
) (background light
)) :foreground
"blue4")
2386 (((class grayscale
) (background light
))
2387 :foreground
"DimGray" :weight bold
:slant italic
)
2388 (((class grayscale
) (background dark
))
2389 :foreground
"LightGray" :weight bold
:slant italic
)
2391 "Face used for the comment tag on variables or faces."
2392 :group
'custom-faces
)
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
2431 `((((class color
) (background dark
))
2432 :foreground
"light blue" :weight bold
)
2433 (((min-colors 88) (class color
) (background light
))
2434 :foreground
"blue1" :weight bold
)
2435 (((class color
) (background light
))
2436 :foreground
"blue" :weight bold
)
2438 "Face used for unpushable variable tags."
2439 :group
'custom-faces
)
2441 (defface custom-variable-button
'((t :underline t
:weight bold
))
2442 "Face used for pushable variable tags."
2443 :group
'custom-faces
)
2445 (defcustom custom-variable-default-form
'edit
2446 "Default form of displaying variable values."
2447 :type
'(choice (const edit
)
2449 :group
'custom-buffer
2452 (defun custom-variable-documentation (variable)
2453 "Return documentation of VARIABLE for use in Custom buffer.
2454 Normally just return the docstring. But if VARIABLE automatically
2455 becomes buffer local when set, append a message to that effect."
2456 (format "%s%s" (documentation-property variable
'variable-documentation t
)
2457 (if (and (local-variable-if-set-p variable
)
2458 (or (not (local-variable-p variable
))
2460 (local-variable-if-set-p variable
))))
2462 This variable automatically becomes buffer-local when set outside Custom.
2463 However, setting it through Custom sets the default value."
2466 (define-widget 'custom-variable
'custom
2467 "A widget for displaying a Custom variable.
2468 The following properties have special meanings for this widget:
2470 :hidden-states should be a list of widget states for which the
2471 widget's initial contents are to be hidden.
2473 :custom-form should be a symbol describing how to display and
2474 edit the variable---either `edit' (using edit widgets),
2475 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2476 if nil, use the return value of `custom-variable-default-form'.
2478 :shown-value, if non-nil, should be a list whose `car' is the
2479 variable value to display in place of the current value.
2481 :custom-style describes the widget interface style; nil is the
2482 default style, while `simple' means a simpler interface that
2483 inhibits the magic custom-state widget."
2485 :help-echo
"Set or reset this variable."
2486 :documentation-property
#'custom-variable-documentation
2487 :custom-category
'option
2489 :custom-menu
'custom-variable-menu-create
2491 :value-create
'custom-variable-value-create
2492 :action
'custom-variable-action
2493 :hidden-states
'(standard)
2494 :custom-set
'custom-variable-set
2495 :custom-mark-to-save
'custom-variable-mark-to-save
2496 :custom-reset-current
'custom-redraw
2497 :custom-reset-saved
'custom-variable-reset-saved
2498 :custom-reset-standard
'custom-variable-reset-standard
2499 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2500 :custom-standard-value
'custom-variable-standard-value
2501 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2503 (defun custom-variable-type (symbol)
2504 "Return a widget suitable for editing the value of SYMBOL.
2505 If SYMBOL has a `custom-type' property, use that.
2506 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2507 try matching its doc string against `custom-guess-doc-alist'."
2508 (let* ((type (or (get symbol
'custom-type
)
2509 (and (not (get symbol
'standard-value
))
2510 (custom-guess-type symbol
))
2512 (options (get symbol
'custom-options
))
2513 (tmp (if (listp type
)
2514 (copy-sequence type
)
2517 (widget-put tmp
:options options
))
2520 (defun custom-variable-value-create (widget)
2521 "Here is where you edit the variable's value."
2522 (custom-load-widget widget
)
2523 (unless (widget-get widget
:custom-form
)
2524 (widget-put widget
:custom-form custom-variable-default-form
))
2525 (let* ((buttons (widget-get widget
:buttons
))
2526 (children (widget-get widget
:children
))
2527 (form (widget-get widget
:custom-form
))
2528 (symbol (widget-get widget
:value
))
2529 (tag (widget-get widget
:tag
))
2530 (type (custom-variable-type symbol
))
2531 (conv (widget-convert type
))
2532 (get (or (get symbol
'custom-get
) 'default-value
))
2533 (prefix (widget-get widget
:custom-prefix
))
2534 (last (widget-get widget
:custom-last
))
2535 (style (widget-get widget
:custom-style
))
2536 (value (let ((shown-value (widget-get widget
:shown-value
)))
2539 ((default-boundp symbol
)
2540 (funcall get symbol
))
2541 (t (widget-get conv
:value
)))))
2542 (state (or (widget-get widget
:custom-state
)
2543 (if (memq (custom-variable-state symbol value
)
2544 (widget-get widget
:hidden-states
))
2547 ;; If we don't know the state, see if we need to edit it in lisp form.
2549 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2550 (when (eq state
'unknown
)
2551 (unless (widget-apply conv
:match value
)
2552 (setq form
'mismatch
)))
2553 ;; Now we can create the child widget.
2554 (cond ((eq custom-buffer-style
'tree
)
2555 (insert prefix
(if last
" `--- " " |--- "))
2556 (push (widget-create-child-and-convert
2557 widget
'custom-browse-variable-tag
)
2559 (insert " " tag
"\n")
2560 (widget-put widget
:buttons buttons
))
2562 ;; Indicate hidden value.
2563 (push (widget-create-child-and-convert
2564 widget
'custom-visibility
2565 :help-echo
"Show the value of this option."
2570 :action
'custom-toggle-hide-variable
2574 (push (widget-create-child-and-convert
2577 :sample-face
'custom-variable-tag
2581 ((memq form
'(lisp mismatch
))
2582 (push (widget-create-child-and-convert
2583 widget
'custom-visibility
2584 :help-echo
"Hide the value of this option."
2589 :action
'custom-toggle-hide-variable
2593 ;; This used to try presenting the saved value or the
2594 ;; standard value, but it seems more intuitive to present
2595 ;; the current value (Bug#7600).
2596 (let* ((value (cond ((default-boundp symbol
)
2597 (custom-quote (funcall get symbol
)))
2599 (custom-quote (widget-get conv
:value
))))))
2600 (insert (symbol-name symbol
) ": ")
2601 (push (widget-create-child-and-convert
2603 :button-face
'custom-variable-button-face
2605 :tag
(symbol-name symbol
)
2611 (push (widget-create-child-and-convert
2612 widget
'custom-visibility
2613 :help-echo
"Hide or show this option."
2618 :action
'custom-toggle-hide-variable
2622 (let* ((format (widget-get type
:format
))
2623 tag-format value-format
)
2624 (unless (string-match ":" format
)
2625 (error "Bad format"))
2626 (setq tag-format
(substring format
0 (match-end 0)))
2627 (setq value-format
(substring format
(match-end 0)))
2628 (push (widget-create-child-and-convert
2631 :action
'custom-tag-action
2632 :help-echo
"Change value of this option."
2633 :mouse-down-action
'custom-tag-mouse-down-action
2634 :button-face
'custom-variable-button
2635 :sample-face
'custom-variable-tag
2638 (push (widget-create-child-and-convert
2640 :format value-format
2643 (unless (eq custom-buffer-style
'tree
)
2644 (unless (eq (preceding-char) ?
\n)
2645 (widget-insert "\n"))
2646 ;; Create the magic button.
2647 (unless (eq style
'simple
)
2648 (let ((magic (widget-create-child-and-convert
2649 widget
'custom-magic nil
)))
2650 (widget-put widget
:custom-magic magic
)
2651 (push magic buttons
)))
2652 (widget-put widget
:buttons buttons
)
2653 ;; Insert documentation.
2654 (widget-put widget
:documentation-indent
3)
2655 (unless (and (eq style
'simple
)
2657 (widget-add-documentation-string-button
2658 widget
:visibility-widget
'custom-visibility
))
2660 ;; The comment field
2661 (unless (eq state
'hidden
)
2662 (let* ((comment (get symbol
'variable-comment
))
2664 (widget-create-child-and-convert
2665 widget
'custom-comment
2667 :value
(or comment
""))))
2668 (widget-put widget
:comment-widget comment-widget
)
2669 ;; Don't push it !!! Custom assumes that the first child is the
2671 (setq children
(append children
(list comment-widget
)))))
2672 ;; Update the rest of the properties.
2673 (widget-put widget
:custom-form form
)
2674 (widget-put widget
:children children
)
2675 ;; Now update the state.
2676 (if (eq state
'hidden
)
2677 (widget-put widget
:custom-state state
)
2678 (custom-variable-state-set widget
))
2680 (unless (eq state
'hidden
)
2681 (when (eq (widget-get widget
:custom-level
) 1)
2682 (custom-add-parent-links widget
))
2683 (custom-add-see-also widget
)))))
2685 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore
)
2686 "Toggle the visibility of a `custom-variable' parent widget.
2687 By default, this signals an error if the parent has unsaved
2688 changes. If the parent has a `simple' :custom-style property,
2689 the present value is saved to its :shown-value property instead."
2690 (let ((widget (widget-get visibility-widget
:parent
)))
2691 (unless (eq (widget-type widget
) 'custom-variable
)
2692 (error "Invalid widget type"))
2693 (custom-load-widget widget
)
2694 (let ((state (widget-get widget
:custom-state
)))
2695 (if (eq state
'hidden
)
2696 (widget-put widget
:custom-state
'unknown
)
2697 ;; In normal interface, widget can't be hidden if modified.
2698 (when (memq state
'(invalid modified set
))
2699 (if (eq (widget-get widget
:custom-style
) 'simple
)
2700 (widget-put widget
:shown-value
2703 (widget-get widget
:children
)))))
2704 (error "There are unsaved changes")))
2705 (widget-put widget
:documentation-shown nil
)
2706 (widget-put widget
:custom-state
'hidden
))
2707 (custom-redraw widget
)
2710 (defun custom-tag-action (widget &rest args
)
2711 "Pass :action to first child of WIDGET's parent."
2712 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2715 (defun custom-tag-mouse-down-action (widget &rest args
)
2716 "Pass :mouse-down-action to first child of WIDGET's parent."
2717 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2718 :mouse-down-action args
))
2720 (defun custom-variable-state (symbol val
)
2721 "Return the state of SYMBOL if its value is VAL.
2722 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2723 Possible return values are `standard', `saved', `set', `themed',
2724 `changed', and `rogue'."
2725 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2726 (value (if (default-boundp symbol
)
2727 (funcall get symbol
)
2729 (comment (get symbol
'variable-comment
))
2732 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2734 (get symbol
'customized-variable-comment
))
2736 (if (condition-case nil
2737 (and (equal value
(eval (car tmp
)))
2738 (equal comment temp
))
2742 ((progn (setq tmp
(get symbol
'theme-value
))
2743 (setq temp
(get symbol
'saved-variable-comment
))
2745 (if (condition-case nil
2746 (and (equal comment temp
)
2749 (car (custom-variable-theme-value
2753 ((eq (caar tmp
) 'user
) 'saved
)
2754 ((eq (caar tmp
) 'changed
)
2755 (if (condition-case nil
2759 (car (get symbol
'standard-value
)))))
2761 ;; The value was originally set outside
2762 ;; custom, but it was set to the standard
2763 ;; value (probably an autoloaded defcustom).
2768 ((setq tmp
(get symbol
'standard-value
))
2769 (if (condition-case nil
2770 (and (equal value
(eval (car tmp
)))
2771 (equal comment nil
))
2777 (defun custom-variable-state-set (widget &optional state
)
2778 "Set the state of WIDGET to STATE.
2779 If STATE is nil, the value is computed by `custom-variable-state'."
2780 (widget-put widget
:custom-state
2781 (or state
(custom-variable-state (widget-value widget
)
2782 (widget-get widget
:value
)))))
2784 (defun custom-variable-standard-value (widget)
2785 (get (widget-value widget
) 'standard-value
))
2787 (defvar custom-variable-menu
2788 `(("Set for Current Session" custom-variable-set
2790 (eq (widget-get widget
:custom-state
) 'modified
)))
2791 ;; Note that in all the backquoted code in this file, we test
2792 ;; init-file-user rather than user-init-file. This is in case
2793 ;; cus-edit is loaded by something in site-start.el, because
2794 ;; user-init-file is not set at that stage.
2795 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2796 ,@(when (or custom-file init-file-user
)
2797 '(("Save for Future Sessions" custom-variable-save
2799 (memq (widget-get widget
:custom-state
)
2800 '(modified set changed rogue
))))))
2801 ("Undo Edits" custom-redraw
2803 (and (default-boundp (widget-value widget
))
2804 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2805 ("Revert This Session's Customization" custom-variable-reset-saved
2807 (memq (widget-get widget
:custom-state
)
2808 '(modified set changed rogue
))))
2809 ,@(when (or custom-file init-file-user
)
2810 '(("Erase Customization" custom-variable-reset-standard
2812 (and (get (widget-value widget
) 'standard-value
)
2813 (memq (widget-get widget
:custom-state
)
2814 '(modified set changed saved rogue
)))))))
2815 ("Set to Backup Value" custom-variable-reset-backup
2817 (get (widget-value widget
) 'backup-value
)))
2818 ("---" ignore ignore
)
2819 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2820 ("---" ignore ignore
)
2821 ("Show Current Value" custom-variable-edit
2823 (eq (widget-get widget
:custom-form
) 'lisp
)))
2824 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2826 (eq (widget-get widget
:custom-form
) 'edit
))))
2827 "Alist of actions for the `custom-variable' widget.
2828 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2829 the menu entry, ACTION is the function to call on the widget when the
2830 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2831 widget as an argument, and returns non-nil if ACTION is valid on that
2832 widget. If FILTER is nil, ACTION is always valid.")
2834 (defun custom-variable-action (widget &optional event
)
2835 "Show the menu for `custom-variable' WIDGET.
2836 Optional EVENT is the location for the menu."
2837 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2838 (custom-toggle-hide widget
)
2839 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2840 (custom-variable-state-set widget
))
2841 (custom-redraw-magic widget
)
2842 (let* ((completion-ignore-case t
)
2843 (answer (widget-choose (concat "Operation on "
2844 (custom-unlispify-tag-name
2845 (widget-get widget
:value
)))
2846 (custom-menu-filter custom-variable-menu
2850 (funcall answer widget
)))))
2852 (defun custom-variable-edit (widget)
2853 "Edit value of WIDGET."
2854 (widget-put widget
:custom-state
'unknown
)
2855 (widget-put widget
:custom-form
'edit
)
2856 (custom-redraw widget
))
2858 (defun custom-variable-edit-lisp (widget)
2859 "Edit the Lisp representation of the value of WIDGET."
2860 (widget-put widget
:custom-state
'unknown
)
2861 (widget-put widget
:custom-form
'lisp
)
2862 (custom-redraw widget
))
2864 (defun custom-variable-set (widget)
2865 "Set the current value for the variable being edited by WIDGET."
2866 (let* ((form (widget-get widget
:custom-form
))
2867 (state (widget-get widget
:custom-state
))
2868 (child (car (widget-get widget
:children
)))
2869 (symbol (widget-value widget
))
2870 (set (or (get symbol
'custom-set
) 'set-default
))
2871 (comment-widget (widget-get widget
:comment-widget
))
2872 (comment (widget-value comment-widget
))
2874 (cond ((eq state
'hidden
)
2875 (user-error "Cannot set hidden variable"))
2876 ((setq val
(widget-apply child
:validate
))
2877 (goto-char (widget-get val
:from
))
2878 (error "%s" (widget-get val
:error
)))
2879 ((memq form
'(lisp mismatch
))
2880 (when (equal comment
"")
2882 ;; Make the comment invisible by hand if it's empty
2883 (custom-comment-hide comment-widget
))
2884 (custom-variable-backup-value widget
)
2885 (custom-push-theme 'theme-value symbol
'user
2886 'set
(custom-quote (widget-value child
)))
2887 (funcall set symbol
(eval (setq val
(widget-value child
))))
2888 (put symbol
'customized-value
(list val
))
2889 (put symbol
'variable-comment comment
)
2890 (put symbol
'customized-variable-comment comment
))
2892 (when (equal comment
"")
2894 ;; Make the comment invisible by hand if it's empty
2895 (custom-comment-hide comment-widget
))
2896 (custom-variable-backup-value widget
)
2897 (custom-push-theme 'theme-value symbol
'user
2898 'set
(custom-quote (widget-value child
)))
2899 (funcall set symbol
(setq val
(widget-value child
)))
2900 (put symbol
'customized-value
(list (custom-quote val
)))
2901 (put symbol
'variable-comment comment
)
2902 (put symbol
'customized-variable-comment comment
)))
2903 (custom-variable-state-set widget
)
2904 (custom-redraw-magic widget
)))
2906 (defun custom-variable-mark-to-save (widget)
2907 "Set value and mark for saving the variable edited by WIDGET."
2908 (let* ((form (widget-get widget
:custom-form
))
2909 (state (widget-get widget
:custom-state
))
2910 (child (car (widget-get widget
:children
)))
2911 (symbol (widget-value widget
))
2912 (set (or (get symbol
'custom-set
) 'set-default
))
2913 (comment-widget (widget-get widget
:comment-widget
))
2914 (comment (widget-value comment-widget
))
2916 (cond ((eq state
'hidden
)
2917 (user-error "Cannot set hidden variable"))
2918 ((setq val
(widget-apply child
:validate
))
2919 (goto-char (widget-get val
:from
))
2920 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2921 ((memq form
'(lisp mismatch
))
2922 (when (equal comment
"")
2924 ;; Make the comment invisible by hand if it's empty
2925 (custom-comment-hide comment-widget
))
2926 (put symbol
'saved-value
(list (widget-value child
)))
2927 (custom-push-theme 'theme-value symbol
'user
2928 'set
(custom-quote (widget-value child
)))
2929 (funcall set symbol
(eval (widget-value child
)))
2930 (put symbol
'variable-comment comment
)
2931 (put symbol
'saved-variable-comment comment
))
2933 (when (equal comment
"")
2935 ;; Make the comment invisible by hand if it's empty
2936 (custom-comment-hide comment-widget
))
2937 (put symbol
'saved-value
2938 (list (custom-quote (widget-value child
))))
2939 (custom-push-theme 'theme-value symbol
'user
2940 'set
(custom-quote (widget-value child
)))
2941 (funcall set symbol
(widget-value child
))
2942 (put symbol
'variable-comment comment
)
2943 (put symbol
'saved-variable-comment comment
)))
2944 (put symbol
'customized-value nil
)
2945 (put symbol
'customized-variable-comment nil
)))
2947 (defsubst custom-variable-state-set-and-redraw
(widget)
2948 "Set state of variable widget WIDGET and redraw with current settings."
2949 (custom-variable-state-set widget
)
2950 (custom-redraw-magic widget
))
2952 (defun custom-variable-save (widget)
2953 "Save value of variable edited by widget WIDGET."
2954 (custom-variable-mark-to-save widget
)
2956 (custom-variable-state-set-and-redraw widget
))
2958 (defun custom-variable-reset-saved (widget)
2959 "Restore the value of the variable being edited by WIDGET.
2960 If there is a saved value, restore it; otherwise reset to the
2961 uncustomized (themed or standard) value.
2963 Update the widget to show that value. The value that was current
2964 before this operation becomes the backup value."
2965 (let* ((symbol (widget-value widget
))
2966 (saved-value (get symbol
'saved-value
))
2967 (comment (get symbol
'saved-variable-comment
)))
2968 (custom-variable-backup-value widget
)
2969 (if (not (or saved-value comment
))
2970 ;; If there is no saved value, remove the setting.
2971 (custom-push-theme 'theme-value symbol
'user
'reset
)
2972 ;; Otherwise, apply the saved value.
2973 (put symbol
'variable-comment comment
)
2974 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe saved-value
))
2976 (funcall (or (get symbol
'custom-set
) 'set-default
)
2977 symbol
(eval (car saved-value
)))))
2978 (put symbol
'customized-value nil
)
2979 (put symbol
'customized-variable-comment nil
)
2980 (widget-put widget
:custom-state
'unknown
)
2981 ;; This call will possibly make the comment invisible
2982 (custom-redraw widget
)))
2984 (defun custom-variable-mark-to-reset-standard (widget)
2985 "Mark to restore standard setting for the variable edited by widget WIDGET.
2986 If `custom-reset-standard-variables-list' is nil, save, reset and
2987 redraw the widget immediately."
2988 (let* ((symbol (widget-value widget
)))
2989 (if (get symbol
'standard-value
)
2990 (custom-variable-backup-value widget
)
2991 (user-error "No standard setting known for %S" symbol
))
2992 (put symbol
'variable-comment nil
)
2993 (put symbol
'customized-value nil
)
2994 (put symbol
'customized-variable-comment nil
)
2995 (custom-push-theme 'theme-value symbol
'user
'reset
)
2996 (custom-theme-recalc-variable symbol
)
2997 (if (and custom-reset-standard-variables-list
2998 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
3000 (put symbol
'saved-value nil
)
3001 (put symbol
'saved-variable-comment nil
)
3002 ;; Append this to `custom-reset-standard-variables-list' to
3003 ;; have `custom-reset-standard-save-and-update' save setting
3004 ;; to the file, update the widget's state, and redraw it.
3005 (setq custom-reset-standard-variables-list
3006 (cons widget custom-reset-standard-variables-list
)))
3007 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
3008 (put symbol
'saved-value nil
)
3009 (put symbol
'saved-variable-comment nil
)
3011 (widget-put widget
:custom-state
'unknown
)
3012 ;; This call will possibly make the comment invisible
3013 (custom-redraw widget
))))
3015 (defun custom-variable-reset-standard (widget)
3016 "Restore standard setting for the variable edited by WIDGET.
3017 This operation eliminates any saved setting for the variable,
3018 restoring it to the state of a variable that has never been customized.
3019 The value that was current before this operation
3020 becomes the backup value, so you can get it again."
3021 (let (custom-reset-standard-variables-list)
3022 (custom-variable-mark-to-reset-standard widget
)))
3024 (defun custom-variable-backup-value (widget)
3025 "Back up the current value for WIDGET's variable.
3026 The backup value is kept in the car of the `backup-value' property."
3027 (let* ((symbol (widget-value widget
))
3028 (get (or (get symbol
'custom-get
) 'default-value
))
3029 (type (custom-variable-type symbol
))
3030 (conv (widget-convert type
))
3031 (value (if (default-boundp symbol
)
3032 (funcall get symbol
)
3033 (widget-get conv
:value
))))
3034 (put symbol
'backup-value
(list value
))))
3036 (defun custom-variable-reset-backup (widget)
3037 "Restore the backup value for the variable being edited by WIDGET.
3038 The value that was current before this operation
3039 becomes the backup value, so you can use this operation repeatedly
3040 to switch between two values."
3041 (let* ((symbol (widget-value widget
))
3042 (set (or (get symbol
'custom-set
) 'set-default
))
3043 (value (get symbol
'backup-value
))
3044 (comment-widget (widget-get widget
:comment-widget
))
3045 (comment (widget-value comment-widget
)))
3048 (custom-variable-backup-value widget
)
3049 (custom-push-theme 'theme-value symbol
'user
'set value
)
3051 (funcall set symbol
(car value
))
3053 (user-error "No backup value for %s" symbol
))
3054 (put symbol
'customized-value
(list (custom-quote (car value
))))
3055 (put symbol
'variable-comment comment
)
3056 (put symbol
'customized-variable-comment comment
)
3057 (custom-variable-state-set widget
)
3058 ;; This call will possibly make the comment invisible
3059 (custom-redraw widget
)))
3061 ;;; The `custom-visibility' Widget
3063 (define-widget 'custom-visibility
'visibility
3064 "Show or hide a documentation string."
3065 :button-face
'custom-visibility
3066 :pressed-face
'custom-visibility
3067 :mouse-face
'highlight
3068 :pressed-face
'highlight
3072 (defface custom-visibility
3073 '((t :height
0.8 :inherit link
))
3074 "Face for the `custom-visibility' widget."
3076 :group
'custom-faces
)
3078 ;;; The `custom-face-edit' Widget.
3080 (define-widget 'custom-face-edit
'checklist
3081 "Widget for editing face attributes.
3082 The following properties have special meanings for this widget:
3084 :value is a plist of face attributes.
3086 :default-face-attributes, if non-nil, is a plist of defaults for
3087 face attributes (as specified by a `default' defface entry)."
3090 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3091 :value-to-internal
'custom-face-edit-fix-value
3092 :match
(lambda (widget value
)
3093 (widget-checklist-match widget
3094 (custom-face-edit-fix-value widget value
)))
3095 :value-create
'custom-face-edit-value-create
3096 :convert-widget
'custom-face-edit-convert-widget
3097 :args
(mapcar (lambda (att)
3098 (list 'group
:inline t
3099 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3100 (list 'const
:format
"" :value
(nth 0 att
))
3102 custom-face-attributes
))
3104 (defun custom-face-edit-value-create (widget)
3105 (let* ((alist (widget-checklist-match-find
3106 widget
(widget-get widget
:value
)))
3107 (args (widget-get widget
:args
))
3108 (show-all (widget-get widget
:show-all-attributes
))
3109 (buttons (widget-get widget
:buttons
))
3110 (defaults (widget-checklist-match-find
3112 (widget-get widget
:default-face-attributes
)))
3114 (unless (looking-back "^ *" (line-beginning-position))
3116 (insert-char ?\s
(widget-get widget
:extra-offset
))
3117 (if (or alist defaults show-all
)
3119 (setq entry
(or (assq prop alist
)
3120 (assq prop defaults
)))
3121 (if (or entry show-all
)
3122 (widget-checklist-add-item widget prop entry
)))
3123 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3124 (let ((indent (widget-get widget
:indent
)))
3125 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3126 (push (widget-create-child-and-convert
3128 :help-echo
"Show or hide all face attributes."
3129 :button-face
'custom-visibility
3130 :pressed-face
'custom-visibility
3131 :mouse-face
'highlight
3132 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3133 :on-glyph nil
:off-glyph nil
3135 :action
'custom-face-edit-value-visibility-action
3139 (widget-put widget
:buttons buttons
)
3140 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3142 (defun custom-face-edit-value-visibility-action (widget &rest _ignore
)
3143 ;; Toggle hiding of face attributes.
3144 (let ((parent (widget-get widget
:parent
)))
3145 (widget-put parent
:show-all-attributes
3146 (not (widget-get parent
:show-all-attributes
)))
3147 (custom-redraw parent
)))
3149 (defun custom-face-edit-fix-value (_widget value
)
3150 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3151 Also change :reverse-video to :inverse-video."
3152 (custom-fix-face-spec value
))
3154 (defun custom-face-edit-convert-widget (widget)
3155 "Convert :args as widget types in WIDGET."
3158 :args
(mapcar (lambda (arg)
3160 :deactivate
'custom-face-edit-deactivate
3161 :activate
'custom-face-edit-activate
3162 :delete
'custom-face-edit-delete
))
3163 (widget-get widget
:args
)))
3166 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3167 "Converted version of the `custom-face-edit' widget.")
3169 (defun custom-face-edit-deactivate (widget)
3170 "Make face widget WIDGET inactive for user modifications."
3171 (unless (widget-get widget
:inactive
)
3172 (let ((tag (custom-face-edit-attribute-tag widget
))
3173 (from (copy-marker (widget-get widget
:from
)))
3174 (value (widget-value widget
))
3175 (inhibit-read-only t
)
3176 (inhibit-modification-hooks t
))
3179 (widget-default-delete widget
)
3180 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3181 (widget-put widget
:inactive
3182 (cons value
(cons from
(- (point) from
))))))))
3184 (defun custom-face-edit-activate (widget)
3185 "Make face widget WIDGET active for user modifications."
3186 (let ((inactive (widget-get widget
:inactive
))
3187 (inhibit-read-only t
)
3188 (inhibit-modification-hooks t
))
3189 (when (consp inactive
)
3191 (goto-char (car (cdr inactive
)))
3192 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3193 (widget-put widget
:inactive nil
)
3194 (widget-apply widget
:create
)
3195 (widget-value-set widget
(car inactive
))
3198 (defun custom-face-edit-delete (widget)
3199 "Remove WIDGET from the buffer."
3200 (let ((inactive (widget-get widget
:inactive
))
3201 (inhibit-read-only t
)
3202 (inhibit-modification-hooks t
))
3204 ;; Widget is alive, we don't have to do anything special
3205 (widget-default-delete widget
)
3206 ;; WIDGET is already deleted because we did so to deactivate it;
3207 ;; now just get rid of the label we put in its place.
3208 (delete-region (car (cdr inactive
))
3209 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3210 (widget-put widget
:inactive nil
))))
3213 (defun custom-face-edit-attribute-tag (widget)
3214 "Return the first :tag property in WIDGET or one of its children."
3215 (let ((tag (widget-get widget
:tag
)))
3216 (or (and (not (equal tag
"")) tag
)
3217 (let ((children (widget-get widget
:children
)))
3218 (while (and (null tag
) children
)
3219 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3222 ;;; The `custom-display' Widget.
3224 (define-widget 'custom-display
'menu-choice
3225 "Select a display type."
3228 :help-echo
"Specify frames where the face attributes should be used."
3229 :args
'((const :tag
"all" t
)
3230 (const :tag
"defaults" default
)
3232 :tag
"specific display"
3235 :args
((group :sibling-args
(:help-echo
"\
3236 Only match the specified window systems.")
3237 (const :format
"Type: "
3239 (checklist :inline t
3242 :sibling-args
(:help-echo
"\
3243 The X11 Window System.")
3245 (const :format
"PM "
3246 :sibling-args
(:help-echo
"\
3247 OS/2 Presentation Manager.")
3249 (const :format
"W32 "
3250 :sibling-args
(:help-echo
"\
3253 (const :format
"NS "
3254 :sibling-args
(:help-echo
"\
3255 GNUstep or Macintosh OS Cocoa interface.")
3257 (const :format
"DOS "
3258 :sibling-args
(:help-echo
"\
3261 (const :format
"TTY%n"
3262 :sibling-args
(:help-echo
"\
3263 Plain text terminals.")
3265 (group :sibling-args
(:help-echo
"\
3266 Only match the frames with the specified color support.")
3267 (const :format
"Class: "
3269 (checklist :inline t
3271 (const :format
"Color "
3272 :sibling-args
(:help-echo
"\
3273 Match color frames.")
3275 (const :format
"Grayscale "
3276 :sibling-args
(:help-echo
"\
3277 Match grayscale frames.")
3279 (const :format
"Monochrome%n"
3280 :sibling-args
(:help-echo
"\
3281 Match frames with no color support.")
3283 (group :sibling-args
(:help-echo
"\
3284 The minimum number of colors the frame should support.")
3285 (const :format
"" min-colors
)
3286 (integer :tag
"Minimum number of colors" ))
3287 (group :sibling-args
(:help-echo
"\
3288 Only match frames with the specified intensity.")
3290 Background brightness: "
3292 (checklist :inline t
3294 (const :format
"Light "
3295 :sibling-args
(:help-echo
"\
3296 Match frames with light backgrounds.")
3298 (const :format
"Dark\n"
3299 :sibling-args
(:help-echo
"\
3300 Match frames with dark backgrounds.")
3302 (group :sibling-args
(:help-echo
"\
3303 Only match frames that support the specified face attributes.")
3304 (const :format
"Supports attributes:" supports
)
3305 (custom-face-edit :inline t
:format
"%n%v"))))))
3307 ;;; The `custom-face' Widget.
3309 (defface custom-face-tag
3310 '((t :inherit custom-variable-tag
))
3311 "Face used for face tags."
3312 :group
'custom-faces
)
3314 (defcustom custom-face-default-form
'selected
3315 "Default form of displaying face definition."
3316 :type
'(choice (const all
)
3319 :group
'custom-buffer
3322 (define-widget 'custom-face
'custom
3323 "Widget for customizing a face.
3324 The following properties have special meanings for this widget:
3326 :value is the face name (a symbol).
3328 :custom-form should be a symbol describing how to display and
3329 edit the face attributes---either `selected' (attributes for
3330 selected display only), `all' (all attributes), `lisp' (as a
3331 Lisp sexp), or `mismatch' (should not happen); if nil, use
3332 the return value of `custom-face-default-form'.
3334 :custom-style describes the widget interface style; nil is the
3335 default style, while `simple' means a simpler interface that
3336 inhibits the magic custom-state widget.
3338 :sample-indent, if non-nil, is the number of columns to which to
3339 indent the face sample (an integer).
3341 :shown-value, if non-nil, is the face spec to display as the value
3342 of the widget, instead of the current face spec."
3343 :sample-face
'custom-face-tag
3344 :help-echo
"Set or reset this face."
3345 :documentation-property
#'face-doc-string
3346 :value-create
'custom-face-value-create
3347 :action
'custom-face-action
3348 :custom-category
'face
3350 :custom-set
'custom-face-set
3351 :custom-mark-to-save
'custom-face-mark-to-save
3352 :custom-reset-current
'custom-redraw
3353 :custom-reset-saved
'custom-face-reset-saved
3354 :custom-reset-standard
'custom-face-reset-standard
3355 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3356 :custom-standard-value
'custom-face-standard-value
3357 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3358 :custom-menu
'custom-face-menu-create
)
3360 (define-widget 'custom-face-all
'editable-list
3361 "An editable list of display specifications and attributes."
3362 :entry-format
"%i %d %v"
3363 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3364 :append-button-args
'(:help-echo
"Append new display specification here.")
3365 :delete-button-args
'(:help-echo
"Delete this display specification.")
3366 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3368 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3369 "Converted version of the `custom-face-all' widget.")
3371 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3372 "Return a canonicalized version of SPEC.
3373 FILTER-INDEX is the index in the entry for each attribute in
3374 `custom-face-attributes' at which the appropriate filter function can be
3375 found, and DEFAULT-FILTER is the filter to apply for attributes that
3377 (mapcar (lambda (entry)
3378 ;; Filter a single face-spec entry
3379 (let ((tests (car entry
))
3381 ;; Handle both old- and new-style attribute syntax
3382 (if (listp (car (cdr entry
)))
3385 (filtered-attrs nil
))
3386 ;; Filter each face attribute
3387 (while unfiltered-attrs
3388 (let* ((attr (pop unfiltered-attrs
))
3389 (pre-filtered-value (pop unfiltered-attrs
))
3391 (or (nth filter-index
(assq attr custom-face-attributes
))
3395 (funcall filter pre-filtered-value
)
3396 pre-filtered-value
)))
3397 (push filtered-value filtered-attrs
)
3398 (push attr filtered-attrs
)))
3400 (list tests filtered-attrs
)))
3403 (defun custom-pre-filter-face-spec (spec)
3404 "Return SPEC changed as necessary for editing by the face customization widget.
3405 SPEC must be a full face spec."
3406 (custom-filter-face-spec spec
2))
3408 (defun custom-post-filter-face-spec (spec)
3409 "Return the customized SPEC in a form suitable for setting the face."
3410 (custom-filter-face-spec spec
3))
3412 (defun custom-face-widget-to-spec (widget)
3413 "Return a face spec corresponding to WIDGET.
3414 WIDGET should be a `custom-face' widget."
3415 (unless (eq (widget-type widget
) 'custom-face
)
3416 (error "Invalid widget"))
3417 (let ((child (car (widget-get widget
:children
))))
3418 (custom-post-filter-face-spec
3419 (if (eq (widget-type child
) 'custom-face-edit
)
3420 `((t ,(widget-value child
)))
3421 (widget-value child
)))))
3423 (defun custom-face-get-current-spec (face)
3424 (let ((spec (or (get face
'customized-face
)
3425 (get face
'saved-face
)
3426 (get face
'face-defface-spec
)
3427 ;; Attempt to construct it.
3428 `((t ,(custom-face-attributes-get
3429 face
(selected-frame)))))))
3430 ;; If the user has changed this face in some other way,
3431 ;; edit it as the user has specified it.
3432 (if (not (face-spec-match-p face spec
(selected-frame)))
3433 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3434 (custom-pre-filter-face-spec spec
)))
3436 (defun custom-toggle-hide-face (visibility-widget &rest _ignore
)
3437 "Toggle the visibility of a `custom-face' parent widget.
3438 By default, this signals an error if the parent has unsaved
3439 changes. If the parent has a `simple' :custom-style property,
3440 the present value is saved to its :shown-value property instead."
3441 (let ((widget (widget-get visibility-widget
:parent
)))
3442 (unless (eq (widget-type widget
) 'custom-face
)
3443 (error "Invalid widget type"))
3444 (custom-load-widget widget
)
3445 (let ((state (widget-get widget
:custom-state
)))
3446 (if (eq state
'hidden
)
3447 (widget-put widget
:custom-state
'unknown
)
3448 ;; In normal interface, widget can't be hidden if modified.
3449 (when (memq state
'(invalid modified set
))
3450 (if (eq (widget-get widget
:custom-style
) 'simple
)
3451 (widget-put widget
:shown-value
3452 (custom-face-widget-to-spec widget
))
3453 (error "There are unsaved changes")))
3454 (widget-put widget
:documentation-shown nil
)
3455 (widget-put widget
:custom-state
'hidden
))
3456 (custom-redraw widget
)
3459 (defun custom-face-value-create (widget)
3460 "Create a list of the display specifications for WIDGET."
3461 (let* ((buttons (widget-get widget
:buttons
))
3462 (symbol (widget-get widget
:value
))
3463 (tag (or (widget-get widget
:tag
)
3464 (prin1-to-string symbol
)))
3465 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3466 (style (widget-get widget
:custom-style
))
3469 (if (eq custom-buffer-style
'tree
)
3471 ;; Draw a tree-style `custom-face' widget
3473 (insert (widget-get widget
:custom-prefix
)
3474 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3475 (push (widget-create-child-and-convert
3476 widget
'custom-browse-face-tag
)
3478 (insert " " tag
"\n")
3479 (widget-put widget
:buttons buttons
))
3481 ;; Draw an ordinary `custom-face' widget
3482 (let ((opoint (point)))
3483 ;; Visibility indicator.
3484 (push (widget-create-child-and-convert
3485 widget
'custom-visibility
3486 :help-echo
"Hide or show this face."
3487 :on
"Hide" :off
"Show"
3488 :on-glyph
"down" :off-glyph
"right"
3489 :action
'custom-toggle-hide-face
3494 (widget-specify-sample widget opoint
(point)))
3496 (cond ((eq custom-buffer-style
'face
) " ")
3497 ((string-match-p "face\\'" tag
) ":")
3501 (let ((sample-indent (widget-get widget
:sample-indent
))
3502 (indent-tabs-mode nil
))
3504 (<= (current-column) sample-indent
)
3505 (indent-to-column sample-indent
)))
3506 (push (widget-create-child-and-convert
3509 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3510 (if spec
(face-spec-choose spec
) symbol
))
3516 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3517 (let ((magic (widget-create-child-and-convert
3518 widget
'custom-magic nil
)))
3519 (widget-put widget
:custom-magic magic
)
3520 (push magic buttons
)))
3523 (widget-put widget
:buttons buttons
)
3525 ;; Insert documentation.
3526 (unless (and hiddenp
(eq style
'simple
))
3527 (widget-put widget
:documentation-indent
3)
3528 (widget-add-documentation-string-button
3529 widget
:visibility-widget
'custom-visibility
)
3530 ;; The comment field
3532 (let* ((comment (get symbol
'face-comment
))
3534 (widget-create-child-and-convert
3535 widget
'custom-comment
3537 :value
(or comment
""))))
3538 (widget-put widget
:comment-widget comment-widget
)
3539 (push comment-widget children
))))
3542 (unless (eq (preceding-char) ?
\n)
3545 (custom-load-widget widget
)
3546 (unless (widget-get widget
:custom-form
)
3547 (widget-put widget
:custom-form custom-face-default-form
))
3549 (let* ((spec (or (widget-get widget
:shown-value
)
3550 (custom-face-get-current-spec symbol
)))
3551 (form (widget-get widget
:custom-form
))
3552 (indent (widget-get widget
:indent
))
3553 face-alist face-entry spec-default spec-match editor
)
3555 ;; Find a display in SPEC matching the selected display.
3556 ;; This will use the usual face customization interface.
3557 (setq face-alist spec
)
3558 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3559 (setq spec-default
(pop face-alist
)))
3561 (while (and face-alist
(listp face-alist
) (null spec-match
))
3562 (setq face-entry
(car face-alist
))
3563 (and (listp face-entry
)
3564 (face-spec-set-match-display (car face-entry
)
3566 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3567 (setq spec-match face-entry
))
3568 (setq face-alist
(cdr face-alist
)))
3570 ;; Insert the appropriate editing widget.
3573 ((and (eq form
'selected
)
3574 (or spec-match spec-default
))
3575 (when indent
(insert-char ?\s indent
))
3576 (widget-create-child-and-convert
3577 widget
'custom-face-edit
3578 :value
(cadr spec-match
)
3579 :default-face-attributes
(cadr spec-default
)))
3580 ((and (not (eq form
'lisp
))
3581 (widget-apply custom-face-all
:match spec
))
3582 (widget-create-child-and-convert
3583 widget
'custom-face-all
:value spec
))
3586 (insert-char ?\s indent
))
3587 (widget-create-child-and-convert
3588 widget
'sexp
:value spec
))))
3589 (custom-face-state-set widget
)
3590 (push editor children
)
3591 (widget-put widget
:children children
))))))
3593 (defvar custom-face-menu
3594 `(("Set for Current Session" custom-face-set
)
3595 ,@(when (or custom-file init-file-user
)
3596 '(("Save for Future Sessions" custom-face-save
)))
3597 ("Undo Edits" custom-redraw
3599 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3600 ("Revert This Session's Customization" custom-face-reset-saved
3602 (memq (widget-get widget
:custom-state
) '(modified set changed
))))
3603 ,@(when (or custom-file init-file-user
)
3604 '(("Erase Customization" custom-face-reset-standard
3606 (get (widget-value widget
) 'face-defface-spec
)))))
3607 ("---" ignore ignore
)
3608 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3609 ("---" ignore ignore
)
3610 ("For Current Display" custom-face-edit-selected
3612 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3613 ("For All Kinds of Displays" custom-face-edit-all
3615 (not (eq (widget-get widget
:custom-form
) 'all
))))
3616 ("Show Lisp Expression" custom-face-edit-lisp
3618 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3619 "Alist of actions for the `custom-face' widget.
3620 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3621 the menu entry, ACTION is the function to call on the widget when the
3622 menu is selected, and FILTER is a predicate which takes a `custom-face'
3623 widget as an argument, and returns non-nil if ACTION is valid on that
3624 widget. If FILTER is nil, ACTION is always valid.")
3626 (defun custom-face-edit-selected (widget)
3627 "Edit selected attributes of the value of WIDGET."
3628 (widget-put widget
:custom-state
'unknown
)
3629 (widget-put widget
:custom-form
'selected
)
3630 (custom-redraw widget
))
3632 (defun custom-face-edit-all (widget)
3633 "Edit all attributes of the value of WIDGET."
3634 (widget-put widget
:custom-state
'unknown
)
3635 (widget-put widget
:custom-form
'all
)
3636 (custom-redraw widget
))
3638 (defun custom-face-edit-lisp (widget)
3639 "Edit the Lisp representation of the value of WIDGET."
3640 (widget-put widget
:custom-state
'unknown
)
3641 (widget-put widget
:custom-form
'lisp
)
3642 (custom-redraw widget
))
3644 (defun custom-face-state (face)
3645 "Return the current state of the face FACE.
3646 This is one of `set', `saved', `changed', `themed', or `rogue'."
3647 (let* ((comment (get face
'face-comment
))
3650 ((or (get face
'customized-face
)
3651 (get face
'customized-face-comment
))
3652 (if (equal (get face
'customized-face-comment
) comment
)
3655 ((or (get face
'saved-face
)
3656 (get face
'saved-face-comment
))
3657 (cond ((not (equal (get face
'saved-face-comment
) comment
))
3659 ((eq 'user
(caar (get face
'theme-face
)))
3661 ((eq 'changed
(caar (get face
'theme-face
)))
3664 ((get face
'face-defface-spec
)
3665 (cond (comment 'changed
)
3666 ((get face
'theme-face
) 'themed
)
3669 ;; If the user called set-face-attribute to change the default for
3670 ;; new frames, this face is "set outside of Customize".
3671 (if (and (not (eq state
'rogue
))
3672 (get face
'face-modified
))
3676 (defun custom-face-state-set (widget)
3677 "Set the state of WIDGET."
3678 (widget-put widget
:custom-state
3679 (custom-face-state (widget-value widget
))))
3681 (defun custom-face-action (widget &optional event
)
3682 "Show the menu for `custom-face' WIDGET.
3683 Optional EVENT is the location for the menu."
3684 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3685 (custom-toggle-hide widget
)
3686 (let* ((completion-ignore-case t
)
3687 (symbol (widget-get widget
:value
))
3688 (answer (widget-choose (concat "Operation on "
3689 (custom-unlispify-tag-name symbol
))
3690 (custom-menu-filter custom-face-menu
3694 (funcall answer widget
)))))
3696 (defun custom-face-set (widget)
3697 "Make the face attributes in WIDGET take effect."
3698 (let* ((symbol (widget-value widget
))
3699 (value (custom-face-widget-to-spec widget
))
3700 (comment-widget (widget-get widget
:comment-widget
))
3701 (comment (widget-value comment-widget
)))
3702 (when (equal comment
"")
3704 ;; Make the comment invisible by hand if it's empty
3705 (custom-comment-hide comment-widget
))
3706 (custom-push-theme 'theme-face symbol
'user
'set value
)
3707 (face-spec-set symbol value
'customized-face
)
3708 (put symbol
'face-comment comment
)
3709 (put symbol
'customized-face-comment comment
)
3710 (custom-face-state-set widget
)
3711 (custom-redraw-magic widget
)))
3713 (defun custom-face-mark-to-save (widget)
3714 "Mark for saving the face edited by WIDGET."
3715 (let* ((symbol (widget-value widget
))
3716 (value (custom-face-widget-to-spec widget
))
3717 (comment-widget (widget-get widget
:comment-widget
))
3718 (comment (widget-value comment-widget
))
3719 (standard (eq (widget-get widget
:custom-state
) 'standard
)))
3720 (when (equal comment
"")
3722 ;; Make the comment invisible by hand if it's empty
3723 (custom-comment-hide comment-widget
))
3724 (custom-push-theme 'theme-face symbol
'user
'set value
)
3725 (face-spec-set symbol value
(if standard
'reset
'saved-face
))
3726 (put symbol
'face-comment comment
)
3727 (put symbol
'customized-face-comment nil
)
3728 (put symbol
'saved-face-comment comment
)))
3730 (defsubst custom-face-state-set-and-redraw
(widget)
3731 "Set state of face widget WIDGET and redraw with current settings."
3732 (custom-face-state-set widget
)
3733 (custom-redraw-magic widget
))
3735 (defun custom-face-save (widget)
3736 "Save the face edited by WIDGET."
3737 (custom-face-mark-to-save widget
)
3739 (custom-face-state-set-and-redraw widget
))
3741 ;; For backward compatibility.
3742 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3745 (defun custom-face-reset-saved (widget)
3746 "Restore WIDGET to the face's default attributes.
3747 If there is a saved face, restore it; otherwise reset to the
3748 uncustomized (themed or standard) face."
3749 (let* ((face (widget-value widget
))
3750 (child (car (widget-get widget
:children
)))
3751 (saved-face (get face
'saved-face
))
3752 (comment (get face
'saved-face-comment
))
3753 (comment-widget (widget-get widget
:comment-widget
)))
3754 (custom-push-theme 'theme-face face
'user
3755 (if saved-face
'set
'reset
)
3757 (face-spec-set face saved-face
'saved-face
)
3758 (put face
'face-comment comment
)
3759 (put face
'customized-face-comment nil
)
3760 (widget-value-set child saved-face
)
3761 ;; This call manages the comment visibility
3762 (widget-value-set comment-widget
(or comment
""))
3763 (custom-face-state-set widget
)
3764 (custom-redraw widget
)))
3766 (defun custom-face-standard-value (widget)
3767 (get (widget-value widget
) 'face-defface-spec
))
3769 (defun custom-face-mark-to-reset-standard (widget)
3770 "Restore widget WIDGET to the face's standard attribute values.
3771 If `custom-reset-standard-faces-list' is nil, save, reset and
3772 redraw the widget immediately."
3773 (let* ((symbol (widget-value widget
))
3774 (child (car (widget-get widget
:children
)))
3775 (value (get symbol
'face-defface-spec
))
3776 (comment-widget (widget-get widget
:comment-widget
)))
3778 (user-error "No standard setting for this face"))
3779 (custom-push-theme 'theme-face symbol
'user
'reset
)
3780 (face-spec-set symbol value
'reset
)
3781 (put symbol
'face-comment nil
)
3782 (put symbol
'customized-face-comment nil
)
3783 (if (and custom-reset-standard-faces-list
3784 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3787 (put symbol
'saved-face nil
)
3788 (put symbol
'saved-face-comment nil
)
3789 ;; Append this to `custom-reset-standard-faces-list' and have
3790 ;; `custom-reset-standard-save-and-update' save setting to the
3791 ;; file, update the widget's state, and redraw it.
3792 (setq custom-reset-standard-faces-list
3793 (cons widget custom-reset-standard-faces-list
)))
3794 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3795 (put symbol
'saved-face nil
)
3796 (put symbol
'saved-face-comment nil
)
3798 (widget-value-set child
3799 (custom-pre-filter-face-spec
3800 (list (list t
(custom-face-attributes-get
3802 ;; This call manages the comment visibility
3803 (widget-value-set comment-widget
"")
3804 (custom-face-state-set widget
)
3805 (custom-redraw-magic widget
))))
3807 (defun custom-face-reset-standard (widget)
3808 "Restore WIDGET to the face's standard attribute values.
3809 This operation eliminates any saved attributes for the face,
3810 restoring it to the state of a face that has never been customized."
3811 (let (custom-reset-standard-faces-list)
3812 (custom-face-mark-to-reset-standard widget
)))
3814 ;;; The `face' Widget.
3816 (defvar widget-face-prompt-value-history nil
3817 "History of input to `widget-face-prompt-value'.")
3819 (define-widget 'face
'symbol
3820 "A Lisp face name (with sample)."
3821 :format
"%{%t%}: (%{sample%}) %v"
3824 :sample-face-get
'widget-face-sample-face-get
3825 :notify
'widget-face-notify
3826 :match
(lambda (_widget value
) (facep value
))
3827 :completions
(apply-partially #'completion-table-with-predicate
3828 obarray
#'facep
'strict
)
3829 :prompt-match
'facep
3830 :prompt-history
'widget-face-prompt-value-history
3831 :validate
(lambda (widget)
3832 (unless (facep (widget-value widget
))
3834 :error
(format "Invalid face: %S"
3835 (widget-value widget
)))
3838 (defun widget-face-sample-face-get (widget)
3839 (let ((value (widget-value widget
)))
3844 (defun widget-face-notify (widget child
&optional event
)
3845 "Update the sample, and notify the parent."
3846 (overlay-put (widget-get widget
:sample-overlay
)
3847 'face
(widget-apply widget
:sample-face-get
))
3848 (widget-default-notify widget child event
))
3851 ;;; The `hook' Widget.
3853 (define-widget 'hook
'list
3854 "An Emacs Lisp hook."
3855 :value-to-internal
(lambda (_widget value
)
3856 (if (and value
(symbolp value
))
3859 :match
(lambda (widget value
)
3861 (widget-group-match widget value
)))
3862 ;; Avoid adding undefined functions to the hook, especially for
3863 ;; things like `find-file-hook' or even more basic ones, to avoid
3865 :set
(lambda (symbol value
)
3868 (add-hook symbol elt
))))
3869 :convert-widget
'custom-hook-convert-widget
3872 (defun custom-hook-convert-widget (widget)
3873 ;; Handle `:options'.
3874 (let* ((options (widget-get widget
:options
))
3875 (other `(editable-list :inline t
3876 :entry-format
"%i %d%v"
3877 (function :format
" %v")))
3879 (list `(checklist :inline t
3880 ,@(mapcar (lambda (entry)
3881 `(function-item ,entry
))
3885 (widget-put widget
:args args
)
3888 ;;; The `custom-group-link' Widget.
3890 (define-widget 'custom-group-link
'link
3891 "Show parent in other window when activated."
3892 :button-face
'custom-link
3893 :mouse-face
'highlight
3894 :pressed-face
'highlight
3895 :help-echo
"Create customization buffer for this group."
3896 :keymap custom-mode-link-map
3897 :follow-link
'mouse-face
3898 :action
'custom-group-link-action
)
3900 (defun custom-group-link-action (widget &rest _ignore
)
3901 (customize-group (widget-value widget
)))
3903 ;;; The `custom-group' Widget.
3905 (defcustom custom-group-tag-faces nil
3906 "Face used for group tags.
3907 The first member is used for level 1 groups, the second for level 2,
3908 and so forth. The remaining group tags are shown with `custom-group-tag'."
3909 :type
'(repeat face
)
3910 :group
'custom-faces
)
3912 (defface custom-group-tag-1
3913 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3914 (((class color
) (background dark
)) :foreground
"pink")
3915 (((min-colors 88) (class color
) (background light
)) :foreground
"red1")
3916 (((class color
) (background light
)) :foreground
"red"))
3917 "Face for group tags."
3918 :group
'custom-faces
)
3920 (defface custom-group-tag
3921 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3922 (((class color
) (background dark
)) :foreground
"light blue")
3923 (((min-colors 88) (class color
) (background light
)) :foreground
"blue1")
3924 (((class color
) (background light
)) :foreground
"blue")
3926 "Face for low level group tags."
3927 :group
'custom-faces
)
3929 (defface custom-group-subtitle
3931 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3932 :group
'custom-faces
)
3934 (defvar custom-group-doc-align-col
20)
3936 (define-widget 'custom-group
'custom
3939 :sample-face-get
'custom-group-sample-face-get
3940 :documentation-property
'group-documentation
3941 :help-echo
"Set or reset all members of this group."
3942 :value-create
'custom-group-value-create
3943 :action
'custom-group-action
3944 :custom-category
'group
3945 :custom-set
'custom-group-set
3946 :custom-mark-to-save
'custom-group-mark-to-save
3947 :custom-reset-current
'custom-group-reset-current
3948 :custom-reset-saved
'custom-group-reset-saved
3949 :custom-reset-standard
'custom-group-reset-standard
3950 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3951 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3952 :custom-menu
'custom-group-menu-create
)
3954 (defun custom-group-sample-face-get (widget)
3955 ;; Use :sample-face.
3956 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3959 (define-widget 'custom-group-visibility
'visibility
3960 "An indicator and manipulator for hidden group contents."
3961 :create
'custom-group-visibility-create
)
3963 (defun custom-group-visibility-create (widget)
3964 (let ((visible (widget-value widget
)))
3966 (insert "--------")))
3967 (widget-default-create widget
))
3969 (defun custom-group-members (symbol groups-only
)
3970 "Return SYMBOL's custom group members.
3971 If GROUPS-ONLY is non-nil, return only those members that are groups."
3972 (if (not groups-only
)
3973 (get symbol
'custom-group
)
3975 (dolist (entry (get symbol
'custom-group
))
3976 (when (eq (nth 1 entry
) 'custom-group
)
3977 (push entry members
)))
3978 (nreverse members
))))
3980 (defun custom-group-value-create (widget)
3981 "Insert a customize group for WIDGET in the current buffer."
3982 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3983 (custom-load-widget widget
))
3984 (let* ((state (widget-get widget
:custom-state
))
3985 (level (widget-get widget
:custom-level
))
3986 ;; (indent (widget-get widget :indent))
3987 (prefix (widget-get widget
:custom-prefix
))
3988 (buttons (widget-get widget
:buttons
))
3989 (tag (substitute-command-keys (widget-get widget
:tag
)))
3990 (symbol (widget-value widget
))
3991 (members (custom-group-members symbol
3992 (and (eq custom-buffer-style
'tree
)
3993 custom-browse-only-groups
)))
3994 (doc (substitute-command-keys (widget-docstring widget
))))
3995 (cond ((and (eq custom-buffer-style
'tree
)
3997 (or members
(custom-unloaded-widget-p widget
)))
3998 (custom-browse-insert-prefix prefix
)
3999 (push (widget-create-child-and-convert
4000 widget
'custom-browse-visibility
4004 (push (widget-create-child-and-convert
4005 widget
'custom-browse-group-tag
)
4007 (insert " " tag
"\n")
4008 (widget-put widget
:buttons buttons
))
4009 ((and (eq custom-buffer-style
'tree
)
4010 (zerop (length members
)))
4011 (custom-browse-insert-prefix prefix
)
4013 (push (widget-create-child-and-convert
4014 widget
'custom-browse-group-tag
)
4016 (insert " " tag
"\n")
4017 (widget-put widget
:buttons buttons
))
4018 ((eq custom-buffer-style
'tree
)
4019 (custom-browse-insert-prefix prefix
)
4020 (if (zerop (length members
))
4022 (custom-browse-insert-prefix prefix
)
4024 ;; (widget-glyph-insert nil "[ ]" "empty")
4025 ;; (widget-glyph-insert nil "-- " "horizontal")
4026 (push (widget-create-child-and-convert
4027 widget
'custom-browse-group-tag
)
4029 (insert " " tag
"\n")
4030 (widget-put widget
:buttons buttons
))
4031 (push (widget-create-child-and-convert
4032 widget
'custom-browse-visibility
4033 ;; :tag-glyph "minus"
4037 ;; (widget-glyph-insert nil "-\\ " "top")
4038 (push (widget-create-child-and-convert
4039 widget
'custom-browse-group-tag
)
4041 (insert " " tag
"\n")
4042 (widget-put widget
:buttons buttons
)
4043 (message "Creating group...")
4044 (let* ((members (custom-sort-items
4046 ;; Never sort the top-level custom group.
4047 (unless (eq symbol
'emacs
)
4048 custom-browse-sort-alphabetically
)
4049 custom-browse-order-groups
))
4050 (prefixes (widget-get widget
:custom-prefixes
))
4051 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4052 (extra-prefix (if (widget-get widget
:custom-last
)
4055 (prefix (concat prefix extra-prefix
))
4058 (setq entry
(car members
)
4059 members
(cdr members
))
4060 (push (widget-create-child-and-convert
4061 widget
(nth 1 entry
)
4063 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4064 :custom-prefixes custom-prefix-list
4065 :custom-level
(1+ level
)
4066 :custom-last
(null members
)
4067 :value
(nth 0 entry
)
4068 :custom-prefix prefix
)
4070 (widget-put widget
:children
(reverse children
)))
4071 (message "Creating group...done")))
4074 ;; Create level indicator.
4076 (if (eq custom-buffer-style
'links
)
4077 (push (widget-create-child-and-convert
4078 widget
'custom-group-link
4082 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4084 (push (widget-create-child-and-convert
4085 widget
'custom-group-visibility
4086 :help-echo
"Show members of this group."
4087 :action
'custom-toggle-parent
4088 (not (eq state
'hidden
)))
4090 (if (>= (current-column) custom-group-doc-align-col
)
4092 ;; Create magic button.
4093 (let ((magic (widget-create-child-and-convert
4094 widget
'custom-magic nil
)))
4095 (widget-put widget
:custom-magic magic
)
4096 (push magic buttons
))
4098 (widget-put widget
:buttons buttons
)
4099 ;; Insert documentation.
4100 (if (and (eq custom-buffer-style
'links
) (> level
1))
4101 (widget-put widget
:documentation-indent
4102 custom-group-doc-align-col
))
4103 (widget-add-documentation-string-button
4104 widget
:visibility-widget
'custom-visibility
))
4108 ;; Draw a horizontal line (this works for both graphical
4109 ;; and text displays):
4112 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4113 (overlay-put (make-overlay p
(1+ p
))
4115 (propertize "\n" 'face
'(:underline t
)
4116 'display
'(space :align-to
999))))
4118 ;; Add parent groups references above the group.
4120 (if (custom-add-parent-links widget
"Parent groups:")
4122 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4124 (let ((start (point)))
4125 (insert tag
" group: ")
4126 (widget-specify-sample widget start
(point)))
4129 (insert " Group definition missing. "))
4130 ((< (length doc
) 50)
4132 ;; Create visibility indicator.
4133 (unless (eq custom-buffer-style
'links
)
4135 (push (widget-create-child-and-convert
4137 :help-echo
"Hide members of this group."
4138 :action
'custom-toggle-parent
4139 (not (eq state
'hidden
)))
4143 ;; Create magic button.
4144 (let ((magic (widget-create-child-and-convert
4145 widget
'custom-magic
4148 (widget-put widget
:custom-magic magic
)
4149 (push magic buttons
))
4151 (widget-put widget
:buttons buttons
)
4152 ;; Insert documentation.
4153 (when (and doc
(>= (length doc
) 50))
4154 (widget-add-documentation-string-button
4155 widget
:visibility-widget
'custom-visibility
))
4158 (if nil
;;; This should test that the buffer
4159 ;;; was not made to display a group.
4161 (insert-char ?\s custom-buffer-indent
)
4162 (custom-add-parent-links widget
)))
4163 (custom-add-see-also widget
4164 (make-string (* custom-buffer-indent level
)
4167 (message "Creating group...")
4168 (let* ((members (custom-sort-items
4170 ;; Never sort the top-level custom group.
4171 (unless (eq symbol
'emacs
)
4172 custom-buffer-sort-alphabetically
)
4173 custom-buffer-order-groups
))
4174 (prefixes (widget-get widget
:custom-prefixes
))
4175 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4176 (len (length members
))
4178 (reporter (make-progress-reporter
4179 "Creating group entries..." 0 len
))
4180 (have-subtitle (and (not (eq symbol
'emacs
))
4181 (eq custom-buffer-order-groups
'last
)))
4185 (dolist (entry members
)
4186 (unless (eq prev-type
'custom-group
)
4187 (widget-insert "\n"))
4188 (progress-reporter-update reporter
(setq count
(1+ count
)))
4189 (let ((sym (nth 0 entry
))
4190 (type (nth 1 entry
)))
4191 (when (and have-subtitle
(eq type
'custom-group
))
4192 (setq have-subtitle nil
)
4194 (propertize "Subgroups:\n" 'face
'custom-group-subtitle
)))
4195 (setq prev-type type
)
4196 (push (widget-create-child-and-convert
4199 :tag
(custom-unlispify-tag-name sym
)
4200 :custom-prefixes custom-prefix-list
4201 :custom-level
(1+ level
)
4204 (unless (eq (preceding-char) ?
\n)
4205 (widget-insert "\n"))))
4207 (setq children
(nreverse children
))
4208 (mapc 'custom-magic-reset children
)
4209 (widget-put widget
:children children
)
4210 (custom-group-state-update widget
)
4211 (progress-reporter-done reporter
))
4213 (let ((p (1+ (point))))
4215 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4216 (overlay-put (make-overlay p
(1+ p
))
4218 (propertize "\n" 'face
'(:underline t
)
4219 'display
'(space :align-to
999))))))))
4221 (defvar custom-group-menu
4222 `(("Set for Current Session" custom-group-set
4224 (eq (widget-get widget
:custom-state
) 'modified
)))
4225 ,@(when (or custom-file init-file-user
)
4226 '(("Save for Future Sessions" custom-group-save
4228 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4229 ("Undo Edits" custom-group-reset-current
4231 (memq (widget-get widget
:custom-state
) '(modified))))
4232 ("Revert This Session's Customizations" custom-group-reset-saved
4234 (memq (widget-get widget
:custom-state
) '(modified set
))))
4235 ,@(when (or custom-file init-file-user
)
4236 '(("Erase Customization" custom-group-reset-standard
4238 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4239 "Alist of actions for the `custom-group' widget.
4240 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4241 the menu entry, ACTION is the function to call on the widget when the
4242 menu is selected, and FILTER is a predicate which takes a `custom-group'
4243 widget as an argument, and returns non-nil if ACTION is valid on that
4244 widget. If FILTER is nil, ACTION is always valid.")
4246 (defun custom-group-action (widget &optional event
)
4247 "Show the menu for `custom-group' WIDGET.
4248 Optional EVENT is the location for the menu."
4249 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4250 (custom-toggle-hide widget
)
4251 (let* ((completion-ignore-case t
)
4252 (answer (widget-choose (concat "Operation on "
4253 (custom-unlispify-tag-name
4254 (widget-get widget
:value
)))
4255 (custom-menu-filter custom-group-menu
4259 (funcall answer widget
)))))
4261 (defun custom-group-set (widget)
4262 "Set changes in all modified group members."
4263 (dolist (child (widget-get widget
:children
))
4264 (when (eq (widget-get child
:custom-state
) 'modified
)
4265 (widget-apply child
:custom-set
))))
4267 (defun custom-group-mark-to-save (widget)
4268 "Mark all modified group members for saving."
4269 (dolist (child (widget-get widget
:children
))
4270 (when (memq (widget-get child
:custom-state
) '(modified set
))
4271 (widget-apply child
:custom-mark-to-save
))))
4273 (defsubst custom-group-state-set-and-redraw
(widget)
4274 "Set state of group widget WIDGET and redraw with current settings."
4275 (dolist (child (widget-get widget
:children
))
4276 (when (memq (widget-get child
:custom-state
) '(modified set
))
4277 (widget-apply child
:custom-state-set-and-redraw
))))
4279 (defun custom-group-save (widget)
4280 "Save all modified group members."
4281 (custom-group-mark-to-save widget
)
4283 (custom-group-state-set-and-redraw widget
))
4285 (defun custom-group-reset-current (widget)
4286 "Reset all modified group members."
4287 (dolist (child (widget-get widget
:children
))
4288 (when (eq (widget-get child
:custom-state
) 'modified
)
4289 (widget-apply child
:custom-reset-current
))))
4291 (defun custom-group-reset-saved (widget)
4292 "Reset all modified or set group members."
4293 (dolist (child (widget-get widget
:children
))
4294 (when (memq (widget-get child
:custom-state
) '(modified set
))
4295 (widget-apply child
:custom-reset-saved
))))
4297 (defun custom-group-reset-standard (widget)
4298 "Reset all modified, set, or saved group members."
4299 (let ((custom-reset-standard-variables-list '(t))
4300 (custom-reset-standard-faces-list '(t)))
4301 (custom-group-mark-to-reset-standard widget
)
4302 (custom-reset-standard-save-and-update)))
4304 (defun custom-group-mark-to-reset-standard (widget)
4305 "Mark to reset all modified, set, or saved group members."
4306 (dolist (child (widget-get widget
:children
))
4307 (when (memq (widget-get child
:custom-state
)
4308 '(modified set saved
))
4309 (widget-apply child
:custom-mark-to-reset-standard
))))
4311 (defun custom-group-state-update (widget)
4313 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4314 (let* ((children (widget-get widget
:children
))
4315 (states (mapcar (lambda (child)
4316 (widget-get child
:custom-state
))
4318 (magics custom-magic-alist
)
4321 (let ((magic (car (car magics
))))
4322 (if (and (not (eq magic
'hidden
))
4323 (memq magic states
))
4326 (setq magics
(cdr magics
)))))
4327 (widget-put widget
:custom-state found
)))
4328 (custom-magic-reset widget
))
4330 ;;; Reading and writing the custom file.
4333 (defcustom custom-file nil
4334 "File used for storing customization information.
4335 The default is nil, which means to use your init file
4336 as specified by `user-init-file'. If the value is not nil,
4337 it should be an absolute file name.
4339 You can set this option through Custom, if you carefully read the
4340 last paragraph below. However, usually it is simpler to write
4341 something like the following in your init file:
4343 \(setq custom-file \"~/.emacs-custom.el\")
4346 Note that both lines are necessary: the first line tells Custom to
4347 save all customizations in this file, but does not load it.
4349 When you change this variable outside Custom, look in the
4350 previous custom file (usually your init file) for the
4351 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4352 and copy them (whichever ones you find) to the new custom file.
4353 This will preserve your existing customizations.
4355 If you save this option using Custom, Custom will write all
4356 currently saved customizations, including the new one for this
4357 option itself, into the file you specify, overwriting any
4358 `custom-set-variables' and `custom-set-faces' forms already
4359 present in that file. It will not delete any customizations from
4360 the old custom file. You should do that manually if that is what you
4361 want. You also have to put something like `(load \"CUSTOM-FILE\")
4362 in your init file, where CUSTOM-FILE is the actual name of the
4363 file. Otherwise, Emacs will not load the file when it starts up,
4364 and hence will not set `custom-file' to that file either."
4365 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4366 (file :format
"%t:%v%d"
4368 "Please read entire docstring below before setting \
4369 this through Custom.
4370 Click on \"More\" (or position point there and press RETURN)
4371 if only the first line of the docstring is shown."))
4374 (defun custom-file (&optional no-error
)
4375 "Return the file name for saving customizations."
4376 (if (or (null user-init-file
)
4377 (and (null custom-file
) init-file-had-error
))
4378 ;; Started with -q, i.e. the file containing Custom settings
4379 ;; hasn't been read. Saving settings there won't make much
4383 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4384 (file-chase-links (or custom-file user-init-file
))))
4386 ;; If recentf-mode is non-nil, this is defined.
4387 (declare-function recentf-expand-file-name
"recentf" (name))
4390 (defun custom-save-all ()
4391 "Save all customizations in `custom-file'."
4392 (when (and (null custom-file
) init-file-had-error
)
4393 (error "Cannot save customizations; init file was not fully loaded"))
4394 (let* ((filename (custom-file))
4399 (recentf-expand-file-name (custom-file)))
4402 (old-buffer (find-buffer-visiting filename
))
4405 (with-current-buffer (let ((find-file-visit-truename t
))
4407 (let ((delay-mode-hooks t
))
4408 (find-file-noselect filename
))))
4409 ;; We'll save using file-precious-flag, so avoid destroying
4410 ;; symlinks. (If we're not already visiting the buffer, this is
4411 ;; handled by find-file-visit-truename, above.)
4413 (setq old-buffer-name
(buffer-file-name))
4414 (set-visited-file-name (file-chase-links filename
)))
4416 (unless (eq major-mode
'emacs-lisp-mode
)
4417 (delay-mode-hooks (emacs-lisp-mode)))
4418 (let ((inhibit-read-only t
)
4421 (custom-save-variables)
4422 (custom-save-faces))
4423 (let ((file-precious-flag t
))
4427 (set-visited-file-name old-buffer-name
)
4428 (set-buffer-modified-p nil
))
4429 (kill-buffer (current-buffer))))))
4432 (defun customize-save-customized ()
4433 "Save all user options which have been set in this session."
4435 (mapatoms (lambda (symbol)
4436 (let ((face (get symbol
'customized-face
))
4437 (value (get symbol
'customized-value
))
4438 (face-comment (get symbol
'customized-face-comment
))
4440 (get symbol
'customized-variable-comment
)))
4442 (put symbol
'saved-face face
)
4443 (custom-push-theme 'theme-face symbol
'user
'set value
)
4444 (put symbol
'customized-face nil
))
4446 (put symbol
'saved-value value
)
4447 (custom-push-theme 'theme-value symbol
'user
'set value
)
4448 (put symbol
'customized-value nil
))
4449 (when variable-comment
4450 (put symbol
'saved-variable-comment variable-comment
)
4451 (put symbol
'customized-variable-comment nil
))
4453 (put symbol
'saved-face-comment face-comment
)
4454 (put symbol
'customized-face-comment nil
)))))
4455 ;; We really should update all custom buffers here.
4458 ;; Editing the custom file contents in a buffer.
4460 (defun custom-save-delete (symbol)
4461 "Delete all calls to SYMBOL from the contents of the current buffer.
4462 Leave point at the old location of the first such call,
4463 or (if there were none) at the end of the buffer.
4465 This function does not save the buffer."
4466 (goto-char (point-min))
4467 ;; Skip all whitespace and comments.
4468 (while (forward-comment 1))
4470 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4473 (while t
;; We exit this loop only via throw.
4474 ;; Skip all whitespace and comments.
4475 (while (forward-comment 1))
4476 (let ((start (point))
4477 (sexp (condition-case nil
4478 (read (current-buffer))
4479 (end-of-file (throw 'found nil
)))))
4480 (when (and (listp sexp
)
4481 (eq (car sexp
) symbol
))
4482 (delete-region start
(point))
4484 (setq first
(point)))))))
4487 ;; Move in front of local variables, otherwise long Custom
4488 ;; entries would make them ineffective.
4489 (let ((pos (point-max))
4490 (case-fold-search t
))
4492 (goto-char (point-max))
4493 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4495 (when (search-forward "Local Variables:" nil t
)
4496 (setq pos
(line-beginning-position))))
4499 (defvar sort-fold-case
) ; defined in sort.el
4501 (defun custom-save-variables ()
4502 "Save all customized variables in `custom-file'."
4504 (custom-save-delete 'custom-set-variables
)
4505 (let ((standard-output (current-buffer))
4506 (saved-list (make-list 1 0))
4508 ;; First create a sorted list of saved variables.
4511 (if (and (get symbol
'saved-value
)
4512 ;; ignore theme values
4513 (or (null (get symbol
'theme-value
))
4514 (eq 'user
(caar (get symbol
'theme-value
)))))
4515 (nconc saved-list
(list symbol
)))))
4516 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4519 (princ "(custom-set-variables
4520 ;; custom-set-variables was added by Custom.
4521 ;; If you edit it by hand, you could mess it up, so be careful.
4522 ;; Your init file should contain only one such instance.
4523 ;; If there is more than one, they won't work right.\n")
4524 (dolist (symbol saved-list
)
4525 (let ((spec (car-safe (get symbol
'theme-value
)))
4526 (value (get symbol
'saved-value
))
4527 (requests (get symbol
'custom-requests
))
4528 (now (and (not (custom-variable-p symbol
))
4530 (eq (get symbol
'force-value
)
4532 (comment (get symbol
'saved-variable-comment
)))
4533 ;; Check REQUESTS for validity.
4534 (dolist (request requests
)
4535 (when (and (symbolp request
) (not (featurep request
)))
4536 (message "Unknown requested feature: %s" request
)
4537 (setq requests
(delq request requests
))))
4538 ;; Is there anything customized about this variable?
4539 (when (or (and spec
(eq (car spec
) 'user
))
4541 (and (null spec
) (get symbol
'saved-value
)))
4542 ;; Output an element for this variable.
4543 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4544 ;; SYMBOL is the variable name.
4545 ;; VALUE-FORM is an expression to return the customized value.
4546 ;; NOW if non-nil means always set the variable immediately
4547 ;; when the customizations are reloaded. This is used
4548 ;; for rogue variables
4549 ;; REQUESTS is a list of packages to load before setting the
4550 ;; variable. Each element of it will be passed to `require'.
4551 ;; COMMENT is whatever comment the user has specified
4552 ;; with the customize facility.
4558 (let ((val (prin1-to-string (car value
))))
4559 (if (< (length val
) 60)
4561 (newline-and-indent)
4562 (let ((beginning-of-val (point)))
4565 (goto-char beginning-of-val
)
4566 (indent-pp-sexp 1)))))
4567 (when (or now requests comment
)
4570 (when (or requests comment
)
4580 (unless (looking-at-p "\n")
4583 (defun custom-save-faces ()
4584 "Save all customized faces in `custom-file'."
4586 (custom-save-delete 'custom-reset-faces
)
4587 (custom-save-delete 'custom-set-faces
)
4588 (let ((standard-output (current-buffer))
4589 (saved-list (make-list 1 0))
4591 ;; First create a sorted list of saved faces.
4594 (if (and (get symbol
'saved-face
)
4595 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4596 (nconc saved-list
(list symbol
)))))
4597 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4598 ;; The default face must be first, since it affects the others.
4599 (if (memq 'default saved-list
)
4600 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4603 (princ "(custom-set-faces
4604 ;; custom-set-faces was added by Custom.
4605 ;; If you edit it by hand, you could mess it up, so be careful.
4606 ;; Your init file should contain only one such instance.
4607 ;; If there is more than one, they won't work right.\n")
4608 (dolist (symbol saved-list
)
4609 (let ((spec (car-safe (get symbol
'theme-face
)))
4610 (value (get symbol
'saved-face
))
4611 (now (not (or (get symbol
'face-defface-spec
)
4612 (and (not (custom-facep symbol
))
4613 (not (get symbol
'force-face
))))))
4614 (comment (get symbol
'saved-face-comment
)))
4615 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4617 (and (null spec
) (get symbol
'saved-face
)))
4618 ;; Don't print default face here.
4625 (when (or now comment
)
4635 (unless (looking-at-p "\n")
4638 ;;; The Customize Menu.
4642 (defcustom custom-menu-nesting
2
4643 "Maximum nesting in custom menus."
4645 :group
'custom-menu
)
4647 (defun custom-face-menu-create (_widget symbol
)
4648 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4649 (vector (custom-unlispify-menu-entry symbol
)
4650 `(customize-face ',symbol
)
4653 (defun custom-variable-menu-create (_widget symbol
)
4654 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4655 (let ((type (get symbol
'custom-type
)))
4656 (unless (listp type
)
4657 (setq type
(list type
)))
4658 (if (and type
(widget-get type
:custom-menu
))
4659 (widget-apply type
:custom-menu symbol
)
4660 (vector (custom-unlispify-menu-entry symbol
)
4661 `(customize-variable ',symbol
)
4664 ;; Add checkboxes to boolean variable entries.
4665 (widget-put (get 'boolean
'widget-type
)
4666 :custom-menu
(lambda (_widget symbol
)
4667 (vector (custom-unlispify-menu-entry symbol
)
4668 `(customize-variable ',symbol
)
4670 ':selected symbol
)))
4672 (defun custom-group-menu-create (_widget symbol
)
4673 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4674 `( ,(custom-unlispify-menu-entry symbol t
)
4675 :filter
(lambda (&rest junk
)
4676 (let* ((menu (custom-menu-create ',symbol
)))
4677 (if (consp menu
) (cdr menu
) menu
)))))
4680 (defun custom-menu-create (symbol)
4681 "Create menu for customization group SYMBOL.
4682 The menu is in a format applicable to `easy-menu-define'."
4683 (let* ((deactivate-mark nil
)
4684 (item (vector (custom-unlispify-menu-entry symbol
)
4685 `(customize-group ',symbol
)
4687 (if (and (or (not (boundp 'custom-menu-nesting
))
4688 (>= custom-menu-nesting
0))
4690 (custom-load-symbol symbol
)
4691 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4692 (let ((custom-prefix-list (custom-prefix-add symbol
4693 custom-prefix-list
))
4694 (members (custom-sort-items (get symbol
'custom-group
)
4695 custom-menu-sort-alphabetically
4696 custom-menu-order-groups
)))
4697 `(,(custom-unlispify-menu-entry symbol t
)
4700 ,@(mapcar (lambda (entry)
4701 (widget-apply (if (listp (nth 1 entry
))
4703 (list (nth 1 entry
)))
4704 :custom-menu
(nth 0 entry
)))
4709 (defun customize-menu-create (symbol &optional name
)
4710 "Return a customize menu for customization group SYMBOL.
4711 If optional NAME is given, use that as the name of the menu.
4712 Otherwise the menu will be named `Customize'.
4713 The format is suitable for use with `easy-menu-define'."
4715 (setq name
"Customize"))
4717 :filter
(lambda (&rest junk
)
4718 (let ((menu (custom-menu-create ',symbol
)))
4719 (if (consp menu
) (cdr menu
) menu
)))))
4721 ;;; Toolbar and menubar support
4724 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4725 "Menu used in customization buffers."
4726 (nconc (list "Custom"
4727 (customize-menu-create 'customize
))
4728 (mapcar (lambda (arg)
4729 (let ((tag (nth 0 arg
))
4730 (command (nth 1 arg
))
4731 (active (nth 2 arg
))
4733 (vector tag command
:active
(eval active
) :help help
)))
4736 (defvar tool-bar-map
)
4738 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4739 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4740 ;;; we set this up lazily in `Custom-mode'.
4741 (defvar custom-tool-bar-map nil
4742 "Keymap for toolbar in Custom mode.")
4744 ;;; The Custom Mode.
4746 (defun Custom-no-edit (_pos &optional _event
)
4747 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4749 (error "You can't edit this part of the Custom buffer"))
4751 (defun Custom-newline (pos &optional event
)
4752 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4754 (let ((button (get-char-property pos
'button
)))
4755 ;; If there is no button at point, then use the one at the start
4756 ;; of the line, if it is a custom-group-link (bug#2298).
4758 (if (setq button
(get-char-property (line-beginning-position) 'button
))
4759 (or (eq (widget-type button
) 'custom-group-link
)
4760 (setq button nil
))))
4762 (widget-apply-action button event
)
4763 (error "You can't edit this part of the Custom buffer"))))
4765 (defun Custom-goto-parent ()
4766 "Go to the parent group listed at the top of this buffer.
4767 If several parents are listed, go to the first of them."
4770 (goto-char (point-min))
4771 (if (search-forward "\nParent groups: " nil t
)
4772 (let* ((button (get-char-property (point) 'button
))
4773 (parent (downcase (widget-get button
:tag
))))
4774 (customize-group parent
)))))
4776 (defcustom Custom-mode-hook nil
4777 "Hook called when entering Custom mode."
4779 :group
'custom-buffer
)
4781 (defun custom-state-buffer-message (widget)
4782 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4783 (message "To install your edits, invoke [State] and choose the Set operation")))
4785 (defun custom--initialize-widget-variables ()
4786 (setq-local widget-documentation-face
'custom-documentation
)
4787 (setq-local widget-button-face custom-button
)
4788 (setq-local widget-button-pressed-face custom-button-pressed
)
4789 (setq-local widget-mouse-face custom-button-mouse
)
4790 ;; We need this because of the "More" button on docstrings.
4791 ;; Otherwise clicking on "More" can push point offscreen, which
4792 ;; causes the window to recenter on point, which pushes the
4793 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4794 (setq-local widget-button-click-moves-point t
)
4795 ;; When possible, use relief for buttons, not bracketing. This test
4796 ;; may not be optimal.
4797 (when custom-raised-buttons
4798 (setq-local widget-push-button-prefix
"")
4799 (setq-local widget-push-button-suffix
"")
4800 (setq-local widget-link-prefix
"")
4801 (setq-local widget-link-suffix
""))
4802 (setq show-trailing-whitespace nil
))
4804 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4805 (define-derived-mode Custom-mode nil
"Custom"
4806 "Major mode for editing customization buffers.
4808 The following commands are available:
4811 Move to next button, link or editable field. \\[widget-forward]
4812 Move to previous button, link or editable field. \\[widget-backward]
4813 \\<custom-field-keymap>\
4814 Complete content of editable text field. \\[widget-complete]
4815 \\<custom-mode-map>\
4816 Invoke button under the mouse pointer. \\[widget-button-click]
4817 Invoke button under point. \\[widget-button-press]
4818 Set all options from current text. \\[Custom-set]
4819 Make values in current text permanent. \\[Custom-save]
4820 Make text match actual option values. \\[Custom-reset-current]
4821 Reset options to permanent settings. \\[Custom-reset-saved]
4822 Erase customizations; set options
4823 and buffer text to the standard values. \\[Custom-reset-standard]
4825 Entry to this mode calls the value of `Custom-mode-hook'
4826 if that value is non-nil."
4827 (use-local-map custom-mode-map
)
4828 (easy-menu-add Custom-mode-menu
)
4829 (setq-local tool-bar-map
4830 (or custom-tool-bar-map
4831 ;; Set up `custom-tool-bar-map'.
4832 (let ((map (make-sparse-keymap)))
4835 (tool-bar-local-item-from-menu
4836 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4837 :label
(nth 5 arg
)))
4839 (setq custom-tool-bar-map map
))))
4840 (make-local-variable 'custom-options
)
4841 (make-local-variable 'custom-local-buffer
)
4842 (custom--initialize-widget-variables)
4843 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4845 (put 'Custom-mode
'mode-class
'special
)
4847 (define-obsolete-function-alias 'custom-mode
'Custom-mode
"23.1")
4849 (add-to-list 'debug-ignored-errors
"^Invalid face:? ")
4855 ;;; cus-edit.el ends here