1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; 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."
170 "Abbreviation handling, typing shortcuts, macros."
174 (defgroup matching nil
175 "Various sorts of searching and matching."
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link
'(custom-manual "(emacs)Emulation")
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
191 (defgroup external nil
192 "Interfacing to external utilities."
195 (defgroup processes nil
196 "Process, subshell, compilation, and job control support."
200 (defgroup convenience nil
201 "Convenience features for faster editing."
204 (defgroup programming nil
205 "Support for programming in other languages."
208 (defgroup languages nil
209 "Specialized modes for editing programming languages."
213 "Lisp support, including Emacs Lisp."
214 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
219 "Support for the C language and related languages."
220 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 :link
'(custom-manual "(ccmode)")
229 "Support for object-oriented programming."
232 (defgroup applications nil
233 "Applications written in Emacs."
236 (defgroup calendar nil
237 "Calendar and time management support."
238 :group
'applications
)
241 "Modes for electronic-mail handling."
242 :group
'applications
)
245 "Support for netnews reading and posting."
246 :link
'(custom-manual "(gnus)")
247 :group
'applications
)
250 "Games, jokes and amusements."
251 :group
'applications
)
253 (defgroup development nil
254 "Support for further development of Emacs."
258 "Support for Emacs documentation."
261 (defgroup extensions nil
262 "Emacs Lisp language extensions."
265 (defgroup internal nil
266 "Code for Emacs internals, build process, defaults."
270 "Maintenance aids for the Emacs development group."
274 (defgroup environment nil
275 "Fitting Emacs with its environment."
279 "Communications, networking, remote access to files."
283 (defgroup hardware nil
284 "Support for interfacing with exotic hardware."
287 (defgroup terminals nil
288 "Support for terminal types."
292 "Front-ends/assistants for, or emulators of, UNIX features."
296 "Internationalization and alternate character-set support."
297 :link
'(custom-manual "(emacs)International")
302 "The X Window system."
306 "Support for Emacs frames and window systems."
310 "Support editing files of data."
314 "Support editing files."
322 "Code related to the TeX formatter."
323 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
327 "Support for multiple fonts."
330 (defgroup hypermedia nil
331 "Support for links between text or other media types."
335 "Support for on-line help systems."
338 (defgroup multimedia nil
339 "Non-textual support, specifically images and sound."
343 "Code local to your site."
346 (defgroup customize
'((widgets custom-group
))
347 "Customization of the Customization support."
351 (defgroup custom-faces nil
352 "Faces used by customize."
356 (defgroup custom-browse nil
357 "Control customize browser."
361 (defgroup custom-buffer nil
362 "Control customize buffers."
366 (defgroup custom-menu nil
367 "Control customize menus."
372 "Storage allocation and gc for GNU Emacs Lisp interpreter."
373 :tag
"Storage Allocation"
377 "Undoing changes in buffers."
378 :link
'(custom-manual "(emacs)Undo")
381 (defgroup mode-line nil
382 "Content of the modeline."
385 (defgroup editing-basics nil
386 "Most basic editing facilities."
389 (defgroup display nil
390 "How characters are displayed in buffers."
393 (defgroup execute nil
394 "Executing external commands."
397 (defgroup installation nil
398 "The Emacs installation."
406 "Internal Emacs limits."
410 "Debugging Emacs itself."
413 (defgroup keyboard nil
414 "Input from the keyboard."
418 "Input from the mouse."
422 "Input from the menus."
426 "Handling data from drag and drop."
429 (defgroup auto-save nil
430 "Preventing accidental loss of data."
433 (defgroup processes-basics nil
434 "Basic stuff dealing with processes."
438 "MULE Emacs internationalization."
441 (defgroup windows nil
442 "Windows within a frame."
443 :link
'(custom-manual "(emacs)Windows")
446 ;;; Custom mode keymaps
448 (defvar custom-mode-map
449 ;; This keymap should be dense, but a dense keymap would prevent inheriting
450 ;; "\r" bindings from the parent map.
451 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
452 (let ((map (make-keymap)))
453 (set-keymap-parent map widget-keymap
)
454 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
455 (define-key map
"\^m" 'Custom-newline
)
456 (define-key map
" " 'scroll-up
)
457 (define-key map
"\177" 'scroll-down
)
458 (define-key map
"\C-c\C-c" 'Custom-set
)
459 (define-key map
"\C-x\C-s" 'Custom-save
)
460 (define-key map
"q" 'Custom-buffer-done
)
461 (define-key map
"u" 'Custom-goto-parent
)
462 (define-key map
"n" 'widget-forward
)
463 (define-key map
"p" 'widget-backward
)
465 "Keymap for `Custom-mode'.")
467 (defvar custom-mode-link-map
468 (let ((map (make-keymap)))
469 (set-keymap-parent map custom-mode-map
)
470 (define-key map
[down-mouse-2
] nil
)
471 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
472 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
474 "Local keymap for links in `Custom-mode'.")
476 (defvar custom-field-keymap
477 (let ((map (copy-keymap widget-field-keymap
)))
478 (define-key map
"\C-c\C-c" 'Custom-set
)
479 (define-key map
"\C-x\C-s" 'Custom-save
)
481 "Keymap used inside editable fields in customization buffers.")
483 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
487 (defun custom-split-regexp-maybe (regexp)
488 "If REGEXP is a string, split it to a list at `\\|'.
489 You can get the original back from the result with:
490 (mapconcat 'identity result \"\\|\")
492 IF REGEXP is not a string, return it unchanged."
494 (split-string regexp
"\\\\|")
497 (defun custom-variable-prompt ()
498 "Prompt for a custom variable, defaulting to the variable at point.
499 Return a list suitable for use in `interactive'."
500 (let* ((v (variable-at-point))
501 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
502 (enable-recursive-minibuffers t
)
504 (setq val
(completing-read
505 (if default
(format "Customize variable (default %s): " default
)
506 "Customize variable: ")
507 obarray
'custom-variable-p t nil nil default
))
508 (list (if (equal val
"")
509 (if (symbolp v
) v nil
)
512 (defun custom-menu-filter (menu widget
)
513 "Convert MENU to the form used by `widget-choose'.
514 MENU should be in the same format as `custom-variable-menu'.
515 WIDGET is the widget to apply the filter entries of MENU on."
517 current name action filter
)
519 (setq current
(car menu
)
521 action
(nth 1 current
)
522 filter
(nth 2 current
)
524 (if (or (null filter
) (funcall filter widget
))
525 (push (cons name action
) result
)
531 (defvar custom-prefix-list nil
532 "List of prefixes that should be ignored by `custom-unlispify'.")
534 (defcustom custom-unlispify-menu-entries t
535 "Display menu entries as words instead of symbols if non-nil."
539 (defcustom custom-unlispify-remove-prefixes nil
540 "Non-nil means remove group prefixes from option names in buffer."
542 :group
'custom-buffer
545 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
546 "Convert SYMBOL into a menu entry."
547 (cond ((not custom-unlispify-menu-entries
)
548 (symbol-name symbol
))
549 ((get symbol
'custom-tag
)
551 (get symbol
'custom-tag
)
552 (concat (get symbol
'custom-tag
) "...")))
554 (with-current-buffer (get-buffer-create " *Custom-Work*")
556 (princ symbol
(current-buffer))
557 (goto-char (point-min))
558 ;; FIXME: Boolean variables are not predicates, so they shouldn't
559 ;; end with `-p'. -stef
560 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
561 ;; (re-search-forward "-p\\'" nil t))
562 ;; (replace-match "" t t)
563 ;; (goto-char (point-min)))
564 (if custom-unlispify-remove-prefixes
565 (let ((prefixes custom-prefix-list
)
568 (setq prefix
(car prefixes
))
569 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
572 (delete-region (point-min) (point)))
573 (setq prefixes
(cdr prefixes
))))))
574 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
575 (capitalize-region (point-min) (point-max))
577 (goto-char (point-max))
581 (defcustom custom-unlispify-tag-names t
582 "Display tag names as words instead of symbols if non-nil."
583 :group
'custom-buffer
586 (defun custom-unlispify-tag-name (symbol)
587 "Convert SYMBOL into a menu entry."
588 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
589 (custom-unlispify-menu-entry symbol t
)))
591 (defun custom-prefix-add (symbol prefixes
)
592 "Add SYMBOL to list of ignored PREFIXES."
593 (cons (or (get symbol
'custom-prefix
)
594 (concat (symbol-name symbol
) "-"))
599 (defcustom custom-guess-name-alist
605 ("-function\\'" function
)
606 ("-functions\\'" (repeat function
))
607 ("-list\\'" (repeat sexp
))
608 ("-alist\\'" (repeat (cons sexp sexp
))))
609 "Alist of (MATCH TYPE).
611 MATCH should be a regexp matching the name of a symbol, and TYPE should
612 be a widget suitable for editing the value of that symbol. The TYPE
613 of the first entry where MATCH matches the name of the symbol will be
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 (defcustom custom-guess-doc-alist
622 '(("\\`\\*?Non-nil " boolean
))
623 "Alist of (MATCH TYPE).
625 MATCH should be a regexp matching a documentation string, and TYPE
626 should be a widget suitable for editing the value of a variable with
627 that documentation string. The TYPE of the first entry where MATCH
628 matches the name of the symbol will be used.
630 This is used for guessing the type of variables not declared with
632 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
633 :group
'custom-buffer
)
635 (defun custom-guess-type (symbol)
636 "Guess a widget suitable for editing the value of SYMBOL.
637 This is done by matching SYMBOL with `custom-guess-name-alist' and
638 if that fails, the doc string with `custom-guess-doc-alist'."
639 (let ((name (symbol-name symbol
))
640 (names custom-guess-name-alist
)
643 (setq current
(car names
)
645 (when (string-match (nth 0 current
) name
)
646 (setq found
(nth 1 current
)
649 (let ((doc (documentation-property symbol
'variable-documentation
))
650 (docs custom-guess-doc-alist
))
653 (setq current
(car docs
)
655 (when (string-match (nth 0 current
) doc
)
656 (setq found
(nth 1 current
)
663 (defcustom custom-browse-sort-alphabetically nil
664 "If non-nil, sort customization group alphabetically in `custom-browse'."
666 :group
'custom-browse
)
668 (defcustom custom-browse-order-groups nil
669 "If non-nil, order group members within each customization group.
670 If `first', order groups before non-groups.
671 If `last', order groups after non-groups."
672 :type
'(choice (const first
)
674 (const :tag
"none" nil
))
675 :group
'custom-browse
)
677 (defcustom custom-browse-only-groups nil
678 "If non-nil, show group members only within each customization group."
680 :group
'custom-browse
)
683 (defcustom custom-buffer-sort-alphabetically nil
684 "If non-nil, sort each customization group alphabetically in Custom buffer."
686 :group
'custom-buffer
)
688 (defcustom custom-buffer-order-groups
'last
689 "If non-nil, order group members within each customization group.
690 If `first', order groups before non-groups.
691 If `last', order groups after non-groups."
692 :type
'(choice (const first
)
694 (const :tag
"none" nil
))
695 :group
'custom-buffer
)
698 (defcustom custom-menu-sort-alphabetically nil
699 "If non-nil, sort each customization group alphabetically in menus."
703 (defcustom custom-menu-order-groups
'first
704 "If non-nil, order group members within each customization group.
705 If `first', order groups before non-groups.
706 If `last', order groups after non-groups."
707 :type
'(choice (const first
)
709 (const :tag
"none" nil
))
712 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
714 (defun custom-sort-items (items sort-alphabetically order-groups
)
715 "Return a sorted copy of ITEMS.
716 ITEMS should be a `custom-group' property.
717 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
718 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
719 groups after non-groups, if nil do not order groups at all."
720 (sort (copy-sequence items
)
722 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
723 (namea (nth 0 a
)) (nameb (nth 0 b
)))
724 (cond ((not order-groups
)
725 ;; Since we don't care about A and B order, maybe sort.
726 (when sort-alphabetically
727 (string-lessp namea nameb
)))
728 ((eq typea
'custom-group
)
729 ;; If B is also a group, maybe sort. Otherwise, order A and B.
730 (if (eq typeb
'custom-group
)
731 (when sort-alphabetically
732 (string-lessp namea nameb
))
733 (eq order-groups
'first
)))
734 ((eq typeb
'custom-group
)
735 ;; Since A cannot be a group, order A and B.
736 (eq order-groups
'last
))
738 ;; Since A and B cannot be groups, sort.
739 (string-lessp namea nameb
)))))))
741 ;;; Custom Mode Commands.
743 ;; This variable is used by `custom-tool-bar-map', or directly by
744 ;; `custom-buffer-create-internal' if the toolbar is not present and
745 ;; `custom-buffer-verbose-help' is non-nil.
747 (defvar custom-commands
748 '(("Set for current session" Custom-set t
749 "Apply all settings in this buffer to the current session"
751 ("Save for future sessions" Custom-save
752 (or custom-file user-init-file
)
753 "Apply all settings in this buffer and save them for future Emacs sessions."
755 ("Undo edits" Custom-reset-current t
756 "Restore all settings in this buffer to reflect their current values."
758 ("Reset to saved" Custom-reset-saved t
759 "Restore all settings in this buffer to their saved values (if any)."
761 ("Erase customizations" Custom-reset-standard
762 (or custom-file user-init-file
)
763 "Un-customize all settings in this buffer and save them with standard values."
765 ("Help for Customize" Custom-help t
766 "Get help for using Customize."
768 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
770 (defun Custom-help ()
771 "Read the node on Easy Customization in the Emacs manual."
773 (info "(emacs)Easy Customization"))
775 (defvar custom-reset-menu
776 '(("Undo Edits" . Custom-reset-current
)
777 ("Reset to Saved" . Custom-reset-saved
)
778 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
779 "Alist of actions for the `Reset' button.
780 The key is a string containing the name of the action, the value is a
781 Lisp function taking the widget as an element which will be called
782 when the action is chosen.")
784 (defvar custom-options nil
785 "Customization widgets in the current buffer.")
787 (defun custom-command-apply (fun query
&optional strong-query
)
788 "Call function FUN on all widgets in `custom-options'.
789 If there is more than one widget, ask user for confirmation using
790 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
791 and `yes-or-no-p' otherwise."
792 (if (or (and (= 1 (length custom-options
))
793 (memq (widget-type (car custom-options
))
794 '(custom-variable custom-face
)))
795 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
796 (progn (mapc fun custom-options
) t
)
800 (defun Custom-set (&rest ignore
)
801 "Set the current value of all edited settings in the buffer."
803 (custom-command-apply
805 (when (eq (widget-get child
:custom-state
) 'modified
)
806 (widget-apply child
:custom-set
)))
807 "Set all values according to this buffer? "))
809 (defun Custom-save (&rest ignore
)
810 "Set all edited settings, then save all settings that have been set.
811 If a setting was edited and set before, this saves it. If a
812 setting was merely edited before, this sets it then saves it."
814 (when (custom-command-apply
816 (when (memq (widget-get child
:custom-state
)
817 '(modified set changed rogue
))
818 (widget-apply child
:custom-mark-to-save
)))
819 "Save all settings in this buffer? " t
)
820 ;; Save changes to buffer and redraw.
822 (dolist (child custom-options
)
823 (widget-apply child
:custom-state-set-and-redraw
))))
825 (defun custom-reset (widget &optional event
)
826 "Select item from reset menu."
827 (let* ((completion-ignore-case t
)
828 (answer (widget-choose "Reset settings"
834 (defun Custom-reset-current (&rest ignore
)
835 "Reset all edited settings in the buffer to show their current values."
837 (custom-command-apply
839 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
840 (widget-apply widget
:custom-reset-current
)))
841 "Reset all settings' buffer text to show current values? "))
843 (defun Custom-reset-saved (&rest ignore
)
844 "Reset all edited or set settings in the buffer to their saved value.
845 This also shows the saved values in the buffer."
847 (custom-command-apply
849 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
850 (widget-apply widget
:custom-reset-saved
)))
851 "Reset all settings (current values and buffer text) to saved values? "))
853 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
854 ;; and `custom-group-reset-standard'. If these variables are nil, both
855 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
856 ;; save, reset and redraw the handled widget immediately. Otherwise,
857 ;; they add the widget to the corresponding list and leave it to
858 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
859 (defvar custom-reset-standard-variables-list nil
)
860 (defvar custom-reset-standard-faces-list nil
)
862 ;; The next function was excerpted from `custom-variable-reset-standard'
863 ;; and `custom-face-reset-standard' and is used to avoid calling
864 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
865 ;; one) when erasing all customizations.
866 (defun custom-reset-standard-save-and-update ()
867 "Save settings and redraw after erasing customizations."
868 (when (or (and custom-reset-standard-variables-list
869 (not (eq custom-reset-standard-variables-list
'(t))))
870 (and custom-reset-standard-faces-list
871 (not (eq custom-reset-standard-faces-list
'(t)))))
872 ;; Save settings to file.
874 ;; Set state of and redraw variables.
875 (dolist (widget custom-reset-standard-variables-list
)
876 (unless (eq widget t
)
877 (widget-put widget
:custom-state
'unknown
)
878 (custom-redraw widget
)))
879 ;; Set state of and redraw faces.
880 (dolist (widget custom-reset-standard-faces-list
)
881 (unless (eq widget t
)
882 (let* ((symbol (widget-value widget
))
883 (child (car (widget-get widget
:children
)))
884 (value (get symbol
'face-defface-spec
))
885 (comment-widget (widget-get widget
:comment-widget
)))
886 (put symbol
'face-comment nil
)
887 (widget-value-set child
888 (custom-pre-filter-face-spec
889 (list (list t
(custom-face-attributes-get
891 ;; This call manages the comment visibility
892 (widget-value-set comment-widget
"")
893 (custom-face-state-set widget
)
894 (custom-redraw-magic widget
))))))
896 (defun Custom-reset-standard (&rest ignore
)
897 "Erase all customizations (either current or saved) in current buffer.
898 The immediate result is to restore them to their standard values.
899 This operation eliminates any saved values for the group members,
900 making them as if they had never been customized at all."
902 ;; Bind these temporarily.
903 (let ((custom-reset-standard-variables-list '(t))
904 (custom-reset-standard-faces-list '(t)))
905 (custom-command-apply
907 (and (or (null (widget-get widget
:custom-standard-value
))
908 (widget-apply widget
:custom-standard-value
))
909 (memq (widget-get widget
:custom-state
)
910 '(modified set changed saved rogue
))
911 (widget-apply widget
:custom-mark-to-reset-standard
)))
912 "Erase all customizations for settings in this buffer? " t
)
913 (custom-reset-standard-save-and-update)))
915 ;;; The Customize Commands
917 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
918 "Prompt for a variable and a value and return them as a list.
919 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
920 prompt for the value. The %s escape in PROMPT-VAL is replaced with
921 the name of the variable.
923 If the variable has a `variable-interactive' property, that is used as if
924 it were the arg to `interactive' (which see) to interactively read the value.
926 If the variable has a `custom-type' property, it must be a widget and the
927 `:prompt-value' property of that widget will be used for reading the value.
929 If optional COMMENT argument is non-nil, also prompt for a comment and return
930 it as the third element in the list."
931 (let* ((var (read-variable prompt-var
))
932 (minibuffer-help-form '(describe-variable var
))
934 (let ((prop (get var
'variable-interactive
))
935 (type (get var
'custom-type
))
936 (prompt (format prompt-val var
)))
938 (setq type
(list type
)))
940 ;; Use VAR's `variable-interactive' property
941 ;; as an interactive spec for prompting.
942 (call-interactively `(lambda (arg)
946 (widget-prompt-value type
952 (eval-minibuffer prompt
))))))
955 (read-string "Comment: " (get var
'variable-comment
)))
959 (defun customize-set-value (variable value
&optional comment
)
960 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
962 If VARIABLE has a `variable-interactive' property, that is used as if
963 it were the arg to `interactive' (which see) to interactively read the value.
965 If VARIABLE has a `custom-type' property, it must be a widget and the
966 `:prompt-value' property of that widget will be used for reading the value.
968 If given a prefix (or a COMMENT argument), also prompt for a comment."
969 (interactive (custom-prompt-variable "Set variable: "
973 (cond ((string= comment
"")
974 (put variable
'variable-comment nil
))
976 (put variable
'variable-comment comment
)))
977 (set variable value
))
980 (defun customize-set-variable (variable value
&optional comment
)
981 "Set the default for VARIABLE to VALUE, and return VALUE.
982 VALUE is a Lisp object.
984 If VARIABLE has a `custom-set' property, that is used for setting
985 VARIABLE, otherwise `set-default' is used.
987 If VARIABLE has a `variable-interactive' property, that is used as if
988 it were the arg to `interactive' (which see) to interactively read the value.
990 If VARIABLE has a `custom-type' property, it must be a widget and the
991 `:prompt-value' property of that widget will be used for reading the value.
993 If given a prefix (or a COMMENT argument), also prompt for a comment."
994 (interactive (custom-prompt-variable "Set variable: "
995 "Set customized value for %s to: "
997 (custom-load-symbol variable
)
998 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
999 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1000 (put variable
'customized-value
(list (custom-quote value
)))
1001 (cond ((string= comment
"")
1002 (put variable
'variable-comment nil
)
1003 (put variable
'customized-variable-comment nil
))
1005 (put variable
'variable-comment comment
)
1006 (put variable
'customized-variable-comment comment
)))
1010 (defun customize-save-variable (variable value
&optional comment
)
1011 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1014 If VARIABLE has a `custom-set' property, that is used for setting
1015 VARIABLE, otherwise `set-default' is used.
1017 If VARIABLE has a `variable-interactive' property, that is used as if
1018 it were the arg to `interactive' (which see) to interactively read the value.
1020 If VARIABLE has a `custom-type' property, it must be a widget and the
1021 `:prompt-value' property of that widget will be used for reading the value.
1023 If given a prefix (or a COMMENT argument), also prompt for a comment."
1024 (interactive (custom-prompt-variable "Set and save variable: "
1025 "Set and save value for %s as: "
1026 current-prefix-arg
))
1027 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1028 (put variable
'saved-value
(list (custom-quote value
)))
1029 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1030 (cond ((string= comment
"")
1031 (put variable
'variable-comment nil
)
1032 (put variable
'saved-variable-comment nil
))
1034 (put variable
'variable-comment comment
)
1035 (put variable
'saved-variable-comment comment
)))
1036 (put variable
'customized-value nil
)
1037 (put variable
'customized-variable-comment nil
)
1043 "Select a customization buffer which you can use to set user options.
1044 User options are structured into \"groups\".
1045 Initially the top-level group `Emacs' and its immediate subgroups
1046 are shown; the contents of those subgroups are initially hidden."
1048 (customize-group 'emacs
))
1051 (defun customize-mode (mode)
1052 "Customize options related to the current major mode.
1053 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1054 then prompt for the MODE to customize."
1057 (let ((completion-regexp-list '("-mode\\'"))
1058 (group (custom-group-of-mode major-mode
)))
1059 (if (and group
(not current-prefix-arg
))
1062 (completing-read (if group
1063 (format "Major mode (default %s): " major-mode
)
1066 'custom-group-of-mode
1067 t nil nil
(if group
(symbol-name major-mode
))))))))
1068 (customize-group (custom-group-of-mode mode
)))
1070 (defun customize-read-group ()
1071 (let ((completion-ignore-case t
))
1072 (completing-read "Customize group (default emacs): "
1075 (or (and (get symbol
'custom-loads
)
1076 (not (get symbol
'custom-autoload
)))
1077 (get symbol
'custom-group
)))
1081 (defun customize-group (&optional group
)
1082 "Customize GROUP, which must be a customization group."
1083 (interactive (list (customize-read-group)))
1084 (when (stringp group
)
1085 (if (string-equal "" group
)
1087 (setq group
(intern group
))))
1088 (let ((name (format "*Customize Group: %s*"
1089 (custom-unlispify-tag-name group
))))
1090 (if (get-buffer name
)
1091 (pop-to-buffer name
)
1092 (custom-buffer-create
1093 (list (list group
'custom-group
))
1095 (concat " for group "
1096 (custom-unlispify-tag-name group
))))))
1099 (defun customize-group-other-window (&optional group
)
1100 "Customize GROUP, which must be a customization group, in another window."
1101 (interactive (list (customize-read-group)))
1102 (let ((pop-up-windows t
)
1103 (same-window-buffer-names nil
)
1104 (same-window-regexps nil
))
1105 (customize-group group
)))
1108 (defalias 'customize-variable
'customize-option
)
1111 (defun customize-option (symbol)
1112 "Customize SYMBOL, which must be a user option variable."
1113 (interactive (custom-variable-prompt))
1115 (error "No variable specified"))
1116 (let ((basevar (indirect-variable symbol
)))
1117 (custom-buffer-create (list (list basevar
'custom-variable
))
1118 (format "*Customize Option: %s*"
1119 (custom-unlispify-tag-name basevar
)))
1120 (unless (eq symbol basevar
)
1121 (message "`%s' is an alias for `%s'" symbol basevar
))))
1124 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1127 (defun customize-option-other-window (symbol)
1128 "Customize SYMBOL, which must be a user option variable.
1129 Show the buffer in another window, but don't select it."
1130 (interactive (custom-variable-prompt))
1132 (error "No variable specified"))
1133 (let ((basevar (indirect-variable symbol
)))
1134 (custom-buffer-create-other-window
1135 (list (list basevar
'custom-variable
))
1136 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1137 (unless (eq symbol basevar
)
1138 (message "`%s' is an alias for `%s'" symbol basevar
))))
1140 (defvar customize-changed-options-previous-release
"21.1"
1141 "Version for `customize-changed-options' to refer back to by default.")
1143 ;; Packages will update this variable, so make it available.
1145 (defvar customize-package-emacs-version-alist nil
1146 "Alist mapping versions of a package to Emacs versions.
1147 We use this for packages that have their own names, but are released
1148 as part of Emacs itself.
1150 Each elements looks like this:
1152 (PACKAGE (PVERSION . EVERSION)...)
1154 Here PACKAGE is the name of a package, as a symbol. After
1155 PACKAGE come one or more elements, each associating a
1156 package version PVERSION with the first Emacs version
1157 EVERSION in which it (or a subsequent version of PACKAGE)
1158 was first released. Both PVERSION and EVERSION are strings.
1159 PVERSION should be a string that this package used in
1160 the :package-version keyword for `defcustom', `defgroup',
1163 For example, the MH-E package updates this alist as follows:
1165 (add-to-list 'customize-package-emacs-version-alist
1166 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1167 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1168 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1169 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1171 The value of PACKAGE needs to be unique and it needs to match the
1172 PACKAGE value appearing in the :package-version keyword. Since
1173 the user might see the value in a error message, a good choice is
1174 the official name of the package, such as MH-E or Gnus.")
1177 (defalias 'customize-changed
'customize-changed-options
)
1180 (defun customize-changed-options (&optional since-version
)
1181 "Customize all settings whose meanings have changed in Emacs itself.
1182 This includes new user option variables and faces, and new
1183 customization groups, as well as older options and faces whose meanings
1184 or default values have changed since the previous major Emacs release.
1186 With argument SINCE-VERSION (a string), customize all settings
1187 that were added or redefined since that version."
1191 (read-from-minibuffer
1192 (format "Customize options changed, since version (default %s): "
1193 customize-changed-options-previous-release
))))
1194 (if (equal since-version
"")
1195 (setq since-version nil
)
1196 (unless (condition-case nil
1197 (numberp (read since-version
))
1199 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1200 (unless since-version
1201 (setq since-version customize-changed-options-previous-release
))
1203 ;; Load the information for versions since since-version. We use
1204 ;; custom-load-symbol for this.
1205 (put 'custom-versions-load-alist
'custom-loads nil
)
1206 (dolist (elt custom-versions-load-alist
)
1207 (if (customize-version-lessp since-version
(car elt
))
1208 (dolist (load (cdr elt
))
1209 (custom-add-load 'custom-versions-load-alist load
))))
1210 (custom-load-symbol 'custom-versions-load-alist
)
1211 (put 'custom-versions-load-alist
'custom-loads nil
)
1216 (let* ((package-version (get symbol
'custom-package-version
))
1218 (or (and package-version
1219 (customize-package-emacs-version symbol
1221 (get symbol
'custom-version
))))
1223 (when (customize-version-lessp since-version version
)
1224 (if (or (get symbol
'custom-group
)
1225 (get symbol
'group-documentation
))
1226 (push (list symbol
'custom-group
) found
))
1227 (if (custom-variable-p symbol
)
1228 (push (list symbol
'custom-variable
) found
))
1229 (if (custom-facep symbol
)
1230 (push (list symbol
'custom-face
) found
)))))))
1232 (custom-buffer-create (custom-sort-items found t
'first
)
1233 "*Customize Changed Options*")
1234 (error "No user option defaults have been changed since Emacs %s"
1237 (defun customize-package-emacs-version (symbol package-version
)
1238 "Return the Emacs version in which SYMBOL's meaning last changed.
1239 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1240 `customize-package-emacs-version-alist' to find the version of
1241 Emacs that is associated with version VERSION of PACKAGE."
1242 (let (package-versions emacs-version
)
1243 ;; Use message instead of error since we want user to be able to
1244 ;; see the rest of the symbols even if a package author has
1245 ;; botched things up.
1246 (cond ((not (listp package-version
))
1247 (message "Invalid package-version value for %s" symbol
))
1248 ((setq package-versions
(assq (car package-version
)
1249 customize-package-emacs-version-alist
))
1251 (cdr (assoc (cdr package-version
) package-versions
)))
1252 (unless emacs-version
1253 (message "%s version %s not found in %s" symbol
1254 (cdr package-version
)
1255 "customize-package-emacs-version-alist")))
1257 (message "Package %s version %s lists no corresponding Emacs version"
1258 (car package-version
)
1259 (cdr package-version
))))
1262 (defun customize-version-lessp (version1 version2
)
1263 ;; Why are the versions strings, and given that they are, why aren't
1264 ;; they converted to numbers and compared as such here? -- fx
1266 ;; In case someone made a mistake and left out the quotes
1267 ;; in the :version value.
1268 (if (numberp version2
)
1269 (setq version2
(prin1-to-string version2
)))
1270 (let (major1 major2 minor1 minor2
)
1271 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1272 (setq major1
(read (or (match-string 1 version1
)
1274 (setq minor1
(read (or (match-string 3 version1
)
1276 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1277 (setq major2
(read (or (match-string 1 version2
)
1279 (setq minor2
(read (or (match-string 3 version2
)
1281 (or (< major1 major2
)
1282 (and (= major1 major2
)
1283 (< minor1 minor2
)))))
1286 (defun customize-face (&optional face
)
1287 "Customize FACE, which should be a face name or nil.
1288 If FACE is nil, customize all faces. If FACE is actually a
1289 face-alias, customize the face it is aliased to.
1291 Interactively, when point is on text which has a face specified,
1292 suggest to customize that face, if it's customizable."
1293 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1294 (if (member face
'(nil ""))
1295 (setq face
(face-list)))
1296 (if (and (listp face
) (null (cdr face
)))
1297 (setq face
(car face
)))
1299 (custom-buffer-create
1301 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1303 "*Customize Faces*")
1304 ;; If FACE is actually an alias, customize the face it is aliased to.
1305 (if (get face
'face-alias
)
1306 (setq face
(get face
'face-alias
)))
1307 (unless (facep face
)
1308 (error "Invalid face %S" face
))
1309 (custom-buffer-create
1310 (list (list face
'custom-face
))
1311 (format "*Customize Face: %s*"
1312 (custom-unlispify-tag-name face
)))))
1315 (defun customize-face-other-window (&optional face
)
1316 "Show customization buffer for face FACE in other window.
1317 If FACE is actually a face-alias, customize the face it is aliased to.
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 (let ((pop-up-windows t
)
1323 (same-window-buffer-names nil
)
1324 (same-window-regexps nil
))
1325 (customize-face face
)))
1327 (defalias 'customize-customized
'customize-unsaved
)
1330 (defun customize-unsaved ()
1331 "Customize all user options set in this session but not saved."
1334 (mapatoms (lambda (symbol)
1335 (and (or (get symbol
'customized-face
)
1336 (get symbol
'customized-face-comment
))
1337 (custom-facep symbol
)
1338 (push (list symbol
'custom-face
) found
))
1339 (and (or (get symbol
'customized-value
)
1340 (get symbol
'customized-variable-comment
))
1342 (push (list symbol
'custom-variable
) found
))))
1344 (error "No user options are set but unsaved")
1345 (custom-buffer-create (custom-sort-items found t nil
)
1346 "*Customize Unsaved*"))))
1349 (defun customize-rogue ()
1350 "Customize all user variables modified outside customize."
1353 (mapatoms (lambda (symbol)
1354 (let ((cval (or (get symbol
'customized-value
)
1355 (get symbol
'saved-value
)
1356 (get symbol
'standard-value
))))
1357 (when (and cval
;Declared with defcustom.
1358 (default-boundp symbol
) ;Has a value.
1359 (not (equal (eval (car cval
))
1360 ;; Which does not match customize.
1361 (default-value symbol
))))
1362 (push (list symbol
'custom-variable
) found
)))))
1364 (error "No rogue user options")
1365 (custom-buffer-create (custom-sort-items found t nil
)
1366 "*Customize Rogue*"))))
1368 (defun customize-saved ()
1369 "Customize all already saved user options."
1372 (mapatoms (lambda (symbol)
1373 (and (or (get symbol
'saved-face
)
1374 (get symbol
'saved-face-comment
))
1375 (custom-facep symbol
)
1376 (push (list symbol
'custom-face
) found
))
1377 (and (or (get symbol
'saved-value
)
1378 (get symbol
'saved-variable-comment
))
1380 (push (list symbol
'custom-variable
) found
))))
1382 (error "No saved user options")
1383 (custom-buffer-create (custom-sort-items found t nil
)
1384 "*Customize Saved*"))))
1387 (defun customize-apropos (regexp &optional all
)
1388 "Customize all loaded options, faces and groups matching REGEXP.
1389 If ALL is `options', include only options.
1390 If ALL is `faces', include only faces.
1391 If ALL is `groups', include only groups.
1392 If ALL is t (interactively, with prefix arg), include variables
1393 that are not customizable options, as well as faces and groups
1394 \(but we recommend using `apropos-variable' instead)."
1395 (interactive "sCustomize (regexp): \nP")
1397 (mapatoms (lambda (symbol)
1398 (when (string-match regexp
(symbol-name symbol
))
1399 (when (and (not (memq all
'(faces options
)))
1400 (get symbol
'custom-group
))
1401 (push (list symbol
'custom-group
) found
))
1402 (when (and (not (memq all
'(options groups
)))
1403 (custom-facep symbol
))
1404 (push (list symbol
'custom-face
) found
))
1405 (when (and (not (memq all
'(groups faces
)))
1407 (eq (indirect-variable symbol
) symbol
)
1408 (or (get symbol
'saved-value
)
1409 (custom-variable-p symbol
)
1410 (and (not (memq all
'(nil options
)))
1411 (get symbol
'variable-documentation
))))
1412 (push (list symbol
'custom-variable
) found
)))))
1414 (error "No %s matching %s"
1417 (format "customizable %s"
1418 (if (memq all
'(options faces groups
))
1422 (custom-buffer-create
1423 (custom-sort-items found t custom-buffer-order-groups
)
1424 "*Customize Apropos*"))))
1427 (defun customize-apropos-options (regexp &optional arg
)
1428 "Customize all loaded customizable options matching REGEXP.
1429 With prefix ARG, include variables that are not customizable options
1430 \(but it is better to use `apropos-variable' if you want to find those)."
1431 (interactive "sCustomize options (regexp): \nP")
1432 (customize-apropos regexp
(or arg
'options
)))
1435 (defun customize-apropos-faces (regexp)
1436 "Customize all loaded faces matching REGEXP."
1437 (interactive "sCustomize faces (regexp): \n")
1438 (customize-apropos regexp
'faces
))
1441 (defun customize-apropos-groups (regexp)
1442 "Customize all loaded groups matching REGEXP."
1443 (interactive "sCustomize groups (regexp): \n")
1444 (customize-apropos regexp
'groups
))
1448 (defcustom custom-buffer-style
'links
1449 "Control the presentation style for customization buffers.
1450 The value should be a symbol, one of:
1452 brackets: groups nest within each other with big horizontal brackets.
1453 links: groups have links to subgroups."
1454 :type
'(radio (const brackets
)
1456 :group
'custom-buffer
)
1458 (defcustom custom-buffer-done-kill nil
1459 "Non-nil means exiting a Custom buffer should kill it."
1462 :group
'custom-buffer
)
1464 (defcustom custom-buffer-indent
3
1465 "Number of spaces to indent nested groups."
1467 :group
'custom-buffer
)
1469 (defun custom-get-fresh-buffer (name)
1470 "Get a fresh new buffer with name NAME.
1471 If the buffer already exist, clean it up to be like new.
1472 Beware: it's not quite like new. Good enough for custom, but maybe
1474 ;; To be more complete, we should also kill all permanent-local variables,
1475 ;; but it's not needed for custom.
1476 (let ((buf (get-buffer name
)))
1477 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1478 ;; This will check if the file is not saved.
1482 (get-buffer-create name
)
1483 (with-current-buffer buf
1484 (kill-all-local-variables)
1485 (run-hooks 'kill-buffer-hook
)
1486 ;; Delete overlays before erasing the buffer so the overlay hooks
1487 ;; don't get run spuriously when we erase the buffer.
1488 (let ((ols (overlay-lists)))
1489 (dolist (ol (nconc (car ols
) (cdr ols
)))
1490 (delete-overlay ol
)))
1495 (defun custom-buffer-create (options &optional name description
)
1496 "Create a buffer containing OPTIONS.
1497 Optional NAME is the name of the buffer.
1498 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1499 SYMBOL is a customization option, and WIDGET is a widget for editing
1501 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1502 (custom-buffer-create-internal options description
))
1505 (defun custom-buffer-create-other-window (options &optional name description
)
1506 "Create a buffer containing OPTIONS, and display it in another window.
1507 The result includes selecting that window.
1508 Optional NAME is the name of the buffer.
1509 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1510 SYMBOL is a customization option, and WIDGET is a widget for editing
1512 (unless name
(setq name
"*Customization*"))
1513 (let ((pop-up-windows t
)
1514 (same-window-buffer-names nil
)
1515 (same-window-regexps nil
))
1516 (pop-to-buffer (custom-get-fresh-buffer name
))
1517 (custom-buffer-create-internal options description
)))
1519 (defcustom custom-reset-button-menu nil
1520 "If non-nil, only show a single reset button in customize buffers.
1521 This button will have a menu with all three reset operations."
1523 :group
'custom-buffer
)
1525 (defcustom custom-buffer-verbose-help t
1526 "If non-nil, include explanatory text in the customization buffer."
1528 :group
'custom-buffer
)
1530 (defun Custom-buffer-done (&rest ignore
)
1531 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1533 (quit-window custom-buffer-done-kill
))
1535 (defvar custom-button nil
1536 "Face used for buttons in customization buffers.")
1538 (defvar custom-button-mouse nil
1539 "Mouse face used for buttons in customization buffers.")
1541 (defvar custom-button-pressed nil
1542 "Face used for pressed buttons in customization buffers.")
1544 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1545 '(("unspecified" . unspecified
))))
1546 "If non-nil, indicate active buttons in a `raised-button' style.
1547 Otherwise use brackets."
1550 :group
'custom-buffer
1551 :set
(lambda (variable value
)
1552 (custom-set-default variable value
)
1554 (if value
'custom-button
'custom-button-unraised
))
1555 (setq custom-button-mouse
1556 (if value
'custom-button-mouse
'highlight
))
1557 (setq custom-button-pressed
1559 'custom-button-pressed
1560 'custom-button-pressed-unraised
))))
1562 (defun custom-buffer-create-internal (options &optional description
)
1564 (let ((init-file (or custom-file user-init-file
)))
1565 ;; Insert verbose help at the top of the custom buffer.
1566 (when custom-buffer-verbose-help
1567 (widget-insert "Editing a setting changes only the text in this buffer."
1570 To apply your changes, use the Save or Set buttons.
1571 Saving a change normally works by editing your init file."
1573 Currently, these settings cannot be saved for future Emacs sessions,
1574 possibly because you started Emacs with `-q'.")
1575 "\nFor details, see ")
1576 (widget-create 'custom-manual
1577 :tag
"Saving Customizations"
1578 "(emacs)Saving Customizations")
1579 (widget-insert " in the ")
1580 (widget-create 'custom-manual
1582 :help-echo
"Read the Emacs manual."
1584 (widget-insert "."))
1585 ;; Insert custom command buttons if the toolbar is not in use.
1587 (widget-insert "\n")
1588 ;; tool-bar is not dumped in builds without x.
1589 (when (not (and (bound-and-true-p tool-bar-mode
) (display-graphic-p)))
1590 (if custom-buffer-verbose-help
1592 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1593 (let ((button (lambda (tag action active help icon
)
1596 (widget-create 'push-button
:tag tag
1597 :help-echo help
:action action
))))
1598 (commands custom-commands
))
1599 (apply button
(pop commands
)) ; Set for current session
1600 (apply button
(pop commands
)) ; Save for future sessions
1601 (if custom-reset-button-menu
1604 (widget-create 'push-button
1606 :help-echo
"Show a menu with reset operations."
1607 :mouse-down-action
'ignore
1608 :action
'custom-reset
))
1609 (widget-insert "\n")
1610 (apply button
(pop commands
)) ; Undo edits
1611 (apply button
(pop commands
)) ; Reset to saved
1612 (apply button
(pop commands
)) ; Erase customization
1614 (pop commands
) ; Help (omitted)
1615 (apply button
(pop commands
))))) ; Exit
1616 (widget-insert "\n\n"))
1618 ;; Now populate the custom buffer.
1619 (message "Creating customization items...")
1620 (buffer-disable-undo)
1621 (setq custom-options
1622 (if (= (length options
) 1)
1623 (mapcar (lambda (entry)
1624 (widget-create (nth 1 entry
)
1625 :documentation-shown t
1626 :custom-state
'unknown
1627 :tag
(custom-unlispify-tag-name
1629 :value
(nth 0 entry
)))
1632 (length (length options
)))
1633 (mapcar (lambda (entry)
1635 (message "Creating customization items ...%2d%%"
1636 (/ (* 100.0 count
) length
))
1637 (widget-create (nth 1 entry
)
1638 :tag
(custom-unlispify-tag-name
1640 :value
(nth 0 entry
))
1641 (setq count
(1+ count
))
1642 (unless (eq (preceding-char) ?
\n)
1643 (widget-insert "\n"))
1644 (widget-insert "\n")))
1646 (unless (eq (preceding-char) ?
\n)
1647 (widget-insert "\n"))
1648 (message "Creating customization items ...done")
1649 (message "Resetting customization items...")
1650 (unless (eq custom-buffer-style
'tree
)
1651 (mapc 'custom-magic-reset custom-options
))
1652 (message "Resetting customization items...done")
1653 (message "Creating customization setup...")
1655 (buffer-enable-undo)
1656 (goto-char (point-min))
1657 (message "Creating customization setup...done"))
1659 ;;; The Tree Browser.
1662 (defun customize-browse (&optional group
)
1663 "Create a tree browser for the customize hierarchy."
1666 (setq group
'emacs
))
1667 (let ((name "*Customize Browser*"))
1668 (pop-to-buffer (custom-get-fresh-buffer name
)))
1670 (widget-insert (format "\
1671 %s buttons; type RET or click mouse-1
1672 on a button to invoke its action.
1673 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1674 (if custom-raised-buttons
1675 "`Raised' text indicates"
1676 "Square brackets indicate")))
1679 (if custom-browse-only-groups
1681 Invoke the [Group] button below to edit that item in another window.\n\n")
1682 (widget-insert "Invoke the ")
1683 (widget-create 'item
1686 :tag-glyph
"folder")
1687 (widget-insert ", ")
1688 (widget-create 'item
1692 (widget-insert ", and ")
1693 (widget-create 'item
1696 :tag-glyph
"option")
1697 (widget-insert " buttons below to edit that
1698 item in another window.\n\n"))
1699 (let ((custom-buffer-style 'tree
))
1700 (widget-create 'custom-group
1702 :custom-state
'unknown
1703 :tag
(custom-unlispify-tag-name group
)
1706 (goto-char (point-min)))
1708 (define-widget 'custom-browse-visibility
'item
1709 "Control visibility of items in the customize tree browser."
1711 :action
'custom-browse-visibility-action
)
1713 (defun custom-browse-visibility-action (widget &rest ignore
)
1714 (let ((custom-buffer-style 'tree
))
1715 (custom-toggle-parent widget
)))
1717 (define-widget 'custom-browse-group-tag
'custom-group-link
1718 "Show parent in other window when activated."
1721 :action
'custom-browse-group-tag-action
)
1723 (defun custom-browse-group-tag-action (widget &rest ignore
)
1724 (let ((parent (widget-get widget
:parent
)))
1725 (customize-group-other-window (widget-value parent
))))
1727 (define-widget 'custom-browse-variable-tag
'custom-group-link
1728 "Show parent in other window when activated."
1731 :action
'custom-browse-variable-tag-action
)
1733 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1734 (let ((parent (widget-get widget
:parent
)))
1735 (customize-variable-other-window (widget-value parent
))))
1737 (define-widget 'custom-browse-face-tag
'custom-group-link
1738 "Show parent in other window when activated."
1741 :action
'custom-browse-face-tag-action
)
1743 (defun custom-browse-face-tag-action (widget &rest ignore
)
1744 (let ((parent (widget-get widget
:parent
)))
1745 (customize-face-other-window (widget-value parent
))))
1747 (defconst custom-browse-alist
'((" " "space")
1753 (defun custom-browse-insert-prefix (prefix)
1754 "Insert PREFIX. On XEmacs convert it to line graphics."
1755 ;; Fixme: do graphics.
1756 (if nil
; (featurep 'xemacs)
1759 (while (not (string-equal prefix
""))
1760 (let ((entry (substring prefix
0 3)))
1761 (setq prefix
(substring prefix
3))
1762 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1763 (name (nth 1 (assoc entry custom-browse-alist
))))
1764 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1765 (overlay-put overlay
'start-open t
)
1766 (overlay-put overlay
'end-open t
)))))
1769 ;;; Modification of Basic Widgets.
1771 ;; We add extra properties to the basic widgets needed here. This is
1772 ;; fine, as long as we are careful to stay within our own namespace.
1774 ;; We want simple widgets to be displayed by default, but complex
1775 ;; widgets to be hidden.
1777 (widget-put (get 'item
'widget-type
) :custom-show t
)
1778 (widget-put (get 'editable-field
'widget-type
)
1779 :custom-show
(lambda (widget value
)
1780 (let ((pp (pp-to-string value
)))
1781 (cond ((string-match "\n" pp
)
1786 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1788 ;;; The `custom-manual' Widget.
1790 (define-widget 'custom-manual
'info-link
1791 "Link to the manual entry for this customization option."
1792 :help-echo
"Read the manual entry for this option."
1793 :keymap custom-mode-link-map
1794 :follow-link
'mouse-face
1795 :button-face
'custom-link
1796 :mouse-face
'highlight
1797 :pressed-face
'highlight
1800 ;;; The `custom-magic' Widget.
1802 (defgroup custom-magic-faces nil
1803 "Faces used by the magic button."
1804 :group
'custom-faces
1805 :group
'custom-buffer
)
1807 (defface custom-invalid
'((((class color
))
1808 (:foreground
"yellow1" :background
"red1"))
1810 (:weight bold
:slant italic
:underline t
)))
1811 "Face used when the customize item is invalid."
1812 :group
'custom-magic-faces
)
1813 ;; backward-compatibility alias
1814 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1816 (defface custom-rogue
'((((class color
))
1817 (:foreground
"pink" :background
"black"))
1820 "Face used when the customize item is not defined for customization."
1821 :group
'custom-magic-faces
)
1822 ;; backward-compatibility alias
1823 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1825 (defface custom-modified
'((((min-colors 88) (class color
))
1826 (:foreground
"white" :background
"blue1"))
1828 (:foreground
"white" :background
"blue"))
1830 (:slant italic
:bold
)))
1831 "Face used when the customize item has been modified."
1832 :group
'custom-magic-faces
)
1833 ;; backward-compatibility alias
1834 (put 'custom-modified-face
'face-alias
'custom-modified
)
1836 (defface custom-set
'((((min-colors 88) (class color
))
1837 (:foreground
"blue1" :background
"white"))
1839 (:foreground
"blue" :background
"white"))
1842 "Face used when the customize item has been set."
1843 :group
'custom-magic-faces
)
1844 ;; backward-compatibility alias
1845 (put 'custom-set-face
'face-alias
'custom-set
)
1847 (defface custom-changed
'((((min-colors 88) (class color
))
1848 (:foreground
"white" :background
"blue1"))
1850 (:foreground
"white" :background
"blue"))
1853 "Face used when the customize item has been changed."
1854 :group
'custom-magic-faces
)
1855 ;; backward-compatibility alias
1856 (put 'custom-changed-face
'face-alias
'custom-changed
)
1858 (defface custom-themed
'((((min-colors 88) (class color
))
1859 (:foreground
"white" :background
"blue1"))
1861 (:foreground
"white" :background
"blue"))
1864 "Face used when the customize item has been set by a theme."
1865 :group
'custom-magic-faces
)
1867 (defface custom-saved
'((t (:underline t
)))
1868 "Face used when the customize item has been saved."
1869 :group
'custom-magic-faces
)
1870 ;; backward-compatibility alias
1871 (put 'custom-saved-face
'face-alias
'custom-saved
)
1873 (defconst custom-magic-alist
1874 '((nil "#" underline
"\
1875 UNINITIALIZED, you should not see this.")
1876 (unknown "?" italic
"\
1877 UNKNOWN, you should not see this.")
1878 (hidden "-" default
"\
1879 HIDDEN, invoke \"Show\" in the previous line to show." "\
1880 group now hidden, invoke \"Show\", above, to show contents.")
1881 (invalid "x" custom-invalid
"\
1882 INVALID, the displayed value cannot be set.")
1883 (modified "*" custom-modified
"\
1884 EDITED, shown value does not take effect until you set or save it." "\
1885 something in this group has been edited but not set.")
1886 (set "+" custom-set
"\
1887 SET for current session only." "\
1888 something in this group has been set but not saved.")
1889 (changed ":" custom-changed
"\
1890 CHANGED outside Customize; operating on it here may be unreliable." "\
1891 something in this group has been changed outside customize.")
1892 (saved "!" custom-saved
"\
1894 something in this group has been set and saved.")
1895 (themed "o" custom-themed
"\
1897 visible group members are all at standard values.")
1898 (rogue "@" custom-rogue
"\
1899 NO CUSTOMIZATION DATA; not intended to be customized." "\
1900 something in this group is not prepared for customization.")
1901 (standard " " nil
"\
1903 visible group members are all at standard values."))
1904 "Alist of customize option states.
1905 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1907 STATE is one of the following symbols:
1910 For internal use, should never occur.
1912 For internal use, should never occur.
1914 This item is not being displayed.
1916 This item is modified, but has an invalid form.
1918 This item is modified, and has a valid form.
1920 This item has been set but not saved.
1922 The current value of this item has been changed outside Customize.
1924 This item is marked for saving.
1926 This item has no customization information.
1928 This item is unchanged from the standard setting.
1930 MAGIC is a string used to present that state.
1932 FACE is a face used to present the state.
1934 ITEM-DESC is a string describing the state for options.
1936 GROUP-DESC is a string describing the state for groups. If this is
1937 left out, ITEM-DESC will be used.
1939 The string %c in either description will be replaced with the
1940 category of the item. These are `group'. `option', and `face'.
1942 The list should be sorted most significant first.")
1944 (defcustom custom-magic-show
'long
1945 "If non-nil, show textual description of the state.
1946 If `long', show a full-line description, not just one word."
1947 :type
'(choice (const :tag
"no" nil
)
1949 (other :tag
"short" short
))
1950 :group
'custom-buffer
)
1952 (defcustom custom-magic-show-hidden
'(option face
)
1953 "Control whether the State button is shown for hidden items.
1954 The value should be a list with the custom categories where the State
1955 button should be visible. Possible categories are `group', `option',
1957 :type
'(set (const group
) (const option
) (const face
))
1958 :group
'custom-buffer
)
1960 (defcustom custom-magic-show-button nil
1961 "Show a \"magic\" button indicating the state of each customization option."
1963 :group
'custom-buffer
)
1965 (define-widget 'custom-magic
'default
1966 "Show and manipulate state for a customization option."
1968 :action
'widget-parent-action
1971 :value-create
'custom-magic-value-create
1972 :value-delete
'widget-children-value-delete
)
1974 (defun widget-magic-mouse-down-action (widget &optional event
)
1975 ;; Non-nil unless hidden.
1976 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1980 (defun custom-magic-value-create (widget)
1981 "Create compact status report for WIDGET."
1982 (let* ((parent (widget-get widget
:parent
))
1983 (state (widget-get parent
:custom-state
))
1984 (hidden (eq state
'hidden
))
1985 (entry (assq state custom-magic-alist
))
1986 (magic (nth 1 entry
))
1987 (face (nth 2 entry
))
1988 (category (widget-get parent
:custom-category
))
1989 (text (or (and (eq category
'group
)
1992 (form (widget-get parent
:custom-form
))
1994 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1995 (setq text
(concat (match-string 1 text
)
1996 (symbol-name category
)
1997 (match-string 2 text
))))
1998 (when (and custom-magic-show
2000 (memq category custom-magic-show-hidden
)))
2002 (when (and (eq category
'group
)
2003 (not (and (eq custom-buffer-style
'links
)
2004 (> (widget-get parent
:custom-level
) 1))))
2005 (insert-char ?\
(* custom-buffer-indent
2006 (widget-get parent
:custom-level
))))
2007 (push (widget-create-child-and-convert
2009 :help-echo
"Change the state of this item."
2010 :format
(if hidden
"%t" "%[%t%]")
2011 :button-prefix
'widget-push-button-prefix
2012 :button-suffix
'widget-push-button-suffix
2013 :mouse-down-action
'widget-magic-mouse-down-action
2017 (let ((start (point)))
2018 (if (eq custom-magic-show
'long
)
2020 (insert (symbol-name state
)))
2021 (cond ((eq form
'lisp
)
2023 ((eq form
'mismatch
)
2024 (insert " (mismatch)")))
2025 (put-text-property start
(point) 'face
'custom-state
))
2027 (when (and (eq category
'group
)
2028 (not (and (eq custom-buffer-style
'links
)
2029 (> (widget-get parent
:custom-level
) 1))))
2030 (insert-char ?\
(* custom-buffer-indent
2031 (widget-get parent
:custom-level
))))
2032 (when custom-magic-show-button
2033 (when custom-magic-show
2034 (let ((indent (widget-get parent
:indent
)))
2036 (insert-char ? indent
))))
2037 (push (widget-create-child-and-convert
2039 :mouse-down-action
'widget-magic-mouse-down-action
2043 :help-echo
"Change the state."
2044 :format
(if hidden
"%t" "%[%t%]")
2045 :tag
(if (memq form
'(lisp mismatch
))
2046 (concat "(" magic
")")
2047 (concat "[" magic
"]")))
2050 (widget-put widget
:children children
)))
2052 (defun custom-magic-reset (widget)
2053 "Redraw the :custom-magic property of WIDGET."
2054 (let ((magic (widget-get widget
:custom-magic
)))
2055 (widget-value-set magic
(widget-value magic
))))
2057 ;;; The `custom' Widget.
2059 (defface custom-button
2060 '((((type x w32 ns
) (class color
)) ; Like default modeline
2061 (:box
(:line-width
2 :style released-button
)
2062 :background
"lightgrey" :foreground
"black"))
2065 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2067 :group
'custom-faces
)
2068 ;; backward-compatibility alias
2069 (put 'custom-button-face
'face-alias
'custom-button
)
2071 (defface custom-button-mouse
2072 '((((type x w32 ns
) (class color
))
2073 (:box
(:line-width
2 :style released-button
)
2074 :background
"grey90" :foreground
"black"))
2076 ;; This is for text terminals that support mouse, like GPM mouse
2077 ;; or the MS-DOS terminal: inverse-video makes the button stand
2078 ;; out on mouse-over.
2079 (:inverse-video t
)))
2080 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2082 :group
'custom-faces
)
2084 (defface custom-button-unraised
2085 '((t :inherit underline
))
2086 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2088 :group
'custom-faces
)
2091 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2093 (setq custom-button-mouse
2094 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2096 (defface custom-button-pressed
2097 '((((type x w32 ns
) (class color
))
2098 (:box
(:line-width
2 :style pressed-button
)
2099 :background
"lightgrey" :foreground
"black"))
2101 (:inverse-video t
)))
2102 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2104 :group
'custom-faces
)
2105 ;; backward-compatibility alias
2106 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2108 (defface custom-button-pressed-unraised
2109 '((default :inherit custom-button-unraised
)
2110 (((class color
) (background light
)) :foreground
"magenta4")
2111 (((class color
) (background dark
)) :foreground
"violet"))
2112 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2114 :group
'custom-faces
)
2116 (setq custom-button-pressed
2117 (if custom-raised-buttons
2118 'custom-button-pressed
2119 'custom-button-pressed-unraised
))
2121 (defface custom-documentation
'((t nil
))
2122 "Face used for documentation strings in customization buffers."
2123 :group
'custom-faces
)
2124 ;; backward-compatibility alias
2125 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2127 (defface custom-state
'((((class color
)
2129 (:foreground
"lime green"))
2132 (:foreground
"dark green"))
2134 "Face used for State descriptions in the customize buffer."
2135 :group
'custom-faces
)
2136 ;; backward-compatibility alias
2137 (put 'custom-state-face
'face-alias
'custom-state
)
2139 (defface custom-link
2140 '((t :inherit link
))
2141 "Face for links in customization buffers."
2143 :group
'custom-faces
)
2145 (define-widget 'custom
'default
2146 "Customize a user option."
2148 :convert-widget
'custom-convert-widget
2149 :notify
'custom-notify
2152 :custom-state
'hidden
2153 :documentation-property
'widget-subclass-responsibility
2154 :value-create
'widget-subclass-responsibility
2155 :value-delete
'widget-children-value-delete
2156 :value-get
'widget-value-value-get
2157 :validate
'widget-children-validate
2158 :match
(lambda (widget value
) (symbolp value
)))
2160 (defun custom-convert-widget (widget)
2161 "Initialize :value and :tag from :args in WIDGET."
2162 (let ((args (widget-get widget
:args
)))
2164 (widget-put widget
:value
(widget-apply widget
2165 :value-to-internal
(car args
)))
2166 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2167 (widget-put widget
:args nil
)))
2170 (defun custom-notify (widget &rest args
)
2171 "Keep track of changes."
2172 (let ((state (widget-get widget
:custom-state
)))
2173 (unless (eq state
'modified
)
2174 (unless (memq state
'(nil unknown hidden
))
2175 (widget-put widget
:custom-state
'modified
))
2176 (custom-magic-reset widget
)
2177 (apply 'widget-default-notify widget args
))))
2179 (defun custom-redraw (widget)
2180 "Redraw WIDGET with current settings."
2181 (let ((line (count-lines (point-min) (point)))
2182 (column (current-column))
2184 (from (marker-position (widget-get widget
:from
)))
2185 (to (marker-position (widget-get widget
:to
))))
2187 (widget-value-set widget
(widget-value widget
))
2188 (custom-redraw-magic widget
))
2189 (when (and (>= pos from
) (<= pos to
))
2194 (goto-line (1+ line
)))
2195 (move-to-column column
))
2198 (defun custom-redraw-magic (widget)
2199 "Redraw WIDGET state with current settings."
2201 (let ((magic (widget-get widget
:custom-magic
)))
2203 (widget-value-set magic
(widget-value magic
))
2204 (when (setq widget
(widget-get widget
:group
))
2205 (custom-group-state-update widget
)))
2207 (setq widget nil
)))))
2210 (defun custom-show (widget value
)
2211 "Non-nil if WIDGET should be shown with VALUE by default."
2212 (let ((show (widget-get widget
:custom-show
)))
2218 (funcall show widget value
)))))
2220 (defun custom-load-widget (widget)
2221 "Load all dependencies for WIDGET."
2222 (custom-load-symbol (widget-value widget
)))
2224 (defun custom-unloaded-symbol-p (symbol)
2225 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2227 (loads (get symbol
'custom-loads
))
2230 (setq load
(car loads
)
2232 (cond ((symbolp load
)
2233 (unless (featurep load
)
2235 ((assoc load load-history
))
2236 ((assoc (locate-library load
) load-history
)
2242 (defun custom-unloaded-widget-p (widget)
2243 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2244 (custom-unloaded-symbol-p (widget-value widget
)))
2246 (defun custom-toggle-hide (widget)
2247 "Toggle visibility of WIDGET."
2248 (custom-load-widget widget
)
2249 (let ((state (widget-get widget
:custom-state
)))
2250 (cond ((memq state
'(invalid modified set
))
2251 (error "There are unsaved changes"))
2253 (widget-put widget
:custom-state
'unknown
))
2255 (widget-put widget
:documentation-shown nil
)
2256 (widget-put widget
:custom-state
'hidden
)))
2257 (custom-redraw widget
)
2260 (defun custom-toggle-parent (widget &rest ignore
)
2261 "Toggle visibility of parent of WIDGET."
2262 (custom-toggle-hide (widget-get widget
:parent
)))
2264 (defun custom-add-see-also (widget &optional prefix
)
2265 "Add `See also ...' to WIDGET if there are any links.
2266 Insert PREFIX first if non-nil."
2267 (let* ((symbol (widget-get widget
:value
))
2268 (links (get symbol
'custom-links
))
2269 (many (> (length links
) 2))
2270 (buttons (widget-get widget
:buttons
))
2271 (indent (widget-get widget
:indent
)))
2274 (insert-char ?\ indent
))
2277 (insert "See also ")
2279 (push (widget-create-child-and-convert
2281 :button-face
'custom-link
2282 :mouse-face
'highlight
2283 :pressed-face
'highlight
)
2285 (setq links
(cdr links
))
2294 (widget-put widget
:buttons buttons
))))
2296 (defun custom-add-parent-links (widget &optional initial-string
2298 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2299 The value is non-nil if any parents were found.
2300 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2301 (let ((name (widget-value widget
))
2302 (type (widget-type widget
))
2303 (buttons (widget-get widget
:buttons
))
2306 (insert (or initial-string
"Groups:"))
2307 (mapatoms (lambda (symbol)
2308 (when (member (list name type
) (get symbol
'custom-group
))
2310 (push (widget-create-child-and-convert
2311 widget
'custom-group-link
2312 :tag
(custom-unlispify-tag-name symbol
)
2315 (setq parents
(cons symbol parents
)))))
2316 (and (null (get name
'custom-links
)) ;No links of its own.
2317 (= (length parents
) 1) ;A single parent.
2318 (let* ((links (delq nil
(mapcar (lambda (w)
2319 (unless (eq (widget-type w
)
2322 (get (car parents
) 'custom-links
))))
2323 (many (> (length links
) 2)))
2326 (left-margin (+ left-margin
2)))
2327 (insert "\n" (or doc-initial-string
"Group documentation:") " ")
2329 (push (widget-create-child-and-convert
2331 :button-face
'custom-link
2332 :mouse-face
'highlight
2333 :pressed-face
'highlight
)
2335 (setq links
(cdr links
))
2344 (fill-region-as-paragraph pt
(point))
2345 (delete-to-left-margin (1+ pt
) (+ pt
2))))))
2348 (delete-region start
(point)))
2349 (widget-put widget
:buttons buttons
)
2352 ;;; The `custom-comment' Widget.
2354 ;; like the editable field
2355 (defface custom-comment
'((((type tty
))
2356 :background
"yellow3"
2357 :foreground
"black")
2358 (((class grayscale color
)
2360 :background
"gray85")
2361 (((class grayscale color
)
2363 :background
"dim gray")
2366 "Face used for comments on variables or faces."
2368 :group
'custom-faces
)
2369 ;; backward-compatibility alias
2370 (put 'custom-comment-face
'face-alias
'custom-comment
)
2372 ;; like font-lock-comment-face
2373 (defface custom-comment-tag
2374 '((((class color
) (background dark
)) (:foreground
"gray80"))
2375 (((class color
) (background light
)) (:foreground
"blue4"))
2376 (((class grayscale
) (background light
))
2377 (:foreground
"DimGray" :weight bold
:slant italic
))
2378 (((class grayscale
) (background dark
))
2379 (:foreground
"LightGray" :weight bold
:slant italic
))
2381 "Face used for the comment tag on variables or faces."
2382 :group
'custom-faces
)
2383 ;; backward-compatibility alias
2384 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2386 (define-widget 'custom-comment
'string
2389 :help-echo
"Edit a comment here."
2390 :sample-face
'custom-comment-tag
2391 :value-face
'custom-comment
2393 :create
'custom-comment-create
)
2395 (defun custom-comment-create (widget)
2396 (let* ((null-comment (equal "" (widget-value widget
))))
2397 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2399 (widget-default-create widget
)
2400 ;; `widget-default-delete' expects markers in these slots --
2401 ;; maybe it shouldn't.
2402 (widget-put widget
:from
(point-marker))
2403 (widget-put widget
:to
(point-marker)))))
2405 (defun custom-comment-hide (widget)
2406 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2408 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2409 ;; the global custom one
2410 (defun custom-comment-show (widget)
2411 (widget-put widget
:comment-shown t
)
2412 (custom-redraw widget
)
2415 (defun custom-comment-invisible-p (widget)
2416 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2418 (not (widget-get widget
:comment-shown
)))))
2420 ;;; The `custom-variable' Widget.
2422 ;; When this was underlined blue, users confused it with a
2423 ;; Mosaic-style hyperlink...
2424 (defface custom-variable-tag
2427 (:foreground
"light blue" :weight bold
))
2428 (((min-colors 88) (class color
)
2430 (:foreground
"blue1" :weight bold
))
2433 (:foreground
"blue" :weight bold
))
2435 "Face used for unpushable variable tags."
2436 :group
'custom-faces
)
2437 ;; backward-compatibility alias
2438 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2440 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2441 "Face used for pushable variable tags."
2442 :group
'custom-faces
)
2443 ;; backward-compatibility alias
2444 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2446 (defcustom custom-variable-default-form
'edit
2447 "Default form of displaying variable values."
2448 :type
'(choice (const edit
)
2450 :group
'custom-buffer
2453 (defun custom-variable-documentation (variable)
2454 "Return documentation of VARIABLE for use in Custom buffer.
2455 Normally just return the docstring. But if VARIABLE automatically
2456 becomes buffer local when set, append a message to that effect."
2457 (if (and (local-variable-if-set-p variable
)
2458 (or (not (local-variable-p variable
))
2460 (local-variable-if-set-p variable
))))
2461 (concat (documentation-property variable
'variable-documentation
)
2463 This variable automatically becomes buffer-local when set outside Custom.
2464 However, setting it through Custom sets the default value.")
2465 (documentation-property variable
'variable-documentation
)))
2467 (define-widget 'custom-variable
'custom
2468 "Customize variable."
2470 :help-echo
"Set or reset this variable."
2471 :documentation-property
#'custom-variable-documentation
2472 :custom-category
'option
2474 :custom-menu
'custom-variable-menu-create
2475 :custom-form nil
; defaults to value of `custom-variable-default-form'
2476 :value-create
'custom-variable-value-create
2477 :action
'custom-variable-action
2478 :custom-set
'custom-variable-set
2479 :custom-mark-to-save
'custom-variable-mark-to-save
2480 :custom-reset-current
'custom-redraw
2481 :custom-reset-saved
'custom-variable-reset-saved
2482 :custom-reset-standard
'custom-variable-reset-standard
2483 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2484 :custom-standard-value
'custom-variable-standard-value
2485 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2487 (defun custom-variable-type (symbol)
2488 "Return a widget suitable for editing the value of SYMBOL.
2489 If SYMBOL has a `custom-type' property, use that.
2490 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2491 try matching its doc string against `custom-guess-doc-alist'."
2492 (let* ((type (or (get symbol
'custom-type
)
2493 (and (not (get symbol
'standard-value
))
2494 (custom-guess-type symbol
))
2496 (options (get symbol
'custom-options
))
2497 (tmp (if (listp type
)
2498 (copy-sequence type
)
2501 (widget-put tmp
:options options
))
2504 (defun custom-variable-value-create (widget)
2505 "Here is where you edit the variable's value."
2506 (custom-load-widget widget
)
2507 (unless (widget-get widget
:custom-form
)
2508 (widget-put widget
:custom-form custom-variable-default-form
))
2509 (let* ((buttons (widget-get widget
:buttons
))
2510 (children (widget-get widget
:children
))
2511 (form (widget-get widget
:custom-form
))
2512 (state (widget-get widget
:custom-state
))
2513 (symbol (widget-get widget
:value
))
2514 (tag (widget-get widget
:tag
))
2515 (type (custom-variable-type symbol
))
2516 (conv (widget-convert type
))
2517 (get (or (get symbol
'custom-get
) 'default-value
))
2518 (prefix (widget-get widget
:custom-prefix
))
2519 (last (widget-get widget
:custom-last
))
2520 (value (if (default-boundp symbol
)
2521 (funcall get symbol
)
2522 (widget-get conv
:value
))))
2523 ;; If the widget is new, the child determines whether it is hidden.
2525 ((custom-show type value
)
2526 (setq state
'unknown
))
2528 (setq state
'hidden
)))
2529 ;; If we don't know the state, see if we need to edit it in lisp form.
2530 (when (eq state
'unknown
)
2531 (unless (widget-apply conv
:match value
)
2532 ;; (widget-apply (widget-convert type) :match value)
2533 (setq form
'mismatch
)))
2534 ;; Now we can create the child widget.
2535 (cond ((eq custom-buffer-style
'tree
)
2536 (insert prefix
(if last
" `--- " " |--- "))
2537 (push (widget-create-child-and-convert
2538 widget
'custom-browse-variable-tag
)
2540 (insert " " tag
"\n")
2541 (widget-put widget
:buttons buttons
))
2543 ;; Indicate hidden value.
2544 (push (widget-create-child-and-convert
2547 :sample-face
'custom-variable-tag
2551 (push (widget-create-child-and-convert
2553 :help-echo
"Show the value of this option."
2555 :action
'custom-toggle-parent
2558 ((memq form
'(lisp mismatch
))
2559 ;; In lisp mode edit the saved value when possible.
2560 (let* ((value (cond ((get symbol
'saved-value
)
2561 (car (get symbol
'saved-value
)))
2562 ((get symbol
'standard-value
)
2563 (car (get symbol
'standard-value
)))
2564 ((default-boundp symbol
)
2565 (custom-quote (funcall get symbol
)))
2567 (custom-quote (widget-get conv
:value
))))))
2568 (insert (symbol-name symbol
) ": ")
2569 (push (widget-create-child-and-convert
2571 :help-echo
"Hide the value of this option."
2574 :action
'custom-toggle-parent
2578 (push (widget-create-child-and-convert
2580 :button-face
'custom-variable-button-face
2582 :tag
(symbol-name symbol
)
2588 (let* ((format (widget-get type
:format
))
2589 tag-format value-format
)
2590 (unless (string-match ":" format
)
2591 (error "Bad format"))
2592 (setq tag-format
(substring format
0 (match-end 0)))
2593 (setq value-format
(substring format
(match-end 0)))
2594 (push (widget-create-child-and-convert
2597 :action
'custom-tag-action
2598 :help-echo
"Change value of this option."
2599 :mouse-down-action
'custom-tag-mouse-down-action
2600 :button-face
'custom-variable-button
2601 :sample-face
'custom-variable-tag
2605 (push (widget-create-child-and-convert
2607 :help-echo
"Hide the value of this option."
2610 :action
'custom-toggle-parent
2613 (push (widget-create-child-and-convert
2615 :format value-format
2618 (unless (eq custom-buffer-style
'tree
)
2619 (unless (eq (preceding-char) ?
\n)
2620 (widget-insert "\n"))
2621 ;; Create the magic button.
2622 (let ((magic (widget-create-child-and-convert
2623 widget
'custom-magic nil
)))
2624 (widget-put widget
:custom-magic magic
)
2625 (push magic buttons
))
2626 (widget-put widget
:buttons buttons
)
2627 ;; Insert documentation.
2628 (widget-put widget
:documentation-indent
3)
2629 (widget-add-documentation-string-button
2630 widget
:visibility-widget
'custom-visibility
)
2632 ;; The comment field
2633 (unless (eq state
'hidden
)
2634 (let* ((comment (get symbol
'variable-comment
))
2636 (widget-create-child-and-convert
2637 widget
'custom-comment
2639 :value
(or comment
""))))
2640 (widget-put widget
:comment-widget comment-widget
)
2641 ;; Don't push it !!! Custom assumes that the first child is the
2643 (setq children
(append children
(list comment-widget
)))))
2644 ;; Update the rest of the properties properties.
2645 (widget-put widget
:custom-form form
)
2646 (widget-put widget
:children children
)
2647 ;; Now update the state.
2648 (if (eq state
'hidden
)
2649 (widget-put widget
:custom-state state
)
2650 (custom-variable-state-set widget
))
2652 (unless (eq state
'hidden
)
2653 (when (eq (widget-get widget
:custom-level
) 1)
2654 (custom-add-parent-links widget
))
2655 (custom-add-see-also widget
)))))
2657 (defun custom-tag-action (widget &rest args
)
2658 "Pass :action to first child of WIDGET's parent."
2659 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2662 (defun custom-tag-mouse-down-action (widget &rest args
)
2663 "Pass :mouse-down-action to first child of WIDGET's parent."
2664 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2665 :mouse-down-action args
))
2667 (defun custom-variable-state-set (widget)
2668 "Set the state of WIDGET."
2669 (let* ((symbol (widget-value widget
))
2670 (get (or (get symbol
'custom-get
) 'default-value
))
2671 (value (if (default-boundp symbol
)
2672 (funcall get symbol
)
2673 (widget-get widget
:value
)))
2674 (comment (get symbol
'variable-comment
))
2677 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2679 (get symbol
'customized-variable-comment
))
2681 (if (condition-case nil
2682 (and (equal value
(eval (car tmp
)))
2683 (equal comment temp
))
2687 ((progn (setq tmp
(get symbol
'theme-value
))
2688 (setq temp
(get symbol
'saved-variable-comment
))
2690 (if (condition-case nil
2691 (and (equal comment temp
)
2694 (car (custom-variable-theme-value
2698 ((eq (caar tmp
) 'user
) 'saved
)
2699 ((eq (caar tmp
) 'changed
)
2700 (if (condition-case nil
2704 (car (get symbol
'standard-value
)))))
2706 ;; The value was originally set outside
2707 ;; custom, but it was set to the standard
2708 ;; value (probably an autoloaded defcustom).
2713 ((setq tmp
(get symbol
'standard-value
))
2714 (if (condition-case nil
2715 (and (equal value
(eval (car tmp
)))
2716 (equal comment nil
))
2721 (widget-put widget
:custom-state state
)))
2723 (defun custom-variable-standard-value (widget)
2724 (get (widget-value widget
) 'standard-value
))
2726 (defvar custom-variable-menu
2727 `(("Set for Current Session" custom-variable-set
2729 (eq (widget-get widget
:custom-state
) 'modified
)))
2730 ;; Note that in all the backquoted code in this file, we test
2731 ;; init-file-user rather than user-init-file. This is in case
2732 ;; cus-edit is loaded by something in site-start.el, because
2733 ;; user-init-file is not set at that stage.
2734 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2735 ,@(when (or custom-file init-file-user
)
2736 '(("Save for Future Sessions" custom-variable-save
2738 (memq (widget-get widget
:custom-state
)
2739 '(modified set changed rogue
))))))
2740 ("Undo Edits" custom-redraw
2742 (and (default-boundp (widget-value widget
))
2743 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2744 ("Reset to Saved" custom-variable-reset-saved
2746 (and (or (get (widget-value widget
) 'saved-value
)
2747 (get (widget-value widget
) 'saved-variable-comment
))
2748 (memq (widget-get widget
:custom-state
)
2749 '(modified set changed rogue
)))))
2750 ,@(when (or custom-file init-file-user
)
2751 '(("Erase Customization" custom-variable-reset-standard
2753 (and (get (widget-value widget
) 'standard-value
)
2754 (memq (widget-get widget
:custom-state
)
2755 '(modified set changed saved rogue
)))))))
2756 ("Set to Backup Value" custom-variable-reset-backup
2758 (get (widget-value widget
) 'backup-value
)))
2759 ("---" ignore ignore
)
2760 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2761 ("---" ignore ignore
)
2762 ("Show Current Value" custom-variable-edit
2764 (eq (widget-get widget
:custom-form
) 'lisp
)))
2765 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2767 (eq (widget-get widget
:custom-form
) 'edit
))))
2768 "Alist of actions for the `custom-variable' widget.
2769 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2770 the menu entry, ACTION is the function to call on the widget when the
2771 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2772 widget as an argument, and returns non-nil if ACTION is valid on that
2773 widget. If FILTER is nil, ACTION is always valid.")
2775 (defun custom-variable-action (widget &optional event
)
2776 "Show the menu for `custom-variable' WIDGET.
2777 Optional EVENT is the location for the menu."
2778 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2779 (custom-toggle-hide widget
)
2780 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2781 (custom-variable-state-set widget
))
2782 (custom-redraw-magic widget
)
2783 (let* ((completion-ignore-case t
)
2784 (answer (widget-choose (concat "Operation on "
2785 (custom-unlispify-tag-name
2786 (widget-get widget
:value
)))
2787 (custom-menu-filter custom-variable-menu
2791 (funcall answer widget
)))))
2793 (defun custom-variable-edit (widget)
2794 "Edit value of WIDGET."
2795 (widget-put widget
:custom-state
'unknown
)
2796 (widget-put widget
:custom-form
'edit
)
2797 (custom-redraw widget
))
2799 (defun custom-variable-edit-lisp (widget)
2800 "Edit the Lisp representation of the value of WIDGET."
2801 (widget-put widget
:custom-state
'unknown
)
2802 (widget-put widget
:custom-form
'lisp
)
2803 (custom-redraw widget
))
2805 (defun custom-variable-set (widget)
2806 "Set the current value for the variable being edited by WIDGET."
2807 (let* ((form (widget-get widget
:custom-form
))
2808 (state (widget-get widget
:custom-state
))
2809 (child (car (widget-get widget
:children
)))
2810 (symbol (widget-value widget
))
2811 (set (or (get symbol
'custom-set
) 'set-default
))
2812 (comment-widget (widget-get widget
:comment-widget
))
2813 (comment (widget-value comment-widget
))
2815 (cond ((eq state
'hidden
)
2816 (error "Cannot set hidden variable"))
2817 ((setq val
(widget-apply child
:validate
))
2818 (goto-char (widget-get val
:from
))
2819 (error "%s" (widget-get val
:error
)))
2820 ((memq form
'(lisp mismatch
))
2821 (when (equal comment
"")
2823 ;; Make the comment invisible by hand if it's empty
2824 (custom-comment-hide comment-widget
))
2825 (custom-variable-backup-value widget
)
2826 (custom-push-theme 'theme-value symbol
'user
2827 'set
(custom-quote (widget-value child
)))
2828 (funcall set symbol
(eval (setq val
(widget-value child
))))
2829 (put symbol
'customized-value
(list val
))
2830 (put symbol
'variable-comment comment
)
2831 (put symbol
'customized-variable-comment comment
))
2833 (when (equal comment
"")
2835 ;; Make the comment invisible by hand if it's empty
2836 (custom-comment-hide comment-widget
))
2837 (custom-variable-backup-value widget
)
2838 (custom-push-theme 'theme-value symbol
'user
2839 'set
(custom-quote (widget-value child
)))
2840 (funcall set symbol
(setq val
(widget-value child
)))
2841 (put symbol
'customized-value
(list (custom-quote val
)))
2842 (put symbol
'variable-comment comment
)
2843 (put symbol
'customized-variable-comment comment
)))
2844 (custom-variable-state-set widget
)
2845 (custom-redraw-magic widget
)))
2847 (defun custom-variable-mark-to-save (widget)
2848 "Set value and mark for saving the variable edited by WIDGET."
2849 (let* ((form (widget-get widget
:custom-form
))
2850 (state (widget-get widget
:custom-state
))
2851 (child (car (widget-get widget
:children
)))
2852 (symbol (widget-value widget
))
2853 (set (or (get symbol
'custom-set
) 'set-default
))
2854 (comment-widget (widget-get widget
:comment-widget
))
2855 (comment (widget-value comment-widget
))
2857 (cond ((eq state
'hidden
)
2858 (error "Cannot set hidden variable"))
2859 ((setq val
(widget-apply child
:validate
))
2860 (goto-char (widget-get val
:from
))
2861 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2862 ((memq form
'(lisp mismatch
))
2863 (when (equal comment
"")
2865 ;; Make the comment invisible by hand if it's empty
2866 (custom-comment-hide comment-widget
))
2867 (put symbol
'saved-value
(list (widget-value child
)))
2868 (custom-push-theme 'theme-value symbol
'user
2869 'set
(custom-quote (widget-value child
)))
2870 (funcall set symbol
(eval (widget-value child
)))
2871 (put symbol
'variable-comment comment
)
2872 (put symbol
'saved-variable-comment comment
))
2874 (when (equal comment
"")
2876 ;; Make the comment invisible by hand if it's empty
2877 (custom-comment-hide comment-widget
))
2878 (put symbol
'saved-value
2879 (list (custom-quote (widget-value child
))))
2880 (custom-push-theme 'theme-value symbol
'user
2881 'set
(custom-quote (widget-value child
)))
2882 (funcall set symbol
(widget-value child
))
2883 (put symbol
'variable-comment comment
)
2884 (put symbol
'saved-variable-comment comment
)))
2885 (put symbol
'customized-value nil
)
2886 (put symbol
'customized-variable-comment nil
)))
2888 (defsubst custom-variable-state-set-and-redraw
(widget)
2889 "Set state of variable widget WIDGET and redraw with current settings."
2890 (custom-variable-state-set widget
)
2891 (custom-redraw-magic widget
))
2893 (defun custom-variable-save (widget)
2894 "Save value of variable edited by widget WIDGET."
2895 (custom-variable-mark-to-save widget
)
2897 (custom-variable-state-set-and-redraw widget
))
2899 (defun custom-variable-reset-saved (widget)
2900 "Restore the saved value for the variable being edited by WIDGET.
2901 This also updates the buffer to show that value.
2902 The value that was current before this operation
2903 becomes the backup value, so you can get it again."
2904 (let* ((symbol (widget-value widget
))
2905 (set (or (get symbol
'custom-set
) 'set-default
))
2906 (value (get symbol
'saved-value
))
2907 (comment (get symbol
'saved-variable-comment
)))
2908 (cond ((or value comment
)
2909 (put symbol
'variable-comment comment
)
2910 (custom-variable-backup-value widget
)
2911 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2913 (funcall set symbol
(eval (car value
)))
2916 (error "No saved value for %s" symbol
)))
2917 (put symbol
'customized-value nil
)
2918 (put symbol
'customized-variable-comment nil
)
2919 (widget-put widget
:custom-state
'unknown
)
2920 ;; This call will possibly make the comment invisible
2921 (custom-redraw widget
)))
2923 (defun custom-variable-mark-to-reset-standard (widget)
2924 "Mark to restore standard setting for the variable edited by widget WIDGET.
2925 If `custom-reset-standard-variables-list' is nil, save, reset and
2926 redraw the widget immediately."
2927 (let* ((symbol (widget-value widget
)))
2928 (if (get symbol
'standard-value
)
2929 (custom-variable-backup-value widget
)
2930 (error "No standard setting known for %S" symbol
))
2931 (put symbol
'variable-comment nil
)
2932 (put symbol
'customized-value nil
)
2933 (put symbol
'customized-variable-comment nil
)
2934 (custom-push-theme 'theme-value symbol
'user
'reset
)
2935 (custom-theme-recalc-variable symbol
)
2936 (if (and custom-reset-standard-variables-list
2937 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2939 (put symbol
'saved-value nil
)
2940 (put symbol
'saved-variable-comment nil
)
2941 ;; Append this to `custom-reset-standard-variables-list' to
2942 ;; have `custom-reset-standard-save-and-update' save setting
2943 ;; to the file, update the widget's state, and redraw it.
2944 (setq custom-reset-standard-variables-list
2945 (cons widget custom-reset-standard-variables-list
)))
2946 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2947 (put symbol
'saved-value nil
)
2948 (put symbol
'saved-variable-comment nil
)
2950 (widget-put widget
:custom-state
'unknown
)
2951 ;; This call will possibly make the comment invisible
2952 (custom-redraw widget
))))
2954 (defun custom-variable-reset-standard (widget)
2955 "Restore standard setting for the variable edited by WIDGET.
2956 This operation eliminates any saved setting for the variable,
2957 restoring it to the state of a variable that has never been customized.
2958 The value that was current before this operation
2959 becomes the backup value, so you can get it again."
2960 (let (custom-reset-standard-variables-list)
2961 (custom-variable-mark-to-reset-standard widget
)))
2963 (defun custom-variable-backup-value (widget)
2964 "Back up the current value for WIDGET's variable.
2965 The backup value is kept in the car of the `backup-value' property."
2966 (let* ((symbol (widget-value widget
))
2967 (get (or (get symbol
'custom-get
) 'default-value
))
2968 (type (custom-variable-type symbol
))
2969 (conv (widget-convert type
))
2970 (value (if (default-boundp symbol
)
2971 (funcall get symbol
)
2972 (widget-get conv
:value
))))
2973 (put symbol
'backup-value
(list value
))))
2975 (defun custom-variable-reset-backup (widget)
2976 "Restore the backup value for the variable being edited by WIDGET.
2977 The value that was current before this operation
2978 becomes the backup value, so you can use this operation repeatedly
2979 to switch between two values."
2980 (let* ((symbol (widget-value widget
))
2981 (set (or (get symbol
'custom-set
) 'set-default
))
2982 (value (get symbol
'backup-value
))
2983 (comment-widget (widget-get widget
:comment-widget
))
2984 (comment (widget-value comment-widget
)))
2987 (custom-variable-backup-value widget
)
2988 (custom-push-theme 'theme-value symbol
'user
'set value
)
2990 (funcall set symbol
(car value
))
2992 (error "No backup value for %s" symbol
))
2993 (put symbol
'customized-value
(list (car value
)))
2994 (put symbol
'variable-comment comment
)
2995 (put symbol
'customized-variable-comment comment
)
2996 (custom-variable-state-set widget
)
2997 ;; This call will possibly make the comment invisible
2998 (custom-redraw widget
)))
3000 ;;; The `custom-visibility' Widget
3002 (define-widget 'custom-visibility
'visibility
3003 "Show or hide a documentation string."
3004 :button-face
'custom-visibility
3005 :pressed-face
'custom-visibility
3006 :mouse-face
'highlight
3007 :pressed-face
'highlight
)
3009 (defface custom-visibility
3010 '((t :height
0.8 :inherit link
))
3011 "Face for the `custom-visibility' widget."
3013 :group
'custom-faces
)
3015 ;;; The `custom-face-edit' Widget.
3017 (define-widget 'custom-face-edit
'checklist
3018 "Edit face attributes."
3022 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3023 :value-to-internal
'custom-face-edit-fix-value
3024 :match
(lambda (widget value
)
3025 (widget-checklist-match widget
3026 (custom-face-edit-fix-value widget value
)))
3027 :convert-widget
'custom-face-edit-convert-widget
3028 :args
(mapcar (lambda (att)
3031 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3032 (list 'const
:format
"" :value
(nth 0 att
))
3034 custom-face-attributes
))
3036 (defun custom-face-edit-fix-value (widget value
)
3037 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3038 Also change :reverse-video to :inverse-video."
3042 (let ((key (car value
))
3043 (val (car (cdr value
))))
3044 (cond ((eq key
:italic
)
3045 (push :slant result
)
3046 (push (if val
'italic
'normal
) result
))
3048 (push :weight result
)
3049 (push (if val
'bold
'normal
) result
))
3050 ((eq key
:reverse-video
)
3051 (push :inverse-video result
)
3055 (push val result
))))
3056 (setq value
(cdr (cdr value
))))
3057 (setq result
(nreverse result
))
3061 (defun custom-face-edit-convert-widget (widget)
3062 "Convert :args as widget types in WIDGET."
3065 :args
(mapcar (lambda (arg)
3067 :deactivate
'custom-face-edit-deactivate
3068 :activate
'custom-face-edit-activate
3069 :delete
'custom-face-edit-delete
))
3070 (widget-get widget
:args
)))
3073 (defun custom-face-edit-deactivate (widget)
3074 "Make face widget WIDGET inactive for user modifications."
3075 (unless (widget-get widget
:inactive
)
3076 (let ((tag (custom-face-edit-attribute-tag widget
))
3077 (from (copy-marker (widget-get widget
:from
)))
3078 (value (widget-value widget
))
3079 (inhibit-read-only t
)
3080 (inhibit-modification-hooks t
))
3083 (widget-default-delete widget
)
3084 (insert tag
": *\n")
3085 (widget-put widget
:inactive
3086 (cons value
(cons from
(- (point) from
))))))))
3088 (defun custom-face-edit-activate (widget)
3089 "Make face widget WIDGET active for user modifications."
3090 (let ((inactive (widget-get widget
:inactive
))
3091 (inhibit-read-only t
)
3092 (inhibit-modification-hooks t
))
3093 (when (consp inactive
)
3095 (goto-char (car (cdr inactive
)))
3096 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3097 (widget-put widget
:inactive nil
)
3098 (widget-apply widget
:create
)
3099 (widget-value-set widget
(car inactive
))
3102 (defun custom-face-edit-delete (widget)
3103 "Remove WIDGET from the buffer."
3104 (let ((inactive (widget-get widget
:inactive
))
3105 (inhibit-read-only t
)
3106 (inhibit-modification-hooks t
))
3108 ;; Widget is alive, we don't have to do anything special
3109 (widget-default-delete widget
)
3110 ;; WIDGET is already deleted because we did so to inactivate it;
3111 ;; now just get rid of the label we put in its place.
3112 (delete-region (car (cdr inactive
))
3113 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3114 (widget-put widget
:inactive nil
))))
3117 (defun custom-face-edit-attribute-tag (widget)
3118 "Return the first :tag property in WIDGET or one of its children."
3119 (let ((tag (widget-get widget
:tag
)))
3120 (or (and (not (equal tag
"")) tag
)
3121 (let ((children (widget-get widget
:children
)))
3122 (while (and (null tag
) children
)
3123 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3126 ;;; The `custom-display' Widget.
3128 (define-widget 'custom-display
'menu-choice
3129 "Select a display type."
3132 :help-echo
"Specify frames where the face attributes should be used."
3133 :args
'((const :tag
"all" t
)
3134 (const :tag
"defaults" default
)
3138 :args
((group :sibling-args
(:help-echo
"\
3139 Only match the specified window systems.")
3140 (const :format
"Type: "
3142 (checklist :inline t
3145 :sibling-args
(:help-echo
"\
3146 The X11 Window System.")
3148 (const :format
"PM "
3149 :sibling-args
(:help-echo
"\
3150 OS/2 Presentation Manager.")
3152 (const :format
"W32 "
3153 :sibling-args
(:help-echo
"\
3156 (const :format
"NS "
3157 :sibling-args
(:help-echo
"\
3158 GNUstep or Macintosh OS Cocoa interface.")
3160 (const :format
"DOS "
3161 :sibling-args
(:help-echo
"\
3164 (const :format
"TTY%n"
3165 :sibling-args
(:help-echo
"\
3166 Plain text terminals.")
3168 (group :sibling-args
(:help-echo
"\
3169 Only match the frames with the specified color support.")
3170 (const :format
"Class: "
3172 (checklist :inline t
3174 (const :format
"Color "
3175 :sibling-args
(:help-echo
"\
3176 Match color frames.")
3178 (const :format
"Grayscale "
3179 :sibling-args
(:help-echo
"\
3180 Match grayscale frames.")
3182 (const :format
"Monochrome%n"
3183 :sibling-args
(:help-echo
"\
3184 Match frames with no color support.")
3186 (group :sibling-args
(:help-echo
"\
3187 The minimum number of colors the frame should support.")
3188 (const :format
"" min-colors
)
3189 (integer :tag
"Minimum number of colors" ))
3190 (group :sibling-args
(:help-echo
"\
3191 Only match frames with the specified intensity.")
3193 Background brightness: "
3195 (checklist :inline t
3197 (const :format
"Light "
3198 :sibling-args
(:help-echo
"\
3199 Match frames with light backgrounds.")
3201 (const :format
"Dark\n"
3202 :sibling-args
(:help-echo
"\
3203 Match frames with dark backgrounds.")
3205 (group :sibling-args
(:help-echo
"\
3206 Only match frames that support the specified face attributes.")
3207 (const :format
"Supports attributes:" supports
)
3208 (custom-face-edit :inline t
:format
"%n%v"))))))
3210 ;;; The `custom-face' Widget.
3212 (defface custom-face-tag
3213 `((t :inherit custom-variable-tag
))
3214 "Face used for face tags."
3215 :group
'custom-faces
)
3216 ;; backward-compatibility alias
3217 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3219 (defcustom custom-face-default-form
'selected
3220 "Default form of displaying face definition."
3221 :type
'(choice (const all
)
3224 :group
'custom-buffer
3227 (define-widget 'custom-face
'custom
3229 :sample-face
'custom-face-tag
3230 :help-echo
"Set or reset this face."
3231 :documentation-property
#'face-doc-string
3232 :value-create
'custom-face-value-create
3233 :action
'custom-face-action
3234 :custom-category
'face
3235 :custom-form nil
; defaults to value of `custom-face-default-form'
3236 :custom-set
'custom-face-set
3237 :custom-mark-to-save
'custom-face-mark-to-save
3238 :custom-reset-current
'custom-redraw
3239 :custom-reset-saved
'custom-face-reset-saved
3240 :custom-reset-standard
'custom-face-reset-standard
3241 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3242 :custom-standard-value
'custom-face-standard-value
3243 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3244 :custom-menu
'custom-face-menu-create
)
3246 (define-widget 'custom-face-all
'editable-list
3247 "An editable list of display specifications and attributes."
3248 :entry-format
"%i %d %v"
3249 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3250 :append-button-args
'(:help-echo
"Append new display specification here.")
3251 :delete-button-args
'(:help-echo
"Delete this display specification.")
3252 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3254 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3255 "Converted version of the `custom-face-all' widget.")
3257 (define-widget 'custom-display-unselected
'item
3258 "A display specification that doesn't match the selected display."
3259 :match
'custom-display-unselected-match
)
3261 (defun custom-display-unselected-match (widget value
)
3262 "Non-nil if VALUE is an unselected display specification."
3263 (not (face-spec-set-match-display value
(selected-frame))))
3265 (define-widget 'custom-face-selected
'group
3266 "Edit the attributes of the selected display in a face specification."
3267 :args
'((choice :inline t
3268 (group :tag
"With Defaults" :inline t
3269 (group (const :tag
"" default
)
3270 (custom-face-edit :tag
" Default\n Attributes"))
3273 (group custom-display-unselected sexp
))
3274 (group (sexp :format
"")
3275 (custom-face-edit :tag
" Overriding\n Attributes"))
3279 (group :tag
"No Defaults" :inline t
3282 (group custom-display-unselected sexp
))
3283 (group (sexp :format
"")
3284 (custom-face-edit :tag
"\n Attributes"))
3291 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3292 "Converted version of the `custom-face-selected' widget.")
3294 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3295 "Return a canonicalized version of SPEC using.
3296 FILTER-INDEX is the index in the entry for each attribute in
3297 `custom-face-attributes' at which the appropriate filter function can be
3298 found, and DEFAULT-FILTER is the filter to apply for attributes that
3300 (mapcar (lambda (entry)
3301 ;; Filter a single face-spec entry
3302 (let ((tests (car entry
))
3304 ;; Handle both old- and new-style attribute syntax
3305 (if (listp (car (cdr entry
)))
3308 (filtered-attrs nil
))
3309 ;; Filter each face attribute
3310 (while unfiltered-attrs
3311 (let* ((attr (pop unfiltered-attrs
))
3312 (pre-filtered-value (pop unfiltered-attrs
))
3314 (or (nth filter-index
(assq attr custom-face-attributes
))
3318 (funcall filter pre-filtered-value
)
3319 pre-filtered-value
)))
3320 (push filtered-value filtered-attrs
)
3321 (push attr filtered-attrs
)))
3323 (list tests filtered-attrs
)))
3326 (defun custom-pre-filter-face-spec (spec)
3327 "Return SPEC changed as necessary for editing by the face customization widget.
3328 SPEC must be a full face spec."
3329 (custom-filter-face-spec spec
2))
3331 (defun custom-post-filter-face-spec (spec)
3332 "Return the customized SPEC in a form suitable for setting the face."
3333 (custom-filter-face-spec spec
3))
3335 (defun custom-face-value-create (widget)
3336 "Create a list of the display specifications for WIDGET."
3337 (let ((buttons (widget-get widget
:buttons
))
3339 (symbol (widget-get widget
:value
))
3340 (tag (widget-get widget
:tag
))
3341 (state (widget-get widget
:custom-state
))
3343 (is-last (widget-get widget
:custom-last
))
3344 (prefix (widget-get widget
:custom-prefix
)))
3346 (setq tag
(prin1-to-string symbol
)))
3347 (cond ((eq custom-buffer-style
'tree
)
3348 (insert prefix
(if is-last
" `--- " " |--- "))
3349 (push (widget-create-child-and-convert
3350 widget
'custom-browse-face-tag
)
3352 (insert " " tag
"\n")
3353 (widget-put widget
:buttons buttons
))
3357 (widget-specify-sample widget begin
(point))
3358 (if (eq custom-buffer-style
'face
)
3360 (if (string-match "face\\'" tag
)
3362 (insert " face: ")))
3364 (push (widget-create-child-and-convert widget
'item
3371 (push (widget-create-child-and-convert
3373 :help-echo
"Hide or show this face."
3376 :action
'custom-toggle-parent
3377 (not (eq state
'hidden
)))
3381 (let ((magic (widget-create-child-and-convert
3382 widget
'custom-magic nil
)))
3383 (widget-put widget
:custom-magic magic
)
3384 (push magic buttons
))
3386 (widget-put widget
:buttons buttons
)
3387 ;; Insert documentation.
3388 (widget-put widget
:documentation-indent
3)
3389 (widget-add-documentation-string-button
3390 widget
:visibility-widget
'custom-visibility
)
3392 ;; The comment field
3393 (unless (eq state
'hidden
)
3394 (let* ((comment (get symbol
'face-comment
))
3396 (widget-create-child-and-convert
3397 widget
'custom-comment
3399 :value
(or comment
""))))
3400 (widget-put widget
:comment-widget comment-widget
)
3401 (push comment-widget children
)))
3403 (unless (eq state
'hidden
)
3404 (when (eq (widget-get widget
:custom-level
) 1)
3405 (custom-add-parent-links widget
))
3406 (custom-add-see-also widget
))
3408 (unless (eq (preceding-char) ?
\n)
3410 (unless (eq state
'hidden
)
3411 (message "Creating face editor...")
3412 (custom-load-widget widget
)
3413 (unless (widget-get widget
:custom-form
)
3414 (widget-put widget
:custom-form custom-face-default-form
))
3415 (let* ((symbol (widget-value widget
))
3416 (spec (or (get symbol
'customized-face
)
3417 (get symbol
'saved-face
)
3418 (get symbol
'face-defface-spec
)
3419 ;; Attempt to construct it.
3420 (list (list t
(custom-face-attributes-get
3421 symbol
(selected-frame))))))
3422 (form (widget-get widget
:custom-form
))
3423 (indent (widget-get widget
:indent
))
3425 ;; If the user has changed this face in some other way,
3426 ;; edit it as the user has specified it.
3427 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3428 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3429 (setq spec
(custom-pre-filter-face-spec spec
))
3430 (setq edit
(widget-create-child-and-convert
3432 (cond ((and (eq form
'selected
)
3433 (widget-apply custom-face-selected
3435 (when indent
(insert-char ?\ indent
))
3436 'custom-face-selected
)
3437 ((and (not (eq form
'lisp
))
3438 (widget-apply custom-face-all
3442 (when indent
(insert-char ?\ indent
))
3445 (custom-face-state-set widget
)
3446 (push edit children
)
3447 (widget-put widget
:children children
))
3448 (message "Creating face editor...done"))))))
3450 (defvar custom-face-menu
3451 `(("Set for Current Session" custom-face-set
)
3452 ,@(when (or custom-file init-file-user
)
3453 '(("Save for Future Sessions" custom-face-save
)))
3454 ("Undo Edits" custom-redraw
3456 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3457 ("Reset to Saved" custom-face-reset-saved
3459 (or (get (widget-value widget
) 'saved-face
)
3460 (get (widget-value widget
) 'saved-face-comment
))))
3461 ,@(when (or custom-file init-file-user
)
3462 '(("Erase Customization" custom-face-reset-standard
3464 (get (widget-value widget
) 'face-defface-spec
)))))
3465 ("---" ignore ignore
)
3466 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3467 ("---" ignore ignore
)
3468 ("For Current Display" custom-face-edit-selected
3470 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3471 ("For All Kinds of Displays" custom-face-edit-all
3473 (not (eq (widget-get widget
:custom-form
) 'all
))))
3474 ("Show Lisp Expression" custom-face-edit-lisp
3476 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3477 "Alist of actions for the `custom-face' widget.
3478 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3479 the menu entry, ACTION is the function to call on the widget when the
3480 menu is selected, and FILTER is a predicate which takes a `custom-face'
3481 widget as an argument, and returns non-nil if ACTION is valid on that
3482 widget. If FILTER is nil, ACTION is always valid.")
3484 (defun custom-face-edit-selected (widget)
3485 "Edit selected attributes of the value of WIDGET."
3486 (widget-put widget
:custom-state
'unknown
)
3487 (widget-put widget
:custom-form
'selected
)
3488 (custom-redraw widget
))
3490 (defun custom-face-edit-all (widget)
3491 "Edit all attributes of the value of WIDGET."
3492 (widget-put widget
:custom-state
'unknown
)
3493 (widget-put widget
:custom-form
'all
)
3494 (custom-redraw widget
))
3496 (defun custom-face-edit-lisp (widget)
3497 "Edit the Lisp representation of the value of WIDGET."
3498 (widget-put widget
:custom-state
'unknown
)
3499 (widget-put widget
:custom-form
'lisp
)
3500 (custom-redraw widget
))
3502 (defun custom-face-state-set (widget)
3503 "Set the state of WIDGET."
3504 (let* ((symbol (widget-value widget
))
3505 (comment (get symbol
'face-comment
))
3509 (setq tmp
(get symbol
'customized-face
))
3510 (setq temp
(get symbol
'customized-face-comment
))
3512 (if (equal temp comment
)
3516 (setq tmp
(get symbol
'saved-face
))
3517 (setq temp
(get symbol
'saved-face-comment
))
3519 (if (equal temp comment
)
3521 ((eq 'user
(caar (get symbol
'theme-face
)))
3523 ((eq 'changed
(caar (get symbol
'theme-face
)))
3527 ((get symbol
'face-defface-spec
)
3528 (if (equal comment nil
)
3533 ;; If the user called set-face-attribute to change the default
3534 ;; for new frames, this face is "set outside of Customize".
3535 (if (and (not (eq state
'rogue
))
3536 (get symbol
'face-modified
))
3537 (setq state
'changed
))
3538 (widget-put widget
:custom-state state
)))
3540 (defun custom-face-action (widget &optional event
)
3541 "Show the menu for `custom-face' WIDGET.
3542 Optional EVENT is the location for the menu."
3543 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3544 (custom-toggle-hide widget
)
3545 (let* ((completion-ignore-case t
)
3546 (symbol (widget-get widget
:value
))
3547 (answer (widget-choose (concat "Operation on "
3548 (custom-unlispify-tag-name symbol
))
3549 (custom-menu-filter custom-face-menu
3553 (funcall answer widget
)))))
3555 (defun custom-face-set (widget)
3556 "Make the face attributes in WIDGET take effect."
3557 (let* ((symbol (widget-value widget
))
3558 (child (car (widget-get widget
:children
)))
3559 (value (custom-post-filter-face-spec (widget-value child
)))
3560 (comment-widget (widget-get widget
:comment-widget
))
3561 (comment (widget-value comment-widget
)))
3562 (when (equal comment
"")
3564 ;; Make the comment invisible by hand if it's empty
3565 (custom-comment-hide comment-widget
))
3566 (put symbol
'customized-face value
)
3567 (custom-push-theme 'theme-face symbol
'user
'set value
)
3568 (if (face-spec-choose value
)
3569 (face-spec-set symbol value t
)
3570 ;; face-set-spec ignores empty attribute lists, so just give it
3571 ;; something harmless instead.
3572 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3573 (put symbol
'customized-face-comment comment
)
3574 (put symbol
'face-comment comment
)
3575 (custom-face-state-set widget
)
3576 (custom-redraw-magic widget
)))
3578 (defun custom-face-mark-to-save (widget)
3579 "Mark for saving the face edited by WIDGET."
3580 (let* ((symbol (widget-value widget
))
3581 (child (car (widget-get widget
:children
)))
3582 (value (custom-post-filter-face-spec (widget-value child
)))
3583 (comment-widget (widget-get widget
:comment-widget
))
3584 (comment (widget-value comment-widget
)))
3585 (when (equal comment
"")
3587 ;; Make the comment invisible by hand if it's empty
3588 (custom-comment-hide comment-widget
))
3589 (custom-push-theme 'theme-face symbol
'user
'set value
)
3590 (if (face-spec-choose value
)
3591 (face-spec-set symbol value t
)
3592 ;; face-set-spec ignores empty attribute lists, so just give it
3593 ;; something harmless instead.
3594 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3595 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3596 (put symbol
'saved-face value
))
3597 (put symbol
'customized-face nil
)
3598 (put symbol
'face-comment comment
)
3599 (put symbol
'customized-face-comment nil
)
3600 (put symbol
'saved-face-comment comment
)))
3602 (defsubst custom-face-state-set-and-redraw
(widget)
3603 "Set state of face widget WIDGET and redraw with current settings."
3604 (custom-face-state-set widget
)
3605 (custom-redraw-magic widget
))
3607 (defun custom-face-save (widget)
3608 "Save the face edited by WIDGET."
3609 (custom-face-mark-to-save widget
)
3611 (custom-face-state-set-and-redraw widget
))
3613 ;; For backward compatibility.
3614 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3617 (defun custom-face-reset-saved (widget)
3618 "Restore WIDGET to the face's default attributes."
3619 (let* ((symbol (widget-value widget
))
3620 (child (car (widget-get widget
:children
)))
3621 (value (get symbol
'saved-face
))
3622 (comment (get symbol
'saved-face-comment
))
3623 (comment-widget (widget-get widget
:comment-widget
)))
3624 (unless (or value comment
)
3625 (error "No saved value for this face"))
3626 (put symbol
'customized-face nil
)
3627 (put symbol
'customized-face-comment nil
)
3628 (custom-push-theme 'theme-face symbol
'user
'set value
)
3629 (face-spec-set symbol value t
)
3630 (put symbol
'face-comment comment
)
3631 (widget-value-set child value
)
3632 ;; This call manages the comment visibility
3633 (widget-value-set comment-widget
(or comment
""))
3634 (custom-face-state-set widget
)
3635 (custom-redraw-magic widget
)))
3637 (defun custom-face-standard-value (widget)
3638 (get (widget-value widget
) 'face-defface-spec
))
3640 (defun custom-face-mark-to-reset-standard (widget)
3641 "Restore widget WIDGET to the face's standard attribute values.
3642 If `custom-reset-standard-faces-list' is nil, save, reset and
3643 redraw the widget immediately."
3644 (let* ((symbol (widget-value widget
))
3645 (child (car (widget-get widget
:children
)))
3646 (value (get symbol
'face-defface-spec
))
3647 (comment-widget (widget-get widget
:comment-widget
)))
3649 (error "No standard setting for this face"))
3650 (put symbol
'customized-face nil
)
3651 (put symbol
'customized-face-comment nil
)
3652 (custom-push-theme 'theme-face symbol
'user
'reset
)
3653 (face-spec-set symbol value t
)
3654 (custom-theme-recalc-face symbol
)
3655 (if (and custom-reset-standard-faces-list
3656 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3659 (put symbol
'saved-face nil
)
3660 (put symbol
'saved-face-comment nil
)
3661 ;; Append this to `custom-reset-standard-faces-list' and have
3662 ;; `custom-reset-standard-save-and-update' save setting to the
3663 ;; file, update the widget's state, and redraw it.
3664 (setq custom-reset-standard-faces-list
3665 (cons widget custom-reset-standard-faces-list
)))
3666 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3667 (put symbol
'saved-face nil
)
3668 (put symbol
'saved-face-comment nil
)
3670 (put symbol
'face-comment nil
)
3671 (widget-value-set child
3672 (custom-pre-filter-face-spec
3673 (list (list t
(custom-face-attributes-get
3675 ;; This call manages the comment visibility
3676 (widget-value-set comment-widget
"")
3677 (custom-face-state-set widget
)
3678 (custom-redraw-magic widget
))))
3680 (defun custom-face-reset-standard (widget)
3681 "Restore WIDGET to the face's standard attribute values.
3682 This operation eliminates any saved attributes for the face,
3683 restoring it to the state of a face that has never been customized."
3684 (let (custom-reset-standard-faces-list)
3685 (custom-face-mark-to-reset-standard widget
)))
3687 ;;; The `face' Widget.
3689 (defvar widget-face-prompt-value-history nil
3690 "History of input to `widget-face-prompt-value'.")
3692 (define-widget 'face
'symbol
3693 "A Lisp face name (with sample)."
3694 :format
"%{%t%}: (%{sample%}) %v"
3697 :sample-face-get
'widget-face-sample-face-get
3698 :notify
'widget-face-notify
3699 :match
(lambda (widget value
) (facep value
))
3700 :complete-function
(lambda ()
3702 (lisp-complete-symbol 'facep
))
3703 :prompt-match
'facep
3704 :prompt-history
'widget-face-prompt-value-history
3705 :validate
(lambda (widget)
3706 (unless (facep (widget-value widget
))
3708 :error
(format "Invalid face: %S"
3709 (widget-value widget
)))
3712 (defun widget-face-sample-face-get (widget)
3713 (let ((value (widget-value widget
)))
3718 (defun widget-face-notify (widget child
&optional event
)
3719 "Update the sample, and notify the parent."
3720 (overlay-put (widget-get widget
:sample-overlay
)
3721 'face
(widget-apply widget
:sample-face-get
))
3722 (widget-default-notify widget child event
))
3725 ;;; The `hook' Widget.
3727 (define-widget 'hook
'list
3728 "An Emacs Lisp hook."
3729 :value-to-internal
(lambda (widget value
)
3730 (if (and value
(symbolp value
))
3733 :match
(lambda (widget value
)
3735 (widget-group-match widget value
)))
3736 ;; Avoid adding undefined functions to the hook, especially for
3737 ;; things like `find-file-hook' or even more basic ones, to avoid
3739 :set
(lambda (symbol value
)
3742 (add-hook symbol elt
))))
3743 :convert-widget
'custom-hook-convert-widget
3746 (defun custom-hook-convert-widget (widget)
3747 ;; Handle `:options'.
3748 (let* ((options (widget-get widget
:options
))
3749 (other `(editable-list :inline t
3750 :entry-format
"%i %d%v"
3751 (function :format
" %v")))
3753 (list `(checklist :inline t
3754 ,@(mapcar (lambda (entry)
3755 `(function-item ,entry
))
3759 (widget-put widget
:args args
)
3762 ;;; The `custom-group-link' Widget.
3764 (define-widget 'custom-group-link
'link
3765 "Show parent in other window when activated."
3766 :button-face
'custom-link
3767 :mouse-face
'highlight
3768 :pressed-face
'highlight
3769 :help-echo
"Create customization buffer for this group."
3770 :keymap custom-mode-link-map
3771 :follow-link
'mouse-face
3772 :action
'custom-group-link-action
)
3774 (defun custom-group-link-action (widget &rest ignore
)
3775 (customize-group (widget-value widget
)))
3777 ;;; The `custom-group' Widget.
3779 (defcustom custom-group-tag-faces nil
3780 ;; In XEmacs, this ought to play games with font size.
3781 ;; Fixme: make it do so in Emacs.
3782 "Face used for group tags.
3783 The first member is used for level 1 groups, the second for level 2,
3784 and so forth. The remaining group tags are shown with `custom-group-tag'."
3785 :type
'(repeat face
)
3786 :group
'custom-faces
)
3788 (defface custom-group-tag-1
3791 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3792 (((min-colors 88) (class color
)
3794 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3797 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3799 "Face used for group tags."
3800 :group
'custom-faces
)
3801 ;; backward-compatibility alias
3802 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3804 (defface custom-group-tag
3807 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3808 (((min-colors 88) (class color
)
3810 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3813 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3815 "Face used for low level group tags."
3816 :group
'custom-faces
)
3817 ;; backward-compatibility alias
3818 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3820 (define-widget 'custom-group
'custom
3823 :sample-face-get
'custom-group-sample-face-get
3824 :documentation-property
'group-documentation
3825 :help-echo
"Set or reset all members of this group."
3826 :value-create
'custom-group-value-create
3827 :action
'custom-group-action
3828 :custom-category
'group
3829 :custom-set
'custom-group-set
3830 :custom-mark-to-save
'custom-group-mark-to-save
3831 :custom-reset-current
'custom-group-reset-current
3832 :custom-reset-saved
'custom-group-reset-saved
3833 :custom-reset-standard
'custom-group-reset-standard
3834 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3835 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3836 :custom-menu
'custom-group-menu-create
)
3838 (defun custom-group-sample-face-get (widget)
3839 ;; Use :sample-face.
3840 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3843 (define-widget 'custom-group-visibility
'visibility
3844 "An indicator and manipulator for hidden group contents."
3845 :create
'custom-group-visibility-create
)
3847 (defun custom-group-visibility-create (widget)
3848 (let ((visible (widget-value widget
)))
3850 (insert "--------")))
3851 (widget-default-create widget
))
3853 (defun custom-group-members (symbol groups-only
)
3854 "Return SYMBOL's custom group members.
3855 If GROUPS-ONLY non-nil, return only those members that are groups."
3856 (if (not groups-only
)
3857 (get symbol
'custom-group
)
3859 (dolist (entry (get symbol
'custom-group
))
3860 (when (eq (nth 1 entry
) 'custom-group
)
3861 (push entry members
)))
3862 (nreverse members
))))
3864 (defun custom-group-value-create (widget)
3865 "Insert a customize group for WIDGET in the current buffer."
3866 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3867 (custom-load-widget widget
))
3868 (let* ((state (widget-get widget
:custom-state
))
3869 (level (widget-get widget
:custom-level
))
3870 ;; (indent (widget-get widget :indent))
3871 (prefix (widget-get widget
:custom-prefix
))
3872 (buttons (widget-get widget
:buttons
))
3873 (tag (widget-get widget
:tag
))
3874 (symbol (widget-value widget
))
3875 (members (custom-group-members symbol
3876 (and (eq custom-buffer-style
'tree
)
3877 custom-browse-only-groups
))))
3878 (cond ((and (eq custom-buffer-style
'tree
)
3880 (or members
(custom-unloaded-widget-p widget
)))
3881 (custom-browse-insert-prefix prefix
)
3882 (push (widget-create-child-and-convert
3883 widget
'custom-browse-visibility
3884 ;; :tag-glyph "plus"
3888 ;; (widget-glyph-insert nil "-- " "horizontal")
3889 (push (widget-create-child-and-convert
3890 widget
'custom-browse-group-tag
)
3892 (insert " " tag
"\n")
3893 (widget-put widget
:buttons buttons
))
3894 ((and (eq custom-buffer-style
'tree
)
3895 (zerop (length members
)))
3896 (custom-browse-insert-prefix prefix
)
3898 ;; (widget-glyph-insert nil "[ ]" "empty")
3899 ;; (widget-glyph-insert nil "-- " "horizontal")
3900 (push (widget-create-child-and-convert
3901 widget
'custom-browse-group-tag
)
3903 (insert " " tag
"\n")
3904 (widget-put widget
:buttons buttons
))
3905 ((eq custom-buffer-style
'tree
)
3906 (custom-browse-insert-prefix prefix
)
3907 (if (zerop (length members
))
3909 (custom-browse-insert-prefix prefix
)
3911 ;; (widget-glyph-insert nil "[ ]" "empty")
3912 ;; (widget-glyph-insert nil "-- " "horizontal")
3913 (push (widget-create-child-and-convert
3914 widget
'custom-browse-group-tag
)
3916 (insert " " tag
"\n")
3917 (widget-put widget
:buttons buttons
))
3918 (push (widget-create-child-and-convert
3919 widget
'custom-browse-visibility
3920 ;; :tag-glyph "minus"
3924 ;; (widget-glyph-insert nil "-\\ " "top")
3925 (push (widget-create-child-and-convert
3926 widget
'custom-browse-group-tag
)
3928 (insert " " tag
"\n")
3929 (widget-put widget
:buttons buttons
)
3930 (message "Creating group...")
3931 (let* ((members (custom-sort-items members
3932 custom-browse-sort-alphabetically
3933 custom-browse-order-groups
))
3934 (prefixes (widget-get widget
:custom-prefixes
))
3935 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3936 (extra-prefix (if (widget-get widget
:custom-last
)
3939 (prefix (concat prefix extra-prefix
))
3942 (setq entry
(car members
)
3943 members
(cdr members
))
3944 (push (widget-create-child-and-convert
3945 widget
(nth 1 entry
)
3947 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3948 :custom-prefixes custom-prefix-list
3949 :custom-level
(1+ level
)
3950 :custom-last
(null members
)
3951 :value
(nth 0 entry
)
3952 :custom-prefix prefix
)
3954 (widget-put widget
:children
(reverse children
)))
3955 (message "Creating group...done")))
3958 ;; Create level indicator.
3960 (if (eq custom-buffer-style
'links
)
3961 (push (widget-create-child-and-convert
3962 widget
'custom-group-link
3966 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3968 (push (widget-create-child-and-convert
3969 widget
'custom-group-visibility
3970 :help-echo
"Show members of this group."
3971 :action
'custom-toggle-parent
3972 (not (eq state
'hidden
)))
3975 ;; Create magic button.
3976 (let ((magic (widget-create-child-and-convert
3977 widget
'custom-magic nil
)))
3978 (widget-put widget
:custom-magic magic
)
3979 (push magic buttons
))
3981 (widget-put widget
:buttons buttons
)
3982 ;; Insert documentation.
3983 (if (and (eq custom-buffer-style
'links
) (> level
1))
3984 (widget-put widget
:documentation-indent
0))
3985 (widget-add-documentation-string-button
3986 widget
:visibility-widget
'custom-visibility
))
3990 ;; Add parent groups references above the group.
3991 (if t
;;; This should test that the buffer
3992 ;;; was made to display a group.
3994 (if (custom-add-parent-links widget
3996 "Parent group documentation:")
3998 ;; Create level indicator.
3999 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4002 (let ((start (point)))
4003 (insert tag
" group: ")
4004 (widget-specify-sample widget start
(point)))
4005 (insert (widget-docstring widget
))
4006 ;; Create visibility indicator.
4007 (unless (eq custom-buffer-style
'links
)
4009 (push (widget-create-child-and-convert
4011 :help-echo
"Hide members of this group."
4012 :action
'custom-toggle-parent
4013 (not (eq state
'hidden
)))
4016 ;; Create more dashes.
4017 ;; Use 76 instead of 75 to compensate for the temporary "<"
4018 ;; added by `widget-insert'.
4019 (insert-char ?-
(- 76 (current-column)
4020 (* custom-buffer-indent level
)))
4022 ;; Create magic button.
4023 (let ((magic (widget-create-child-and-convert
4024 widget
'custom-magic
4027 (widget-put widget
:custom-magic magic
)
4028 (push magic buttons
))
4030 (widget-put widget
:buttons buttons
)
4031 ;; Insert documentation.
4032 (widget-add-documentation-string-button
4033 widget
:visibility-widget
'custom-visibility
)
4036 (if nil
;;; This should test that the buffer
4037 ;;; was not made to display a group.
4039 (insert-char ?\ custom-buffer-indent
)
4040 (custom-add-parent-links widget
)))
4041 (custom-add-see-also widget
4042 (make-string (* custom-buffer-indent level
)
4045 (message "Creating group...")
4046 (let* ((members (custom-sort-items members
4047 custom-buffer-sort-alphabetically
4048 custom-buffer-order-groups
))
4049 (prefixes (widget-get widget
:custom-prefixes
))
4050 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4051 (length (length members
))
4053 (children (mapcar (lambda (entry)
4054 (widget-insert "\n")
4056 Creating group members... %2d%%"
4057 (/ (* 100.0 count
) length
))
4058 (setq count
(1+ count
))
4060 (widget-create-child-and-convert
4061 widget
(nth 1 entry
)
4063 :tag
(custom-unlispify-tag-name
4065 :custom-prefixes custom-prefix-list
4066 :custom-level
(1+ level
)
4067 :value
(nth 0 entry
))
4068 (unless (eq (preceding-char) ?
\n)
4069 (widget-insert "\n"))))
4071 (message "Creating group magic...")
4072 (mapc 'custom-magic-reset children
)
4073 (message "Creating group state...")
4074 (widget-put widget
:children children
)
4075 (custom-group-state-update widget
)
4076 (message "Creating group... done"))
4079 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4080 (insert "\\- " (widget-get widget
:tag
) " group end ")
4081 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
4084 (defvar custom-group-menu
4085 `(("Set for Current Session" custom-group-set
4087 (eq (widget-get widget
:custom-state
) 'modified
)))
4088 ,@(when (or custom-file init-file-user
)
4089 '(("Save for Future Sessions" custom-group-save
4091 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4092 ("Undo Edits" custom-group-reset-current
4094 (memq (widget-get widget
:custom-state
) '(modified))))
4095 ("Reset to Saved" custom-group-reset-saved
4097 (memq (widget-get widget
:custom-state
) '(modified set
))))
4098 ,@(when (or custom-file init-file-user
)
4099 '(("Erase Customization" custom-group-reset-standard
4101 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4102 "Alist of actions for the `custom-group' widget.
4103 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4104 the menu entry, ACTION is the function to call on the widget when the
4105 menu is selected, and FILTER is a predicate which takes a `custom-group'
4106 widget as an argument, and returns non-nil if ACTION is valid on that
4107 widget. If FILTER is nil, ACTION is always valid.")
4109 (defun custom-group-action (widget &optional event
)
4110 "Show the menu for `custom-group' WIDGET.
4111 Optional EVENT is the location for the menu."
4112 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4113 (custom-toggle-hide widget
)
4114 (let* ((completion-ignore-case t
)
4115 (answer (widget-choose (concat "Operation on "
4116 (custom-unlispify-tag-name
4117 (widget-get widget
:value
)))
4118 (custom-menu-filter custom-group-menu
4122 (funcall answer widget
)))))
4124 (defun custom-group-set (widget)
4125 "Set changes in all modified group members."
4126 (dolist (child (widget-get widget
:children
))
4127 (when (eq (widget-get child
:custom-state
) 'modified
)
4128 (widget-apply child
:custom-set
))))
4130 (defun custom-group-mark-to-save (widget)
4131 "Mark all modified group members for saving."
4132 (dolist (child (widget-get widget
:children
))
4133 (when (memq (widget-get child
:custom-state
) '(modified set
))
4134 (widget-apply child
:custom-mark-to-save
))))
4136 (defsubst custom-group-state-set-and-redraw
(widget)
4137 "Set state of group widget WIDGET and redraw with current settings."
4138 (dolist (child (widget-get widget
:children
))
4139 (when (memq (widget-get child
:custom-state
) '(modified set
))
4140 (widget-apply child
:custom-state-set-and-redraw
))))
4142 (defun custom-group-save (widget)
4143 "Save all modified group members."
4144 (custom-group-mark-to-save widget
)
4146 (custom-group-state-set-and-redraw widget
))
4148 (defun custom-group-reset-current (widget)
4149 "Reset all modified group members."
4150 (dolist (child (widget-get widget
:children
))
4151 (when (eq (widget-get child
:custom-state
) 'modified
)
4152 (widget-apply child
:custom-reset-current
))))
4154 (defun custom-group-reset-saved (widget)
4155 "Reset all modified or set group members."
4156 (dolist (child (widget-get widget
:children
))
4157 (when (memq (widget-get child
:custom-state
) '(modified set
))
4158 (widget-apply child
:custom-reset-saved
))))
4160 (defun custom-group-reset-standard (widget)
4161 "Reset all modified, set, or saved group members."
4162 (let ((custom-reset-standard-variables-list '(t))
4163 (custom-reset-standard-faces-list '(t)))
4164 (custom-group-mark-to-reset-standard widget
)
4165 (custom-reset-standard-save-and-update)))
4167 (defun custom-group-mark-to-reset-standard (widget)
4168 "Mark to reset all modified, set, or saved group members."
4169 (dolist (child (widget-get widget
:children
))
4170 (when (memq (widget-get child
:custom-state
)
4171 '(modified set saved
))
4172 (widget-apply child
:custom-mark-to-reset-standard
))))
4174 (defun custom-group-state-update (widget)
4176 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4177 (let* ((children (widget-get widget
:children
))
4178 (states (mapcar (lambda (child)
4179 (widget-get child
:custom-state
))
4181 (magics custom-magic-alist
)
4184 (let ((magic (car (car magics
))))
4185 (if (and (not (eq magic
'hidden
))
4186 (memq magic states
))
4189 (setq magics
(cdr magics
)))))
4190 (widget-put widget
:custom-state found
)))
4191 (custom-magic-reset widget
))
4193 ;;; Reading and writing the custom file.
4196 (defcustom custom-file nil
4197 "File used for storing customization information.
4198 The default is nil, which means to use your init file
4199 as specified by `user-init-file'. If the value is not nil,
4200 it should be an absolute file name.
4202 You can set this option through Custom, if you carefully read the
4203 last paragraph below. However, usually it is simpler to write
4204 something like the following in your init file:
4206 \(setq custom-file \"~/.emacs-custom.el\")
4209 Note that both lines are necessary: the first line tells Custom to
4210 save all customizations in this file, but does not load it.
4212 When you change this variable outside Custom, look in the
4213 previous custom file \(usually your init file) for the
4214 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4215 and copy them (whichever ones you find) to the new custom file.
4216 This will preserve your existing customizations.
4218 If you save this option using Custom, Custom will write all
4219 currently saved customizations, including the new one for this
4220 option itself, into the file you specify, overwriting any
4221 `custom-set-variables' and `custom-set-faces' forms already
4222 present in that file. It will not delete any customizations from
4223 the old custom file. You should do that manually if that is what you
4224 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4225 in your init file, where CUSTOM-FILE is the actual name of the
4226 file. Otherwise, Emacs will not load the file when it starts up,
4227 and hence will not set `custom-file' to that file either."
4228 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4229 (file :format
"%t:%v%d"
4231 "Please read entire docstring below before setting \
4232 this through Custom.
4233 Click on \"More\" \(or position point there and press RETURN)
4234 if only the first line of the docstring is shown."))
4237 (defun custom-file ()
4238 "Return the file name for saving customizations."
4241 (let ((user-init-file user-init-file
)
4243 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4244 (when (null user-init-file
)
4245 (if (or (file-exists-p default-init-file
)
4246 (and (eq system-type
'windows-nt
)
4247 (file-exists-p "~/_emacs")))
4248 ;; Started with -q, i.e. the file containing
4249 ;; Custom settings hasn't been read. Saving
4250 ;; settings there would overwrite other settings.
4251 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4252 (setq user-init-file default-init-file
))
4255 ;; If recentf-mode is non-nil, this is defined.
4256 (declare-function recentf-expand-file-name
"recentf" (name))
4259 (defun custom-save-all ()
4260 "Save all customizations in `custom-file'."
4261 (when (and (null custom-file
) init-file-had-error
)
4262 (error "Cannot save customizations; init file was not fully loaded"))
4263 (let* ((filename (custom-file))
4268 (recentf-expand-file-name (custom-file)))
4271 (old-buffer (find-buffer-visiting filename
))
4274 (with-current-buffer (let ((find-file-visit-truename t
))
4275 (or old-buffer
(find-file-noselect filename
)))
4276 ;; We'll save using file-precious-flag, so avoid destroying
4277 ;; symlinks. (If we're not already visiting the buffer, this is
4278 ;; handled by find-file-visit-truename, above.)
4280 (setq old-buffer-name
(buffer-file-name))
4281 (set-visited-file-name (file-chase-links filename
)))
4283 (unless (eq major-mode
'emacs-lisp-mode
)
4285 (let ((inhibit-read-only t
))
4286 (custom-save-variables)
4287 (custom-save-faces))
4288 (let ((file-precious-flag t
))
4292 (set-visited-file-name old-buffer-name
)
4293 (set-buffer-modified-p nil
))
4294 (kill-buffer (current-buffer))))))
4297 (defun customize-save-customized ()
4298 "Save all user options which have been set in this session."
4300 (mapatoms (lambda (symbol)
4301 (let ((face (get symbol
'customized-face
))
4302 (value (get symbol
'customized-value
))
4303 (face-comment (get symbol
'customized-face-comment
))
4305 (get symbol
'customized-variable-comment
)))
4307 (put symbol
'saved-face face
)
4308 (custom-push-theme 'theme-face symbol
'user
'set value
)
4309 (put symbol
'customized-face nil
))
4311 (put symbol
'saved-value value
)
4312 (custom-push-theme 'theme-value symbol
'user
'set value
)
4313 (put symbol
'customized-value nil
))
4314 (when variable-comment
4315 (put symbol
'saved-variable-comment variable-comment
)
4316 (put symbol
'customized-variable-comment nil
))
4318 (put symbol
'saved-face-comment face-comment
)
4319 (put symbol
'customized-face-comment nil
)))))
4320 ;; We really should update all custom buffers here.
4323 ;; Editing the custom file contents in a buffer.
4325 (defun custom-save-delete (symbol)
4326 "Delete all calls to SYMBOL from the contents of the current buffer.
4327 Leave point at the old location of the first such call,
4328 or (if there were none) at the end of the buffer.
4330 This function does not save the buffer."
4331 (goto-char (point-min))
4332 ;; Skip all whitespace and comments.
4333 (while (forward-comment 1))
4335 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4338 (while t
;; We exit this loop only via throw.
4339 ;; Skip all whitespace and comments.
4340 (while (forward-comment 1))
4341 (let ((start (point))
4342 (sexp (condition-case nil
4343 (read (current-buffer))
4344 (end-of-file (throw 'found nil
)))))
4345 (when (and (listp sexp
)
4346 (eq (car sexp
) symbol
))
4347 (delete-region start
(point))
4349 (setq first
(point)))))))
4352 ;; Move in front of local variables, otherwise long Custom
4353 ;; entries would make them ineffective.
4354 (let ((pos (point-max))
4355 (case-fold-search t
))
4357 (goto-char (point-max))
4358 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4360 (when (search-forward "Local Variables:" nil t
)
4361 (setq pos
(line-beginning-position))))
4364 (defun custom-save-variables ()
4365 "Save all customized variables in `custom-file'."
4367 (custom-save-delete 'custom-set-variables
)
4368 (let ((standard-output (current-buffer))
4369 (saved-list (make-list 1 0))
4371 ;; First create a sorted list of saved variables.
4374 (if (and (get symbol
'saved-value
)
4375 ;; ignore theme values
4376 (or (null (get symbol
'theme-value
))
4377 (eq 'user
(caar (get symbol
'theme-value
)))))
4378 (nconc saved-list
(list symbol
)))))
4379 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4382 (princ "(custom-set-variables
4383 ;; custom-set-variables was added by Custom.
4384 ;; If you edit it by hand, you could mess it up, so be careful.
4385 ;; Your init file should contain only one such instance.
4386 ;; If there is more than one, they won't work right.\n")
4387 (dolist (symbol saved-list
)
4388 (let ((spec (car-safe (get symbol
'theme-value
)))
4389 (value (get symbol
'saved-value
))
4390 (requests (get symbol
'custom-requests
))
4391 (now (and (not (custom-variable-p symbol
))
4393 (eq (get symbol
'force-value
)
4395 (comment (get symbol
'saved-variable-comment
)))
4396 ;; Check REQUESTS for validity.
4397 (dolist (request requests
)
4398 (when (and (symbolp request
) (not (featurep request
)))
4399 (message "Unknown requested feature: %s" request
)
4400 (setq requests
(delq request requests
))))
4401 ;; Is there anything customized about this variable?
4402 (when (or (and spec
(eq (car spec
) 'user
))
4404 (and (null spec
) (get symbol
'saved-value
)))
4405 ;; Output an element for this variable.
4406 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4407 ;; SYMBOL is the variable name.
4408 ;; VALUE-FORM is an expression to return the customized value.
4409 ;; NOW if non-nil means always set the variable immediately
4410 ;; when the customizations are reloaded. This is used
4411 ;; for rogue variables
4412 ;; REQUESTS is a list of packages to load before setting the
4413 ;; variable. Each element of it will be passed to `require'.
4414 ;; COMMENT is whatever comment the user has specified
4415 ;; with the customize facility.
4422 (when (or now requests comment
)
4425 (when (or requests comment
)
4435 (unless (looking-at "\n")
4438 (defun custom-save-faces ()
4439 "Save all customized faces in `custom-file'."
4441 (custom-save-delete 'custom-reset-faces
)
4442 (custom-save-delete 'custom-set-faces
)
4443 (let ((standard-output (current-buffer))
4444 (saved-list (make-list 1 0))
4446 ;; First create a sorted list of saved faces.
4449 (if (and (get symbol
'saved-face
)
4450 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4451 (nconc saved-list
(list symbol
)))))
4452 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4453 ;; The default face must be first, since it affects the others.
4454 (if (memq 'default saved-list
)
4455 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4458 (princ "(custom-set-faces
4459 ;; custom-set-faces was added by Custom.
4460 ;; If you edit it by hand, you could mess it up, so be careful.
4461 ;; Your init file should contain only one such instance.
4462 ;; If there is more than one, they won't work right.\n")
4463 (dolist (symbol saved-list
)
4464 (let ((spec (car-safe (get symbol
'theme-face
)))
4465 (value (get symbol
'saved-face
))
4466 (now (not (or (get symbol
'face-defface-spec
)
4467 (and (not (custom-facep symbol
))
4468 (not (get symbol
'force-face
))))))
4469 (comment (get symbol
'saved-face-comment
)))
4470 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4472 (and (null spec
) (get symbol
'saved-face
)))
4473 ;; Don't print default face here.
4480 (when (or now comment
)
4490 (unless (looking-at "\n")
4493 ;;; The Customize Menu.
4497 (defcustom custom-menu-nesting
2
4498 "Maximum nesting in custom menus."
4500 :group
'custom-menu
)
4502 (defun custom-face-menu-create (widget symbol
)
4503 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4504 (vector (custom-unlispify-menu-entry symbol
)
4505 `(customize-face ',symbol
)
4508 (defun custom-variable-menu-create (widget symbol
)
4509 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4510 (let ((type (get symbol
'custom-type
)))
4511 (unless (listp type
)
4512 (setq type
(list type
)))
4513 (if (and type
(widget-get type
:custom-menu
))
4514 (widget-apply type
:custom-menu symbol
)
4515 (vector (custom-unlispify-menu-entry symbol
)
4516 `(customize-variable ',symbol
)
4519 ;; Add checkboxes to boolean variable entries.
4520 (widget-put (get 'boolean
'widget-type
)
4521 :custom-menu
(lambda (widget symbol
)
4522 (vector (custom-unlispify-menu-entry symbol
)
4523 `(customize-variable ',symbol
)
4525 ':selected symbol
)))
4527 (defun custom-group-menu-create (widget symbol
)
4528 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4529 `( ,(custom-unlispify-menu-entry symbol t
)
4530 :filter
(lambda (&rest junk
)
4531 (let* ((menu (custom-menu-create ',symbol
)))
4532 (if (consp menu
) (cdr menu
) menu
)))))
4535 (defun custom-menu-create (symbol)
4536 "Create menu for customization group SYMBOL.
4537 The menu is in a format applicable to `easy-menu-define'."
4538 (let* ((deactivate-mark nil
)
4539 (item (vector (custom-unlispify-menu-entry symbol
)
4540 `(customize-group ',symbol
)
4542 (if (and (or (not (boundp 'custom-menu-nesting
))
4543 (>= custom-menu-nesting
0))
4545 (custom-load-symbol symbol
)
4546 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4547 (let ((custom-prefix-list (custom-prefix-add symbol
4548 custom-prefix-list
))
4549 (members (custom-sort-items (get symbol
'custom-group
)
4550 custom-menu-sort-alphabetically
4551 custom-menu-order-groups
)))
4552 `(,(custom-unlispify-menu-entry symbol t
)
4555 ,@(mapcar (lambda (entry)
4556 (widget-apply (if (listp (nth 1 entry
))
4558 (list (nth 1 entry
)))
4559 :custom-menu
(nth 0 entry
)))
4564 (defun customize-menu-create (symbol &optional name
)
4565 "Return a customize menu for customization group SYMBOL.
4566 If optional NAME is given, use that as the name of the menu.
4567 Otherwise the menu will be named `Customize'.
4568 The format is suitable for use with `easy-menu-define'."
4570 (setq name
"Customize"))
4572 :filter
(lambda (&rest junk
)
4573 (let ((menu (custom-menu-create ',symbol
)))
4574 (if (consp menu
) (cdr menu
) menu
)))))
4576 ;;; Toolbar and menubar support
4579 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4580 "Menu used in customization buffers."
4581 (nconc (list "Custom"
4582 (customize-menu-create 'customize
))
4583 (mapcar (lambda (arg)
4584 (let ((tag (nth 0 arg
))
4585 (command (nth 1 arg
))
4586 (active (nth 2 arg
))
4588 (vector tag command
:active
(eval active
) :help help
)))
4591 (defvar tool-bar-map
)
4593 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4594 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4595 ;;; we set this up lazily in `Custom-mode'.
4596 (defvar custom-tool-bar-map nil
4597 "Keymap for toolbar in Custom mode.")
4599 ;;; The Custom Mode.
4601 (defun Custom-no-edit (pos &optional event
)
4602 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4604 (error "You can't edit this part of the Custom buffer"))
4606 (defun Custom-newline (pos &optional event
)
4607 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4609 (let ((button (get-char-property pos
'button
)))
4611 (widget-apply-action button event
)
4612 (error "You can't edit this part of the Custom buffer"))))
4614 (defun Custom-goto-parent ()
4615 "Go to the parent group listed at the top of this buffer.
4616 If several parents are listed, go to the first of them."
4619 (goto-char (point-min))
4620 (if (search-forward "\nParent groups: " nil t
)
4621 (let* ((button (get-char-property (point) 'button
))
4622 (parent (downcase (widget-get button
:tag
))))
4623 (customize-group parent
)))))
4625 (defcustom Custom-mode-hook nil
4626 "Hook called when entering Custom mode."
4628 :group
'custom-buffer
)
4630 (defun custom-state-buffer-message (widget)
4631 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4632 (message "To install your edits, invoke [State] and choose the Set operation")))
4634 (define-derived-mode Custom-mode nil
"Custom"
4635 "Major mode for editing customization buffers.
4637 The following commands are available:
4640 Move to next button, link or editable field. \\[widget-forward]
4641 Move to previous button, link or editable field. \\[advertised-widget-backward]
4642 \\<custom-field-keymap>\
4643 Complete content of editable text field. \\[widget-complete]
4644 \\<custom-mode-map>\
4645 Invoke button under the mouse pointer. \\[widget-button-click]
4646 Invoke button under point. \\[widget-button-press]
4647 Set all options from current text. \\[Custom-set]
4648 Make values in current text permanent. \\[Custom-save]
4649 Make text match actual option values. \\[Custom-reset-current]
4650 Reset options to permanent settings. \\[Custom-reset-saved]
4651 Erase customizations; set options
4652 and buffer text to the standard values. \\[Custom-reset-standard]
4654 Entry to this mode calls the value of `Custom-mode-hook'
4655 if that value is non-nil."
4656 (use-local-map custom-mode-map
)
4657 (easy-menu-add Custom-mode-menu
)
4658 (when (display-graphic-p)
4659 (set (make-local-variable 'tool-bar-map
)
4660 (or custom-tool-bar-map
4661 ;; Set up `custom-tool-bar-map'.
4662 (let ((map (make-sparse-keymap)))
4665 (tool-bar-local-item-from-menu
4666 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4668 (setq custom-tool-bar-map map
)))))
4669 (make-local-variable 'custom-options
)
4670 (make-local-variable 'custom-local-buffer
)
4671 (make-local-variable 'widget-documentation-face
)
4672 (setq widget-documentation-face
'custom-documentation
)
4673 (make-local-variable 'widget-button-face
)
4674 (setq widget-button-face custom-button
)
4675 (setq show-trailing-whitespace nil
)
4677 ;; We need this because of the "More" button on docstrings.
4678 ;; Otherwise clicking on "More" can push point offscreen, which
4679 ;; causes the window to recenter on point, which pushes the
4680 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4681 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4683 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4684 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4686 ;; When possible, use relief for buttons, not bracketing. This test
4687 ;; may not be optimal.
4688 (when custom-raised-buttons
4689 (set (make-local-variable 'widget-push-button-prefix
) "")
4690 (set (make-local-variable 'widget-push-button-suffix
) "")
4691 (set (make-local-variable 'widget-link-prefix
) "")
4692 (set (make-local-variable 'widget-link-suffix
) ""))
4693 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4695 (put 'Custom-mode
'mode-class
'special
)
4697 ;; backward-compatibility
4698 (defun custom-mode ()
4699 "Non-interactive variant of `Custom-mode'."
4701 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4702 (put 'custom-mode
'mode-class
'special
)
4703 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4706 '("^No user option defaults have been changed since Emacs "
4708 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4709 "^No customizable items matching "
4710 "^There are unset changes"
4711 "^Cannot set hidden variable"
4712 "^No \\(?:saved\\|backup\\) value for "
4713 "^No standard setting known for "
4714 "^No standard setting for this face"
4715 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4716 (add-to-list 'debug-ignored-errors regexp
))
4722 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4723 ;;; cus-edit.el ends here