1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996-1997, 1999-2012 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file implements the code to create and edit customize buffers.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
35 ;; The identity of a customize option is represented by a Lisp symbol.
36 ;; The following values are associated with an option.
38 ;; 0. The current value.
40 ;; This is the value of the option as seen by "the rest of Emacs".
42 ;; Usually extracted by 'default-value', but can be extracted with
43 ;; different means if the option symbol has the 'custom-get'
44 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; 1. The widget value.
49 ;; This is the value shown in the widget in a customize buffer.
51 ;; 2. The customized value.
53 ;; This is the last value given to the option through customize.
55 ;; It is stored in the 'customized-value' property of the option, in a
56 ;; cons-cell whose car evaluates to the customized value.
58 ;; 3. The saved value.
60 ;; This is last value saved from customize.
62 ;; It is stored in the 'saved-value' property of the option, in a
63 ;; cons-cell whose car evaluates to the saved value.
65 ;; 4. The standard value.
67 ;; This is the value given in the 'defcustom' declaration.
69 ;; It is stored in the 'standard-value' property of the option, in a
70 ;; cons-cell whose car evaluates to the standard value.
72 ;; 5. The "think" value.
74 ;; This is what customize thinks the current value should be.
76 ;; This is the customized value, if any such value exists, otherwise
77 ;; the saved value, if that exists, and as a last resort the standard
80 ;; The reason for storing values unevaluated: This is so you can have
81 ;; values that depend on the environment. For example, you can have a
82 ;; variable that has one value when Emacs is running under a window
83 ;; system, and another value on a tty. Since the evaluation is only done
84 ;; when the variable is first initialized, this is only relevant for the
85 ;; saved (and standard) values, but affect others values for
88 ;; You can see (and modify and save) this unevaluated value by selecting
89 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
90 ;; give you the unevaluated saved value, if any, otherwise the
91 ;; unevaluated standard value.
93 ;; The possible states for a customize widget are:
97 ;; The state has not been determined yet.
101 ;; The widget value is different from the current value.
105 ;; The current value is different from the "think" value.
109 ;; The "think" value is the customized value.
113 ;; The "think" value is the saved value.
117 ;; The "think" value is the standard value.
121 ;; There is no standard value. This means that the variable was
122 ;; not defined with defcustom, nor handled in cus-start.el. Most
123 ;; standard interactive Custom commands do not let you create a
124 ;; Custom buffer containing such variables. However, such Custom
125 ;; buffers can be created, for instance, by calling
126 ;; `customize-apropos' with a prefix arg or by calling
127 ;; `customize-option' non-interactively.
131 ;; There is no widget value.
135 ;; The widget value is not valid member of the :type specified for the
143 (defvar custom-versions-load-alist
) ; from cus-load
144 (defvar recentf-exclude
) ; from recentf.el
154 (put 'custom-define-hook
'custom-type
'hook
)
155 (put 'custom-define-hook
'standard-value
'(nil))
156 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link
'(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
169 (defgroup convenience nil
170 "Convenience features for faster editing."
174 "Support for editing files."
178 "Support for editing text files."
183 "Support for editing binary data files."
187 "Abbreviation handling, typing shortcuts, macros."
191 (defgroup matching nil
192 "Various sorts of searching and matching."
195 (defgroup emulations nil
196 "Emulations of other editors."
197 :link
'(custom-manual "(emacs)Emulation")
204 (defgroup outlines nil
205 "Support for hierarchical outlining."
208 (defgroup external nil
209 "Interfacing to external utilities."
213 "Communications, networking, and remote access to files."
217 (defgroup processes nil
218 "Process, subshell, compilation, and job control support."
221 (defgroup programming nil
222 "Support for programming in other languages."
225 (defgroup languages nil
226 "Modes for editing programming languages."
230 "Lisp support, including Emacs Lisp."
231 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
236 "Support for the C language and related languages."
237 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
238 :link
'(custom-manual "(ccmode)")
245 (defgroup applications nil
246 "Applications written in Emacs."
249 (defgroup calendar nil
250 "Calendar and time management support."
251 :group
'applications
)
254 "Modes for electronic-mail handling."
255 :group
'applications
)
258 "Reading and posting to newsgroups."
259 :link
'(custom-manual "(gnus)")
260 :group
'applications
)
263 "Games, jokes and amusements."
264 :group
'applications
)
266 (defgroup development nil
267 "Support for further development of Emacs."
271 "Support for Emacs documentation."
274 (defgroup extensions nil
275 "Emacs Lisp language extensions."
278 (defgroup internal nil
279 "Code for Emacs internals, build process, defaults."
283 "Maintenance aids for the Emacs development group."
287 (defgroup environment nil
288 "Fitting Emacs with its environment."
291 (defgroup hardware nil
292 "Support for interfacing with miscellaneous hardware."
295 (defgroup terminals nil
296 "Support for terminal types."
300 "Interfaces, assistants, and emulators for UNIX features."
304 "Internationalization and alternate character-set support."
305 :link
'(custom-manual "(emacs)International")
310 "The X Window system."
314 "Support for Emacs frames and window systems."
318 "Code related to the TeX formatter."
319 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
323 "Support for multiple fonts."
327 "Support for on-line help systems."
330 (defgroup multimedia nil
331 "Non-textual support, specifically images and sound."
335 "Code local to your site."
338 (defgroup customize
'((widgets custom-group
))
339 "Customization of the Customization support."
343 (defgroup custom-faces nil
344 "Faces used by customize."
348 (defgroup custom-browse nil
349 "Control customize browser."
353 (defgroup custom-buffer nil
354 "Control customize buffers."
358 (defgroup custom-menu nil
359 "Control customize menus."
364 "Storage allocation and gc for GNU Emacs Lisp interpreter."
365 :tag
"Storage Allocation"
369 "Undoing changes in buffers."
370 :link
'(custom-manual "(emacs)Undo")
373 (defgroup mode-line nil
374 "Contents of the mode line."
377 (defgroup editing-basics nil
378 "Most basic editing facilities."
381 (defgroup display nil
382 "How characters are displayed in buffers."
385 (defgroup execute nil
386 "Executing external commands."
389 (defgroup installation nil
390 "The Emacs installation."
398 "Internal Emacs limits."
402 "Debugging Emacs itself."
405 (defgroup keyboard nil
406 "Input from the keyboard."
410 "Input from the mouse."
414 "Input from the menus."
418 "Handling data from drag and drop."
421 (defgroup auto-save nil
422 "Preventing accidental loss of data."
425 (defgroup processes-basics nil
426 "Basic stuff dealing with processes."
430 "MULE Emacs internationalization."
433 (defgroup windows nil
434 "Windows within a frame."
435 :link
'(custom-manual "(emacs)Windows")
438 ;;; Custom mode keymaps
440 (defvar custom-mode-map
441 (let ((map (make-keymap)))
442 (set-keymap-parent map widget-keymap
)
443 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
444 (define-key map
"\^m" 'Custom-newline
)
445 (define-key map
" " 'scroll-up-command
)
446 (define-key map
"\177" 'scroll-down-command
)
447 (define-key map
"\C-c\C-c" 'Custom-set
)
448 (define-key map
"\C-x\C-s" 'Custom-save
)
449 (define-key map
"q" 'Custom-buffer-done
)
450 (define-key map
"u" 'Custom-goto-parent
)
451 (define-key map
"n" 'widget-forward
)
452 (define-key map
"p" 'widget-backward
)
454 "Keymap for `Custom-mode'.")
456 (defvar custom-mode-link-map
457 (let ((map (make-keymap)))
458 (set-keymap-parent map custom-mode-map
)
459 (define-key map
[down-mouse-2
] nil
)
460 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
461 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
463 "Local keymap for links in `Custom-mode'.")
465 (defvar custom-field-keymap
466 (let ((map (copy-keymap widget-field-keymap
)))
467 (define-key map
"\C-c\C-c" 'Custom-set
)
468 (define-key map
"\C-x\C-s" 'Custom-save
)
470 "Keymap used inside editable fields in customization buffers.")
472 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
476 (defun custom-split-regexp-maybe (regexp)
477 "If REGEXP is a string, split it to a list at `\\|'.
478 You can get the original back from the result with:
479 (mapconcat 'identity result \"\\|\")
481 IF REGEXP is not a string, return it unchanged."
483 (split-string regexp
"\\\\|")
486 (defun custom-variable-prompt ()
487 "Prompt for a custom variable, defaulting to the variable at point.
488 Return a list suitable for use in `interactive'."
489 (let* ((v (variable-at-point))
490 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
491 (enable-recursive-minibuffers t
)
493 (setq val
(completing-read
494 (if default
(format "Customize variable (default %s): " default
)
495 "Customize variable: ")
496 obarray
'custom-variable-p t nil nil default
))
497 (list (if (equal val
"")
498 (if (symbolp v
) v nil
)
501 (defun custom-menu-filter (menu widget
)
502 "Convert MENU to the form used by `widget-choose'.
503 MENU should be in the same format as `custom-variable-menu'.
504 WIDGET is the widget to apply the filter entries of MENU on."
506 current name action filter
)
508 (setq current
(car menu
)
510 action
(nth 1 current
)
511 filter
(nth 2 current
)
513 (if (or (null filter
) (funcall filter widget
))
514 (push (cons name action
) result
)
520 (defvar custom-prefix-list nil
521 "List of prefixes that should be ignored by `custom-unlispify'.")
523 (defcustom custom-unlispify-menu-entries t
524 "Display menu entries as words instead of symbols if non-nil."
528 (defcustom custom-unlispify-remove-prefixes nil
529 "Non-nil means remove group prefixes from option names in buffer.
530 Discarding prefixes often leads to confusing names for options
531 and faces in Customize buffers, so do not set this to a non-nil
532 value unless you are sure you know what it does."
534 :group
'custom-buffer
537 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
538 "Convert SYMBOL into a menu entry."
539 (cond ((not custom-unlispify-menu-entries
)
540 (symbol-name symbol
))
541 ((get symbol
'custom-tag
)
543 (get symbol
'custom-tag
)
544 (concat (get symbol
'custom-tag
) "...")))
546 (with-current-buffer (get-buffer-create " *Custom-Work*")
548 (princ symbol
(current-buffer))
549 (goto-char (point-min))
550 (if custom-unlispify-remove-prefixes
551 (let ((prefixes custom-prefix-list
)
554 (setq prefix
(car prefixes
))
555 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
558 (delete-region (point-min) (point)))
559 (setq prefixes
(cdr prefixes
))))))
560 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
561 (capitalize-region (point-min) (point-max))
563 (goto-char (point-max))
567 (defcustom custom-unlispify-tag-names t
568 "Display tag names as words instead of symbols if non-nil."
569 :group
'custom-buffer
572 (defun custom-unlispify-tag-name (symbol)
573 "Convert SYMBOL into a menu entry."
574 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
575 (custom-unlispify-menu-entry symbol t
)))
577 (defun custom-prefix-add (symbol prefixes
)
578 "Add SYMBOL to list of ignored PREFIXES."
579 (cons (or (get symbol
'custom-prefix
)
580 (concat (symbol-name symbol
) "-"))
585 (defcustom custom-guess-name-alist
591 ("-function\\'" function
)
592 ("-functions\\'" (repeat function
))
593 ("-list\\'" (repeat sexp
))
594 ("-alist\\'" (alist :key-type sexp
:value-type sexp
)))
595 "Alist of (MATCH TYPE).
597 MATCH should be a regexp matching the name of a symbol, and TYPE should
598 be a widget suitable for editing the value of that symbol. The TYPE
599 of the first entry where MATCH matches the name of the symbol will be
602 This is used for guessing the type of variables not declared with
604 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
605 :group
'custom-buffer
)
607 (defcustom custom-guess-doc-alist
608 '(("\\`\\*?Non-nil " boolean
))
609 "Alist of (MATCH TYPE).
611 MATCH should be a regexp matching a documentation string, and TYPE
612 should be a widget suitable for editing the value of a variable with
613 that documentation string. The TYPE of the first entry where MATCH
614 matches the name of the symbol will be used.
616 This is used for guessing the type of variables not declared with
618 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
619 :group
'custom-buffer
)
621 (defun custom-guess-type (symbol)
622 "Guess a widget suitable for editing the value of SYMBOL.
623 This is done by matching SYMBOL with `custom-guess-name-alist' and
624 if that fails, the doc string with `custom-guess-doc-alist'."
625 (let ((name (symbol-name symbol
))
626 (names custom-guess-name-alist
)
629 (setq current
(car names
)
631 (when (string-match (nth 0 current
) name
)
632 (setq found
(nth 1 current
)
635 (let ((doc (documentation-property symbol
'variable-documentation
))
636 (docs custom-guess-doc-alist
))
639 (setq current
(car docs
)
641 (when (string-match (nth 0 current
) doc
)
642 (setq found
(nth 1 current
)
649 (defcustom custom-browse-sort-alphabetically nil
650 "If non-nil, sort customization group alphabetically in `custom-browse'."
652 :group
'custom-browse
)
654 (defcustom custom-browse-order-groups nil
655 "If non-nil, order group members within each customization group.
656 If `first', order groups before non-groups.
657 If `last', order groups after non-groups."
658 :type
'(choice (const first
)
660 (const :tag
"none" nil
))
661 :group
'custom-browse
)
663 (defcustom custom-browse-only-groups nil
664 "If non-nil, show group members only within each customization group."
666 :group
'custom-browse
)
669 (defcustom custom-buffer-sort-alphabetically t
670 "Whether to sort customization groups alphabetically in Custom buffer."
672 :group
'custom-buffer
675 (defcustom custom-buffer-order-groups
'last
676 "If non-nil, order group members within each customization group.
677 If `first', order groups before non-groups.
678 If `last', order groups after non-groups."
679 :type
'(choice (const first
)
681 (const :tag
"none" nil
))
682 :group
'custom-buffer
)
685 (defcustom custom-menu-sort-alphabetically nil
686 "If non-nil, sort each customization group alphabetically in menus."
690 (defcustom custom-menu-order-groups
'first
691 "If non-nil, order group members within each customization group.
692 If `first', order groups before non-groups.
693 If `last', order groups after non-groups."
694 :type
'(choice (const first
)
696 (const :tag
"none" nil
))
699 (defun custom-sort-items (items sort-alphabetically order-groups
)
700 "Return a sorted copy of ITEMS.
701 ITEMS should be a `custom-group' property.
702 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
703 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
704 groups after non-groups, if nil do not order groups at all."
705 (sort (copy-sequence items
)
707 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
708 (namea (nth 0 a
)) (nameb (nth 0 b
)))
709 (cond ((not order-groups
)
710 ;; Since we don't care about A and B order, maybe sort.
711 (when sort-alphabetically
712 (string-lessp namea nameb
)))
713 ((eq typea
'custom-group
)
714 ;; If B is also a group, maybe sort. Otherwise, order A and B.
715 (if (eq typeb
'custom-group
)
716 (when sort-alphabetically
717 (string-lessp namea nameb
))
718 (eq order-groups
'first
)))
719 ((eq typeb
'custom-group
)
720 ;; Since A cannot be a group, order A and B.
721 (eq order-groups
'last
))
723 ;; Since A and B cannot be groups, sort.
724 (string-lessp namea nameb
)))))))
726 ;;; Custom Mode Commands.
728 ;; This variable is used by `custom-tool-bar-map', or directly by
729 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
731 (defvar custom-commands
732 '((" Apply " Custom-set t
733 "Apply settings (for the current session only)"
736 (" Apply and Save " Custom-save
737 (or custom-file user-init-file
)
738 "Apply settings and save for future sessions."
741 (" Undo Edits " Custom-reset-current t
742 "Restore customization buffer to reflect existing settings."
745 (" Reset Customizations " Custom-reset-saved t
746 "Undo any settings applied only for the current session."
749 (" Erase Customizations " Custom-reset-standard
750 (or custom-file user-init-file
)
751 "Un-customize settings in this and future sessions."
754 (" Help for Customize " Custom-help t
755 "Get help for using Customize."
758 (" Exit " Custom-buffer-done t
"Exit Customize." "exit" "Exit")))
760 (defun Custom-help ()
761 "Read the node on Easy Customization in the Emacs manual."
763 (info "(emacs)Easy Customization"))
765 (defvar custom-reset-menu
766 '(("Undo Edits in Customization Buffer" . Custom-reset-current
)
767 ("Revert This Session's Customizations" . Custom-reset-saved
)
768 ("Erase Customizations" . Custom-reset-standard
))
769 "Alist of actions for the `Reset' button.
770 The key is a string containing the name of the action, the value is a
771 Lisp function taking the widget as an element which will be called
772 when the action is chosen.")
774 (defvar custom-options nil
775 "Customization widgets in the current buffer.")
777 (defun custom-command-apply (fun query
&optional strong-query
)
778 "Call function FUN on all widgets in `custom-options'.
779 If there is more than one widget, ask user for confirmation using
780 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
781 and `yes-or-no-p' otherwise."
782 (if (or (and (= 1 (length custom-options
))
783 (memq (widget-type (car custom-options
))
784 '(custom-variable custom-face
)))
785 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
786 (progn (mapc fun custom-options
) t
)
790 (defun Custom-set (&rest _ignore
)
791 "Set the current value of all edited settings in the buffer."
793 (custom-command-apply
795 (when (eq (widget-get child
:custom-state
) 'modified
)
796 (widget-apply child
:custom-set
)))
797 "Set all values according to this buffer? "))
799 (defun Custom-save (&rest _ignore
)
800 "Set all edited settings, then save all settings that have been set.
801 If a setting was edited and set before, this saves it. If a
802 setting was merely edited before, this sets it then saves it."
804 (when (custom-command-apply
806 (when (memq (widget-get child
:custom-state
)
807 '(modified set changed rogue
))
808 (widget-apply child
:custom-mark-to-save
)))
809 "Save all settings in this buffer? " t
)
810 ;; Save changes to buffer and redraw.
812 (dolist (child custom-options
)
813 (widget-apply child
:custom-state-set-and-redraw
))))
815 (defun custom-reset (_widget &optional event
)
816 "Select item from reset menu."
817 (let* ((completion-ignore-case t
)
818 (answer (widget-choose "Reset settings"
824 (defun Custom-reset-current (&rest _ignore
)
825 "Reset all edited settings in the buffer to show their current values."
827 (custom-command-apply
829 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
830 (widget-apply widget
:custom-reset-current
)))
831 "Reset all settings' buffer text to show current values? "))
833 (defun Custom-reset-saved (&rest _ignore
)
834 "Reset all edited or set settings in the buffer to their saved value.
835 This also shows the saved values in the buffer."
837 (custom-command-apply
839 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
840 (widget-apply widget
:custom-reset-saved
)))
841 "Reset all settings (current values and buffer text) to saved values? "))
843 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
844 ;; and `custom-group-reset-standard'. If these variables are nil, both
845 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
846 ;; save, reset and redraw the handled widget immediately. Otherwise,
847 ;; they add the widget to the corresponding list and leave it to
848 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
849 (defvar custom-reset-standard-variables-list nil
)
850 (defvar custom-reset-standard-faces-list nil
)
852 ;; The next function was excerpted from `custom-variable-reset-standard'
853 ;; and `custom-face-reset-standard' and is used to avoid calling
854 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
855 ;; one) when erasing all customizations.
856 (defun custom-reset-standard-save-and-update ()
857 "Save settings and redraw after erasing customizations."
858 (when (or (and custom-reset-standard-variables-list
859 (not (eq custom-reset-standard-variables-list
'(t))))
860 (and custom-reset-standard-faces-list
861 (not (eq custom-reset-standard-faces-list
'(t)))))
862 ;; Save settings to file.
864 ;; Set state of and redraw variables.
865 (dolist (widget custom-reset-standard-variables-list
)
866 (unless (eq widget t
)
867 (widget-put widget
:custom-state
'unknown
)
868 (custom-redraw widget
)))
869 ;; Set state of and redraw faces.
870 (dolist (widget custom-reset-standard-faces-list
)
871 (unless (eq widget t
)
872 (let* ((symbol (widget-value widget
))
873 (child (car (widget-get widget
:children
)))
874 (comment-widget (widget-get widget
:comment-widget
)))
875 (put symbol
'face-comment nil
)
876 (widget-value-set child
877 (custom-pre-filter-face-spec
878 (list (list t
(custom-face-attributes-get
880 ;; This call manages the comment visibility
881 (widget-value-set comment-widget
"")
882 (custom-face-state-set widget
)
883 (custom-redraw-magic widget
))))))
885 (defun Custom-reset-standard (&rest _ignore
)
886 "Erase all customizations (either current or saved) in current buffer.
887 The immediate result is to restore them to their standard values.
888 This operation eliminates any saved values for the group members,
889 making them as if they had never been customized at all."
891 ;; Bind these temporarily.
892 (let ((custom-reset-standard-variables-list '(t))
893 (custom-reset-standard-faces-list '(t)))
894 (custom-command-apply
896 (and (or (null (widget-get widget
:custom-standard-value
))
897 (widget-apply widget
:custom-standard-value
))
898 (memq (widget-get widget
:custom-state
)
899 '(modified set changed saved rogue
))
900 (widget-apply widget
:custom-mark-to-reset-standard
)))
901 "The settings will revert to their default values, in this
902 and future sessions. Really erase customizations? " t
)
903 (custom-reset-standard-save-and-update)))
905 ;;; The Customize Commands
907 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
908 "Prompt for a variable and a value and return them as a list.
909 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
910 prompt for the value. The %s escape in PROMPT-VAL is replaced with
911 the name of the variable.
913 If the variable has a `variable-interactive' property, that is used as if
914 it were the arg to `interactive' (which see) to interactively read the value.
916 If the variable has a `custom-type' property, it must be a widget and the
917 `:prompt-value' property of that widget will be used for reading the value.
918 If the variable also has a `custom-get' property, that is used for finding
919 the current value of the variable, otherwise `symbol-value' is used.
921 If optional COMMENT argument is non-nil, also prompt for a comment and return
922 it as the third element in the list."
923 (let* ((var (read-variable prompt-var
))
924 (minibuffer-help-form '(describe-variable var
))
926 (let ((prop (get var
'variable-interactive
))
927 (type (get var
'custom-type
))
928 (prompt (format prompt-val var
)))
930 (setq type
(list type
)))
932 ;; Use VAR's `variable-interactive' property
933 ;; as an interactive spec for prompting.
934 (call-interactively `(lambda (arg)
938 (widget-prompt-value type
942 (or (get var
'custom-get
) 'symbol-value
)
946 (eval-minibuffer prompt
))))))
949 (read-string "Comment: " (get var
'variable-comment
)))
953 (defun customize-set-value (variable value
&optional comment
)
954 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
956 If VARIABLE has a `variable-interactive' property, that is used as if
957 it were the arg to `interactive' (which see) to interactively read the value.
959 If VARIABLE has a `custom-type' property, it must be a widget and the
960 `:prompt-value' property of that widget will be used for reading the value.
962 If given a prefix (or a COMMENT argument), also prompt for a comment."
963 (interactive (custom-prompt-variable "Set variable: "
967 (cond ((string= comment
"")
968 (put variable
'variable-comment nil
))
970 (put variable
'variable-comment comment
)))
971 (set variable value
))
974 (defun customize-set-variable (variable value
&optional comment
)
975 "Set the default for VARIABLE to VALUE, and return VALUE.
976 VALUE is a Lisp object.
978 If VARIABLE has a `custom-set' property, that is used for setting
979 VARIABLE, otherwise `set-default' is used.
981 If VARIABLE has a `variable-interactive' property, that is used as if
982 it were the arg to `interactive' (which see) to interactively read the value.
984 If VARIABLE has a `custom-type' property, it must be a widget and the
985 `:prompt-value' property of that widget will be used for reading the value.
987 If given a prefix (or a COMMENT argument), also prompt for a comment."
988 (interactive (custom-prompt-variable "Set variable: "
989 "Set customized value for %s to: "
991 (custom-load-symbol variable
)
992 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
993 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
994 (put variable
'customized-value
(list (custom-quote value
)))
995 (cond ((string= comment
"")
996 (put variable
'variable-comment nil
)
997 (put variable
'customized-variable-comment nil
))
999 (put variable
'variable-comment comment
)
1000 (put variable
'customized-variable-comment comment
)))
1004 (defun customize-save-variable (variable value
&optional comment
)
1005 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1008 If VARIABLE has a `custom-set' property, that is used for setting
1009 VARIABLE, otherwise `set-default' is used.
1011 If VARIABLE has a `variable-interactive' property, that is used as if
1012 it were the arg to `interactive' (which see) to interactively read the value.
1014 If VARIABLE has a `custom-type' property, it must be a widget and the
1015 `:prompt-value' property of that widget will be used for reading the value.
1017 If given a prefix (or a COMMENT argument), also prompt for a comment."
1018 (interactive (custom-prompt-variable "Set and save variable: "
1019 "Set and save value for %s as: "
1020 current-prefix-arg
))
1021 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1022 (put variable
'saved-value
(list (custom-quote value
)))
1023 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1024 (cond ((string= comment
"")
1025 (put variable
'variable-comment nil
)
1026 (put variable
'saved-variable-comment nil
))
1028 (put variable
'variable-comment comment
)
1029 (put variable
'saved-variable-comment comment
)))
1030 (put variable
'customized-value nil
)
1031 (put variable
'customized-variable-comment nil
)
1034 (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
1036 (set variable value
))
1039 ;; Some parts of Emacs might prompt the user to save customizations,
1040 ;; during startup before customizations are loaded. This function
1041 ;; handles this corner case by avoiding calling `custom-save-variable'
1042 ;; too early, which could wipe out existing customizations.
1045 (defun customize-push-and-save (list-var elts
)
1046 "Add ELTS to LIST-VAR and save for future sessions, safely.
1047 ELTS should be a list. This function adds each entry to the
1048 value of LIST-VAR using `add-to-list'.
1050 If Emacs is initialized, call `customize-save-variable' to save
1051 the resulting list value now. Otherwise, add an entry to
1052 `after-init-hook' to save it after initialization."
1053 (dolist (entry elts
)
1054 (add-to-list list-var entry
))
1056 (let ((coding-system-for-read nil
))
1057 (customize-save-variable list-var
(eval list-var
)))
1058 (add-hook 'after-init-hook
1060 (customize-push-and-save ',list-var
',elts
)))))
1064 "Select a customization buffer which you can use to set user options.
1065 User options are structured into \"groups\".
1066 Initially the top-level group `Emacs' and its immediate subgroups
1067 are shown; the contents of those subgroups are initially hidden."
1069 (customize-group 'emacs
))
1072 (defun customize-mode (mode)
1073 "Customize options related to the current major mode.
1074 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1075 then prompt for the MODE to customize."
1078 (let ((completion-regexp-list '("-mode\\'"))
1079 (group (custom-group-of-mode major-mode
)))
1080 (if (and group
(not current-prefix-arg
))
1083 (completing-read (if group
1084 (format "Major mode (default %s): " major-mode
)
1087 'custom-group-of-mode
1088 t nil nil
(if group
(symbol-name major-mode
))))))))
1089 (customize-group (custom-group-of-mode mode
)))
1091 (defun customize-read-group ()
1092 (let ((completion-ignore-case t
))
1093 (completing-read "Customize group (default emacs): "
1096 (or (and (get symbol
'custom-loads
)
1097 (not (get symbol
'custom-autoload
)))
1098 (get symbol
'custom-group
)))
1102 (defun customize-group (&optional group other-window
)
1103 "Customize GROUP, which must be a customization group.
1104 If OTHER-WINDOW is non-nil, display in another window."
1105 (interactive (list (customize-read-group)))
1106 (when (stringp group
)
1107 (if (string-equal "" group
)
1109 (setq group
(intern group
))))
1110 (let ((name (format "*Customize Group: %s*"
1111 (custom-unlispify-tag-name group
))))
1113 ((null (get-buffer name
))
1114 (funcall (if other-window
1115 'custom-buffer-create-other-window
1116 'custom-buffer-create
)
1117 (list (list group
'custom-group
))
1119 (concat " for group "
1120 (custom-unlispify-tag-name group
))))
1122 (switch-to-buffer-other-window name
))
1124 (pop-to-buffer-same-window name
)))))
1127 (defun customize-group-other-window (&optional group
)
1128 "Customize GROUP, which must be a customization group, in another window."
1129 (interactive (list (customize-read-group)))
1130 (customize-group group t
))
1133 (defalias 'customize-variable
'customize-option
)
1136 (defun customize-option (symbol)
1137 "Customize SYMBOL, which must be a user option."
1138 (interactive (custom-variable-prompt))
1140 (error "No variable specified"))
1141 (let ((basevar (indirect-variable symbol
)))
1142 (custom-buffer-create (list (list basevar
'custom-variable
))
1143 (format "*Customize Option: %s*"
1144 (custom-unlispify-tag-name basevar
)))
1145 (unless (eq symbol basevar
)
1146 (message "`%s' is an alias for `%s'" symbol basevar
))))
1149 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1152 (defun customize-option-other-window (symbol)
1153 "Customize SYMBOL, which must be a user option.
1154 Show the buffer in another window, but don't select it."
1155 (interactive (custom-variable-prompt))
1157 (error "No variable specified"))
1158 (let ((basevar (indirect-variable symbol
)))
1159 (custom-buffer-create-other-window
1160 (list (list basevar
'custom-variable
))
1161 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1162 (unless (eq symbol basevar
)
1163 (message "`%s' is an alias for `%s'" symbol basevar
))))
1165 (defvar customize-changed-options-previous-release
"24.1"
1166 "Version for `customize-changed-options' to refer back to by default.")
1168 ;; Packages will update this variable, so make it available.
1170 (defvar customize-package-emacs-version-alist nil
1171 "Alist mapping versions of a package to Emacs versions.
1172 We use this for packages that have their own names, but are released
1173 as part of Emacs itself.
1175 Each elements looks like this:
1177 (PACKAGE (PVERSION . EVERSION)...)
1179 Here PACKAGE is the name of a package, as a symbol. After
1180 PACKAGE come one or more elements, each associating a
1181 package version PVERSION with the first Emacs version
1182 EVERSION in which it (or a subsequent version of PACKAGE)
1183 was first released. Both PVERSION and EVERSION are strings.
1184 PVERSION should be a string that this package used in
1185 the :package-version keyword for `defcustom', `defgroup',
1188 For example, the MH-E package updates this alist as follows:
1190 (add-to-list 'customize-package-emacs-version-alist
1191 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1192 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1193 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1194 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1196 The value of PACKAGE needs to be unique and it needs to match the
1197 PACKAGE value appearing in the :package-version keyword. Since
1198 the user might see the value in a error message, a good choice is
1199 the official name of the package, such as MH-E or Gnus.")
1202 (defalias 'customize-changed
'customize-changed-options
)
1205 (defun customize-changed-options (&optional since-version
)
1206 "Customize all settings whose meanings have changed in Emacs itself.
1207 This includes new user options and faces, and new customization
1208 groups, as well as older options and faces whose meanings or
1209 default values have changed since the previous major Emacs
1212 With argument SINCE-VERSION (a string), customize all settings
1213 that were added or redefined since that version."
1217 (read-from-minibuffer
1218 (format "Customize options changed, since version (default %s): "
1219 customize-changed-options-previous-release
))))
1220 (if (equal since-version
"")
1221 (setq since-version nil
)
1222 (unless (condition-case nil
1223 (numberp (read since-version
))
1225 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1226 (unless since-version
1227 (setq since-version customize-changed-options-previous-release
))
1229 ;; Load the information for versions since since-version. We use
1230 ;; custom-load-symbol for this.
1231 (put 'custom-versions-load-alist
'custom-loads nil
)
1232 (dolist (elt custom-versions-load-alist
)
1233 (if (customize-version-lessp since-version
(car elt
))
1234 (dolist (load (cdr elt
))
1235 (custom-add-load 'custom-versions-load-alist load
))))
1236 (custom-load-symbol 'custom-versions-load-alist
)
1237 (put 'custom-versions-load-alist
'custom-loads nil
)
1242 (let* ((package-version (get symbol
'custom-package-version
))
1244 (or (and package-version
1245 (customize-package-emacs-version symbol
1247 (get symbol
'custom-version
))))
1249 (when (customize-version-lessp since-version version
)
1250 (if (or (get symbol
'custom-group
)
1251 (get symbol
'group-documentation
))
1252 (push (list symbol
'custom-group
) found
))
1253 (if (custom-variable-p symbol
)
1254 (push (list symbol
'custom-variable
) found
))
1255 (if (custom-facep symbol
)
1256 (push (list symbol
'custom-face
) found
)))))))
1258 (custom-buffer-create (custom-sort-items found t
'first
)
1259 "*Customize Changed Options*")
1260 (user-error "No user option defaults have been changed since Emacs %s"
1263 (defun customize-package-emacs-version (symbol package-version
)
1264 "Return the Emacs version in which SYMBOL's meaning last changed.
1265 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1266 `customize-package-emacs-version-alist' to find the version of
1267 Emacs that is associated with version VERSION of PACKAGE."
1268 (let (package-versions emacs-version
)
1269 ;; Use message instead of error since we want user to be able to
1270 ;; see the rest of the symbols even if a package author has
1271 ;; botched things up.
1272 (cond ((not (listp package-version
))
1273 (message "Invalid package-version value for %s" symbol
))
1274 ((setq package-versions
(assq (car package-version
)
1275 customize-package-emacs-version-alist
))
1277 (cdr (assoc (cdr package-version
) package-versions
)))
1278 (unless emacs-version
1279 (message "%s version %s not found in %s" symbol
1280 (cdr package-version
)
1281 "customize-package-emacs-version-alist")))
1283 (message "Package %s version %s lists no corresponding Emacs version"
1284 (car package-version
)
1285 (cdr package-version
))))
1288 (defun customize-version-lessp (version1 version2
)
1289 ;; Why are the versions strings, and given that they are, why aren't
1290 ;; they converted to numbers and compared as such here? -- fx
1292 ;; In case someone made a mistake and left out the quotes
1293 ;; in the :version value.
1294 (if (numberp version2
)
1295 (setq version2
(prin1-to-string version2
)))
1296 (let (major1 major2 minor1 minor2
)
1297 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1298 (setq major1
(read (or (match-string 1 version1
)
1300 (setq minor1
(read (or (match-string 3 version1
)
1302 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1303 (setq major2
(read (or (match-string 1 version2
)
1305 (setq minor2
(read (or (match-string 3 version2
)
1307 (or (< major1 major2
)
1308 (and (= major1 major2
)
1309 (< minor1 minor2
)))))
1312 (defun customize-face (&optional face other-window
)
1313 "Customize FACE, which should be a face name or nil.
1314 If FACE is nil, customize all faces. If FACE is actually a
1315 face-alias, customize the face it is aliased to.
1317 If OTHER-WINDOW is non-nil, display in another window.
1319 Interactively, when point is on text which has a face specified,
1320 suggest to customize that face, if it's customizable."
1321 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1322 (if (member face
'(nil ""))
1323 (setq face
(face-list)))
1324 (if (and (listp face
) (null (cdr face
)))
1325 (setq face
(car face
)))
1326 (let ((display-fun (if other-window
1327 'custom-buffer-create-other-window
1328 'custom-buffer-create
)))
1330 (funcall display-fun
1332 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1334 "*Customize Faces*")
1335 ;; If FACE is actually an alias, customize the face it is aliased to.
1336 (if (get face
'face-alias
)
1337 (setq face
(get face
'face-alias
)))
1338 (unless (facep face
)
1339 (error "Invalid face %S" face
))
1340 (funcall display-fun
1341 (list (list face
'custom-face
))
1342 (format "*Customize Face: %s*"
1343 (custom-unlispify-tag-name face
))))))
1346 (defun customize-face-other-window (&optional face
)
1347 "Show customization buffer for face FACE in other window.
1348 If FACE is actually a face-alias, customize the face it is aliased to.
1350 Interactively, when point is on text which has a face specified,
1351 suggest to customize that face, if it's customizable."
1352 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1353 (customize-face face t
))
1355 (defalias 'customize-customized
'customize-unsaved
)
1358 (defun customize-unsaved ()
1359 "Customize all options and faces set in this session but not saved."
1362 (mapatoms (lambda (symbol)
1363 (and (or (get symbol
'customized-face
)
1364 (get symbol
'customized-face-comment
))
1365 (custom-facep symbol
)
1366 (push (list symbol
'custom-face
) found
))
1367 (and (or (get symbol
'customized-value
)
1368 (get symbol
'customized-variable-comment
))
1370 (push (list symbol
'custom-variable
) found
))))
1372 (error "No user options are set but unsaved")
1373 (custom-buffer-create (custom-sort-items found t nil
)
1374 "*Customize Unsaved*"))))
1377 (defun customize-rogue ()
1378 "Customize all user variables modified outside customize."
1381 (mapatoms (lambda (symbol)
1382 (let ((cval (or (get symbol
'customized-value
)
1383 (get symbol
'saved-value
)
1384 (get symbol
'standard-value
))))
1385 (when (and cval
;Declared with defcustom.
1386 (default-boundp symbol
) ;Has a value.
1387 (not (equal (eval (car cval
))
1388 ;; Which does not match customize.
1389 (default-value symbol
))))
1390 (push (list symbol
'custom-variable
) found
)))))
1392 (user-error "No rogue user options")
1393 (custom-buffer-create (custom-sort-items found t nil
)
1394 "*Customize Rogue*"))))
1396 (defun customize-saved ()
1397 "Customize all saved options and faces."
1400 (mapatoms (lambda (symbol)
1401 (and (or (get symbol
'saved-face
)
1402 (get symbol
'saved-face-comment
))
1403 (custom-facep symbol
)
1404 (push (list symbol
'custom-face
) found
))
1405 (and (or (get symbol
'saved-value
)
1406 (get symbol
'saved-variable-comment
))
1408 (push (list symbol
'custom-variable
) found
))))
1410 (user-error "No saved user options")
1411 (custom-buffer-create (custom-sort-items found t nil
)
1412 "*Customize Saved*"))))
1414 (declare-function apropos-parse-pattern
"apropos" (pattern))
1417 (defun customize-apropos (pattern &optional type
)
1418 "Customize loaded options, faces and groups matching PATTERN.
1419 PATTERN can be a word, a list of words (separated by spaces),
1420 or a regexp (using some regexp special characters). If it is a word,
1421 search for matches for that word as a substring. If it is a list of words,
1422 search for matches for any two (or more) of those words.
1424 If TYPE is `options', include only options.
1425 If TYPE is `faces', include only faces.
1426 If TYPE is `groups', include only groups."
1427 (interactive (list (apropos-read-pattern "symbol") nil
))
1429 (unless (memq type
'(nil options faces groups
))
1430 (error "Invalid setting type %s" (symbol-name type
)))
1431 (apropos-parse-pattern pattern
)
1435 (when (string-match apropos-regexp
(symbol-name symbol
))
1436 ,(if (memq type
'(nil groups
))
1437 '(if (get symbol
'custom-group
)
1438 (push (list symbol
'custom-group
) found
)))
1439 ,(if (memq type
'(nil faces
))
1440 '(if (custom-facep symbol
)
1441 (push (list symbol
'custom-face
) found
)))
1442 ,(if (memq type
'(nil options
))
1443 `(if (and (boundp symbol
)
1444 (eq (indirect-variable symbol
) symbol
)
1445 (or (get symbol
'saved-value
)
1446 (custom-variable-p symbol
)))
1447 (push (list symbol
'custom-variable
) found
))))))
1449 (error "No customizable %s matching %s" (symbol-name type
) pattern
))
1450 (custom-buffer-create
1451 (custom-sort-items found t custom-buffer-order-groups
)
1452 "*Customize Apropos*")))
1455 (defun customize-apropos-options (regexp &optional ignored
)
1456 "Customize all loaded customizable options matching REGEXP."
1457 (interactive (list (apropos-read-pattern "options")))
1458 (customize-apropos regexp
'options
))
1461 (defun customize-apropos-faces (regexp)
1462 "Customize all loaded faces matching REGEXP."
1463 (interactive (list (apropos-read-pattern "faces")))
1464 (customize-apropos regexp
'faces
))
1467 (defun customize-apropos-groups (regexp)
1468 "Customize all loaded groups matching REGEXP."
1469 (interactive (list (apropos-read-pattern "groups")))
1470 (customize-apropos regexp
'groups
))
1474 (defcustom custom-buffer-style
'links
1475 "Control the presentation style for customization buffers.
1476 The value should be a symbol, one of:
1478 brackets: groups nest within each other with big horizontal brackets.
1479 links: groups have links to subgroups."
1480 :type
'(radio (const brackets
)
1482 :group
'custom-buffer
)
1484 (defcustom custom-buffer-done-kill nil
1485 "Non-nil means exiting a Custom buffer should kill it."
1488 :group
'custom-buffer
)
1490 (defcustom custom-buffer-indent
3
1491 "Number of spaces to indent nested groups."
1493 :group
'custom-buffer
)
1495 (defun custom-get-fresh-buffer (name)
1496 "Get a fresh new buffer with name NAME.
1497 If the buffer already exist, clean it up to be like new.
1498 Beware: it's not quite like new. Good enough for custom, but maybe
1500 ;; To be more complete, we should also kill all permanent-local variables,
1501 ;; but it's not needed for custom.
1502 (let ((buf (get-buffer name
)))
1503 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1504 ;; This will check if the file is not saved.
1508 (get-buffer-create name
)
1509 (with-current-buffer buf
1510 (kill-all-local-variables)
1511 (run-hooks 'kill-buffer-hook
)
1512 ;; Delete overlays before erasing the buffer so the overlay hooks
1513 ;; don't get run spuriously when we erase the buffer.
1514 (let ((ols (overlay-lists)))
1515 (dolist (ol (nconc (car ols
) (cdr ols
)))
1516 (delete-overlay ol
)))
1521 (defun custom-buffer-create (options &optional name description
)
1522 "Create a buffer containing OPTIONS.
1523 Optional NAME is the name of the buffer.
1524 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1525 SYMBOL is a customization option, and WIDGET is a widget for editing
1527 (pop-to-buffer-same-window (custom-get-fresh-buffer (or name
"*Customization*")))
1528 (custom-buffer-create-internal options description
))
1531 (defun custom-buffer-create-other-window (options &optional name description
)
1532 "Create a buffer containing OPTIONS, and display it in another window.
1533 The result includes selecting that window.
1534 Optional NAME is the name of the buffer.
1535 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1536 SYMBOL is a customization option, and WIDGET is a widget for editing
1538 (unless name
(setq name
"*Customization*"))
1539 (switch-to-buffer-other-window (custom-get-fresh-buffer name
))
1540 (custom-buffer-create-internal options description
))
1542 (defcustom custom-reset-button-menu t
1543 "If non-nil, only show a single reset button in customize buffers.
1544 This button will have a menu with all three reset operations."
1546 :group
'custom-buffer
1549 (defcustom custom-buffer-verbose-help t
1550 "If non-nil, include explanatory text in the customization buffer."
1552 :group
'custom-buffer
)
1554 (defun Custom-buffer-done (&rest _ignore
)
1555 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1557 (quit-window custom-buffer-done-kill
))
1559 (defvar custom-button nil
1560 "Face used for buttons in customization buffers.")
1562 (defvar custom-button-mouse nil
1563 "Mouse face used for buttons in customization buffers.")
1565 (defvar custom-button-pressed nil
1566 "Face used for pressed buttons in customization buffers.")
1568 (defcustom custom-search-field t
1569 "If non-nil, show a search field in Custom buffers."
1572 :group
'custom-buffer
)
1574 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1575 '(("unspecified" . unspecified
))))
1576 "If non-nil, indicate active buttons in a `raised-button' style.
1577 Otherwise use brackets."
1580 :group
'custom-buffer
1581 :set
(lambda (variable value
)
1582 (custom-set-default variable value
)
1584 (if value
'custom-button
'custom-button-unraised
))
1585 (setq custom-button-mouse
1586 (if value
'custom-button-mouse
'highlight
))
1587 (setq custom-button-pressed
1589 'custom-button-pressed
1590 'custom-button-pressed-unraised
))))
1592 (defun custom-buffer-create-internal (options &optional _description
)
1594 (let ((init-file (or custom-file user-init-file
)))
1595 ;; Insert verbose help at the top of the custom buffer.
1596 (when custom-buffer-verbose-help
1598 (widget-insert "Custom settings cannot be saved; maybe you started Emacs with `-q'.\n"))
1599 (widget-insert "For help using this buffer, see ")
1600 (widget-create 'custom-manual
1601 :tag
"Easy Customization"
1602 "(emacs)Easy Customization")
1603 (widget-insert " in the ")
1604 (widget-create 'custom-manual
1606 :help-echo
"Read the Emacs manual."
1608 (widget-insert "."))
1609 (widget-insert "\n")
1611 ;; Insert the search field.
1612 (when custom-search-field
1613 (widget-insert "\n")
1614 (let* ((echo "Search for custom items.
1615 You can enter one or more words separated by spaces,
1616 or a regular expression.")
1620 :size
40 :help-echo echo
1621 :action
`(lambda (widget &optional event
)
1622 (customize-apropos (split-string (widget-value widget
)))))))
1624 (widget-create-child-and-convert
1625 search-widget
'push-button
1627 :help-echo echo
:action
1628 (lambda (widget &optional _event
)
1629 (customize-apropos (split-string (widget-value (widget-get widget
:parent
))))))
1630 (widget-insert "\n")))
1632 ;; The custom command buttons are also in the toolbar, so for a
1633 ;; time they were not inserted in the buffer if the toolbar was in use.
1634 ;; But it can be a little confusing for the buffer layout to
1635 ;; change according to whether or nor the toolbar is on, not to
1636 ;; mention that a custom buffer can in theory be created in a
1637 ;; frame with a toolbar, then later viewed in one without.
1638 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1639 (if custom-buffer-verbose-help
1641 Operate on all settings in this buffer:\n"))
1642 (let ((button (lambda (tag action active help _icon _label
)
1645 (widget-create 'push-button
:tag tag
1646 :help-echo help
:action action
))))
1647 (commands custom-commands
))
1648 (if custom-reset-button-menu
1650 (widget-create 'push-button
1652 :help-echo
"Show a menu with reset operations."
1653 :mouse-down-action
'ignore
1654 :action
'custom-reset
)
1655 (apply button
(pop commands
)) ; Apply
1656 (apply button
(pop commands
))) ; Apply and Save
1657 (apply button
(pop commands
)) ; Apply
1658 (apply button
(pop commands
)) ; Apply and Save
1659 (widget-insert "\n")
1660 (apply button
(pop commands
)) ; Undo
1661 (apply button
(pop commands
)) ; Reset
1662 (apply button
(pop commands
)) ; Erase
1664 (pop commands
) ; Help (omitted)
1665 (apply button
(pop commands
)))) ; Exit
1666 (widget-insert "\n\n"))
1668 ;; Now populate the custom buffer.
1669 (message "Creating customization items...")
1670 (buffer-disable-undo)
1671 (setq custom-options
1672 (if (= (length options
) 1)
1673 (mapcar (lambda (entry)
1674 (widget-create (nth 1 entry
)
1675 :documentation-shown t
1676 :custom-state
'unknown
1677 :tag
(custom-unlispify-tag-name
1679 :value
(nth 0 entry
)))
1682 (length (length options
)))
1683 (mapcar (lambda (entry)
1685 (message "Creating customization items ...%2d%%"
1686 (/ (* 100.0 count
) length
))
1687 (widget-create (nth 1 entry
)
1688 :tag
(custom-unlispify-tag-name
1690 :value
(nth 0 entry
))
1691 (setq count
(1+ count
))
1692 (unless (eq (preceding-char) ?
\n)
1693 (widget-insert "\n"))
1694 (widget-insert "\n")))
1696 (unless (eq (preceding-char) ?
\n)
1697 (widget-insert "\n"))
1698 (message "Creating customization items ...done")
1699 (message "Resetting customization items...")
1700 (unless (eq custom-buffer-style
'tree
)
1701 (mapc 'custom-magic-reset custom-options
))
1702 (message "Resetting customization items...done")
1703 (message "Creating customization setup...")
1705 (buffer-enable-undo)
1706 (goto-char (point-min))
1707 (message "Creating customization setup...done"))
1709 ;;; The Tree Browser.
1712 (defun customize-browse (&optional group
)
1713 "Create a tree browser for the customize hierarchy."
1716 (setq group
'emacs
))
1717 (let ((name "*Customize Browser*"))
1718 (pop-to-buffer-same-window (custom-get-fresh-buffer name
)))
1720 (widget-insert (format "\
1721 %s buttons; type RET or click mouse-1
1722 on a button to invoke its action.
1723 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1724 (if custom-raised-buttons
1725 "`Raised' text indicates"
1726 "Square brackets indicate")))
1729 (if custom-browse-only-groups
1731 Invoke the [Group] button below to edit that item in another window.\n\n")
1732 (widget-insert "Invoke the ")
1733 (widget-create 'item
1736 :tag-glyph
"folder")
1737 (widget-insert ", ")
1738 (widget-create 'item
1742 (widget-insert ", and ")
1743 (widget-create 'item
1746 :tag-glyph
"option")
1747 (widget-insert " buttons below to edit that
1748 item in another window.\n\n"))
1749 (let ((custom-buffer-style 'tree
))
1750 (widget-create 'custom-group
1752 :custom-state
'unknown
1753 :tag
(custom-unlispify-tag-name group
)
1756 (goto-char (point-min)))
1758 (define-widget 'custom-browse-visibility
'item
1759 "Control visibility of items in the customize tree browser."
1761 :action
'custom-browse-visibility-action
)
1763 (defun custom-browse-visibility-action (widget &rest _ignore
)
1764 (let ((custom-buffer-style 'tree
))
1765 (custom-toggle-parent widget
)))
1767 (define-widget 'custom-browse-group-tag
'custom-group-link
1768 "Show parent in other window when activated."
1771 :action
'custom-browse-group-tag-action
)
1773 (defun custom-browse-group-tag-action (widget &rest _ignore
)
1774 (let ((parent (widget-get widget
:parent
)))
1775 (customize-group-other-window (widget-value parent
))))
1777 (define-widget 'custom-browse-variable-tag
'custom-group-link
1778 "Show parent in other window when activated."
1781 :action
'custom-browse-variable-tag-action
)
1783 (defun custom-browse-variable-tag-action (widget &rest _ignore
)
1784 (let ((parent (widget-get widget
:parent
)))
1785 (customize-variable-other-window (widget-value parent
))))
1787 (define-widget 'custom-browse-face-tag
'custom-group-link
1788 "Show parent in other window when activated."
1791 :action
'custom-browse-face-tag-action
)
1793 (defun custom-browse-face-tag-action (widget &rest _ignore
)
1794 (let ((parent (widget-get widget
:parent
)))
1795 (customize-face-other-window (widget-value parent
))))
1797 (defconst custom-browse-alist
'((" " "space")
1803 (defun custom-browse-insert-prefix (prefix)
1804 "Insert PREFIX. On XEmacs convert it to line graphics."
1805 ;; Fixme: do graphics.
1806 (if nil
; (featurep 'xemacs)
1809 (while (not (string-equal prefix
""))
1810 (let ((entry (substring prefix
0 3)))
1811 (setq prefix
(substring prefix
3))
1812 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1813 (name (nth 1 (assoc entry custom-browse-alist
))))
1814 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1815 (overlay-put overlay
'start-open t
)
1816 (overlay-put overlay
'end-open t
)))))
1819 ;;; Modification of Basic Widgets.
1821 ;; We add extra properties to the basic widgets needed here. This is
1822 ;; fine, as long as we are careful to stay within our own namespace.
1824 ;; We want simple widgets to be displayed by default, but complex
1825 ;; widgets to be hidden.
1827 ;; This widget type is obsolete as of Emacs 24.1.
1828 (widget-put (get 'item
'widget-type
) :custom-show t
)
1829 (widget-put (get 'editable-field
'widget-type
)
1830 :custom-show
(lambda (_widget value
)
1831 (let ((pp (pp-to-string value
)))
1832 (cond ((string-match "\n" pp
)
1837 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1839 ;;; The `custom-manual' Widget.
1841 (define-widget 'custom-manual
'info-link
1842 "Link to the manual entry for this customization option."
1843 :help-echo
"Read the manual entry for this option."
1844 :keymap custom-mode-link-map
1845 :follow-link
'mouse-face
1846 :button-face
'custom-link
1847 :mouse-face
'highlight
1848 :pressed-face
'highlight
1851 ;;; The `custom-magic' Widget.
1853 (defgroup custom-magic-faces nil
1854 "Faces used by the magic button."
1855 :group
'custom-faces
1856 :group
'custom-buffer
)
1858 (defface custom-invalid
'((((class color
))
1859 :foreground
"yellow1" :background
"red1")
1860 (t :weight bold
:slant italic
:underline t
))
1861 "Face used when the customize item is invalid."
1862 :group
'custom-magic-faces
)
1864 (defface custom-rogue
'((((class color
))
1865 :foreground
"pink" :background
"black")
1867 "Face used when the customize item is not defined for customization."
1868 :group
'custom-magic-faces
)
1870 (defface custom-modified
'((((min-colors 88) (class color
))
1871 :foreground
"white" :background
"blue1")
1873 :foreground
"white" :background
"blue")
1875 "Face used when the customize item has been modified."
1876 :group
'custom-magic-faces
)
1878 (defface custom-set
'((((min-colors 88) (class color
))
1879 :foreground
"blue1" :background
"white")
1881 :foreground
"blue" :background
"white")
1883 "Face used when the customize item has been set."
1884 :group
'custom-magic-faces
)
1886 (defface custom-changed
'((((min-colors 88) (class color
))
1887 :foreground
"white" :background
"blue1")
1889 :foreground
"white" :background
"blue")
1891 "Face used when the customize item has been changed."
1892 :group
'custom-magic-faces
)
1894 (defface custom-themed
'((((min-colors 88) (class color
))
1895 :foreground
"white" :background
"blue1")
1897 :foreground
"white" :background
"blue")
1899 "Face used when the customize item has been set by a theme."
1900 :group
'custom-magic-faces
)
1902 (defface custom-saved
'((t :underline t
))
1903 "Face used when the customize item has been saved."
1904 :group
'custom-magic-faces
)
1906 (defconst custom-magic-alist
1907 '((nil "#" underline
"\
1908 UNINITIALIZED, you should not see this.")
1909 (unknown "?" italic
"\
1910 UNKNOWN, you should not see this.")
1911 (hidden "-" default
"\
1912 HIDDEN, invoke \"Show\" in the previous line to show." "\
1913 group now hidden, invoke \"Show\", above, to show contents.")
1914 (invalid "x" custom-invalid
"\
1915 INVALID, the displayed value cannot be set.")
1916 (modified "*" custom-modified
"\
1917 EDITED, shown value does not take effect until you set or save it." "\
1918 something in this group has been edited but not set.")
1919 (set "+" custom-set
"\
1920 SET for current session only." "\
1921 something in this group has been set but not saved.")
1922 (changed ":" custom-changed
"\
1923 CHANGED outside Customize." "\
1924 something in this group has been changed outside customize.")
1925 (saved "!" custom-saved
"\
1927 something in this group has been set and saved.")
1928 (themed "o" custom-themed
"\
1930 visible group members are all at standard values.")
1931 (rogue "@" custom-rogue
"\
1932 NO CUSTOMIZATION DATA; not intended to be customized." "\
1933 something in this group is not prepared for customization.")
1934 (standard " " nil
"\
1936 visible group members are all at standard values."))
1937 "Alist of customize option states.
1938 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1940 STATE is one of the following symbols:
1943 For internal use, should never occur.
1945 For internal use, should never occur.
1947 This item is not being displayed.
1949 This item is modified, but has an invalid form.
1951 This item is modified, and has a valid form.
1953 This item has been set but not saved.
1955 The current value of this item has been changed outside Customize.
1957 This item is marked for saving.
1959 This item has no customization information.
1961 This item is unchanged from the standard setting.
1963 MAGIC is a string used to present that state.
1965 FACE is a face used to present the state.
1967 ITEM-DESC is a string describing the state for options.
1969 GROUP-DESC is a string describing the state for groups. If this is
1970 left out, ITEM-DESC will be used.
1972 The string %c in either description will be replaced with the
1973 category of the item. These are `group'. `option', and `face'.
1975 The list should be sorted most significant first.")
1977 (defcustom custom-magic-show
'long
1978 "If non-nil, show textual description of the state.
1979 If `long', show a full-line description, not just one word."
1980 :type
'(choice (const :tag
"no" nil
)
1982 (other :tag
"short" short
))
1983 :group
'custom-buffer
)
1985 (defcustom custom-magic-show-hidden
'(option face
)
1986 "Control whether the State button is shown for hidden items.
1987 The value should be a list with the custom categories where the State
1988 button should be visible. Possible categories are `group', `option',
1990 :type
'(set (const group
) (const option
) (const face
))
1991 :group
'custom-buffer
)
1993 (defcustom custom-magic-show-button nil
1994 "Show a \"magic\" button indicating the state of each customization option."
1996 :group
'custom-buffer
)
1998 (define-widget 'custom-magic
'default
1999 "Show and manipulate state for a customization option."
2001 :action
'widget-parent-action
2004 :value-create
'custom-magic-value-create
2005 :value-delete
'widget-children-value-delete
)
2007 (defun widget-magic-mouse-down-action (widget &optional _event
)
2008 ;; Non-nil unless hidden.
2009 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
2013 (defun custom-magic-value-create (widget)
2014 "Create compact status report for WIDGET."
2015 (let* ((parent (widget-get widget
:parent
))
2016 (state (widget-get parent
:custom-state
))
2017 (hidden (eq state
'hidden
))
2018 (entry (assq state custom-magic-alist
))
2019 (magic (nth 1 entry
))
2020 (face (nth 2 entry
))
2021 (category (widget-get parent
:custom-category
))
2022 (text (or (and (eq category
'group
)
2025 (form (widget-get parent
:custom-form
))
2027 (unless (eq state
'hidden
)
2028 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2029 (setq text
(concat (match-string 1 text
)
2030 (symbol-name category
)
2031 (match-string 2 text
))))
2032 (when (and custom-magic-show
2034 (memq category custom-magic-show-hidden
)))
2036 (when (and (eq category
'group
)
2037 (not (and (eq custom-buffer-style
'links
)
2038 (> (widget-get parent
:custom-level
) 1))))
2039 (insert-char ?\
(* custom-buffer-indent
2040 (widget-get parent
:custom-level
))))
2041 (push (widget-create-child-and-convert
2043 :help-echo
"Change the state of this item."
2044 :format
(if hidden
"%t" "%[%t%]")
2045 :button-prefix
'widget-push-button-prefix
2046 :button-suffix
'widget-push-button-suffix
2047 :mouse-down-action
'widget-magic-mouse-down-action
2051 (let ((start (point)))
2052 (if (eq custom-magic-show
'long
)
2054 (insert (symbol-name state
)))
2055 (cond ((eq form
'lisp
)
2057 ((eq form
'mismatch
)
2058 (insert " (mismatch)")))
2059 (put-text-property start
(point) 'face
'custom-state
))
2061 (when (and (eq category
'group
)
2062 (not (and (eq custom-buffer-style
'links
)
2063 (> (widget-get parent
:custom-level
) 1))))
2064 (insert-char ?\
(* custom-buffer-indent
2065 (widget-get parent
:custom-level
))))
2066 (when custom-magic-show-button
2067 (when custom-magic-show
2068 (let ((indent (widget-get parent
:indent
)))
2070 (insert-char ? indent
))))
2071 (push (widget-create-child-and-convert
2073 :mouse-down-action
'widget-magic-mouse-down-action
2077 :help-echo
"Change the state."
2078 :format
(if hidden
"%t" "%[%t%]")
2079 :tag
(if (memq form
'(lisp mismatch
))
2080 (concat "(" magic
")")
2081 (concat "[" magic
"]")))
2084 (widget-put widget
:children children
))))
2086 (defun custom-magic-reset (widget)
2087 "Redraw the :custom-magic property of WIDGET."
2088 (let ((magic (widget-get widget
:custom-magic
)))
2090 (widget-value-set magic
(widget-value magic
)))))
2092 ;;; The `custom' Widget.
2094 (defface custom-button
2095 '((((type x w32 ns
) (class color
)) ; Like default mode line
2096 :box
(:line-width
2 :style released-button
)
2097 :background
"lightgrey" :foreground
"black"))
2098 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2100 :group
'custom-faces
)
2102 (defface custom-button-mouse
2103 '((((type x w32 ns
) (class color
))
2104 :box
(:line-width
2 :style released-button
)
2105 :background
"grey90" :foreground
"black")
2107 ;; This is for text terminals that support mouse, like GPM mouse
2108 ;; or the MS-DOS terminal: inverse-video makes the button stand
2109 ;; out on mouse-over.
2111 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2113 :group
'custom-faces
)
2115 (defface custom-button-unraised
2116 '((t :inherit underline
))
2117 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2119 :group
'custom-faces
)
2122 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2124 (setq custom-button-mouse
2125 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2127 (defface custom-button-pressed
2128 '((((type x w32 ns
) (class color
))
2129 :box
(:line-width
2 :style pressed-button
)
2130 :background
"lightgrey" :foreground
"black")
2131 (t :inverse-video t
))
2132 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2134 :group
'custom-faces
)
2136 (defface custom-button-pressed-unraised
2137 '((default :inherit custom-button-unraised
)
2138 (((class color
) (background light
)) :foreground
"magenta4")
2139 (((class color
) (background dark
)) :foreground
"violet"))
2140 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2142 :group
'custom-faces
)
2144 (setq custom-button-pressed
2145 (if custom-raised-buttons
2146 'custom-button-pressed
2147 'custom-button-pressed-unraised
))
2149 (defface custom-documentation
'((t nil
))
2150 "Face used for documentation strings in customization buffers."
2151 :group
'custom-faces
)
2153 (defface custom-state
'((((class color
) (background dark
))
2154 :foreground
"lime green")
2155 (((class color
) (background light
))
2156 :foreground
"dark green"))
2157 "Face used for State descriptions in the customize buffer."
2158 :group
'custom-faces
)
2160 (defface custom-link
'((t :inherit link
))
2161 "Face for links in customization buffers."
2163 :group
'custom-faces
)
2165 (define-widget 'custom
'default
2166 "Customize a user option."
2168 :convert-widget
'custom-convert-widget
2169 :notify
'custom-notify
2172 :custom-state
'hidden
2173 :documentation-property
'widget-subclass-responsibility
2174 :value-create
'widget-subclass-responsibility
2175 :value-delete
'widget-children-value-delete
2176 :value-get
'widget-value-value-get
2177 :validate
'widget-children-validate
2178 :match
(lambda (_widget value
) (symbolp value
)))
2180 (defun custom-convert-widget (widget)
2181 "Initialize :value and :tag from :args in WIDGET."
2182 (let ((args (widget-get widget
:args
)))
2184 (widget-put widget
:value
(widget-apply widget
2185 :value-to-internal
(car args
)))
2186 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2187 (widget-put widget
:args nil
)))
2190 (defun custom-notify (widget &rest args
)
2191 "Keep track of changes."
2192 (let ((state (widget-get widget
:custom-state
)))
2193 (unless (eq state
'modified
)
2194 (unless (memq state
'(nil unknown hidden
))
2195 (widget-put widget
:custom-state
'modified
))
2196 (custom-magic-reset widget
)
2197 (apply 'widget-default-notify widget args
))))
2199 (defun custom-redraw (widget)
2200 "Redraw WIDGET with current settings."
2201 (let ((line (count-lines (point-min) (point)))
2202 (column (current-column))
2204 (from (marker-position (widget-get widget
:from
)))
2205 (to (marker-position (widget-get widget
:to
))))
2207 (widget-value-set widget
(widget-value widget
))
2208 (custom-redraw-magic widget
))
2209 (when (and (>= pos from
) (<= pos to
))
2212 (goto-char (point-min))
2213 (forward-line (if (> column
0)
2216 (move-to-column column
))
2219 (defun custom-redraw-magic (widget)
2220 "Redraw WIDGET state with current settings."
2222 (let ((magic (widget-get widget
:custom-magic
)))
2224 (widget-value-set magic
(widget-value magic
))
2225 (when (setq widget
(widget-get widget
:group
))
2226 (custom-group-state-update widget
)))
2228 (setq widget nil
)))))
2231 (defun custom-show (widget value
)
2232 "Non-nil if WIDGET should be shown with VALUE by default."
2233 (declare (obsolete "this widget type is no longer supported." "24.1"))
2234 (let ((show (widget-get widget
:custom-show
)))
2235 (if (functionp show
)
2236 (funcall show widget value
)
2239 (defun custom-load-widget (widget)
2240 "Load all dependencies for WIDGET."
2241 (custom-load-symbol (widget-value widget
)))
2243 (defun custom-unloaded-symbol-p (symbol)
2244 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2246 (loads (get symbol
'custom-loads
))
2249 (setq load
(car loads
)
2251 (cond ((symbolp load
)
2252 (unless (featurep load
)
2254 ((assoc load load-history
))
2255 ((assoc (locate-library load
) load-history
)
2261 (defun custom-unloaded-widget-p (widget)
2262 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2263 (custom-unloaded-symbol-p (widget-value widget
)))
2265 (defun custom-toggle-hide (widget)
2266 "Toggle visibility of WIDGET."
2267 (custom-load-widget widget
)
2268 (let ((state (widget-get widget
:custom-state
)))
2269 (cond ((memq state
'(invalid modified set
))
2270 (error "There are unsaved changes"))
2272 (widget-put widget
:custom-state
'unknown
))
2274 (widget-put widget
:documentation-shown nil
)
2275 (widget-put widget
:custom-state
'hidden
)))
2276 (custom-redraw widget
)
2279 (defun custom-toggle-parent (widget &rest _ignore
)
2280 "Toggle visibility of parent of WIDGET."
2281 (custom-toggle-hide (widget-get widget
:parent
)))
2283 (defun custom-add-see-also (widget &optional prefix
)
2284 "Add `See also ...' to WIDGET if there are any links.
2285 Insert PREFIX first if non-nil."
2286 (let* ((symbol (widget-get widget
:value
))
2287 (links (get symbol
'custom-links
))
2288 (many (> (length links
) 2))
2289 (buttons (widget-get widget
:buttons
))
2290 (indent (widget-get widget
:indent
)))
2293 (insert-char ?\ indent
))
2296 (insert "See also ")
2298 (push (widget-create-child-and-convert
2300 :button-face
'custom-link
2301 :mouse-face
'highlight
2302 :pressed-face
'highlight
)
2304 (setq links
(cdr links
))
2313 (widget-put widget
:buttons buttons
))))
2315 (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string
)
2316 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2317 The value is non-nil if any parents were found.
2318 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2319 (let ((name (widget-value widget
))
2320 (type (widget-type widget
))
2321 (buttons (widget-get widget
:buttons
))
2324 (insert (or initial-string
"Groups:"))
2325 (mapatoms (lambda (symbol)
2326 (when (member (list name type
) (get symbol
'custom-group
))
2328 (push (widget-create-child-and-convert
2329 widget
'custom-group-link
2330 :tag
(custom-unlispify-tag-name symbol
)
2333 (setq parents
(cons symbol parents
)))))
2336 (delete-region start
(point)))
2337 (widget-put widget
:buttons buttons
)
2340 ;;; The `custom-comment' Widget.
2342 ;; like the editable field
2343 (defface custom-comment
'((((type tty
))
2344 :background
"yellow3"
2345 :foreground
"black")
2346 (((class grayscale color
)
2348 :background
"gray85")
2349 (((class grayscale color
)
2351 :background
"dim gray")
2354 "Face used for comments on variables or faces."
2356 :group
'custom-faces
)
2358 ;; like font-lock-comment-face
2359 (defface custom-comment-tag
2360 '((((class color
) (background dark
)) :foreground
"gray80")
2361 (((class color
) (background light
)) :foreground
"blue4")
2362 (((class grayscale
) (background light
))
2363 :foreground
"DimGray" :weight bold
:slant italic
)
2364 (((class grayscale
) (background dark
))
2365 :foreground
"LightGray" :weight bold
:slant italic
)
2367 "Face used for the comment tag on variables or faces."
2368 :group
'custom-faces
)
2370 (define-widget 'custom-comment
'string
2373 :help-echo
"Edit a comment here."
2374 :sample-face
'custom-comment-tag
2375 :value-face
'custom-comment
2377 :create
'custom-comment-create
)
2379 (defun custom-comment-create (widget)
2380 (let* ((null-comment (equal "" (widget-value widget
))))
2381 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2383 (widget-default-create widget
)
2384 ;; `widget-default-delete' expects markers in these slots --
2385 ;; maybe it shouldn't.
2386 (widget-put widget
:from
(point-marker))
2387 (widget-put widget
:to
(point-marker)))))
2389 (defun custom-comment-hide (widget)
2390 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2392 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2393 ;; the global custom one
2394 (defun custom-comment-show (widget)
2395 (widget-put widget
:comment-shown t
)
2396 (custom-redraw widget
)
2399 (defun custom-comment-invisible-p (widget)
2400 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2402 (not (widget-get widget
:comment-shown
)))))
2404 ;;; The `custom-variable' Widget.
2406 (defface custom-variable-tag
2407 `((((class color
) (background dark
))
2408 :foreground
"light blue" :weight bold
)
2409 (((min-colors 88) (class color
) (background light
))
2410 :foreground
"blue1" :weight bold
)
2411 (((class color
) (background light
))
2412 :foreground
"blue" :weight bold
)
2414 "Face used for unpushable variable tags."
2415 :group
'custom-faces
)
2417 (defface custom-variable-button
'((t :underline t
:weight bold
))
2418 "Face used for pushable variable tags."
2419 :group
'custom-faces
)
2421 (defcustom custom-variable-default-form
'edit
2422 "Default form of displaying variable values."
2423 :type
'(choice (const edit
)
2425 :group
'custom-buffer
2428 (defun custom-variable-documentation (variable)
2429 "Return documentation of VARIABLE for use in Custom buffer.
2430 Normally just return the docstring. But if VARIABLE automatically
2431 becomes buffer local when set, append a message to that effect."
2432 (format "%s%s" (documentation-property variable
'variable-documentation
)
2433 (if (and (local-variable-if-set-p variable
)
2434 (or (not (local-variable-p variable
))
2436 (local-variable-if-set-p variable
))))
2438 This variable automatically becomes buffer-local when set outside Custom.
2439 However, setting it through Custom sets the default value."
2442 (define-widget 'custom-variable
'custom
2443 "A widget for displaying a Custom variable.
2444 The following properties have special meanings for this widget:
2446 :hidden-states should be a list of widget states for which the
2447 widget's initial contents are to be hidden.
2449 :custom-form should be a symbol describing how to display and
2450 edit the variable---either `edit' (using edit widgets),
2451 `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
2452 if nil, use the return value of `custom-variable-default-form'.
2454 :shown-value, if non-nil, should be a list whose `car' is the
2455 variable value to display in place of the current value.
2457 :custom-style describes the widget interface style; nil is the
2458 default style, while `simple' means a simpler interface that
2459 inhibits the magic custom-state widget."
2461 :help-echo
"Set or reset this variable."
2462 :documentation-property
#'custom-variable-documentation
2463 :custom-category
'option
2465 :custom-menu
'custom-variable-menu-create
2467 :value-create
'custom-variable-value-create
2468 :action
'custom-variable-action
2469 :hidden-states
'(standard)
2470 :custom-set
'custom-variable-set
2471 :custom-mark-to-save
'custom-variable-mark-to-save
2472 :custom-reset-current
'custom-redraw
2473 :custom-reset-saved
'custom-variable-reset-saved
2474 :custom-reset-standard
'custom-variable-reset-standard
2475 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2476 :custom-standard-value
'custom-variable-standard-value
2477 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2479 (defun custom-variable-type (symbol)
2480 "Return a widget suitable for editing the value of SYMBOL.
2481 If SYMBOL has a `custom-type' property, use that.
2482 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2483 try matching its doc string against `custom-guess-doc-alist'."
2484 (let* ((type (or (get symbol
'custom-type
)
2485 (and (not (get symbol
'standard-value
))
2486 (custom-guess-type symbol
))
2488 (options (get symbol
'custom-options
))
2489 (tmp (if (listp type
)
2490 (copy-sequence type
)
2493 (widget-put tmp
:options options
))
2496 (defun custom-variable-value-create (widget)
2497 "Here is where you edit the variable's value."
2498 (custom-load-widget widget
)
2499 (unless (widget-get widget
:custom-form
)
2500 (widget-put widget
:custom-form custom-variable-default-form
))
2501 (let* ((buttons (widget-get widget
:buttons
))
2502 (children (widget-get widget
:children
))
2503 (form (widget-get widget
:custom-form
))
2504 (symbol (widget-get widget
:value
))
2505 (tag (widget-get widget
:tag
))
2506 (type (custom-variable-type symbol
))
2507 (conv (widget-convert type
))
2508 (get (or (get symbol
'custom-get
) 'default-value
))
2509 (prefix (widget-get widget
:custom-prefix
))
2510 (last (widget-get widget
:custom-last
))
2511 (style (widget-get widget
:custom-style
))
2512 (value (let ((shown-value (widget-get widget
:shown-value
)))
2515 ((default-boundp symbol
)
2516 (funcall get symbol
))
2517 (t (widget-get conv
:value
)))))
2518 (state (or (widget-get widget
:custom-state
)
2519 (if (memq (custom-variable-state symbol value
)
2520 (widget-get widget
:hidden-states
))
2523 ;; If we don't know the state, see if we need to edit it in lisp form.
2525 (setq state
(if (custom-show type value
) 'unknown
'hidden
)))
2526 (when (eq state
'unknown
)
2527 (unless (widget-apply conv
:match value
)
2528 (setq form
'mismatch
)))
2529 ;; Now we can create the child widget.
2530 (cond ((eq custom-buffer-style
'tree
)
2531 (insert prefix
(if last
" `--- " " |--- "))
2532 (push (widget-create-child-and-convert
2533 widget
'custom-browse-variable-tag
)
2535 (insert " " tag
"\n")
2536 (widget-put widget
:buttons buttons
))
2538 ;; Indicate hidden value.
2539 (push (widget-create-child-and-convert
2540 widget
'custom-visibility
2541 :help-echo
"Show the value of this option."
2546 :action
'custom-toggle-hide-variable
2550 (push (widget-create-child-and-convert
2553 :sample-face
'custom-variable-tag
2557 ((memq form
'(lisp mismatch
))
2558 (push (widget-create-child-and-convert
2559 widget
'custom-visibility
2560 :help-echo
"Hide the value of this option."
2565 :action
'custom-toggle-hide-variable
2569 ;; This used to try presenting the saved value or the
2570 ;; standard value, but it seems more intuitive to present
2571 ;; the current value (Bug#7600).
2572 (let* ((value (cond ((default-boundp symbol
)
2573 (custom-quote (funcall get symbol
)))
2575 (custom-quote (widget-get conv
:value
))))))
2576 (insert (symbol-name symbol
) ": ")
2577 (push (widget-create-child-and-convert
2579 :button-face
'custom-variable-button-face
2581 :tag
(symbol-name symbol
)
2587 (push (widget-create-child-and-convert
2588 widget
'custom-visibility
2589 :help-echo
"Hide or show this option."
2594 :action
'custom-toggle-hide-variable
2598 (let* ((format (widget-get type
:format
))
2599 tag-format value-format
)
2600 (unless (string-match ":" format
)
2601 (error "Bad format"))
2602 (setq tag-format
(substring format
0 (match-end 0)))
2603 (setq value-format
(substring format
(match-end 0)))
2604 (push (widget-create-child-and-convert
2607 :action
'custom-tag-action
2608 :help-echo
"Change value of this option."
2609 :mouse-down-action
'custom-tag-mouse-down-action
2610 :button-face
'custom-variable-button
2611 :sample-face
'custom-variable-tag
2614 (push (widget-create-child-and-convert
2616 :format value-format
2619 (unless (eq custom-buffer-style
'tree
)
2620 (unless (eq (preceding-char) ?
\n)
2621 (widget-insert "\n"))
2622 ;; Create the magic button.
2623 (unless (eq style
'simple
)
2624 (let ((magic (widget-create-child-and-convert
2625 widget
'custom-magic nil
)))
2626 (widget-put widget
:custom-magic magic
)
2627 (push magic buttons
)))
2628 (widget-put widget
:buttons buttons
)
2629 ;; Insert documentation.
2630 (widget-put widget
:documentation-indent
3)
2631 (unless (and (eq style
'simple
)
2633 (widget-add-documentation-string-button
2634 widget
:visibility-widget
'custom-visibility
))
2636 ;; The comment field
2637 (unless (eq state
'hidden
)
2638 (let* ((comment (get symbol
'variable-comment
))
2640 (widget-create-child-and-convert
2641 widget
'custom-comment
2643 :value
(or comment
""))))
2644 (widget-put widget
:comment-widget comment-widget
)
2645 ;; Don't push it !!! Custom assumes that the first child is the
2647 (setq children
(append children
(list comment-widget
)))))
2648 ;; Update the rest of the properties.
2649 (widget-put widget
:custom-form form
)
2650 (widget-put widget
:children children
)
2651 ;; Now update the state.
2652 (if (eq state
'hidden
)
2653 (widget-put widget
:custom-state state
)
2654 (custom-variable-state-set widget
))
2656 (unless (eq state
'hidden
)
2657 (when (eq (widget-get widget
:custom-level
) 1)
2658 (custom-add-parent-links widget
))
2659 (custom-add-see-also widget
)))))
2661 (defun custom-toggle-hide-variable (visibility-widget &rest _ignore
)
2662 "Toggle the visibility of a `custom-variable' parent widget.
2663 By default, this signals an error if the parent has unsaved
2664 changes. If the parent has a `simple' :custom-style property,
2665 the present value is saved to its :shown-value property instead."
2666 (let ((widget (widget-get visibility-widget
:parent
)))
2667 (unless (eq (widget-type widget
) 'custom-variable
)
2668 (error "Invalid widget type"))
2669 (custom-load-widget widget
)
2670 (let ((state (widget-get widget
:custom-state
)))
2671 (if (eq state
'hidden
)
2672 (widget-put widget
:custom-state
'unknown
)
2673 ;; In normal interface, widget can't be hidden if modified.
2674 (when (memq state
'(invalid modified set
))
2675 (if (eq (widget-get widget
:custom-style
) 'simple
)
2676 (widget-put widget
:shown-value
2679 (widget-get widget
:children
)))))
2680 (error "There are unsaved changes")))
2681 (widget-put widget
:documentation-shown nil
)
2682 (widget-put widget
:custom-state
'hidden
))
2683 (custom-redraw widget
)
2686 (defun custom-tag-action (widget &rest args
)
2687 "Pass :action to first child of WIDGET's parent."
2688 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2691 (defun custom-tag-mouse-down-action (widget &rest args
)
2692 "Pass :mouse-down-action to first child of WIDGET's parent."
2693 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2694 :mouse-down-action args
))
2696 (defun custom-variable-state (symbol val
)
2697 "Return the state of SYMBOL if its value is VAL.
2698 If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
2699 Possible return values are `standard', `saved', `set', `themed',
2700 `changed', and `rogue'."
2701 (let* ((get (or (get symbol
'custom-get
) 'default-value
))
2702 (value (if (default-boundp symbol
)
2703 (funcall get symbol
)
2705 (comment (get symbol
'variable-comment
))
2708 (cond ((progn (setq tmp
(get symbol
'customized-value
))
2710 (get symbol
'customized-variable-comment
))
2712 (if (condition-case nil
2713 (and (equal value
(eval (car tmp
)))
2714 (equal comment temp
))
2718 ((progn (setq tmp
(get symbol
'theme-value
))
2719 (setq temp
(get symbol
'saved-variable-comment
))
2721 (if (condition-case nil
2722 (and (equal comment temp
)
2725 (car (custom-variable-theme-value
2729 ((eq (caar tmp
) 'user
) 'saved
)
2730 ((eq (caar tmp
) 'changed
)
2731 (if (condition-case nil
2735 (car (get symbol
'standard-value
)))))
2737 ;; The value was originally set outside
2738 ;; custom, but it was set to the standard
2739 ;; value (probably an autoloaded defcustom).
2744 ((setq tmp
(get symbol
'standard-value
))
2745 (if (condition-case nil
2746 (and (equal value
(eval (car tmp
)))
2747 (equal comment nil
))
2753 (defun custom-variable-state-set (widget &optional state
)
2754 "Set the state of WIDGET to STATE.
2755 If STATE is nil, the value is computed by `custom-variable-state'."
2756 (widget-put widget
:custom-state
2757 (or state
(custom-variable-state (widget-value widget
)
2758 (widget-get widget
:value
)))))
2760 (defun custom-variable-standard-value (widget)
2761 (get (widget-value widget
) 'standard-value
))
2763 (defvar custom-variable-menu
2764 `(("Set for Current Session" custom-variable-set
2766 (eq (widget-get widget
:custom-state
) 'modified
)))
2767 ;; Note that in all the backquoted code in this file, we test
2768 ;; init-file-user rather than user-init-file. This is in case
2769 ;; cus-edit is loaded by something in site-start.el, because
2770 ;; user-init-file is not set at that stage.
2771 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2772 ,@(when (or custom-file init-file-user
)
2773 '(("Save for Future Sessions" custom-variable-save
2775 (memq (widget-get widget
:custom-state
)
2776 '(modified set changed rogue
))))))
2777 ("Undo Edits" custom-redraw
2779 (and (default-boundp (widget-value widget
))
2780 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2781 ("Revert This Session's Customization" custom-variable-reset-saved
2783 (memq (widget-get widget
:custom-state
)
2784 '(modified set changed rogue
))))
2785 ,@(when (or custom-file init-file-user
)
2786 '(("Erase Customization" custom-variable-reset-standard
2788 (and (get (widget-value widget
) 'standard-value
)
2789 (memq (widget-get widget
:custom-state
)
2790 '(modified set changed saved rogue
)))))))
2791 ("Set to Backup Value" custom-variable-reset-backup
2793 (get (widget-value widget
) 'backup-value
)))
2794 ("---" ignore ignore
)
2795 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2796 ("---" ignore ignore
)
2797 ("Show Current Value" custom-variable-edit
2799 (eq (widget-get widget
:custom-form
) 'lisp
)))
2800 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2802 (eq (widget-get widget
:custom-form
) 'edit
))))
2803 "Alist of actions for the `custom-variable' widget.
2804 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2805 the menu entry, ACTION is the function to call on the widget when the
2806 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2807 widget as an argument, and returns non-nil if ACTION is valid on that
2808 widget. If FILTER is nil, ACTION is always valid.")
2810 (defun custom-variable-action (widget &optional event
)
2811 "Show the menu for `custom-variable' WIDGET.
2812 Optional EVENT is the location for the menu."
2813 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2814 (custom-toggle-hide widget
)
2815 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2816 (custom-variable-state-set widget
))
2817 (custom-redraw-magic widget
)
2818 (let* ((completion-ignore-case t
)
2819 (answer (widget-choose (concat "Operation on "
2820 (custom-unlispify-tag-name
2821 (widget-get widget
:value
)))
2822 (custom-menu-filter custom-variable-menu
2826 (funcall answer widget
)))))
2828 (defun custom-variable-edit (widget)
2829 "Edit value of WIDGET."
2830 (widget-put widget
:custom-state
'unknown
)
2831 (widget-put widget
:custom-form
'edit
)
2832 (custom-redraw widget
))
2834 (defun custom-variable-edit-lisp (widget)
2835 "Edit the Lisp representation of the value of WIDGET."
2836 (widget-put widget
:custom-state
'unknown
)
2837 (widget-put widget
:custom-form
'lisp
)
2838 (custom-redraw widget
))
2840 (defun custom-variable-set (widget)
2841 "Set the current value for the variable being edited by WIDGET."
2842 (let* ((form (widget-get widget
:custom-form
))
2843 (state (widget-get widget
:custom-state
))
2844 (child (car (widget-get widget
:children
)))
2845 (symbol (widget-value widget
))
2846 (set (or (get symbol
'custom-set
) 'set-default
))
2847 (comment-widget (widget-get widget
:comment-widget
))
2848 (comment (widget-value comment-widget
))
2850 (cond ((eq state
'hidden
)
2851 (user-error "Cannot set hidden variable"))
2852 ((setq val
(widget-apply child
:validate
))
2853 (goto-char (widget-get val
:from
))
2854 (error "%s" (widget-get val
:error
)))
2855 ((memq form
'(lisp mismatch
))
2856 (when (equal comment
"")
2858 ;; Make the comment invisible by hand if it's empty
2859 (custom-comment-hide comment-widget
))
2860 (custom-variable-backup-value widget
)
2861 (custom-push-theme 'theme-value symbol
'user
2862 'set
(custom-quote (widget-value child
)))
2863 (funcall set symbol
(eval (setq val
(widget-value child
))))
2864 (put symbol
'customized-value
(list val
))
2865 (put symbol
'variable-comment comment
)
2866 (put symbol
'customized-variable-comment comment
))
2868 (when (equal comment
"")
2870 ;; Make the comment invisible by hand if it's empty
2871 (custom-comment-hide comment-widget
))
2872 (custom-variable-backup-value widget
)
2873 (custom-push-theme 'theme-value symbol
'user
2874 'set
(custom-quote (widget-value child
)))
2875 (funcall set symbol
(setq val
(widget-value child
)))
2876 (put symbol
'customized-value
(list (custom-quote val
)))
2877 (put symbol
'variable-comment comment
)
2878 (put symbol
'customized-variable-comment comment
)))
2879 (custom-variable-state-set widget
)
2880 (custom-redraw-magic widget
)))
2882 (defun custom-variable-mark-to-save (widget)
2883 "Set value and mark for saving the variable edited by WIDGET."
2884 (let* ((form (widget-get widget
:custom-form
))
2885 (state (widget-get widget
:custom-state
))
2886 (child (car (widget-get widget
:children
)))
2887 (symbol (widget-value widget
))
2888 (set (or (get symbol
'custom-set
) 'set-default
))
2889 (comment-widget (widget-get widget
:comment-widget
))
2890 (comment (widget-value comment-widget
))
2892 (cond ((eq state
'hidden
)
2893 (user-error "Cannot set hidden variable"))
2894 ((setq val
(widget-apply child
:validate
))
2895 (goto-char (widget-get val
:from
))
2896 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2897 ((memq form
'(lisp mismatch
))
2898 (when (equal comment
"")
2900 ;; Make the comment invisible by hand if it's empty
2901 (custom-comment-hide comment-widget
))
2902 (put symbol
'saved-value
(list (widget-value child
)))
2903 (custom-push-theme 'theme-value symbol
'user
2904 'set
(custom-quote (widget-value child
)))
2905 (funcall set symbol
(eval (widget-value child
)))
2906 (put symbol
'variable-comment comment
)
2907 (put symbol
'saved-variable-comment comment
))
2909 (when (equal comment
"")
2911 ;; Make the comment invisible by hand if it's empty
2912 (custom-comment-hide comment-widget
))
2913 (put symbol
'saved-value
2914 (list (custom-quote (widget-value child
))))
2915 (custom-push-theme 'theme-value symbol
'user
2916 'set
(custom-quote (widget-value child
)))
2917 (funcall set symbol
(widget-value child
))
2918 (put symbol
'variable-comment comment
)
2919 (put symbol
'saved-variable-comment comment
)))
2920 (put symbol
'customized-value nil
)
2921 (put symbol
'customized-variable-comment nil
)))
2923 (defsubst custom-variable-state-set-and-redraw
(widget)
2924 "Set state of variable widget WIDGET and redraw with current settings."
2925 (custom-variable-state-set widget
)
2926 (custom-redraw-magic widget
))
2928 (defun custom-variable-save (widget)
2929 "Save value of variable edited by widget WIDGET."
2930 (custom-variable-mark-to-save widget
)
2932 (custom-variable-state-set-and-redraw widget
))
2934 (defun custom-variable-reset-saved (widget)
2935 "Restore the value of the variable being edited by WIDGET.
2936 If there is a saved value, restore it; otherwise reset to the
2937 uncustomized (themed or standard) value.
2939 Update the widget to show that value. The value that was current
2940 before this operation becomes the backup value."
2941 (let* ((symbol (widget-value widget
))
2942 (saved-value (get symbol
'saved-value
))
2943 (comment (get symbol
'saved-variable-comment
)))
2944 (custom-variable-backup-value widget
)
2945 (if (not (or saved-value comment
))
2946 ;; If there is no saved value, remove the setting.
2947 (custom-push-theme 'theme-value symbol
'user
'reset
)
2948 ;; Otherwise, apply the saved value.
2949 (put symbol
'variable-comment comment
)
2950 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe saved-value
))
2952 (funcall (or (get symbol
'custom-set
) 'set-default
)
2953 symbol
(eval (car saved-value
)))))
2954 (put symbol
'customized-value nil
)
2955 (put symbol
'customized-variable-comment nil
)
2956 (widget-put widget
:custom-state
'unknown
)
2957 ;; This call will possibly make the comment invisible
2958 (custom-redraw widget
)))
2960 (defun custom-variable-mark-to-reset-standard (widget)
2961 "Mark to restore standard setting for the variable edited by widget WIDGET.
2962 If `custom-reset-standard-variables-list' is nil, save, reset and
2963 redraw the widget immediately."
2964 (let* ((symbol (widget-value widget
)))
2965 (if (get symbol
'standard-value
)
2966 (custom-variable-backup-value widget
)
2967 (user-error "No standard setting known for %S" symbol
))
2968 (put symbol
'variable-comment nil
)
2969 (put symbol
'customized-value nil
)
2970 (put symbol
'customized-variable-comment nil
)
2971 (custom-push-theme 'theme-value symbol
'user
'reset
)
2972 (custom-theme-recalc-variable symbol
)
2973 (if (and custom-reset-standard-variables-list
2974 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2976 (put symbol
'saved-value nil
)
2977 (put symbol
'saved-variable-comment nil
)
2978 ;; Append this to `custom-reset-standard-variables-list' to
2979 ;; have `custom-reset-standard-save-and-update' save setting
2980 ;; to the file, update the widget's state, and redraw it.
2981 (setq custom-reset-standard-variables-list
2982 (cons widget custom-reset-standard-variables-list
)))
2983 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2984 (put symbol
'saved-value nil
)
2985 (put symbol
'saved-variable-comment nil
)
2987 (widget-put widget
:custom-state
'unknown
)
2988 ;; This call will possibly make the comment invisible
2989 (custom-redraw widget
))))
2991 (defun custom-variable-reset-standard (widget)
2992 "Restore standard setting for the variable edited by WIDGET.
2993 This operation eliminates any saved setting for the variable,
2994 restoring it to the state of a variable that has never been customized.
2995 The value that was current before this operation
2996 becomes the backup value, so you can get it again."
2997 (let (custom-reset-standard-variables-list)
2998 (custom-variable-mark-to-reset-standard widget
)))
3000 (defun custom-variable-backup-value (widget)
3001 "Back up the current value for WIDGET's variable.
3002 The backup value is kept in the car of the `backup-value' property."
3003 (let* ((symbol (widget-value widget
))
3004 (get (or (get symbol
'custom-get
) 'default-value
))
3005 (type (custom-variable-type symbol
))
3006 (conv (widget-convert type
))
3007 (value (if (default-boundp symbol
)
3008 (funcall get symbol
)
3009 (widget-get conv
:value
))))
3010 (put symbol
'backup-value
(list value
))))
3012 (defun custom-variable-reset-backup (widget)
3013 "Restore the backup value for the variable being edited by WIDGET.
3014 The value that was current before this operation
3015 becomes the backup value, so you can use this operation repeatedly
3016 to switch between two values."
3017 (let* ((symbol (widget-value widget
))
3018 (set (or (get symbol
'custom-set
) 'set-default
))
3019 (value (get symbol
'backup-value
))
3020 (comment-widget (widget-get widget
:comment-widget
))
3021 (comment (widget-value comment-widget
)))
3024 (custom-variable-backup-value widget
)
3025 (custom-push-theme 'theme-value symbol
'user
'set value
)
3027 (funcall set symbol
(car value
))
3029 (user-error "No backup value for %s" symbol
))
3030 (put symbol
'customized-value
(list (custom-quote (car value
))))
3031 (put symbol
'variable-comment comment
)
3032 (put symbol
'customized-variable-comment comment
)
3033 (custom-variable-state-set widget
)
3034 ;; This call will possibly make the comment invisible
3035 (custom-redraw widget
)))
3037 ;;; The `custom-visibility' Widget
3039 (define-widget 'custom-visibility
'visibility
3040 "Show or hide a documentation string."
3041 :button-face
'custom-visibility
3042 :pressed-face
'custom-visibility
3043 :mouse-face
'highlight
3044 :pressed-face
'highlight
3048 (defface custom-visibility
3049 '((t :height
0.8 :inherit link
))
3050 "Face for the `custom-visibility' widget."
3052 :group
'custom-faces
)
3054 ;;; The `custom-face-edit' Widget.
3056 (define-widget 'custom-face-edit
'checklist
3057 "Widget for editing face attributes.
3058 The following properties have special meanings for this widget:
3060 :value is a plist of face attributes.
3062 :default-face-attributes, if non-nil, is a plist of defaults for
3063 face attributes (as specified by a `default' defface entry)."
3066 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3067 :value-to-internal
'custom-face-edit-fix-value
3068 :match
(lambda (widget value
)
3069 (widget-checklist-match widget
3070 (custom-face-edit-fix-value widget value
)))
3071 :value-create
'custom-face-edit-value-create
3072 :convert-widget
'custom-face-edit-convert-widget
3073 :args
(mapcar (lambda (att)
3074 (list 'group
:inline t
3075 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3076 (list 'const
:format
"" :value
(nth 0 att
))
3078 custom-face-attributes
))
3080 (defun custom-face-edit-value-create (widget)
3081 (let* ((alist (widget-checklist-match-find
3082 widget
(widget-get widget
:value
)))
3083 (args (widget-get widget
:args
))
3084 (show-all (widget-get widget
:show-all-attributes
))
3085 (buttons (widget-get widget
:buttons
))
3086 (defaults (widget-checklist-match-find
3088 (widget-get widget
:default-face-attributes
)))
3090 (unless (looking-back "^ *")
3092 (insert-char ?\s
(widget-get widget
:extra-offset
))
3093 (if (or alist defaults show-all
)
3095 (setq entry
(or (assq prop alist
)
3096 (assq prop defaults
)))
3097 (if (or entry show-all
)
3098 (widget-checklist-add-item widget prop entry
)))
3099 (insert (propertize "-- Empty face --" 'face
'shadow
) ?
\n))
3100 (let ((indent (widget-get widget
:indent
)))
3101 (if indent
(insert-char ?\s
(widget-get widget
:indent
))))
3102 (push (widget-create-child-and-convert
3104 :help-echo
"Show or hide all face attributes."
3105 :button-face
'custom-visibility
3106 :pressed-face
'custom-visibility
3107 :mouse-face
'highlight
3108 :on
"Hide Unused Attributes" :off
"Show All Attributes"
3109 :on-glyph nil
:off-glyph nil
3111 :action
'custom-face-edit-value-visibility-action
3115 (widget-put widget
:buttons buttons
)
3116 (widget-put widget
:children
(nreverse (widget-get widget
:children
)))))
3118 (defun custom-face-edit-value-visibility-action (widget &rest _ignore
)
3119 ;; Toggle hiding of face attributes.
3120 (let ((parent (widget-get widget
:parent
)))
3121 (widget-put parent
:show-all-attributes
3122 (not (widget-get parent
:show-all-attributes
)))
3123 (custom-redraw parent
)))
3125 (defun custom-face-edit-fix-value (_widget value
)
3126 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3127 Also change :reverse-video to :inverse-video."
3128 (custom-fix-face-spec value
))
3130 (defun custom-face-edit-convert-widget (widget)
3131 "Convert :args as widget types in WIDGET."
3134 :args
(mapcar (lambda (arg)
3136 :deactivate
'custom-face-edit-deactivate
3137 :activate
'custom-face-edit-activate
3138 :delete
'custom-face-edit-delete
))
3139 (widget-get widget
:args
)))
3142 (defconst custom-face-edit
(widget-convert 'custom-face-edit
)
3143 "Converted version of the `custom-face-edit' widget.")
3145 (defun custom-face-edit-deactivate (widget)
3146 "Make face widget WIDGET inactive for user modifications."
3147 (unless (widget-get widget
:inactive
)
3148 (let ((tag (custom-face-edit-attribute-tag widget
))
3149 (from (copy-marker (widget-get widget
:from
)))
3150 (value (widget-value widget
))
3151 (inhibit-read-only t
)
3152 (inhibit-modification-hooks t
))
3155 (widget-default-delete widget
)
3156 (insert tag
": " (propertize "--" 'face
'shadow
) "\n")
3157 (widget-put widget
:inactive
3158 (cons value
(cons from
(- (point) from
))))))))
3160 (defun custom-face-edit-activate (widget)
3161 "Make face widget WIDGET active for user modifications."
3162 (let ((inactive (widget-get widget
:inactive
))
3163 (inhibit-read-only t
)
3164 (inhibit-modification-hooks t
))
3165 (when (consp inactive
)
3167 (goto-char (car (cdr inactive
)))
3168 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3169 (widget-put widget
:inactive nil
)
3170 (widget-apply widget
:create
)
3171 (widget-value-set widget
(car inactive
))
3174 (defun custom-face-edit-delete (widget)
3175 "Remove WIDGET from the buffer."
3176 (let ((inactive (widget-get widget
:inactive
))
3177 (inhibit-read-only t
)
3178 (inhibit-modification-hooks t
))
3180 ;; Widget is alive, we don't have to do anything special
3181 (widget-default-delete widget
)
3182 ;; WIDGET is already deleted because we did so to deactivate it;
3183 ;; now just get rid of the label we put in its place.
3184 (delete-region (car (cdr inactive
))
3185 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3186 (widget-put widget
:inactive nil
))))
3189 (defun custom-face-edit-attribute-tag (widget)
3190 "Return the first :tag property in WIDGET or one of its children."
3191 (let ((tag (widget-get widget
:tag
)))
3192 (or (and (not (equal tag
"")) tag
)
3193 (let ((children (widget-get widget
:children
)))
3194 (while (and (null tag
) children
)
3195 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3198 ;;; The `custom-display' Widget.
3200 (define-widget 'custom-display
'menu-choice
3201 "Select a display type."
3204 :help-echo
"Specify frames where the face attributes should be used."
3205 :args
'((const :tag
"all" t
)
3206 (const :tag
"defaults" default
)
3208 :tag
"specific display"
3211 :args
((group :sibling-args
(:help-echo
"\
3212 Only match the specified window systems.")
3213 (const :format
"Type: "
3215 (checklist :inline t
3218 :sibling-args
(:help-echo
"\
3219 The X11 Window System.")
3221 (const :format
"PM "
3222 :sibling-args
(:help-echo
"\
3223 OS/2 Presentation Manager.")
3225 (const :format
"W32 "
3226 :sibling-args
(:help-echo
"\
3229 (const :format
"NS "
3230 :sibling-args
(:help-echo
"\
3231 GNUstep or Macintosh OS Cocoa interface.")
3233 (const :format
"DOS "
3234 :sibling-args
(:help-echo
"\
3237 (const :format
"TTY%n"
3238 :sibling-args
(:help-echo
"\
3239 Plain text terminals.")
3241 (group :sibling-args
(:help-echo
"\
3242 Only match the frames with the specified color support.")
3243 (const :format
"Class: "
3245 (checklist :inline t
3247 (const :format
"Color "
3248 :sibling-args
(:help-echo
"\
3249 Match color frames.")
3251 (const :format
"Grayscale "
3252 :sibling-args
(:help-echo
"\
3253 Match grayscale frames.")
3255 (const :format
"Monochrome%n"
3256 :sibling-args
(:help-echo
"\
3257 Match frames with no color support.")
3259 (group :sibling-args
(:help-echo
"\
3260 The minimum number of colors the frame should support.")
3261 (const :format
"" min-colors
)
3262 (integer :tag
"Minimum number of colors" ))
3263 (group :sibling-args
(:help-echo
"\
3264 Only match frames with the specified intensity.")
3266 Background brightness: "
3268 (checklist :inline t
3270 (const :format
"Light "
3271 :sibling-args
(:help-echo
"\
3272 Match frames with light backgrounds.")
3274 (const :format
"Dark\n"
3275 :sibling-args
(:help-echo
"\
3276 Match frames with dark backgrounds.")
3278 (group :sibling-args
(:help-echo
"\
3279 Only match frames that support the specified face attributes.")
3280 (const :format
"Supports attributes:" supports
)
3281 (custom-face-edit :inline t
:format
"%n%v"))))))
3283 ;;; The `custom-face' Widget.
3285 (defface custom-face-tag
3286 '((t :inherit custom-variable-tag
))
3287 "Face used for face tags."
3288 :group
'custom-faces
)
3290 (defcustom custom-face-default-form
'selected
3291 "Default form of displaying face definition."
3292 :type
'(choice (const all
)
3295 :group
'custom-buffer
3298 (define-widget 'custom-face
'custom
3299 "Widget for customizing a face.
3300 The following properties have special meanings for this widget:
3302 :value is the face name (a symbol).
3304 :custom-form should be a symbol describing how to display and
3305 edit the face attributes---either `selected' (attributes for
3306 selected display only), `all' (all attributes), `lisp' (as a
3307 Lisp sexp), or `mismatch' (should not happen); if nil, use
3308 the return value of `custom-face-default-form'.
3310 :custom-style describes the widget interface style; nil is the
3311 default style, while `simple' means a simpler interface that
3312 inhibits the magic custom-state widget.
3314 :sample-indent, if non-nil, is the number of columns to which to
3315 indent the face sample (an integer).
3317 :shown-value, if non-nil, is the face spec to display as the value
3318 of the widget, instead of the current face spec."
3319 :sample-face
'custom-face-tag
3320 :help-echo
"Set or reset this face."
3321 :documentation-property
#'face-doc-string
3322 :value-create
'custom-face-value-create
3323 :action
'custom-face-action
3324 :custom-category
'face
3326 :custom-set
'custom-face-set
3327 :custom-mark-to-save
'custom-face-mark-to-save
3328 :custom-reset-current
'custom-redraw
3329 :custom-reset-saved
'custom-face-reset-saved
3330 :custom-reset-standard
'custom-face-reset-standard
3331 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3332 :custom-standard-value
'custom-face-standard-value
3333 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3334 :custom-menu
'custom-face-menu-create
)
3336 (define-widget 'custom-face-all
'editable-list
3337 "An editable list of display specifications and attributes."
3338 :entry-format
"%i %d %v"
3339 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3340 :append-button-args
'(:help-echo
"Append new display specification here.")
3341 :delete-button-args
'(:help-echo
"Delete this display specification.")
3342 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3344 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3345 "Converted version of the `custom-face-all' widget.")
3347 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3348 "Return a canonicalized version of SPEC using.
3349 FILTER-INDEX is the index in the entry for each attribute in
3350 `custom-face-attributes' at which the appropriate filter function can be
3351 found, and DEFAULT-FILTER is the filter to apply for attributes that
3353 (mapcar (lambda (entry)
3354 ;; Filter a single face-spec entry
3355 (let ((tests (car entry
))
3357 ;; Handle both old- and new-style attribute syntax
3358 (if (listp (car (cdr entry
)))
3361 (filtered-attrs nil
))
3362 ;; Filter each face attribute
3363 (while unfiltered-attrs
3364 (let* ((attr (pop unfiltered-attrs
))
3365 (pre-filtered-value (pop unfiltered-attrs
))
3367 (or (nth filter-index
(assq attr custom-face-attributes
))
3371 (funcall filter pre-filtered-value
)
3372 pre-filtered-value
)))
3373 (push filtered-value filtered-attrs
)
3374 (push attr filtered-attrs
)))
3376 (list tests filtered-attrs
)))
3379 (defun custom-pre-filter-face-spec (spec)
3380 "Return SPEC changed as necessary for editing by the face customization widget.
3381 SPEC must be a full face spec."
3382 (custom-filter-face-spec spec
2))
3384 (defun custom-post-filter-face-spec (spec)
3385 "Return the customized SPEC in a form suitable for setting the face."
3386 (custom-filter-face-spec spec
3))
3388 (defun custom-face-widget-to-spec (widget)
3389 "Return a face spec corresponding to WIDGET.
3390 WIDGET should be a `custom-face' widget."
3391 (unless (eq (widget-type widget
) 'custom-face
)
3392 (error "Invalid widget"))
3393 (let ((child (car (widget-get widget
:children
))))
3394 (custom-post-filter-face-spec
3395 (if (eq (widget-type child
) 'custom-face-edit
)
3396 `((t ,(widget-value child
)))
3397 (widget-value child
)))))
3399 (defun custom-face-get-current-spec (face)
3400 (let ((spec (or (get face
'customized-face
)
3401 (get face
'saved-face
)
3402 (get face
'face-defface-spec
)
3403 ;; Attempt to construct it.
3404 `((t ,(custom-face-attributes-get
3405 face
(selected-frame)))))))
3406 ;; If the user has changed this face in some other way,
3407 ;; edit it as the user has specified it.
3408 (if (not (face-spec-match-p face spec
(selected-frame)))
3409 (setq spec
`((t ,(face-attr-construct face
(selected-frame))))))
3410 (custom-pre-filter-face-spec spec
)))
3412 (defun custom-toggle-hide-face (visibility-widget &rest _ignore
)
3413 "Toggle the visibility of a `custom-face' parent widget.
3414 By default, this signals an error if the parent has unsaved
3415 changes. If the parent has a `simple' :custom-style property,
3416 the present value is saved to its :shown-value property instead."
3417 (let ((widget (widget-get visibility-widget
:parent
)))
3418 (unless (eq (widget-type widget
) 'custom-face
)
3419 (error "Invalid widget type"))
3420 (custom-load-widget widget
)
3421 (let ((state (widget-get widget
:custom-state
)))
3422 (if (eq state
'hidden
)
3423 (widget-put widget
:custom-state
'unknown
)
3424 ;; In normal interface, widget can't be hidden if modified.
3425 (when (memq state
'(invalid modified set
))
3426 (if (eq (widget-get widget
:custom-style
) 'simple
)
3427 (widget-put widget
:shown-value
3428 (custom-face-widget-to-spec widget
))
3429 (error "There are unsaved changes")))
3430 (widget-put widget
:documentation-shown nil
)
3431 (widget-put widget
:custom-state
'hidden
))
3432 (custom-redraw widget
)
3435 (defun custom-face-value-create (widget)
3436 "Create a list of the display specifications for WIDGET."
3437 (let* ((buttons (widget-get widget
:buttons
))
3438 (symbol (widget-get widget
:value
))
3439 (tag (or (widget-get widget
:tag
)
3440 (prin1-to-string symbol
)))
3441 (hiddenp (eq (widget-get widget
:custom-state
) 'hidden
))
3442 (style (widget-get widget
:custom-style
))
3445 (if (eq custom-buffer-style
'tree
)
3447 ;; Draw a tree-style `custom-face' widget
3449 (insert (widget-get widget
:custom-prefix
)
3450 (if (widget-get widget
:custom-last
) " `--- " " |--- "))
3451 (push (widget-create-child-and-convert
3452 widget
'custom-browse-face-tag
)
3454 (insert " " tag
"\n")
3455 (widget-put widget
:buttons buttons
))
3457 ;; Draw an ordinary `custom-face' widget
3458 (let ((opoint (point)))
3459 ;; Visibility indicator.
3460 (push (widget-create-child-and-convert
3461 widget
'custom-visibility
3462 :help-echo
"Hide or show this face."
3463 :on
"Hide" :off
"Show"
3464 :on-glyph
"down" :off-glyph
"right"
3465 :action
'custom-toggle-hide-face
3470 (widget-specify-sample widget opoint
(point)))
3472 (cond ((eq custom-buffer-style
'face
) " ")
3473 ((string-match "face\\'" tag
) ":")
3477 (let ((sample-indent (widget-get widget
:sample-indent
))
3478 (indent-tabs-mode nil
))
3480 (<= (current-column) sample-indent
)
3481 (indent-to-column sample-indent
)))
3482 (push (widget-create-child-and-convert
3485 :sample-face
(let ((spec (widget-get widget
:shown-value
)))
3486 (if spec
(face-spec-choose spec
) symbol
))
3492 (unless (eq (widget-get widget
:custom-style
) 'simple
)
3493 (let ((magic (widget-create-child-and-convert
3494 widget
'custom-magic nil
)))
3495 (widget-put widget
:custom-magic magic
)
3496 (push magic buttons
)))
3499 (widget-put widget
:buttons buttons
)
3501 ;; Insert documentation.
3502 (unless (and hiddenp
(eq style
'simple
))
3503 (widget-put widget
:documentation-indent
3)
3504 (widget-add-documentation-string-button
3505 widget
:visibility-widget
'custom-visibility
)
3506 ;; The comment field
3508 (let* ((comment (get symbol
'face-comment
))
3510 (widget-create-child-and-convert
3511 widget
'custom-comment
3513 :value
(or comment
""))))
3514 (widget-put widget
:comment-widget comment-widget
)
3515 (push comment-widget children
))))
3518 (unless (eq (preceding-char) ?
\n)
3521 (custom-load-widget widget
)
3522 (unless (widget-get widget
:custom-form
)
3523 (widget-put widget
:custom-form custom-face-default-form
))
3525 (let* ((spec (or (widget-get widget
:shown-value
)
3526 (custom-face-get-current-spec symbol
)))
3527 (form (widget-get widget
:custom-form
))
3528 (indent (widget-get widget
:indent
))
3529 face-alist face-entry spec-default spec-match editor
)
3531 ;; Find a display in SPEC matching the selected display.
3532 ;; This will use the usual face customization interface.
3533 (setq face-alist spec
)
3534 (when (eq (car-safe (car-safe face-alist
)) 'default
)
3535 (setq spec-default
(pop face-alist
)))
3537 (while (and face-alist
(listp face-alist
) (null spec-match
))
3538 (setq face-entry
(car face-alist
))
3539 (and (listp face-entry
)
3540 (face-spec-set-match-display (car face-entry
)
3542 (widget-apply custom-face-edit
:match
(cadr face-entry
))
3543 (setq spec-match face-entry
))
3544 (setq face-alist
(cdr face-alist
)))
3546 ;; Insert the appropriate editing widget.
3549 ((and (eq form
'selected
)
3550 (or spec-match spec-default
))
3551 (when indent
(insert-char ?\s indent
))
3552 (widget-create-child-and-convert
3553 widget
'custom-face-edit
3554 :value
(cadr spec-match
)
3555 :default-face-attributes
(cadr spec-default
)))
3556 ((and (not (eq form
'lisp
))
3557 (widget-apply custom-face-all
:match spec
))
3558 (widget-create-child-and-convert
3559 widget
'custom-face-all
:value spec
))
3562 (insert-char ?\s indent
))
3563 (widget-create-child-and-convert
3564 widget
'sexp
:value spec
))))
3565 (custom-face-state-set widget
)
3566 (push editor children
)
3567 (widget-put widget
:children children
))))))
3569 (defvar custom-face-menu
3570 `(("Set for Current Session" custom-face-set
)
3571 ,@(when (or custom-file init-file-user
)
3572 '(("Save for Future Sessions" custom-face-save
)))
3573 ("Undo Edits" custom-redraw
3575 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3576 ("Revert This Session's Customization" custom-face-reset-saved
3578 (memq (widget-get widget
:custom-state
) '(modified set changed
))))
3579 ,@(when (or custom-file init-file-user
)
3580 '(("Erase Customization" custom-face-reset-standard
3582 (get (widget-value widget
) 'face-defface-spec
)))))
3583 ("---" ignore ignore
)
3584 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3585 ("---" ignore ignore
)
3586 ("For Current Display" custom-face-edit-selected
3588 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3589 ("For All Kinds of Displays" custom-face-edit-all
3591 (not (eq (widget-get widget
:custom-form
) 'all
))))
3592 ("Show Lisp Expression" custom-face-edit-lisp
3594 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3595 "Alist of actions for the `custom-face' widget.
3596 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3597 the menu entry, ACTION is the function to call on the widget when the
3598 menu is selected, and FILTER is a predicate which takes a `custom-face'
3599 widget as an argument, and returns non-nil if ACTION is valid on that
3600 widget. If FILTER is nil, ACTION is always valid.")
3602 (defun custom-face-edit-selected (widget)
3603 "Edit selected attributes of the value of WIDGET."
3604 (widget-put widget
:custom-state
'unknown
)
3605 (widget-put widget
:custom-form
'selected
)
3606 (custom-redraw widget
))
3608 (defun custom-face-edit-all (widget)
3609 "Edit all attributes of the value of WIDGET."
3610 (widget-put widget
:custom-state
'unknown
)
3611 (widget-put widget
:custom-form
'all
)
3612 (custom-redraw widget
))
3614 (defun custom-face-edit-lisp (widget)
3615 "Edit the Lisp representation of the value of WIDGET."
3616 (widget-put widget
:custom-state
'unknown
)
3617 (widget-put widget
:custom-form
'lisp
)
3618 (custom-redraw widget
))
3620 (defun custom-face-state (face)
3621 "Return the current state of the face FACE.
3622 This is one of `set', `saved', `changed', `themed', or `rogue'."
3623 (let* ((comment (get face
'face-comment
))
3626 ((or (get face
'customized-face
)
3627 (get face
'customized-face-comment
))
3628 (if (equal (get face
'customized-face-comment
) comment
)
3631 ((or (get face
'saved-face
)
3632 (get face
'saved-face-comment
))
3633 (cond ((not (equal (get face
'saved-face-comment
) comment
))
3635 ((eq 'user
(caar (get face
'theme-face
)))
3637 ((eq 'changed
(caar (get face
'theme-face
)))
3640 ((get face
'face-defface-spec
)
3641 (cond (comment 'changed
)
3642 ((get face
'theme-face
) 'themed
)
3645 ;; If the user called set-face-attribute to change the default for
3646 ;; new frames, this face is "set outside of Customize".
3647 (if (and (not (eq state
'rogue
))
3648 (get face
'face-modified
))
3652 (defun custom-face-state-set (widget)
3653 "Set the state of WIDGET."
3654 (widget-put widget
:custom-state
3655 (custom-face-state (widget-value widget
))))
3657 (defun custom-face-action (widget &optional event
)
3658 "Show the menu for `custom-face' WIDGET.
3659 Optional EVENT is the location for the menu."
3660 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3661 (custom-toggle-hide widget
)
3662 (let* ((completion-ignore-case t
)
3663 (symbol (widget-get widget
:value
))
3664 (answer (widget-choose (concat "Operation on "
3665 (custom-unlispify-tag-name symbol
))
3666 (custom-menu-filter custom-face-menu
3670 (funcall answer widget
)))))
3672 (defun custom-face-set (widget)
3673 "Make the face attributes in WIDGET take effect."
3674 (let* ((symbol (widget-value widget
))
3675 (value (custom-face-widget-to-spec widget
))
3676 (comment-widget (widget-get widget
:comment-widget
))
3677 (comment (widget-value comment-widget
)))
3678 (when (equal comment
"")
3680 ;; Make the comment invisible by hand if it's empty
3681 (custom-comment-hide comment-widget
))
3682 (put symbol
'customized-face value
)
3683 (custom-push-theme 'theme-face symbol
'user
'set value
)
3684 (if (face-spec-choose value
)
3685 (face-spec-set symbol value t
)
3686 ;; face-set-spec ignores empty attribute lists, so just give it
3687 ;; something harmless instead.
3688 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3689 (put symbol
'customized-face-comment comment
)
3690 (put symbol
'face-comment comment
)
3691 (custom-face-state-set widget
)
3692 (custom-redraw-magic widget
)))
3694 (defun custom-face-mark-to-save (widget)
3695 "Mark for saving the face edited by WIDGET."
3696 (let* ((symbol (widget-value widget
))
3697 (value (custom-face-widget-to-spec widget
))
3698 (comment-widget (widget-get widget
:comment-widget
))
3699 (comment (widget-value comment-widget
)))
3700 (when (equal comment
"")
3702 ;; Make the comment invisible by hand if it's empty
3703 (custom-comment-hide comment-widget
))
3704 (custom-push-theme 'theme-face symbol
'user
'set value
)
3705 (if (face-spec-choose value
)
3706 (face-spec-set symbol value t
)
3707 ;; face-set-spec ignores empty attribute lists, so just give it
3708 ;; something harmless instead.
3709 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3710 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3711 (put symbol
'saved-face value
))
3712 (put symbol
'customized-face nil
)
3713 (put symbol
'face-comment comment
)
3714 (put symbol
'customized-face-comment nil
)
3715 (put symbol
'saved-face-comment comment
)))
3717 (defsubst custom-face-state-set-and-redraw
(widget)
3718 "Set state of face widget WIDGET and redraw with current settings."
3719 (custom-face-state-set widget
)
3720 (custom-redraw-magic widget
))
3722 (defun custom-face-save (widget)
3723 "Save the face edited by WIDGET."
3724 (custom-face-mark-to-save widget
)
3726 (custom-face-state-set-and-redraw widget
))
3728 ;; For backward compatibility.
3729 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3732 (defun custom-face-reset-saved (widget)
3733 "Restore WIDGET to the face's default attributes.
3734 If there is a saved face, restore it; otherwise reset to the
3735 uncustomized (themed or standard) face."
3736 (let* ((face (widget-value widget
))
3737 (child (car (widget-get widget
:children
)))
3738 (saved-face (get face
'saved-face
))
3739 (comment (get face
'saved-face-comment
))
3740 (comment-widget (widget-get widget
:comment-widget
)))
3741 (put face
'customized-face nil
)
3742 (put face
'customized-face-comment nil
)
3743 (custom-push-theme 'theme-face face
'user
3744 (if saved-face
'set
'reset
)
3746 (face-spec-set face saved-face t
)
3747 (put face
'face-comment comment
)
3748 (widget-value-set child saved-face
)
3749 ;; This call manages the comment visibility
3750 (widget-value-set comment-widget
(or comment
""))
3751 (custom-face-state-set widget
)
3752 (custom-redraw widget
)))
3754 (defun custom-face-standard-value (widget)
3755 (get (widget-value widget
) 'face-defface-spec
))
3757 (defun custom-face-mark-to-reset-standard (widget)
3758 "Restore widget WIDGET to the face's standard attribute values.
3759 If `custom-reset-standard-faces-list' is nil, save, reset and
3760 redraw the widget immediately."
3761 (let* ((symbol (widget-value widget
))
3762 (child (car (widget-get widget
:children
)))
3763 (value (get symbol
'face-defface-spec
))
3764 (comment-widget (widget-get widget
:comment-widget
)))
3766 (user-error "No standard setting for this face"))
3767 (put symbol
'customized-face nil
)
3768 (put symbol
'customized-face-comment nil
)
3769 (custom-push-theme 'theme-face symbol
'user
'reset
)
3770 (face-spec-set symbol value t
)
3771 (custom-theme-recalc-face symbol
)
3772 (if (and custom-reset-standard-faces-list
3773 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3776 (put symbol
'saved-face nil
)
3777 (put symbol
'saved-face-comment nil
)
3778 ;; Append this to `custom-reset-standard-faces-list' and have
3779 ;; `custom-reset-standard-save-and-update' save setting to the
3780 ;; file, update the widget's state, and redraw it.
3781 (setq custom-reset-standard-faces-list
3782 (cons widget custom-reset-standard-faces-list
)))
3783 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3784 (put symbol
'saved-face nil
)
3785 (put symbol
'saved-face-comment nil
)
3787 (put symbol
'face-comment nil
)
3788 (widget-value-set child
3789 (custom-pre-filter-face-spec
3790 (list (list t
(custom-face-attributes-get
3792 ;; This call manages the comment visibility
3793 (widget-value-set comment-widget
"")
3794 (custom-face-state-set widget
)
3795 (custom-redraw-magic widget
))))
3797 (defun custom-face-reset-standard (widget)
3798 "Restore WIDGET to the face's standard attribute values.
3799 This operation eliminates any saved attributes for the face,
3800 restoring it to the state of a face that has never been customized."
3801 (let (custom-reset-standard-faces-list)
3802 (custom-face-mark-to-reset-standard widget
)))
3804 ;;; The `face' Widget.
3806 (defvar widget-face-prompt-value-history nil
3807 "History of input to `widget-face-prompt-value'.")
3809 (define-widget 'face
'symbol
3810 "A Lisp face name (with sample)."
3811 :format
"%{%t%}: (%{sample%}) %v"
3814 :sample-face-get
'widget-face-sample-face-get
3815 :notify
'widget-face-notify
3816 :match
(lambda (_widget value
) (facep value
))
3817 :completions
(apply-partially #'completion-table-with-predicate
3818 obarray
#'facep
'strict
)
3819 :prompt-match
'facep
3820 :prompt-history
'widget-face-prompt-value-history
3821 :validate
(lambda (widget)
3822 (unless (facep (widget-value widget
))
3824 :error
(format "Invalid face: %S"
3825 (widget-value widget
)))
3828 (defun widget-face-sample-face-get (widget)
3829 (let ((value (widget-value widget
)))
3834 (defun widget-face-notify (widget child
&optional event
)
3835 "Update the sample, and notify the parent."
3836 (overlay-put (widget-get widget
:sample-overlay
)
3837 'face
(widget-apply widget
:sample-face-get
))
3838 (widget-default-notify widget child event
))
3841 ;;; The `hook' Widget.
3843 (define-widget 'hook
'list
3844 "An Emacs Lisp hook."
3845 :value-to-internal
(lambda (_widget value
)
3846 (if (and value
(symbolp value
))
3849 :match
(lambda (widget value
)
3851 (widget-group-match widget value
)))
3852 ;; Avoid adding undefined functions to the hook, especially for
3853 ;; things like `find-file-hook' or even more basic ones, to avoid
3855 :set
(lambda (symbol value
)
3858 (add-hook symbol elt
))))
3859 :convert-widget
'custom-hook-convert-widget
3862 (defun custom-hook-convert-widget (widget)
3863 ;; Handle `:options'.
3864 (let* ((options (widget-get widget
:options
))
3865 (other `(editable-list :inline t
3866 :entry-format
"%i %d%v"
3867 (function :format
" %v")))
3869 (list `(checklist :inline t
3870 ,@(mapcar (lambda (entry)
3871 `(function-item ,entry
))
3875 (widget-put widget
:args args
)
3878 ;;; The `custom-group-link' Widget.
3880 (define-widget 'custom-group-link
'link
3881 "Show parent in other window when activated."
3882 :button-face
'custom-link
3883 :mouse-face
'highlight
3884 :pressed-face
'highlight
3885 :help-echo
"Create customization buffer for this group."
3886 :keymap custom-mode-link-map
3887 :follow-link
'mouse-face
3888 :action
'custom-group-link-action
)
3890 (defun custom-group-link-action (widget &rest _ignore
)
3891 (customize-group (widget-value widget
)))
3893 ;;; The `custom-group' Widget.
3895 (defcustom custom-group-tag-faces nil
3896 "Face used for group tags.
3897 The first member is used for level 1 groups, the second for level 2,
3898 and so forth. The remaining group tags are shown with `custom-group-tag'."
3899 :type
'(repeat face
)
3900 :group
'custom-faces
)
3902 (defface custom-group-tag-1
3903 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3904 (((class color
) (background dark
)) :foreground
"pink")
3905 (((min-colors 88) (class color
) (background light
)) :foreground
"red1")
3906 (((class color
) (background light
)) :foreground
"red"))
3907 "Face for group tags."
3908 :group
'custom-faces
)
3910 (defface custom-group-tag
3911 '((default :weight bold
:height
1.2 :inherit variable-pitch
)
3912 (((class color
) (background dark
)) :foreground
"light blue")
3913 (((min-colors 88) (class color
) (background light
)) :foreground
"blue1")
3914 (((class color
) (background light
)) :foreground
"blue")
3916 "Face for low level group tags."
3917 :group
'custom-faces
)
3919 (defface custom-group-subtitle
3921 "Face for the \"Subgroups:\" subtitle in Custom buffers."
3922 :group
'custom-faces
)
3924 (defvar custom-group-doc-align-col
20)
3926 (define-widget 'custom-group
'custom
3929 :sample-face-get
'custom-group-sample-face-get
3930 :documentation-property
'group-documentation
3931 :help-echo
"Set or reset all members of this group."
3932 :value-create
'custom-group-value-create
3933 :action
'custom-group-action
3934 :custom-category
'group
3935 :custom-set
'custom-group-set
3936 :custom-mark-to-save
'custom-group-mark-to-save
3937 :custom-reset-current
'custom-group-reset-current
3938 :custom-reset-saved
'custom-group-reset-saved
3939 :custom-reset-standard
'custom-group-reset-standard
3940 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3941 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3942 :custom-menu
'custom-group-menu-create
)
3944 (defun custom-group-sample-face-get (widget)
3945 ;; Use :sample-face.
3946 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3949 (define-widget 'custom-group-visibility
'visibility
3950 "An indicator and manipulator for hidden group contents."
3951 :create
'custom-group-visibility-create
)
3953 (defun custom-group-visibility-create (widget)
3954 (let ((visible (widget-value widget
)))
3956 (insert "--------")))
3957 (widget-default-create widget
))
3959 (defun custom-group-members (symbol groups-only
)
3960 "Return SYMBOL's custom group members.
3961 If GROUPS-ONLY non-nil, return only those members that are groups."
3962 (if (not groups-only
)
3963 (get symbol
'custom-group
)
3965 (dolist (entry (get symbol
'custom-group
))
3966 (when (eq (nth 1 entry
) 'custom-group
)
3967 (push entry members
)))
3968 (nreverse members
))))
3970 (defun custom-group-value-create (widget)
3971 "Insert a customize group for WIDGET in the current buffer."
3972 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3973 (custom-load-widget widget
))
3974 (let* ((state (widget-get widget
:custom-state
))
3975 (level (widget-get widget
:custom-level
))
3976 ;; (indent (widget-get widget :indent))
3977 (prefix (widget-get widget
:custom-prefix
))
3978 (buttons (widget-get widget
:buttons
))
3979 (tag (widget-get widget
:tag
))
3980 (symbol (widget-value widget
))
3981 (members (custom-group-members symbol
3982 (and (eq custom-buffer-style
'tree
)
3983 custom-browse-only-groups
)))
3984 (doc (widget-docstring widget
)))
3985 (cond ((and (eq custom-buffer-style
'tree
)
3987 (or members
(custom-unloaded-widget-p widget
)))
3988 (custom-browse-insert-prefix prefix
)
3989 (push (widget-create-child-and-convert
3990 widget
'custom-browse-visibility
3994 (push (widget-create-child-and-convert
3995 widget
'custom-browse-group-tag
)
3997 (insert " " tag
"\n")
3998 (widget-put widget
:buttons buttons
))
3999 ((and (eq custom-buffer-style
'tree
)
4000 (zerop (length members
)))
4001 (custom-browse-insert-prefix prefix
)
4003 (push (widget-create-child-and-convert
4004 widget
'custom-browse-group-tag
)
4006 (insert " " tag
"\n")
4007 (widget-put widget
:buttons buttons
))
4008 ((eq custom-buffer-style
'tree
)
4009 (custom-browse-insert-prefix prefix
)
4010 (if (zerop (length members
))
4012 (custom-browse-insert-prefix prefix
)
4014 ;; (widget-glyph-insert nil "[ ]" "empty")
4015 ;; (widget-glyph-insert nil "-- " "horizontal")
4016 (push (widget-create-child-and-convert
4017 widget
'custom-browse-group-tag
)
4019 (insert " " tag
"\n")
4020 (widget-put widget
:buttons buttons
))
4021 (push (widget-create-child-and-convert
4022 widget
'custom-browse-visibility
4023 ;; :tag-glyph "minus"
4027 ;; (widget-glyph-insert nil "-\\ " "top")
4028 (push (widget-create-child-and-convert
4029 widget
'custom-browse-group-tag
)
4031 (insert " " tag
"\n")
4032 (widget-put widget
:buttons buttons
)
4033 (message "Creating group...")
4034 (let* ((members (custom-sort-items
4036 ;; Never sort the top-level custom group.
4037 (unless (eq symbol
'emacs
)
4038 custom-browse-sort-alphabetically
)
4039 custom-browse-order-groups
))
4040 (prefixes (widget-get widget
:custom-prefixes
))
4041 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4042 (extra-prefix (if (widget-get widget
:custom-last
)
4045 (prefix (concat prefix extra-prefix
))
4048 (setq entry
(car members
)
4049 members
(cdr members
))
4050 (push (widget-create-child-and-convert
4051 widget
(nth 1 entry
)
4053 :tag
(custom-unlispify-tag-name (nth 0 entry
))
4054 :custom-prefixes custom-prefix-list
4055 :custom-level
(1+ level
)
4056 :custom-last
(null members
)
4057 :value
(nth 0 entry
)
4058 :custom-prefix prefix
)
4060 (widget-put widget
:children
(reverse children
)))
4061 (message "Creating group...done")))
4064 ;; Create level indicator.
4066 (if (eq custom-buffer-style
'links
)
4067 (push (widget-create-child-and-convert
4068 widget
'custom-group-link
4072 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4074 (push (widget-create-child-and-convert
4075 widget
'custom-group-visibility
4076 :help-echo
"Show members of this group."
4077 :action
'custom-toggle-parent
4078 (not (eq state
'hidden
)))
4080 (if (>= (current-column) custom-group-doc-align-col
)
4082 ;; Create magic button.
4083 (let ((magic (widget-create-child-and-convert
4084 widget
'custom-magic nil
)))
4085 (widget-put widget
:custom-magic magic
)
4086 (push magic buttons
))
4088 (widget-put widget
:buttons buttons
)
4089 ;; Insert documentation.
4090 (if (and (eq custom-buffer-style
'links
) (> level
1))
4091 (widget-put widget
:documentation-indent
4092 custom-group-doc-align-col
))
4093 (widget-add-documentation-string-button
4094 widget
:visibility-widget
'custom-visibility
))
4098 ;; Draw a horizontal line (this works for both graphical
4099 ;; and text displays):
4102 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4103 (overlay-put (make-overlay p
(1+ p
))
4105 (propertize "\n" 'face
'(:underline t
)
4106 'display
'(space :align-to
999))))
4108 ;; Add parent groups references above the group.
4110 (if (custom-add-parent-links widget
"Parent groups:")
4112 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4114 (let ((start (point)))
4115 (insert tag
" group: ")
4116 (widget-specify-sample widget start
(point)))
4119 (insert " Group definition missing. "))
4120 ((< (length doc
) 50)
4122 ;; Create visibility indicator.
4123 (unless (eq custom-buffer-style
'links
)
4125 (push (widget-create-child-and-convert
4127 :help-echo
"Hide members of this group."
4128 :action
'custom-toggle-parent
4129 (not (eq state
'hidden
)))
4133 ;; Create magic button.
4134 (let ((magic (widget-create-child-and-convert
4135 widget
'custom-magic
4138 (widget-put widget
:custom-magic magic
)
4139 (push magic buttons
))
4141 (widget-put widget
:buttons buttons
)
4142 ;; Insert documentation.
4143 (when (and doc
(>= (length doc
) 50))
4144 (widget-add-documentation-string-button
4145 widget
:visibility-widget
'custom-visibility
))
4148 (if nil
;;; This should test that the buffer
4149 ;;; was not made to display a group.
4151 (insert-char ?\ custom-buffer-indent
)
4152 (custom-add-parent-links widget
)))
4153 (custom-add-see-also widget
4154 (make-string (* custom-buffer-indent level
)
4157 (message "Creating group...")
4158 (let* ((members (custom-sort-items
4160 ;; Never sort the top-level custom group.
4161 (unless (eq symbol
'emacs
)
4162 custom-buffer-sort-alphabetically
)
4163 custom-buffer-order-groups
))
4164 (prefixes (widget-get widget
:custom-prefixes
))
4165 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4166 (len (length members
))
4168 (reporter (make-progress-reporter
4169 "Creating group entries..." 0 len
))
4170 (have-subtitle (and (not (eq symbol
'emacs
))
4171 (eq custom-buffer-order-groups
'last
)))
4175 (dolist (entry members
)
4176 (unless (eq prev-type
'custom-group
)
4177 (widget-insert "\n"))
4178 (progress-reporter-update reporter
(setq count
(1+ count
)))
4179 (let ((sym (nth 0 entry
))
4180 (type (nth 1 entry
)))
4181 (when (and have-subtitle
(eq type
'custom-group
))
4182 (setq have-subtitle nil
)
4184 (propertize "Subgroups:\n" 'face
'custom-group-subtitle
)))
4185 (setq prev-type type
)
4186 (push (widget-create-child-and-convert
4189 :tag
(custom-unlispify-tag-name sym
)
4190 :custom-prefixes custom-prefix-list
4191 :custom-level
(1+ level
)
4194 (unless (eq (preceding-char) ?
\n)
4195 (widget-insert "\n"))))
4197 (setq children
(nreverse children
))
4198 (mapc 'custom-magic-reset children
)
4199 (widget-put widget
:children children
)
4200 (custom-group-state-update widget
)
4201 (progress-reporter-done reporter
))
4203 (let ((p (1+ (point))))
4205 (put-text-property p
(1+ p
) 'face
'(:underline t
))
4206 (overlay-put (make-overlay p
(1+ p
))
4208 (propertize "\n" 'face
'(:underline t
)
4209 'display
'(space :align-to
999))))))))
4211 (defvar custom-group-menu
4212 `(("Set for Current Session" custom-group-set
4214 (eq (widget-get widget
:custom-state
) 'modified
)))
4215 ,@(when (or custom-file init-file-user
)
4216 '(("Save for Future Sessions" custom-group-save
4218 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4219 ("Undo Edits" custom-group-reset-current
4221 (memq (widget-get widget
:custom-state
) '(modified))))
4222 ("Revert This Session's Customizations" custom-group-reset-saved
4224 (memq (widget-get widget
:custom-state
) '(modified set
))))
4225 ,@(when (or custom-file init-file-user
)
4226 '(("Erase Customization" custom-group-reset-standard
4228 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4229 "Alist of actions for the `custom-group' widget.
4230 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4231 the menu entry, ACTION is the function to call on the widget when the
4232 menu is selected, and FILTER is a predicate which takes a `custom-group'
4233 widget as an argument, and returns non-nil if ACTION is valid on that
4234 widget. If FILTER is nil, ACTION is always valid.")
4236 (defun custom-group-action (widget &optional event
)
4237 "Show the menu for `custom-group' WIDGET.
4238 Optional EVENT is the location for the menu."
4239 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4240 (custom-toggle-hide widget
)
4241 (let* ((completion-ignore-case t
)
4242 (answer (widget-choose (concat "Operation on "
4243 (custom-unlispify-tag-name
4244 (widget-get widget
:value
)))
4245 (custom-menu-filter custom-group-menu
4249 (funcall answer widget
)))))
4251 (defun custom-group-set (widget)
4252 "Set changes in all modified group members."
4253 (dolist (child (widget-get widget
:children
))
4254 (when (eq (widget-get child
:custom-state
) 'modified
)
4255 (widget-apply child
:custom-set
))))
4257 (defun custom-group-mark-to-save (widget)
4258 "Mark all modified group members for saving."
4259 (dolist (child (widget-get widget
:children
))
4260 (when (memq (widget-get child
:custom-state
) '(modified set
))
4261 (widget-apply child
:custom-mark-to-save
))))
4263 (defsubst custom-group-state-set-and-redraw
(widget)
4264 "Set state of group widget WIDGET and redraw with current settings."
4265 (dolist (child (widget-get widget
:children
))
4266 (when (memq (widget-get child
:custom-state
) '(modified set
))
4267 (widget-apply child
:custom-state-set-and-redraw
))))
4269 (defun custom-group-save (widget)
4270 "Save all modified group members."
4271 (custom-group-mark-to-save widget
)
4273 (custom-group-state-set-and-redraw widget
))
4275 (defun custom-group-reset-current (widget)
4276 "Reset all modified group members."
4277 (dolist (child (widget-get widget
:children
))
4278 (when (eq (widget-get child
:custom-state
) 'modified
)
4279 (widget-apply child
:custom-reset-current
))))
4281 (defun custom-group-reset-saved (widget)
4282 "Reset all modified or set group members."
4283 (dolist (child (widget-get widget
:children
))
4284 (when (memq (widget-get child
:custom-state
) '(modified set
))
4285 (widget-apply child
:custom-reset-saved
))))
4287 (defun custom-group-reset-standard (widget)
4288 "Reset all modified, set, or saved group members."
4289 (let ((custom-reset-standard-variables-list '(t))
4290 (custom-reset-standard-faces-list '(t)))
4291 (custom-group-mark-to-reset-standard widget
)
4292 (custom-reset-standard-save-and-update)))
4294 (defun custom-group-mark-to-reset-standard (widget)
4295 "Mark to reset all modified, set, or saved group members."
4296 (dolist (child (widget-get widget
:children
))
4297 (when (memq (widget-get child
:custom-state
)
4298 '(modified set saved
))
4299 (widget-apply child
:custom-mark-to-reset-standard
))))
4301 (defun custom-group-state-update (widget)
4303 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4304 (let* ((children (widget-get widget
:children
))
4305 (states (mapcar (lambda (child)
4306 (widget-get child
:custom-state
))
4308 (magics custom-magic-alist
)
4311 (let ((magic (car (car magics
))))
4312 (if (and (not (eq magic
'hidden
))
4313 (memq magic states
))
4316 (setq magics
(cdr magics
)))))
4317 (widget-put widget
:custom-state found
)))
4318 (custom-magic-reset widget
))
4320 ;;; Reading and writing the custom file.
4323 (defcustom custom-file nil
4324 "File used for storing customization information.
4325 The default is nil, which means to use your init file
4326 as specified by `user-init-file'. If the value is not nil,
4327 it should be an absolute file name.
4329 You can set this option through Custom, if you carefully read the
4330 last paragraph below. However, usually it is simpler to write
4331 something like the following in your init file:
4333 \(setq custom-file \"~/.emacs-custom.el\")
4336 Note that both lines are necessary: the first line tells Custom to
4337 save all customizations in this file, but does not load it.
4339 When you change this variable outside Custom, look in the
4340 previous custom file \(usually your init file) for the
4341 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4342 and copy them (whichever ones you find) to the new custom file.
4343 This will preserve your existing customizations.
4345 If you save this option using Custom, Custom will write all
4346 currently saved customizations, including the new one for this
4347 option itself, into the file you specify, overwriting any
4348 `custom-set-variables' and `custom-set-faces' forms already
4349 present in that file. It will not delete any customizations from
4350 the old custom file. You should do that manually if that is what you
4351 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4352 in your init file, where CUSTOM-FILE is the actual name of the
4353 file. Otherwise, Emacs will not load the file when it starts up,
4354 and hence will not set `custom-file' to that file either."
4355 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4356 (file :format
"%t:%v%d"
4358 "Please read entire docstring below before setting \
4359 this through Custom.
4360 Click on \"More\" \(or position point there and press RETURN)
4361 if only the first line of the docstring is shown."))
4364 (defun custom-file (&optional no-error
)
4365 "Return the file name for saving customizations."
4366 (if (null user-init-file
)
4367 ;; Started with -q, i.e. the file containing Custom settings
4368 ;; hasn't been read. Saving settings there won't make much
4372 (user-error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4373 (file-chase-links (or custom-file user-init-file
))))
4375 ;; If recentf-mode is non-nil, this is defined.
4376 (declare-function recentf-expand-file-name
"recentf" (name))
4379 (defun custom-save-all ()
4380 "Save all customizations in `custom-file'."
4381 (when (and (null custom-file
) init-file-had-error
)
4382 (error "Cannot save customizations; init file was not fully loaded"))
4383 (let* ((filename (custom-file))
4388 (recentf-expand-file-name (custom-file)))
4391 (old-buffer (find-buffer-visiting filename
))
4394 (with-current-buffer (let ((find-file-visit-truename t
))
4395 (or old-buffer
(find-file-noselect filename
)))
4396 ;; We'll save using file-precious-flag, so avoid destroying
4397 ;; symlinks. (If we're not already visiting the buffer, this is
4398 ;; handled by find-file-visit-truename, above.)
4400 (setq old-buffer-name
(buffer-file-name))
4401 (set-visited-file-name (file-chase-links filename
)))
4403 (unless (eq major-mode
'emacs-lisp-mode
)
4405 (let ((inhibit-read-only t
)
4408 (custom-save-variables)
4409 (custom-save-faces))
4410 (let ((file-precious-flag t
))
4414 (set-visited-file-name old-buffer-name
)
4415 (set-buffer-modified-p nil
))
4416 (kill-buffer (current-buffer))))))
4419 (defun customize-save-customized ()
4420 "Save all user options which have been set in this session."
4422 (mapatoms (lambda (symbol)
4423 (let ((face (get symbol
'customized-face
))
4424 (value (get symbol
'customized-value
))
4425 (face-comment (get symbol
'customized-face-comment
))
4427 (get symbol
'customized-variable-comment
)))
4429 (put symbol
'saved-face face
)
4430 (custom-push-theme 'theme-face symbol
'user
'set value
)
4431 (put symbol
'customized-face nil
))
4433 (put symbol
'saved-value value
)
4434 (custom-push-theme 'theme-value symbol
'user
'set value
)
4435 (put symbol
'customized-value nil
))
4436 (when variable-comment
4437 (put symbol
'saved-variable-comment variable-comment
)
4438 (put symbol
'customized-variable-comment nil
))
4440 (put symbol
'saved-face-comment face-comment
)
4441 (put symbol
'customized-face-comment nil
)))))
4442 ;; We really should update all custom buffers here.
4445 ;; Editing the custom file contents in a buffer.
4447 (defun custom-save-delete (symbol)
4448 "Delete all calls to SYMBOL from the contents of the current buffer.
4449 Leave point at the old location of the first such call,
4450 or (if there were none) at the end of the buffer.
4452 This function does not save the buffer."
4453 (goto-char (point-min))
4454 ;; Skip all whitespace and comments.
4455 (while (forward-comment 1))
4457 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4460 (while t
;; We exit this loop only via throw.
4461 ;; Skip all whitespace and comments.
4462 (while (forward-comment 1))
4463 (let ((start (point))
4464 (sexp (condition-case nil
4465 (read (current-buffer))
4466 (end-of-file (throw 'found nil
)))))
4467 (when (and (listp sexp
)
4468 (eq (car sexp
) symbol
))
4469 (delete-region start
(point))
4471 (setq first
(point)))))))
4474 ;; Move in front of local variables, otherwise long Custom
4475 ;; entries would make them ineffective.
4476 (let ((pos (point-max))
4477 (case-fold-search t
))
4479 (goto-char (point-max))
4480 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4482 (when (search-forward "Local Variables:" nil t
)
4483 (setq pos
(line-beginning-position))))
4486 (defvar sort-fold-case
) ; defined in sort.el
4488 (defun custom-save-variables ()
4489 "Save all customized variables in `custom-file'."
4491 (custom-save-delete 'custom-set-variables
)
4492 (let ((standard-output (current-buffer))
4493 (saved-list (make-list 1 0))
4495 ;; First create a sorted list of saved variables.
4498 (if (and (get symbol
'saved-value
)
4499 ;; ignore theme values
4500 (or (null (get symbol
'theme-value
))
4501 (eq 'user
(caar (get symbol
'theme-value
)))))
4502 (nconc saved-list
(list symbol
)))))
4503 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4506 (princ "(custom-set-variables
4507 ;; custom-set-variables was added by Custom.
4508 ;; If you edit it by hand, you could mess it up, so be careful.
4509 ;; Your init file should contain only one such instance.
4510 ;; If there is more than one, they won't work right.\n")
4511 (dolist (symbol saved-list
)
4512 (let ((spec (car-safe (get symbol
'theme-value
)))
4513 (value (get symbol
'saved-value
))
4514 (requests (get symbol
'custom-requests
))
4515 (now (and (not (custom-variable-p symbol
))
4517 (eq (get symbol
'force-value
)
4519 (comment (get symbol
'saved-variable-comment
)))
4520 ;; Check REQUESTS for validity.
4521 (dolist (request requests
)
4522 (when (and (symbolp request
) (not (featurep request
)))
4523 (message "Unknown requested feature: %s" request
)
4524 (setq requests
(delq request requests
))))
4525 ;; Is there anything customized about this variable?
4526 (when (or (and spec
(eq (car spec
) 'user
))
4528 (and (null spec
) (get symbol
'saved-value
)))
4529 ;; Output an element for this variable.
4530 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4531 ;; SYMBOL is the variable name.
4532 ;; VALUE-FORM is an expression to return the customized value.
4533 ;; NOW if non-nil means always set the variable immediately
4534 ;; when the customizations are reloaded. This is used
4535 ;; for rogue variables
4536 ;; REQUESTS is a list of packages to load before setting the
4537 ;; variable. Each element of it will be passed to `require'.
4538 ;; COMMENT is whatever comment the user has specified
4539 ;; with the customize facility.
4546 (when (or now requests comment
)
4549 (when (or requests comment
)
4559 (unless (looking-at "\n")
4562 (defun custom-save-faces ()
4563 "Save all customized faces in `custom-file'."
4565 (custom-save-delete 'custom-reset-faces
)
4566 (custom-save-delete 'custom-set-faces
)
4567 (let ((standard-output (current-buffer))
4568 (saved-list (make-list 1 0))
4570 ;; First create a sorted list of saved faces.
4573 (if (and (get symbol
'saved-face
)
4574 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4575 (nconc saved-list
(list symbol
)))))
4576 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4577 ;; The default face must be first, since it affects the others.
4578 (if (memq 'default saved-list
)
4579 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4582 (princ "(custom-set-faces
4583 ;; custom-set-faces was added by Custom.
4584 ;; If you edit it by hand, you could mess it up, so be careful.
4585 ;; Your init file should contain only one such instance.
4586 ;; If there is more than one, they won't work right.\n")
4587 (dolist (symbol saved-list
)
4588 (let ((spec (car-safe (get symbol
'theme-face
)))
4589 (value (get symbol
'saved-face
))
4590 (now (not (or (get symbol
'face-defface-spec
)
4591 (and (not (custom-facep symbol
))
4592 (not (get symbol
'force-face
))))))
4593 (comment (get symbol
'saved-face-comment
)))
4594 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4596 (and (null spec
) (get symbol
'saved-face
)))
4597 ;; Don't print default face here.
4604 (when (or now comment
)
4614 (unless (looking-at "\n")
4617 ;;; The Customize Menu.
4621 (defcustom custom-menu-nesting
2
4622 "Maximum nesting in custom menus."
4624 :group
'custom-menu
)
4626 (defun custom-face-menu-create (_widget symbol
)
4627 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4628 (vector (custom-unlispify-menu-entry symbol
)
4629 `(customize-face ',symbol
)
4632 (defun custom-variable-menu-create (_widget symbol
)
4633 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4634 (let ((type (get symbol
'custom-type
)))
4635 (unless (listp type
)
4636 (setq type
(list type
)))
4637 (if (and type
(widget-get type
:custom-menu
))
4638 (widget-apply type
:custom-menu symbol
)
4639 (vector (custom-unlispify-menu-entry symbol
)
4640 `(customize-variable ',symbol
)
4643 ;; Add checkboxes to boolean variable entries.
4644 (widget-put (get 'boolean
'widget-type
)
4645 :custom-menu
(lambda (_widget symbol
)
4646 (vector (custom-unlispify-menu-entry symbol
)
4647 `(customize-variable ',symbol
)
4649 ':selected symbol
)))
4651 (defun custom-group-menu-create (_widget symbol
)
4652 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4653 `( ,(custom-unlispify-menu-entry symbol t
)
4654 :filter
(lambda (&rest junk
)
4655 (let* ((menu (custom-menu-create ',symbol
)))
4656 (if (consp menu
) (cdr menu
) menu
)))))
4659 (defun custom-menu-create (symbol)
4660 "Create menu for customization group SYMBOL.
4661 The menu is in a format applicable to `easy-menu-define'."
4662 (let* ((deactivate-mark nil
)
4663 (item (vector (custom-unlispify-menu-entry symbol
)
4664 `(customize-group ',symbol
)
4666 (if (and (or (not (boundp 'custom-menu-nesting
))
4667 (>= custom-menu-nesting
0))
4669 (custom-load-symbol symbol
)
4670 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4671 (let ((custom-prefix-list (custom-prefix-add symbol
4672 custom-prefix-list
))
4673 (members (custom-sort-items (get symbol
'custom-group
)
4674 custom-menu-sort-alphabetically
4675 custom-menu-order-groups
)))
4676 `(,(custom-unlispify-menu-entry symbol t
)
4679 ,@(mapcar (lambda (entry)
4680 (widget-apply (if (listp (nth 1 entry
))
4682 (list (nth 1 entry
)))
4683 :custom-menu
(nth 0 entry
)))
4688 (defun customize-menu-create (symbol &optional name
)
4689 "Return a customize menu for customization group SYMBOL.
4690 If optional NAME is given, use that as the name of the menu.
4691 Otherwise the menu will be named `Customize'.
4692 The format is suitable for use with `easy-menu-define'."
4694 (setq name
"Customize"))
4696 :filter
(lambda (&rest junk
)
4697 (let ((menu (custom-menu-create ',symbol
)))
4698 (if (consp menu
) (cdr menu
) menu
)))))
4700 ;;; Toolbar and menubar support
4703 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4704 "Menu used in customization buffers."
4705 (nconc (list "Custom"
4706 (customize-menu-create 'customize
))
4707 (mapcar (lambda (arg)
4708 (let ((tag (nth 0 arg
))
4709 (command (nth 1 arg
))
4710 (active (nth 2 arg
))
4712 (vector tag command
:active
(eval active
) :help help
)))
4715 (defvar tool-bar-map
)
4717 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4718 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4719 ;;; we set this up lazily in `Custom-mode'.
4720 (defvar custom-tool-bar-map nil
4721 "Keymap for toolbar in Custom mode.")
4723 ;;; The Custom Mode.
4725 (defun Custom-no-edit (_pos &optional _event
)
4726 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4728 (error "You can't edit this part of the Custom buffer"))
4730 (defun Custom-newline (pos &optional event
)
4731 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4733 (let ((button (get-char-property pos
'button
)))
4734 ;; If there is no button at point, then use the one at the start
4735 ;; of the line, if it is a custom-group-link (bug#2298).
4737 (if (setq button
(get-char-property (line-beginning-position) 'button
))
4738 (or (eq (widget-type button
) 'custom-group-link
)
4739 (setq button nil
))))
4741 (widget-apply-action button event
)
4742 (error "You can't edit this part of the Custom buffer"))))
4744 (defun Custom-goto-parent ()
4745 "Go to the parent group listed at the top of this buffer.
4746 If several parents are listed, go to the first of them."
4749 (goto-char (point-min))
4750 (if (search-forward "\nParent groups: " nil t
)
4751 (let* ((button (get-char-property (point) 'button
))
4752 (parent (downcase (widget-get button
:tag
))))
4753 (customize-group parent
)))))
4755 (defcustom Custom-mode-hook nil
4756 "Hook called when entering Custom mode."
4758 :group
'custom-buffer
)
4760 (defun custom-state-buffer-message (widget)
4761 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4762 (message "To install your edits, invoke [State] and choose the Set operation")))
4764 (defun custom--initialize-widget-variables ()
4765 (set (make-local-variable 'widget-documentation-face
) 'custom-documentation
)
4766 (set (make-local-variable 'widget-button-face
) custom-button
)
4767 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4768 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4769 ;; We need this because of the "More" button on docstrings.
4770 ;; Otherwise clicking on "More" can push point offscreen, which
4771 ;; causes the window to recenter on point, which pushes the
4772 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4773 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4774 ;; When possible, use relief for buttons, not bracketing. This test
4775 ;; may not be optimal.
4776 (when custom-raised-buttons
4777 (set (make-local-variable 'widget-push-button-prefix
) "")
4778 (set (make-local-variable 'widget-push-button-suffix
) "")
4779 (set (make-local-variable 'widget-link-prefix
) "")
4780 (set (make-local-variable 'widget-link-suffix
) ""))
4781 (setq show-trailing-whitespace nil
))
4783 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4784 (define-derived-mode Custom-mode nil
"Custom"
4785 "Major mode for editing customization buffers.
4787 The following commands are available:
4790 Move to next button, link or editable field. \\[widget-forward]
4791 Move to previous button, link or editable field. \\[widget-backward]
4792 \\<custom-field-keymap>\
4793 Complete content of editable text field. \\[widget-complete]
4794 \\<custom-mode-map>\
4795 Invoke button under the mouse pointer. \\[widget-button-click]
4796 Invoke button under point. \\[widget-button-press]
4797 Set all options from current text. \\[Custom-set]
4798 Make values in current text permanent. \\[Custom-save]
4799 Make text match actual option values. \\[Custom-reset-current]
4800 Reset options to permanent settings. \\[Custom-reset-saved]
4801 Erase customizations; set options
4802 and buffer text to the standard values. \\[Custom-reset-standard]
4804 Entry to this mode calls the value of `Custom-mode-hook'
4805 if that value is non-nil."
4806 (use-local-map custom-mode-map
)
4807 (easy-menu-add Custom-mode-menu
)
4808 (set (make-local-variable 'tool-bar-map
)
4809 (or custom-tool-bar-map
4810 ;; Set up `custom-tool-bar-map'.
4811 (let ((map (make-sparse-keymap)))
4814 (tool-bar-local-item-from-menu
4815 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
4816 :label
(nth 5 arg
)))
4818 (setq custom-tool-bar-map map
))))
4819 (make-local-variable 'custom-options
)
4820 (make-local-variable 'custom-local-buffer
)
4821 (custom--initialize-widget-variables)
4822 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4824 (put 'Custom-mode
'mode-class
'special
)
4826 (define-obsolete-function-alias 'custom-mode
'Custom-mode
"23.1")
4828 (add-to-list 'debug-ignored-errors
"^Invalid face:? ")
4834 ;;; cus-edit.el ends here