1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages -*- lexical-binding:t -*-
3 ;; Copyright (C) 1996-1997, 1999-2017 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")
204 (defgroup outlines nil
205 "Support for hierarchical outlining."
208 (defgroup external nil
209 "Interfacing to external utilities."
213 "Communications, networking, and remote access to files."
217 (defgroup processes nil
218 "Process, subshell, compilation, and job control support."
221 (defgroup programming nil
222 "Support for programming in other languages."
225 (defgroup languages nil
226 "Modes for editing programming languages."
230 "Lisp support, including Emacs Lisp."
231 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
236 "Support for the C language and related languages."
237 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
238 :link
'(custom-manual "(ccmode)")
245 (defgroup applications nil
246 "Applications written in Emacs."
249 (defgroup calendar nil
250 "Calendar and time management support."
251 :group
'applications
)
254 "Modes for electronic-mail handling."
255 :group
'applications
)
258 "Reading and posting to newsgroups."
259 :link
'(custom-manual "(gnus)")
260 :group
'applications
)
263 "Games, jokes and amusements."
264 :group
'applications
)
266 (defgroup development nil
267 "Support for further development of Emacs."
271 "Support for Emacs documentation."
274 (defgroup extensions nil
275 "Emacs Lisp language extensions."
278 (defgroup internal nil
279 "Code for Emacs internals, build process, defaults."
283 "Maintenance aids for the Emacs development group."
287 (defgroup environment nil
288 "Fitting Emacs with its environment."
291 (defgroup hardware nil
292 "Support for interfacing with miscellaneous hardware."
295 (defgroup terminals nil
296 "Support for terminal types."
300 "Interfaces, assistants, and emulators for UNIX features."
304 "Internationalization and alternate character-set support."
305 :link
'(custom-manual "(emacs)International")
310 "The X Window system."
314 "Support for Emacs frames and window systems."
318 "Code related to the TeX formatter."
319 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
323 "Support for multiple fonts."
327 "Support for Emacs help systems."
330 (defgroup multimedia nil
331 "Non-textual support, specifically images and sound."
335 "Code local to your site."
338 (defgroup customize
'((widgets custom-group
))
339 "Customization of the Customization support."
343 (defgroup custom-faces nil
344 "Faces used by customize."
348 (defgroup custom-browse nil
349 "Control customize browser."
353 (defgroup custom-buffer nil
354 "Control customize buffers."
358 (defgroup custom-menu nil
359 "Control customize menus."
364 "Storage allocation and gc for GNU Emacs Lisp interpreter."
365 :tag
"Storage Allocation"
369 "Undoing changes in buffers."
370 :link
'(custom-manual "(emacs)Undo")
373 (defgroup mode-line nil
374 "Contents of the mode line."
377 (defgroup editing-basics nil
378 "Most basic editing facilities."
381 (defgroup display nil
382 "How characters are displayed in buffers."
385 (defgroup execute nil
386 "Executing external commands."
389 (defgroup installation nil
390 "The Emacs installation."
398 "Internal Emacs limits."
402 "Debugging Emacs itself."
405 (defgroup keyboard nil
406 "Input from the keyboard."
410 "Input from the mouse."
414 "Input from the menus."
418 "Handling data from drag and drop."
421 (defgroup auto-save nil
422 "Preventing accidental loss of data."
425 (defgroup processes-basics nil
426 "Basic stuff dealing with processes."
430 "MULE Emacs internationalization."
433 (defgroup windows nil
434 "Windows within a frame."
435 :link
'(custom-manual "(emacs)Windows")
438 ;;; Custom mode keymaps
440 (defvar custom-mode-map
441 (let ((map (make-keymap)))
442 (set-keymap-parent map widget-keymap
)
443 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
444 (define-key map
"\^m" 'Custom-newline
)
445 (define-key map
" " 'scroll-up-command
)
446 (define-key map
[?\S-\
] 'scroll-down-command
)
447 (define-key map
"\177" 'scroll-down-command
)
448 (define-key map
"\C-c\C-c" 'Custom-set
)
449 (define-key map
"\C-x\C-s" 'Custom-save
)
450 (define-key map
"q" 'Custom-buffer-done
)
451 (define-key map
"u" 'Custom-goto-parent
)
452 (define-key map
"n" 'widget-forward
)
453 (define-key map
"p" 'widget-backward
)
455 "Keymap for `Custom-mode'.")
457 (defvar custom-mode-link-map
458 (let ((map (make-keymap)))
459 (set-keymap-parent map custom-mode-map
)
460 (define-key map
[down-mouse-2
] nil
)
461 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
462 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
464 "Local keymap for links in `Custom-mode'.")
466 (defvar custom-field-keymap
467 (let ((map (copy-keymap widget-field-keymap
)))
468 (define-key map
"\C-c\C-c" 'Custom-set
)
469 (define-key map
"\C-x\C-s" 'Custom-save
)
471 "Keymap used inside editable fields in customization buffers.")
473 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
477 (defun custom-split-regexp-maybe (regexp)
478 "If REGEXP is a string, split it to a list at `\\|'.
479 You can get the original back from the result with:
480 (mapconcat \\='identity result \"\\|\")
482 IF REGEXP is not a string, return it unchanged."
484 (split-string regexp
"\\\\|")
487 (defun custom-variable-prompt ()
488 "Prompt for a custom variable, defaulting to the variable at point.
489 Return a list suitable for use in `interactive'."
490 (let* ((v (variable-at-point))
491 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
492 (enable-recursive-minibuffers t
)
494 (setq val
(completing-read
495 (if default
(format "Customize variable (default %s): " default
)
496 "Customize variable: ")
497 obarray
'custom-variable-p t nil nil default
))
498 (list (if (equal val
"")
499 (if (symbolp v
) v nil
)
502 (defun custom-menu-filter (menu widget
)
503 "Convert MENU to the form used by `widget-choose'.
504 MENU should be in the same format as `custom-variable-menu'.
505 WIDGET is the widget to apply the filter entries of MENU on."
507 current name action filter
)
509 (setq current
(car menu
)
511 action
(nth 1 current
)
512 filter
(nth 2 current
)
514 (if (or (null filter
) (funcall filter widget
))
515 (push (cons name action
) result
)
521 (defvar custom-prefix-list nil
522 "List of prefixes that should be ignored by `custom-unlispify'.")
524 (defcustom custom-unlispify-menu-entries t
525 "Display menu entries as words instead of symbols if non-nil."
529 (defcustom custom-unlispify-remove-prefixes nil
530 "Non-nil means remove group prefixes from option names in buffer.
531 Discarding prefixes often leads to confusing names for options
532 and faces in Customize buffers, so do not set this to a non-nil
533 value unless you are sure you know what it does."
535 :group
'custom-buffer
538 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
539 "Convert SYMBOL into a menu entry."
540 (cond ((not custom-unlispify-menu-entries
)
541 (symbol-name symbol
))
542 ((get symbol
'custom-tag
)
544 (get symbol
'custom-tag
)
545 (concat (get symbol
'custom-tag
) "...")))
547 (with-current-buffer (get-buffer-create " *Custom-Work*")
549 (princ symbol
(current-buffer))
550 (goto-char (point-min))
551 (if custom-unlispify-remove-prefixes
552 (let ((prefixes custom-prefix-list
)
555 (setq prefix
(car prefixes
))
556 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
559 (delete-region (point-min) (point)))
560 (setq prefixes
(cdr prefixes
))))))
561 (subst-char-in-region (point-min) (point-max) ?- ?\s t
)
562 (capitalize-region (point-min) (point-max))
564 (goto-char (point-max))
568 (defcustom custom-unlispify-tag-names t
569 "Display tag names as words instead of symbols if non-nil."
570 :group
'custom-buffer
573 (defun custom-unlispify-tag-name (symbol)
574 "Convert SYMBOL into a menu entry."
575 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
576 (custom-unlispify-menu-entry symbol t
)))
578 (defun custom-prefix-add (symbol prefixes
)
579 "Add SYMBOL to list of ignored PREFIXES."
580 (cons (or (get symbol
'custom-prefix
)
581 (concat (symbol-name symbol
) "-"))
586 (defcustom custom-guess-name-alist
592 ("-function\\'" function
)
593 ("-functions\\'" (repeat function
))
594 ("-list\\'" (repeat sexp
))
595 ("-alist\\'" (alist :key-type sexp
:value-type sexp
)))
596 "Alist of (MATCH TYPE).
598 MATCH should be a regexp matching the name of a symbol, and TYPE should
599 be a widget suitable for editing the value of that symbol. The TYPE
600 of the first entry where MATCH matches the name of the symbol will be
603 This is used for guessing the type of variables not declared with
605 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
606 :group
'custom-buffer
)
608 (defcustom custom-guess-doc-alist
609 '(("\\`\\*?Non-nil " boolean
))
610 "Alist of (MATCH TYPE).
612 MATCH should be a regexp matching a documentation string, and TYPE
613 should be a widget suitable for editing the value of a variable with
614 that documentation string. The TYPE of the first entry where MATCH
615 matches the name of the symbol will be used.
617 This is used for guessing the type of variables not declared with
619 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
620 :group
'custom-buffer
)
622 (defun custom-guess-type (symbol)
623 "Guess a widget suitable for editing the value of SYMBOL.
624 This is done by matching SYMBOL with `custom-guess-name-alist' and
625 if that fails, the doc string with `custom-guess-doc-alist'."
626 (let ((name (symbol-name symbol
))
627 (names custom-guess-name-alist
)
630 (setq current
(car names
)
632 (when (string-match-p (nth 0 current
) name
)
633 (setq found
(nth 1 current
)
636 (let ((doc (documentation-property symbol
'variable-documentation t
))
637 (docs custom-guess-doc-alist
))
640 (setq current
(car docs
)
642 (when (string-match-p (nth 0 current
) doc
)
643 (setq found
(nth 1 current
)
650 (defcustom custom-browse-sort-alphabetically nil
651 "If non-nil, sort customization group alphabetically in `custom-browse'."
653 :group
'custom-browse
)
655 (defcustom custom-browse-order-groups nil
656 "If non-nil, order group members within each customization group.
657 If `first', order groups before non-groups.
658 If `last', order groups after non-groups."
659 :type
'(choice (const first
)
661 (const :tag
"none" nil
))
662 :group
'custom-browse
)
664 (defcustom custom-browse-only-groups nil
665 "If non-nil, show group members only within each customization group."
667 :group
'custom-browse
)
670 (defcustom custom-buffer-sort-alphabetically t
671 "Whether to sort customization groups alphabetically in Custom buffer."
673 :group
'custom-buffer
676 (defcustom custom-buffer-order-groups
'last
677 "If non-nil, order group members within each customization group.
678 If `first', order groups before non-groups.
679 If `last', order groups after non-groups."
680 :type
'(choice (const first
)
682 (const :tag
"none" nil
))
683 :group
'custom-buffer
)
686 (defcustom custom-menu-sort-alphabetically nil
687 "If non-nil, sort each customization group alphabetically in menus."
691 (defcustom custom-menu-order-groups
'first
692 "If non-nil, order group members within each customization group.
693 If `first', order groups before non-groups.
694 If `last', order groups after non-groups."
695 :type
'(choice (const first
)
697 (const :tag
"none" nil
))
700 (defun custom-sort-items (items sort-alphabetically order-groups
)
701 "Return a sorted copy of ITEMS.
702 ITEMS should be a list of `custom-group' properties.
703 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
704 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
705 groups after non-groups, if nil do not order groups at all."
706 (sort (copy-sequence items
)
708 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
709 (namea (nth 0 a
)) (nameb (nth 0 b
)))
710 (cond ((not order-groups
)
711 ;; Since we don't care about A and B order, maybe sort.
712 (when sort-alphabetically
713 (string-lessp namea nameb
)))
714 ((eq typea
'custom-group
)
715 ;; If B is also a group, maybe sort. Otherwise, order A and B.
716 (if (eq typeb
'custom-group
)
717 (when sort-alphabetically
718 (string-lessp namea nameb
))
719 (eq order-groups
'first
)))
720 ((eq typeb
'custom-group
)
721 ;; Since A cannot be a group, order A and B.
722 (eq order-groups
'last
))
724 ;; Since A and B cannot be groups, sort.
725 (string-lessp namea nameb
)))))))
727 ;;; Custom Mode Commands.
729 ;; This variable is used by `custom-tool-bar-map', or directly by
730 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
732 (defvar custom-commands
733 '((" Apply " Custom-set t
734 "Apply settings (for the current session only)."
737 (" Apply and Save " Custom-save
738 (or custom-file user-init-file
)
739 "Apply settings and save for future sessions."
742 (" Undo Edits " Custom-reset-current t
743 "Restore customization buffer to reflect existing settings."
746 (" Reset Customizations " Custom-reset-saved t
747 "Undo any settings applied only for the current session."
750 (" Erase Customizations " Custom-reset-standard
751 (or custom-file user-init-file
)
752 "Un-customize settings in this and future sessions."
755 (" Help for Customize " Custom-help t
756 "Get help for using Customize."
759 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
761 (defun Custom-help ()
762 "Read the node on Easy Customization in the Emacs manual."
764 (info "(emacs)Easy Customization"))
766 (defvar custom-reset-menu
767 '(("Undo Edits in Customization Buffer" . Custom-reset-current
)
768 ("Revert This Session's Customizations" . Custom-reset-saved
)
769 ("Erase Customizations" . Custom-reset-standard
))
770 "Alist of actions for the `Reset' button.
771 The key is a string containing the name of the action, the value is a
772 Lisp function taking the widget as an element which will be called
773 when the action is chosen.")
775 (defvar custom-options nil
776 "Customization widgets in the current buffer.")
778 (defun custom-command-apply (fun query
&optional strong-query
)
779 "Call function FUN on all widgets in `custom-options'.
780 If there is more than one widget, ask user for confirmation using
781 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
782 and `yes-or-no-p' otherwise. Return non-nil if the functionality
783 has been executed, nil otherwise."
784 (if (or (and (= 1 (length custom-options
))
785 (memq (widget-type (car custom-options
))
786 '(custom-variable custom-face
)))
787 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
788 (progn (mapc fun custom-options
) t
)
792 (defun Custom-set (&rest _ignore
)
793 "Set the current value of all edited settings in the buffer."
795 (custom-command-apply
797 (when (eq (widget-get child
:custom-state
) 'modified
)
798 (widget-apply child
:custom-set
)))
799 "Set all values according to this buffer? "))
801 (defun Custom-save (&rest _ignore
)
802 "Set all edited settings, then save all settings that have been set.
803 If a setting was edited and set before, this saves it. If a
804 setting was merely edited before, this sets it then saves it."
806 (when (custom-command-apply
808 (when (memq (widget-get child
:custom-state
)
809 '(modified set changed rogue
))
810 (widget-apply child
:custom-mark-to-save
)))
811 "Save all settings in this buffer? " t
)
812 ;; Save changes to buffer and redraw.
814 (dolist (child custom-options
)
815 (widget-apply child
:custom-state-set-and-redraw
))))
817 (defun custom-reset (_widget &optional event
)
818 "Select item from reset menu."
819 (let* ((completion-ignore-case t
)
820 (answer (widget-choose "Reset settings"
826 (defun Custom-reset-current (&rest _ignore
)
827 "Reset all edited settings in the buffer to show their current values."
829 (custom-command-apply
831 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
832 (widget-apply widget
:custom-reset-current
)))
833 "Reset all settings' buffer text to show current values? "))
835 (defun Custom-reset-saved (&rest _ignore
)
836 "Reset all edited or set settings in the buffer to their saved value.
837 This also shows the saved values in the buffer."
839 (custom-command-apply
841 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
842 (widget-apply widget
:custom-reset-saved
)))
843 "Reset all settings (current values and buffer text) to saved values? "))
845 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
846 ;; and `custom-group-reset-standard'. If these variables are nil, both
847 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
848 ;; save, reset and redraw the handled widget immediately. Otherwise,
849 ;; they add the widget to the corresponding list and leave it to
850 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
851 (defvar custom-reset-standard-variables-list nil
)
852 (defvar custom-reset-standard-faces-list nil
)
854 ;; The next function was excerpted from `custom-variable-reset-standard'
855 ;; and `custom-face-reset-standard' and is used to avoid calling
856 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
857 ;; one) when erasing all customizations.
858 (defun custom-reset-standard-save-and-update ()
859 "Save settings and redraw after erasing customizations."
860 (when (or (and custom-reset-standard-variables-list
861 (not (eq custom-reset-standard-variables-list
'(t))))
862 (and custom-reset-standard-faces-list
863 (not (eq custom-reset-standard-faces-list
'(t)))))
864 ;; Save settings to file.
866 ;; Set state of and redraw variables.
867 (dolist (widget custom-reset-standard-variables-list
)
868 (unless (eq widget t
)
869 (widget-put widget
:custom-state
'unknown
)
870 (custom-redraw widget
)))
871 ;; Set state of and redraw faces.
872 (dolist (widget custom-reset-standard-faces-list
)
873 (unless (eq widget t
)
874 (let* ((symbol (widget-value widget
))
875 (child (car (widget-get widget
:children
)))
876 (comment-widget (widget-get widget
:comment-widget
)))
877 (put symbol
'face-comment nil
)
878 (widget-value-set child
879 (custom-pre-filter-face-spec
880 (list (list t
(custom-face-attributes-get
882 ;; This call manages the comment visibility
883 (widget-value-set comment-widget
"")
884 (custom-face-state-set widget
)
885 (custom-redraw-magic widget
))))))
887 (defun Custom-reset-standard (&rest _ignore
)
888 "Erase all customizations (either current or saved) in current buffer.
889 The immediate result is to restore them to their standard values.
890 This operation eliminates any saved values for the group members,
891 making them as if they had never been customized at all."
893 ;; Bind these temporarily.
894 (let ((custom-reset-standard-variables-list '(t))
895 (custom-reset-standard-faces-list '(t)))
896 (if (custom-command-apply
898 (and (or (null (widget-get widget
:custom-standard-value
))
899 (widget-apply widget
:custom-standard-value
))
900 (memq (widget-get widget
:custom-state
)
901 '(modified set changed saved rogue
))
902 (widget-apply widget
:custom-mark-to-reset-standard
)))
903 "The settings will revert to their default values, in this
904 and future sessions. Really erase customizations? " t
)
905 (custom-reset-standard-save-and-update))))
907 ;;; The Customize Commands
909 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
910 "Prompt for a variable and a value and return them as a list.
911 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
912 prompt for the value. The %s escape in PROMPT-VAL is replaced with
913 the name of the variable.
915 If the variable has a `variable-interactive' property, that is used as if
916 it were the arg to `interactive' (which see) to interactively read the value.
918 If the variable has a `custom-type' property, it must be a widget and the
919 `:prompt-value' property of that widget will be used for reading the value.
920 If the variable also has a `custom-get' property, that is used for finding
921 the current value of the variable, otherwise `symbol-value' is used.
923 If optional COMMENT argument is non-nil, also prompt for a comment and return
924 it as the third element in the list."
925 (let* ((var (read-variable prompt-var
))
926 (minibuffer-help-form '(describe-variable var
))
928 (let ((prop (get var
'variable-interactive
))
929 (type (get var
'custom-type
))
930 (prompt (format prompt-val var
)))
932 (setq type
(list type
)))
934 ;; Use VAR's `variable-interactive' property
935 ;; as an interactive spec for prompting.
936 (call-interactively `(lambda (arg)
940 (widget-prompt-value type
944 (or (get var
'custom-get
) 'symbol-value
)
948 (eval-minibuffer prompt
))))))
951 (read-string "Comment: " (get var
'variable-comment
)))
955 (defun customize-set-value (variable value
&optional comment
)
956 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
958 If VARIABLE has a `variable-interactive' property, that is used as if
959 it were the arg to `interactive' (which see) to interactively read the value.
961 If VARIABLE has a `custom-type' property, it must be a widget and the
962 `:prompt-value' property of that widget will be used for reading the value.
964 If given a prefix (or a COMMENT argument), also prompt for a comment."
965 (interactive (custom-prompt-variable "Set variable: "
969 (cond ((string= comment
"")
970 (put variable
'variable-comment nil
))
972 (put variable
'variable-comment comment
)))
973 (set variable value
))
976 (defun customize-set-variable (variable value
&optional comment
)
977 "Set the default for VARIABLE to VALUE, and return VALUE.
978 VALUE is a Lisp object.
980 If VARIABLE has a `custom-set' property, that is used for setting
981 VARIABLE, otherwise `set-default' is used.
983 If VARIABLE has a `variable-interactive' property, that is used as if
984 it were the arg to `interactive' (which see) to interactively read the value.
986 If VARIABLE has a `custom-type' property, it must be a widget and the
987 `:prompt-value' property of that widget will be used for reading the value.
989 If given a prefix (or a COMMENT argument), also prompt for a comment."
990 (interactive (custom-prompt-variable "Set variable: "
991 "Set customized value for %s to: "
993 (custom-load-symbol variable
)
994 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
995 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
996 (put variable
'customized-value
(list (custom-quote value
)))
997 (cond ((string= comment
"")
998 (put variable
'variable-comment nil
)
999 (put variable
'customized-variable-comment nil
))
1001 (put variable
'variable-comment comment
)
1002 (put variable
'customized-variable-comment comment
)))
1006 (defun customize-save-variable (variable value
&optional comment
)
1007 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1010 If VARIABLE has a `custom-set' property, that is used for setting
1011 VARIABLE, otherwise `set-default' is used.
1013 If VARIABLE has a `variable-interactive' property, that is used as if
1014 it were the arg to `interactive' (which see) to interactively read the value.
1016 If VARIABLE has a `custom-type' property, it must be a widget and the
1017 `:prompt-value' property of that widget will be used for reading the value.
1019 If given a prefix (or a COMMENT argument), also prompt for a comment."
1020 (interactive (custom-prompt-variable "Set and save variable: "
1021 "Set and save value for %s as: "
1022 current-prefix-arg
))
1023 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1024 (put variable
'saved-value
(list (custom-quote value
)))
1025 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1026 (cond ((string= comment
"")
1027 (put variable
'variable-comment nil
)
1028 (put variable
'saved-variable-comment nil
))
1030 (put variable
'variable-comment comment
)
1031 (put variable
'saved-variable-comment comment
)))
1032 (put variable
'customized-value nil
)
1033 (put variable
'customized-variable-comment nil
)
1036 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1038 (set variable value
))
1041 ;; Some parts of Emacs might prompt the user to save customizations,
1042 ;; during startup before customizations are loaded. This function
1043 ;; handles this corner case by avoiding calling `custom-save-variable'
1044 ;; too early, which could wipe out existing customizations.
1047 (defun customize-push-and-save (list-var elts
)
1048 "Add ELTS to LIST-VAR and save for future sessions, safely.
1049 ELTS should be a list. This function adds each entry to the
1050 value of LIST-VAR using `add-to-list'.
1052 If Emacs is initialized, call `customize-save-variable' to save
1053 the resulting list value now. Otherwise, add an entry to
1054 `after-init-hook' to save it after initialization."
1055 (dolist (entry elts
)
1056 (add-to-list list-var entry
))
1058 (let ((coding-system-for-read nil
))
1059 (customize-save-variable list-var
(eval list-var
)))
1060 (add-hook 'after-init-hook
1062 (customize-push-and-save list-var elts
)))))
1066 "Select a customization buffer which you can use to set user options.
1067 User options are structured into \"groups\".
1068 Initially the top-level group `Emacs' and its immediate subgroups
1069 are shown; the contents of those subgroups are initially hidden."
1071 (customize-group 'emacs
))
1074 (defun customize-mode (mode)
1075 "Customize options related to a major or minor mode.
1076 By default the current major mode is used. With a prefix
1077 argument or if the current major mode has no known group, prompt
1078 for the MODE to customize."
1081 (let ((completion-regexp-list '("-mode\\'"))
1082 (group (custom-group-of-mode major-mode
)))
1083 (if (and group
(not current-prefix-arg
))
1086 (completing-read (if group
1087 (format "Mode (default %s): " major-mode
)
1090 'custom-group-of-mode
1091 t nil nil
(if group
(symbol-name major-mode
))))))))
1092 (customize-group (custom-group-of-mode mode
)))
1094 (defun customize-read-group ()
1095 (let ((completion-ignore-case t
))
1096 (completing-read "Customize group (default emacs): "
1099 (or (and (get symbol
'custom-loads
)
1100 (not (get symbol
'custom-autoload
)))
1101 (get symbol
'custom-group
)))
1105 (defun customize-group (&optional group other-window
)
1106 "Customize GROUP, which must be a customization group.
1107 If OTHER-WINDOW is non-nil, display in another window."
1108 (interactive (list (customize-read-group)))
1109 (when (stringp group
)
1110 (if (string-equal "" group
)
1112 (setq group
(intern group
))))
1113 (let ((name (format "*Customize Group: %s*"
1114 (custom-unlispify-tag-name group
))))
1116 ((null (get-buffer name
))
1117 (funcall (if other-window
1118 'custom-buffer-create-other-window
1119 'custom-buffer-create
)
1120 (list (list group
'custom-group
))
1122 (concat " for group "
1123 (custom-unlispify-tag-name group
))))
1125 (switch-to-buffer-other-window name
))
1127 (pop-to-buffer-same-window name
)))))
1130 (defun customize-group-other-window (&optional group
)
1131 "Customize GROUP, which must be a customization group, in another window."
1132 (interactive (list (customize-read-group)))
1133 (customize-group group t
))
1136 (defalias 'customize-variable
'customize-option
)
1139 (defun customize-option (symbol)
1140 "Customize SYMBOL, which must be a user option."
1141 (interactive (custom-variable-prompt))
1143 (error "No variable specified"))
1144 (let ((basevar (indirect-variable symbol
)))
1145 (custom-buffer-create (list (list basevar
'custom-variable
))
1146 (format "*Customize Option: %s*"
1147 (custom-unlispify-tag-name basevar
)))
1148 (unless (eq symbol basevar
)
1149 (message "`%s' is an alias for `%s'" symbol basevar
))))
1152 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1155 (defun customize-option-other-window (symbol)
1156 "Customize SYMBOL, which must be a user option.
1157 Show the buffer in another window, but don't select it."
1158 (interactive (custom-variable-prompt))
1160 (error "No variable specified"))
1161 (let ((basevar (indirect-variable symbol
)))
1162 (custom-buffer-create-other-window
1163 (list (list basevar
'custom-variable
))
1164 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1165 (unless (eq symbol basevar
)
1166 (message "`%s' is an alias for `%s'" symbol basevar
))))
1168 (defvar customize-changed-options-previous-release
"24.1"
1169 "Version for `customize-changed-options' to refer back to by default.")
1171 ;; Packages will update this variable, so make it available.
1173 (defvar customize-package-emacs-version-alist nil
1174 "Alist mapping versions of a package to Emacs versions.
1175 We use this for packages that have their own names, but are released
1176 as part of Emacs itself.
1178 Each elements looks like this:
1180 (PACKAGE (PVERSION . EVERSION)...)
1182 Here PACKAGE is the name of a package, as a symbol. After
1183 PACKAGE come one or more elements, each associating a
1184 package version PVERSION with the first Emacs version
1185 EVERSION in which it (or a subsequent version of PACKAGE)
1186 was first released. Both PVERSION and EVERSION are strings.
1187 PVERSION should be a string that this package used in
1188 the :package-version keyword for `defcustom', `defgroup',
1191 For example, the MH-E package updates this alist as follows:
1193 (add-to-list \\='customize-package-emacs-version-alist
1194 \\='(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1195 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1196 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1197 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1199 The value of PACKAGE needs to be unique and it needs to match the
1200 PACKAGE value appearing in the :package-version keyword. Since
1201 the user might see the value in a error message, a good choice is
1202 the official name of the package, such as MH-E or Gnus.")
1205 (defalias 'customize-changed
'customize-changed-options
)
1208 (defun customize-changed-options (&optional since-version
)
1209 "Customize all settings whose meanings have changed in Emacs itself.
1210 This includes new user options and faces, and new customization
1211 groups, as well as older options and faces whose meanings or
1212 default values have changed since the previous major Emacs
1215 With argument SINCE-VERSION (a string), customize all settings
1216 that were added or redefined since that version."
1220 (read-from-minibuffer
1221 (format "Customize options changed, since version (default %s): "
1222 customize-changed-options-previous-release
))))
1223 (if (equal since-version
"")
1224 (setq since-version nil
)
1225 (unless (condition-case nil
1226 (numberp (read since-version
))
1228 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1229 (unless since-version
1230 (setq since-version customize-changed-options-previous-release
))
1232 ;; Load the information for versions since since-version. We use
1233 ;; custom-load-symbol for this.
1234 (put 'custom-versions-load-alist
'custom-loads nil
)
1235 (dolist (elt custom-versions-load-alist
)
1236 (if (customize-version-lessp since-version
(car elt
))
1237 (dolist (load (cdr elt
))
1238 (custom-add-load 'custom-versions-load-alist load
))))
1239 (custom-load-symbol 'custom-versions-load-alist
)
1240 (put 'custom-versions-load-alist
'custom-loads nil
)
1245 (let* ((package-version (get symbol
'custom-package-version
))
1247 (or (and package-version
1248 (customize-package-emacs-version symbol
1250 (get symbol
'custom-version
))))
1252 (when (customize-version-lessp since-version version
)
1253 (if (or (get symbol
'custom-group
)
1254 (get symbol
'group-documentation
))
1255 (push (list symbol
'custom-group
) found
))
1256 (if (custom-variable-p symbol
)
1257 (push (list symbol
'custom-variable
) found
))
1258 (if (custom-facep symbol
)
1259 (push (list symbol
'custom-face
) found
)))))))
1261 (custom-buffer-create (custom-sort-items found t
'first
)
1262 "*Customize Changed Options*")
1263 (user-error "No user option defaults have been changed since Emacs %s"
1266 (defun customize-package-emacs-version (symbol package-version
)
1267 "Return the Emacs version in which SYMBOL's meaning last changed.
1268 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1269 `customize-package-emacs-version-alist' to find the version of
1270 Emacs that is associated with version VERSION of PACKAGE."
1271 (let (package-versions emacs-version
)
1272 ;; Use message instead of error since we want user to be able to
1273 ;; see the rest of the symbols even if a package author has
1274 ;; botched things up.
1275 (cond ((not (listp package-version
))
1276 (message "Invalid package-version value for %s" symbol
))
1277 ((setq package-versions
(assq (car package-version
)
1278 customize-package-emacs-version-alist
))
1280 (cdr (assoc (cdr package-version
) package-versions
)))
1281 (unless emacs-version
1282 (message "%s version %s not found in %s" symbol
1283 (cdr package-version
)
1284 "customize-package-emacs-version-alist")))
1286 (message "Package %s version %s lists no corresponding Emacs version"
1287 (car package-version
)
1288 (cdr package-version
))))
1291 (defun customize-version-lessp (version1 version2
)
1292 ;; Why are the versions strings, and given that they are, why aren't
1293 ;; they converted to numbers and compared as such here? -- fx
1295 ;; In case someone made a mistake and left out the quotes
1296 ;; in the :version value.
1297 (if (numberp version2
)
1298 (setq version2
(prin1-to-string version2
)))
1299 (let (major1 major2 minor1 minor2
)
1300 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1301 (setq major1
(read (or (match-string 1 version1
)
1303 (setq minor1
(read (or (match-string 3 version1
)
1305 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1306 (setq major2
(read (or (match-string 1 version2
)
1308 (setq minor2
(read (or (match-string 3 version2
)
1310 (or (< major1 major2
)
1311 (and (= major1 major2
)
1312 (< minor1 minor2
)))))
1315 (defun customize-face (&optional face other-window
)
1316 "Customize FACE, which should be a face name or nil.
1317 If FACE is nil, customize all faces. If FACE is actually a
1318 face-alias, customize the face it is aliased to.
1320 If OTHER-WINDOW is non-nil, display in another window.
1322 Interactively, when point is on text which has a face specified,
1323 suggest to customize that face, if it's customizable."
1324 (interactive (list (read-face-name "Customize face"
1325 (or (face-at-point t t
) "all faces") t
)))
1326 (if (member face
'(nil ""))
1327 (setq face
(face-list)))
1328 (if (and (listp face
) (null (cdr face
)))
1329 (setq face
(car face
)))
1330 (let ((display-fun (if other-window
1331 'custom-buffer-create-other-window
1332 'custom-buffer-create
)))
1334 (funcall display-fun
1336 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1338 "*Customize Faces*")
1339 ;; If FACE is actually an alias, customize the face it is aliased to.
1340 (if (get face
'face-alias
)
1341 (setq face
(get face
'face-alias
)))
1342 (unless (facep face
)
1343 (error "Invalid face %S" face
))
1344 (funcall display-fun
1345 (list (list face
'custom-face
))
1346 (format "*Customize Face: %s*"
1347 (custom-unlispify-tag-name face
))))))
1350 (defun customize-face-other-window (&optional face
)
1351 "Show customization buffer for face FACE in other window.
1352 If FACE is actually a face-alias, customize the face it is aliased to.
1354 Interactively, when point is on text which has a face specified,
1355 suggest to customize that face, if it's customizable."
1356 (interactive (list (read-face-name "Customize face"
1357 (or (face-at-point t t
) "all faces") t
)))
1358 (customize-face face t
))
1360 (defun custom-unsaved-options ()
1361 "List of options and faces set in this session but not saved.
1362 Each entry is of the form (SYMBOL TYPE), where TYPE is one of the
1363 symbols `custom-face' or `custom-variable'."
1365 (mapatoms (lambda (symbol)
1366 (and (or (get symbol
'customized-face
)
1367 (get symbol
'customized-face-comment
))
1368 (custom-facep symbol
)
1369 (push (list symbol
'custom-face
) found
))
1370 (and (or (get symbol
'customized-value
)
1371 (get symbol
'customized-variable-comment
))
1373 (push (list symbol
'custom-variable
) found
))))
1376 (defalias 'customize-customized
'customize-unsaved
)
1379 (defun customize-unsaved ()
1380 "Customize all options and faces set in this session but not saved."
1382 (let ((found (custom-unsaved-options)))
1384 (error "No user options are set but unsaved")
1385 (custom-buffer-create (custom-sort-items found t nil
)
1386 "*Customize Unsaved*"))))
1389 (defun customize-rogue ()
1390 "Customize all user variables modified outside customize."
1393 (mapatoms (lambda (symbol)
1394 (let ((cval (or (get symbol
'customized-value
)
1395 (get symbol
'saved-value
)
1396 (get symbol
'standard-value
))))
1397 (when (and cval
;Declared with defcustom.
1398 (default-boundp symbol
) ;Has a value.
1399 (not (equal (eval (car cval
))
1400 ;; Which does not match customize.
1401 (default-value symbol
))))
1402 (push (list symbol
'custom-variable
) found
)))))
1404 (user-error "No rogue user options")
1405 (custom-buffer-create (custom-sort-items found t nil
)
1406 "*Customize Rogue*"))))
1408 (defun customize-saved ()
1409 "Customize all saved options and faces."
1412 (mapatoms (lambda (symbol)
1413 (and (or (get symbol
'saved-face
)
1414 (get symbol
'saved-face-comment
))
1415 (custom-facep symbol
)
1416 (push (list symbol
'custom-face
) found
))
1417 (and (or (get symbol
'saved-value
)
1418 (get symbol
'saved-variable-comment
))
1420 (push (list symbol
'custom-variable
) found
))))
1422 (user-error "No saved user options")
1423 (custom-buffer-create (custom-sort-items found t nil
)
1424 "*Customize Saved*"))))
1426 (declare-function apropos-parse-pattern
"apropos" (pattern))
1427 (defvar apropos-regexp
)
1430 (defun customize-apropos (pattern &optional type
)
1431 "Customize loaded options, faces and groups matching PATTERN.
1432 PATTERN can be a word, a list of words (separated by spaces),
1433 or a regexp (using some regexp special characters). If it is a word,
1434 search for matches for that word as a substring. If it is a list of
1435 words, search for matches for any two (or more) of those words.
1437 If TYPE is `options', include only options.
1438 If TYPE is `faces', include only faces.
1439 If TYPE is `groups', include only groups."
1440 (interactive (list (apropos-read-pattern "symbol") nil
))
1442 (unless (memq type
'(nil options faces groups
))
1443 (error "Invalid setting type %s" (symbol-name type
)))
1444 (apropos-parse-pattern pattern
) ;Sets apropos-regexp by side-effect: Yuck!
1448 (when (string-match-p apropos-regexp
(symbol-name symbol
))
1449 (if (memq type
'(nil groups
))
1450 (if (get symbol
'custom-group
)
1451 (push (list symbol
'custom-group
) found
)))
1452 (if (memq type
'(nil faces
))
1453 (if (custom-facep symbol
)
1454 (push (list symbol
'custom-face
) found
)))
1455 (if (memq type
'(nil options
))
1456 (if (and (boundp symbol
)
1457 (eq (indirect-variable symbol
) symbol
)
1458 (or (get symbol
'saved-value
)
1459 (custom-variable-p symbol
)))
1460 (push (list symbol
'custom-variable
) found
))))))
1462 (error "No customizable %s matching %s" (if (not type
)
1463 "group, face, or option"
1466 (custom-buffer-create
1467 (custom-sort-items found t custom-buffer-order-groups
)
1468 "*Customize Apropos*")))
1471 (defun customize-apropos-options (regexp &optional ignored
)
1472 "Customize all loaded customizable options matching REGEXP."
1473 (interactive (list (apropos-read-pattern "options")))
1474 (customize-apropos regexp
'options
))
1477 (defun customize-apropos-faces (regexp)
1478 "Customize all loaded faces matching REGEXP."
1479 (interactive (list (apropos-read-pattern "faces")))
1480 (customize-apropos regexp
'faces
))
1483 (defun customize-apropos-groups (regexp)
1484 "Customize all loaded groups matching REGEXP."
1485 (interactive (list (apropos-read-pattern "groups")))
1486 (customize-apropos regexp
'groups
))
1489 (defun custom-prompt-customize-unsaved-options ()
1490 "Prompt user to customize any unsaved customization options.
1491 Return non-nil if user chooses to customize, for use in
1492 `kill-emacs-query-functions'."
1493 (not (and (custom-unsaved-options)
1494 (yes-or-no-p "Some customized options have not been saved; Examine? ")
1500 (defcustom custom-buffer-style
'links
1501 "Control the presentation style for customization buffers.
1502 The value should be a symbol, one of:
1503 `brackets': groups nest within each other with big horizontal brackets.
1504 `links': groups have links to subgroups.
1505 `tree': display groups as trees."
1506 :type
'(radio (const brackets
)
1509 :group
'custom-buffer
)
1511 (defcustom custom-buffer-done-kill nil
1512 "Non-nil means exiting a Custom buffer should kill it."
1515 :group
'custom-buffer
)
1517 (defcustom custom-buffer-indent
3
1518 "Number of spaces to indent nested groups."
1520 :group
'custom-buffer
)
1522 (defun custom-get-fresh-buffer (name)
1523 "Get a fresh new buffer with name NAME.
1524 If the buffer already exist, clean it up to be like new.
1525 Beware: it's not quite like new. Good enough for custom, but maybe
1527 ;; To be more complete, we should also kill all permanent-local variables,
1528 ;; but it's not needed for custom.
1529 (let ((buf (get-buffer name
)))
1530 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1531 ;; This will check if the file is not saved.
1535 (get-buffer-create name
)
1536 (with-current-buffer buf
1537 (kill-all-local-variables)
1538 (run-hooks 'kill-buffer-hook
)
1539 ;; Delete overlays before erasing the buffer so the overlay hooks
1540 ;; don't get run spuriously when we erase the buffer.
1541 (let ((ols (overlay-lists)))
1542 (dolist (ol (nconc (car ols
) (cdr ols
)))
1543 (delete-overlay ol
)))
1548 (defun custom-buffer-create (options &optional name description
)
1549 "Create a buffer containing OPTIONS.
1550 Optional NAME is the name of the buffer.
1551 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1552 SYMBOL is a customization option, and WIDGET is a widget for editing
1554 DESCRIPTION is unused."
1555 (pop-to-buffer-same-window (custom-get-fresh-buffer (or name
"*Customization*")))
1556 (custom-buffer-create-internal options description
))
1559 (defun custom-buffer-create-other-window (options &optional name description
)
1560 "Create a buffer containing OPTIONS, and display it in another window.
1561 The result includes selecting that window.
1562 Optional NAME is the name of the buffer.
1563 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1564 SYMBOL is a customization option, and WIDGET is a widget for editing
1566 (unless name
(setq name
"*Customization*"))
1567 (switch-to-buffer-other-window (custom-get-fresh-buffer name
))
1568 (custom-buffer-create-internal options description
))
1570 (defcustom custom-reset-button-menu t
1571 "If non-nil, only show a single reset button in customize buffers.
1572 This button will have a menu with all three reset operations."
1574 :group
'custom-buffer
1577 (defcustom custom-buffer-verbose-help t
1578 "If non-nil, include explanatory text in the customization buffer."
1580 :group
'custom-buffer
)
1582 (defun Custom-buffer-done (&rest _ignore
)
1583 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1585 (quit-window custom-buffer-done-kill
))
1587 (defvar custom-button nil
1588 "Face used for buttons in customization buffers.")
1590 (defvar custom-button-mouse nil
1591 "Mouse face used for buttons in customization buffers.")
1593 (defvar custom-button-pressed nil
1594 "Face used for pressed buttons in customization buffers.")
1596 (defcustom custom-search-field t
1597 "If non-nil, show a search field in Custom buffers."
1600 :group
'custom-buffer
)
1602 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1603 '(("unspecified" . unspecified
))))
1604 "If non-nil, indicate active buttons in a raised-button style.
1605 Otherwise use brackets."
1608 :group
'custom-buffer
1609 :set
(lambda (variable value
)
1610 (custom-set-default variable value
)
1612 (if value
'custom-button
'custom-button-unraised
))
1613 (setq custom-button-mouse
1614 (if value
'custom-button-mouse
'highlight
))
1615 (setq custom-button-pressed
1617 'custom-button-pressed
1618 'custom-button-pressed-unraised
))))
1620 (defun custom-buffer-create-internal (options &optional _description
)
1622 (let ((init-file (or custom-file user-init-file
)))
1623 ;; Insert verbose help at the top of the custom buffer.
1624 (when custom-buffer-verbose-help
1626 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1627 (widget-insert "For help using this buffer, see ")
1628 (widget-create 'custom-manual
1629 :tag
"Easy Customization"
1630 "(emacs)Easy Customization")
1631 (widget-insert " in the ")
1632 (widget-create 'custom-manual
1634 :help-echo
"Read the Emacs manual."
1636 (widget-insert "."))
1637 (widget-insert "\n")
1639 ;; Insert the search field.
1640 (when custom-search-field
1641 (widget-insert "\n")
1642 (let* ((echo "Search for custom items.
1643 You can enter one or more words separated by spaces,
1644 or a regular expression.")
1648 :size
40 :help-echo echo
1649 :action
(lambda (widget &optional _event
)
1650 (customize-apropos (split-string (widget-value widget
)))))))
1652 (widget-create-child-and-convert
1653 search-widget
'push-button
1655 :help-echo echo
:action
1656 (lambda (widget &optional _event
)
1657 (customize-apropos (split-string (widget-value (widget-get widget
:parent
))))))
1658 (widget-insert "\n")))
1660 ;; The custom command buttons are also in the toolbar, so for a
1661 ;; time they were not inserted in the buffer if the toolbar was in use.
1662 ;; But it can be a little confusing for the buffer layout to
1663 ;; change according to whether or nor the toolbar is on, not to
1664 ;; mention that a custom buffer can in theory be created in a
1665 ;; frame with a toolbar, then later viewed in one without.
1666 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1667 (if custom-buffer-verbose-help
1669 Operate on all settings in this buffer:\n"))
1670 (let ((button (lambda (tag action active help _icon _label
)
1673 (widget-create 'push-button
:tag tag
1674 :help-echo help
:action action
))))
1675 (commands custom-commands
))
1676 (if custom-reset-button-menu
1678 (widget-create 'push-button
1680 :help-echo
"Show a menu with reset operations."
1681 :mouse-down-action
'ignore
1682 :action
'custom-reset
)
1683 (apply button
(pop commands
)) ; Apply
1684 (apply button
(pop commands
))) ; Apply and Save
1685 (apply button
(pop commands
)) ; Apply
1686 (apply button
(pop commands
)) ; Apply and Save
1687 (widget-insert "\n")
1688 (apply button
(pop commands
)) ; Undo
1689 (apply button
(pop commands
)) ; Reset
1690 (apply button
(pop commands
)) ; Erase
1692 (pop commands
) ; Help (omitted)
1693 (apply button
(pop commands
)))) ; Exit
1694 (widget-insert "\n\n"))
1696 ;; Now populate the custom buffer.
1697 (message "Creating customization items...")
1698 (buffer-disable-undo)
1699 (setq custom-options
1700 (if (= (length options
) 1)
1701 (mapcar (lambda (entry)
1702 (widget-create (nth 1 entry
)
1703 :documentation-shown t
1704 :custom-state
'unknown
1705 :tag
(custom-unlispify-tag-name
1707 :value
(nth 0 entry
)))
1710 (length (length options
)))
1711 (mapcar (lambda (entry)
1713 (message "Creating customization items ...%2d%%"
1714 (floor (* 100.0 count
) length
))
1715 (widget-create (nth 1 entry
)
1716 :tag
(custom-unlispify-tag-name
1718 :value
(nth 0 entry
))
1719 (setq count
(1+ count
))
1720 (unless (eq (preceding-char) ?
\n)
1721 (widget-insert "\n"))
1722 (widget-insert "\n")))
1724 (unless (eq (preceding-char) ?
\n)
1725 (widget-insert "\n"))
1726 (message "Creating customization items ...done")
1727 (message "Resetting customization items...")
1728 (unless (eq custom-buffer-style
'tree
)
1729 (mapc 'custom-magic-reset custom-options
))
1730 (message "Resetting customization items...done")
1731 (message "Creating customization setup...")
1733 (buffer-enable-undo)
1734 (goto-char (point-min))
1735 (message "Creating customization setup...done"))
1737 ;;; The Tree Browser.
1740 (defun customize-browse (&optional group
)
1741 "Create a tree browser for the customize hierarchy."
1744 (setq group
'emacs
))
1745 (let ((name "*Customize Browser*"))
1746 (pop-to-buffer-same-window (custom-get-fresh-buffer name
)))
1748 (widget-insert (format "\
1749 %s buttons; type RET or click mouse-1
1750 on a button to invoke its action.
1751 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1752 (if custom-raised-buttons
1753 "Raised text indicates"
1754 "Square brackets indicate")))
1757 (if custom-browse-only-groups
1759 Invoke the [Group] button below to edit that item in another window.\n\n")
1760 (widget-insert "Invoke the ")
1761 (widget-create 'item
1764 :tag-glyph
"folder")
1765 (widget-insert ", ")
1766 (widget-create 'item
1770 (widget-insert ", and ")
1771 (widget-create 'item
1774 :tag-glyph
"option")
1775 (widget-insert " buttons below to edit that
1776 item in another window.\n\n"))
1777 (let ((custom-buffer-style 'tree
))
1778 (widget-create 'custom-group
1780 :custom-state
'unknown
1781 :tag
(custom-unlispify-tag-name group
)
1784 (goto-char (point-min)))
1786 (define-widget 'custom-browse-visibility
'item
1787 "Control visibility of items in the customize tree browser."
1789 :action
'custom-browse-visibility-action
)
1791 (defun custom-browse-visibility-action (widget &rest _ignore
)
1792 (let ((custom-buffer-style 'tree
))
1793 (custom-toggle-parent widget
)))
1795 (define-widget 'custom-browse-group-tag
'custom-group-link
1796 "Show parent in other window when activated."
1799 :action
'custom-browse-group-tag-action
)
1801 (defun custom-browse-group-tag-action (widget &rest _ignore
)
1802 (let ((parent (widget-get widget
:parent
)))
1803 (customize-group-other-window (widget-value parent
))))
1805 (define-widget 'custom-browse-variable-tag
'custom-group-link
1806 "Show parent in other window when activated."
1809 :action
'custom-browse-variable-tag-action
)
1811 (defun custom-browse-variable-tag-action (widget &rest _ignore
)
1812 (let ((parent (widget-get widget
:parent
)))
1813 (customize-variable-other-window (widget-value parent
))))
1815 (define-widget 'custom-browse-face-tag
'custom-group-link
1816 "Show parent in other window when activated."
1819 :action
'custom-browse-face-tag-action
)
1821 (defun custom-browse-face-tag-action (widget &rest _ignore
)
1822 (let ((parent (widget-get widget
:parent
)))
1823 (customize-face-other-window (widget-value parent
))))
1825 (defconst custom-browse-alist
'((" " "space")
1831 (defun custom-browse-insert-prefix (prefix)
1832 "Insert PREFIX. On XEmacs convert it to line graphics."
1833 ;; Fixme: do graphics.
1834 (if nil
; (featurep 'xemacs)
1837 (while (not (string-equal prefix
""))
1838 (let ((entry (substring prefix
0 3)))
1839 (setq prefix
(substring prefix
3))
1840 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1841 (name (nth 1 (assoc entry custom-browse-alist
))))
1842 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1843 (overlay-put overlay
'start-open t
)
1844 (overlay-put overlay
'end-open t
)))))
1847 ;;; Modification of Basic Widgets.
1849 ;; We add extra properties to the basic widgets needed here. This is
1850 ;; fine, as long as we are careful to stay within our own namespace.
1852 ;; We want simple widgets to be displayed by default, but complex
1853 ;; widgets to be hidden.
1855 ;; This widget type is obsolete as of Emacs 24.1.
1856 (widget-put (get 'item
'widget-type
) :custom-show t
)
1857 (widget-put (get 'editable-field
'widget-type
)
1858 :custom-show
(lambda (_widget value
)
1859 (let ((pp (pp-to-string value
)))
1860 (cond ((string-match-p "\n" pp
)
1865 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1867 ;;; The `custom-manual' Widget.
1869 (define-widget 'custom-manual
'info-link
1870 "Link to the manual entry for this customization option."
1871 :help-echo
"Read the manual entry for this option."
1872 :keymap custom-mode-link-map
1873 :follow-link
'mouse-face
1874 :button-face
'custom-link
1875 :mouse-face
'highlight
1876 :pressed-face
'highlight
1879 ;;; The `custom-magic' Widget.
1881 (defgroup custom-magic-faces nil
1882 "Faces used by the magic button."
1883 :group
'custom-faces
1884 :group
'custom-buffer
)
1886 (defface custom-invalid
'((((class color
))
1887 :foreground
"yellow1" :background
"red1")
1888 (t :weight bold
:slant italic
:underline t
))
1889 "Face used when the customize item is invalid."
1890 :group
'custom-magic-faces
)
1892 (defface custom-rogue
'((((class color
))
1893 :foreground
"pink" :background
"black")
1895 "Face used when the customize item is not defined for customization."
1896 :group
'custom-magic-faces
)
1898 (defface custom-modified
'((((min-colors 88) (class color
))
1899 :foreground
"white" :background
"blue1")
1901 :foreground
"white" :background
"blue")
1903 "Face used when the customize item has been modified."
1904 :group
'custom-magic-faces
)
1906 (defface custom-set
'((((min-colors 88) (class color
))
1907 :foreground
"blue1" :background
"white")
1909 :foreground
"blue" :background
"white")
1911 "Face used when the customize item has been set."
1912 :group
'custom-magic-faces
)
1914 (defface custom-changed
'((((min-colors 88) (class color
))
1915 :foreground
"white" :background
"blue1")
1917 :foreground
"white" :background
"blue")
1919 "Face used when the customize item has been changed."
1920 :group
'custom-magic-faces
)
1922 (defface custom-themed
'((((min-colors 88) (class color
))
1923 :foreground
"white" :background
"blue1")
1925 :foreground
"white" :background
"blue")
1927 "Face used when the customize item has been set by a theme."
1928 :group
'custom-magic-faces
)
1930 (defface custom-saved
'((t :underline t
))
1931 "Face used when the customize item has been saved."
1932 :group
'custom-magic-faces
)
1934 (defconst custom-magic-alist
1935 '((nil "#" underline
"\
1936 UNINITIALIZED, you should not see this.")
1937 (unknown "?" italic
"\
1938 UNKNOWN, you should not see this.")
1939 (hidden "-" default
"\
1940 HIDDEN, invoke \"Show\" in the previous line to show." "\
1941 group now hidden, invoke \"Show\", above, to show contents.")
1942 (invalid "x" custom-invalid
"\
1943 INVALID, the displayed value cannot be set.")
1944 (modified "*" custom-modified
"\
1945 EDITED, shown value does not take effect until you set or save it." "\
1946 something in this group has been edited but not set.")
1947 (set "+" custom-set
"\
1948 SET for current session only." "\
1949 something in this group has been set but not saved.")
1950 (changed ":" custom-changed
"\
1951 CHANGED outside Customize." "\
1952 something in this group has been changed outside customize.")
1953 (saved "!" custom-saved
"\
1955 something in this group has been set and saved.")
1956 (themed "o" custom-themed
"\
1958 visible group members are set by enabled themes.")
1959 (rogue "@" custom-rogue
"\
1960 NO CUSTOMIZATION DATA; not intended to be customized." "\
1961 something in this group is not prepared for customization.")
1962 (standard " " nil
"\
1964 visible group members are all at standard values."))
1965 "Alist of customize option states.
1966 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1968 STATE is one of the following symbols:
1971 For internal use, should never occur.
1973 For internal use, should never occur.
1975 This item is not being displayed.
1977 This item is modified, but has an invalid form.
1979 This item is modified, and has a valid form.
1981 This item has been set but not saved.
1983 The current value of this item has been changed outside Customize.
1985 This item is marked for saving.
1987 This item has no customization information.
1989 This item was set by an enabled Custom theme.
1991 This item is unchanged from the standard setting.
1993 MAGIC is a string used to present that state.
1995 FACE is a face used to present the state.
1997 ITEM-DESC is a string describing the state for options.
1999 GROUP-DESC is a string describing the state for groups. If this is
2000 left out, ITEM-DESC will be used.
2002 The string %c in either description will be replaced with the
2003 category of the item. These are `group', `option', and `face'.
2005 The list should be sorted most significant first.")
2007 (defcustom custom-magic-show
'long
2008 "If non-nil, show textual description of the state.
2009 If `long', show a full-line description, not just one word."
2010 :type
'(choice (const :tag
"no" nil
)
2012 (other :tag
"short" short
))
2013 :group
'custom-buffer
)
2015 (defcustom custom-magic-show-hidden
'(option face
)
2016 "Control whether the State button is shown for hidden items.
2017 The value should be a list with the custom categories where the State
2018 button should be visible. Possible categories are `group', `option',
2020 :type
'(set (const group
) (const option
) (const face
))
2021 :group
'custom-buffer
)
2023 (defcustom custom-magic-show-button nil
2024 "Show a \"magic\" button indicating the state of each customization option."
2026 :group
'custom-buffer
)
2028 (define-widget 'custom-magic
'default
2029 "Show and manipulate state for a customization option."
2031 :action
'widget-parent-action
2034 :value-create
'custom-magic-value-create
2035 :value-delete
'widget-children-value-delete
)
2037 (defun widget-magic-mouse-down-action (widget &optional _event
)
2038 ;; Non-nil unless hidden.
2039 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2043 (defun custom-magic-value-create (widget)
2044 "Create compact status report for WIDGET."
2045 (let* ((parent (widget-get widget
:parent
))
2046 (state (widget-get parent
:custom-state
))
2047 (hidden (eq state
'hidden
))
2048 (entry (assq state custom-magic-alist
))
2049 (magic (nth 1 entry
))
2050 (face (nth 2 entry
))
2051 (category (widget-get parent
:custom-category
))
2052 (text (or (and (eq category
'group
)
2055 (form (widget-get parent
:custom-form
))
2057 (unless (eq state
'hidden
)
2058 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2059 (setq text
(concat (match-string 1 text
)
2060 (symbol-name category
)
2061 (match-string 2 text
))))
2062 (when (and custom-magic-show
2064 (memq category custom-magic-show-hidden
)))
2066 (when (and (eq category
'group
)
2067 (not (and (eq custom-buffer-style
'links
)
2068 (> (widget-get parent
:custom-level
) 1))))
2069 (insert-char ?\s
(* custom-buffer-indent
2070 (widget-get parent
:custom-level
))))
2071 (push (widget-create-child-and-convert
2073 :help-echo
"Change the state of this item."
2074 :format
(if hidden
"%t" "%[%t%]")
2075 :button-prefix
'widget-push-button-prefix
2076 :button-suffix
'widget-push-button-suffix
2077 :mouse-down-action
'widget-magic-mouse-down-action
2081 (let ((start (point)))
2082 (if (eq custom-magic-show
'long
)
2084 (insert (symbol-name state
)))
2085 (cond ((eq form
'lisp
)
2087 ((eq form
'mismatch
)
2088 (insert " (mismatch)")))
2089 (put-text-property start
(point) 'face
'custom-state
))
2091 (when (and (eq category
'group
)
2092 (not (and (eq custom-buffer-style
'links
)
2093 (> (widget-get parent
:custom-level
) 1))))
2094 (insert-char ?\s
(* custom-buffer-indent
2095 (widget-get parent
:custom-level
))))
2096 (when custom-magic-show-button
2097 (when custom-magic-show
2098 (let ((indent (widget-get parent
:indent
)))
2100 (insert-char ? indent
))))
2101 (push (widget-create-child-and-convert
2103 :mouse-down-action
'widget-magic-mouse-down-action
2107 :help-echo
"Change the state."
2108 :format
(if hidden
"%t" "%[%t%]")
2109 :tag
(if (memq form
'(lisp mismatch
))
2110 (concat "(" magic
")")
2111 (concat "[" magic
"]")))
2114 (widget-put widget
:children children
))))
2116 (defun custom-magic-reset (widget)
2117 "Redraw the :custom-magic property of WIDGET."
2118 (let ((magic (widget-get widget
:custom-magic
)))
2120 (widget-value-set magic
(widget-value magic
)))))
2122 ;;; The `custom' Widget.
2124 (defface custom-button
2125 '((((type x w32 ns
) (class color
)) ; Like default mode line
2126 :box
(:line-width
2 :style released-button
)
2127 :background
"lightgrey" :foreground
"black"))
2128 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2130 :group
'custom-faces
)
2132 (defface custom-button-mouse
2133 '((((type x w32 ns
) (class color
))
2134 :box
(:line-width
2 :style released-button
)
2135 :background
"grey90" :foreground
"black")
2137 ;; This is for text terminals that support mouse, like GPM mouse
2138 ;; or the MS-DOS terminal: inverse-video makes the button stand
2139 ;; out on mouse-over.
2141 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2143 :group
'custom-faces
)
2145 (defface custom-button-unraised
2146 '((t :inherit underline
))
2147 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2149 :group
'custom-faces
)
2152 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2154 (setq custom-button-mouse
2155 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2157 (defface custom-button-pressed
2158 '((((type x w32 ns
) (class color
))
2159 :box
(:line-width
2 :style pressed-button
)
2160 :background
"lightgrey" :foreground
"black")
2161 (t :inverse-video t
))
2162 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2164 :group
'custom-faces
)
2166 (defface custom-button-pressed-unraised
2167 '((default :inherit custom-button-unraised
)
2168 (((class color
) (background light
)) :foreground
"magenta4")
2169 (((class color
) (background dark
)) :foreground
"violet"))
2170 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2172 :group
'custom-faces
)
2174 (setq custom-button-pressed
2175 (if custom-raised-buttons
2176 'custom-button-pressed
2177 'custom-button-pressed-unraised
))
2179 (defface custom-documentation
'((t nil
))
2180 "Face used for documentation strings in customization buffers."
2181 :group
'custom-faces
)
2183 (defface custom-state
'((((class color
) (background dark
))
2184 :foreground
"lime green")
2185 (((class color
) (background light
))
2186 :foreground
"dark green"))
2187 "Face used for State descriptions in the customize buffer."
2188 :group
'custom-faces
)
2190 (defface custom-link
'((t :inherit link
))
2191 "Face for links in customization buffers."
2193 :group
'custom-faces
)
2195 (define-widget 'custom
'default
2196 "Customize a user option."
2198 :convert-widget
'custom-convert-widget
2199 :notify
'custom-notify
2202 :custom-state
'hidden
2203 :documentation-property
'widget-subclass-responsibility
2204 :value-create
'widget-subclass-responsibility
2205 :value-delete
'widget-children-value-delete
2206 :value-get
'widget-value-value-get
2207 :validate
'widget-children-validate
2208 :match
(lambda (_widget value
) (symbolp value
)))
2210 (defun custom-convert-widget (widget)
2211 "Initialize :value and :tag from :args in WIDGET."
2212 (let ((args (widget-get widget
:args
)))
2214 (widget-put widget
:value
(widget-apply widget
2215 :value-to-internal
(car args
)))
2216 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2217 (widget-put widget
:args nil
)))
2220 (defun custom-notify (widget &rest args
)
2221 "Keep track of changes."
2222 (let ((state (widget-get widget
:custom-state
)))
2223 (unless (eq state
'modified
)
2224 (unless (memq state
'(nil unknown hidden
))
2225 (widget-put widget
:custom-state
'modified
))
2226 (custom-magic-reset widget
)
2227 (apply 'widget-default-notify widget args
))))
2229 (defun custom-redraw (widget)
2230 "Redraw WIDGET with current settings."
2231 (let ((line (count-lines (point-min) (point)))
2232 (column (current-column))
2234 (from (marker-position (widget-get widget
:from
)))
2235 (to (marker-position (widget-get widget
:to
))))
2237 (widget-value-set widget
(widget-value widget
))
2238 (custom-redraw-magic widget
))
2239 (when (and (>= pos from
) (<= pos to
))
2242 (goto-char (point-min))
2243 (forward-line (if (> column
0)
2246 (move-to-column column
))
2249 (defun custom-redraw-magic (widget)
2250 "Redraw WIDGET state with current settings."
2252 (let ((magic (widget-get widget
:custom-magic
)))
2254 (widget-value-set magic
(widget-value magic
))
2255 (when (setq widget
(widget-get widget
:group
))
2256 (custom-group-state-update widget
)))
2258 (setq widget nil
)))))
2261 (defun custom-show (widget value
)
2262 "Non-nil if WIDGET should be shown with VALUE by default."
2263 (declare (obsolete "this widget type is no longer supported." "24.1"))
2264 (let ((show (widget-get widget
:custom-show
)))
2265 (if (functionp show
)
2266 (funcall show widget value
)
2269 (defun custom-load-widget (widget)
2270 "Load all dependencies for WIDGET."
2271 (custom-load-symbol (widget-value widget
)))
2273 (defun custom-unloaded-symbol-p (symbol)
2274 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2276 (loads (get symbol
'custom-loads
))
2279 (setq load
(car loads
)
2281 (cond ((symbolp load
)
2282 (unless (featurep load
)
2284 ((assoc load load-history
))
2285 ((assoc (locate-library load
) load-history
)
2291 (defun custom-unloaded-widget-p (widget)
2292 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2293 (custom-unloaded-symbol-p (widget-value widget
)))
2295 (defun custom-toggle-hide (widget)
2296 "Toggle visibility of WIDGET."
2297 (custom-load-widget widget
)
2298 (let ((state (widget-get widget
:custom-state
)))
2299 (cond ((memq state
'(invalid modified set
))
2300 (error "There are unsaved changes"))
2302 (widget-put widget
:custom-state
'unknown
))
2304 (widget-put widget
:documentation-shown nil
)
2305 (widget-put widget
:custom-state
'hidden
)))
2306 (custom-redraw widget
)
2309 (defun custom-toggle-parent (widget &rest _ignore
)
2310 "Toggle visibility of parent of WIDGET."
2311 (custom-toggle-hide (widget-get widget
:parent
)))
2313 (defun custom-add-see-also (widget &optional prefix
)
2314 "Add `See also ...' to WIDGET if there are any links.
2315 Insert PREFIX first if non-nil."
2316 (let* ((symbol (widget-get widget
:value
))
2317 (links (get symbol
'custom-links
))
2318 (many (> (length links
) 2))
2319 (buttons (widget-get widget
:buttons
))
2320 (indent (widget-get widget
:indent
)))
2323 (insert-char ?\s indent
))
2326 (insert "See also ")
2328 (push (widget-create-child-and-convert
2330 :button-face
'custom-link
2331 :mouse-face
'highlight
2332 :pressed-face
'highlight
)
2334 (setq links
(cdr links
))
2343 (widget-put widget
:buttons buttons
))))
2345 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string
)
2346 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2347 The value is non-nil if any parents were found.
2348 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2349 (let ((name (widget-value widget
))
2350 (type (widget-type widget
))
2351 (buttons (widget-get widget
:buttons
))
2354 (insert (or initial-string
"Groups:"))
2355 (mapatoms (lambda (symbol)
2356 (when (member (list name type
) (get symbol
'custom-group
))
2358 (push (widget-create-child-and-convert
2359 widget
'custom-group-link
2360 :tag
(custom-unlispify-tag-name symbol
)
2363 (setq parents
(cons symbol parents
)))))
2366 (delete-region start
(point)))
2367 (widget-put widget
:buttons buttons
)
2370 ;;; The `custom-comment' Widget.
2372 ;; like the editable field
2373 (defface custom-comment
'((((type tty
))
2374 :background
"yellow3"
2375 :foreground
"black")
2376 (((class grayscale color
)
2378 :background
"gray85")
2379 (((class grayscale color
)
2381 :background
"dim gray")
2384 "Face used for comments on variables or faces."
2386 :group
'custom-faces
)
2388 ;; like font-lock-comment-face
2389 (defface custom-comment-tag
2390 '((((class color
) (background dark
)) :foreground
"gray80")
2391 (((class color
) (background light
)) :foreground
"blue4")
2392 (((class grayscale
) (background light
))
2393 :foreground
"DimGray" :weight bold
:slant italic
)
2394 (((class grayscale
) (background dark
))
2395 :foreground
"LightGray" :weight bold
:slant italic
)
2397 "Face used for the comment tag on variables or faces."
2398 :group
'custom-faces
)
2400 (define-widget 'custom-comment
'string
2403 :help-echo
"Edit a comment here."
2404 :sample-face
'custom-comment-tag
2405 :value-face
'custom-comment
2407 :create
'custom-comment-create
)
2409 (defun custom-comment-create (widget)
2410 (let* ((null-comment (equal "" (widget-value widget
))))
2411 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2413 (widget-default-create widget
)
2414 ;; `widget-default-delete' expects markers in these slots --
2415 ;; maybe it shouldn't.
2416 (widget-put widget
:from
(point-marker))
2417 (widget-put widget
:to
(point-marker)))))
2419 (defun custom-comment-hide (widget)
2420 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2422 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2423 ;; the global custom one
2424 (defun custom-comment-show (widget)
2425 (widget-put widget
:comment-shown t
)
2426 (custom-redraw widget
)
2429 (defun custom-comment-invisible-p (widget)
2430 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2432 (not (widget-get widget
:comment-shown
)))))
2434 ;;; The `custom-variable' Widget.
2436 (defface custom-variable-tag
2437 `((((class color
) (background dark
))
2438 :foreground
"light blue" :weight bold
)
2439 (((min-colors 88) (class color
) (background light
))
2440 :foreground
"blue1" :weight bold
)
2441 (((class color
) (background light
))
2442 :foreground
"blue" :weight bold
)
2444 "Face used for unpushable variable tags."
2445 :group
'custom-faces
)
2447 (defface custom-variable-button
'((t :underline t
:weight bold
))
2448 "Face used for pushable variable tags."
2449 :group
'custom-faces
)
2451 (defcustom custom-variable-default-form
'edit
2452 "Default form of displaying variable values."
2453 :type
'(choice (const edit
)
2455 :group
'custom-buffer
2458 (defun custom-variable-documentation (variable)
2459 "Return documentation of VARIABLE for use in Custom buffer.
2460 Normally just return the docstring. But if VARIABLE automatically
2461 becomes buffer local when set, append a message to that effect."
2462 (format "%s%s" (documentation-property variable
'variable-documentation t
)
2463 (if (and (local-variable-if-set-p variable
)
2464 (or (not (local-variable-p variable
))
2466 (local-variable-if-set-p variable
))))
2468 This variable automatically becomes buffer-local when set outside Custom.
2469 However, setting it through Custom sets the default value."
2472 (define-widget 'custom-variable
'custom
2473 "A widget for displaying a Custom variable.
2474 The following properties have special meanings for this widget:
2476 :hidden-states should be a list of widget states for which the
2477 widget's initial contents are to be hidden.
2479 :custom-form should be a symbol describing how to display and
2480 edit the variable---either `edit' (using edit widgets),
2481 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2482 if nil, use the return value of `custom-variable-default-form'.
2484 :shown-value, if non-nil, should be a list whose `car' is the
2485 variable value to display in place of the current value.
2487 :custom-style describes the widget interface style; nil is the
2488 default style, while `simple' means a simpler interface that
2489 inhibits the magic custom-state widget."
2491 :help-echo
"Set or reset this variable."
2492 :documentation-property
#'custom-variable-documentation
2493 :custom-category
'option
2495 :custom-menu
'custom-variable-menu-create
2497 :value-create
'custom-variable-value-create
2498 :action
'custom-variable-action
2499 :hidden-states
'(standard)
2500 :custom-set
'custom-variable-set
2501 :custom-mark-to-save
'custom-variable-mark-to-save
2502 :custom-reset-current
'custom-redraw
2503 :custom-reset-saved
'custom-variable-reset-saved
2504 :custom-reset-standard
'custom-variable-reset-standard
2505 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2506 :custom-standard-value
'custom-variable-standard-value
2507 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2509 (defun custom-variable-type (symbol)
2510 "Return a widget suitable for editing the value of SYMBOL.
2511 If SYMBOL has a `custom-type' property, use that.
2512 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2513 try matching its doc string against `custom-guess-doc-alist'."
2514 (let* ((type (or (get symbol
'custom-type
)
2515 (and (not (get symbol
'standard-value
))
2516 (custom-guess-type symbol
))
2518 (options (get symbol
'custom-options
))
2519 (tmp (if (listp type
)
2520 (copy-sequence type
)
2523 (widget-put tmp
:options options
))
2526 (defun custom-variable-value-create (widget)
2527 "Here is where you edit the variable's value."
2528 (custom-load-widget widget
)
2529 (unless (widget-get widget
:custom-form
)
2530 (widget-put widget
:custom-form custom-variable-default-form
))
2531 (let* ((buttons (widget-get widget
:buttons
))
2532 (children (widget-get widget
:children
))
2533 (form (widget-get widget
:custom-form
))
2534 (symbol (widget-get widget
:value
))
2535 (tag (widget-get widget
:tag
))
2536 (type (custom-variable-type symbol
))
2537 (conv (widget-convert type
))
2538 (get (or (get symbol
'custom-get
) 'default-value
))
2539 (prefix (widget-get widget
:custom-prefix
))
2540 (last (widget-get widget
:custom-last
))
2541 (style (widget-get widget
:custom-style
))
2542 (value (let ((shown-value (widget-get widget
:shown-value
)))
2545 ((default-boundp symbol
)
2546 (funcall get symbol
))
2547 (t (widget-get conv
:value
)))))
2548 (state (or (widget-get widget
:custom-state
)
2549 (if (memq (custom-variable-state symbol value
)
2550 (widget-get widget
:hidden-states
))
2553 ;; If we don't know the state, see if we need to edit it in lisp form.
2555 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2556 (when (eq state
'unknown
)
2557 (unless (widget-apply conv
:match value
)
2558 (setq form
'mismatch
)))
2559 ;; Now we can create the child widget.
2560 (cond ((eq custom-buffer-style
'tree
)
2561 (insert prefix
(if last
" `--- " " |--- "))
2562 (push (widget-create-child-and-convert
2563 widget
'custom-browse-variable-tag
)
2565 (insert " " tag
"\n")
2566 (widget-put widget
:buttons buttons
))
2568 ;; Indicate hidden value.
2569 (push (widget-create-child-and-convert
2570 widget
'custom-visibility
2571 :help-echo
"Show the value of this option."
2576 :action
'custom-toggle-hide-variable
2580 (push (widget-create-child-and-convert
2583 :sample-face
'custom-variable-tag
2587 ((memq form
'(lisp mismatch
))
2588 (push (widget-create-child-and-convert
2589 widget
'custom-visibility
2590 :help-echo
"Hide the value of this option."
2595 :action
'custom-toggle-hide-variable
2599 ;; This used to try presenting the saved value or the
2600 ;; standard value, but it seems more intuitive to present
2601 ;; the current value (Bug#7600).
2602 (let* ((value (cond ((default-boundp symbol
)
2603 (custom-quote (funcall get symbol
)))
2605 (custom-quote (widget-get conv
:value
))))))
2606 (insert (symbol-name symbol
) ": ")
2607 (push (widget-create-child-and-convert
2609 :button-face
'custom-variable-button-face
2611 :tag
(symbol-name symbol
)
2617 (push (widget-create-child-and-convert
2618 widget
'custom-visibility
2619 :help-echo
"Hide or show this option."
2624 :action
'custom-toggle-hide-variable
2628 (let* ((format (widget-get type
:format
))
2629 tag-format value-format
)
2630 (unless (string-match ":" format
)
2631 (error "Bad format"))
2632 (setq tag-format
(substring format
0 (match-end 0)))
2633 (setq value-format
(substring format
(match-end 0)))
2634 (push (widget-create-child-and-convert
2637 :action
'custom-tag-action
2638 :help-echo
"Change value of this option."
2639 :mouse-down-action
'custom-tag-mouse-down-action
2640 :button-face
'custom-variable-button
2641 :sample-face
'custom-variable-tag
2644 (push (widget-create-child-and-convert
2646 :format value-format
2649 (unless (eq custom-buffer-style
'tree
)
2650 (unless (eq (preceding-char) ?
\n)
2651 (widget-insert "\n"))
2652 ;; Create the magic button.
2653 (unless (eq style
'simple
)
2654 (let ((magic (widget-create-child-and-convert
2655 widget
'custom-magic nil
)))
2656 (widget-put widget
:custom-magic magic
)
2657 (push magic buttons
)))
2658 (widget-put widget
:buttons buttons
)
2659 ;; Insert documentation.
2660 (widget-put widget
:documentation-indent
3)
2661 (unless (and (eq style
'simple
)
2663 (widget-add-documentation-string-button
2664 widget
:visibility-widget
'custom-visibility
))
2666 ;; The comment field
2667 (unless (eq state
'hidden
)
2668 (let* ((comment (get symbol
'variable-comment
))
2670 (widget-create-child-and-convert
2671 widget
'custom-comment
2673 :value
(or comment
""))))
2674 (widget-put widget
:comment-widget comment-widget
)
2675 ;; Don't push it !!! Custom assumes that the first child is the
2677 (setq children
(append children
(list comment-widget
)))))
2678 ;; Update the rest of the properties.
2679 (widget-put widget
:custom-form form
)
2680 (widget-put widget
:children children
)
2681 ;; Now update the state.
2682 (if (eq state
'hidden
)
2683 (widget-put widget
:custom-state state
)
2684 (custom-variable-state-set widget
))
2686 (unless (eq state
'hidden
)
2687 (when (eq (widget-get widget
:custom-level
) 1)
2688 (custom-add-parent-links widget
))
2689 (custom-add-see-also widget
)))))
2691 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore
)
2692 "Toggle the visibility of a `custom-variable' parent widget.
2693 By default, this signals an error if the parent has unsaved
2694 changes. If the parent has a `simple' :custom-style property,
2695 the present value is saved to its :shown-value property instead."
2696 (let ((widget (widget-get visibility-widget
:parent
)))
2697 (unless (eq (widget-type widget
) 'custom-variable
)
2698 (error "Invalid widget type"))
2699 (custom-load-widget widget
)
2700 (let ((state (widget-get widget
:custom-state
)))
2701 (if (eq state
'hidden
)
2702 (widget-put widget
:custom-state
'unknown
)
2703 ;; In normal interface, widget can't be hidden if modified.
2704 (when (memq state
'(invalid modified set
))
2705 (if (eq (widget-get widget
:custom-style
) 'simple
)
2706 (widget-put widget
:shown-value
2709 (widget-get widget
:children
)))))
2710 (error "There are unsaved changes")))
2711 (widget-put widget
:documentation-shown nil
)
2712 (widget-put widget
:custom-state
'hidden
))
2713 (custom-redraw widget
)
2716 (defun custom-tag-action (widget &rest args
)
2717 "Pass :action to first child of WIDGET's parent."
2718 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2721 (defun custom-tag-mouse-down-action (widget &rest args
)
2722 "Pass :mouse-down-action to first child of WIDGET's parent."
2723 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2724 :mouse-down-action args
))
2726 (defun custom-variable-state (symbol val
)
2727 "Return the state of SYMBOL if its value is VAL.
2728 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2729 Possible return values are `standard', `saved', `set', `themed',
2730 `changed', and `rogue'."
2731 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2732 (value (if (default-boundp symbol
)
2733 (funcall get symbol
)
2735 (comment (get symbol
'variable-comment
))
2738 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2740 (get symbol
'customized-variable-comment
))
2742 (if (condition-case nil
2743 (and (equal value
(eval (car tmp
)))
2744 (equal comment temp
))
2748 ((progn (setq tmp
(get symbol
'theme-value
))
2749 (setq temp
(get symbol
'saved-variable-comment
))
2751 (if (condition-case nil
2752 (and (equal comment temp
)
2755 (car (custom-variable-theme-value
2759 ((eq (caar tmp
) 'user
) 'saved
)
2760 ((eq (caar tmp
) 'changed
)
2761 (if (condition-case nil
2765 (car (get symbol
'standard-value
)))))
2767 ;; The value was originally set outside
2768 ;; custom, but it was set to the standard
2769 ;; value (probably an autoloaded defcustom).
2774 ((setq tmp
(get symbol
'standard-value
))
2775 (if (condition-case nil
2776 (and (equal value
(eval (car tmp
)))
2777 (equal comment nil
))
2783 (defun custom-variable-state-set (widget &optional state
)
2784 "Set the state of WIDGET to STATE.
2785 If STATE is nil, the value is computed by `custom-variable-state'."
2786 (widget-put widget
:custom-state
2787 (or state
(custom-variable-state (widget-value widget
)
2788 (widget-get widget
:value
)))))
2790 (defun custom-variable-standard-value (widget)
2791 (get (widget-value widget
) 'standard-value
))
2793 (defvar custom-variable-menu
2794 `(("Set for Current Session" custom-variable-set
2796 (eq (widget-get widget
:custom-state
) 'modified
)))
2797 ;; Note that in all the backquoted code in this file, we test
2798 ;; init-file-user rather than user-init-file. This is in case
2799 ;; cus-edit is loaded by something in site-start.el, because
2800 ;; user-init-file is not set at that stage.
2801 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2802 ,@(when (or custom-file init-file-user
)
2803 '(("Save for Future Sessions" custom-variable-save
2805 (memq (widget-get widget
:custom-state
)
2806 '(modified set changed rogue
))))))
2807 ("Undo Edits" custom-redraw
2809 (and (default-boundp (widget-value widget
))
2810 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2811 ("Revert This Session's Customization" custom-variable-reset-saved
2813 (memq (widget-get widget
:custom-state
)
2814 '(modified set changed rogue
))))
2815 ,@(when (or custom-file init-file-user
)
2816 '(("Erase Customization" custom-variable-reset-standard
2818 (and (get (widget-value widget
) 'standard-value
)
2819 (memq (widget-get widget
:custom-state
)
2820 '(modified set changed saved rogue
)))))))
2821 ("Set to Backup Value" custom-variable-reset-backup
2823 (get (widget-value widget
) 'backup-value
)))
2824 ("---" ignore ignore
)
2825 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2826 ("---" ignore ignore
)
2827 ("Show Current Value" custom-variable-edit
2829 (eq (widget-get widget
:custom-form
) 'lisp
)))
2830 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2832 (eq (widget-get widget
:custom-form
) 'edit
))))
2833 "Alist of actions for the `custom-variable' widget.
2834 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2835 the menu entry, ACTION is the function to call on the widget when the
2836 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2837 widget as an argument, and returns non-nil if ACTION is valid on that
2838 widget. If FILTER is nil, ACTION is always valid.")
2840 (defun custom-variable-action (widget &optional event
)
2841 "Show the menu for `custom-variable' WIDGET.
2842 Optional EVENT is the location for the menu."
2843 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2844 (custom-toggle-hide widget
)
2845 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2846 (custom-variable-state-set widget
))
2847 (custom-redraw-magic widget
)
2848 (let* ((completion-ignore-case t
)
2849 (answer (widget-choose (concat "Operation on "
2850 (custom-unlispify-tag-name
2851 (widget-get widget
:value
)))
2852 (custom-menu-filter custom-variable-menu
2856 (funcall answer widget
)))))
2858 (defun custom-variable-edit (widget)
2859 "Edit value of WIDGET."
2860 (widget-put widget
:custom-state
'unknown
)
2861 (widget-put widget
:custom-form
'edit
)
2862 (custom-redraw widget
))
2864 (defun custom-variable-edit-lisp (widget)
2865 "Edit the Lisp representation of the value of WIDGET."
2866 (widget-put widget
:custom-state
'unknown
)
2867 (widget-put widget
:custom-form
'lisp
)
2868 (custom-redraw widget
))
2870 (defun custom-variable-set (widget)
2871 "Set the current value for the variable being edited by WIDGET."
2872 (let* ((form (widget-get widget
:custom-form
))
2873 (state (widget-get widget
:custom-state
))
2874 (child (car (widget-get widget
:children
)))
2875 (symbol (widget-value widget
))
2876 (set (or (get symbol
'custom-set
) 'set-default
))
2877 (comment-widget (widget-get widget
:comment-widget
))
2878 (comment (widget-value comment-widget
))
2880 (cond ((eq state
'hidden
)
2881 (user-error "Cannot set hidden variable"))
2882 ((setq val
(widget-apply child
:validate
))
2883 (goto-char (widget-get val
:from
))
2884 (error "%s" (widget-get val
:error
)))
2885 ((memq form
'(lisp mismatch
))
2886 (when (equal comment
"")
2888 ;; Make the comment invisible by hand if it's empty
2889 (custom-comment-hide comment-widget
))
2890 (custom-variable-backup-value widget
)
2891 (custom-push-theme 'theme-value symbol
'user
2892 'set
(custom-quote (widget-value child
)))
2893 (funcall set symbol
(eval (setq val
(widget-value child
))))
2894 (put symbol
'customized-value
(list val
))
2895 (put symbol
'variable-comment comment
)
2896 (put symbol
'customized-variable-comment comment
))
2898 (when (equal comment
"")
2900 ;; Make the comment invisible by hand if it's empty
2901 (custom-comment-hide comment-widget
))
2902 (custom-variable-backup-value widget
)
2903 (custom-push-theme 'theme-value symbol
'user
2904 'set
(custom-quote (widget-value child
)))
2905 (funcall set symbol
(setq val
(widget-value child
)))
2906 (put symbol
'customized-value
(list (custom-quote val
)))
2907 (put symbol
'variable-comment comment
)
2908 (put symbol
'customized-variable-comment comment
)))
2909 (custom-variable-state-set widget
)
2910 (custom-redraw-magic widget
)))
2912 (defun custom-variable-mark-to-save (widget)
2913 "Set value and mark for saving the variable edited by WIDGET."
2914 (let* ((form (widget-get widget
:custom-form
))
2915 (state (widget-get widget
:custom-state
))
2916 (child (car (widget-get widget
:children
)))
2917 (symbol (widget-value widget
))
2918 (set (or (get symbol
'custom-set
) 'set-default
))
2919 (comment-widget (widget-get widget
:comment-widget
))
2920 (comment (widget-value comment-widget
))
2922 (cond ((eq state
'hidden
)
2923 (user-error "Cannot set hidden variable"))
2924 ((setq val
(widget-apply child
:validate
))
2925 (goto-char (widget-get val
:from
))
2926 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2927 ((memq form
'(lisp mismatch
))
2928 (when (equal comment
"")
2930 ;; Make the comment invisible by hand if it's empty
2931 (custom-comment-hide comment-widget
))
2932 (put symbol
'saved-value
(list (widget-value child
)))
2933 (custom-push-theme 'theme-value symbol
'user
2934 'set
(custom-quote (widget-value child
)))
2935 (funcall set symbol
(eval (widget-value child
)))
2936 (put symbol
'variable-comment comment
)
2937 (put symbol
'saved-variable-comment comment
))
2939 (when (equal comment
"")
2941 ;; Make the comment invisible by hand if it's empty
2942 (custom-comment-hide comment-widget
))
2943 (put symbol
'saved-value
2944 (list (custom-quote (widget-value child
))))
2945 (custom-push-theme 'theme-value symbol
'user
2946 'set
(custom-quote (widget-value child
)))
2947 (funcall set symbol
(widget-value child
))
2948 (put symbol
'variable-comment comment
)
2949 (put symbol
'saved-variable-comment comment
)))
2950 (put symbol
'customized-value nil
)
2951 (put symbol
'customized-variable-comment nil
)))
2953 (defsubst custom-variable-state-set-and-redraw
(widget)
2954 "Set state of variable widget WIDGET and redraw with current settings."
2955 (custom-variable-state-set widget
)
2956 (custom-redraw-magic widget
))
2958 (defun custom-variable-save (widget)
2959 "Save value of variable edited by widget WIDGET."
2960 (custom-variable-mark-to-save widget
)
2962 (custom-variable-state-set-and-redraw widget
))
2964 (defun custom-variable-reset-saved (widget)
2965 "Restore the value of the variable being edited by WIDGET.
2966 If there is a saved value, restore it; otherwise reset to the
2967 uncustomized (themed or standard) value.
2969 Update the widget to show that value. The value that was current
2970 before this operation becomes the backup value."
2971 (let* ((symbol (widget-value widget
))
2972 (saved-value (get symbol
'saved-value
))
2973 (comment (get symbol
'saved-variable-comment
)))
2974 (custom-variable-backup-value widget
)
2975 (if (not (or saved-value comment
))
2976 ;; If there is no saved value, remove the setting.
2977 (custom-push-theme 'theme-value symbol
'user
'reset
)
2978 ;; Otherwise, apply the saved value.
2979 (put symbol
'variable-comment comment
)
2980 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe saved-value
))
2982 (funcall (or (get symbol
'custom-set
) 'set-default
)
2983 symbol
(eval (car saved-value
)))))
2984 (put symbol
'customized-value nil
)
2985 (put symbol
'customized-variable-comment nil
)
2986 (widget-put widget
:custom-state
'unknown
)
2987 ;; This call will possibly make the comment invisible
2988 (custom-redraw widget
)))
2990 (defun custom-variable-mark-to-reset-standard (widget)
2991 "Mark to restore standard setting for the variable edited by widget WIDGET.
2992 If `custom-reset-standard-variables-list' is nil, save, reset and
2993 redraw the widget immediately."
2994 (let* ((symbol (widget-value widget
)))
2995 (if (get symbol
'standard-value
)
2996 (custom-variable-backup-value widget
)
2997 (user-error "No standard setting known for %S" symbol
))
2998 (put symbol
'variable-comment nil
)
2999 (put symbol
'customized-value nil
)
3000 (put symbol
'customized-variable-comment nil
)
3001 (custom-push-theme 'theme-value symbol
'user
'reset
)
3002 (custom-theme-recalc-variable symbol
)
3003 (if (and custom-reset-standard-variables-list
3004 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
3006 (put symbol
'saved-value nil
)
3007 (put symbol
'saved-variable-comment nil
)
3008 ;; Append this to `custom-reset-standard-variables-list' to
3009 ;; have `custom-reset-standard-save-and-update' save setting
3010 ;; to the file, update the widget's state, and redraw it.
3011 (setq custom-reset-standard-variables-list
3012 (cons widget custom-reset-standard-variables-list
)))
3013 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
3014 (put symbol
'saved-value nil
)
3015 (put symbol
'saved-variable-comment nil
)
3017 (widget-put widget
:custom-state
'unknown
)
3018 ;; This call will possibly make the comment invisible
3019 (custom-redraw widget
))))
3021 (defun custom-variable-reset-standard (widget)
3022 "Restore standard setting for the variable edited by WIDGET.
3023 This operation eliminates any saved setting for the variable,
3024 restoring it to the state of a variable that has never been customized.
3025 The value that was current before this operation
3026 becomes the backup value, so you can get it again."
3027 (let (custom-reset-standard-variables-list)
3028 (custom-variable-mark-to-reset-standard widget
)))
3030 (defun custom-variable-backup-value (widget)
3031 "Back up the current value for WIDGET's variable.
3032 The backup value is kept in the car of the `backup-value' property."
3033 (let* ((symbol (widget-value widget
))
3034 (get (or (get symbol
'custom-get
) 'default-value
))
3035 (type (custom-variable-type symbol
))
3036 (conv (widget-convert type
))
3037 (value (if (default-boundp symbol
)
3038 (funcall get symbol
)
3039 (widget-get conv
:value
))))
3040 (put symbol
'backup-value
(list value
))))
3042 (defun custom-variable-reset-backup (widget)
3043 "Restore the backup value for the variable being edited by WIDGET.
3044 The value that was current before this operation
3045 becomes the backup value, so you can use this operation repeatedly
3046 to switch between two values."
3047 (let* ((symbol (widget-value widget
))
3048 (set (or (get symbol
'custom-set
) 'set-default
))
3049 (value (get symbol
'backup-value
))
3050 (comment-widget (widget-get widget
:comment-widget
))
3051 (comment (widget-value comment-widget
)))
3054 (custom-variable-backup-value widget
)
3055 (custom-push-theme 'theme-value symbol
'user
'set value
)
3057 (funcall set symbol
(car value
))
3059 (user-error "No backup value for %s" symbol
))
3060 (put symbol
'customized-value
(list (custom-quote (car value
))))
3061 (put symbol
'variable-comment comment
)
3062 (put symbol
'customized-variable-comment comment
)
3063 (custom-variable-state-set widget
)
3064 ;; This call will possibly make the comment invisible
3065 (custom-redraw widget
)))
3067 ;;; The `custom-visibility' Widget
3069 (define-widget 'custom-visibility
'visibility
3070 "Show or hide a documentation string."
3071 :button-face
'custom-visibility
3072 :pressed-face
'custom-visibility
3073 :mouse-face
'highlight
3074 :pressed-face
'highlight
3078 (defface custom-visibility
3079 '((t :height
0.8 :inherit link
))
3080 "Face for the `custom-visibility' widget."
3082 :group
'custom-faces
)
3084 ;;; The `custom-face-edit' Widget.
3086 (define-widget 'custom-face-edit
'checklist
3087 "Widget for editing face attributes.
3088 The following properties have special meanings for this widget:
3090 :value is a plist of face attributes.
3092 :default-face-attributes, if non-nil, is a plist of defaults for
3093 face attributes (as specified by a `default' defface entry)."
3096 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3097 :value-to-internal
'custom-face-edit-fix-value
3098 :match
(lambda (widget value
)
3099 (widget-checklist-match widget
3100 (custom-face-edit-fix-value widget value
)))
3101 :value-create
'custom-face-edit-value-create
3102 :convert-widget
'custom-face-edit-convert-widget
3103 :args
(mapcar (lambda (att)
3104 (list 'group
:inline t
3105 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3106 (list 'const
:format
"" :value
(nth 0 att
))
3108 custom-face-attributes
))
3110 (defun custom-face-edit-value-create (widget)
3111 (let* ((alist (widget-checklist-match-find
3112 widget
(widget-get widget
:value
)))
3113 (args (widget-get widget
:args
))
3114 (show-all (widget-get widget
:show-all-attributes
))
3115 (buttons (widget-get widget
:buttons
))
3116 (defaults (widget-checklist-match-find
3118 (widget-get widget
:default-face-attributes
)))
3120 (unless (looking-back "^ *" (line-beginning-position))
3122 (insert-char ?\s
(widget-get widget
:extra-offset
))
3123 (if (or alist defaults show-all
)
3125 (setq entry
(or (assq prop alist
)
3126 (assq prop defaults
)))
3127 (if (or entry show-all
)
3128 (widget-checklist-add-item widget prop entry
)))
3129 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3130 (let ((indent (widget-get widget
:indent
)))
3131 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3132 (push (widget-create-child-and-convert
3134 :help-echo
"Show or hide all face attributes."
3135 :button-face
'custom-visibility
3136 :pressed-face
'custom-visibility
3137 :mouse-face
'highlight
3138 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3139 :on-glyph nil
:off-glyph nil
3141 :action
'custom-face-edit-value-visibility-action
3145 (widget-put widget
:buttons buttons
)
3146 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3148 (defun custom-face-edit-value-visibility-action (widget &rest _ignore
)
3149 ;; Toggle hiding of face attributes.
3150 (let ((parent (widget-get widget
:parent
)))
3151 (widget-put parent
:show-all-attributes
3152 (not (widget-get parent
:show-all-attributes
)))
3153 (custom-redraw parent
)))
3155 (defun custom-face-edit-fix-value (_widget value
)
3156 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3157 Also change :reverse-video to :inverse-video."
3158 (custom-fix-face-spec value
))
3160 (defun custom-face-edit-convert-widget (widget)
3161 "Convert :args as widget types in WIDGET."
3164 :args
(mapcar (lambda (arg)
3166 :deactivate
'custom-face-edit-deactivate
3167 :activate
'custom-face-edit-activate
3168 :delete
'custom-face-edit-delete
))
3169 (widget-get widget
:args
)))
3172 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3173 "Converted version of the `custom-face-edit' widget.")
3175 (defun custom-face-edit-deactivate (widget)
3176 "Make face widget WIDGET inactive for user modifications."
3177 (unless (widget-get widget
:inactive
)
3178 (let ((tag (custom-face-edit-attribute-tag widget
))
3179 (from (copy-marker (widget-get widget
:from
)))
3180 (value (widget-value widget
))
3181 (inhibit-read-only t
)
3182 (inhibit-modification-hooks t
))
3185 (widget-default-delete widget
)
3186 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3187 (widget-put widget
:inactive
3188 (cons value
(cons from
(- (point) from
))))))))
3190 (defun custom-face-edit-activate (widget)
3191 "Make face widget WIDGET active for user modifications."
3192 (let ((inactive (widget-get widget
:inactive
))
3193 (inhibit-read-only t
)
3194 (inhibit-modification-hooks t
))
3195 (when (consp inactive
)
3197 (goto-char (car (cdr inactive
)))
3198 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3199 (widget-put widget
:inactive nil
)
3200 (widget-apply widget
:create
)
3201 (widget-value-set widget
(car inactive
))
3204 (defun custom-face-edit-delete (widget)
3205 "Remove WIDGET from the buffer."
3206 (let ((inactive (widget-get widget
:inactive
))
3207 (inhibit-read-only t
)
3208 (inhibit-modification-hooks t
))
3210 ;; Widget is alive, we don't have to do anything special
3211 (widget-default-delete widget
)
3212 ;; WIDGET is already deleted because we did so to deactivate it;
3213 ;; now just get rid of the label we put in its place.
3214 (delete-region (car (cdr inactive
))
3215 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3216 (widget-put widget
:inactive nil
))))
3219 (defun custom-face-edit-attribute-tag (widget)
3220 "Return the first :tag property in WIDGET or one of its children."
3221 (let ((tag (widget-get widget
:tag
)))
3222 (or (and (not (equal tag
"")) tag
)
3223 (let ((children (widget-get widget
:children
)))
3224 (while (and (null tag
) children
)
3225 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3228 ;;; The `custom-display' Widget.
3230 (define-widget 'custom-display
'menu-choice
3231 "Select a display type."
3234 :help-echo
"Specify frames where the face attributes should be used."
3235 :args
'((const :tag
"all" t
)
3236 (const :tag
"defaults" default
)
3238 :tag
"specific display"
3241 :args
((group :sibling-args
(:help-echo
"\
3242 Only match the specified window systems.")
3243 (const :format
"Type: "
3245 (checklist :inline t
3248 :sibling-args
(:help-echo
"\
3249 The X11 Window System.")
3251 (const :format
"PM "
3252 :sibling-args
(:help-echo
"\
3253 OS/2 Presentation Manager.")
3255 (const :format
"W32 "
3256 :sibling-args
(:help-echo
"\
3259 (const :format
"NS "
3260 :sibling-args
(:help-echo
"\
3261 GNUstep or Macintosh OS Cocoa interface.")
3263 (const :format
"DOS "
3264 :sibling-args
(:help-echo
"\
3267 (const :format
"TTY%n"
3268 :sibling-args
(:help-echo
"\
3269 Plain text terminals.")
3271 (group :sibling-args
(:help-echo
"\
3272 Only match the frames with the specified color support.")
3273 (const :format
"Class: "
3275 (checklist :inline t
3277 (const :format
"Color "
3278 :sibling-args
(:help-echo
"\
3279 Match color frames.")
3281 (const :format
"Grayscale "
3282 :sibling-args
(:help-echo
"\
3283 Match grayscale frames.")
3285 (const :format
"Monochrome%n"
3286 :sibling-args
(:help-echo
"\
3287 Match frames with no color support.")
3289 (group :sibling-args
(:help-echo
"\
3290 The minimum number of colors the frame should support.")
3291 (const :format
"" min-colors
)
3292 (integer :tag
"Minimum number of colors" ))
3293 (group :sibling-args
(:help-echo
"\
3294 Only match frames with the specified intensity.")
3296 Background brightness: "
3298 (checklist :inline t
3300 (const :format
"Light "
3301 :sibling-args
(:help-echo
"\
3302 Match frames with light backgrounds.")
3304 (const :format
"Dark\n"
3305 :sibling-args
(:help-echo
"\
3306 Match frames with dark backgrounds.")
3308 (group :sibling-args
(:help-echo
"\
3309 Only match frames that support the specified face attributes.")
3310 (const :format
"Supports attributes:" supports
)
3311 (custom-face-edit :inline t
:format
"%n%v"))))))
3313 ;;; The `custom-face' Widget.
3315 (defface custom-face-tag
3316 '((t :inherit custom-variable-tag
))
3317 "Face used for face tags."
3318 :group
'custom-faces
)
3320 (defcustom custom-face-default-form
'selected
3321 "Default form of displaying face definition."
3322 :type
'(choice (const all
)
3325 :group
'custom-buffer
3328 (define-widget 'custom-face
'custom
3329 "Widget for customizing a face.
3330 The following properties have special meanings for this widget:
3332 :value is the face name (a symbol).
3334 :custom-form should be a symbol describing how to display and
3335 edit the face attributes---either `selected' (attributes for
3336 selected display only), `all' (all attributes), `lisp' (as a
3337 Lisp sexp), or `mismatch' (should not happen); if nil, use
3338 the return value of `custom-face-default-form'.
3340 :custom-style describes the widget interface style; nil is the
3341 default style, while `simple' means a simpler interface that
3342 inhibits the magic custom-state widget.
3344 :sample-indent, if non-nil, is the number of columns to which to
3345 indent the face sample (an integer).
3347 :shown-value, if non-nil, is the face spec to display as the value
3348 of the widget, instead of the current face spec."
3349 :sample-face
'custom-face-tag
3350 :help-echo
"Set or reset this face."
3351 :documentation-property
#'face-doc-string
3352 :value-create
'custom-face-value-create
3353 :action
'custom-face-action
3354 :custom-category
'face
3356 :custom-set
'custom-face-set
3357 :custom-mark-to-save
'custom-face-mark-to-save
3358 :custom-reset-current
'custom-redraw
3359 :custom-reset-saved
'custom-face-reset-saved
3360 :custom-reset-standard
'custom-face-reset-standard
3361 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3362 :custom-standard-value
'custom-face-standard-value
3363 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3364 :custom-menu
'custom-face-menu-create
)
3366 (define-widget 'custom-face-all
'editable-list
3367 "An editable list of display specifications and attributes."
3368 :entry-format
"%i %d %v"
3369 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3370 :append-button-args
'(:help-echo
"Append new display specification here.")
3371 :delete-button-args
'(:help-echo
"Delete this display specification.")
3372 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3374 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3375 "Converted version of the `custom-face-all' widget.")
3377 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3378 "Return a canonicalized version of SPEC.
3379 FILTER-INDEX is the index in the entry for each attribute in
3380 `custom-face-attributes' at which the appropriate filter function can be
3381 found, and DEFAULT-FILTER is the filter to apply for attributes that
3383 (mapcar (lambda (entry)
3384 ;; Filter a single face-spec entry
3385 (let ((tests (car entry
))
3387 ;; Handle both old- and new-style attribute syntax
3388 (if (listp (car (cdr entry
)))
3391 (filtered-attrs nil
))
3392 ;; Filter each face attribute
3393 (while unfiltered-attrs
3394 (let* ((attr (pop unfiltered-attrs
))
3395 (pre-filtered-value (pop unfiltered-attrs
))
3397 (or (nth filter-index
(assq attr custom-face-attributes
))
3401 (funcall filter pre-filtered-value
)
3402 pre-filtered-value
)))
3403 (push filtered-value filtered-attrs
)
3404 (push attr filtered-attrs
)))
3406 (list tests filtered-attrs
)))
3409 (defun custom-pre-filter-face-spec (spec)
3410 "Return SPEC changed as necessary for editing by the face customization widget.
3411 SPEC must be a full face spec."
3412 (custom-filter-face-spec spec
2))
3414 (defun custom-post-filter-face-spec (spec)
3415 "Return the customized SPEC in a form suitable for setting the face."
3416 (custom-filter-face-spec spec
3))
3418 (defun custom-face-widget-to-spec (widget)
3419 "Return a face spec corresponding to WIDGET.
3420 WIDGET should be a `custom-face' widget."
3421 (unless (eq (widget-type widget
) 'custom-face
)
3422 (error "Invalid widget"))
3423 (let ((child (car (widget-get widget
:children
))))
3424 (custom-post-filter-face-spec
3425 (if (eq (widget-type child
) 'custom-face-edit
)
3426 `((t ,(widget-value child
)))
3427 (widget-value child
)))))
3429 (defun custom-face-get-current-spec (face)
3430 (let ((spec (or (get face
'customized-face
)
3431 (get face
'saved-face
)
3432 (get face
'face-defface-spec
)
3433 ;; Attempt to construct it.
3434 `((t ,(custom-face-attributes-get
3435 face
(selected-frame)))))))
3436 ;; If the user has changed this face in some other way,
3437 ;; edit it as the user has specified it.
3438 (if (not (face-spec-match-p face spec
(selected-frame)))
3439 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3440 (custom-pre-filter-face-spec spec
)))
3442 (defun custom-toggle-hide-face (visibility-widget &rest _ignore
)
3443 "Toggle the visibility of a `custom-face' parent widget.
3444 By default, this signals an error if the parent has unsaved
3445 changes. If the parent has a `simple' :custom-style property,
3446 the present value is saved to its :shown-value property instead."
3447 (let ((widget (widget-get visibility-widget
:parent
)))
3448 (unless (eq (widget-type widget
) 'custom-face
)
3449 (error "Invalid widget type"))
3450 (custom-load-widget widget
)
3451 (let ((state (widget-get widget
:custom-state
)))
3452 (if (eq state
'hidden
)
3453 (widget-put widget
:custom-state
'unknown
)
3454 ;; In normal interface, widget can't be hidden if modified.
3455 (when (memq state
'(invalid modified set
))
3456 (if (eq (widget-get widget
:custom-style
) 'simple
)
3457 (widget-put widget
:shown-value
3458 (custom-face-widget-to-spec widget
))
3459 (error "There are unsaved changes")))
3460 (widget-put widget
:documentation-shown nil
)
3461 (widget-put widget
:custom-state
'hidden
))
3462 (custom-redraw widget
)
3465 (defun custom-face-value-create (widget)
3466 "Create a list of the display specifications for WIDGET."
3467 (let* ((buttons (widget-get widget
:buttons
))
3468 (symbol (widget-get widget
:value
))
3469 (tag (or (widget-get widget
:tag
)
3470 (prin1-to-string symbol
)))
3471 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3472 (style (widget-get widget
:custom-style
))
3475 (if (eq custom-buffer-style
'tree
)
3477 ;; Draw a tree-style `custom-face' widget
3479 (insert (widget-get widget
:custom-prefix
)
3480 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3481 (push (widget-create-child-and-convert
3482 widget
'custom-browse-face-tag
)
3484 (insert " " tag
"\n")
3485 (widget-put widget
:buttons buttons
))
3487 ;; Draw an ordinary `custom-face' widget
3488 (let ((opoint (point)))
3489 ;; Visibility indicator.
3490 (push (widget-create-child-and-convert
3491 widget
'custom-visibility
3492 :help-echo
"Hide or show this face."
3493 :on
"Hide" :off
"Show"
3494 :on-glyph
"down" :off-glyph
"right"
3495 :action
'custom-toggle-hide-face
3500 (widget-specify-sample widget opoint
(point)))
3502 (cond ((eq custom-buffer-style
'face
) " ")
3503 ((string-match-p "face\\'" tag
) ":")
3507 (let ((sample-indent (widget-get widget
:sample-indent
))
3508 (indent-tabs-mode nil
))
3510 (<= (current-column) sample-indent
)
3511 (indent-to-column sample-indent
)))
3512 (push (widget-create-child-and-convert
3515 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3516 (if spec
(face-spec-choose spec
) symbol
))
3522 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3523 (let ((magic (widget-create-child-and-convert
3524 widget
'custom-magic nil
)))
3525 (widget-put widget
:custom-magic magic
)
3526 (push magic buttons
)))
3529 (widget-put widget
:buttons buttons
)
3531 ;; Insert documentation.
3532 (unless (and hiddenp
(eq style
'simple
))
3533 (widget-put widget
:documentation-indent
3)
3534 (widget-add-documentation-string-button
3535 widget
:visibility-widget
'custom-visibility
)
3536 ;; The comment field
3538 (let* ((comment (get symbol
'face-comment
))
3540 (widget-create-child-and-convert
3541 widget
'custom-comment
3543 :value
(or comment
""))))
3544 (widget-put widget
:comment-widget comment-widget
)
3545 (push comment-widget children
))))
3548 (unless (eq (preceding-char) ?
\n)
3551 (custom-load-widget widget
)
3552 (unless (widget-get widget
:custom-form
)
3553 (widget-put widget
:custom-form custom-face-default-form
))
3555 (let* ((spec (or (widget-get widget
:shown-value
)
3556 (custom-face-get-current-spec symbol
)))
3557 (form (widget-get widget
:custom-form
))
3558 (indent (widget-get widget
:indent
))
3559 face-alist face-entry spec-default spec-match editor
)
3561 ;; Find a display in SPEC matching the selected display.
3562 ;; This will use the usual face customization interface.
3563 (setq face-alist spec
)
3564 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3565 (setq spec-default
(pop face-alist
)))
3567 (while (and face-alist
(listp face-alist
) (null spec-match
))
3568 (setq face-entry
(car face-alist
))
3569 (and (listp face-entry
)
3570 (face-spec-set-match-display (car face-entry
)
3572 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3573 (setq spec-match face-entry
))
3574 (setq face-alist
(cdr face-alist
)))
3576 ;; Insert the appropriate editing widget.
3579 ((and (eq form
'selected
)
3580 (or spec-match spec-default
))
3581 (when indent
(insert-char ?\s indent
))
3582 (widget-create-child-and-convert
3583 widget
'custom-face-edit
3584 :value
(cadr spec-match
)
3585 :default-face-attributes
(cadr spec-default
)))
3586 ((and (not (eq form
'lisp
))
3587 (widget-apply custom-face-all
:match spec
))
3588 (widget-create-child-and-convert
3589 widget
'custom-face-all
:value spec
))
3592 (insert-char ?\s indent
))
3593 (widget-create-child-and-convert
3594 widget
'sexp
:value spec
))))
3595 (custom-face-state-set widget
)
3596 (push editor children
)
3597 (widget-put widget
:children children
))))))
3599 (defvar custom-face-menu
3600 `(("Set for Current Session" custom-face-set
)
3601 ,@(when (or custom-file init-file-user
)
3602 '(("Save for Future Sessions" custom-face-save
)))
3603 ("Undo Edits" custom-redraw
3605 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3606 ("Revert This Session's Customization" custom-face-reset-saved
3608 (memq (widget-get widget
:custom-state
) '(modified set changed
))))
3609 ,@(when (or custom-file init-file-user
)
3610 '(("Erase Customization" custom-face-reset-standard
3612 (get (widget-value widget
) 'face-defface-spec
)))))
3613 ("---" ignore ignore
)
3614 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3615 ("---" ignore ignore
)
3616 ("For Current Display" custom-face-edit-selected
3618 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3619 ("For All Kinds of Displays" custom-face-edit-all
3621 (not (eq (widget-get widget
:custom-form
) 'all
))))
3622 ("Show Lisp Expression" custom-face-edit-lisp
3624 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3625 "Alist of actions for the `custom-face' widget.
3626 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3627 the menu entry, ACTION is the function to call on the widget when the
3628 menu is selected, and FILTER is a predicate which takes a `custom-face'
3629 widget as an argument, and returns non-nil if ACTION is valid on that
3630 widget. If FILTER is nil, ACTION is always valid.")
3632 (defun custom-face-edit-selected (widget)
3633 "Edit selected attributes of the value of WIDGET."
3634 (widget-put widget
:custom-state
'unknown
)
3635 (widget-put widget
:custom-form
'selected
)
3636 (custom-redraw widget
))
3638 (defun custom-face-edit-all (widget)
3639 "Edit all attributes of the value of WIDGET."
3640 (widget-put widget
:custom-state
'unknown
)
3641 (widget-put widget
:custom-form
'all
)
3642 (custom-redraw widget
))
3644 (defun custom-face-edit-lisp (widget)
3645 "Edit the Lisp representation of the value of WIDGET."
3646 (widget-put widget
:custom-state
'unknown
)
3647 (widget-put widget
:custom-form
'lisp
)
3648 (custom-redraw widget
))
3650 (defun custom-face-state (face)
3651 "Return the current state of the face FACE.
3652 This is one of `set', `saved', `changed', `themed', or `rogue'."
3653 (let* ((comment (get face
'face-comment
))
3656 ((or (get face
'customized-face
)
3657 (get face
'customized-face-comment
))
3658 (if (equal (get face
'customized-face-comment
) comment
)
3661 ((or (get face
'saved-face
)
3662 (get face
'saved-face-comment
))
3663 (cond ((not (equal (get face
'saved-face-comment
) comment
))
3665 ((eq 'user
(caar (get face
'theme-face
)))
3667 ((eq 'changed
(caar (get face
'theme-face
)))
3670 ((get face
'face-defface-spec
)
3671 (cond (comment 'changed
)
3672 ((get face
'theme-face
) 'themed
)
3675 ;; If the user called set-face-attribute to change the default for
3676 ;; new frames, this face is "set outside of Customize".
3677 (if (and (not (eq state
'rogue
))
3678 (get face
'face-modified
))
3682 (defun custom-face-state-set (widget)
3683 "Set the state of WIDGET."
3684 (widget-put widget
:custom-state
3685 (custom-face-state (widget-value widget
))))
3687 (defun custom-face-action (widget &optional event
)
3688 "Show the menu for `custom-face' WIDGET.
3689 Optional EVENT is the location for the menu."
3690 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3691 (custom-toggle-hide widget
)
3692 (let* ((completion-ignore-case t
)
3693 (symbol (widget-get widget
:value
))
3694 (answer (widget-choose (concat "Operation on "
3695 (custom-unlispify-tag-name symbol
))
3696 (custom-menu-filter custom-face-menu
3700 (funcall answer widget
)))))
3702 (defun custom-face-set (widget)
3703 "Make the face attributes in WIDGET take effect."
3704 (let* ((symbol (widget-value widget
))
3705 (value (custom-face-widget-to-spec widget
))
3706 (comment-widget (widget-get widget
:comment-widget
))
3707 (comment (widget-value comment-widget
)))
3708 (when (equal comment
"")
3710 ;; Make the comment invisible by hand if it's empty
3711 (custom-comment-hide comment-widget
))
3712 (custom-push-theme 'theme-face symbol
'user
'set value
)
3713 (face-spec-set symbol value
'customized-face
)
3714 (put symbol
'face-comment comment
)
3715 (put symbol
'customized-face-comment comment
)
3716 (custom-face-state-set widget
)
3717 (custom-redraw-magic widget
)))
3719 (defun custom-face-mark-to-save (widget)
3720 "Mark for saving the face edited by WIDGET."
3721 (let* ((symbol (widget-value widget
))
3722 (value (custom-face-widget-to-spec widget
))
3723 (comment-widget (widget-get widget
:comment-widget
))
3724 (comment (widget-value comment-widget
))
3725 (standard (eq (widget-get widget
:custom-state
) 'standard
)))
3726 (when (equal comment
"")
3728 ;; Make the comment invisible by hand if it's empty
3729 (custom-comment-hide comment-widget
))
3730 (custom-push-theme 'theme-face symbol
'user
'set value
)
3731 (face-spec-set symbol value
(if standard
'reset
'saved-face
))
3732 (put symbol
'face-comment comment
)
3733 (put symbol
'customized-face-comment nil
)
3734 (put symbol
'saved-face-comment comment
)))
3736 (defsubst custom-face-state-set-and-redraw
(widget)
3737 "Set state of face widget WIDGET and redraw with current settings."
3738 (custom-face-state-set widget
)
3739 (custom-redraw-magic widget
))
3741 (defun custom-face-save (widget)
3742 "Save the face edited by WIDGET."
3743 (custom-face-mark-to-save widget
)
3745 (custom-face-state-set-and-redraw widget
))
3747 ;; For backward compatibility.
3748 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3751 (defun custom-face-reset-saved (widget)
3752 "Restore WIDGET to the face's default attributes.
3753 If there is a saved face, restore it; otherwise reset to the
3754 uncustomized (themed or standard) face."
3755 (let* ((face (widget-value widget
))
3756 (child (car (widget-get widget
:children
)))
3757 (saved-face (get face
'saved-face
))
3758 (comment (get face
'saved-face-comment
))
3759 (comment-widget (widget-get widget
:comment-widget
)))
3760 (custom-push-theme 'theme-face face
'user
3761 (if saved-face
'set
'reset
)
3763 (face-spec-set face saved-face
'saved-face
)
3764 (put face
'face-comment comment
)
3765 (put face
'customized-face-comment nil
)
3766 (widget-value-set child saved-face
)
3767 ;; This call manages the comment visibility
3768 (widget-value-set comment-widget
(or comment
""))
3769 (custom-face-state-set widget
)
3770 (custom-redraw widget
)))
3772 (defun custom-face-standard-value (widget)
3773 (get (widget-value widget
) 'face-defface-spec
))
3775 (defun custom-face-mark-to-reset-standard (widget)
3776 "Restore widget WIDGET to the face's standard attribute values.
3777 If `custom-reset-standard-faces-list' is nil, save, reset and
3778 redraw the widget immediately."
3779 (let* ((symbol (widget-value widget
))
3780 (child (car (widget-get widget
:children
)))
3781 (value (get symbol
'face-defface-spec
))
3782 (comment-widget (widget-get widget
:comment-widget
)))
3784 (user-error "No standard setting for this face"))
3785 (custom-push-theme 'theme-face symbol
'user
'reset
)
3786 (face-spec-set symbol value
'reset
)
3787 (put symbol
'face-comment nil
)
3788 (put symbol
'customized-face-comment nil
)
3789 (if (and custom-reset-standard-faces-list
3790 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3793 (put symbol
'saved-face nil
)
3794 (put symbol
'saved-face-comment nil
)
3795 ;; Append this to `custom-reset-standard-faces-list' and have
3796 ;; `custom-reset-standard-save-and-update' save setting to the
3797 ;; file, update the widget's state, and redraw it.
3798 (setq custom-reset-standard-faces-list
3799 (cons widget custom-reset-standard-faces-list
)))
3800 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3801 (put symbol
'saved-face nil
)
3802 (put symbol
'saved-face-comment nil
)
3804 (widget-value-set child
3805 (custom-pre-filter-face-spec
3806 (list (list t
(custom-face-attributes-get
3808 ;; This call manages the comment visibility
3809 (widget-value-set comment-widget
"")
3810 (custom-face-state-set widget
)
3811 (custom-redraw-magic widget
))))
3813 (defun custom-face-reset-standard (widget)
3814 "Restore WIDGET to the face's standard attribute values.
3815 This operation eliminates any saved attributes for the face,
3816 restoring it to the state of a face that has never been customized."
3817 (let (custom-reset-standard-faces-list)
3818 (custom-face-mark-to-reset-standard widget
)))
3820 ;;; The `face' Widget.
3822 (defvar widget-face-prompt-value-history nil
3823 "History of input to `widget-face-prompt-value'.")
3825 (define-widget 'face
'symbol
3826 "A Lisp face name (with sample)."
3827 :format
"%{%t%}: (%{sample%}) %v"
3830 :sample-face-get
'widget-face-sample-face-get
3831 :notify
'widget-face-notify
3832 :match
(lambda (_widget value
) (facep value
))
3833 :completions
(apply-partially #'completion-table-with-predicate
3834 obarray
#'facep
'strict
)
3835 :prompt-match
'facep
3836 :prompt-history
'widget-face-prompt-value-history
3837 :validate
(lambda (widget)
3838 (unless (facep (widget-value widget
))
3840 :error
(format "Invalid face: %S"
3841 (widget-value widget
)))
3844 (defun widget-face-sample-face-get (widget)
3845 (let ((value (widget-value widget
)))
3850 (defun widget-face-notify (widget child
&optional event
)
3851 "Update the sample, and notify the parent."
3852 (overlay-put (widget-get widget
:sample-overlay
)
3853 'face
(widget-apply widget
:sample-face-get
))
3854 (widget-default-notify widget child event
))
3857 ;;; The `hook' Widget.
3859 (define-widget 'hook
'list
3860 "An Emacs Lisp hook."
3861 :value-to-internal
(lambda (_widget value
)
3862 (if (and value
(symbolp value
))
3865 :match
(lambda (widget value
)
3867 (widget-group-match widget value
)))
3868 ;; Avoid adding undefined functions to the hook, especially for
3869 ;; things like `find-file-hook' or even more basic ones, to avoid
3871 :set
(lambda (symbol value
)
3874 (add-hook symbol elt
))))
3875 :convert-widget
'custom-hook-convert-widget
3878 (defun custom-hook-convert-widget (widget)
3879 ;; Handle `:options'.
3880 (let* ((options (widget-get widget
:options
))
3881 (other `(editable-list :inline t
3882 :entry-format
"%i %d%v"
3883 (function :format
" %v")))
3885 (list `(checklist :inline t
3886 ,@(mapcar (lambda (entry)
3887 `(function-item ,entry
))
3891 (widget-put widget
:args args
)
3894 ;;; The `custom-group-link' Widget.
3896 (define-widget 'custom-group-link
'link
3897 "Show parent in other window when activated."
3898 :button-face
'custom-link
3899 :mouse-face
'highlight
3900 :pressed-face
'highlight
3901 :help-echo
"Create customization buffer for this group."
3902 :keymap custom-mode-link-map
3903 :follow-link
'mouse-face
3904 :action
'custom-group-link-action
)
3906 (defun custom-group-link-action (widget &rest _ignore
)
3907 (customize-group (widget-value widget
)))
3909 ;;; The `custom-group' Widget.
3911 (defcustom custom-group-tag-faces nil
3912 "Face used for group tags.
3913 The first member is used for level 1 groups, the second for level 2,
3914 and so forth. The remaining group tags are shown with `custom-group-tag'."
3915 :type
'(repeat face
)
3916 :group
'custom-faces
)
3918 (defface custom-group-tag-1
3919 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3920 (((class color
) (background dark
)) :foreground
"pink")
3921 (((min-colors 88) (class color
) (background light
)) :foreground
"red1")
3922 (((class color
) (background light
)) :foreground
"red"))
3923 "Face for group tags."
3924 :group
'custom-faces
)
3926 (defface custom-group-tag
3927 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3928 (((class color
) (background dark
)) :foreground
"light blue")
3929 (((min-colors 88) (class color
) (background light
)) :foreground
"blue1")
3930 (((class color
) (background light
)) :foreground
"blue")
3932 "Face for low level group tags."
3933 :group
'custom-faces
)
3935 (defface custom-group-subtitle
3937 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3938 :group
'custom-faces
)
3940 (defvar custom-group-doc-align-col
20)
3942 (define-widget 'custom-group
'custom
3945 :sample-face-get
'custom-group-sample-face-get
3946 :documentation-property
'group-documentation
3947 :help-echo
"Set or reset all members of this group."
3948 :value-create
'custom-group-value-create
3949 :action
'custom-group-action
3950 :custom-category
'group
3951 :custom-set
'custom-group-set
3952 :custom-mark-to-save
'custom-group-mark-to-save
3953 :custom-reset-current
'custom-group-reset-current
3954 :custom-reset-saved
'custom-group-reset-saved
3955 :custom-reset-standard
'custom-group-reset-standard
3956 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3957 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3958 :custom-menu
'custom-group-menu-create
)
3960 (defun custom-group-sample-face-get (widget)
3961 ;; Use :sample-face.
3962 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3965 (define-widget 'custom-group-visibility
'visibility
3966 "An indicator and manipulator for hidden group contents."
3967 :create
'custom-group-visibility-create
)
3969 (defun custom-group-visibility-create (widget)
3970 (let ((visible (widget-value widget
)))
3972 (insert "--------")))
3973 (widget-default-create widget
))
3975 (defun custom-group-members (symbol groups-only
)
3976 "Return SYMBOL's custom group members.
3977 If GROUPS-ONLY is non-nil, return only those members that are groups."
3978 (if (not groups-only
)
3979 (get symbol
'custom-group
)
3981 (dolist (entry (get symbol
'custom-group
))
3982 (when (eq (nth 1 entry
) 'custom-group
)
3983 (push entry members
)))
3984 (nreverse members
))))
3986 (defun custom-group-value-create (widget)
3987 "Insert a customize group for WIDGET in the current buffer."
3988 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3989 (custom-load-widget widget
))
3990 (let* ((state (widget-get widget
:custom-state
))
3991 (level (widget-get widget
:custom-level
))
3992 ;; (indent (widget-get widget :indent))
3993 (prefix (widget-get widget
:custom-prefix
))
3994 (buttons (widget-get widget
:buttons
))
3995 (tag (substitute-command-keys (widget-get widget
:tag
)))
3996 (symbol (widget-value widget
))
3997 (members (custom-group-members symbol
3998 (and (eq custom-buffer-style
'tree
)
3999 custom-browse-only-groups
)))
4000 (doc (substitute-command-keys (widget-docstring widget
))))
4001 (cond ((and (eq custom-buffer-style
'tree
)
4003 (or members
(custom-unloaded-widget-p widget
)))
4004 (custom-browse-insert-prefix prefix
)
4005 (push (widget-create-child-and-convert
4006 widget
'custom-browse-visibility
4010 (push (widget-create-child-and-convert
4011 widget
'custom-browse-group-tag
)
4013 (insert " " tag
"\n")
4014 (widget-put widget
:buttons buttons
))
4015 ((and (eq custom-buffer-style
'tree
)
4016 (zerop (length members
)))
4017 (custom-browse-insert-prefix prefix
)
4019 (push (widget-create-child-and-convert
4020 widget
'custom-browse-group-tag
)
4022 (insert " " tag
"\n")
4023 (widget-put widget
:buttons buttons
))
4024 ((eq custom-buffer-style
'tree
)
4025 (custom-browse-insert-prefix prefix
)
4026 (if (zerop (length members
))
4028 (custom-browse-insert-prefix prefix
)
4030 ;; (widget-glyph-insert nil "[ ]" "empty")
4031 ;; (widget-glyph-insert nil "-- " "horizontal")
4032 (push (widget-create-child-and-convert
4033 widget
'custom-browse-group-tag
)
4035 (insert " " tag
"\n")
4036 (widget-put widget
:buttons buttons
))
4037 (push (widget-create-child-and-convert
4038 widget
'custom-browse-visibility
4039 ;; :tag-glyph "minus"
4043 ;; (widget-glyph-insert nil "-\\ " "top")
4044 (push (widget-create-child-and-convert
4045 widget
'custom-browse-group-tag
)
4047 (insert " " tag
"\n")
4048 (widget-put widget
:buttons buttons
)
4049 (message "Creating group...")
4050 (let* ((members (custom-sort-items
4052 ;; Never sort the top-level custom group.
4053 (unless (eq symbol
'emacs
)
4054 custom-browse-sort-alphabetically
)
4055 custom-browse-order-groups
))
4056 (prefixes (widget-get widget
:custom-prefixes
))
4057 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4058 (extra-prefix (if (widget-get widget
:custom-last
)
4061 (prefix (concat prefix extra-prefix
))
4064 (setq entry
(car members
)
4065 members
(cdr members
))
4066 (push (widget-create-child-and-convert
4067 widget
(nth 1 entry
)
4069 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4070 :custom-prefixes custom-prefix-list
4071 :custom-level
(1+ level
)
4072 :custom-last
(null members
)
4073 :value
(nth 0 entry
)
4074 :custom-prefix prefix
)
4076 (widget-put widget
:children
(reverse children
)))
4077 (message "Creating group...done")))
4080 ;; Create level indicator.
4082 (if (eq custom-buffer-style
'links
)
4083 (push (widget-create-child-and-convert
4084 widget
'custom-group-link
4088 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4090 (push (widget-create-child-and-convert
4091 widget
'custom-group-visibility
4092 :help-echo
"Show members of this group."
4093 :action
'custom-toggle-parent
4094 (not (eq state
'hidden
)))
4096 (if (>= (current-column) custom-group-doc-align-col
)
4098 ;; Create magic button.
4099 (let ((magic (widget-create-child-and-convert
4100 widget
'custom-magic nil
)))
4101 (widget-put widget
:custom-magic magic
)
4102 (push magic buttons
))
4104 (widget-put widget
:buttons buttons
)
4105 ;; Insert documentation.
4106 (if (and (eq custom-buffer-style
'links
) (> level
1))
4107 (widget-put widget
:documentation-indent
4108 custom-group-doc-align-col
))
4109 (widget-add-documentation-string-button
4110 widget
:visibility-widget
'custom-visibility
))
4114 ;; Draw a horizontal line (this works for both graphical
4115 ;; and text displays):
4118 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4119 (overlay-put (make-overlay p
(1+ p
))
4121 (propertize "\n" 'face
'(:underline t
)
4122 'display
'(space :align-to
999))))
4124 ;; Add parent groups references above the group.
4126 (if (custom-add-parent-links widget
"Parent groups:")
4128 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4130 (let ((start (point)))
4131 (insert tag
" group: ")
4132 (widget-specify-sample widget start
(point)))
4135 (insert " Group definition missing. "))
4136 ((< (length doc
) 50)
4138 ;; Create visibility indicator.
4139 (unless (eq custom-buffer-style
'links
)
4141 (push (widget-create-child-and-convert
4143 :help-echo
"Hide members of this group."
4144 :action
'custom-toggle-parent
4145 (not (eq state
'hidden
)))
4149 ;; Create magic button.
4150 (let ((magic (widget-create-child-and-convert
4151 widget
'custom-magic
4154 (widget-put widget
:custom-magic magic
)
4155 (push magic buttons
))
4157 (widget-put widget
:buttons buttons
)
4158 ;; Insert documentation.
4159 (when (and doc
(>= (length doc
) 50))
4160 (widget-add-documentation-string-button
4161 widget
:visibility-widget
'custom-visibility
))
4164 (if nil
;;; This should test that the buffer
4165 ;;; was not made to display a group.
4167 (insert-char ?\s custom-buffer-indent
)
4168 (custom-add-parent-links widget
)))
4169 (custom-add-see-also widget
4170 (make-string (* custom-buffer-indent level
)
4173 (message "Creating group...")
4174 (let* ((members (custom-sort-items
4176 ;; Never sort the top-level custom group.
4177 (unless (eq symbol
'emacs
)
4178 custom-buffer-sort-alphabetically
)
4179 custom-buffer-order-groups
))
4180 (prefixes (widget-get widget
:custom-prefixes
))
4181 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4182 (len (length members
))
4184 (reporter (make-progress-reporter
4185 "Creating group entries..." 0 len
))
4186 (have-subtitle (and (not (eq symbol
'emacs
))
4187 (eq custom-buffer-order-groups
'last
)))
4191 (dolist (entry members
)
4192 (unless (eq prev-type
'custom-group
)
4193 (widget-insert "\n"))
4194 (progress-reporter-update reporter
(setq count
(1+ count
)))
4195 (let ((sym (nth 0 entry
))
4196 (type (nth 1 entry
)))
4197 (when (and have-subtitle
(eq type
'custom-group
))
4198 (setq have-subtitle nil
)
4200 (propertize "Subgroups:\n" 'face
'custom-group-subtitle
)))
4201 (setq prev-type type
)
4202 (push (widget-create-child-and-convert
4205 :tag
(custom-unlispify-tag-name sym
)
4206 :custom-prefixes custom-prefix-list
4207 :custom-level
(1+ level
)
4210 (unless (eq (preceding-char) ?
\n)
4211 (widget-insert "\n"))))
4213 (setq children
(nreverse children
))
4214 (mapc 'custom-magic-reset children
)
4215 (widget-put widget
:children children
)
4216 (custom-group-state-update widget
)
4217 (progress-reporter-done reporter
))
4219 (let ((p (1+ (point))))
4221 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4222 (overlay-put (make-overlay p
(1+ p
))
4224 (propertize "\n" 'face
'(:underline t
)
4225 'display
'(space :align-to
999))))))))
4227 (defvar custom-group-menu
4228 `(("Set for Current Session" custom-group-set
4230 (eq (widget-get widget
:custom-state
) 'modified
)))
4231 ,@(when (or custom-file init-file-user
)
4232 '(("Save for Future Sessions" custom-group-save
4234 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4235 ("Undo Edits" custom-group-reset-current
4237 (memq (widget-get widget
:custom-state
) '(modified))))
4238 ("Revert This Session's Customizations" custom-group-reset-saved
4240 (memq (widget-get widget
:custom-state
) '(modified set
))))
4241 ,@(when (or custom-file init-file-user
)
4242 '(("Erase Customization" custom-group-reset-standard
4244 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4245 "Alist of actions for the `custom-group' widget.
4246 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4247 the menu entry, ACTION is the function to call on the widget when the
4248 menu is selected, and FILTER is a predicate which takes a `custom-group'
4249 widget as an argument, and returns non-nil if ACTION is valid on that
4250 widget. If FILTER is nil, ACTION is always valid.")
4252 (defun custom-group-action (widget &optional event
)
4253 "Show the menu for `custom-group' WIDGET.
4254 Optional EVENT is the location for the menu."
4255 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4256 (custom-toggle-hide widget
)
4257 (let* ((completion-ignore-case t
)
4258 (answer (widget-choose (concat "Operation on "
4259 (custom-unlispify-tag-name
4260 (widget-get widget
:value
)))
4261 (custom-menu-filter custom-group-menu
4265 (funcall answer widget
)))))
4267 (defun custom-group-set (widget)
4268 "Set changes in all modified group members."
4269 (dolist (child (widget-get widget
:children
))
4270 (when (eq (widget-get child
:custom-state
) 'modified
)
4271 (widget-apply child
:custom-set
))))
4273 (defun custom-group-mark-to-save (widget)
4274 "Mark all modified group members for saving."
4275 (dolist (child (widget-get widget
:children
))
4276 (when (memq (widget-get child
:custom-state
) '(modified set
))
4277 (widget-apply child
:custom-mark-to-save
))))
4279 (defsubst custom-group-state-set-and-redraw
(widget)
4280 "Set state of group widget WIDGET and redraw with current settings."
4281 (dolist (child (widget-get widget
:children
))
4282 (when (memq (widget-get child
:custom-state
) '(modified set
))
4283 (widget-apply child
:custom-state-set-and-redraw
))))
4285 (defun custom-group-save (widget)
4286 "Save all modified group members."
4287 (custom-group-mark-to-save widget
)
4289 (custom-group-state-set-and-redraw widget
))
4291 (defun custom-group-reset-current (widget)
4292 "Reset all modified group members."
4293 (dolist (child (widget-get widget
:children
))
4294 (when (eq (widget-get child
:custom-state
) 'modified
)
4295 (widget-apply child
:custom-reset-current
))))
4297 (defun custom-group-reset-saved (widget)
4298 "Reset all modified or set group members."
4299 (dolist (child (widget-get widget
:children
))
4300 (when (memq (widget-get child
:custom-state
) '(modified set
))
4301 (widget-apply child
:custom-reset-saved
))))
4303 (defun custom-group-reset-standard (widget)
4304 "Reset all modified, set, or saved group members."
4305 (let ((custom-reset-standard-variables-list '(t))
4306 (custom-reset-standard-faces-list '(t)))
4307 (custom-group-mark-to-reset-standard widget
)
4308 (custom-reset-standard-save-and-update)))
4310 (defun custom-group-mark-to-reset-standard (widget)
4311 "Mark to reset all modified, set, or saved group members."
4312 (dolist (child (widget-get widget
:children
))
4313 (when (memq (widget-get child
:custom-state
)
4314 '(modified set saved
))
4315 (widget-apply child
:custom-mark-to-reset-standard
))))
4317 (defun custom-group-state-update (widget)
4319 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4320 (let* ((children (widget-get widget
:children
))
4321 (states (mapcar (lambda (child)
4322 (widget-get child
:custom-state
))
4324 (magics custom-magic-alist
)
4327 (let ((magic (car (car magics
))))
4328 (if (and (not (eq magic
'hidden
))
4329 (memq magic states
))
4332 (setq magics
(cdr magics
)))))
4333 (widget-put widget
:custom-state found
)))
4334 (custom-magic-reset widget
))
4336 ;;; Reading and writing the custom file.
4339 (defcustom custom-file nil
4340 "File used for storing customization information.
4341 The default is nil, which means to use your init file
4342 as specified by `user-init-file'. If the value is not nil,
4343 it should be an absolute file name.
4345 You can set this option through Custom, if you carefully read the
4346 last paragraph below. However, usually it is simpler to write
4347 something like the following in your init file:
4349 \(setq custom-file \"~/.emacs-custom.el\")
4352 Note that both lines are necessary: the first line tells Custom to
4353 save all customizations in this file, but does not load it.
4355 When you change this variable outside Custom, look in the
4356 previous custom file (usually your init file) for the
4357 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4358 and copy them (whichever ones you find) to the new custom file.
4359 This will preserve your existing customizations.
4361 If you save this option using Custom, Custom will write all
4362 currently saved customizations, including the new one for this
4363 option itself, into the file you specify, overwriting any
4364 `custom-set-variables' and `custom-set-faces' forms already
4365 present in that file. It will not delete any customizations from
4366 the old custom file. You should do that manually if that is what you
4367 want. You also have to put something like (load \"CUSTOM-FILE\")
4368 in your init file, where CUSTOM-FILE is the actual name of the
4369 file. Otherwise, Emacs will not load the file when it starts up,
4370 and hence will not set `custom-file' to that file either."
4371 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4372 (file :format
"%t:%v%d"
4374 "Please read entire docstring below before setting \
4375 this through Custom.
4376 Click on \"More\" (or position point there and press RETURN)
4377 if only the first line of the docstring is shown."))
4380 (defun custom-file (&optional no-error
)
4381 "Return the file name for saving customizations."
4382 (if (or (null user-init-file
)
4383 (and (null custom-file
) init-file-had-error
))
4384 ;; Started with -q, i.e. the file containing Custom settings
4385 ;; hasn't been read. Saving settings there won't make much
4389 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4390 (file-chase-links (or custom-file user-init-file
))))
4392 ;; If recentf-mode is non-nil, this is defined.
4393 (declare-function recentf-expand-file-name
"recentf" (name))
4396 (defun custom-save-all ()
4397 "Save all customizations in `custom-file'."
4398 (when (and (null custom-file
) init-file-had-error
)
4399 (error "Cannot save customizations; init file was not fully loaded"))
4400 (let* ((filename (custom-file))
4405 (recentf-expand-file-name (custom-file)))
4408 (old-buffer (find-buffer-visiting filename
))
4411 (with-current-buffer (let ((find-file-visit-truename t
))
4413 (let ((delay-mode-hooks t
))
4414 (find-file-noselect filename
))))
4415 ;; We'll save using file-precious-flag, so avoid destroying
4416 ;; symlinks. (If we're not already visiting the buffer, this is
4417 ;; handled by find-file-visit-truename, above.)
4419 (setq old-buffer-name
(buffer-file-name))
4420 (set-visited-file-name (file-chase-links filename
)))
4422 (unless (eq major-mode
'emacs-lisp-mode
)
4423 (delay-mode-hooks (emacs-lisp-mode)))
4424 (let ((inhibit-read-only t
)
4427 (custom-save-variables)
4428 (custom-save-faces))
4429 (let ((file-precious-flag t
))
4433 (set-visited-file-name old-buffer-name
)
4434 (set-buffer-modified-p nil
))
4435 (kill-buffer (current-buffer))))))
4438 (defun customize-save-customized ()
4439 "Save all user options which have been set in this session."
4441 (mapatoms (lambda (symbol)
4442 (let ((face (get symbol
'customized-face
))
4443 (value (get symbol
'customized-value
))
4444 (face-comment (get symbol
'customized-face-comment
))
4446 (get symbol
'customized-variable-comment
)))
4448 (put symbol
'saved-face face
)
4449 (custom-push-theme 'theme-face symbol
'user
'set value
)
4450 (put symbol
'customized-face nil
))
4452 (put symbol
'saved-value value
)
4453 (custom-push-theme 'theme-value symbol
'user
'set value
)
4454 (put symbol
'customized-value nil
))
4455 (when variable-comment
4456 (put symbol
'saved-variable-comment variable-comment
)
4457 (put symbol
'customized-variable-comment nil
))
4459 (put symbol
'saved-face-comment face-comment
)
4460 (put symbol
'customized-face-comment nil
)))))
4461 ;; We really should update all custom buffers here.
4464 ;; Editing the custom file contents in a buffer.
4466 (defun custom-save-delete (symbol)
4467 "Delete all calls to SYMBOL from the contents of the current buffer.
4468 Leave point at the old location of the first such call,
4469 or (if there were none) at the end of the buffer.
4471 This function does not save the buffer."
4472 (goto-char (point-min))
4473 ;; Skip all whitespace and comments.
4474 (while (forward-comment 1))
4476 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4479 (while t
;; We exit this loop only via throw.
4480 ;; Skip all whitespace and comments.
4481 (while (forward-comment 1))
4482 (let ((start (point))
4483 (sexp (condition-case nil
4484 (read (current-buffer))
4485 (end-of-file (throw 'found nil
)))))
4486 (when (and (listp sexp
)
4487 (eq (car sexp
) symbol
))
4488 (delete-region start
(point))
4490 (setq first
(point)))))))
4493 ;; Move in front of local variables, otherwise long Custom
4494 ;; entries would make them ineffective.
4495 (let ((pos (point-max))
4496 (case-fold-search t
))
4498 (goto-char (point-max))
4499 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4501 (when (search-forward "Local Variables:" nil t
)
4502 (setq pos
(line-beginning-position))))
4505 (defvar sort-fold-case
) ; defined in sort.el
4507 (defun custom-save-variables ()
4508 "Save all customized variables in `custom-file'."
4510 (custom-save-delete 'custom-set-variables
)
4511 (let ((standard-output (current-buffer))
4512 (saved-list (make-list 1 0))
4514 ;; First create a sorted list of saved variables.
4517 (if (and (get symbol
'saved-value
)
4518 ;; ignore theme values
4519 (or (null (get symbol
'theme-value
))
4520 (eq 'user
(caar (get symbol
'theme-value
)))))
4521 (nconc saved-list
(list symbol
)))))
4522 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4525 (princ "(custom-set-variables
4526 ;; custom-set-variables was added by Custom.
4527 ;; If you edit it by hand, you could mess it up, so be careful.
4528 ;; Your init file should contain only one such instance.
4529 ;; If there is more than one, they won't work right.\n")
4530 (dolist (symbol saved-list
)
4531 (let ((spec (car-safe (get symbol
'theme-value
)))
4532 (value (get symbol
'saved-value
))
4533 (requests (get symbol
'custom-requests
))
4534 (now (and (not (custom-variable-p symbol
))
4536 (eq (get symbol
'force-value
)
4538 (comment (get symbol
'saved-variable-comment
)))
4539 ;; Check REQUESTS for validity.
4540 (dolist (request requests
)
4541 (when (and (symbolp request
) (not (featurep request
)))
4542 (message "Unknown requested feature: %s" request
)
4543 (setq requests
(delq request requests
))))
4544 ;; Is there anything customized about this variable?
4545 (when (or (and spec
(eq (car spec
) 'user
))
4547 (and (null spec
) (get symbol
'saved-value
)))
4548 ;; Output an element for this variable.
4549 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4550 ;; SYMBOL is the variable name.
4551 ;; VALUE-FORM is an expression to return the customized value.
4552 ;; NOW if non-nil means always set the variable immediately
4553 ;; when the customizations are reloaded. This is used
4554 ;; for rogue variables
4555 ;; REQUESTS is a list of packages to load before setting the
4556 ;; variable. Each element of it will be passed to `require'.
4557 ;; COMMENT is whatever comment the user has specified
4558 ;; with the customize facility.
4564 (let ((val (prin1-to-string (car value
))))
4565 (if (< (length val
) 60)
4567 (newline-and-indent)
4568 (let ((beginning-of-val (point)))
4571 (goto-char beginning-of-val
)
4572 (indent-pp-sexp 1)))))
4573 (when (or now requests comment
)
4576 (when (or requests comment
)
4586 (unless (looking-at-p "\n")
4589 (defun custom-save-faces ()
4590 "Save all customized faces in `custom-file'."
4592 (custom-save-delete 'custom-reset-faces
)
4593 (custom-save-delete 'custom-set-faces
)
4594 (let ((standard-output (current-buffer))
4595 (saved-list (make-list 1 0))
4597 ;; First create a sorted list of saved faces.
4600 (if (and (get symbol
'saved-face
)
4601 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4602 (nconc saved-list
(list symbol
)))))
4603 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4604 ;; The default face must be first, since it affects the others.
4605 (if (memq 'default saved-list
)
4606 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4609 (princ "(custom-set-faces
4610 ;; custom-set-faces was added by Custom.
4611 ;; If you edit it by hand, you could mess it up, so be careful.
4612 ;; Your init file should contain only one such instance.
4613 ;; If there is more than one, they won't work right.\n")
4614 (dolist (symbol saved-list
)
4615 (let ((spec (car-safe (get symbol
'theme-face
)))
4616 (value (get symbol
'saved-face
))
4617 (now (not (or (get symbol
'face-defface-spec
)
4618 (and (not (custom-facep symbol
))
4619 (not (get symbol
'force-face
))))))
4620 (comment (get symbol
'saved-face-comment
)))
4621 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4623 (and (null spec
) (get symbol
'saved-face
)))
4624 ;; Don't print default face here.
4631 (when (or now comment
)
4641 (unless (looking-at-p "\n")
4644 ;;; The Customize Menu.
4648 (defcustom custom-menu-nesting
2
4649 "Maximum nesting in custom menus."
4651 :group
'custom-menu
)
4653 (defun custom-face-menu-create (_widget symbol
)
4654 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4655 (vector (custom-unlispify-menu-entry symbol
)
4656 `(customize-face ',symbol
)
4659 (defun custom-variable-menu-create (_widget symbol
)
4660 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4661 (let ((type (get symbol
'custom-type
)))
4662 (unless (listp type
)
4663 (setq type
(list type
)))
4664 (if (and type
(widget-get type
:custom-menu
))
4665 (widget-apply type
:custom-menu symbol
)
4666 (vector (custom-unlispify-menu-entry symbol
)
4667 `(customize-variable ',symbol
)
4670 ;; Add checkboxes to boolean variable entries.
4671 (widget-put (get 'boolean
'widget-type
)
4672 :custom-menu
(lambda (_widget symbol
)
4673 (vector (custom-unlispify-menu-entry symbol
)
4674 `(customize-variable ',symbol
)
4676 ':selected symbol
)))
4678 (defun custom-group-menu-create (_widget symbol
)
4679 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4680 `( ,(custom-unlispify-menu-entry symbol t
)
4681 :filter
(lambda (&rest junk
)
4682 (let* ((menu (custom-menu-create ',symbol
)))
4683 (if (consp menu
) (cdr menu
) menu
)))))
4686 (defun custom-menu-create (symbol)
4687 "Create menu for customization group SYMBOL.
4688 The menu is in a format applicable to `easy-menu-define'."
4689 (let* ((deactivate-mark nil
)
4690 (item (vector (custom-unlispify-menu-entry symbol
)
4691 `(customize-group ',symbol
)
4693 (if (and (or (not (boundp 'custom-menu-nesting
))
4694 (>= custom-menu-nesting
0))
4696 (custom-load-symbol symbol
)
4697 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4698 (let ((custom-prefix-list (custom-prefix-add symbol
4699 custom-prefix-list
))
4700 (members (custom-sort-items (get symbol
'custom-group
)
4701 custom-menu-sort-alphabetically
4702 custom-menu-order-groups
)))
4703 `(,(custom-unlispify-menu-entry symbol t
)
4706 ,@(mapcar (lambda (entry)
4707 (widget-apply (if (listp (nth 1 entry
))
4709 (list (nth 1 entry
)))
4710 :custom-menu
(nth 0 entry
)))
4715 (defun customize-menu-create (symbol &optional name
)
4716 "Return a customize menu for customization group SYMBOL.
4717 If optional NAME is given, use that as the name of the menu.
4718 Otherwise the menu will be named `Customize'.
4719 The format is suitable for use with `easy-menu-define'."
4721 (setq name
"Customize"))
4723 :filter
(lambda (&rest junk
)
4724 (let ((menu (custom-menu-create ',symbol
)))
4725 (if (consp menu
) (cdr menu
) menu
)))))
4727 ;;; Toolbar and menubar support
4730 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4731 "Menu used in customization buffers."
4732 (nconc (list "Custom"
4733 (customize-menu-create 'customize
))
4734 (mapcar (lambda (arg)
4735 (let ((tag (nth 0 arg
))
4736 (command (nth 1 arg
))
4737 (active (nth 2 arg
))
4739 (vector tag command
:active
(eval active
) :help help
)))
4742 (defvar tool-bar-map
)
4744 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4745 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4746 ;;; we set this up lazily in `Custom-mode'.
4747 (defvar custom-tool-bar-map nil
4748 "Keymap for toolbar in Custom mode.")
4750 ;;; The Custom Mode.
4752 (defun Custom-no-edit (_pos &optional _event
)
4753 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4755 (error "You can't edit this part of the Custom buffer"))
4757 (defun Custom-newline (pos &optional event
)
4758 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4760 (let ((button (get-char-property pos
'button
)))
4761 ;; If there is no button at point, then use the one at the start
4762 ;; of the line, if it is a custom-group-link (bug#2298).
4764 (if (setq button
(get-char-property (line-beginning-position) 'button
))
4765 (or (eq (widget-type button
) 'custom-group-link
)
4766 (setq button nil
))))
4768 (widget-apply-action button event
)
4769 (error "You can't edit this part of the Custom buffer"))))
4771 (defun Custom-goto-parent ()
4772 "Go to the parent group listed at the top of this buffer.
4773 If several parents are listed, go to the first of them."
4776 (goto-char (point-min))
4777 (if (search-forward "\nParent groups: " nil t
)
4778 (let* ((button (get-char-property (point) 'button
))
4779 (parent (downcase (widget-get button
:tag
))))
4780 (customize-group parent
)))))
4782 (defcustom Custom-mode-hook nil
4783 "Hook called when entering Custom mode."
4785 :group
'custom-buffer
)
4787 (defun custom-state-buffer-message (widget)
4788 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4789 (message "To install your edits, invoke [State] and choose the Set operation")))
4791 (defun custom--initialize-widget-variables ()
4792 (setq-local widget-documentation-face
'custom-documentation
)
4793 (setq-local widget-button-face custom-button
)
4794 (setq-local widget-button-pressed-face custom-button-pressed
)
4795 (setq-local widget-mouse-face custom-button-mouse
)
4796 ;; We need this because of the "More" button on docstrings.
4797 ;; Otherwise clicking on "More" can push point offscreen, which
4798 ;; causes the window to recenter on point, which pushes the
4799 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4800 (setq-local widget-button-click-moves-point t
)
4801 ;; When possible, use relief for buttons, not bracketing. This test
4802 ;; may not be optimal.
4803 (when custom-raised-buttons
4804 (setq-local widget-push-button-prefix
"")
4805 (setq-local widget-push-button-suffix
"")
4806 (setq-local widget-link-prefix
"")
4807 (setq-local widget-link-suffix
""))
4808 (setq show-trailing-whitespace nil
))
4810 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4811 (define-derived-mode Custom-mode nil
"Custom"
4812 "Major mode for editing customization buffers.
4814 The following commands are available:
4817 Move to next button, link or editable field. \\[widget-forward]
4818 Move to previous button, link or editable field. \\[widget-backward]
4819 \\<custom-field-keymap>\
4820 Complete content of editable text field. \\[widget-complete]
4821 \\<custom-mode-map>\
4822 Invoke button under the mouse pointer. \\[widget-button-click]
4823 Invoke button under point. \\[widget-button-press]
4824 Set all options from current text. \\[Custom-set]
4825 Make values in current text permanent. \\[Custom-save]
4826 Make text match actual option values. \\[Custom-reset-current]
4827 Reset options to permanent settings. \\[Custom-reset-saved]
4828 Erase customizations; set options
4829 and buffer text to the standard values. \\[Custom-reset-standard]
4831 Entry to this mode calls the value of `Custom-mode-hook'
4832 if that value is non-nil."
4833 (use-local-map custom-mode-map
)
4834 (easy-menu-add Custom-mode-menu
)
4835 (setq-local tool-bar-map
4836 (or custom-tool-bar-map
4837 ;; Set up `custom-tool-bar-map'.
4838 (let ((map (make-sparse-keymap)))
4841 (tool-bar-local-item-from-menu
4842 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4843 :label
(nth 5 arg
)))
4845 (setq custom-tool-bar-map map
))))
4846 (make-local-variable 'custom-options
)
4847 (make-local-variable 'custom-local-buffer
)
4848 (custom--initialize-widget-variables)
4849 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4851 (put 'Custom-mode
'mode-class
'special
)
4853 (define-obsolete-function-alias 'custom-mode
'Custom-mode
"23.1")
4855 (add-to-list 'debug-ignored-errors
"^Invalid face:? ")
4861 ;;; cus-edit.el ends here