1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages -*- lexical-binding:t -*-
3 ;; Copyright (C) 1996-1997, 1999-2018 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 <https://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.
179 Use group `text' for this instead. This group is deprecated."
183 "Support for editing text files."
185 ;; Inherit from deprecated `wp' for compatibility, for now.
189 "Support for editing binary data files."
193 "Abbreviation handling, typing shortcuts, macros."
197 (defgroup matching nil
198 "Various sorts of searching and matching."
201 (defgroup emulations nil
202 "Emulations of other editors."
203 :link
'(custom-manual "(emacs)Emulation")
206 (defgroup external nil
207 "Interfacing to external utilities."
211 "Communications, networking, and remote access to files."
215 (defgroup processes nil
216 "Process, subshell, compilation, and job control support."
219 (defgroup programming nil
220 "Support for programming in other languages."
223 (defgroup languages nil
224 "Modes for editing programming languages."
228 "Lisp support, including Emacs Lisp."
229 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
234 "Support for the C language and related languages."
235 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
236 :link
'(custom-manual "(ccmode)")
243 (defgroup applications nil
244 "Applications written in Emacs."
247 (defgroup calendar nil
248 "Calendar and time management support."
249 :group
'applications
)
252 "Modes for electronic-mail handling."
253 :group
'applications
)
256 "Reading and posting to newsgroups."
257 :link
'(custom-manual "(gnus)")
258 :group
'applications
)
261 "Games, jokes and amusements."
262 :group
'applications
)
264 (defgroup development nil
265 "Support for further development of Emacs."
269 "Support for Emacs documentation."
272 (defgroup extensions nil
273 "Emacs Lisp language extensions."
276 (defgroup internal nil
277 "Code for Emacs internals, build process, defaults."
281 "Maintenance aids for the Emacs development group."
285 (defgroup environment nil
286 "Fitting Emacs with its environment."
289 (defgroup hardware nil
290 "Support for interfacing with miscellaneous hardware."
293 (defgroup terminals nil
294 "Support for terminal types."
298 "Interfaces, assistants, and emulators for UNIX features."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Code related to the TeX formatter."
317 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
321 "Support for multiple fonts."
325 "Support for Emacs help systems."
328 (defgroup multimedia nil
329 "Non-textual support, specifically images and sound."
333 "Code local to your site."
336 (defgroup customize
'((widgets custom-group
))
337 "Customization of the Customization support."
341 (defgroup custom-faces nil
342 "Faces used by customize."
346 (defgroup custom-browse nil
347 "Control customize browser."
351 (defgroup custom-buffer nil
352 "Control customize buffers."
356 (defgroup custom-menu nil
357 "Control customize menus."
362 "Storage allocation and gc for GNU Emacs Lisp interpreter."
363 :tag
"Storage Allocation"
367 "Undoing changes in buffers."
368 :link
'(custom-manual "(emacs)Undo")
371 (defgroup mode-line nil
372 "Contents of the mode line."
375 (defgroup editing-basics nil
376 "Most basic editing facilities."
379 (defgroup display nil
380 "How characters are displayed in buffers."
383 (defgroup execute nil
384 "Executing external commands."
387 (defgroup installation nil
388 "The Emacs installation."
396 "Internal Emacs limits."
400 "Debugging Emacs itself."
403 (defgroup keyboard nil
404 "Input from the keyboard."
408 "Input from the menus."
412 "Handling data from drag and drop."
415 (defgroup auto-save nil
416 "Preventing accidental loss of data."
419 (defgroup processes-basics nil
420 "Basic stuff dealing with processes."
424 "MULE Emacs internationalization."
427 (defgroup windows nil
428 "Windows within a frame."
429 :link
'(custom-manual "(emacs)Windows")
432 ;;; Custom mode keymaps
434 (defvar custom-mode-map
435 (let ((map (make-keymap)))
436 (set-keymap-parent map widget-keymap
)
437 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
438 (define-key map
"\^m" 'Custom-newline
)
439 (define-key map
" " 'scroll-up-command
)
440 (define-key map
[?\S-\
] 'scroll-down-command
)
441 (define-key map
"\177" 'scroll-down-command
)
442 (define-key map
"\C-c\C-c" 'Custom-set
)
443 (define-key map
"\C-x\C-s" 'Custom-save
)
444 (define-key map
"q" 'Custom-buffer-done
)
445 (define-key map
"u" 'Custom-goto-parent
)
446 (define-key map
"n" 'widget-forward
)
447 (define-key map
"p" 'widget-backward
)
449 "Keymap for `Custom-mode'.")
451 (defvar custom-mode-link-map
452 (let ((map (make-keymap)))
453 (set-keymap-parent map custom-mode-map
)
454 (define-key map
[down-mouse-2
] nil
)
455 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
456 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
458 "Local keymap for links in `Custom-mode'.")
460 (defvar custom-field-keymap
461 (let ((map (copy-keymap widget-field-keymap
)))
462 (define-key map
"\C-c\C-c" 'Custom-set
)
463 (define-key map
"\C-x\C-s" 'Custom-save
)
465 "Keymap used inside editable fields in customization buffers.")
467 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
471 (defun custom-split-regexp-maybe (regexp)
472 "If REGEXP is a string, split it to a list at `\\|'.
473 You can get the original back from the result with:
474 (mapconcat \\='identity result \"\\|\")
476 IF REGEXP is not a string, return it unchanged."
478 (split-string regexp
"\\\\|")
481 (defun custom-variable-prompt ()
482 "Prompt for a custom variable, defaulting to the variable at point.
483 Return a list suitable for use in `interactive'."
484 (let* ((v (variable-at-point))
485 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
486 (enable-recursive-minibuffers t
)
488 (setq val
(completing-read
489 (if default
(format "Customize variable (default %s): " default
)
490 "Customize variable: ")
491 obarray
'custom-variable-p t nil nil default
))
492 (list (if (equal val
"")
493 (if (symbolp v
) v nil
)
496 (defun custom-menu-filter (menu widget
)
497 "Convert MENU to the form used by `widget-choose'.
498 MENU should be in the same format as `custom-variable-menu'.
499 WIDGET is the widget to apply the filter entries of MENU on."
501 current name action filter
)
503 (setq current
(car menu
)
505 action
(nth 1 current
)
506 filter
(nth 2 current
)
508 (if (or (null filter
) (funcall filter widget
))
509 (push (cons name action
) result
)
515 (defvar custom-prefix-list nil
516 "List of prefixes that should be ignored by `custom-unlispify'.")
518 (defcustom custom-unlispify-menu-entries t
519 "Display menu entries as words instead of symbols if non-nil."
523 (defcustom custom-unlispify-remove-prefixes nil
524 "Non-nil means remove group prefixes from option names in buffer.
525 Discarding prefixes often leads to confusing names for options
526 and faces in Customize buffers, so do not set this to a non-nil
527 value unless you are sure you know what it does."
529 :group
'custom-buffer
532 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
533 "Convert SYMBOL into a menu entry."
534 (cond ((not custom-unlispify-menu-entries
)
535 (symbol-name symbol
))
536 ((get symbol
'custom-tag
)
538 (get symbol
'custom-tag
)
539 (concat (get symbol
'custom-tag
) "...")))
541 (with-current-buffer (get-buffer-create " *Custom-Work*")
543 (princ symbol
(current-buffer))
544 (goto-char (point-min))
545 (if custom-unlispify-remove-prefixes
546 (let ((prefixes custom-prefix-list
)
549 (setq prefix
(car prefixes
))
550 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
553 (delete-region (point-min) (point)))
554 (setq prefixes
(cdr prefixes
))))))
555 (subst-char-in-region (point-min) (point-max) ?- ?\s t
)
556 (capitalize-region (point-min) (point-max))
558 (goto-char (point-max))
562 (defcustom custom-unlispify-tag-names t
563 "Display tag names as words instead of symbols if non-nil."
564 :group
'custom-buffer
567 (defun custom-unlispify-tag-name (symbol)
568 "Convert SYMBOL into a menu entry."
569 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
570 (custom-unlispify-menu-entry symbol t
)))
572 (defun custom-prefix-add (symbol prefixes
)
573 "Add SYMBOL to list of ignored PREFIXES."
574 (cons (or (get symbol
'custom-prefix
)
575 (concat (symbol-name symbol
) "-"))
580 (defcustom custom-guess-name-alist
586 ("-function\\'" function
)
587 ("-functions\\'" (repeat function
))
588 ("-list\\'" (repeat sexp
))
589 ("-alist\\'" (alist :key-type sexp
:value-type sexp
)))
590 "Alist of (MATCH TYPE).
592 MATCH should be a regexp matching the name of a symbol, and TYPE should
593 be a widget suitable for editing the value of that symbol. The TYPE
594 of the first entry where MATCH matches the name of the symbol will be
597 This is used for guessing the type of variables not declared with
599 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
600 :group
'custom-buffer
)
602 (defcustom custom-guess-doc-alist
603 '(("\\`\\*?Non-nil " boolean
))
604 "Alist of (MATCH TYPE).
606 MATCH should be a regexp matching a documentation string, and TYPE
607 should be a widget suitable for editing the value of a variable with
608 that documentation string. The TYPE of the first entry where MATCH
609 matches the name of the symbol will be used.
611 This is used for guessing the type of variables not declared with
613 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
614 :group
'custom-buffer
)
616 (defun custom-guess-type (symbol)
617 "Guess a widget suitable for editing the value of SYMBOL.
618 This is done by matching SYMBOL with `custom-guess-name-alist' and
619 if that fails, the doc string with `custom-guess-doc-alist'."
620 (let ((name (symbol-name symbol
))
621 (names custom-guess-name-alist
)
624 (setq current
(car names
)
626 (when (string-match-p (nth 0 current
) name
)
627 (setq found
(nth 1 current
)
630 (let ((doc (documentation-property symbol
'variable-documentation t
))
631 (docs custom-guess-doc-alist
))
634 (setq current
(car docs
)
636 (when (string-match-p (nth 0 current
) doc
)
637 (setq found
(nth 1 current
)
644 (defcustom custom-browse-sort-alphabetically nil
645 "If non-nil, sort customization group alphabetically in `custom-browse'."
647 :group
'custom-browse
)
649 (defcustom custom-browse-order-groups nil
650 "If non-nil, order group members within each customization group.
651 If `first', order groups before non-groups.
652 If `last', order groups after non-groups."
653 :type
'(choice (const first
)
655 (const :tag
"none" nil
))
656 :group
'custom-browse
)
658 (defcustom custom-browse-only-groups nil
659 "If non-nil, show group members only within each customization group."
661 :group
'custom-browse
)
664 (defcustom custom-buffer-sort-alphabetically t
665 "Whether to sort customization groups alphabetically in Custom buffer."
667 :group
'custom-buffer
670 (defcustom custom-buffer-order-groups
'last
671 "If non-nil, order group members within each customization group.
672 If `first', order groups before non-groups.
673 If `last', order groups after non-groups."
674 :type
'(choice (const first
)
676 (const :tag
"none" nil
))
677 :group
'custom-buffer
)
680 (defcustom custom-menu-sort-alphabetically nil
681 "If non-nil, sort each customization group alphabetically in menus."
685 (defcustom custom-menu-order-groups
'first
686 "If non-nil, order group members within each customization group.
687 If `first', order groups before non-groups.
688 If `last', order groups after non-groups."
689 :type
'(choice (const first
)
691 (const :tag
"none" nil
))
694 (defun custom-sort-items (items sort-alphabetically order-groups
)
695 "Return a sorted copy of ITEMS.
696 ITEMS should be a list of `custom-group' properties.
697 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
698 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
699 groups after non-groups, if nil do not order groups at all."
700 (sort (copy-sequence items
)
702 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
703 (namea (nth 0 a
)) (nameb (nth 0 b
)))
704 (cond ((not order-groups
)
705 ;; Since we don't care about A and B order, maybe sort.
706 (when sort-alphabetically
707 (string-lessp namea nameb
)))
708 ((eq typea
'custom-group
)
709 ;; If B is also a group, maybe sort. Otherwise, order A and B.
710 (if (eq typeb
'custom-group
)
711 (when sort-alphabetically
712 (string-lessp namea nameb
))
713 (eq order-groups
'first
)))
714 ((eq typeb
'custom-group
)
715 ;; Since A cannot be a group, order A and B.
716 (eq order-groups
'last
))
718 ;; Since A and B cannot be groups, sort.
719 (string-lessp namea nameb
)))))))
721 ;;; Custom Mode Commands.
723 ;; This variable is used by `custom-tool-bar-map', or directly by
724 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
726 (defvar custom-commands
727 '((" Apply " Custom-set t
728 "Apply settings (for the current session only)."
731 (" Apply and Save " Custom-save
732 (or custom-file user-init-file
)
733 "Apply settings and save for future sessions."
736 (" Undo Edits " Custom-reset-current t
737 "Restore customization buffer to reflect existing settings."
740 (" Reset Customizations " Custom-reset-saved t
741 "Undo any settings applied only for the current session."
744 (" Erase Customizations " Custom-reset-standard
745 (or custom-file user-init-file
)
746 "Un-customize settings in this and future sessions."
749 (" Help for Customize " Custom-help t
750 "Get help for using Customize."
753 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
755 (defun Custom-help ()
756 "Read the node on Easy Customization in the Emacs manual."
758 (info "(emacs)Easy Customization"))
760 (defvar custom-reset-menu
761 '(("Undo Edits in Customization Buffer" . Custom-reset-current
)
762 ("Revert This Session's Customizations" . Custom-reset-saved
)
763 ("Erase Customizations" . Custom-reset-standard
))
764 "Alist of actions for the `Reset' button.
765 The key is a string containing the name of the action, the value is a
766 Lisp function taking the widget as an element which will be called
767 when the action is chosen.")
769 (defvar custom-options nil
770 "Customization widgets in the current buffer.")
772 (defun custom-command-apply (fun query
&optional strong-query
)
773 "Call function FUN on all widgets in `custom-options'.
774 If there is more than one widget, ask user for confirmation using
775 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
776 and `yes-or-no-p' otherwise. Return non-nil if the functionality
777 has been executed, nil otherwise."
778 (if (or (and (= 1 (length custom-options
))
779 (memq (widget-type (car custom-options
))
780 '(custom-variable custom-face
)))
781 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
782 (progn (mapc fun custom-options
) t
)
786 (defun Custom-set (&rest _ignore
)
787 "Set the current value of all edited settings in the buffer."
789 (custom-command-apply
791 (when (eq (widget-get child
:custom-state
) 'modified
)
792 (widget-apply child
:custom-set
)))
793 "Set all values according to this buffer? "))
795 (defun Custom-save (&rest _ignore
)
796 "Set all edited settings, then save all settings that have been set.
797 If a setting was edited and set before, this saves it. If a
798 setting was merely edited before, this sets it then saves it."
800 (when (custom-command-apply
802 (when (memq (widget-get child
:custom-state
)
803 '(modified set changed rogue
))
804 (widget-apply child
:custom-mark-to-save
)))
805 "Save all settings in this buffer? " t
)
806 ;; Save changes to buffer and redraw.
808 (dolist (child custom-options
)
809 (widget-apply child
:custom-state-set-and-redraw
))))
811 (defun custom-reset (_widget &optional event
)
812 "Select item from reset menu."
813 (let* ((completion-ignore-case t
)
814 (answer (widget-choose "Reset settings"
820 (defun Custom-reset-current (&rest _ignore
)
821 "Reset all edited settings in the buffer to show their current values."
823 (custom-command-apply
825 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
826 (widget-apply widget
:custom-reset-current
)))
827 "Reset all settings' buffer text to show current values? "))
829 (defun Custom-reset-saved (&rest _ignore
)
830 "Reset all edited or set settings in the buffer to their saved value.
831 This also shows the saved values in the buffer."
833 (custom-command-apply
835 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
836 (widget-apply widget
:custom-reset-saved
)))
837 "Reset all settings (current values and buffer text) to saved values? "))
839 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
840 ;; and `custom-group-reset-standard'. If these variables are nil, both
841 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
842 ;; save, reset and redraw the handled widget immediately. Otherwise,
843 ;; they add the widget to the corresponding list and leave it to
844 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
845 (defvar custom-reset-standard-variables-list nil
)
846 (defvar custom-reset-standard-faces-list nil
)
848 ;; The next function was excerpted from `custom-variable-reset-standard'
849 ;; and `custom-face-reset-standard' and is used to avoid calling
850 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
851 ;; one) when erasing all customizations.
852 (defun custom-reset-standard-save-and-update ()
853 "Save settings and redraw after erasing customizations."
854 (when (or (and custom-reset-standard-variables-list
855 (not (eq custom-reset-standard-variables-list
'(t))))
856 (and custom-reset-standard-faces-list
857 (not (eq custom-reset-standard-faces-list
'(t)))))
858 ;; Save settings to file.
860 ;; Set state of and redraw variables.
861 (dolist (widget custom-reset-standard-variables-list
)
862 (unless (eq widget t
)
863 (widget-put widget
:custom-state
'unknown
)
864 (custom-redraw widget
)))
865 ;; Set state of and redraw faces.
866 (dolist (widget custom-reset-standard-faces-list
)
867 (unless (eq widget t
)
868 (let* ((symbol (widget-value widget
))
869 (child (car (widget-get widget
:children
)))
870 (comment-widget (widget-get widget
:comment-widget
)))
871 (put symbol
'face-comment nil
)
872 (widget-value-set child
873 (custom-pre-filter-face-spec
874 (list (list t
(custom-face-attributes-get
876 ;; This call manages the comment visibility
877 (widget-value-set comment-widget
"")
878 (custom-face-state-set widget
)
879 (custom-redraw-magic widget
))))))
881 (defun Custom-reset-standard (&rest _ignore
)
882 "Erase all customizations (either current or saved) in current buffer.
883 The immediate result is to restore them to their standard values.
884 This operation eliminates any saved values for the group members,
885 making them as if they had never been customized at all."
887 ;; Bind these temporarily.
888 (let ((custom-reset-standard-variables-list '(t))
889 (custom-reset-standard-faces-list '(t)))
890 (if (custom-command-apply
892 (and (or (null (widget-get widget
:custom-standard-value
))
893 (widget-apply widget
:custom-standard-value
))
894 (memq (widget-get widget
:custom-state
)
895 '(modified set changed saved rogue
))
896 (widget-apply widget
:custom-mark-to-reset-standard
)))
897 "The settings will revert to their default values, in this
898 and future sessions. Really erase customizations? " t
)
899 (custom-reset-standard-save-and-update))))
901 ;;; The Customize Commands
903 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
904 "Prompt for a variable and a value and return them as a list.
905 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
906 prompt for the value. The %s escape in PROMPT-VAL is replaced with
907 the name of the variable.
909 If the variable has a `variable-interactive' property, that is used as if
910 it were the arg to `interactive' (which see) to interactively read the value.
912 If the variable has a `custom-type' property, it must be a widget and the
913 `:prompt-value' property of that widget will be used for reading the value.
914 If the variable also has a `custom-get' property, that is used for finding
915 the current value of the variable, otherwise `symbol-value' is used.
917 If optional COMMENT argument is non-nil, also prompt for a comment and return
918 it as the third element in the list."
919 (let* ((var (read-variable prompt-var
))
920 (minibuffer-help-form '(describe-variable var
))
922 (let ((prop (get var
'variable-interactive
))
923 (type (get var
'custom-type
))
924 (prompt (format prompt-val var
)))
926 (setq type
(list type
)))
928 ;; Use VAR's `variable-interactive' property
929 ;; as an interactive spec for prompting.
930 (call-interactively `(lambda (arg)
934 (widget-prompt-value type
938 (or (get var
'custom-get
) 'symbol-value
)
942 (eval-minibuffer prompt
))))))
945 (read-string "Comment: " (get var
'variable-comment
)))
949 (defun customize-set-value (variable value
&optional comment
)
950 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
952 If VARIABLE has a `variable-interactive' property, that is used as if
953 it were the arg to `interactive' (which see) to interactively read the value.
955 If VARIABLE has a `custom-type' property, it must be a widget and the
956 `:prompt-value' property of that widget will be used for reading the value.
958 If given a prefix (or a COMMENT argument), also prompt for a comment."
959 (interactive (custom-prompt-variable "Set variable: "
963 (cond ((string= comment
"")
964 (put variable
'variable-comment nil
))
966 (put variable
'variable-comment comment
)))
967 (set variable value
))
970 (defun customize-set-variable (variable value
&optional comment
)
971 "Set the default for VARIABLE to VALUE, and return VALUE.
972 VALUE is a Lisp object.
974 If VARIABLE has a `custom-set' property, that is used for setting
975 VARIABLE, otherwise `set-default' is used.
977 If VARIABLE has a `variable-interactive' property, that is used as if
978 it were the arg to `interactive' (which see) to interactively read the value.
980 If VARIABLE has a `custom-type' property, it must be a widget and the
981 `:prompt-value' property of that widget will be used for reading the value.
983 If given a prefix (or a COMMENT argument), also prompt for a comment."
984 (interactive (custom-prompt-variable "Set variable: "
985 "Set customized value for %s to: "
987 (custom-load-symbol variable
)
988 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
989 (funcall (or (get variable
'custom-set
) #'set-default
) variable value
)
990 (put variable
'customized-value
(list (custom-quote value
)))
991 (cond ((string= comment
"")
992 (put variable
'variable-comment nil
)
993 (put variable
'customized-variable-comment nil
))
995 (put variable
'variable-comment comment
)
996 (put variable
'customized-variable-comment comment
)))
1000 (defun customize-save-variable (variable value
&optional comment
)
1001 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1004 If VARIABLE has a `custom-set' property, that is used for setting
1005 VARIABLE, otherwise `set-default' is used.
1007 If VARIABLE has a `variable-interactive' property, that is used as if
1008 it were the arg to `interactive' (which see) to interactively read the value.
1010 If VARIABLE has a `custom-type' property, it must be a widget and the
1011 `:prompt-value' property of that widget will be used for reading the value.
1013 If given a prefix (or a COMMENT argument), also prompt for a comment."
1014 (interactive (custom-prompt-variable "Set and save variable: "
1015 "Set and save value for %s as: "
1016 current-prefix-arg
))
1017 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1018 (put variable
'saved-value
(list (custom-quote value
)))
1019 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1020 (cond ((string= comment
"")
1021 (put variable
'variable-comment nil
)
1022 (put variable
'saved-variable-comment nil
))
1024 (put variable
'variable-comment comment
)
1025 (put variable
'saved-variable-comment comment
)))
1026 (put variable
'customized-value nil
)
1027 (put variable
'customized-variable-comment nil
)
1030 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1032 (set variable value
))
1035 ;; Some parts of Emacs might prompt the user to save customizations,
1036 ;; during startup before customizations are loaded. This function
1037 ;; handles this corner case by avoiding calling `custom-save-variable'
1038 ;; too early, which could wipe out existing customizations.
1041 (defun customize-push-and-save (list-var elts
)
1042 "Add ELTS to LIST-VAR and save for future sessions, safely.
1043 ELTS should be a list. This function adds each entry to the
1044 value of LIST-VAR using `add-to-list'.
1046 If Emacs is initialized, call `customize-save-variable' to save
1047 the resulting list value now. Otherwise, add an entry to
1048 `after-init-hook' to save it after initialization."
1049 (dolist (entry elts
)
1050 (add-to-list list-var entry
))
1052 (let ((coding-system-for-read nil
))
1053 (customize-save-variable list-var
(eval list-var
)))
1054 (add-hook 'after-init-hook
1056 (customize-push-and-save list-var elts
)))))
1060 "Select a customization buffer which you can use to set user options.
1061 User options are structured into \"groups\".
1062 Initially the top-level group `Emacs' and its immediate subgroups
1063 are shown; the contents of those subgroups are initially hidden."
1065 (customize-group 'emacs
))
1068 (defun customize-mode (mode)
1069 "Customize options related to a major or minor mode.
1070 By default the current major mode is used. With a prefix
1071 argument or if the current major mode has no known group, prompt
1072 for the MODE to customize."
1075 (let ((completion-regexp-list '("-mode\\'"))
1076 (group (custom-group-of-mode major-mode
)))
1077 (if (and group
(not current-prefix-arg
))
1080 (completing-read (if group
1081 (format "Mode (default %s): " major-mode
)
1084 'custom-group-of-mode
1085 t nil nil
(if group
(symbol-name major-mode
))))))))
1086 (customize-group (custom-group-of-mode mode
)))
1088 (defun customize-read-group ()
1089 (let ((completion-ignore-case t
))
1090 (completing-read "Customize group (default emacs): "
1093 (or (and (get symbol
'custom-loads
)
1094 (not (get symbol
'custom-autoload
)))
1095 (get symbol
'custom-group
)))
1099 (defun customize-group (&optional group other-window
)
1100 "Customize GROUP, which must be a customization group.
1101 If OTHER-WINDOW is non-nil, display in another window."
1102 (interactive (list (customize-read-group)))
1103 (when (stringp group
)
1104 (if (string-equal "" group
)
1106 (setq group
(intern group
))))
1107 (let ((name (format "*Customize Group: %s*"
1108 (custom-unlispify-tag-name group
))))
1110 ((null (get-buffer name
))
1111 (funcall (if other-window
1112 'custom-buffer-create-other-window
1113 'custom-buffer-create
)
1114 (list (list group
'custom-group
))
1116 (concat " for group "
1117 (custom-unlispify-tag-name group
))))
1119 (switch-to-buffer-other-window name
))
1121 (pop-to-buffer-same-window name
)))))
1124 (defun customize-group-other-window (&optional group
)
1125 "Customize GROUP, which must be a customization group, in another window."
1126 (interactive (list (customize-read-group)))
1127 (customize-group group t
))
1130 (defalias 'customize-variable
'customize-option
)
1133 (defun customize-option (symbol)
1134 "Customize SYMBOL, which must be a user option."
1135 (interactive (custom-variable-prompt))
1137 (error "No variable specified"))
1138 (let ((basevar (indirect-variable symbol
)))
1139 (custom-buffer-create (list (list basevar
'custom-variable
))
1140 (format "*Customize Option: %s*"
1141 (custom-unlispify-tag-name basevar
)))
1142 (unless (eq symbol basevar
)
1143 (message "`%s' is an alias for `%s'" symbol basevar
))))
1146 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1149 (defun customize-option-other-window (symbol)
1150 "Customize SYMBOL, which must be a user option.
1151 Show the buffer in another window, but don't select it."
1152 (interactive (custom-variable-prompt))
1154 (error "No variable specified"))
1155 (let ((basevar (indirect-variable symbol
)))
1156 (custom-buffer-create-other-window
1157 (list (list basevar
'custom-variable
))
1158 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1159 (unless (eq symbol basevar
)
1160 (message "`%s' is an alias for `%s'" symbol basevar
))))
1162 (defvar customize-changed-options-previous-release
"25.3"
1163 "Version for `customize-changed-options' to refer back to by default.")
1165 ;; Packages will update this variable, so make it available.
1167 (defvar customize-package-emacs-version-alist nil
1168 "Alist mapping versions of a package to Emacs versions.
1169 We use this for packages that have their own names, but are released
1170 as part of Emacs itself.
1172 Each elements looks like this:
1174 (PACKAGE (PVERSION . EVERSION)...)
1176 Here PACKAGE is the name of a package, as a symbol. After
1177 PACKAGE come one or more elements, each associating a
1178 package version PVERSION with the first Emacs version
1179 EVERSION in which it (or a subsequent version of PACKAGE)
1180 was first released. Both PVERSION and EVERSION are strings.
1181 PVERSION should be a string that this package used in
1182 the :package-version keyword for `defcustom', `defgroup',
1185 For example, the MH-E package updates this alist as follows:
1187 (add-to-list \\='customize-package-emacs-version-alist
1188 \\='(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1189 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1190 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1191 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1193 The value of PACKAGE needs to be unique and it needs to match the
1194 PACKAGE value appearing in the :package-version keyword. Since
1195 the user might see the value in a error message, a good choice is
1196 the official name of the package, such as MH-E or Gnus.")
1199 (defalias 'customize-changed
'customize-changed-options
)
1202 (defun customize-changed-options (&optional since-version
)
1203 "Customize all settings whose meanings have changed in Emacs itself.
1204 This includes new user options and faces, and new customization
1205 groups, as well as older options and faces whose meanings or
1206 default values have changed since the previous major Emacs
1209 With argument SINCE-VERSION (a string), customize all settings
1210 that were added or redefined since that version."
1214 (read-from-minibuffer
1215 (format "Customize options changed, since version (default %s): "
1216 customize-changed-options-previous-release
))))
1217 (if (equal since-version
"")
1218 (setq since-version nil
)
1219 (unless (condition-case nil
1220 (numberp (read since-version
))
1222 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1223 (unless since-version
1224 (setq since-version customize-changed-options-previous-release
))
1226 ;; Load the information for versions since since-version. We use
1227 ;; custom-load-symbol for this.
1228 (put 'custom-versions-load-alist
'custom-loads nil
)
1229 (dolist (elt custom-versions-load-alist
)
1230 (if (customize-version-lessp since-version
(car elt
))
1231 (dolist (load (cdr elt
))
1232 (custom-add-load 'custom-versions-load-alist load
))))
1233 (custom-load-symbol 'custom-versions-load-alist
)
1234 (put 'custom-versions-load-alist
'custom-loads nil
)
1239 (let* ((package-version (get symbol
'custom-package-version
))
1241 (or (and package-version
1242 (customize-package-emacs-version symbol
1244 (get symbol
'custom-version
))))
1246 (when (customize-version-lessp since-version version
)
1247 (if (or (get symbol
'custom-group
)
1248 (get symbol
'group-documentation
))
1249 (push (list symbol
'custom-group
) found
))
1250 (if (custom-variable-p symbol
)
1251 (push (list symbol
'custom-variable
) found
))
1252 (if (custom-facep symbol
)
1253 (push (list symbol
'custom-face
) found
)))))))
1255 (custom-buffer-create (custom-sort-items found t
'first
)
1256 "*Customize Changed Options*")
1257 (user-error "No user option defaults have been changed since Emacs %s"
1260 (defun customize-package-emacs-version (symbol package-version
)
1261 "Return the Emacs version in which SYMBOL's meaning last changed.
1262 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1263 `customize-package-emacs-version-alist' to find the version of
1264 Emacs that is associated with version VERSION of PACKAGE."
1265 (let (package-versions emacs-version
)
1266 ;; Use message instead of error since we want user to be able to
1267 ;; see the rest of the symbols even if a package author has
1268 ;; botched things up.
1269 (cond ((not (listp package-version
))
1270 (message "Invalid package-version value for %s" symbol
))
1271 ((setq package-versions
(assq (car package-version
)
1272 customize-package-emacs-version-alist
))
1274 (cdr (assoc (cdr package-version
) package-versions
)))
1275 (unless emacs-version
1276 (message "%s version %s not found in %s" symbol
1277 (cdr package-version
)
1278 "customize-package-emacs-version-alist")))
1280 (message "Package %s version %s lists no corresponding Emacs version"
1281 (car package-version
)
1282 (cdr package-version
))))
1285 (defun customize-version-lessp (version1 version2
)
1286 ;; Why are the versions strings, and given that they are, why aren't
1287 ;; they converted to numbers and compared as such here? -- fx
1289 ;; In case someone made a mistake and left out the quotes
1290 ;; in the :version value.
1291 (if (numberp version2
)
1292 (setq version2
(prin1-to-string version2
)))
1293 (let (major1 major2 minor1 minor2
)
1294 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1295 (setq major1
(read (or (match-string 1 version1
)
1297 (setq minor1
(read (or (match-string 3 version1
)
1299 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1300 (setq major2
(read (or (match-string 1 version2
)
1302 (setq minor2
(read (or (match-string 3 version2
)
1304 (or (< major1 major2
)
1305 (and (= major1 major2
)
1306 (< minor1 minor2
)))))
1309 (defun customize-face (&optional face other-window
)
1310 "Customize FACE, which should be a face name or nil.
1311 If FACE is nil, customize all faces. If FACE is actually a
1312 face-alias, customize the face it is aliased to.
1314 If OTHER-WINDOW is non-nil, display in another window.
1316 Interactively, when point is on text which has a face specified,
1317 suggest to customize that face, if it's customizable."
1318 (interactive (list (read-face-name "Customize face"
1319 (or (face-at-point t t
) "all faces") t
)))
1320 (if (member face
'(nil ""))
1321 (setq face
(face-list)))
1322 (if (and (listp face
) (null (cdr face
)))
1323 (setq face
(car face
)))
1324 (let ((display-fun (if other-window
1325 'custom-buffer-create-other-window
1326 'custom-buffer-create
)))
1328 (funcall display-fun
1330 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1332 "*Customize Faces*")
1333 ;; If FACE is actually an alias, customize the face it is aliased to.
1334 (if (get face
'face-alias
)
1335 (setq face
(get face
'face-alias
)))
1336 (unless (facep face
)
1337 (user-error "Invalid face %S" face
))
1338 (funcall display-fun
1339 (list (list face
'custom-face
))
1340 (format "*Customize Face: %s*"
1341 (custom-unlispify-tag-name face
))))))
1344 (defun customize-face-other-window (&optional face
)
1345 "Show customization buffer for face FACE in other window.
1346 If FACE is actually a face-alias, customize the face it is aliased to.
1348 Interactively, when point is on text which has a face specified,
1349 suggest to customize that face, if it's customizable."
1350 (interactive (list (read-face-name "Customize face"
1351 (or (face-at-point t t
) "all faces") t
)))
1352 (customize-face face t
))
1354 (defun custom-unsaved-options ()
1355 "List of options and faces set in this session but not saved.
1356 Each entry is of the form (SYMBOL TYPE), where TYPE is one of the
1357 symbols `custom-face' or `custom-variable'."
1359 (mapatoms (lambda (symbol)
1360 (and (or (get symbol
'customized-face
)
1361 (get symbol
'customized-face-comment
))
1362 (custom-facep symbol
)
1363 (push (list symbol
'custom-face
) found
))
1364 (and (or (get symbol
'customized-value
)
1365 (get symbol
'customized-variable-comment
))
1367 (push (list symbol
'custom-variable
) found
))))
1370 (defalias 'customize-customized
'customize-unsaved
)
1373 (defun customize-unsaved ()
1374 "Customize all options and faces set in this session but not saved."
1376 (let ((found (custom-unsaved-options)))
1378 (error "No user options are set but unsaved")
1379 (custom-buffer-create (custom-sort-items found t nil
)
1380 "*Customize Unsaved*"))))
1383 (defun customize-rogue ()
1384 "Customize all user variables modified outside customize."
1387 (mapatoms (lambda (symbol)
1388 (let ((cval (or (get symbol
'customized-value
)
1389 (get symbol
'saved-value
)
1390 (get symbol
'standard-value
))))
1391 (when (and cval
;Declared with defcustom.
1392 (default-boundp symbol
) ;Has a value.
1393 (not (equal (eval (car cval
))
1394 ;; Which does not match customize.
1395 (default-value symbol
))))
1396 (push (list symbol
'custom-variable
) found
)))))
1398 (user-error "No rogue user options")
1399 (custom-buffer-create (custom-sort-items found t nil
)
1400 "*Customize Rogue*"))))
1402 (defun customize-saved ()
1403 "Customize all saved options and faces."
1406 (mapatoms (lambda (symbol)
1407 (and (or (get symbol
'saved-face
)
1408 (get symbol
'saved-face-comment
))
1409 (custom-facep symbol
)
1410 (push (list symbol
'custom-face
) found
))
1411 (and (or (get symbol
'saved-value
)
1412 (get symbol
'saved-variable-comment
))
1414 (push (list symbol
'custom-variable
) found
))))
1416 (user-error "No saved user options")
1417 (custom-buffer-create (custom-sort-items found t nil
)
1418 "*Customize Saved*"))))
1420 (declare-function apropos-parse-pattern
"apropos" (pattern))
1421 (defvar apropos-regexp
)
1424 (defun customize-apropos (pattern &optional type
)
1425 "Customize loaded options, faces and groups matching PATTERN.
1426 PATTERN can be a word, a list of words (separated by spaces),
1427 or a regexp (using some regexp special characters). If it is a word,
1428 search for matches for that word as a substring. If it is a list of
1429 words, search for matches for any two (or more) of those words.
1431 If TYPE is `options', include only options.
1432 If TYPE is `faces', include only faces.
1433 If TYPE is `groups', include only groups."
1434 (interactive (list (apropos-read-pattern "symbol") nil
))
1436 (unless (memq type
'(nil options faces groups
))
1437 (error "Invalid setting type %s" (symbol-name type
)))
1438 (apropos-parse-pattern pattern
) ;Sets apropos-regexp by side-effect: Yuck!
1442 (when (string-match-p apropos-regexp
(symbol-name symbol
))
1443 (if (memq type
'(nil groups
))
1444 (if (get symbol
'custom-group
)
1445 (push (list symbol
'custom-group
) found
)))
1446 (if (memq type
'(nil faces
))
1447 (if (custom-facep symbol
)
1448 (push (list symbol
'custom-face
) found
)))
1449 (if (memq type
'(nil options
))
1450 (if (and (boundp symbol
)
1451 (eq (indirect-variable symbol
) symbol
)
1452 (or (get symbol
'saved-value
)
1453 (custom-variable-p symbol
)))
1454 (push (list symbol
'custom-variable
) found
))))))
1456 (error "No customizable %s matching %s" (if (not type
)
1457 "group, face, or option"
1460 (custom-buffer-create
1461 (custom-sort-items found t custom-buffer-order-groups
)
1462 "*Customize Apropos*")))
1465 (defun customize-apropos-options (regexp &optional ignored
)
1466 "Customize all loaded customizable options matching REGEXP."
1467 (interactive (list (apropos-read-pattern "options")))
1468 (customize-apropos regexp
'options
))
1471 (defun customize-apropos-faces (regexp)
1472 "Customize all loaded faces matching REGEXP."
1473 (interactive (list (apropos-read-pattern "faces")))
1474 (customize-apropos regexp
'faces
))
1477 (defun customize-apropos-groups (regexp)
1478 "Customize all loaded groups matching REGEXP."
1479 (interactive (list (apropos-read-pattern "groups")))
1480 (customize-apropos regexp
'groups
))
1483 (defun custom-prompt-customize-unsaved-options ()
1484 "Prompt user to customize any unsaved customization options.
1485 Return non-nil if user chooses to customize, for use in
1486 `kill-emacs-query-functions'."
1487 (not (and (custom-unsaved-options)
1488 (yes-or-no-p "Some customized options have not been saved; Examine? ")
1494 (defcustom custom-buffer-style
'links
1495 "Control the presentation style for customization buffers.
1496 The value should be a symbol, one of:
1497 `brackets': groups nest within each other with big horizontal brackets.
1498 `links': groups have links to subgroups.
1499 `tree': display groups as trees."
1500 :type
'(radio (const brackets
)
1503 :group
'custom-buffer
)
1505 (defcustom custom-buffer-done-kill nil
1506 "Non-nil means exiting a Custom buffer should kill it."
1509 :group
'custom-buffer
)
1511 (defcustom custom-buffer-indent
3
1512 "Number of spaces to indent nested groups."
1514 :group
'custom-buffer
)
1516 (defun custom-get-fresh-buffer (name)
1517 "Get a fresh new buffer with name NAME.
1518 If the buffer already exist, clean it up to be like new.
1519 Beware: it's not quite like new. Good enough for custom, but maybe
1521 ;; To be more complete, we should also kill all permanent-local variables,
1522 ;; but it's not needed for custom.
1523 (let ((buf (get-buffer name
)))
1524 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1525 ;; This will check if the file is not saved.
1529 (get-buffer-create name
)
1530 (with-current-buffer buf
1531 (kill-all-local-variables)
1532 (run-hooks 'kill-buffer-hook
)
1533 ;; Delete overlays before erasing the buffer so the overlay hooks
1534 ;; don't get run spuriously when we erase the buffer.
1535 (let ((ols (overlay-lists)))
1536 (dolist (ol (nconc (car ols
) (cdr ols
)))
1537 (delete-overlay ol
)))
1542 (defun custom-buffer-create (options &optional name _description
)
1543 "Create a buffer containing OPTIONS.
1544 Optional NAME is the name of the buffer.
1545 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1546 SYMBOL is a customization option, and WIDGET is a widget for editing
1548 DESCRIPTION is unused."
1549 (pop-to-buffer-same-window
1550 (custom-get-fresh-buffer (or name
"*Customization*")))
1551 (custom-buffer-create-internal options
))
1554 (defun custom-buffer-create-other-window (options &optional name _description
)
1555 "Create a buffer containing OPTIONS, and display it in another window.
1556 The result includes selecting that window.
1557 Optional NAME is the name of the buffer.
1558 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1559 SYMBOL is a customization option, and WIDGET is a widget for editing
1561 DESCRIPTION is unused."
1562 (unless name
(setq name
"*Customization*"))
1563 (switch-to-buffer-other-window (custom-get-fresh-buffer name
))
1564 (custom-buffer-create-internal options
))
1566 (defcustom custom-reset-button-menu t
1567 "If non-nil, only show a single reset button in customize buffers.
1568 This button will have a menu with all three reset operations."
1570 :group
'custom-buffer
1573 (defcustom custom-buffer-verbose-help t
1574 "If non-nil, include explanatory text in the customization buffer."
1576 :group
'custom-buffer
)
1578 (defun Custom-buffer-done (&rest _ignore
)
1579 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1581 (quit-window custom-buffer-done-kill
))
1583 (defvar custom-button nil
1584 "Face used for buttons in customization buffers.")
1586 (defvar custom-button-mouse nil
1587 "Mouse face used for buttons in customization buffers.")
1589 (defvar custom-button-pressed nil
1590 "Face used for pressed buttons in customization buffers.")
1592 (defcustom custom-search-field t
1593 "If non-nil, show a search field in Custom buffers."
1596 :group
'custom-buffer
)
1598 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1599 '(("unspecified" . unspecified
))))
1600 "If non-nil, indicate active buttons in a raised-button style.
1601 Otherwise use brackets."
1604 :group
'custom-buffer
1605 :set
(lambda (variable value
)
1606 (custom-set-default variable value
)
1608 (if value
'custom-button
'custom-button-unraised
))
1609 (setq custom-button-mouse
1610 (if value
'custom-button-mouse
'highlight
))
1611 (setq custom-button-pressed
1613 'custom-button-pressed
1614 'custom-button-pressed-unraised
))))
1616 (defun custom-buffer-create-internal (options &optional _description
)
1618 (let ((init-file (or custom-file user-init-file
)))
1619 ;; Insert verbose help at the top of the custom buffer.
1620 (when custom-buffer-verbose-help
1624 "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n")))
1625 (widget-insert "For help using this buffer, see ")
1626 (widget-create 'custom-manual
1627 :tag
"Easy Customization"
1628 "(emacs)Easy Customization")
1629 (widget-insert " in the ")
1630 (widget-create 'custom-manual
1632 :help-echo
"Read the Emacs manual."
1634 (widget-insert "."))
1635 (widget-insert "\n")
1637 ;; Insert the search field.
1638 (when custom-search-field
1639 (widget-insert "\n")
1640 (let* ((echo "Search for custom items.
1641 You can enter one or more words separated by spaces,
1642 or a regular expression.")
1646 :size
40 :help-echo echo
1647 :action
(lambda (widget &optional _event
)
1648 (customize-apropos (split-string (widget-value widget
)))))))
1650 (widget-create-child-and-convert
1651 search-widget
'push-button
1653 :help-echo echo
:action
1654 (lambda (widget &optional _event
)
1655 (customize-apropos (split-string (widget-value (widget-get widget
:parent
))))))
1656 (widget-insert "\n")))
1658 ;; The custom command buttons are also in the toolbar, so for a
1659 ;; time they were not inserted in the buffer if the toolbar was in use.
1660 ;; But it can be a little confusing for the buffer layout to
1661 ;; change according to whether or nor the toolbar is on, not to
1662 ;; mention that a custom buffer can in theory be created in a
1663 ;; frame with a toolbar, then later viewed in one without.
1664 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1665 (if custom-buffer-verbose-help
1667 Operate on all settings in this buffer:\n"))
1668 (let ((button (lambda (tag action active help _icon _label
)
1671 (widget-create 'push-button
:tag tag
1672 :help-echo help
:action action
))))
1673 (commands custom-commands
))
1674 (if custom-reset-button-menu
1676 (widget-create 'push-button
1678 :help-echo
"Show a menu with reset operations."
1679 :mouse-down-action
'ignore
1680 :action
'custom-reset
)
1681 (apply button
(pop commands
)) ; Apply
1682 (apply button
(pop commands
))) ; Apply and Save
1683 (apply button
(pop commands
)) ; Apply
1684 (apply button
(pop commands
)) ; Apply and Save
1685 (widget-insert "\n")
1686 (apply button
(pop commands
)) ; Undo
1687 (apply button
(pop commands
)) ; Reset
1688 (apply button
(pop commands
)) ; Erase
1690 (pop commands
) ; Help (omitted)
1691 (apply button
(pop commands
)))) ; Exit
1692 (widget-insert "\n\n"))
1694 ;; Now populate the custom buffer.
1695 (message "Creating customization items...")
1696 (buffer-disable-undo)
1697 (setq custom-options
1698 (if (= (length options
) 1)
1699 (mapcar (lambda (entry)
1700 (widget-create (nth 1 entry
)
1701 :documentation-shown t
1702 :custom-state
'unknown
1703 :tag
(custom-unlispify-tag-name
1705 :value
(nth 0 entry
)))
1708 (length (length options
)))
1709 (mapcar (lambda (entry)
1711 (message "Creating customization items ...%2d%%"
1712 (floor (* 100.0 count
) length
))
1713 (widget-create (nth 1 entry
)
1714 :tag
(custom-unlispify-tag-name
1716 :value
(nth 0 entry
))
1717 (setq count
(1+ count
))
1718 (unless (eq (preceding-char) ?
\n)
1719 (widget-insert "\n"))
1720 (widget-insert "\n")))
1722 (unless (eq (preceding-char) ?
\n)
1723 (widget-insert "\n"))
1724 (message "Creating customization items ...done")
1725 (message "Resetting customization items...")
1726 (unless (eq custom-buffer-style
'tree
)
1727 (mapc 'custom-magic-reset custom-options
))
1728 (message "Resetting customization items...done")
1729 (message "Creating customization setup...")
1731 (buffer-enable-undo)
1732 (goto-char (point-min))
1733 (message "Creating customization setup...done"))
1735 ;;; The Tree Browser.
1738 (defun customize-browse (&optional group
)
1739 "Create a tree browser for the customize hierarchy."
1742 (setq group
'emacs
))
1743 (let ((name "*Customize Browser*"))
1744 (pop-to-buffer-same-window (custom-get-fresh-buffer name
)))
1746 (widget-insert (format "\
1747 %s buttons; type RET or click mouse-1
1748 on a button to invoke its action.
1749 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1750 (if custom-raised-buttons
1751 "Raised text indicates"
1752 "Square brackets indicate")))
1755 (if custom-browse-only-groups
1757 Invoke the [Group] button below to edit that item in another window.\n\n")
1758 (widget-insert "Invoke the ")
1759 (widget-create 'item
1762 :tag-glyph
"folder")
1763 (widget-insert ", ")
1764 (widget-create 'item
1768 (widget-insert ", and ")
1769 (widget-create 'item
1772 :tag-glyph
"option")
1773 (widget-insert " buttons below to edit that
1774 item in another window.\n\n"))
1775 (let ((custom-buffer-style 'tree
))
1776 (widget-create 'custom-group
1778 :custom-state
'unknown
1779 :tag
(custom-unlispify-tag-name group
)
1782 (goto-char (point-min)))
1784 (define-widget 'custom-browse-visibility
'item
1785 "Control visibility of items in the customize tree browser."
1787 :action
'custom-browse-visibility-action
)
1789 (defun custom-browse-visibility-action (widget &rest _ignore
)
1790 (let ((custom-buffer-style 'tree
))
1791 (custom-toggle-parent widget
)))
1793 (define-widget 'custom-browse-group-tag
'custom-group-link
1794 "Show parent in other window when activated."
1797 :action
'custom-browse-group-tag-action
)
1799 (defun custom-browse-group-tag-action (widget &rest _ignore
)
1800 (let ((parent (widget-get widget
:parent
)))
1801 (customize-group-other-window (widget-value parent
))))
1803 (define-widget 'custom-browse-variable-tag
'custom-group-link
1804 "Show parent in other window when activated."
1807 :action
'custom-browse-variable-tag-action
)
1809 (defun custom-browse-variable-tag-action (widget &rest _ignore
)
1810 (let ((parent (widget-get widget
:parent
)))
1811 (customize-variable-other-window (widget-value parent
))))
1813 (define-widget 'custom-browse-face-tag
'custom-group-link
1814 "Show parent in other window when activated."
1817 :action
'custom-browse-face-tag-action
)
1819 (defun custom-browse-face-tag-action (widget &rest _ignore
)
1820 (let ((parent (widget-get widget
:parent
)))
1821 (customize-face-other-window (widget-value parent
))))
1823 (defconst custom-browse-alist
'((" " "space")
1829 (defun custom-browse-insert-prefix (prefix)
1830 "Insert PREFIX. On XEmacs convert it to line graphics."
1831 ;; Fixme: do graphics.
1832 (if nil
; (featurep 'xemacs)
1835 (while (not (string-equal prefix
""))
1836 (let ((entry (substring prefix
0 3)))
1837 (setq prefix
(substring prefix
3))
1838 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1839 (name (nth 1 (assoc entry custom-browse-alist
))))
1840 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1841 (overlay-put overlay
'start-open t
)
1842 (overlay-put overlay
'end-open t
)))))
1845 ;;; Modification of Basic Widgets.
1847 ;; We add extra properties to the basic widgets needed here. This is
1848 ;; fine, as long as we are careful to stay within our own namespace.
1850 ;; We want simple widgets to be displayed by default, but complex
1851 ;; widgets to be hidden.
1853 ;; This widget type is obsolete as of Emacs 24.1.
1854 (widget-put (get 'item
'widget-type
) :custom-show t
)
1855 (widget-put (get 'editable-field
'widget-type
)
1856 :custom-show
(lambda (_widget value
)
1857 (let ((pp (pp-to-string value
)))
1858 (cond ((string-match-p "\n" pp
)
1863 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1865 ;;; The `custom-manual' Widget.
1867 (define-widget 'custom-manual
'info-link
1868 "Link to the manual entry for this customization option."
1869 :help-echo
"Read the manual entry for this option."
1870 :keymap custom-mode-link-map
1871 :follow-link
'mouse-face
1872 :button-face
'custom-link
1873 :mouse-face
'highlight
1874 :pressed-face
'highlight
1877 ;;; The `custom-magic' Widget.
1879 (defgroup custom-magic-faces nil
1880 "Faces used by the magic button."
1881 :group
'custom-faces
1882 :group
'custom-buffer
)
1884 (defface custom-invalid
'((((class color
))
1885 :foreground
"yellow1" :background
"red1")
1886 (t :weight bold
:slant italic
:underline t
))
1887 "Face used when the customize item is invalid."
1888 :group
'custom-magic-faces
)
1890 (defface custom-rogue
'((((class color
))
1891 :foreground
"pink" :background
"black")
1893 "Face used when the customize item is not defined for customization."
1894 :group
'custom-magic-faces
)
1896 (defface custom-modified
'((((min-colors 88) (class color
))
1897 :foreground
"white" :background
"blue1")
1899 :foreground
"white" :background
"blue")
1901 "Face used when the customize item has been modified."
1902 :group
'custom-magic-faces
)
1904 (defface custom-set
'((((min-colors 88) (class color
))
1905 :foreground
"blue1" :background
"white")
1907 :foreground
"blue" :background
"white")
1909 "Face used when the customize item has been set."
1910 :group
'custom-magic-faces
)
1912 (defface custom-changed
'((((min-colors 88) (class color
))
1913 :foreground
"white" :background
"blue1")
1915 :foreground
"white" :background
"blue")
1917 "Face used when the customize item has been changed."
1918 :group
'custom-magic-faces
)
1920 (defface custom-themed
'((((min-colors 88) (class color
))
1921 :foreground
"white" :background
"blue1")
1923 :foreground
"white" :background
"blue")
1925 "Face used when the customize item has been set by a theme."
1926 :group
'custom-magic-faces
)
1928 (defface custom-saved
'((t :underline t
))
1929 "Face used when the customize item has been saved."
1930 :group
'custom-magic-faces
)
1932 (defconst custom-magic-alist
1933 '((nil "#" underline
"\
1934 UNINITIALIZED, you should not see this.")
1935 (unknown "?" italic
"\
1936 UNKNOWN, you should not see this.")
1937 (hidden "-" default
"\
1938 HIDDEN, invoke \"Show\" in the previous line to show." "\
1939 group now hidden, invoke \"Show\", above, to show contents.")
1940 (invalid "x" custom-invalid
"\
1941 INVALID, the displayed value cannot be set.")
1942 (modified "*" custom-modified
"\
1943 EDITED, shown value does not take effect until you set or save it." "\
1944 something in this group has been edited but not set.")
1945 (set "+" custom-set
"\
1946 SET for current session only." "\
1947 something in this group has been set but not saved.")
1948 (changed ":" custom-changed
"\
1949 CHANGED outside Customize." "\
1950 something in this group has been changed outside customize.")
1951 (saved "!" custom-saved
"\
1953 something in this group has been set and saved.")
1954 (themed "o" custom-themed
"\
1956 visible group members are set by enabled themes.")
1957 (rogue "@" custom-rogue
"\
1958 NO CUSTOMIZATION DATA; not intended to be customized." "\
1959 something in this group is not prepared for customization.")
1960 (standard " " nil
"\
1962 visible group members are all at standard values."))
1963 "Alist of customize option states.
1964 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1966 STATE is one of the following symbols:
1969 For internal use, should never occur.
1971 For internal use, should never occur.
1973 This item is not being displayed.
1975 This item is modified, but has an invalid form.
1977 This item is modified, and has a valid form.
1979 This item has been set but not saved.
1981 The current value of this item has been changed outside Customize.
1983 This item is marked for saving.
1985 This item has no customization information.
1987 This item was set by an enabled Custom theme.
1989 This item is unchanged from the standard setting.
1991 MAGIC is a string used to present that state.
1993 FACE is a face used to present the state.
1995 ITEM-DESC is a string describing the state for options.
1997 GROUP-DESC is a string describing the state for groups. If this is
1998 left out, ITEM-DESC will be used.
2000 The string %c in either description will be replaced with the
2001 category of the item. These are `group', `option', and `face'.
2003 The list should be sorted most significant first.")
2005 (defcustom custom-magic-show
'long
2006 "If non-nil, show textual description of the state.
2007 If `long', show a full-line description, not just one word."
2008 :type
'(choice (const :tag
"no" nil
)
2010 (other :tag
"short" short
))
2011 :group
'custom-buffer
)
2013 (defcustom custom-magic-show-hidden
'(option face
)
2014 "Control whether the State button is shown for hidden items.
2015 The value should be a list with the custom categories where the State
2016 button should be visible. Possible categories are `group', `option',
2018 :type
'(set (const group
) (const option
) (const face
))
2019 :group
'custom-buffer
)
2021 (defcustom custom-magic-show-button nil
2022 "Show a \"magic\" button indicating the state of each customization option."
2024 :group
'custom-buffer
)
2026 (define-widget 'custom-magic
'default
2027 "Show and manipulate state for a customization option."
2029 :action
'widget-parent-action
2032 :value-create
'custom-magic-value-create
2033 :value-delete
'widget-children-value-delete
)
2035 (defun widget-magic-mouse-down-action (widget &optional _event
)
2036 ;; Non-nil unless hidden.
2037 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2041 (defun custom-magic-value-create (widget)
2042 "Create compact status report for WIDGET."
2043 (let* ((parent (widget-get widget
:parent
))
2044 (state (widget-get parent
:custom-state
))
2045 (hidden (eq state
'hidden
))
2046 (entry (assq state custom-magic-alist
))
2047 (magic (nth 1 entry
))
2048 (face (nth 2 entry
))
2049 (category (widget-get parent
:custom-category
))
2050 (text (or (and (eq category
'group
)
2053 (form (widget-get parent
:custom-form
))
2055 (unless (eq state
'hidden
)
2056 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2057 (setq text
(concat (match-string 1 text
)
2058 (symbol-name category
)
2059 (match-string 2 text
))))
2060 (when (and custom-magic-show
2062 (memq category custom-magic-show-hidden
)))
2064 (when (and (eq category
'group
)
2065 (not (and (eq custom-buffer-style
'links
)
2066 (> (widget-get parent
:custom-level
) 1))))
2067 (insert-char ?\s
(* custom-buffer-indent
2068 (widget-get parent
:custom-level
))))
2069 (push (widget-create-child-and-convert
2071 :help-echo
"Change the state of this item."
2072 :format
(if hidden
"%t" "%[%t%]")
2073 :button-prefix
'widget-push-button-prefix
2074 :button-suffix
'widget-push-button-suffix
2075 :mouse-down-action
'widget-magic-mouse-down-action
2079 (let ((start (point)))
2080 (if (eq custom-magic-show
'long
)
2082 (insert (symbol-name state
)))
2083 (cond ((eq form
'lisp
)
2085 ((eq form
'mismatch
)
2086 (insert " (mismatch)")))
2087 (put-text-property start
(point) 'face
'custom-state
))
2089 (when (and (eq category
'group
)
2090 (not (and (eq custom-buffer-style
'links
)
2091 (> (widget-get parent
:custom-level
) 1))))
2092 (insert-char ?\s
(* custom-buffer-indent
2093 (widget-get parent
:custom-level
))))
2094 (when custom-magic-show-button
2095 (when custom-magic-show
2096 (let ((indent (widget-get parent
:indent
)))
2098 (insert-char ? indent
))))
2099 (push (widget-create-child-and-convert
2101 :mouse-down-action
'widget-magic-mouse-down-action
2105 :help-echo
"Change the state."
2106 :format
(if hidden
"%t" "%[%t%]")
2107 :tag
(if (memq form
'(lisp mismatch
))
2108 (concat "(" magic
")")
2109 (concat "[" magic
"]")))
2112 (widget-put widget
:children children
))))
2114 (defun custom-magic-reset (widget)
2115 "Redraw the :custom-magic property of WIDGET."
2116 (let ((magic (widget-get widget
:custom-magic
)))
2118 (widget-value-set magic
(widget-value magic
)))))
2120 ;;; The `custom' Widget.
2122 (defface custom-button
2123 '((((type x w32 ns
) (class color
)) ; Like default mode line
2124 :box
(:line-width
2 :style released-button
)
2125 :background
"lightgrey" :foreground
"black"))
2126 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2128 :group
'custom-faces
)
2130 (defface custom-button-mouse
2131 '((((type x w32 ns
) (class color
))
2132 :box
(:line-width
2 :style released-button
)
2133 :background
"grey90" :foreground
"black")
2135 ;; This is for text terminals that support mouse, like GPM mouse
2136 ;; or the MS-DOS terminal: inverse-video makes the button stand
2137 ;; out on mouse-over.
2139 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2141 :group
'custom-faces
)
2143 (defface custom-button-unraised
2144 '((t :inherit underline
))
2145 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2147 :group
'custom-faces
)
2150 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2152 (setq custom-button-mouse
2153 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2155 (defface custom-button-pressed
2156 '((((type x w32 ns
) (class color
))
2157 :box
(:line-width
2 :style pressed-button
)
2158 :background
"lightgrey" :foreground
"black")
2159 (t :inverse-video t
))
2160 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2162 :group
'custom-faces
)
2164 (defface custom-button-pressed-unraised
2165 '((default :inherit custom-button-unraised
)
2166 (((class color
) (background light
)) :foreground
"magenta4")
2167 (((class color
) (background dark
)) :foreground
"violet"))
2168 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2170 :group
'custom-faces
)
2172 (setq custom-button-pressed
2173 (if custom-raised-buttons
2174 'custom-button-pressed
2175 'custom-button-pressed-unraised
))
2177 (defface custom-documentation
'((t nil
))
2178 "Face used for documentation strings in customization buffers."
2179 :group
'custom-faces
)
2181 (defface custom-state
'((((class color
) (background dark
))
2182 :foreground
"lime green")
2183 (((class color
) (background light
))
2184 :foreground
"dark green"))
2185 "Face used for State descriptions in the customize buffer."
2186 :group
'custom-faces
)
2188 (defface custom-link
'((t :inherit link
))
2189 "Face for links in customization buffers."
2191 :group
'custom-faces
)
2193 (define-widget 'custom
'default
2194 "Customize a user option."
2196 :convert-widget
'custom-convert-widget
2197 :notify
'custom-notify
2200 :custom-state
'hidden
2201 :documentation-property
'widget-subclass-responsibility
2202 :value-create
'widget-subclass-responsibility
2203 :value-delete
'widget-children-value-delete
2204 :value-get
'widget-value-value-get
2205 :validate
'widget-children-validate
2206 :match
(lambda (_widget value
) (symbolp value
)))
2208 (defun custom-convert-widget (widget)
2209 "Initialize :value and :tag from :args in WIDGET."
2210 (let ((args (widget-get widget
:args
)))
2212 (widget-put widget
:value
(widget-apply widget
2213 :value-to-internal
(car args
)))
2214 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2215 (widget-put widget
:args nil
)))
2218 (defun custom-notify (widget &rest args
)
2219 "Keep track of changes."
2220 (let ((state (widget-get widget
:custom-state
)))
2221 (unless (eq state
'modified
)
2222 (unless (memq state
'(nil unknown hidden
))
2223 (widget-put widget
:custom-state
'modified
))
2224 (custom-magic-reset widget
)
2225 (apply 'widget-default-notify widget args
))))
2227 (defun custom-redraw (widget)
2228 "Redraw WIDGET with current settings."
2229 (let ((line (count-lines (point-min) (point)))
2230 (column (current-column))
2232 (from (marker-position (widget-get widget
:from
)))
2233 (to (marker-position (widget-get widget
:to
))))
2235 (widget-value-set widget
(widget-value widget
))
2236 (custom-redraw-magic widget
))
2237 (when (and (>= pos from
) (<= pos to
))
2240 (goto-char (point-min))
2241 (forward-line (if (> column
0)
2244 (move-to-column column
))
2247 (defun custom-redraw-magic (widget)
2248 "Redraw WIDGET state with current settings."
2250 (let ((magic (widget-get widget
:custom-magic
)))
2252 (widget-value-set magic
(widget-value magic
))
2253 (when (setq widget
(widget-get widget
:group
))
2254 (custom-group-state-update widget
)))
2256 (setq widget nil
)))))
2259 (defun custom-show (widget value
)
2260 "Non-nil if WIDGET should be shown with VALUE by default."
2261 (declare (obsolete "this widget type is no longer supported." "24.1"))
2262 (let ((show (widget-get widget
:custom-show
)))
2263 (if (functionp show
)
2264 (funcall show widget value
)
2267 (defun custom-load-widget (widget)
2268 "Load all dependencies for WIDGET."
2269 (custom-load-symbol (widget-value widget
)))
2271 (defun custom-unloaded-symbol-p (symbol)
2272 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2274 (loads (get symbol
'custom-loads
))
2277 (setq load
(car loads
)
2279 (cond ((symbolp load
)
2280 (unless (featurep load
)
2282 ((assoc load load-history
))
2283 ((assoc (locate-library load
) load-history
)
2289 (defun custom-unloaded-widget-p (widget)
2290 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2291 (custom-unloaded-symbol-p (widget-value widget
)))
2293 (defun custom-toggle-hide (widget)
2294 "Toggle visibility of WIDGET."
2295 (custom-load-widget widget
)
2296 (let ((state (widget-get widget
:custom-state
)))
2297 (cond ((memq state
'(invalid modified set
))
2298 (error "There are unsaved changes"))
2300 (widget-put widget
:custom-state
'unknown
))
2302 (widget-put widget
:documentation-shown nil
)
2303 (widget-put widget
:custom-state
'hidden
)))
2304 (custom-redraw widget
)
2307 (defun custom-toggle-parent (widget &rest _ignore
)
2308 "Toggle visibility of parent of WIDGET."
2309 (custom-toggle-hide (widget-get widget
:parent
)))
2311 (defun custom-add-see-also (widget &optional prefix
)
2312 "Add `See also ...' to WIDGET if there are any links.
2313 Insert PREFIX first if non-nil."
2314 (let* ((symbol (widget-get widget
:value
))
2315 (links (get symbol
'custom-links
))
2316 (many (> (length links
) 2))
2317 (buttons (widget-get widget
:buttons
))
2318 (indent (widget-get widget
:indent
)))
2321 (insert-char ?\s indent
))
2324 (insert "See also ")
2326 (push (widget-create-child-and-convert
2328 :button-face
'custom-link
2329 :mouse-face
'highlight
2330 :pressed-face
'highlight
)
2332 (setq links
(cdr links
))
2341 (widget-put widget
:buttons buttons
))))
2343 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string
)
2344 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2345 The value is non-nil if any parents were found.
2346 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2347 (let ((name (widget-value widget
))
2348 (type (widget-type widget
))
2349 (buttons (widget-get widget
:buttons
))
2352 (insert (or initial-string
"Groups:"))
2353 (mapatoms (lambda (symbol)
2354 (when (member (list name type
) (get symbol
'custom-group
))
2356 (push (widget-create-child-and-convert
2357 widget
'custom-group-link
2358 :tag
(custom-unlispify-tag-name symbol
)
2361 (setq parents
(cons symbol parents
)))))
2364 (delete-region start
(point)))
2365 (widget-put widget
:buttons buttons
)
2368 ;;; The `custom-comment' Widget.
2370 ;; like the editable field
2371 (defface custom-comment
'((((type tty
))
2372 :background
"yellow3"
2373 :foreground
"black")
2374 (((class grayscale color
)
2376 :background
"gray85")
2377 (((class grayscale color
)
2379 :background
"dim gray")
2382 "Face used for comments on variables or faces."
2384 :group
'custom-faces
)
2386 ;; like font-lock-comment-face
2387 (defface custom-comment-tag
2388 '((((class color
) (background dark
)) :foreground
"gray80")
2389 (((class color
) (background light
)) :foreground
"blue4")
2390 (((class grayscale
) (background light
))
2391 :foreground
"DimGray" :weight bold
:slant italic
)
2392 (((class grayscale
) (background dark
))
2393 :foreground
"LightGray" :weight bold
:slant italic
)
2395 "Face used for the comment tag on variables or faces."
2396 :group
'custom-faces
)
2398 (define-widget 'custom-comment
'string
2401 :help-echo
"Edit a comment here."
2402 :sample-face
'custom-comment-tag
2403 :value-face
'custom-comment
2405 :create
'custom-comment-create
)
2407 (defun custom-comment-create (widget)
2408 (let* ((null-comment (equal "" (widget-value widget
))))
2409 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2411 (widget-default-create widget
)
2412 ;; `widget-default-delete' expects markers in these slots --
2413 ;; maybe it shouldn't.
2414 (widget-put widget
:from
(point-marker))
2415 (widget-put widget
:to
(point-marker)))))
2417 (defun custom-comment-hide (widget)
2418 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2420 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2421 ;; the global custom one
2422 (defun custom-comment-show (widget)
2423 (widget-put widget
:comment-shown t
)
2424 (custom-redraw widget
)
2427 (defun custom-comment-invisible-p (widget)
2428 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2430 (not (widget-get widget
:comment-shown
)))))
2432 ;;; The `custom-variable' Widget.
2434 (defface custom-variable-obsolete
2435 '((((class color
) (background dark
))
2436 :foreground
"light blue")
2437 (((min-colors 88) (class color
) (background light
))
2438 :foreground
"blue1")
2439 (((class color
) (background light
))
2442 "Face used for obsolete variables."
2444 :group
'custom-faces
)
2446 (defface custom-variable-tag
2447 `((((class color
) (background dark
))
2448 :foreground
"light blue" :weight bold
)
2449 (((min-colors 88) (class color
) (background light
))
2450 :foreground
"blue1" :weight bold
)
2451 (((class color
) (background light
))
2452 :foreground
"blue" :weight bold
)
2454 "Face used for unpushable variable tags."
2455 :group
'custom-faces
)
2457 (defface custom-variable-button
'((t :underline t
:weight bold
))
2458 "Face used for pushable variable tags."
2459 :group
'custom-faces
)
2461 (defcustom custom-variable-default-form
'edit
2462 "Default form of displaying variable values."
2463 :type
'(choice (const edit
)
2465 :group
'custom-buffer
2468 (defun custom-variable-documentation (variable)
2469 "Return documentation of VARIABLE for use in Custom buffer.
2470 Normally just return the docstring. But if VARIABLE automatically
2471 becomes buffer local when set, append a message to that effect.
2472 Also append any obsolescence information."
2473 (format "%s%s%s" (documentation-property variable
'variable-documentation t
)
2474 (if (and (local-variable-if-set-p variable
)
2475 (or (not (local-variable-p variable
))
2477 (local-variable-if-set-p variable
))))
2479 This variable automatically becomes buffer-local when set outside Custom.
2480 However, setting it through Custom sets the default value."
2482 ;; This duplicates some code from describe-variable.
2483 ;; TODO extract to separate utility function?
2484 (let* ((obsolete (get variable
'byte-obsolete-variable
))
2485 (use (car obsolete
)))
2488 This variable is obsolete"
2489 (if (nth 2 obsolete
)
2490 (format " since %s" (nth 2 obsolete
)))
2491 (cond ((stringp use
) (concat ";\n" use
))
2492 (use (format-message ";\nuse `%s' instead."
2497 (define-widget 'custom-variable
'custom
2498 "A widget for displaying a Custom variable.
2499 The following properties have special meanings for this widget:
2501 :hidden-states should be a list of widget states for which the
2502 widget's initial contents are to be hidden.
2504 :custom-form should be a symbol describing how to display and
2505 edit the variable---either `edit' (using edit widgets),
2506 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2507 if nil, use the return value of `custom-variable-default-form'.
2509 :shown-value, if non-nil, should be a list whose `car' is the
2510 variable value to display in place of the current value.
2512 :custom-style describes the widget interface style; nil is the
2513 default style, while `simple' means a simpler interface that
2514 inhibits the magic custom-state widget."
2516 :help-echo
"Set or reset this variable."
2517 :documentation-property
#'custom-variable-documentation
2518 :custom-category
'option
2520 :custom-menu
'custom-variable-menu-create
2522 :value-create
'custom-variable-value-create
2523 :action
'custom-variable-action
2524 :hidden-states
'(standard)
2525 :custom-set
'custom-variable-set
2526 :custom-mark-to-save
'custom-variable-mark-to-save
2527 :custom-reset-current
'custom-redraw
2528 :custom-reset-saved
'custom-variable-reset-saved
2529 :custom-reset-standard
'custom-variable-reset-standard
2530 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2531 :custom-standard-value
'custom-variable-standard-value
2532 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2534 (defun custom-variable-type (symbol)
2535 "Return a widget suitable for editing the value of SYMBOL.
2536 If SYMBOL has a `custom-type' property, use that.
2537 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2538 try matching its doc string against `custom-guess-doc-alist'."
2539 (let* ((type (or (get symbol
'custom-type
)
2540 (and (not (get symbol
'standard-value
))
2541 (custom-guess-type symbol
))
2543 (options (get symbol
'custom-options
))
2544 (tmp (if (listp type
)
2545 (copy-sequence type
)
2548 ;; This used to use widget-put, but with strict plists that
2549 ;; fails when type is an even-length list, eg (repeat character).
2550 ;; Passing our result through widget-convert makes it a valid widget.
2551 (setcdr tmp
(append (list :options options
) (cdr tmp
))))
2554 (defun custom-variable-value-create (widget)
2555 "Here is where you edit the variable's value."
2556 (custom-load-widget widget
)
2557 (unless (widget-get widget
:custom-form
)
2558 (widget-put widget
:custom-form custom-variable-default-form
))
2559 (let* ((buttons (widget-get widget
:buttons
))
2560 (children (widget-get widget
:children
))
2561 (form (widget-get widget
:custom-form
))
2562 (symbol (widget-get widget
:value
))
2563 (tag (widget-get widget
:tag
))
2564 (type (custom-variable-type symbol
))
2565 (conv (widget-convert type
))
2566 (get (or (get symbol
'custom-get
) 'default-value
))
2567 (prefix (widget-get widget
:custom-prefix
))
2568 (last (widget-get widget
:custom-last
))
2569 (style (widget-get widget
:custom-style
))
2570 (value (let ((shown-value (widget-get widget
:shown-value
)))
2573 ((default-boundp symbol
)
2574 (funcall get symbol
))
2575 (t (widget-get conv
:value
)))))
2576 (state (or (widget-get widget
:custom-state
)
2577 (if (memq (custom-variable-state symbol value
)
2578 (widget-get widget
:hidden-states
))
2580 (obsolete (get symbol
'byte-obsolete-variable
)))
2582 ;; If we don't know the state, see if we need to edit it in lisp form.
2584 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2585 (when (eq state
'unknown
)
2586 (unless (widget-apply conv
:match value
)
2587 (setq form
'mismatch
)))
2588 ;; Now we can create the child widget.
2589 (cond ((eq custom-buffer-style
'tree
)
2590 (insert prefix
(if last
" `--- " " |--- "))
2591 (push (widget-create-child-and-convert
2592 widget
'custom-browse-variable-tag
)
2594 (insert " " tag
"\n")
2595 (widget-put widget
:buttons buttons
))
2597 ;; Indicate hidden value.
2598 (push (widget-create-child-and-convert
2599 widget
'custom-visibility
2600 :help-echo
"Show the value of this option."
2605 :action
'custom-toggle-hide-variable
2609 (push (widget-create-child-and-convert
2612 :sample-face
(if obsolete
2613 'custom-variable-obsolete
2614 'custom-variable-tag
)
2618 ((memq form
'(lisp mismatch
))
2619 (push (widget-create-child-and-convert
2620 widget
'custom-visibility
2621 :help-echo
"Hide the value of this option."
2626 :action
'custom-toggle-hide-variable
2630 ;; This used to try presenting the saved value or the
2631 ;; standard value, but it seems more intuitive to present
2632 ;; the current value (Bug#7600).
2633 (let* ((value (cond ((default-boundp symbol
)
2634 (custom-quote (funcall get symbol
)))
2636 (custom-quote (widget-get conv
:value
))))))
2637 (insert (symbol-name symbol
) ": ")
2638 (push (widget-create-child-and-convert
2640 :button-face
'custom-variable-button-face
2642 :tag
(symbol-name symbol
)
2648 (push (widget-create-child-and-convert
2649 widget
'custom-visibility
2650 :help-echo
"Hide or show this option."
2655 :action
'custom-toggle-hide-variable
2659 (let* ((format (widget-get type
:format
))
2660 tag-format value-format
)
2661 (unless (string-match ":" format
)
2662 (error "Bad format"))
2663 (setq tag-format
(substring format
0 (match-end 0)))
2664 (setq value-format
(substring format
(match-end 0)))
2665 (push (widget-create-child-and-convert
2668 :action
'custom-tag-action
2669 :help-echo
"Change value of this option."
2670 :mouse-down-action
'custom-tag-mouse-down-action
2671 :button-face
'custom-variable-button
2672 :sample-face
(if obsolete
2673 'custom-variable-obsolete
2674 'custom-variable-tag
)
2677 (push (widget-create-child-and-convert
2679 :format value-format
2682 (unless (eq custom-buffer-style
'tree
)
2683 (unless (eq (preceding-char) ?
\n)
2684 (widget-insert "\n"))
2685 ;; Create the magic button.
2686 (unless (eq style
'simple
)
2687 (let ((magic (widget-create-child-and-convert
2688 widget
'custom-magic nil
)))
2689 (widget-put widget
:custom-magic magic
)
2690 (push magic buttons
)))
2691 (widget-put widget
:buttons buttons
)
2692 ;; Insert documentation.
2693 (widget-put widget
:documentation-indent
3)
2694 (unless (and (eq style
'simple
)
2696 (widget-add-documentation-string-button
2697 widget
:visibility-widget
'custom-visibility
))
2699 ;; The comment field
2700 (unless (eq state
'hidden
)
2701 (let* ((comment (get symbol
'variable-comment
))
2703 (widget-create-child-and-convert
2704 widget
'custom-comment
2706 :value
(or comment
""))))
2707 (widget-put widget
:comment-widget comment-widget
)
2708 ;; Don't push it !!! Custom assumes that the first child is the
2710 (setq children
(append children
(list comment-widget
)))))
2711 ;; Update the rest of the properties.
2712 (widget-put widget
:custom-form form
)
2713 (widget-put widget
:children children
)
2714 ;; Now update the state.
2715 (if (eq state
'hidden
)
2716 (widget-put widget
:custom-state state
)
2717 (custom-variable-state-set widget
))
2719 (unless (eq state
'hidden
)
2720 (when (eq (widget-get widget
:custom-level
) 1)
2721 (custom-add-parent-links widget
))
2722 (custom-add-see-also widget
)))))
2724 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore
)
2725 "Toggle the visibility of a `custom-variable' parent widget.
2726 By default, this signals an error if the parent has unsaved
2727 changes. If the parent has a `simple' :custom-style property,
2728 the present value is saved to its :shown-value property instead."
2729 (let ((widget (widget-get visibility-widget
:parent
)))
2730 (unless (eq (widget-type widget
) 'custom-variable
)
2731 (error "Invalid widget type"))
2732 (custom-load-widget widget
)
2733 (let ((state (widget-get widget
:custom-state
)))
2734 (if (eq state
'hidden
)
2735 (widget-put widget
:custom-state
'unknown
)
2736 ;; In normal interface, widget can't be hidden if modified.
2737 (when (memq state
'(invalid modified set
))
2738 (if (eq (widget-get widget
:custom-style
) 'simple
)
2739 (widget-put widget
:shown-value
2742 (widget-get widget
:children
)))))
2743 (error "There are unsaved changes")))
2744 (widget-put widget
:documentation-shown nil
)
2745 (widget-put widget
:custom-state
'hidden
))
2746 (custom-redraw widget
)
2749 (defun custom-tag-action (widget &rest args
)
2750 "Pass :action to first child of WIDGET's parent."
2751 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2754 (defun custom-tag-mouse-down-action (widget &rest args
)
2755 "Pass :mouse-down-action to first child of WIDGET's parent."
2756 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2757 :mouse-down-action args
))
2759 (defun custom-variable-state (symbol val
)
2760 "Return the state of SYMBOL if its value is VAL.
2761 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2762 Possible return values are `standard', `saved', `set', `themed',
2763 `changed', and `rogue'."
2764 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2765 (value (if (default-boundp symbol
)
2766 (funcall get symbol
)
2768 (comment (get symbol
'variable-comment
))
2771 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2773 (get symbol
'customized-variable-comment
))
2775 (if (condition-case nil
2776 (and (equal value
(eval (car tmp
)))
2777 (equal comment temp
))
2781 ((progn (setq tmp
(get symbol
'theme-value
))
2782 (setq temp
(get symbol
'saved-variable-comment
))
2784 (if (condition-case nil
2785 (and (equal comment temp
)
2788 (car (custom-variable-theme-value
2792 ((eq (caar tmp
) 'user
) 'saved
)
2793 ((eq (caar tmp
) 'changed
)
2794 (if (condition-case nil
2798 (car (get symbol
'standard-value
)))))
2800 ;; The value was originally set outside
2801 ;; custom, but it was set to the standard
2802 ;; value (probably an autoloaded defcustom).
2807 ((setq tmp
(get symbol
'standard-value
))
2808 (if (condition-case nil
2809 (and (equal value
(eval (car tmp
)))
2810 (equal comment nil
))
2816 (defun custom-variable-state-set (widget &optional state
)
2817 "Set the state of WIDGET to STATE.
2818 If STATE is nil, the value is computed by `custom-variable-state'."
2819 (widget-put widget
:custom-state
2820 (or state
(custom-variable-state (widget-value widget
)
2821 (widget-get widget
:value
)))))
2823 (defun custom-variable-standard-value (widget)
2824 (get (widget-value widget
) 'standard-value
))
2826 (defvar custom-variable-menu
2827 `(("Set for Current Session" custom-variable-set
2829 (eq (widget-get widget
:custom-state
) 'modified
)))
2830 ;; Note that in all the backquoted code in this file, we test
2831 ;; init-file-user rather than user-init-file. This is in case
2832 ;; cus-edit is loaded by something in site-start.el, because
2833 ;; user-init-file is not set at that stage.
2834 ;; https://lists.gnu.org/r/emacs-devel/2007-10/msg00310.html
2835 ,@(when (or custom-file init-file-user
)
2836 '(("Save for Future Sessions" custom-variable-save
2838 (memq (widget-get widget
:custom-state
)
2839 '(modified set changed rogue
))))))
2840 ("Undo Edits" custom-redraw
2842 (and (default-boundp (widget-value widget
))
2843 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2844 ("Revert This Session's Customization" custom-variable-reset-saved
2846 (memq (widget-get widget
:custom-state
)
2847 '(modified set changed rogue
))))
2848 ,@(when (or custom-file init-file-user
)
2849 '(("Erase Customization" custom-variable-reset-standard
2851 (and (get (widget-value widget
) 'standard-value
)
2852 (memq (widget-get widget
:custom-state
)
2853 '(modified set changed saved rogue
)))))))
2854 ("Set to Backup Value" custom-variable-reset-backup
2856 (get (widget-value widget
) 'backup-value
)))
2857 ("---" ignore ignore
)
2858 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2859 ("---" ignore ignore
)
2860 ("Show Current Value" custom-variable-edit
2862 (eq (widget-get widget
:custom-form
) 'lisp
)))
2863 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2865 (eq (widget-get widget
:custom-form
) 'edit
))))
2866 "Alist of actions for the `custom-variable' widget.
2867 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2868 the menu entry, ACTION is the function to call on the widget when the
2869 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2870 widget as an argument, and returns non-nil if ACTION is valid on that
2871 widget. If FILTER is nil, ACTION is always valid.")
2873 (defun custom-variable-action (widget &optional event
)
2874 "Show the menu for `custom-variable' WIDGET.
2875 Optional EVENT is the location for the menu."
2876 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2877 (custom-toggle-hide widget
)
2878 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2879 (custom-variable-state-set widget
))
2880 (custom-redraw-magic widget
)
2881 (let* ((completion-ignore-case t
)
2882 (answer (widget-choose (concat "Operation on "
2883 (custom-unlispify-tag-name
2884 (widget-get widget
:value
)))
2885 (custom-menu-filter custom-variable-menu
2889 (funcall answer widget
)))))
2891 (defun custom-variable-edit (widget)
2892 "Edit value of WIDGET."
2893 (widget-put widget
:custom-state
'unknown
)
2894 (widget-put widget
:custom-form
'edit
)
2895 (custom-redraw widget
))
2897 (defun custom-variable-edit-lisp (widget)
2898 "Edit the Lisp representation of the value of WIDGET."
2899 (widget-put widget
:custom-state
'unknown
)
2900 (widget-put widget
:custom-form
'lisp
)
2901 (custom-redraw widget
))
2903 (defun custom-variable-set (widget)
2904 "Set the current value for the variable being edited by WIDGET."
2905 (let* ((form (widget-get widget
:custom-form
))
2906 (state (widget-get widget
:custom-state
))
2907 (child (car (widget-get widget
:children
)))
2908 (symbol (widget-value widget
))
2909 (set (or (get symbol
'custom-set
) 'set-default
))
2910 (comment-widget (widget-get widget
:comment-widget
))
2911 (comment (widget-value comment-widget
))
2913 (cond ((eq state
'hidden
)
2914 (user-error "Cannot set hidden variable"))
2915 ((setq val
(widget-apply child
:validate
))
2916 (goto-char (widget-get val
:from
))
2917 (error "%s" (widget-get val
:error
)))
2918 ((memq form
'(lisp mismatch
))
2919 (when (equal comment
"")
2921 ;; Make the comment invisible by hand if it's empty
2922 (custom-comment-hide comment-widget
))
2923 (custom-variable-backup-value widget
)
2924 (custom-push-theme 'theme-value symbol
'user
2925 'set
(custom-quote (widget-value child
)))
2926 (funcall set symbol
(eval (setq val
(widget-value child
))))
2927 (put symbol
'customized-value
(list val
))
2928 (put symbol
'variable-comment comment
)
2929 (put symbol
'customized-variable-comment comment
))
2931 (when (equal comment
"")
2933 ;; Make the comment invisible by hand if it's empty
2934 (custom-comment-hide comment-widget
))
2935 (custom-variable-backup-value widget
)
2936 (custom-push-theme 'theme-value symbol
'user
2937 'set
(custom-quote (widget-value child
)))
2938 (funcall set symbol
(setq val
(widget-value child
)))
2939 (put symbol
'customized-value
(list (custom-quote val
)))
2940 (put symbol
'variable-comment comment
)
2941 (put symbol
'customized-variable-comment comment
)))
2942 (custom-variable-state-set widget
)
2943 (custom-redraw-magic widget
)))
2945 (defun custom-variable-mark-to-save (widget)
2946 "Set value and mark for saving the variable edited by WIDGET."
2947 (let* ((form (widget-get widget
:custom-form
))
2948 (state (widget-get widget
:custom-state
))
2949 (child (car (widget-get widget
:children
)))
2950 (symbol (widget-value widget
))
2951 (set (or (get symbol
'custom-set
) 'set-default
))
2952 (comment-widget (widget-get widget
:comment-widget
))
2953 (comment (widget-value comment-widget
))
2955 (cond ((eq state
'hidden
)
2956 (user-error "Cannot set hidden variable"))
2957 ((setq val
(widget-apply child
:validate
))
2958 (goto-char (widget-get val
:from
))
2959 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2960 ((memq form
'(lisp mismatch
))
2961 (when (equal comment
"")
2963 ;; Make the comment invisible by hand if it's empty
2964 (custom-comment-hide comment-widget
))
2965 (put symbol
'saved-value
(list (widget-value child
)))
2966 (custom-push-theme 'theme-value symbol
'user
2967 'set
(custom-quote (widget-value child
)))
2968 (funcall set symbol
(eval (widget-value child
)))
2969 (put symbol
'variable-comment comment
)
2970 (put symbol
'saved-variable-comment comment
))
2972 (when (equal comment
"")
2974 ;; Make the comment invisible by hand if it's empty
2975 (custom-comment-hide comment-widget
))
2976 (put symbol
'saved-value
2977 (list (custom-quote (widget-value child
))))
2978 (custom-push-theme 'theme-value symbol
'user
2979 'set
(custom-quote (widget-value child
)))
2980 (funcall set symbol
(widget-value child
))
2981 (put symbol
'variable-comment comment
)
2982 (put symbol
'saved-variable-comment comment
)))
2983 (put symbol
'customized-value nil
)
2984 (put symbol
'customized-variable-comment nil
)))
2986 (defsubst custom-variable-state-set-and-redraw
(widget)
2987 "Set state of variable widget WIDGET and redraw with current settings."
2988 (custom-variable-state-set widget
)
2989 (custom-redraw-magic widget
))
2991 (defun custom-variable-save (widget)
2992 "Save value of variable edited by widget WIDGET."
2993 (custom-variable-mark-to-save widget
)
2995 (custom-variable-state-set-and-redraw widget
))
2997 (defun custom-variable-reset-saved (widget)
2998 "Restore the value of the variable being edited by WIDGET.
2999 If there is a saved value, restore it; otherwise reset to the
3000 uncustomized (themed or standard) value.
3002 Update the widget to show that value. The value that was current
3003 before this operation becomes the backup value."
3004 (let* ((symbol (widget-value widget
))
3005 (saved-value (get symbol
'saved-value
))
3006 (comment (get symbol
'saved-variable-comment
)))
3007 (custom-variable-backup-value widget
)
3008 (if (not (or saved-value comment
))
3009 ;; If there is no saved value, remove the setting.
3010 (custom-push-theme 'theme-value symbol
'user
'reset
)
3011 ;; Otherwise, apply the saved value.
3012 (put symbol
'variable-comment comment
)
3013 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe saved-value
))
3015 (funcall (or (get symbol
'custom-set
) 'set-default
)
3016 symbol
(eval (car saved-value
)))))
3017 (put symbol
'customized-value nil
)
3018 (put symbol
'customized-variable-comment nil
)
3019 (widget-put widget
:custom-state
'unknown
)
3020 ;; This call will possibly make the comment invisible
3021 (custom-redraw widget
)))
3023 (defun custom-variable-mark-to-reset-standard (widget)
3024 "Mark to restore standard setting for the variable edited by widget WIDGET.
3025 If `custom-reset-standard-variables-list' is nil, save, reset and
3026 redraw the widget immediately."
3027 (let* ((symbol (widget-value widget
)))
3028 (if (get symbol
'standard-value
)
3029 (custom-variable-backup-value widget
)
3030 (user-error "No standard setting known for %S" symbol
))
3031 (put symbol
'variable-comment nil
)
3032 (put symbol
'customized-value nil
)
3033 (put symbol
'customized-variable-comment nil
)
3034 (custom-push-theme 'theme-value symbol
'user
'reset
)
3035 (custom-theme-recalc-variable symbol
)
3036 (if (and custom-reset-standard-variables-list
3037 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
3039 (put symbol
'saved-value nil
)
3040 (put symbol
'saved-variable-comment nil
)
3041 ;; Append this to `custom-reset-standard-variables-list' to
3042 ;; have `custom-reset-standard-save-and-update' save setting
3043 ;; to the file, update the widget's state, and redraw it.
3044 (setq custom-reset-standard-variables-list
3045 (cons widget custom-reset-standard-variables-list
)))
3046 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
3047 (put symbol
'saved-value nil
)
3048 (put symbol
'saved-variable-comment nil
)
3050 (widget-put widget
:custom-state
'unknown
)
3051 ;; This call will possibly make the comment invisible
3052 (custom-redraw widget
))))
3054 (defun custom-variable-reset-standard (widget)
3055 "Restore standard setting for the variable edited by WIDGET.
3056 This operation eliminates any saved setting for the variable,
3057 restoring it to the state of a variable that has never been customized.
3058 The value that was current before this operation
3059 becomes the backup value, so you can get it again."
3060 (let (custom-reset-standard-variables-list)
3061 (custom-variable-mark-to-reset-standard widget
)))
3063 (defun custom-variable-backup-value (widget)
3064 "Back up the current value for WIDGET's variable.
3065 The backup value is kept in the car of the `backup-value' property."
3066 (let* ((symbol (widget-value widget
))
3067 (get (or (get symbol
'custom-get
) 'default-value
))
3068 (type (custom-variable-type symbol
))
3069 (conv (widget-convert type
))
3070 (value (if (default-boundp symbol
)
3071 (funcall get symbol
)
3072 (widget-get conv
:value
))))
3073 (put symbol
'backup-value
(list value
))))
3075 (defun custom-variable-reset-backup (widget)
3076 "Restore the backup value for the variable being edited by WIDGET.
3077 The value that was current before this operation
3078 becomes the backup value, so you can use this operation repeatedly
3079 to switch between two values."
3080 (let* ((symbol (widget-value widget
))
3081 (set (or (get symbol
'custom-set
) 'set-default
))
3082 (value (get symbol
'backup-value
))
3083 (comment-widget (widget-get widget
:comment-widget
))
3084 (comment (widget-value comment-widget
)))
3087 (custom-variable-backup-value widget
)
3088 (custom-push-theme 'theme-value symbol
'user
'set value
)
3090 (funcall set symbol
(car value
))
3092 (user-error "No backup value for %s" symbol
))
3093 (put symbol
'customized-value
(list (custom-quote (car value
))))
3094 (put symbol
'variable-comment comment
)
3095 (put symbol
'customized-variable-comment comment
)
3096 (custom-variable-state-set widget
)
3097 ;; This call will possibly make the comment invisible
3098 (custom-redraw widget
)))
3100 ;;; The `custom-visibility' Widget
3102 (define-widget 'custom-visibility
'visibility
3103 "Show or hide a documentation string."
3104 :button-face
'custom-visibility
3105 :pressed-face
'custom-visibility
3106 :mouse-face
'highlight
3107 :pressed-face
'highlight
3111 (defface custom-visibility
3112 '((t :height
0.8 :inherit link
))
3113 "Face for the `custom-visibility' widget."
3115 :group
'custom-faces
)
3117 ;;; The `custom-face-edit' Widget.
3119 (define-widget 'custom-face-edit
'checklist
3120 "Widget for editing face attributes.
3121 The following properties have special meanings for this widget:
3123 :value is a plist of face attributes.
3125 :default-face-attributes, if non-nil, is a plist of defaults for
3126 face attributes (as specified by a `default' defface entry)."
3129 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3130 :value-to-internal
'custom-face-edit-fix-value
3131 :match
(lambda (widget value
)
3132 (widget-checklist-match widget
3133 (custom-face-edit-fix-value widget value
)))
3134 :value-create
'custom-face-edit-value-create
3135 :convert-widget
'custom-face-edit-convert-widget
3136 :args
(mapcar (lambda (att)
3137 (list 'group
:inline t
3138 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3139 (list 'const
:format
"" :value
(nth 0 att
))
3141 custom-face-attributes
))
3143 (defun custom-face-edit-value-create (widget)
3144 (let* ((alist (widget-checklist-match-find
3145 widget
(widget-get widget
:value
)))
3146 (args (widget-get widget
:args
))
3147 (show-all (widget-get widget
:show-all-attributes
))
3148 (buttons (widget-get widget
:buttons
))
3149 (defaults (widget-checklist-match-find
3151 (widget-get widget
:default-face-attributes
)))
3153 (unless (looking-back "^ *" (line-beginning-position))
3155 (insert-char ?\s
(widget-get widget
:extra-offset
))
3156 (if (or alist defaults show-all
)
3158 (setq entry
(or (assq prop alist
)
3159 (assq prop defaults
)))
3160 (if (or entry show-all
)
3161 (widget-checklist-add-item widget prop entry
)))
3162 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3163 (let ((indent (widget-get widget
:indent
)))
3164 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3165 (push (widget-create-child-and-convert
3167 :help-echo
"Show or hide all face attributes."
3168 :button-face
'custom-visibility
3169 :pressed-face
'custom-visibility
3170 :mouse-face
'highlight
3171 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3172 :on-glyph nil
:off-glyph nil
3174 :action
'custom-face-edit-value-visibility-action
3178 (widget-put widget
:buttons buttons
)
3179 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3181 (defun custom-face-edit-value-visibility-action (widget &rest _ignore
)
3182 ;; Toggle hiding of face attributes.
3183 (let ((parent (widget-get widget
:parent
)))
3184 (widget-put parent
:show-all-attributes
3185 (not (widget-get parent
:show-all-attributes
)))
3186 (custom-redraw parent
)))
3188 (defun custom-face-edit-fix-value (_widget value
)
3189 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3190 Also change :reverse-video to :inverse-video."
3191 (custom-fix-face-spec value
))
3193 (defun custom-face-edit-convert-widget (widget)
3194 "Convert :args as widget types in WIDGET."
3197 :args
(mapcar (lambda (arg)
3199 :deactivate
'custom-face-edit-deactivate
3200 :activate
'custom-face-edit-activate
3201 :delete
'custom-face-edit-delete
))
3202 (widget-get widget
:args
)))
3205 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3206 "Converted version of the `custom-face-edit' widget.")
3208 (defun custom-face-edit-deactivate (widget)
3209 "Make face widget WIDGET inactive for user modifications."
3210 (unless (widget-get widget
:inactive
)
3211 (let ((tag (custom-face-edit-attribute-tag widget
))
3212 (from (copy-marker (widget-get widget
:from
)))
3213 (value (widget-value widget
))
3214 (inhibit-read-only t
)
3215 (inhibit-modification-hooks t
))
3218 (widget-default-delete widget
)
3219 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3220 (widget-put widget
:inactive
3221 (cons value
(cons from
(- (point) from
))))))))
3223 (defun custom-face-edit-activate (widget)
3224 "Make face widget WIDGET active for user modifications."
3225 (let ((inactive (widget-get widget
:inactive
))
3226 (inhibit-read-only t
)
3227 (inhibit-modification-hooks t
))
3228 (when (consp inactive
)
3230 (goto-char (car (cdr inactive
)))
3231 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3232 (widget-put widget
:inactive nil
)
3233 (widget-apply widget
:create
)
3234 (widget-value-set widget
(car inactive
))
3237 (defun custom-face-edit-delete (widget)
3238 "Remove WIDGET from the buffer."
3239 (let ((inactive (widget-get widget
:inactive
))
3240 (inhibit-read-only t
)
3241 (inhibit-modification-hooks t
))
3243 ;; Widget is alive, we don't have to do anything special
3244 (widget-default-delete widget
)
3245 ;; WIDGET is already deleted because we did so to deactivate it;
3246 ;; now just get rid of the label we put in its place.
3247 (delete-region (car (cdr inactive
))
3248 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3249 (widget-put widget
:inactive nil
))))
3252 (defun custom-face-edit-attribute-tag (widget)
3253 "Return the first :tag property in WIDGET or one of its children."
3254 (let ((tag (widget-get widget
:tag
)))
3255 (or (and (not (equal tag
"")) tag
)
3256 (let ((children (widget-get widget
:children
)))
3257 (while (and (null tag
) children
)
3258 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3261 ;;; The `custom-display' Widget.
3263 (define-widget 'custom-display
'menu-choice
3264 "Select a display type."
3267 :help-echo
"Specify frames where the face attributes should be used."
3268 :args
'((const :tag
"all" t
)
3269 (const :tag
"defaults" default
)
3271 :tag
"specific display"
3274 :args
((group :sibling-args
(:help-echo
"\
3275 Only match the specified window systems.")
3276 (const :format
"Type: "
3278 (checklist :inline t
3281 :sibling-args
(:help-echo
"\
3282 The X11 Window System.")
3284 (const :format
"W32 "
3285 :sibling-args
(:help-echo
"\
3288 (const :format
"NS "
3289 :sibling-args
(:help-echo
"\
3290 GNUstep or Macintosh OS Cocoa interface.")
3292 (const :format
"DOS "
3293 :sibling-args
(:help-echo
"\
3296 (const :format
"TTY%n"
3297 :sibling-args
(:help-echo
"\
3298 Plain text terminals.")
3300 (group :sibling-args
(:help-echo
"\
3301 Only match the frames with the specified color support.")
3302 (const :format
"Class: "
3304 (checklist :inline t
3306 (const :format
"Color "
3307 :sibling-args
(:help-echo
"\
3308 Match color frames.")
3310 (const :format
"Grayscale "
3311 :sibling-args
(:help-echo
"\
3312 Match grayscale frames.")
3314 (const :format
"Monochrome%n"
3315 :sibling-args
(:help-echo
"\
3316 Match frames with no color support.")
3318 (group :sibling-args
(:help-echo
"\
3319 The minimum number of colors the frame should support.")
3320 (const :format
"" min-colors
)
3321 (integer :tag
"Minimum number of colors" ))
3322 (group :sibling-args
(:help-echo
"\
3323 Only match frames with the specified intensity.")
3325 Background brightness: "
3327 (checklist :inline t
3329 (const :format
"Light "
3330 :sibling-args
(:help-echo
"\
3331 Match frames with light backgrounds.")
3333 (const :format
"Dark\n"
3334 :sibling-args
(:help-echo
"\
3335 Match frames with dark backgrounds.")
3337 (group :sibling-args
(:help-echo
"\
3338 Only match frames that support the specified face attributes.")
3339 (const :format
"Supports attributes:" supports
)
3340 (custom-face-edit :inline t
:format
"%n%v"))))))
3342 ;;; The `custom-face' Widget.
3344 (defface custom-face-tag
3345 '((t :inherit custom-variable-tag
))
3346 "Face used for face tags."
3347 :group
'custom-faces
)
3349 (defcustom custom-face-default-form
'selected
3350 "Default form of displaying face definition."
3351 :type
'(choice (const all
)
3354 :group
'custom-buffer
3357 (defun custom-face-documentation (face)
3358 "Return documentation of FACE for use in Custom buffer."
3359 (format "%s%s" (face-documentation face
)
3360 ;; This duplicates some code from describe-face.
3361 ;; TODO extract to separate utility function?
3362 ;; In practice this does not get used, because M-x customize-face
3364 (let ((alias (get face
'face-alias
))
3365 (obsolete (get face
'obsolete-face
)))
3366 (if (and alias obsolete
)
3367 (format "\nThis face is obsolete%s; use `%s' instead.\n"
3368 (if (stringp obsolete
)
3369 (format " since %s" obsolete
)
3374 (define-widget 'custom-face
'custom
3375 "Widget for customizing a face.
3376 The following properties have special meanings for this widget:
3378 :value is the face name (a symbol).
3380 :custom-form should be a symbol describing how to display and
3381 edit the face attributes---either `selected' (attributes for
3382 selected display only), `all' (all attributes), `lisp' (as a
3383 Lisp sexp), or `mismatch' (should not happen); if nil, use
3384 the return value of `custom-face-default-form'.
3386 :custom-style describes the widget interface style; nil is the
3387 default style, while `simple' means a simpler interface that
3388 inhibits the magic custom-state widget.
3390 :sample-indent, if non-nil, is the number of columns to which to
3391 indent the face sample (an integer).
3393 :shown-value, if non-nil, is the face spec to display as the value
3394 of the widget, instead of the current face spec."
3395 :sample-face
'custom-face-tag
3396 :help-echo
"Set or reset this face."
3397 :documentation-property
#'custom-face-documentation
3398 :value-create
'custom-face-value-create
3399 :action
'custom-face-action
3400 :custom-category
'face
3402 :custom-set
'custom-face-set
3403 :custom-mark-to-save
'custom-face-mark-to-save
3404 :custom-reset-current
'custom-redraw
3405 :custom-reset-saved
'custom-face-reset-saved
3406 :custom-reset-standard
'custom-face-reset-standard
3407 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3408 :custom-standard-value
'custom-face-standard-value
3409 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3410 :custom-menu
'custom-face-menu-create
)
3412 (define-widget 'custom-face-all
'editable-list
3413 "An editable list of display specifications and attributes."
3414 :entry-format
"%i %d %v"
3415 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3416 :append-button-args
'(:help-echo
"Append new display specification here.")
3417 :delete-button-args
'(:help-echo
"Delete this display specification.")
3418 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3420 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3421 "Converted version of the `custom-face-all' widget.")
3423 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3424 "Return a canonicalized version of SPEC.
3425 FILTER-INDEX is the index in the entry for each attribute in
3426 `custom-face-attributes' at which the appropriate filter function can be
3427 found, and DEFAULT-FILTER is the filter to apply for attributes that
3429 (mapcar (lambda (entry)
3430 ;; Filter a single face-spec entry
3431 (let ((tests (car entry
))
3433 ;; Handle both old- and new-style attribute syntax
3434 (if (listp (car (cdr entry
)))
3437 (filtered-attrs nil
))
3438 ;; Filter each face attribute
3439 (while unfiltered-attrs
3440 (let* ((attr (pop unfiltered-attrs
))
3441 (pre-filtered-value (pop unfiltered-attrs
))
3443 (or (nth filter-index
(assq attr custom-face-attributes
))
3447 (funcall filter pre-filtered-value
)
3448 pre-filtered-value
)))
3449 (push filtered-value filtered-attrs
)
3450 (push attr filtered-attrs
)))
3452 (list tests filtered-attrs
)))
3455 (defun custom-pre-filter-face-spec (spec)
3456 "Return SPEC changed as necessary for editing by the face customization widget.
3457 SPEC must be a full face spec."
3458 (custom-filter-face-spec spec
2))
3460 (defun custom-post-filter-face-spec (spec)
3461 "Return the customized SPEC in a form suitable for setting the face."
3462 (custom-filter-face-spec spec
3))
3464 (defun custom-face-widget-to-spec (widget)
3465 "Return a face spec corresponding to WIDGET.
3466 WIDGET should be a `custom-face' widget."
3467 (unless (eq (widget-type widget
) 'custom-face
)
3468 (error "Invalid widget"))
3469 (let ((child (car (widget-get widget
:children
))))
3470 (custom-post-filter-face-spec
3471 (if (eq (widget-type child
) 'custom-face-edit
)
3472 `((t ,(widget-value child
)))
3473 (widget-value child
)))))
3475 (defun custom-face-get-current-spec (face)
3476 (let ((spec (or (get face
'customized-face
)
3477 (get face
'saved-face
)
3478 (get face
'face-defface-spec
)
3479 ;; Attempt to construct it.
3480 `((t ,(custom-face-attributes-get
3481 face
(selected-frame)))))))
3482 ;; If the user has changed this face in some other way,
3483 ;; edit it as the user has specified it.
3484 (if (not (face-spec-match-p face spec
(selected-frame)))
3485 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3486 (custom-pre-filter-face-spec spec
)))
3488 (defun custom-toggle-hide-face (visibility-widget &rest _ignore
)
3489 "Toggle the visibility of a `custom-face' parent widget.
3490 By default, this signals an error if the parent has unsaved
3491 changes. If the parent has a `simple' :custom-style property,
3492 the present value is saved to its :shown-value property instead."
3493 (let ((widget (widget-get visibility-widget
:parent
)))
3494 (unless (eq (widget-type widget
) 'custom-face
)
3495 (error "Invalid widget type"))
3496 (custom-load-widget widget
)
3497 (let ((state (widget-get widget
:custom-state
)))
3498 (if (eq state
'hidden
)
3499 (widget-put widget
:custom-state
'unknown
)
3500 ;; In normal interface, widget can't be hidden if modified.
3501 (when (memq state
'(invalid modified set
))
3502 (if (eq (widget-get widget
:custom-style
) 'simple
)
3503 (widget-put widget
:shown-value
3504 (custom-face-widget-to-spec widget
))
3505 (error "There are unsaved changes")))
3506 (widget-put widget
:documentation-shown nil
)
3507 (widget-put widget
:custom-state
'hidden
))
3508 (custom-redraw widget
)
3511 (defun custom-face-value-create (widget)
3512 "Create a list of the display specifications for WIDGET."
3513 (let* ((buttons (widget-get widget
:buttons
))
3514 (symbol (widget-get widget
:value
))
3515 (tag (or (widget-get widget
:tag
)
3516 (prin1-to-string symbol
)))
3517 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3518 (style (widget-get widget
:custom-style
))
3521 (if (eq custom-buffer-style
'tree
)
3523 ;; Draw a tree-style `custom-face' widget
3525 (insert (widget-get widget
:custom-prefix
)
3526 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3527 (push (widget-create-child-and-convert
3528 widget
'custom-browse-face-tag
)
3530 (insert " " tag
"\n")
3531 (widget-put widget
:buttons buttons
))
3533 ;; Draw an ordinary `custom-face' widget
3534 (let ((opoint (point)))
3535 ;; Visibility indicator.
3536 (push (widget-create-child-and-convert
3537 widget
'custom-visibility
3538 :help-echo
"Hide or show this face."
3539 :on
"Hide" :off
"Show"
3540 :on-glyph
"down" :off-glyph
"right"
3541 :action
'custom-toggle-hide-face
3546 (widget-specify-sample widget opoint
(point)))
3548 (cond ((eq custom-buffer-style
'face
) " ")
3549 ((string-match-p "face\\'" tag
) ":")
3553 (let ((sample-indent (widget-get widget
:sample-indent
))
3554 (indent-tabs-mode nil
))
3556 (<= (current-column) sample-indent
)
3557 (indent-to-column sample-indent
)))
3558 (push (widget-create-child-and-convert
3561 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3562 (if spec
(face-spec-choose spec
) symbol
))
3568 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3569 (let ((magic (widget-create-child-and-convert
3570 widget
'custom-magic nil
)))
3571 (widget-put widget
:custom-magic magic
)
3572 (push magic buttons
)))
3575 (widget-put widget
:buttons buttons
)
3577 ;; Insert documentation.
3578 (unless (and hiddenp
(eq style
'simple
))
3579 (widget-put widget
:documentation-indent
3)
3580 (widget-add-documentation-string-button
3581 widget
:visibility-widget
'custom-visibility
)
3582 ;; The comment field
3584 (let* ((comment (get symbol
'face-comment
))
3586 (widget-create-child-and-convert
3587 widget
'custom-comment
3589 :value
(or comment
""))))
3590 (widget-put widget
:comment-widget comment-widget
)
3591 (push comment-widget children
))))
3594 (unless (eq (preceding-char) ?
\n)
3597 (custom-load-widget widget
)
3598 (unless (widget-get widget
:custom-form
)
3599 (widget-put widget
:custom-form custom-face-default-form
))
3601 (let* ((spec (or (widget-get widget
:shown-value
)
3602 (custom-face-get-current-spec symbol
)))
3603 (form (widget-get widget
:custom-form
))
3604 (indent (widget-get widget
:indent
))
3605 face-alist face-entry spec-default spec-match editor
)
3607 ;; Find a display in SPEC matching the selected display.
3608 ;; This will use the usual face customization interface.
3609 (setq face-alist spec
)
3610 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3611 (setq spec-default
(pop face-alist
)))
3613 (while (and face-alist
(listp face-alist
) (null spec-match
))
3614 (setq face-entry
(car face-alist
))
3615 (and (listp face-entry
)
3616 (face-spec-set-match-display (car face-entry
)
3618 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3619 (setq spec-match face-entry
))
3620 (setq face-alist
(cdr face-alist
)))
3622 ;; Insert the appropriate editing widget.
3625 ((and (eq form
'selected
)
3626 (or spec-match spec-default
))
3627 (when indent
(insert-char ?\s indent
))
3628 (widget-create-child-and-convert
3629 widget
'custom-face-edit
3630 :value
(cadr spec-match
)
3631 :default-face-attributes
(cadr spec-default
)))
3632 ((and (not (eq form
'lisp
))
3633 (widget-apply custom-face-all
:match spec
))
3634 (widget-create-child-and-convert
3635 widget
'custom-face-all
:value spec
))
3638 (insert-char ?\s indent
))
3639 (widget-create-child-and-convert
3640 widget
'sexp
:value spec
))))
3641 (custom-face-state-set widget
)
3642 (push editor children
)
3643 (widget-put widget
:children children
))))))
3645 (defvar custom-face-menu
3646 `(("Set for Current Session" custom-face-set
)
3647 ,@(when (or custom-file init-file-user
)
3648 '(("Save for Future Sessions" custom-face-save
)))
3649 ("Undo Edits" custom-redraw
3651 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3652 ("Revert This Session's Customization" custom-face-reset-saved
3654 (memq (widget-get widget
:custom-state
) '(modified set changed
))))
3655 ,@(when (or custom-file init-file-user
)
3656 '(("Erase Customization" custom-face-reset-standard
3658 (get (widget-value widget
) 'face-defface-spec
)))))
3659 ("---" ignore ignore
)
3660 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3661 ("---" ignore ignore
)
3662 ("For Current Display" custom-face-edit-selected
3664 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3665 ("For All Kinds of Displays" custom-face-edit-all
3667 (not (eq (widget-get widget
:custom-form
) 'all
))))
3668 ("Show Lisp Expression" custom-face-edit-lisp
3670 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3671 "Alist of actions for the `custom-face' widget.
3672 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3673 the menu entry, ACTION is the function to call on the widget when the
3674 menu is selected, and FILTER is a predicate which takes a `custom-face'
3675 widget as an argument, and returns non-nil if ACTION is valid on that
3676 widget. If FILTER is nil, ACTION is always valid.")
3678 (defun custom-face-edit-selected (widget)
3679 "Edit selected attributes of the value of WIDGET."
3680 (widget-put widget
:custom-state
'unknown
)
3681 (widget-put widget
:custom-form
'selected
)
3682 (custom-redraw widget
))
3684 (defun custom-face-edit-all (widget)
3685 "Edit all attributes of the value of WIDGET."
3686 (widget-put widget
:custom-state
'unknown
)
3687 (widget-put widget
:custom-form
'all
)
3688 (custom-redraw widget
))
3690 (defun custom-face-edit-lisp (widget)
3691 "Edit the Lisp representation of the value of WIDGET."
3692 (widget-put widget
:custom-state
'unknown
)
3693 (widget-put widget
:custom-form
'lisp
)
3694 (custom-redraw widget
))
3696 (defun custom-face-state (face)
3697 "Return the current state of the face FACE.
3698 This is one of `set', `saved', `changed', `themed', or `rogue'."
3699 (let* ((comment (get face
'face-comment
))
3702 ((or (get face
'customized-face
)
3703 (get face
'customized-face-comment
))
3704 (if (equal (get face
'customized-face-comment
) comment
)
3707 ((or (get face
'saved-face
)
3708 (get face
'saved-face-comment
))
3709 (cond ((not (equal (get face
'saved-face-comment
) comment
))
3711 ((eq 'user
(caar (get face
'theme-face
)))
3713 ((eq 'changed
(caar (get face
'theme-face
)))
3716 ((get face
'face-defface-spec
)
3717 (cond (comment 'changed
)
3718 ((get face
'theme-face
) 'themed
)
3721 ;; If the user called set-face-attribute to change the default for
3722 ;; new frames, this face is "set outside of Customize".
3723 (if (and (not (eq state
'rogue
))
3724 (get face
'face-modified
))
3728 (defun custom-face-state-set (widget)
3729 "Set the state of WIDGET."
3730 (widget-put widget
:custom-state
3731 (custom-face-state (widget-value widget
))))
3733 (defun custom-face-action (widget &optional event
)
3734 "Show the menu for `custom-face' WIDGET.
3735 Optional EVENT is the location for the menu."
3736 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3737 (custom-toggle-hide widget
)
3738 (let* ((completion-ignore-case t
)
3739 (symbol (widget-get widget
:value
))
3740 (answer (widget-choose (concat "Operation on "
3741 (custom-unlispify-tag-name symbol
))
3742 (custom-menu-filter custom-face-menu
3746 (funcall answer widget
)))))
3748 (defun custom-face-set (widget)
3749 "Make the face attributes in WIDGET take effect."
3750 (let* ((symbol (widget-value widget
))
3751 (value (custom-face-widget-to-spec widget
))
3752 (comment-widget (widget-get widget
:comment-widget
))
3753 (comment (widget-value comment-widget
)))
3754 (when (equal comment
"")
3756 ;; Make the comment invisible by hand if it's empty
3757 (custom-comment-hide comment-widget
))
3758 (custom-push-theme 'theme-face symbol
'user
'set value
)
3759 (face-spec-set symbol value
'customized-face
)
3760 (put symbol
'face-comment comment
)
3761 (put symbol
'customized-face-comment comment
)
3762 (custom-face-state-set widget
)
3763 (custom-redraw-magic widget
)))
3765 (defun custom-face-mark-to-save (widget)
3766 "Mark for saving the face edited by WIDGET."
3767 (let* ((symbol (widget-value widget
))
3768 (value (custom-face-widget-to-spec widget
))
3769 (comment-widget (widget-get widget
:comment-widget
))
3770 (comment (widget-value comment-widget
))
3771 (standard (eq (widget-get widget
:custom-state
) 'standard
)))
3772 (when (equal comment
"")
3774 ;; Make the comment invisible by hand if it's empty
3775 (custom-comment-hide comment-widget
))
3776 (custom-push-theme 'theme-face symbol
'user
'set value
)
3777 (face-spec-set symbol value
(if standard
'reset
'saved-face
))
3778 (put symbol
'face-comment comment
)
3779 (put symbol
'customized-face-comment nil
)
3780 (put symbol
'saved-face-comment comment
)))
3782 (defsubst custom-face-state-set-and-redraw
(widget)
3783 "Set state of face widget WIDGET and redraw with current settings."
3784 (custom-face-state-set widget
)
3785 (custom-redraw-magic widget
))
3787 (defun custom-face-save (widget)
3788 "Save the face edited by WIDGET."
3789 (custom-face-mark-to-save widget
)
3791 (custom-face-state-set-and-redraw widget
))
3793 ;; For backward compatibility.
3794 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3797 (defun custom-face-reset-saved (widget)
3798 "Restore WIDGET to the face's default attributes.
3799 If there is a saved face, restore it; otherwise reset to the
3800 uncustomized (themed or standard) face."
3801 (let* ((face (widget-value widget
))
3802 (child (car (widget-get widget
:children
)))
3803 (saved-face (get face
'saved-face
))
3804 (comment (get face
'saved-face-comment
))
3805 (comment-widget (widget-get widget
:comment-widget
)))
3806 (custom-push-theme 'theme-face face
'user
3807 (if saved-face
'set
'reset
)
3809 (face-spec-set face saved-face
'saved-face
)
3810 (put face
'face-comment comment
)
3811 (put face
'customized-face-comment nil
)
3812 (widget-value-set child saved-face
)
3813 ;; This call manages the comment visibility
3814 (widget-value-set comment-widget
(or comment
""))
3815 (custom-face-state-set widget
)
3816 (custom-redraw widget
)))
3818 (defun custom-face-standard-value (widget)
3819 (get (widget-value widget
) 'face-defface-spec
))
3821 (defun custom-face-mark-to-reset-standard (widget)
3822 "Restore widget WIDGET to the face's standard attribute values.
3823 If `custom-reset-standard-faces-list' is nil, save, reset and
3824 redraw the widget immediately."
3825 (let* ((symbol (widget-value widget
))
3826 (child (car (widget-get widget
:children
)))
3827 (value (get symbol
'face-defface-spec
))
3828 (comment-widget (widget-get widget
:comment-widget
)))
3830 (user-error "No standard setting for this face"))
3831 (custom-push-theme 'theme-face symbol
'user
'reset
)
3832 (face-spec-set symbol value
'reset
)
3833 (put symbol
'face-comment nil
)
3834 (put symbol
'customized-face-comment nil
)
3835 (if (and custom-reset-standard-faces-list
3836 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3839 (put symbol
'saved-face nil
)
3840 (put symbol
'saved-face-comment nil
)
3841 ;; Append this to `custom-reset-standard-faces-list' and have
3842 ;; `custom-reset-standard-save-and-update' save setting to the
3843 ;; file, update the widget's state, and redraw it.
3844 (setq custom-reset-standard-faces-list
3845 (cons widget custom-reset-standard-faces-list
)))
3846 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3847 (put symbol
'saved-face nil
)
3848 (put symbol
'saved-face-comment nil
)
3850 (widget-value-set child
3851 (custom-pre-filter-face-spec
3852 (list (list t
(custom-face-attributes-get
3854 ;; This call manages the comment visibility
3855 (widget-value-set comment-widget
"")
3856 (custom-face-state-set widget
)
3857 (custom-redraw-magic widget
))))
3859 (defun custom-face-reset-standard (widget)
3860 "Restore WIDGET to the face's standard attribute values.
3861 This operation eliminates any saved attributes for the face,
3862 restoring it to the state of a face that has never been customized."
3863 (let (custom-reset-standard-faces-list)
3864 (custom-face-mark-to-reset-standard widget
)))
3866 ;;; The `face' Widget.
3868 (defvar widget-face-prompt-value-history nil
3869 "History of input to `widget-face-prompt-value'.")
3871 (define-widget 'face
'symbol
3872 "A Lisp face name (with sample)."
3873 :format
"%{%t%}: (%{sample%}) %v"
3876 :sample-face-get
'widget-face-sample-face-get
3877 :notify
'widget-face-notify
3878 :match
(lambda (_widget value
) (facep value
))
3879 :completions
(apply-partially #'completion-table-with-predicate
3880 obarray
#'facep
'strict
)
3881 :prompt-match
'facep
3882 :prompt-history
'widget-face-prompt-value-history
3883 :validate
(lambda (widget)
3884 (unless (facep (widget-value widget
))
3886 :error
(format "Invalid face: %S"
3887 (widget-value widget
)))
3890 (defun widget-face-sample-face-get (widget)
3891 (let ((value (widget-value widget
)))
3896 (defun widget-face-notify (widget child
&optional event
)
3897 "Update the sample, and notify the parent."
3898 (overlay-put (widget-get widget
:sample-overlay
)
3899 'face
(widget-apply widget
:sample-face-get
))
3900 (widget-default-notify widget child event
))
3903 ;;; The `hook' Widget.
3905 (define-widget 'hook
'list
3906 "An Emacs Lisp hook."
3907 :value-to-internal
(lambda (_widget value
)
3908 (if (and value
(symbolp value
))
3911 :match
(lambda (widget value
)
3913 (widget-group-match widget value
)))
3914 ;; Avoid adding undefined functions to the hook, especially for
3915 ;; things like `find-file-hook' or even more basic ones, to avoid
3917 :set
(lambda (symbol value
)
3920 (add-hook symbol elt
))))
3921 :convert-widget
'custom-hook-convert-widget
3924 (defun custom-hook-convert-widget (widget)
3925 ;; Handle `:options'.
3926 (let* ((options (widget-get widget
:options
))
3927 (other `(editable-list :inline t
3928 :entry-format
"%i %d%v"
3929 (function :format
" %v")))
3931 (list `(checklist :inline t
3932 ,@(mapcar (lambda (entry)
3933 `(function-item ,entry
))
3937 (widget-put widget
:args args
)
3940 ;;; The `custom-group-link' Widget.
3942 (define-widget 'custom-group-link
'link
3943 "Show parent in other window when activated."
3944 :button-face
'custom-link
3945 :mouse-face
'highlight
3946 :pressed-face
'highlight
3947 :help-echo
"Create customization buffer for this group."
3948 :keymap custom-mode-link-map
3949 :follow-link
'mouse-face
3950 :action
'custom-group-link-action
)
3952 (defun custom-group-link-action (widget &rest _ignore
)
3953 (customize-group (widget-value widget
)))
3955 ;;; The `custom-group' Widget.
3957 (defcustom custom-group-tag-faces nil
3958 "Face used for group tags.
3959 The first member is used for level 1 groups, the second for level 2,
3960 and so forth. The remaining group tags are shown with `custom-group-tag'."
3961 :type
'(repeat face
)
3962 :group
'custom-faces
)
3964 (defface custom-group-tag-1
3965 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3966 (((class color
) (background dark
)) :foreground
"pink")
3967 (((min-colors 88) (class color
) (background light
)) :foreground
"red1")
3968 (((class color
) (background light
)) :foreground
"red"))
3969 "Face for group tags."
3970 :group
'custom-faces
)
3972 (defface custom-group-tag
3973 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3974 (((class color
) (background dark
)) :foreground
"light blue")
3975 (((min-colors 88) (class color
) (background light
)) :foreground
"blue1")
3976 (((class color
) (background light
)) :foreground
"blue")
3978 "Face for low level group tags."
3979 :group
'custom-faces
)
3981 (defface custom-group-subtitle
3983 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3984 :group
'custom-faces
)
3986 (defvar custom-group-doc-align-col
20)
3988 (define-widget 'custom-group
'custom
3991 :sample-face-get
'custom-group-sample-face-get
3992 :documentation-property
'group-documentation
3993 :help-echo
"Set or reset all members of this group."
3994 :value-create
'custom-group-value-create
3995 :action
'custom-group-action
3996 :custom-category
'group
3997 :custom-set
'custom-group-set
3998 :custom-mark-to-save
'custom-group-mark-to-save
3999 :custom-reset-current
'custom-group-reset-current
4000 :custom-reset-saved
'custom-group-reset-saved
4001 :custom-reset-standard
'custom-group-reset-standard
4002 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
4003 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
4004 :custom-menu
'custom-group-menu-create
)
4006 (defun custom-group-sample-face-get (widget)
4007 ;; Use :sample-face.
4008 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
4011 (define-widget 'custom-group-visibility
'visibility
4012 "An indicator and manipulator for hidden group contents."
4013 :create
'custom-group-visibility-create
)
4015 (defun custom-group-visibility-create (widget)
4016 (let ((visible (widget-value widget
)))
4018 (insert "--------")))
4019 (widget-default-create widget
))
4021 (defun custom-group-members (symbol groups-only
)
4022 "Return SYMBOL's custom group members.
4023 If GROUPS-ONLY is non-nil, return only those members that are groups."
4024 (if (not groups-only
)
4025 (get symbol
'custom-group
)
4027 (dolist (entry (get symbol
'custom-group
))
4028 (when (eq (nth 1 entry
) 'custom-group
)
4029 (push entry members
)))
4030 (nreverse members
))))
4032 (defun custom-group-value-create (widget)
4033 "Insert a customize group for WIDGET in the current buffer."
4034 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4035 (custom-load-widget widget
))
4036 (let* ((state (widget-get widget
:custom-state
))
4037 (level (widget-get widget
:custom-level
))
4038 ;; (indent (widget-get widget :indent))
4039 (prefix (widget-get widget
:custom-prefix
))
4040 (buttons (widget-get widget
:buttons
))
4041 (tag (substitute-command-keys (widget-get widget
:tag
)))
4042 (symbol (widget-value widget
))
4043 (members (custom-group-members symbol
4044 (and (eq custom-buffer-style
'tree
)
4045 custom-browse-only-groups
)))
4046 (doc (substitute-command-keys (widget-docstring widget
))))
4047 (cond ((and (eq custom-buffer-style
'tree
)
4049 (or members
(custom-unloaded-widget-p widget
)))
4050 (custom-browse-insert-prefix prefix
)
4051 (push (widget-create-child-and-convert
4052 widget
'custom-browse-visibility
4056 (push (widget-create-child-and-convert
4057 widget
'custom-browse-group-tag
)
4059 (insert " " tag
"\n")
4060 (widget-put widget
:buttons buttons
))
4061 ((and (eq custom-buffer-style
'tree
)
4062 (zerop (length members
)))
4063 (custom-browse-insert-prefix prefix
)
4065 (push (widget-create-child-and-convert
4066 widget
'custom-browse-group-tag
)
4068 (insert " " tag
"\n")
4069 (widget-put widget
:buttons buttons
))
4070 ((eq custom-buffer-style
'tree
)
4071 (custom-browse-insert-prefix prefix
)
4072 (if (zerop (length members
))
4074 (custom-browse-insert-prefix prefix
)
4076 ;; (widget-glyph-insert nil "[ ]" "empty")
4077 ;; (widget-glyph-insert nil "-- " "horizontal")
4078 (push (widget-create-child-and-convert
4079 widget
'custom-browse-group-tag
)
4081 (insert " " tag
"\n")
4082 (widget-put widget
:buttons buttons
))
4083 (push (widget-create-child-and-convert
4084 widget
'custom-browse-visibility
4085 ;; :tag-glyph "minus"
4089 ;; (widget-glyph-insert nil "-\\ " "top")
4090 (push (widget-create-child-and-convert
4091 widget
'custom-browse-group-tag
)
4093 (insert " " tag
"\n")
4094 (widget-put widget
:buttons buttons
)
4095 (message "Creating group...")
4096 (let* ((members (custom-sort-items
4098 ;; Never sort the top-level custom group.
4099 (unless (eq symbol
'emacs
)
4100 custom-browse-sort-alphabetically
)
4101 custom-browse-order-groups
))
4102 (prefixes (widget-get widget
:custom-prefixes
))
4103 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4104 (extra-prefix (if (widget-get widget
:custom-last
)
4107 (prefix (concat prefix extra-prefix
))
4110 (setq entry
(car members
)
4111 members
(cdr members
))
4112 (push (widget-create-child-and-convert
4113 widget
(nth 1 entry
)
4115 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4116 :custom-prefixes custom-prefix-list
4117 :custom-level
(1+ level
)
4118 :custom-last
(null members
)
4119 :value
(nth 0 entry
)
4120 :custom-prefix prefix
)
4122 (widget-put widget
:children
(reverse children
)))
4123 (message "Creating group...done")))
4126 ;; Create level indicator.
4128 (if (eq custom-buffer-style
'links
)
4129 (push (widget-create-child-and-convert
4130 widget
'custom-group-link
4134 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4136 (push (widget-create-child-and-convert
4137 widget
'custom-group-visibility
4138 :help-echo
"Show members of this group."
4139 :action
'custom-toggle-parent
4140 (not (eq state
'hidden
)))
4142 (if (>= (current-column) custom-group-doc-align-col
)
4144 ;; Create magic button.
4145 (let ((magic (widget-create-child-and-convert
4146 widget
'custom-magic nil
)))
4147 (widget-put widget
:custom-magic magic
)
4148 (push magic buttons
))
4150 (widget-put widget
:buttons buttons
)
4151 ;; Insert documentation.
4152 (if (and (eq custom-buffer-style
'links
) (> level
1))
4153 (widget-put widget
:documentation-indent
4154 custom-group-doc-align-col
))
4155 (widget-add-documentation-string-button
4156 widget
:visibility-widget
'custom-visibility
))
4160 ;; Draw a horizontal line (this works for both graphical
4161 ;; and text displays):
4164 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4165 (overlay-put (make-overlay p
(1+ p
))
4167 (propertize "\n" 'face
'(:underline t
)
4168 'display
'(space :align-to
999))))
4170 ;; Add parent groups references above the group.
4172 (if (custom-add-parent-links widget
"Parent groups:")
4174 (insert-char ?\s
(* custom-buffer-indent
(1- level
)))
4176 (let ((start (point)))
4177 (insert tag
" group: ")
4178 (widget-specify-sample widget start
(point)))
4181 (insert " Group definition missing. "))
4182 ((< (length doc
) 50)
4184 ;; Create visibility indicator.
4185 (unless (eq custom-buffer-style
'links
)
4187 (push (widget-create-child-and-convert
4189 :help-echo
"Hide members of this group."
4190 :action
'custom-toggle-parent
4191 (not (eq state
'hidden
)))
4195 ;; Create magic button.
4196 (let ((magic (widget-create-child-and-convert
4197 widget
'custom-magic
4200 (widget-put widget
:custom-magic magic
)
4201 (push magic buttons
))
4203 (widget-put widget
:buttons buttons
)
4204 ;; Insert documentation.
4205 (when (and doc
(>= (length doc
) 50))
4206 (widget-add-documentation-string-button
4207 widget
:visibility-widget
'custom-visibility
))
4210 (if nil
;;; This should test that the buffer
4211 ;;; was not made to display a group.
4213 (insert-char ?\s custom-buffer-indent
)
4214 (custom-add-parent-links widget
)))
4215 (custom-add-see-also widget
4216 (make-string (* custom-buffer-indent level
)
4219 (message "Creating group...")
4220 (let* ((members (custom-sort-items
4222 ;; Never sort the top-level custom group.
4223 (unless (eq symbol
'emacs
)
4224 custom-buffer-sort-alphabetically
)
4225 custom-buffer-order-groups
))
4226 (prefixes (widget-get widget
:custom-prefixes
))
4227 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4228 (len (length members
))
4230 (reporter (make-progress-reporter
4231 "Creating group entries..." 0 len
))
4232 (have-subtitle (and (not (eq symbol
'emacs
))
4233 (eq custom-buffer-order-groups
'last
)))
4237 (dolist (entry members
)
4238 (unless (eq prev-type
'custom-group
)
4239 (widget-insert "\n"))
4240 (progress-reporter-update reporter
(setq count
(1+ count
)))
4241 (let ((sym (nth 0 entry
))
4242 (type (nth 1 entry
)))
4243 (when (and have-subtitle
(eq type
'custom-group
))
4244 (setq have-subtitle nil
)
4246 (propertize "Subgroups:\n" 'face
'custom-group-subtitle
)))
4247 (setq prev-type type
)
4248 (push (widget-create-child-and-convert
4251 :tag
(custom-unlispify-tag-name sym
)
4252 :custom-prefixes custom-prefix-list
4253 :custom-level
(1+ level
)
4256 (unless (eq (preceding-char) ?
\n)
4257 (widget-insert "\n"))))
4259 (setq children
(nreverse children
))
4260 (mapc 'custom-magic-reset children
)
4261 (widget-put widget
:children children
)
4262 (custom-group-state-update widget
)
4263 (progress-reporter-done reporter
))
4265 (let ((p (1+ (point))))
4267 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4268 (overlay-put (make-overlay p
(1+ p
))
4270 (propertize "\n" 'face
'(:underline t
)
4271 'display
'(space :align-to
999))))))))
4273 (defvar custom-group-menu
4274 `(("Set for Current Session" custom-group-set
4276 (eq (widget-get widget
:custom-state
) 'modified
)))
4277 ,@(when (or custom-file init-file-user
)
4278 '(("Save for Future Sessions" custom-group-save
4280 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4281 ("Undo Edits" custom-group-reset-current
4283 (memq (widget-get widget
:custom-state
) '(modified))))
4284 ("Revert This Session's Customizations" custom-group-reset-saved
4286 (memq (widget-get widget
:custom-state
) '(modified set
))))
4287 ,@(when (or custom-file init-file-user
)
4288 '(("Erase Customization" custom-group-reset-standard
4290 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4291 "Alist of actions for the `custom-group' widget.
4292 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4293 the menu entry, ACTION is the function to call on the widget when the
4294 menu is selected, and FILTER is a predicate which takes a `custom-group'
4295 widget as an argument, and returns non-nil if ACTION is valid on that
4296 widget. If FILTER is nil, ACTION is always valid.")
4298 (defun custom-group-action (widget &optional event
)
4299 "Show the menu for `custom-group' WIDGET.
4300 Optional EVENT is the location for the menu."
4301 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4302 (custom-toggle-hide widget
)
4303 (let* ((completion-ignore-case t
)
4304 (answer (widget-choose (concat "Operation on "
4305 (custom-unlispify-tag-name
4306 (widget-get widget
:value
)))
4307 (custom-menu-filter custom-group-menu
4311 (funcall answer widget
)))))
4313 (defun custom-group-set (widget)
4314 "Set changes in all modified group members."
4315 (dolist (child (widget-get widget
:children
))
4316 (when (eq (widget-get child
:custom-state
) 'modified
)
4317 (widget-apply child
:custom-set
))))
4319 (defun custom-group-mark-to-save (widget)
4320 "Mark all modified group members for saving."
4321 (dolist (child (widget-get widget
:children
))
4322 (when (memq (widget-get child
:custom-state
) '(modified set
))
4323 (widget-apply child
:custom-mark-to-save
))))
4325 (defsubst custom-group-state-set-and-redraw
(widget)
4326 "Set state of group widget WIDGET and redraw with current settings."
4327 (dolist (child (widget-get widget
:children
))
4328 (when (memq (widget-get child
:custom-state
) '(modified set
))
4329 (widget-apply child
:custom-state-set-and-redraw
))))
4331 (defun custom-group-save (widget)
4332 "Save all modified group members."
4333 (custom-group-mark-to-save widget
)
4335 (custom-group-state-set-and-redraw widget
))
4337 (defun custom-group-reset-current (widget)
4338 "Reset all modified group members."
4339 (dolist (child (widget-get widget
:children
))
4340 (when (eq (widget-get child
:custom-state
) 'modified
)
4341 (widget-apply child
:custom-reset-current
))))
4343 (defun custom-group-reset-saved (widget)
4344 "Reset all modified or set group members."
4345 (dolist (child (widget-get widget
:children
))
4346 (when (memq (widget-get child
:custom-state
) '(modified set
))
4347 (widget-apply child
:custom-reset-saved
))))
4349 (defun custom-group-reset-standard (widget)
4350 "Reset all modified, set, or saved group members."
4351 (let ((custom-reset-standard-variables-list '(t))
4352 (custom-reset-standard-faces-list '(t)))
4353 (custom-group-mark-to-reset-standard widget
)
4354 (custom-reset-standard-save-and-update)))
4356 (defun custom-group-mark-to-reset-standard (widget)
4357 "Mark to reset all modified, set, or saved group members."
4358 (dolist (child (widget-get widget
:children
))
4359 (when (memq (widget-get child
:custom-state
)
4360 '(modified set saved
))
4361 (widget-apply child
:custom-mark-to-reset-standard
))))
4363 (defun custom-group-state-update (widget)
4365 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4366 (let* ((children (widget-get widget
:children
))
4367 (states (mapcar (lambda (child)
4368 (widget-get child
:custom-state
))
4370 (magics custom-magic-alist
)
4373 (let ((magic (car (car magics
))))
4374 (if (and (not (eq magic
'hidden
))
4375 (memq magic states
))
4378 (setq magics
(cdr magics
)))))
4379 (widget-put widget
:custom-state found
)))
4380 (custom-magic-reset widget
))
4382 ;;; Reading and writing the custom file.
4385 (defcustom custom-file nil
4386 "File used for storing customization information.
4387 The default is nil, which means to use your init file
4388 as specified by `user-init-file'. If the value is not nil,
4389 it should be an absolute file name.
4391 You can set this option through Custom, if you carefully read the
4392 last paragraph below. However, usually it is simpler to write
4393 something like the following in your init file:
4395 \(setq custom-file \"~/.emacs-custom.el\")
4398 Note that both lines are necessary: the first line tells Custom to
4399 save all customizations in this file, but does not load it.
4401 When you change this variable outside Custom, look in the
4402 previous custom file (usually your init file) for the
4403 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4404 and copy them (whichever ones you find) to the new custom file.
4405 This will preserve your existing customizations.
4407 If you save this option using Custom, Custom will write all
4408 currently saved customizations, including the new one for this
4409 option itself, into the file you specify, overwriting any
4410 `custom-set-variables' and `custom-set-faces' forms already
4411 present in that file. It will not delete any customizations from
4412 the old custom file. You should do that manually if that is what you
4413 want. You also have to put something like (load \"CUSTOM-FILE\")
4414 in your init file, where CUSTOM-FILE is the actual name of the
4415 file. Otherwise, Emacs will not load the file when it starts up,
4416 and hence will not set `custom-file' to that file either."
4417 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4418 (file :format
"%t:%v%d"
4420 "Please read entire docstring below before setting \
4421 this through Custom.
4422 Click on \"More\" (or position point there and press RETURN)
4423 if only the first line of the docstring is shown."))
4426 (defun custom-file (&optional no-error
)
4427 "Return the file name for saving customizations."
4428 (if (or (null user-init-file
)
4429 (and (null custom-file
) init-file-had-error
))
4430 ;; Started with -q, i.e. the file containing Custom settings
4431 ;; hasn't been read. Saving settings there won't make much
4435 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4436 (file-chase-links (or custom-file user-init-file
))))
4438 ;; If recentf-mode is non-nil, this is defined.
4439 (declare-function recentf-expand-file-name
"recentf" (name))
4442 (defun custom-save-all ()
4443 "Save all customizations in `custom-file'."
4444 (when (and (null custom-file
) init-file-had-error
)
4445 (error "Cannot save customizations; init file was not fully loaded"))
4446 (let* ((filename (custom-file))
4451 (recentf-expand-file-name (custom-file)))
4454 (old-buffer (find-buffer-visiting filename
))
4457 (with-current-buffer (let ((find-file-visit-truename t
))
4459 (let ((delay-mode-hooks t
))
4460 (find-file-noselect filename
))))
4461 ;; We'll save using file-precious-flag, so avoid destroying
4462 ;; symlinks. (If we're not already visiting the buffer, this is
4463 ;; handled by find-file-visit-truename, above.)
4465 (setq old-buffer-name
(buffer-file-name))
4466 (set-visited-file-name (file-chase-links filename
)))
4468 (unless (eq major-mode
'emacs-lisp-mode
)
4469 (delay-mode-hooks (emacs-lisp-mode)))
4470 (let ((inhibit-read-only t
)
4473 (custom-save-variables)
4474 (custom-save-faces))
4475 (let ((file-precious-flag t
))
4479 (set-visited-file-name old-buffer-name
)
4480 (set-buffer-modified-p nil
))
4481 (kill-buffer (current-buffer))))))
4484 (defun customize-save-customized ()
4485 "Save all user options which have been set in this session."
4487 (mapatoms (lambda (symbol)
4488 (let ((face (get symbol
'customized-face
))
4489 (value (get symbol
'customized-value
))
4490 (face-comment (get symbol
'customized-face-comment
))
4492 (get symbol
'customized-variable-comment
)))
4494 (put symbol
'saved-face face
)
4495 (custom-push-theme 'theme-face symbol
'user
'set value
)
4496 (put symbol
'customized-face nil
))
4498 (put symbol
'saved-value value
)
4499 (custom-push-theme 'theme-value symbol
'user
'set value
)
4500 (put symbol
'customized-value nil
))
4501 (when variable-comment
4502 (put symbol
'saved-variable-comment variable-comment
)
4503 (put symbol
'customized-variable-comment nil
))
4505 (put symbol
'saved-face-comment face-comment
)
4506 (put symbol
'customized-face-comment nil
)))))
4507 ;; We really should update all custom buffers here.
4510 ;; Editing the custom file contents in a buffer.
4512 (defun custom-save-delete (symbol)
4513 "Delete all calls to SYMBOL from the contents of the current buffer.
4514 Leave point at the old location of the first such call,
4515 or (if there were none) at the end of the buffer.
4517 This function does not save the buffer."
4518 (goto-char (point-min))
4519 ;; Skip all whitespace and comments.
4520 (while (forward-comment 1))
4522 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4525 (while t
;; We exit this loop only via throw.
4526 ;; Skip all whitespace and comments.
4527 (while (forward-comment 1))
4528 (let ((start (point))
4529 (sexp (condition-case nil
4530 (read (current-buffer))
4531 (end-of-file (throw 'found nil
)))))
4532 (when (and (listp sexp
)
4533 (eq (car sexp
) symbol
))
4534 (delete-region start
(point))
4536 (setq first
(point)))))))
4539 ;; Move in front of local variables, otherwise long Custom
4540 ;; entries would make them ineffective.
4541 (let ((pos (point-max))
4542 (case-fold-search t
))
4544 (goto-char (point-max))
4545 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4547 (when (search-forward "Local Variables:" nil t
)
4548 (setq pos
(line-beginning-position))))
4551 (defvar sort-fold-case
) ; defined in sort.el
4553 (defun custom-save-variables ()
4554 "Save all customized variables in `custom-file'."
4556 (custom-save-delete 'custom-set-variables
)
4557 (let ((standard-output (current-buffer))
4558 (saved-list (make-list 1 0))
4560 ;; First create a sorted list of saved variables.
4563 (if (and (get symbol
'saved-value
)
4564 ;; ignore theme values
4565 (or (null (get symbol
'theme-value
))
4566 (eq 'user
(caar (get symbol
'theme-value
)))))
4567 (nconc saved-list
(list symbol
)))))
4568 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4571 (princ "(custom-set-variables
4572 ;; custom-set-variables was added by Custom.
4573 ;; If you edit it by hand, you could mess it up, so be careful.
4574 ;; Your init file should contain only one such instance.
4575 ;; If there is more than one, they won't work right.\n")
4576 (dolist (symbol saved-list
)
4577 (let ((spec (car-safe (get symbol
'theme-value
)))
4578 (value (get symbol
'saved-value
))
4579 (requests (get symbol
'custom-requests
))
4580 (now (and (not (custom-variable-p symbol
))
4582 (eq (get symbol
'force-value
)
4584 (comment (get symbol
'saved-variable-comment
)))
4585 ;; Check REQUESTS for validity.
4586 (dolist (request requests
)
4587 (when (and (symbolp request
) (not (featurep request
)))
4588 (message "Unknown requested feature: %s" request
)
4589 (setq requests
(delq request requests
))))
4590 ;; Is there anything customized about this variable?
4591 (when (or (and spec
(eq (car spec
) 'user
))
4593 (and (null spec
) (get symbol
'saved-value
)))
4594 ;; Output an element for this variable.
4595 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4596 ;; SYMBOL is the variable name.
4597 ;; VALUE-FORM is an expression to return the customized value.
4598 ;; NOW if non-nil means always set the variable immediately
4599 ;; when the customizations are reloaded. This is used
4600 ;; for rogue variables
4601 ;; REQUESTS is a list of packages to load before setting the
4602 ;; variable. Each element of it will be passed to `require'.
4603 ;; COMMENT is whatever comment the user has specified
4604 ;; with the customize facility.
4610 (let ((val (prin1-to-string (car value
))))
4611 (if (< (length val
) 60)
4613 (newline-and-indent)
4614 (let ((beginning-of-val (point)))
4617 (goto-char beginning-of-val
)
4618 (indent-pp-sexp 1)))))
4619 (when (or now requests comment
)
4622 (when (or requests comment
)
4632 (when (/= (following-char) ?
\n)
4635 (defun custom-save-faces ()
4636 "Save all customized faces in `custom-file'."
4638 (custom-save-delete 'custom-reset-faces
)
4639 (custom-save-delete 'custom-set-faces
)
4640 (let ((standard-output (current-buffer))
4641 (saved-list (make-list 1 0))
4643 ;; First create a sorted list of saved faces.
4646 (if (and (get symbol
'saved-face
)
4647 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4648 (nconc saved-list
(list symbol
)))))
4649 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4650 ;; The default face must be first, since it affects the others.
4651 (if (memq 'default saved-list
)
4652 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4655 (princ "(custom-set-faces
4656 ;; custom-set-faces was added by Custom.
4657 ;; If you edit it by hand, you could mess it up, so be careful.
4658 ;; Your init file should contain only one such instance.
4659 ;; If there is more than one, they won't work right.\n")
4660 (dolist (symbol saved-list
)
4661 (let ((spec (car-safe (get symbol
'theme-face
)))
4662 (value (get symbol
'saved-face
))
4663 (now (not (or (get symbol
'face-defface-spec
)
4664 (and (not (custom-facep symbol
))
4665 (not (get symbol
'force-face
))))))
4666 (comment (get symbol
'saved-face-comment
)))
4667 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4669 (and (null spec
) (get symbol
'saved-face
)))
4670 ;; Don't print default face here.
4677 (when (or now comment
)
4687 (when (/= (following-char) ?
\n)
4690 ;;; The Customize Menu.
4694 (defcustom custom-menu-nesting
2
4695 "Maximum nesting in custom menus."
4697 :group
'custom-menu
)
4699 (defun custom-face-menu-create (_widget symbol
)
4700 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4701 (vector (custom-unlispify-menu-entry symbol
)
4702 `(customize-face ',symbol
)
4705 (defun custom-variable-menu-create (_widget symbol
)
4706 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4707 (let ((type (get symbol
'custom-type
)))
4708 (unless (listp type
)
4709 (setq type
(list type
)))
4710 (if (and type
(widget-get type
:custom-menu
))
4711 (widget-apply type
:custom-menu symbol
)
4712 (vector (custom-unlispify-menu-entry symbol
)
4713 `(customize-variable ',symbol
)
4716 ;; Add checkboxes to boolean variable entries.
4717 (widget-put (get 'boolean
'widget-type
)
4718 :custom-menu
(lambda (_widget symbol
)
4719 (vector (custom-unlispify-menu-entry symbol
)
4720 `(customize-variable ',symbol
)
4722 ':selected symbol
)))
4724 (defun custom-group-menu-create (_widget symbol
)
4725 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4726 `( ,(custom-unlispify-menu-entry symbol t
)
4727 :filter
(lambda (&rest junk
)
4728 (let* ((menu (custom-menu-create ',symbol
)))
4729 (if (consp menu
) (cdr menu
) menu
)))))
4732 (defun custom-menu-create (symbol)
4733 "Create menu for customization group SYMBOL.
4734 The menu is in a format applicable to `easy-menu-define'."
4735 (let* ((deactivate-mark nil
)
4736 (item (vector (custom-unlispify-menu-entry symbol
)
4737 `(customize-group ',symbol
)
4739 (if (and (or (not (boundp 'custom-menu-nesting
))
4740 (>= custom-menu-nesting
0))
4742 (custom-load-symbol symbol
)
4743 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4744 (let ((custom-prefix-list (custom-prefix-add symbol
4745 custom-prefix-list
))
4746 (members (custom-sort-items (get symbol
'custom-group
)
4747 custom-menu-sort-alphabetically
4748 custom-menu-order-groups
)))
4749 `(,(custom-unlispify-menu-entry symbol t
)
4752 ,@(mapcar (lambda (entry)
4753 (widget-apply (if (listp (nth 1 entry
))
4755 (list (nth 1 entry
)))
4756 :custom-menu
(nth 0 entry
)))
4761 (defun customize-menu-create (symbol &optional name
)
4762 "Return a customize menu for customization group SYMBOL.
4763 If optional NAME is given, use that as the name of the menu.
4764 Otherwise the menu will be named `Customize'.
4765 The format is suitable for use with `easy-menu-define'."
4767 (setq name
"Customize"))
4769 :filter
(lambda (&rest junk
)
4770 (let ((menu (custom-menu-create ',symbol
)))
4771 (if (consp menu
) (cdr menu
) menu
)))))
4773 ;;; Toolbar and menubar support
4776 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4777 "Menu used in customization buffers."
4778 (nconc (list "Custom"
4779 (customize-menu-create 'customize
))
4780 (mapcar (lambda (arg)
4781 (let ((tag (nth 0 arg
))
4782 (command (nth 1 arg
))
4783 (active (nth 2 arg
))
4785 (vector tag command
:active
(eval active
) :help help
)))
4788 (defvar tool-bar-map
)
4790 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4791 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4792 ;;; we set this up lazily in `Custom-mode'.
4793 (defvar custom-tool-bar-map nil
4794 "Keymap for toolbar in Custom mode.")
4796 ;;; The Custom Mode.
4798 (defun Custom-no-edit (_pos &optional _event
)
4799 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4801 (error "You can't edit this part of the Custom buffer"))
4803 (defun Custom-newline (pos &optional event
)
4804 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4806 (let ((button (get-char-property pos
'button
)))
4807 ;; If there is no button at point, then use the one at the start
4808 ;; of the line, if it is a custom-group-link (bug#2298).
4810 (if (setq button
(get-char-property (line-beginning-position) 'button
))
4811 (or (eq (widget-type button
) 'custom-group-link
)
4812 (setq button nil
))))
4814 (widget-apply-action button event
)
4815 (error "You can't edit this part of the Custom buffer"))))
4817 (defun Custom-goto-parent ()
4818 "Go to the parent group listed at the top of this buffer.
4819 If several parents are listed, go to the first of them."
4822 (goto-char (point-min))
4823 (if (search-forward "\nParent groups: " nil t
)
4824 (let* ((button (get-char-property (point) 'button
))
4825 (parent (downcase (widget-get button
:tag
))))
4826 (customize-group parent
)))))
4828 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4830 (defcustom Custom-mode-hook nil
4831 "Hook called when entering Custom mode."
4833 :group
'custom-buffer
)
4835 (defun custom-state-buffer-message (widget)
4836 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4837 (message "To install your edits, invoke [State] and choose the Set operation")))
4839 (defun custom--initialize-widget-variables ()
4840 (setq-local widget-documentation-face
'custom-documentation
)
4841 (setq-local widget-button-face custom-button
)
4842 (setq-local widget-button-pressed-face custom-button-pressed
)
4843 (setq-local widget-mouse-face custom-button-mouse
)
4844 ;; We need this because of the "More" button on docstrings.
4845 ;; Otherwise clicking on "More" can push point offscreen, which
4846 ;; causes the window to recenter on point, which pushes the
4847 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4848 (setq-local widget-button-click-moves-point t
)
4849 ;; When possible, use relief for buttons, not bracketing. This test
4850 ;; may not be optimal.
4851 (when custom-raised-buttons
4852 (setq-local widget-push-button-prefix
"")
4853 (setq-local widget-push-button-suffix
"")
4854 (setq-local widget-link-prefix
"")
4855 (setq-local widget-link-suffix
""))
4856 (setq show-trailing-whitespace nil
))
4858 (define-derived-mode Custom-mode nil
"Custom"
4859 "Major mode for editing customization buffers.
4861 The following commands are available:
4864 Move to next button, link or editable field. \\[widget-forward]
4865 Move to previous button, link or editable field. \\[widget-backward]
4866 \\<custom-field-keymap>\
4867 Complete content of editable text field. \\[widget-complete]
4868 \\<custom-mode-map>\
4869 Invoke button under the mouse pointer. \\[widget-button-click]
4870 Invoke button under point. \\[widget-button-press]
4871 Set all options from current text. \\[Custom-set]
4872 Make values in current text permanent. \\[Custom-save]
4873 Make text match actual option values. \\[Custom-reset-current]
4874 Reset options to permanent settings. \\[Custom-reset-saved]
4875 Erase customizations; set options
4876 and buffer text to the standard values. \\[Custom-reset-standard]
4878 Entry to this mode calls the value of `Custom-mode-hook'
4879 if that value is non-nil."
4880 (use-local-map custom-mode-map
)
4881 (easy-menu-add Custom-mode-menu
)
4882 (setq-local tool-bar-map
4883 (or custom-tool-bar-map
4884 ;; Set up `custom-tool-bar-map'.
4885 (let ((map (make-sparse-keymap)))
4888 (tool-bar-local-item-from-menu
4889 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4890 :label
(nth 5 arg
)))
4892 (setq custom-tool-bar-map map
))))
4893 (make-local-variable 'custom-options
)
4894 (make-local-variable 'custom-local-buffer
)
4895 (custom--initialize-widget-variables)
4896 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4898 (put 'Custom-mode
'mode-class
'special
)
4900 (define-obsolete-function-alias 'custom-mode
'Custom-mode
"23.1")
4906 ;;; cus-edit.el ends here