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, or (at your option)
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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This file implements the code to create and edit customize buffers.
33 ;; No commands should have names starting with `custom-' because
34 ;; that interferes with completion. Use `customize-' for commands
35 ;; that the user will run with M-x, and `Custom-' for interactive commands.
37 ;; The identity of a customize option is represented by a Lisp symbol.
38 ;; The following values are associated with an option.
40 ;; 0. The current value.
42 ;; This is the value of the option as seen by "the rest of Emacs".
44 ;; Usually extracted by 'default-value', but can be extracted with
45 ;; different means if the option symbol has the 'custom-get'
46 ;; property. Similarly, set-default (or the 'custom-set' property)
49 ;; 1. The widget value.
51 ;; This is the value shown in the widget in a customize buffer.
53 ;; 2. The customized value.
55 ;; This is the last value given to the option through customize.
57 ;; It is stored in the 'customized-value' property of the option, in a
58 ;; cons-cell whose car evaluates to the customized value.
60 ;; 3. The saved value.
62 ;; This is last value saved from customize.
64 ;; It is stored in the 'saved-value' property of the option, in a
65 ;; cons-cell whose car evaluates to the saved value.
67 ;; 4. The standard value.
69 ;; This is the value given in the 'defcustom' declaration.
71 ;; It is stored in the 'standard-value' property of the option, in a
72 ;; cons-cell whose car evaluates to the standard value.
74 ;; 5. The "think" value.
76 ;; This is what customize thinks the current value should be.
78 ;; This is the customized value, if any such value exists, otherwise
79 ;; the saved value, if that exists, and as a last resort the standard
82 ;; The reason for storing values unevaluated: This is so you can have
83 ;; values that depend on the environment. For example, you can have a
84 ;; variable that has one value when Emacs is running under a window
85 ;; system, and another value on a tty. Since the evaluation is only done
86 ;; when the variable is first initialized, this is only relevant for the
87 ;; saved (and standard) values, but affect others values for
90 ;; You can see (and modify and save) this unevaluated value by selecting
91 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
92 ;; give you the unevaluated saved value, if any, otherwise the
93 ;; unevaluated standard value.
95 ;; The possible states for a customize widget are:
99 ;; The state has not been determined yet.
103 ;; The widget value is different from the current value.
107 ;; The current value is different from the "think" value.
111 ;; The "think" value is the customized value.
115 ;; The "think" value is the saved value.
119 ;; The "think" value is the standard value.
123 ;; There is no standard value. This means that the variable was
124 ;; not defined with defcustom, nor handled in cus-start.el. Most
125 ;; standard interactive Custom commands do not let you create a
126 ;; Custom buffer containing such variables. However, such Custom
127 ;; buffers can be created, for instance, by calling
128 ;; `customize-apropos' with a prefix arg or by calling
129 ;; `customize-option' non-interactively.
133 ;; There is no widget value.
137 ;; The widget value is not valid member of the :type specified for the
145 (defvar custom-versions-load-alist
) ; from cus-load
146 (defvar recentf-exclude
) ; from recentf.el
156 (put 'custom-define-hook
'custom-type
'hook
)
157 (put 'custom-define-hook
'standard-value
'(nil))
158 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
160 ;;; Customization Groups.
163 "Customization of the One True Editor."
164 :link
'(custom-manual "(emacs)Top"))
166 ;; Most of these groups are stolen from `finder.el',
167 (defgroup editing nil
168 "Basic text editing facilities."
172 "Abbreviation handling, typing shortcuts, macros."
176 (defgroup matching nil
177 "Various sorts of searching and matching."
180 (defgroup emulations nil
181 "Emulations of other editors."
182 :link
'(custom-manual "(emacs)Emulation")
189 (defgroup outlines nil
190 "Support for hierarchical outlining."
193 (defgroup external nil
194 "Interfacing to external utilities."
197 (defgroup processes nil
198 "Process, subshell, compilation, and job control support."
202 (defgroup convenience nil
203 "Convenience features for faster editing."
206 (defgroup programming nil
207 "Support for programming in other languages."
210 (defgroup languages nil
211 "Specialized modes for editing programming languages."
215 "Lisp support, including Emacs Lisp."
216 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
221 "Support for the C language and related languages."
222 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
223 :link
'(custom-manual "(ccmode)")
231 "Support for object-oriented programming."
234 (defgroup applications nil
235 "Applications written in Emacs."
238 (defgroup calendar nil
239 "Calendar and time management support."
240 :group
'applications
)
243 "Modes for electronic-mail handling."
244 :group
'applications
)
247 "Support for netnews reading and posting."
248 :link
'(custom-manual "(gnus)")
249 :group
'applications
)
252 "Games, jokes and amusements."
253 :group
'applications
)
255 (defgroup development nil
256 "Support for further development of Emacs."
260 "Support for Emacs documentation."
263 (defgroup extensions nil
264 "Emacs Lisp language extensions."
267 (defgroup internal nil
268 "Code for Emacs internals, build process, defaults."
272 "Maintenance aids for the Emacs development group."
276 (defgroup environment nil
277 "Fitting Emacs with its environment."
281 "Communications, networking, remote access to files."
285 (defgroup hardware nil
286 "Support for interfacing with exotic hardware."
289 (defgroup terminals nil
290 "Support for terminal types."
294 "Front-ends/assistants for, or emulators of, UNIX features."
298 "Support code for vms."
302 "Internationalization and alternate character-set support."
303 :link
'(custom-manual "(emacs)International")
308 "The X Window system."
312 "Support for Emacs frames and window systems."
316 "Support editing files of data."
320 "Support editing files."
328 "Code related to the TeX formatter."
329 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
333 "Support for multiple fonts."
336 (defgroup hypermedia nil
337 "Support for links between text or other media types."
341 "Support for on-line help systems."
344 (defgroup multimedia nil
345 "Non-textual support, specifically images and sound."
349 "Code local to your site."
352 (defgroup customize
'((widgets custom-group
))
353 "Customization of the Customization support."
357 (defgroup custom-faces nil
358 "Faces used by customize."
362 (defgroup custom-browse nil
363 "Control customize browser."
367 (defgroup custom-buffer nil
368 "Control customize buffers."
372 (defgroup custom-menu nil
373 "Control customize menus."
378 "Storage allocation and gc for GNU Emacs Lisp interpreter."
379 :tag
"Storage Allocation"
383 "Undoing changes in buffers."
384 :link
'(custom-manual "(emacs)Undo")
387 (defgroup mode-line nil
388 "Content of the modeline."
391 (defgroup editing-basics nil
392 "Most basic editing facilities."
395 (defgroup display nil
396 "How characters are displayed in buffers."
399 (defgroup execute nil
400 "Executing external commands."
403 (defgroup installation nil
404 "The Emacs installation."
412 "Internal Emacs limits."
416 "Debugging Emacs itself."
419 (defgroup minibuffer nil
420 "Controlling the behavior of the minibuffer."
421 :link
'(custom-manual "(emacs)Minibuffer")
424 (defgroup keyboard nil
425 "Input from the keyboard."
429 "Input from the mouse."
433 "Input from the menus."
437 "Handling data from drag and drop."
440 (defgroup auto-save nil
441 "Preventing accidental loss of data."
444 (defgroup processes-basics nil
445 "Basic stuff dealing with processes."
449 "MULE Emacs internationalization."
452 (defgroup windows nil
453 "Windows within a frame."
454 :link
'(custom-manual "(emacs)Windows")
458 "Mac specific features."
459 :link
'(custom-manual "(emacs)Mac OS")
464 ;;; Custom mode keymaps
466 (defvar custom-mode-map
467 ;; This keymap should be dense, but a dense keymap would prevent inheriting
468 ;; "\r" bindings from the parent map.
469 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
470 (let ((map (make-keymap)))
471 (set-keymap-parent map widget-keymap
)
472 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
473 (define-key map
"\^m" 'Custom-newline
)
474 (define-key map
" " 'scroll-up
)
475 (define-key map
"\177" 'scroll-down
)
476 (define-key map
"\C-c\C-c" 'Custom-set
)
477 (define-key map
"\C-x\C-s" 'Custom-save
)
478 (define-key map
"q" 'Custom-buffer-done
)
479 (define-key map
"u" 'Custom-goto-parent
)
480 (define-key map
"n" 'widget-forward
)
481 (define-key map
"p" 'widget-backward
)
483 "Keymap for `custom-mode'.")
485 (defvar custom-mode-link-map
486 (let ((map (make-keymap)))
487 (set-keymap-parent map custom-mode-map
)
488 (define-key map
[down-mouse-2
] nil
)
489 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
490 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
492 "Local keymap for links in `custom-mode'.")
494 (defvar custom-field-keymap
495 (let ((map (copy-keymap widget-field-keymap
)))
496 (define-key map
"\C-c\C-c" 'Custom-set
)
497 (define-key map
"\C-x\C-s" 'Custom-save
)
499 "Keymap used inside editable fields in customization buffers.")
501 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
505 (defun custom-split-regexp-maybe (regexp)
506 "If REGEXP is a string, split it to a list at `\\|'.
507 You can get the original back from the result with:
508 (mapconcat 'identity result \"\\|\")
510 IF REGEXP is not a string, return it unchanged."
512 (split-string regexp
"\\\\|")
515 (defun custom-variable-prompt ()
516 "Prompt for a custom variable, defaulting to the variable at point.
517 Return a list suitable for use in `interactive'."
518 (let* ((v (variable-at-point))
519 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
520 (enable-recursive-minibuffers t
)
522 (setq val
(completing-read
523 (if default
(format "Customize variable (default %s): " default
)
524 "Customize variable: ")
525 obarray
'custom-variable-p t nil nil default
))
526 (list (if (equal val
"")
527 (if (symbolp v
) v nil
)
530 (defun custom-menu-filter (menu widget
)
531 "Convert MENU to the form used by `widget-choose'.
532 MENU should be in the same format as `custom-variable-menu'.
533 WIDGET is the widget to apply the filter entries of MENU on."
535 current name action filter
)
537 (setq current
(car menu
)
539 action
(nth 1 current
)
540 filter
(nth 2 current
)
542 (if (or (null filter
) (funcall filter widget
))
543 (push (cons name action
) result
)
549 (defvar custom-prefix-list nil
550 "List of prefixes that should be ignored by `custom-unlispify'.")
552 (defcustom custom-unlispify-menu-entries t
553 "Display menu entries as words instead of symbols if non-nil."
557 (defcustom custom-unlispify-remove-prefixes nil
558 "Non-nil means remove group prefixes from option names in buffer."
560 :group
'custom-buffer
563 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
564 "Convert SYMBOL into a menu entry."
565 (cond ((not custom-unlispify-menu-entries
)
566 (symbol-name symbol
))
567 ((get symbol
'custom-tag
)
569 (get symbol
'custom-tag
)
570 (concat (get symbol
'custom-tag
) "...")))
572 (with-current-buffer (get-buffer-create " *Custom-Work*")
574 (princ symbol
(current-buffer))
575 (goto-char (point-min))
576 ;; FIXME: Boolean variables are not predicates, so they shouldn't
577 ;; end with `-p'. -stef
578 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
579 ;; (re-search-forward "-p\\'" nil t))
580 ;; (replace-match "" t t)
581 ;; (goto-char (point-min)))
582 (if custom-unlispify-remove-prefixes
583 (let ((prefixes custom-prefix-list
)
586 (setq prefix
(car prefixes
))
587 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
590 (delete-region (point-min) (point)))
591 (setq prefixes
(cdr prefixes
))))))
592 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
593 (capitalize-region (point-min) (point-max))
595 (goto-char (point-max))
599 (defcustom custom-unlispify-tag-names t
600 "Display tag names as words instead of symbols if non-nil."
601 :group
'custom-buffer
604 (defun custom-unlispify-tag-name (symbol)
605 "Convert SYMBOL into a menu entry."
606 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
607 (custom-unlispify-menu-entry symbol t
)))
609 (defun custom-prefix-add (symbol prefixes
)
610 "Add SYMBOL to list of ignored PREFIXES."
611 (cons (or (get symbol
'custom-prefix
)
612 (concat (symbol-name symbol
) "-"))
617 (defcustom custom-guess-name-alist
623 ("-function\\'" function
)
624 ("-functions\\'" (repeat function
))
625 ("-list\\'" (repeat sexp
))
626 ("-alist\\'" (repeat (cons sexp sexp
))))
627 "Alist of (MATCH TYPE).
629 MATCH should be a regexp matching the name of a symbol, and TYPE should
630 be a widget suitable for editing the value of that symbol. The TYPE
631 of the first entry where MATCH matches the name of the symbol will be
634 This is used for guessing the type of variables not declared with
636 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
637 :group
'custom-buffer
)
639 (defcustom custom-guess-doc-alist
640 '(("\\`\\*?Non-nil " boolean
))
641 "Alist of (MATCH TYPE).
643 MATCH should be a regexp matching a documentation string, and TYPE
644 should be a widget suitable for editing the value of a variable with
645 that documentation string. The TYPE of the first entry where MATCH
646 matches the name of the symbol will be used.
648 This is used for guessing the type of variables not declared with
650 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
651 :group
'custom-buffer
)
653 (defun custom-guess-type (symbol)
654 "Guess a widget suitable for editing the value of SYMBOL.
655 This is done by matching SYMBOL with `custom-guess-name-alist' and
656 if that fails, the doc string with `custom-guess-doc-alist'."
657 (let ((name (symbol-name symbol
))
658 (names custom-guess-name-alist
)
661 (setq current
(car names
)
663 (when (string-match (nth 0 current
) name
)
664 (setq found
(nth 1 current
)
667 (let ((doc (documentation-property symbol
'variable-documentation
))
668 (docs custom-guess-doc-alist
))
671 (setq current
(car docs
)
673 (when (string-match (nth 0 current
) doc
)
674 (setq found
(nth 1 current
)
681 (defcustom custom-browse-sort-alphabetically nil
682 "If non-nil, sort customization group alphabetically in `custom-browse'."
684 :group
'custom-browse
)
686 (defcustom custom-browse-order-groups nil
687 "If non-nil, order group members within each customization group.
688 If `first', order groups before non-groups.
689 If `last', order groups after non-groups."
690 :type
'(choice (const first
)
692 (const :tag
"none" nil
))
693 :group
'custom-browse
)
695 (defcustom custom-browse-only-groups nil
696 "If non-nil, show group members only within each customization group."
698 :group
'custom-browse
)
701 (defcustom custom-buffer-sort-alphabetically nil
702 "If non-nil, sort each customization group alphabetically in Custom buffer."
704 :group
'custom-buffer
)
706 (defcustom custom-buffer-order-groups
'last
707 "If non-nil, order group members within each customization group.
708 If `first', order groups before non-groups.
709 If `last', order groups after non-groups."
710 :type
'(choice (const first
)
712 (const :tag
"none" nil
))
713 :group
'custom-buffer
)
716 (defcustom custom-menu-sort-alphabetically nil
717 "If non-nil, sort each customization group alphabetically in menus."
721 (defcustom custom-menu-order-groups
'first
722 "If non-nil, order group members within each customization group.
723 If `first', order groups before non-groups.
724 If `last', order groups after non-groups."
725 :type
'(choice (const first
)
727 (const :tag
"none" nil
))
730 ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'")
732 (defun custom-sort-items (items sort-alphabetically order-groups
)
733 "Return a sorted copy of ITEMS.
734 ITEMS should be a `custom-group' property.
735 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
736 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
737 groups after non-groups, if nil do not order groups at all."
738 (sort (copy-sequence items
)
740 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
741 (namea (nth 0 a
)) (nameb (nth 0 b
)))
742 (cond ((not order-groups
)
743 ;; Since we don't care about A and B order, maybe sort.
744 (when sort-alphabetically
745 (string-lessp namea nameb
)))
746 ((eq typea
'custom-group
)
747 ;; If B is also a group, maybe sort. Otherwise, order A and B.
748 (if (eq typeb
'custom-group
)
749 (when sort-alphabetically
750 (string-lessp namea nameb
))
751 (eq order-groups
'first
)))
752 ((eq typeb
'custom-group
)
753 ;; Since A cannot be a group, order A and B.
754 (eq order-groups
'last
))
756 ;; Since A and B cannot be groups, sort.
757 (string-lessp namea nameb
)))))))
759 ;;; Custom Mode Commands.
761 ;; This variable is used by `custom-tool-bar-map', or directly by
762 ;; `custom-buffer-create-internal' if the toolbar is not present and
763 ;; `custom-buffer-verbose-help' is non-nil.
765 (defvar custom-commands
766 '(("Set for current session" Custom-set t
767 "Apply all settings in this buffer to the current session"
769 ("Save for future sessions" Custom-save
770 (or custom-file user-init-file
)
771 "Apply all settings in this buffer and save them for future Emacs sessions."
773 ("Undo edits" Custom-reset-current t
774 "Restore all settings in this buffer to reflect their current values."
776 ("Reset to saved" Custom-reset-saved t
777 "Restore all settings in this buffer to their saved values (if any)."
779 ("Erase customizations" Custom-reset-standard
780 (or custom-file user-init-file
)
781 "Un-customize all settings in this buffer and save them with standard values."
783 ("Help for Customize" Custom-help t
784 "Get help for using Customize."
786 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
788 (defun Custom-help ()
789 "Read the node on Easy Customization in the Emacs manual."
791 (info "(emacs)Easy Customization"))
793 (defvar custom-reset-menu
794 '(("Undo Edits" . Custom-reset-current
)
795 ("Reset to Saved" . Custom-reset-saved
)
796 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
797 "Alist of actions for the `Reset' button.
798 The key is a string containing the name of the action, the value is a
799 Lisp function taking the widget as an element which will be called
800 when the action is chosen.")
802 (defvar custom-options nil
803 "Customization widgets in the current buffer.")
805 (defun custom-command-apply (fun query
&optional strong-query
)
806 "Call function FUN on all widgets in `custom-options'.
807 If there is more than one widget, ask user for confirmation using
808 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
809 and `yes-or-no-p' otherwise."
810 (if (or (and (= 1 (length custom-options
))
811 (memq (widget-type (car custom-options
))
812 '(custom-variable custom-face
)))
813 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
814 (progn (mapc fun custom-options
) t
)
818 (defun Custom-set (&rest ignore
)
819 "Set the current value of all edited settings in the buffer."
821 (custom-command-apply
823 (when (eq (widget-get child
:custom-state
) 'modified
)
824 (widget-apply child
:custom-set
)))
825 "Set all values according to this buffer? "))
827 (defun Custom-save (&rest ignore
)
828 "Set all edited settings, then save all settings that have been set.
829 If a setting was edited and set before, this saves it. If a
830 setting was merely edited before, this sets it then saves it."
832 (when (custom-command-apply
834 (when (memq (widget-get child
:custom-state
)
835 '(modified set changed rogue
))
836 (widget-apply child
:custom-mark-to-save
)))
837 "Save all settings in this buffer? " t
)
838 ;; Save changes to buffer and redraw.
840 (dolist (child custom-options
)
841 (widget-apply child
:custom-state-set-and-redraw
))))
843 (defun custom-reset (widget &optional event
)
844 "Select item from reset menu."
845 (let* ((completion-ignore-case t
)
846 (answer (widget-choose "Reset settings"
852 (defun Custom-reset-current (&rest ignore
)
853 "Reset all edited settings in the buffer to show their current values."
855 (custom-command-apply
857 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
858 (widget-apply widget
:custom-reset-current
)))
859 "Reset all settings' buffer text to show current values? "))
861 (defun Custom-reset-saved (&rest ignore
)
862 "Reset all edited or set settings in the buffer to their saved value.
863 This also shows the saved values in the buffer."
865 (custom-command-apply
867 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
868 (widget-apply widget
:custom-reset-saved
)))
869 "Reset all settings (current values and buffer text) to saved values? "))
871 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
872 ;; and `custom-group-reset-standard'. If these variables are nil, both
873 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
874 ;; save, reset and redraw the handled widget immediately. Otherwise,
875 ;; they add the widget to the corresponding list and leave it to
876 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
877 (defvar custom-reset-standard-variables-list nil
)
878 (defvar custom-reset-standard-faces-list nil
)
880 ;; The next function was excerpted from `custom-variable-reset-standard'
881 ;; and `custom-face-reset-standard' and is used to avoid calling
882 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
883 ;; one) when erasing all customizations.
884 (defun custom-reset-standard-save-and-update ()
885 "Save settings and redraw after erasing customizations."
886 (when (or (and custom-reset-standard-variables-list
887 (not (eq custom-reset-standard-variables-list
'(t))))
888 (and custom-reset-standard-faces-list
889 (not (eq custom-reset-standard-faces-list
'(t)))))
890 ;; Save settings to file.
892 ;; Set state of and redraw variables.
893 (dolist (widget custom-reset-standard-variables-list
)
894 (unless (eq widget t
)
895 (widget-put widget
:custom-state
'unknown
)
896 (custom-redraw widget
)))
897 ;; Set state of and redraw faces.
898 (dolist (widget custom-reset-standard-faces-list
)
899 (unless (eq widget t
)
900 (let* ((symbol (widget-value widget
))
901 (child (car (widget-get widget
:children
)))
902 (value (get symbol
'face-defface-spec
))
903 (comment-widget (widget-get widget
:comment-widget
)))
904 (put symbol
'face-comment nil
)
905 (widget-value-set child
906 (custom-pre-filter-face-spec
907 (list (list t
(custom-face-attributes-get
909 ;; This call manages the comment visibility
910 (widget-value-set comment-widget
"")
911 (custom-face-state-set widget
)
912 (custom-redraw-magic widget
))))))
914 (defun Custom-reset-standard (&rest ignore
)
915 "Erase all customizations (either current or saved) in current buffer.
916 The immediate result is to restore them to their standard values.
917 This operation eliminates any saved values for the group members,
918 making them as if they had never been customized at all."
920 ;; Bind these temporarily.
921 (let ((custom-reset-standard-variables-list '(t))
922 (custom-reset-standard-faces-list '(t)))
923 (custom-command-apply
925 (and (or (null (widget-get widget
:custom-standard-value
))
926 (widget-apply widget
:custom-standard-value
))
927 (memq (widget-get widget
:custom-state
)
928 '(modified set changed saved rogue
))
929 (widget-apply widget
:custom-mark-to-reset-standard
)))
930 "Erase all customizations for settings in this buffer? " t
)
931 (custom-reset-standard-save-and-update)))
933 ;;; The Customize Commands
935 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
936 "Prompt for a variable and a value and return them as a list.
937 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
938 prompt for the value. The %s escape in PROMPT-VAL is replaced with
939 the name of the variable.
941 If the variable has a `variable-interactive' property, that is used as if
942 it were the arg to `interactive' (which see) to interactively read the value.
944 If the variable has a `custom-type' property, it must be a widget and the
945 `:prompt-value' property of that widget will be used for reading the value.
947 If optional COMMENT argument is non-nil, also prompt for a comment and return
948 it as the third element in the list."
949 (let* ((var (read-variable prompt-var
))
950 (minibuffer-help-form '(describe-variable var
))
952 (let ((prop (get var
'variable-interactive
))
953 (type (get var
'custom-type
))
954 (prompt (format prompt-val var
)))
956 (setq type
(list type
)))
958 ;; Use VAR's `variable-interactive' property
959 ;; as an interactive spec for prompting.
960 (call-interactively `(lambda (arg)
964 (widget-prompt-value type
970 (eval-minibuffer prompt
))))))
973 (read-string "Comment: " (get var
'variable-comment
)))
977 (defun customize-set-value (variable value
&optional comment
)
978 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
980 If VARIABLE has a `variable-interactive' property, that is used as if
981 it were the arg to `interactive' (which see) to interactively read the value.
983 If VARIABLE has a `custom-type' property, it must be a widget and the
984 `:prompt-value' property of that widget will be used for reading the value.
986 If given a prefix (or a COMMENT argument), also prompt for a comment."
987 (interactive (custom-prompt-variable "Set variable: "
991 (cond ((string= comment
"")
992 (put variable
'variable-comment nil
))
994 (put variable
'variable-comment comment
)))
995 (set variable value
))
998 (defun customize-set-variable (variable value
&optional comment
)
999 "Set the default for VARIABLE to VALUE, and return VALUE.
1000 VALUE is a Lisp object.
1002 If VARIABLE has a `custom-set' property, that is used for setting
1003 VARIABLE, otherwise `set-default' is used.
1005 If VARIABLE has a `variable-interactive' property, that is used as if
1006 it were the arg to `interactive' (which see) to interactively read the value.
1008 If VARIABLE has a `custom-type' property, it must be a widget and the
1009 `:prompt-value' property of that widget will be used for reading the value.
1011 If given a prefix (or a COMMENT argument), also prompt for a comment."
1012 (interactive (custom-prompt-variable "Set variable: "
1013 "Set customized value for %s to: "
1014 current-prefix-arg
))
1015 (custom-load-symbol variable
)
1016 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1017 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1018 (put variable
'customized-value
(list (custom-quote value
)))
1019 (cond ((string= comment
"")
1020 (put variable
'variable-comment nil
)
1021 (put variable
'customized-variable-comment nil
))
1023 (put variable
'variable-comment comment
)
1024 (put variable
'customized-variable-comment comment
)))
1028 (defun customize-save-variable (variable value
&optional comment
)
1029 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1032 If VARIABLE has a `custom-set' property, that is used for setting
1033 VARIABLE, otherwise `set-default' is used.
1035 If VARIABLE has a `variable-interactive' property, that is used as if
1036 it were the arg to `interactive' (which see) to interactively read the value.
1038 If VARIABLE has a `custom-type' property, it must be a widget and the
1039 `:prompt-value' property of that widget will be used for reading the value.
1041 If given a prefix (or a COMMENT argument), also prompt for a comment."
1042 (interactive (custom-prompt-variable "Set and save variable: "
1043 "Set and save value for %s as: "
1044 current-prefix-arg
))
1045 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1046 (put variable
'saved-value
(list (custom-quote value
)))
1047 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1048 (cond ((string= comment
"")
1049 (put variable
'variable-comment nil
)
1050 (put variable
'saved-variable-comment nil
))
1052 (put variable
'variable-comment comment
)
1053 (put variable
'saved-variable-comment comment
)))
1054 (put variable
'customized-value nil
)
1055 (put variable
'customized-variable-comment nil
)
1061 "Select a customization buffer which you can use to set user options.
1062 User options are structured into \"groups\".
1063 Initially the top-level group `Emacs' and its immediate subgroups
1064 are shown; the contents of those subgroups are initially hidden."
1066 (customize-group 'emacs
))
1069 (defun customize-mode (mode)
1070 "Customize options related to the current major mode.
1071 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1072 then prompt for the MODE to customize."
1075 (let ((completion-regexp-list '("-mode\\'"))
1076 (group (custom-group-of-mode major-mode
)))
1077 (if (and group
(not current-prefix-arg
))
1080 (completing-read (if group
1081 (format "Major mode (default %s): " major-mode
)
1084 'custom-group-of-mode
1085 t nil nil
(if group
(symbol-name major-mode
))))))))
1086 (customize-group (custom-group-of-mode mode
)))
1088 (defun customize-read-group ()
1089 (let ((completion-ignore-case t
))
1090 (completing-read "Customize group (default emacs): "
1093 (or (and (get symbol
'custom-loads
)
1094 (not (get symbol
'custom-autoload
)))
1095 (get symbol
'custom-group
)))
1099 (defun customize-group (&optional group
)
1100 "Customize GROUP, which must be a customization group."
1101 (interactive (list (customize-read-group)))
1102 (when (stringp group
)
1103 (if (string-equal "" group
)
1105 (setq group
(intern group
))))
1106 (let ((name (format "*Customize Group: %s*"
1107 (custom-unlispify-tag-name group
))))
1108 (if (get-buffer name
)
1109 (pop-to-buffer name
)
1110 (custom-buffer-create
1111 (list (list group
'custom-group
))
1113 (concat " for group "
1114 (custom-unlispify-tag-name group
))))))
1117 (defun customize-group-other-window (&optional group
)
1118 "Customize GROUP, which must be a customization group, in another window."
1119 (interactive (list (customize-read-group)))
1120 (let ((pop-up-windows t
)
1121 (same-window-buffer-names nil
)
1122 (same-window-regexps nil
))
1123 (customize-group group
)))
1126 (defalias 'customize-variable
'customize-option
)
1129 (defun customize-option (symbol)
1130 "Customize SYMBOL, which must be a user option variable."
1131 (interactive (custom-variable-prompt))
1133 (error "No variable specified"))
1134 (let ((basevar (indirect-variable symbol
)))
1135 (custom-buffer-create (list (list basevar
'custom-variable
))
1136 (format "*Customize Option: %s*"
1137 (custom-unlispify-tag-name basevar
)))
1138 (unless (eq symbol basevar
)
1139 (message "`%s' is an alias for `%s'" symbol basevar
))))
1142 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1145 (defun customize-option-other-window (symbol)
1146 "Customize SYMBOL, which must be a user option variable.
1147 Show the buffer in another window, but don't select it."
1148 (interactive (custom-variable-prompt))
1150 (error "No variable specified"))
1151 (let ((basevar (indirect-variable symbol
)))
1152 (custom-buffer-create-other-window
1153 (list (list basevar
'custom-variable
))
1154 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1155 (unless (eq symbol basevar
)
1156 (message "`%s' is an alias for `%s'" symbol basevar
))))
1158 (defvar customize-changed-options-previous-release
"21.1"
1159 "Version for `customize-changed-options' to refer back to by default.")
1161 ;; Packages will update this variable, so make it available.
1163 (defvar customize-package-emacs-version-alist nil
1164 "Alist mapping versions of a package to Emacs versions.
1165 We use this for packages that have their own names, but are released
1166 as part of Emacs itself.
1168 Each elements looks like this:
1170 (PACKAGE (PVERSION . EVERSION)...)
1172 Here PACKAGE is the name of a package, as a symbol. After
1173 PACKAGE come one or more elements, each associating a
1174 package version PVERSION with the first Emacs version
1175 EVERSION in which it (or a subsequent version of PACKAGE)
1176 was first released. Both PVERSION and EVERSION are strings.
1177 PVERSION should be a string that this package used in
1178 the :package-version keyword for `defcustom', `defgroup',
1181 For example, the MH-E package updates this alist as follows:
1183 (add-to-list 'customize-package-emacs-version-alist
1184 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1185 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1186 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1187 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1189 The value of PACKAGE needs to be unique and it needs to match the
1190 PACKAGE value appearing in the :package-version keyword. Since
1191 the user might see the value in a error message, a good choice is
1192 the official name of the package, such as MH-E or Gnus.")
1195 (defalias 'customize-changed
'customize-changed-options
)
1198 (defun customize-changed-options (&optional since-version
)
1199 "Customize all settings whose meanings have changed in Emacs itself.
1200 This includes new user option variables and faces, and new
1201 customization groups, as well as older options and faces whose meanings
1202 or default values have changed since the previous major Emacs release.
1204 With argument SINCE-VERSION (a string), customize all settings
1205 that were added or redefined since that version."
1209 (read-from-minibuffer
1210 (format "Customize options changed, since version (default %s): "
1211 customize-changed-options-previous-release
))))
1212 (if (equal since-version
"")
1213 (setq since-version nil
)
1214 (unless (condition-case nil
1215 (numberp (read since-version
))
1217 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1218 (unless since-version
1219 (setq since-version customize-changed-options-previous-release
))
1221 ;; Load the information for versions since since-version. We use
1222 ;; custom-load-symbol for this.
1223 (put 'custom-versions-load-alist
'custom-loads nil
)
1224 (dolist (elt custom-versions-load-alist
)
1225 (if (customize-version-lessp since-version
(car elt
))
1226 (dolist (load (cdr elt
))
1227 (custom-add-load 'custom-versions-load-alist load
))))
1228 (custom-load-symbol 'custom-versions-load-alist
)
1229 (put 'custom-versions-load-alist
'custom-loads nil
)
1234 (let* ((package-version (get symbol
'custom-package-version
))
1236 (or (and package-version
1237 (customize-package-emacs-version symbol
1239 (get symbol
'custom-version
))))
1241 (when (customize-version-lessp since-version version
)
1242 (if (or (get symbol
'custom-group
)
1243 (get symbol
'group-documentation
))
1244 (push (list symbol
'custom-group
) found
))
1245 (if (custom-variable-p symbol
)
1246 (push (list symbol
'custom-variable
) found
))
1247 (if (custom-facep symbol
)
1248 (push (list symbol
'custom-face
) found
)))))))
1250 (custom-buffer-create (custom-sort-items found t
'first
)
1251 "*Customize Changed Options*")
1252 (error "No user option defaults have been changed since Emacs %s"
1255 (defun customize-package-emacs-version (symbol package-version
)
1256 "Return the Emacs version in which SYMBOL's meaning last changed.
1257 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1258 `customize-package-emacs-version-alist' to find the version of
1259 Emacs that is associated with version VERSION of PACKAGE."
1260 (let (package-versions emacs-version
)
1261 ;; Use message instead of error since we want user to be able to
1262 ;; see the rest of the symbols even if a package author has
1263 ;; botched things up.
1264 (cond ((not (listp package-version
))
1265 (message "Invalid package-version value for %s" symbol
))
1266 ((setq package-versions
(assq (car package-version
)
1267 customize-package-emacs-version-alist
))
1269 (cdr (assoc (cdr package-version
) package-versions
)))
1270 (unless emacs-version
1271 (message "%s version %s not found in %s" symbol
1272 (cdr package-version
)
1273 "customize-package-emacs-version-alist")))
1275 (message "Package %s version %s lists no corresponding Emacs version"
1276 (car package-version
)
1277 (cdr package-version
))))
1280 (defun customize-version-lessp (version1 version2
)
1281 ;; Why are the versions strings, and given that they are, why aren't
1282 ;; they converted to numbers and compared as such here? -- fx
1284 ;; In case someone made a mistake and left out the quotes
1285 ;; in the :version value.
1286 (if (numberp version2
)
1287 (setq version2
(prin1-to-string version2
)))
1288 (let (major1 major2 minor1 minor2
)
1289 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1290 (setq major1
(read (or (match-string 1 version1
)
1292 (setq minor1
(read (or (match-string 3 version1
)
1294 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1295 (setq major2
(read (or (match-string 1 version2
)
1297 (setq minor2
(read (or (match-string 3 version2
)
1299 (or (< major1 major2
)
1300 (and (= major1 major2
)
1301 (< minor1 minor2
)))))
1304 (defun customize-face (&optional face
)
1305 "Customize FACE, which should be a face name or nil.
1306 If FACE is nil, customize all faces. If FACE is actually a
1307 face-alias, customize the face it is aliased to.
1309 Interactively, when point is on text which has a face specified,
1310 suggest to customize that face, if it's customizable."
1311 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1312 (if (member face
'(nil ""))
1313 (setq face
(face-list)))
1314 (if (and (listp face
) (null (cdr face
)))
1315 (setq face
(car face
)))
1317 (custom-buffer-create
1319 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1321 "*Customize Faces*")
1322 ;; If FACE is actually an alias, customize the face it is aliased to.
1323 (if (get face
'face-alias
)
1324 (setq face
(get face
'face-alias
)))
1325 (unless (facep face
)
1326 (error "Invalid face %S" face
))
1327 (custom-buffer-create
1328 (list (list face
'custom-face
))
1329 (format "*Customize Face: %s*"
1330 (custom-unlispify-tag-name face
)))))
1333 (defun customize-face-other-window (&optional face
)
1334 "Show customization buffer for face FACE in other window.
1335 If FACE is actually a face-alias, customize the face it is aliased to.
1337 Interactively, when point is on text which has a face specified,
1338 suggest to customize that face, if it's customizable."
1339 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1340 (let ((pop-up-windows t
)
1341 (same-window-buffer-names nil
)
1342 (same-window-regexps nil
))
1343 (customize-face face
)))
1345 (defalias 'customize-customized
'customize-unsaved
)
1348 (defun customize-unsaved ()
1349 "Customize all user options set in this session but not saved."
1352 (mapatoms (lambda (symbol)
1353 (and (or (get symbol
'customized-face
)
1354 (get symbol
'customized-face-comment
))
1355 (custom-facep symbol
)
1356 (push (list symbol
'custom-face
) found
))
1357 (and (or (get symbol
'customized-value
)
1358 (get symbol
'customized-variable-comment
))
1360 (push (list symbol
'custom-variable
) found
))))
1362 (error "No user options are set but unsaved")
1363 (custom-buffer-create (custom-sort-items found t nil
)
1364 "*Customize Unsaved*"))))
1367 (defun customize-rogue ()
1368 "Customize all user variables modified outside customize."
1371 (mapatoms (lambda (symbol)
1372 (let ((cval (or (get symbol
'customized-value
)
1373 (get symbol
'saved-value
)
1374 (get symbol
'standard-value
))))
1375 (when (and cval
;Declared with defcustom.
1376 (default-boundp symbol
) ;Has a value.
1377 (not (equal (eval (car cval
))
1378 ;; Which does not match customize.
1379 (default-value symbol
))))
1380 (push (list symbol
'custom-variable
) found
)))))
1382 (error "No rogue user options")
1383 (custom-buffer-create (custom-sort-items found t nil
)
1384 "*Customize Rogue*"))))
1386 (defun customize-saved ()
1387 "Customize all already saved user options."
1390 (mapatoms (lambda (symbol)
1391 (and (or (get symbol
'saved-face
)
1392 (get symbol
'saved-face-comment
))
1393 (custom-facep symbol
)
1394 (push (list symbol
'custom-face
) found
))
1395 (and (or (get symbol
'saved-value
)
1396 (get symbol
'saved-variable-comment
))
1398 (push (list symbol
'custom-variable
) found
))))
1400 (error "No saved user options")
1401 (custom-buffer-create (custom-sort-items found t nil
)
1402 "*Customize Saved*"))))
1405 (defun customize-apropos (regexp &optional all
)
1406 "Customize all loaded options, faces and groups matching REGEXP.
1407 If ALL is `options', include only options.
1408 If ALL is `faces', include only faces.
1409 If ALL is `groups', include only groups.
1410 If ALL is t (interactively, with prefix arg), include variables
1411 that are not customizable options, as well as faces and groups
1412 \(but we recommend using `apropos-variable' instead)."
1413 (interactive "sCustomize (regexp): \nP")
1415 (mapatoms (lambda (symbol)
1416 (when (string-match regexp
(symbol-name symbol
))
1417 (when (and (not (memq all
'(faces options
)))
1418 (get symbol
'custom-group
))
1419 (push (list symbol
'custom-group
) found
))
1420 (when (and (not (memq all
'(options groups
)))
1421 (custom-facep symbol
))
1422 (push (list symbol
'custom-face
) found
))
1423 (when (and (not (memq all
'(groups faces
)))
1425 (eq (indirect-variable symbol
) symbol
)
1426 (or (get symbol
'saved-value
)
1427 (custom-variable-p symbol
)
1428 (and (not (memq all
'(nil options
)))
1429 (get symbol
'variable-documentation
))))
1430 (push (list symbol
'custom-variable
) found
)))))
1432 (error "No %s matching %s"
1435 (format "customizable %s"
1436 (if (memq all
'(options faces groups
))
1440 (custom-buffer-create
1441 (custom-sort-items found t custom-buffer-order-groups
)
1442 "*Customize Apropos*"))))
1445 (defun customize-apropos-options (regexp &optional arg
)
1446 "Customize all loaded customizable options matching REGEXP.
1447 With prefix arg, include variables that are not customizable options
1448 \(but it is better to use `apropos-variable' if you want to find those)."
1449 (interactive "sCustomize options (regexp): \nP")
1450 (customize-apropos regexp
(or arg
'options
)))
1453 (defun customize-apropos-faces (regexp)
1454 "Customize all loaded faces matching REGEXP."
1455 (interactive "sCustomize faces (regexp): \n")
1456 (customize-apropos regexp
'faces
))
1459 (defun customize-apropos-groups (regexp)
1460 "Customize all loaded groups matching REGEXP."
1461 (interactive "sCustomize groups (regexp): \n")
1462 (customize-apropos regexp
'groups
))
1466 (defcustom custom-buffer-style
'links
1467 "Control the presentation style for customization buffers.
1468 The value should be a symbol, one of:
1470 brackets: groups nest within each other with big horizontal brackets.
1471 links: groups have links to subgroups."
1472 :type
'(radio (const brackets
)
1474 :group
'custom-buffer
)
1476 (defcustom custom-buffer-done-kill nil
1477 "*Non-nil means exiting a Custom buffer should kill it."
1480 :group
'custom-buffer
)
1482 (defcustom custom-buffer-indent
3
1483 "Number of spaces to indent nested groups."
1485 :group
'custom-buffer
)
1487 (defun custom-get-fresh-buffer (name)
1488 "Get a fresh new buffer with name NAME.
1489 If the buffer already exist, clean it up to be like new.
1490 Beware: it's not quite like new. Good enough for custom, but maybe
1492 ;; To be more complete, we should also kill all permanent-local variables,
1493 ;; but it's not needed for custom.
1494 (let ((buf (get-buffer name
)))
1495 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1496 ;; This will check if the file is not saved.
1500 (get-buffer-create name
)
1501 (with-current-buffer buf
1502 (kill-all-local-variables)
1503 (run-hooks 'kill-buffer-hook
)
1504 ;; Delete overlays before erasing the buffer so the overlay hooks
1505 ;; don't get run spuriously when we erase the buffer.
1506 (let ((ols (overlay-lists)))
1507 (dolist (ol (nconc (car ols
) (cdr ols
)))
1508 (delete-overlay ol
)))
1513 (defun custom-buffer-create (options &optional name description
)
1514 "Create a buffer containing OPTIONS.
1515 Optional NAME is the name of the buffer.
1516 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1517 SYMBOL is a customization option, and WIDGET is a widget for editing
1519 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1520 (custom-buffer-create-internal options description
))
1523 (defun custom-buffer-create-other-window (options &optional name description
)
1524 "Create a buffer containing OPTIONS, and display it in another window.
1525 The result includes selecting that window.
1526 Optional NAME is the name of the buffer.
1527 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1528 SYMBOL is a customization option, and WIDGET is a widget for editing
1530 (unless name
(setq name
"*Customization*"))
1531 (let ((pop-up-windows t
)
1532 (same-window-buffer-names nil
)
1533 (same-window-regexps nil
))
1534 (pop-to-buffer (custom-get-fresh-buffer name
))
1535 (custom-buffer-create-internal options description
)))
1537 (defcustom custom-reset-button-menu nil
1538 "If non-nil, only show a single reset button in customize buffers.
1539 This button will have a menu with all three reset operations."
1541 :group
'custom-buffer
)
1543 (defcustom custom-buffer-verbose-help t
1544 "If non-nil, include explanatory text in the customization buffer."
1546 :group
'custom-buffer
)
1548 (defun Custom-buffer-done (&rest ignore
)
1549 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1551 (quit-window custom-buffer-done-kill
))
1553 (defvar custom-button nil
1554 "Face used for buttons in customization buffers.")
1556 (defvar custom-button-mouse nil
1557 "Mouse face used for buttons in customization buffers.")
1559 (defvar custom-button-pressed nil
1560 "Face used for pressed buttons in customization buffers.")
1562 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1563 '(("unspecified" . unspecified
))))
1564 "If non-nil, indicate active buttons in a `raised-button' style.
1565 Otherwise use brackets."
1568 :group
'custom-buffer
1569 :set
(lambda (variable value
)
1570 (custom-set-default variable value
)
1572 (if value
'custom-button
'custom-button-unraised
))
1573 (setq custom-button-mouse
1574 (if value
'custom-button-mouse
'highlight
))
1575 (setq custom-button-pressed
1577 'custom-button-pressed
1578 'custom-button-pressed-unraised
))))
1580 (defun custom-buffer-create-internal (options &optional description
)
1582 (let ((init-file (or custom-file user-init-file
)))
1583 ;; Insert verbose help at the top of the custom buffer.
1584 (when custom-buffer-verbose-help
1585 (widget-insert "Editing a setting changes only the text in this buffer."
1588 To apply your changes, use the Save or Set buttons.
1589 Saving a change normally works by editing your init file."
1591 Currently, these settings cannot be saved for future Emacs sessions,
1592 possibly because you started Emacs with `-q'.")
1593 "\nFor details, see ")
1594 (widget-create 'custom-manual
1595 :tag
"Saving Customizations"
1596 "(emacs)Saving Customizations")
1597 (widget-insert " in the ")
1598 (widget-create 'custom-manual
1600 :help-echo
"Read the Emacs manual."
1602 (widget-insert "."))
1603 ;; Insert custom command buttons if the toolbar is not in use.
1605 (widget-insert "\n")
1606 ;; tool-bar is not dumped in builds without x.
1607 (when (not (and (bound-and-true-p tool-bar-mode
) (display-graphic-p)))
1608 (if custom-buffer-verbose-help
1610 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1611 (let ((button (lambda (tag action active help icon
)
1614 (widget-create 'push-button
:tag tag
1615 :help-echo help
:action action
))))
1616 (commands custom-commands
))
1617 (apply button
(pop commands
)) ; Set for current session
1618 (apply button
(pop commands
)) ; Save for future sessions
1619 (if custom-reset-button-menu
1622 (widget-create 'push-button
1624 :help-echo
"Show a menu with reset operations."
1625 :mouse-down-action
'ignore
1626 :action
'custom-reset
))
1627 (widget-insert "\n")
1628 (apply button
(pop commands
)) ; Undo edits
1629 (apply button
(pop commands
)) ; Reset to saved
1630 (apply button
(pop commands
)) ; Erase customization
1632 (pop commands
) ; Help (omitted)
1633 (apply button
(pop commands
))))) ; Exit
1634 (widget-insert "\n\n"))
1636 ;; Now populate the custom buffer.
1637 (message "Creating customization items...")
1638 (buffer-disable-undo)
1639 (setq custom-options
1640 (if (= (length options
) 1)
1641 (mapcar (lambda (entry)
1642 (widget-create (nth 1 entry
)
1643 :documentation-shown t
1644 :custom-state
'unknown
1645 :tag
(custom-unlispify-tag-name
1647 :value
(nth 0 entry
)))
1650 (length (length options
)))
1651 (mapcar (lambda (entry)
1653 (message "Creating customization items ...%2d%%"
1654 (/ (* 100.0 count
) length
))
1655 (widget-create (nth 1 entry
)
1656 :tag
(custom-unlispify-tag-name
1658 :value
(nth 0 entry
))
1659 (setq count
(1+ count
))
1660 (unless (eq (preceding-char) ?
\n)
1661 (widget-insert "\n"))
1662 (widget-insert "\n")))
1664 (unless (eq (preceding-char) ?
\n)
1665 (widget-insert "\n"))
1666 (message "Creating customization items ...done")
1667 (message "Resetting customization items...")
1668 (unless (eq custom-buffer-style
'tree
)
1669 (mapc 'custom-magic-reset custom-options
))
1670 (message "Resetting customization items...done")
1671 (message "Creating customization setup...")
1673 (buffer-enable-undo)
1674 (goto-char (point-min))
1675 (message "Creating customization setup...done"))
1677 ;;; The Tree Browser.
1680 (defun customize-browse (&optional group
)
1681 "Create a tree browser for the customize hierarchy."
1684 (setq group
'emacs
))
1685 (let ((name "*Customize Browser*"))
1686 (pop-to-buffer (custom-get-fresh-buffer name
)))
1688 (widget-insert (format "\
1689 %s buttons; type RET or click mouse-1
1690 on a button to invoke its action.
1691 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1692 (if custom-raised-buttons
1693 "`Raised' text indicates"
1694 "Square brackets indicate")))
1697 (if custom-browse-only-groups
1699 Invoke the [Group] button below to edit that item in another window.\n\n")
1700 (widget-insert "Invoke the ")
1701 (widget-create 'item
1704 :tag-glyph
"folder")
1705 (widget-insert ", ")
1706 (widget-create 'item
1710 (widget-insert ", and ")
1711 (widget-create 'item
1714 :tag-glyph
"option")
1715 (widget-insert " buttons below to edit that
1716 item in another window.\n\n"))
1717 (let ((custom-buffer-style 'tree
))
1718 (widget-create 'custom-group
1720 :custom-state
'unknown
1721 :tag
(custom-unlispify-tag-name group
)
1724 (goto-char (point-min)))
1726 (define-widget 'custom-browse-visibility
'item
1727 "Control visibility of items in the customize tree browser."
1729 :action
'custom-browse-visibility-action
)
1731 (defun custom-browse-visibility-action (widget &rest ignore
)
1732 (let ((custom-buffer-style 'tree
))
1733 (custom-toggle-parent widget
)))
1735 (define-widget 'custom-browse-group-tag
'custom-group-link
1736 "Show parent in other window when activated."
1739 :action
'custom-browse-group-tag-action
)
1741 (defun custom-browse-group-tag-action (widget &rest ignore
)
1742 (let ((parent (widget-get widget
:parent
)))
1743 (customize-group-other-window (widget-value parent
))))
1745 (define-widget 'custom-browse-variable-tag
'custom-group-link
1746 "Show parent in other window when activated."
1749 :action
'custom-browse-variable-tag-action
)
1751 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1752 (let ((parent (widget-get widget
:parent
)))
1753 (customize-variable-other-window (widget-value parent
))))
1755 (define-widget 'custom-browse-face-tag
'custom-group-link
1756 "Show parent in other window when activated."
1759 :action
'custom-browse-face-tag-action
)
1761 (defun custom-browse-face-tag-action (widget &rest ignore
)
1762 (let ((parent (widget-get widget
:parent
)))
1763 (customize-face-other-window (widget-value parent
))))
1765 (defconst custom-browse-alist
'((" " "space")
1771 (defun custom-browse-insert-prefix (prefix)
1772 "Insert PREFIX. On XEmacs convert it to line graphics."
1773 ;; Fixme: do graphics.
1774 (if nil
; (featurep 'xemacs)
1777 (while (not (string-equal prefix
""))
1778 (let ((entry (substring prefix
0 3)))
1779 (setq prefix
(substring prefix
3))
1780 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1781 (name (nth 1 (assoc entry custom-browse-alist
))))
1782 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1783 (overlay-put overlay
'start-open t
)
1784 (overlay-put overlay
'end-open t
)))))
1787 ;;; Modification of Basic Widgets.
1789 ;; We add extra properties to the basic widgets needed here. This is
1790 ;; fine, as long as we are careful to stay within out own namespace.
1792 ;; We want simple widgets to be displayed by default, but complex
1793 ;; widgets to be hidden.
1795 (widget-put (get 'item
'widget-type
) :custom-show t
)
1796 (widget-put (get 'editable-field
'widget-type
)
1797 :custom-show
(lambda (widget value
)
1798 (let ((pp (pp-to-string value
)))
1799 (cond ((string-match "\n" pp
)
1804 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1806 ;;; The `custom-manual' Widget.
1808 (define-widget 'custom-manual
'info-link
1809 "Link to the manual entry for this customization option."
1810 :help-echo
"Read the manual entry for this option."
1811 :keymap custom-mode-link-map
1812 :follow-link
'mouse-face
1813 :button-face
'custom-link
1814 :mouse-face
'highlight
1815 :pressed-face
'highlight
1818 ;;; The `custom-magic' Widget.
1820 (defgroup custom-magic-faces nil
1821 "Faces used by the magic button."
1822 :group
'custom-faces
1823 :group
'custom-buffer
)
1825 (defface custom-invalid
'((((class color
))
1826 (:foreground
"yellow1" :background
"red1"))
1828 (:weight bold
:slant italic
:underline t
)))
1829 "Face used when the customize item is invalid."
1830 :group
'custom-magic-faces
)
1831 ;; backward-compatibility alias
1832 (put 'custom-invalid-face
'face-alias
'custom-invalid
)
1834 (defface custom-rogue
'((((class color
))
1835 (:foreground
"pink" :background
"black"))
1838 "Face used when the customize item is not defined for customization."
1839 :group
'custom-magic-faces
)
1840 ;; backward-compatibility alias
1841 (put 'custom-rogue-face
'face-alias
'custom-rogue
)
1843 (defface custom-modified
'((((min-colors 88) (class color
))
1844 (:foreground
"white" :background
"blue1"))
1846 (:foreground
"white" :background
"blue"))
1848 (:slant italic
:bold
)))
1849 "Face used when the customize item has been modified."
1850 :group
'custom-magic-faces
)
1851 ;; backward-compatibility alias
1852 (put 'custom-modified-face
'face-alias
'custom-modified
)
1854 (defface custom-set
'((((min-colors 88) (class color
))
1855 (:foreground
"blue1" :background
"white"))
1857 (:foreground
"blue" :background
"white"))
1860 "Face used when the customize item has been set."
1861 :group
'custom-magic-faces
)
1862 ;; backward-compatibility alias
1863 (put 'custom-set-face
'face-alias
'custom-set
)
1865 (defface custom-changed
'((((min-colors 88) (class color
))
1866 (:foreground
"white" :background
"blue1"))
1868 (:foreground
"white" :background
"blue"))
1871 "Face used when the customize item has been changed."
1872 :group
'custom-magic-faces
)
1873 ;; backward-compatibility alias
1874 (put 'custom-changed-face
'face-alias
'custom-changed
)
1876 (defface custom-themed
'((((min-colors 88) (class color
))
1877 (:foreground
"white" :background
"blue1"))
1879 (:foreground
"white" :background
"blue"))
1882 "Face used when the customize item has been set by a theme."
1883 :group
'custom-magic-faces
)
1885 (defface custom-saved
'((t (:underline t
)))
1886 "Face used when the customize item has been saved."
1887 :group
'custom-magic-faces
)
1888 ;; backward-compatibility alias
1889 (put 'custom-saved-face
'face-alias
'custom-saved
)
1891 (defconst custom-magic-alist
1892 '((nil "#" underline
"\
1893 UNINITIALIZED, you should not see this.")
1894 (unknown "?" italic
"\
1895 UNKNOWN, you should not see this.")
1896 (hidden "-" default
"\
1897 HIDDEN, invoke \"Show\" in the previous line to show." "\
1898 group now hidden, invoke \"Show\", above, to show contents.")
1899 (invalid "x" custom-invalid
"\
1900 INVALID, the displayed value cannot be set.")
1901 (modified "*" custom-modified
"\
1902 EDITED, shown value does not take effect until you set or save it." "\
1903 something in this group has been edited but not set.")
1904 (set "+" custom-set
"\
1905 SET for current session only." "\
1906 something in this group has been set but not saved.")
1907 (changed ":" custom-changed
"\
1908 CHANGED outside Customize; operating on it here may be unreliable." "\
1909 something in this group has been changed outside customize.")
1910 (saved "!" custom-saved
"\
1912 something in this group has been set and saved.")
1913 (themed "o" custom-themed
"\
1915 visible group members are all at standard values.")
1916 (rogue "@" custom-rogue
"\
1917 NO CUSTOMIZATION DATA; not intended to be customized." "\
1918 something in this group is not prepared for customization.")
1919 (standard " " nil
"\
1921 visible group members are all at standard values."))
1922 "Alist of customize option states.
1923 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1925 STATE is one of the following symbols:
1928 For internal use, should never occur.
1930 For internal use, should never occur.
1932 This item is not being displayed.
1934 This item is modified, but has an invalid form.
1936 This item is modified, and has a valid form.
1938 This item has been set but not saved.
1940 The current value of this item has been changed outside Customize.
1942 This item is marked for saving.
1944 This item has no customization information.
1946 This item is unchanged from the standard setting.
1948 MAGIC is a string used to present that state.
1950 FACE is a face used to present the state.
1952 ITEM-DESC is a string describing the state for options.
1954 GROUP-DESC is a string describing the state for groups. If this is
1955 left out, ITEM-DESC will be used.
1957 The string %c in either description will be replaced with the
1958 category of the item. These are `group'. `option', and `face'.
1960 The list should be sorted most significant first.")
1962 (defcustom custom-magic-show
'long
1963 "If non-nil, show textual description of the state.
1964 If `long', show a full-line description, not just one word."
1965 :type
'(choice (const :tag
"no" nil
)
1967 (other :tag
"short" short
))
1968 :group
'custom-buffer
)
1970 (defcustom custom-magic-show-hidden
'(option face
)
1971 "Control whether the State button is shown for hidden items.
1972 The value should be a list with the custom categories where the State
1973 button should be visible. Possible categories are `group', `option',
1975 :type
'(set (const group
) (const option
) (const face
))
1976 :group
'custom-buffer
)
1978 (defcustom custom-magic-show-button nil
1979 "Show a \"magic\" button indicating the state of each customization option."
1981 :group
'custom-buffer
)
1983 (define-widget 'custom-magic
'default
1984 "Show and manipulate state for a customization option."
1986 :action
'widget-parent-action
1989 :value-create
'custom-magic-value-create
1990 :value-delete
'widget-children-value-delete
)
1992 (defun widget-magic-mouse-down-action (widget &optional event
)
1993 ;; Non-nil unless hidden.
1994 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1998 (defun custom-magic-value-create (widget)
1999 "Create compact status report for WIDGET."
2000 (let* ((parent (widget-get widget
:parent
))
2001 (state (widget-get parent
:custom-state
))
2002 (hidden (eq state
'hidden
))
2003 (entry (assq state custom-magic-alist
))
2004 (magic (nth 1 entry
))
2005 (face (nth 2 entry
))
2006 (category (widget-get parent
:custom-category
))
2007 (text (or (and (eq category
'group
)
2010 (form (widget-get parent
:custom-form
))
2012 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
2013 (setq text
(concat (match-string 1 text
)
2014 (symbol-name category
)
2015 (match-string 2 text
))))
2016 (when (and custom-magic-show
2018 (memq category custom-magic-show-hidden
)))
2020 (when (and (eq category
'group
)
2021 (not (and (eq custom-buffer-style
'links
)
2022 (> (widget-get parent
:custom-level
) 1))))
2023 (insert-char ?\
(* custom-buffer-indent
2024 (widget-get parent
:custom-level
))))
2025 (push (widget-create-child-and-convert
2027 :help-echo
"Change the state of this item."
2028 :format
(if hidden
"%t" "%[%t%]")
2029 :button-prefix
'widget-push-button-prefix
2030 :button-suffix
'widget-push-button-suffix
2031 :mouse-down-action
'widget-magic-mouse-down-action
2035 (let ((start (point)))
2036 (if (eq custom-magic-show
'long
)
2038 (insert (symbol-name state
)))
2039 (cond ((eq form
'lisp
)
2041 ((eq form
'mismatch
)
2042 (insert " (mismatch)")))
2043 (put-text-property start
(point) 'face
'custom-state
))
2045 (when (and (eq category
'group
)
2046 (not (and (eq custom-buffer-style
'links
)
2047 (> (widget-get parent
:custom-level
) 1))))
2048 (insert-char ?\
(* custom-buffer-indent
2049 (widget-get parent
:custom-level
))))
2050 (when custom-magic-show-button
2051 (when custom-magic-show
2052 (let ((indent (widget-get parent
:indent
)))
2054 (insert-char ? indent
))))
2055 (push (widget-create-child-and-convert
2057 :mouse-down-action
'widget-magic-mouse-down-action
2061 :help-echo
"Change the state."
2062 :format
(if hidden
"%t" "%[%t%]")
2063 :tag
(if (memq form
'(lisp mismatch
))
2064 (concat "(" magic
")")
2065 (concat "[" magic
"]")))
2068 (widget-put widget
:children children
)))
2070 (defun custom-magic-reset (widget)
2071 "Redraw the :custom-magic property of WIDGET."
2072 (let ((magic (widget-get widget
:custom-magic
)))
2073 (widget-value-set magic
(widget-value magic
))))
2075 ;;; The `custom' Widget.
2077 (defface custom-button
2078 '((((type x w32 mac
) (class color
)) ; Like default modeline
2079 (:box
(:line-width
2 :style released-button
)
2080 :background
"lightgrey" :foreground
"black"))
2083 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2085 :group
'custom-faces
)
2086 ;; backward-compatibility alias
2087 (put 'custom-button-face
'face-alias
'custom-button
)
2089 (defface custom-button-mouse
2090 '((((type x w32 mac
) (class color
))
2091 (:box
(:line-width
2 :style released-button
)
2092 :background
"grey90" :foreground
"black"))
2095 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2097 :group
'custom-faces
)
2099 (defface custom-button-unraised
2100 '((t :inherit underline
))
2101 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2103 :group
'custom-faces
)
2106 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2108 (setq custom-button-mouse
2109 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2111 (defface custom-button-pressed
2112 '((((type x w32 mac
) (class color
))
2113 (:box
(:line-width
2 :style pressed-button
)
2114 :background
"lightgrey" :foreground
"black"))
2116 (:inverse-video t
)))
2117 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2119 :group
'custom-faces
)
2120 ;; backward-compatibility alias
2121 (put 'custom-button-pressed-face
'face-alias
'custom-button-pressed
)
2123 (defface custom-button-pressed-unraised
2124 '((default :inherit custom-button-unraised
)
2125 (((class color
) (background light
)) :foreground
"magenta4")
2126 (((class color
) (background dark
)) :foreground
"violet"))
2127 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2129 :group
'custom-faces
)
2131 (setq custom-button-pressed
2132 (if custom-raised-buttons
2133 'custom-button-pressed
2134 'custom-button-pressed-unraised
))
2136 (defface custom-documentation
'((t nil
))
2137 "Face used for documentation strings in customization buffers."
2138 :group
'custom-faces
)
2139 ;; backward-compatibility alias
2140 (put 'custom-documentation-face
'face-alias
'custom-documentation
)
2142 (defface custom-state
'((((class color
)
2144 (:foreground
"lime green"))
2147 (:foreground
"dark green"))
2149 "Face used for State descriptions in the customize buffer."
2150 :group
'custom-faces
)
2151 ;; backward-compatibility alias
2152 (put 'custom-state-face
'face-alias
'custom-state
)
2154 (defface custom-link
2155 '((t :inherit link
))
2156 "Face for links in customization buffers."
2158 :group
'custom-faces
)
2160 (define-widget 'custom
'default
2161 "Customize a user option."
2163 :convert-widget
'custom-convert-widget
2164 :notify
'custom-notify
2167 :custom-state
'hidden
2168 :documentation-property
'widget-subclass-responsibility
2169 :value-create
'widget-subclass-responsibility
2170 :value-delete
'widget-children-value-delete
2171 :value-get
'widget-value-value-get
2172 :validate
'widget-children-validate
2173 :match
(lambda (widget value
) (symbolp value
)))
2175 (defun custom-convert-widget (widget)
2176 "Initialize :value and :tag from :args in WIDGET."
2177 (let ((args (widget-get widget
:args
)))
2179 (widget-put widget
:value
(widget-apply widget
2180 :value-to-internal
(car args
)))
2181 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2182 (widget-put widget
:args nil
)))
2185 (defun custom-notify (widget &rest args
)
2186 "Keep track of changes."
2187 (let ((state (widget-get widget
:custom-state
)))
2188 (unless (eq state
'modified
)
2189 (unless (memq state
'(nil unknown hidden
))
2190 (widget-put widget
:custom-state
'modified
))
2191 (custom-magic-reset widget
)
2192 (apply 'widget-default-notify widget args
))))
2194 (defun custom-redraw (widget)
2195 "Redraw WIDGET with current settings."
2196 (let ((line (count-lines (point-min) (point)))
2197 (column (current-column))
2199 (from (marker-position (widget-get widget
:from
)))
2200 (to (marker-position (widget-get widget
:to
))))
2202 (widget-value-set widget
(widget-value widget
))
2203 (custom-redraw-magic widget
))
2204 (when (and (>= pos from
) (<= pos to
))
2209 (goto-line (1+ line
)))
2210 (move-to-column column
))
2213 (defun custom-redraw-magic (widget)
2214 "Redraw WIDGET state with current settings."
2216 (let ((magic (widget-get widget
:custom-magic
)))
2218 (widget-value-set magic
(widget-value magic
))
2219 (when (setq widget
(widget-get widget
:group
))
2220 (custom-group-state-update widget
)))
2222 (setq widget nil
)))))
2225 (defun custom-show (widget value
)
2226 "Non-nil if WIDGET should be shown with VALUE by default."
2227 (let ((show (widget-get widget
:custom-show
)))
2233 (funcall show widget value
)))))
2235 (defun custom-load-widget (widget)
2236 "Load all dependencies for WIDGET."
2237 (custom-load-symbol (widget-value widget
)))
2239 (defun custom-unloaded-symbol-p (symbol)
2240 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2242 (loads (get symbol
'custom-loads
))
2245 (setq load
(car loads
)
2247 (cond ((symbolp load
)
2248 (unless (featurep load
)
2250 ((assoc load load-history
))
2251 ((assoc (locate-library load
) load-history
)
2257 (defun custom-unloaded-widget-p (widget)
2258 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2259 (custom-unloaded-symbol-p (widget-value widget
)))
2261 (defun custom-toggle-hide (widget)
2262 "Toggle visibility of WIDGET."
2263 (custom-load-widget widget
)
2264 (let ((state (widget-get widget
:custom-state
)))
2265 (cond ((memq state
'(invalid modified
))
2266 (error "There are unset changes"))
2268 (widget-put widget
:custom-state
'unknown
))
2270 (widget-put widget
:documentation-shown nil
)
2271 (widget-put widget
:custom-state
'hidden
)))
2272 (custom-redraw widget
)
2275 (defun custom-toggle-parent (widget &rest ignore
)
2276 "Toggle visibility of parent of WIDGET."
2277 (custom-toggle-hide (widget-get widget
:parent
)))
2279 (defun custom-add-see-also (widget &optional prefix
)
2280 "Add `See also ...' to WIDGET if there are any links.
2281 Insert PREFIX first if non-nil."
2282 (let* ((symbol (widget-get widget
:value
))
2283 (links (get symbol
'custom-links
))
2284 (many (> (length links
) 2))
2285 (buttons (widget-get widget
:buttons
))
2286 (indent (widget-get widget
:indent
)))
2289 (insert-char ?\ indent
))
2292 (insert "See also ")
2294 (push (widget-create-child-and-convert
2296 :button-face
'custom-link
2297 :mouse-face
'highlight
2298 :pressed-face
'highlight
)
2300 (setq links
(cdr links
))
2309 (widget-put widget
:buttons buttons
))))
2311 (defun custom-add-parent-links (widget &optional initial-string
2313 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2314 The value is non-nil if any parents were found.
2315 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2316 (let ((name (widget-value widget
))
2317 (type (widget-type widget
))
2318 (buttons (widget-get widget
:buttons
))
2321 (insert (or initial-string
"Groups:"))
2322 (mapatoms (lambda (symbol)
2323 (when (member (list name type
) (get symbol
'custom-group
))
2325 (push (widget-create-child-and-convert
2326 widget
'custom-group-link
2327 :tag
(custom-unlispify-tag-name symbol
)
2330 (setq parents
(cons symbol parents
)))))
2331 (and (null (get name
'custom-links
)) ;No links of its own.
2332 (= (length parents
) 1) ;A single parent.
2333 (let* ((links (delq nil
(mapcar (lambda (w)
2334 (unless (eq (widget-type w
)
2337 (get (car parents
) 'custom-links
))))
2338 (many (> (length links
) 2)))
2341 (left-margin (+ left-margin
2)))
2342 (insert "\n" (or doc-initial-string
"Group documentation:") " ")
2344 (push (widget-create-child-and-convert
2346 :button-face
'custom-link
2347 :mouse-face
'highlight
2348 :pressed-face
'highlight
)
2350 (setq links
(cdr links
))
2359 (fill-region-as-paragraph pt
(point))
2360 (delete-to-left-margin (1+ pt
) (+ pt
2))))))
2363 (delete-region start
(point)))
2364 (widget-put widget
:buttons buttons
)
2367 ;;; The `custom-comment' Widget.
2369 ;; like the editable field
2370 (defface custom-comment
'((((type tty
))
2371 :background
"yellow3"
2372 :foreground
"black")
2373 (((class grayscale color
)
2375 :background
"gray85")
2376 (((class grayscale color
)
2378 :background
"dim gray")
2381 "Face used for comments on variables or faces"
2383 :group
'custom-faces
)
2384 ;; backward-compatibility alias
2385 (put 'custom-comment-face
'face-alias
'custom-comment
)
2387 ;; like font-lock-comment-face
2388 (defface custom-comment-tag
2389 '((((class color
) (background dark
)) (:foreground
"gray80"))
2390 (((class color
) (background light
)) (:foreground
"blue4"))
2391 (((class grayscale
) (background light
))
2392 (:foreground
"DimGray" :weight bold
:slant italic
))
2393 (((class grayscale
) (background dark
))
2394 (:foreground
"LightGray" :weight bold
:slant italic
))
2396 "Face used for variables or faces comment tags"
2397 :group
'custom-faces
)
2398 ;; backward-compatibility alias
2399 (put 'custom-comment-tag-face
'face-alias
'custom-comment-tag
)
2401 (define-widget 'custom-comment
'string
2404 :help-echo
"Edit a comment here."
2405 :sample-face
'custom-comment-tag-face
2406 :value-face
'custom-comment-face
2408 :create
'custom-comment-create
)
2410 (defun custom-comment-create (widget)
2411 (let* ((null-comment (equal "" (widget-value widget
))))
2412 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2414 (widget-default-create widget
)
2415 ;; `widget-default-delete' expects markers in these slots --
2416 ;; maybe it shouldn't.
2417 (widget-put widget
:from
(point-marker))
2418 (widget-put widget
:to
(point-marker)))))
2420 (defun custom-comment-hide (widget)
2421 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2423 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2424 ;; the global custom one
2425 (defun custom-comment-show (widget)
2426 (widget-put widget
:comment-shown t
)
2427 (custom-redraw widget
)
2430 (defun custom-comment-invisible-p (widget)
2431 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2433 (not (widget-get widget
:comment-shown
)))))
2435 ;;; The `custom-variable' Widget.
2437 ;; When this was underlined blue, users confused it with a
2438 ;; Mosaic-style hyperlink...
2439 (defface custom-variable-tag
2442 (:foreground
"light blue" :weight bold
))
2443 (((min-colors 88) (class color
)
2445 (:foreground
"blue1" :weight bold
))
2448 (:foreground
"blue" :weight bold
))
2450 "Face used for unpushable variable tags."
2451 :group
'custom-faces
)
2452 ;; backward-compatibility alias
2453 (put 'custom-variable-tag-face
'face-alias
'custom-variable-tag
)
2455 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2456 "Face used for pushable variable tags."
2457 :group
'custom-faces
)
2458 ;; backward-compatibility alias
2459 (put 'custom-variable-button-face
'face-alias
'custom-variable-button
)
2461 (defcustom custom-variable-default-form
'edit
2462 "Default form of displaying variable values."
2463 :type
'(choice (const edit
)
2465 :group
'custom-buffer
2468 (defun custom-variable-documentation (variable)
2469 "Return documentation of VARIABLE for use in Custom buffer.
2470 Normally just return the docstring. But if VARIABLE automatically
2471 becomes buffer local when set, append a message to that effect."
2472 (if (and (local-variable-if-set-p variable
)
2473 (or (not (local-variable-p variable
))
2475 (local-variable-if-set-p variable
))))
2476 (concat (documentation-property variable
'variable-documentation
)
2478 This variable automatically becomes buffer-local when set outside Custom.
2479 However, setting it through Custom sets the default value.")
2480 (documentation-property variable
'variable-documentation
)))
2482 (define-widget 'custom-variable
'custom
2483 "Customize variable."
2485 :help-echo
"Set or reset this variable."
2486 :documentation-property
#'custom-variable-documentation
2487 :custom-category
'option
2489 :custom-menu
'custom-variable-menu-create
2490 :custom-form nil
; defaults to value of `custom-variable-default-form'
2491 :value-create
'custom-variable-value-create
2492 :action
'custom-variable-action
2493 :custom-set
'custom-variable-set
2494 :custom-mark-to-save
'custom-variable-mark-to-save
2495 :custom-reset-current
'custom-redraw
2496 :custom-reset-saved
'custom-variable-reset-saved
2497 :custom-reset-standard
'custom-variable-reset-standard
2498 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2499 :custom-standard-value
'custom-variable-standard-value
2500 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2502 (defun custom-variable-type (symbol)
2503 "Return a widget suitable for editing the value of SYMBOL.
2504 If SYMBOL has a `custom-type' property, use that.
2505 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2506 try matching its doc string against `custom-guess-doc-alist'."
2507 (let* ((type (or (get symbol
'custom-type
)
2508 (and (not (get symbol
'standard-value
))
2509 (custom-guess-type symbol
))
2511 (options (get symbol
'custom-options
))
2512 (tmp (if (listp type
)
2513 (copy-sequence type
)
2516 (widget-put tmp
:options options
))
2519 (defun custom-variable-value-create (widget)
2520 "Here is where you edit the variable's value."
2521 (custom-load-widget widget
)
2522 (unless (widget-get widget
:custom-form
)
2523 (widget-put widget
:custom-form custom-variable-default-form
))
2524 (let* ((buttons (widget-get widget
:buttons
))
2525 (children (widget-get widget
:children
))
2526 (form (widget-get widget
:custom-form
))
2527 (state (widget-get widget
:custom-state
))
2528 (symbol (widget-get widget
:value
))
2529 (tag (widget-get widget
:tag
))
2530 (type (custom-variable-type symbol
))
2531 (conv (widget-convert type
))
2532 (get (or (get symbol
'custom-get
) 'default-value
))
2533 (prefix (widget-get widget
:custom-prefix
))
2534 (last (widget-get widget
:custom-last
))
2535 (value (if (default-boundp symbol
)
2536 (funcall get symbol
)
2537 (widget-get conv
:value
))))
2538 ;; If the widget is new, the child determines whether it is hidden.
2540 ((custom-show type value
)
2541 (setq state
'unknown
))
2543 (setq state
'hidden
)))
2544 ;; If we don't know the state, see if we need to edit it in lisp form.
2545 (when (eq state
'unknown
)
2546 (unless (widget-apply conv
:match value
)
2547 ;; (widget-apply (widget-convert type) :match value)
2548 (setq form
'mismatch
)))
2549 ;; Now we can create the child widget.
2550 (cond ((eq custom-buffer-style
'tree
)
2551 (insert prefix
(if last
" `--- " " |--- "))
2552 (push (widget-create-child-and-convert
2553 widget
'custom-browse-variable-tag
)
2555 (insert " " tag
"\n")
2556 (widget-put widget
:buttons buttons
))
2558 ;; Indicate hidden value.
2559 (push (widget-create-child-and-convert
2562 :sample-face
'custom-variable-tag-face
2566 (push (widget-create-child-and-convert
2568 :help-echo
"Show the value of this option."
2570 :action
'custom-toggle-parent
2573 ((memq form
'(lisp mismatch
))
2574 ;; In lisp mode edit the saved value when possible.
2575 (let* ((value (cond ((get symbol
'saved-value
)
2576 (car (get symbol
'saved-value
)))
2577 ((get symbol
'standard-value
)
2578 (car (get symbol
'standard-value
)))
2579 ((default-boundp symbol
)
2580 (custom-quote (funcall get symbol
)))
2582 (custom-quote (widget-get conv
:value
))))))
2583 (insert (symbol-name symbol
) ": ")
2584 (push (widget-create-child-and-convert
2586 :help-echo
"Hide the value of this option."
2589 :action
'custom-toggle-parent
2593 (push (widget-create-child-and-convert
2595 :button-face
'custom-variable-button-face
2597 :tag
(symbol-name symbol
)
2603 (let* ((format (widget-get type
:format
))
2604 tag-format value-format
)
2605 (unless (string-match ":" format
)
2606 (error "Bad format"))
2607 (setq tag-format
(substring format
0 (match-end 0)))
2608 (setq value-format
(substring format
(match-end 0)))
2609 (push (widget-create-child-and-convert
2612 :action
'custom-tag-action
2613 :help-echo
"Change value of this option."
2614 :mouse-down-action
'custom-tag-mouse-down-action
2615 :button-face
'custom-variable-button-face
2616 :sample-face
'custom-variable-tag-face
2620 (push (widget-create-child-and-convert
2622 :help-echo
"Hide the value of this option."
2625 :action
'custom-toggle-parent
2628 (push (widget-create-child-and-convert
2630 :format value-format
2633 (unless (eq custom-buffer-style
'tree
)
2634 (unless (eq (preceding-char) ?
\n)
2635 (widget-insert "\n"))
2636 ;; Create the magic button.
2637 (let ((magic (widget-create-child-and-convert
2638 widget
'custom-magic nil
)))
2639 (widget-put widget
:custom-magic magic
)
2640 (push magic buttons
))
2641 (widget-put widget
:buttons buttons
)
2642 ;; Insert documentation.
2643 (widget-put widget
:documentation-indent
3)
2644 (widget-add-documentation-string-button
2645 widget
:visibility-widget
'custom-visibility
)
2647 ;; The comment field
2648 (unless (eq state
'hidden
)
2649 (let* ((comment (get symbol
'variable-comment
))
2651 (widget-create-child-and-convert
2652 widget
'custom-comment
2654 :value
(or comment
""))))
2655 (widget-put widget
:comment-widget comment-widget
)
2656 ;; Don't push it !!! Custom assumes that the first child is the
2658 (setq children
(append children
(list comment-widget
)))))
2659 ;; Update the rest of the properties properties.
2660 (widget-put widget
:custom-form form
)
2661 (widget-put widget
:children children
)
2662 ;; Now update the state.
2663 (if (eq state
'hidden
)
2664 (widget-put widget
:custom-state state
)
2665 (custom-variable-state-set widget
))
2667 (unless (eq state
'hidden
)
2668 (when (eq (widget-get widget
:custom-level
) 1)
2669 (custom-add-parent-links widget
))
2670 (custom-add-see-also widget
)))))
2672 (defun custom-tag-action (widget &rest args
)
2673 "Pass :action to first child of WIDGET's parent."
2674 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2677 (defun custom-tag-mouse-down-action (widget &rest args
)
2678 "Pass :mouse-down-action to first child of WIDGET's parent."
2679 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2680 :mouse-down-action args
))
2682 (defun custom-variable-state-set (widget)
2683 "Set the state of WIDGET."
2684 (let* ((symbol (widget-value widget
))
2685 (get (or (get symbol
'custom-get
) 'default-value
))
2686 (value (if (default-boundp symbol
)
2687 (funcall get symbol
)
2688 (widget-get widget
:value
)))
2689 (comment (get symbol
'variable-comment
))
2692 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2694 (get symbol
'customized-variable-comment
))
2696 (if (condition-case nil
2697 (and (equal value
(eval (car tmp
)))
2698 (equal comment temp
))
2702 ((progn (setq tmp
(get symbol
'theme-value
))
2703 (setq temp
(get symbol
'saved-variable-comment
))
2705 (if (condition-case nil
2706 (and (equal comment temp
)
2709 (car (custom-variable-theme-value
2713 ((eq (caar tmp
) 'user
) 'saved
)
2714 ((eq (caar tmp
) 'changed
)
2715 (if (condition-case nil
2719 (car (get symbol
'standard-value
)))))
2721 ;; The value was originally set outside
2722 ;; custom, but it was set to the standard
2723 ;; value (probably an autoloaded defcustom).
2728 ((setq tmp
(get symbol
'standard-value
))
2729 (if (condition-case nil
2730 (and (equal value
(eval (car tmp
)))
2731 (equal comment nil
))
2736 (widget-put widget
:custom-state state
)))
2738 (defun custom-variable-standard-value (widget)
2739 (get (widget-value widget
) 'standard-value
))
2741 (defvar custom-variable-menu
2742 `(("Set for Current Session" custom-variable-set
2744 (eq (widget-get widget
:custom-state
) 'modified
)))
2745 ;; Note that in all the backquoted code in this file, we test
2746 ;; init-file-user rather than user-init-file. This is in case
2747 ;; cus-edit is loaded by something in site-start.el, because
2748 ;; user-init-file is not set at that stage.
2749 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2750 ,@(when (or custom-file init-file-user
)
2751 '(("Save for Future Sessions" custom-variable-save
2753 (memq (widget-get widget
:custom-state
)
2754 '(modified set changed rogue
))))))
2755 ("Undo Edits" custom-redraw
2757 (and (default-boundp (widget-value widget
))
2758 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2759 ("Reset to Saved" custom-variable-reset-saved
2761 (and (or (get (widget-value widget
) 'saved-value
)
2762 (get (widget-value widget
) 'saved-variable-comment
))
2763 (memq (widget-get widget
:custom-state
)
2764 '(modified set changed rogue
)))))
2765 ,@(when (or custom-file init-file-user
)
2766 '(("Erase Customization" custom-variable-reset-standard
2768 (and (get (widget-value widget
) 'standard-value
)
2769 (memq (widget-get widget
:custom-state
)
2770 '(modified set changed saved rogue
)))))))
2771 ("Set to Backup Value" custom-variable-reset-backup
2773 (get (widget-value widget
) 'backup-value
)))
2774 ("---" ignore ignore
)
2775 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2776 ("---" ignore ignore
)
2777 ("Show Current Value" custom-variable-edit
2779 (eq (widget-get widget
:custom-form
) 'lisp
)))
2780 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2782 (eq (widget-get widget
:custom-form
) 'edit
))))
2783 "Alist of actions for the `custom-variable' widget.
2784 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2785 the menu entry, ACTION is the function to call on the widget when the
2786 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2787 widget as an argument, and returns non-nil if ACTION is valid on that
2788 widget. If FILTER is nil, ACTION is always valid.")
2790 (defun custom-variable-action (widget &optional event
)
2791 "Show the menu for `custom-variable' WIDGET.
2792 Optional EVENT is the location for the menu."
2793 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2794 (custom-toggle-hide widget
)
2795 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2796 (custom-variable-state-set widget
))
2797 (custom-redraw-magic widget
)
2798 (let* ((completion-ignore-case t
)
2799 (answer (widget-choose (concat "Operation on "
2800 (custom-unlispify-tag-name
2801 (widget-get widget
:value
)))
2802 (custom-menu-filter custom-variable-menu
2806 (funcall answer widget
)))))
2808 (defun custom-variable-edit (widget)
2809 "Edit value of WIDGET."
2810 (widget-put widget
:custom-state
'unknown
)
2811 (widget-put widget
:custom-form
'edit
)
2812 (custom-redraw widget
))
2814 (defun custom-variable-edit-lisp (widget)
2815 "Edit the Lisp representation of the value of WIDGET."
2816 (widget-put widget
:custom-state
'unknown
)
2817 (widget-put widget
:custom-form
'lisp
)
2818 (custom-redraw widget
))
2820 (defun custom-variable-set (widget)
2821 "Set the current value for the variable being edited by WIDGET."
2822 (let* ((form (widget-get widget
:custom-form
))
2823 (state (widget-get widget
:custom-state
))
2824 (child (car (widget-get widget
:children
)))
2825 (symbol (widget-value widget
))
2826 (set (or (get symbol
'custom-set
) 'set-default
))
2827 (comment-widget (widget-get widget
:comment-widget
))
2828 (comment (widget-value comment-widget
))
2830 (cond ((eq state
'hidden
)
2831 (error "Cannot set hidden variable"))
2832 ((setq val
(widget-apply child
:validate
))
2833 (goto-char (widget-get val
:from
))
2834 (error "%s" (widget-get val
:error
)))
2835 ((memq form
'(lisp mismatch
))
2836 (when (equal comment
"")
2838 ;; Make the comment invisible by hand if it's empty
2839 (custom-comment-hide comment-widget
))
2840 (custom-variable-backup-value widget
)
2841 (custom-push-theme 'theme-value symbol
'user
2842 'set
(custom-quote (widget-value child
)))
2843 (funcall set symbol
(eval (setq val
(widget-value child
))))
2844 (put symbol
'customized-value
(list val
))
2845 (put symbol
'variable-comment comment
)
2846 (put symbol
'customized-variable-comment comment
))
2848 (when (equal comment
"")
2850 ;; Make the comment invisible by hand if it's empty
2851 (custom-comment-hide comment-widget
))
2852 (custom-variable-backup-value widget
)
2853 (custom-push-theme 'theme-value symbol
'user
2854 'set
(custom-quote (widget-value child
)))
2855 (funcall set symbol
(setq val
(widget-value child
)))
2856 (put symbol
'customized-value
(list (custom-quote val
)))
2857 (put symbol
'variable-comment comment
)
2858 (put symbol
'customized-variable-comment comment
)))
2859 (custom-variable-state-set widget
)
2860 (custom-redraw-magic widget
)))
2862 (defun custom-variable-mark-to-save (widget)
2863 "Set value and mark for saving the variable edited by WIDGET."
2864 (let* ((form (widget-get widget
:custom-form
))
2865 (state (widget-get widget
:custom-state
))
2866 (child (car (widget-get widget
:children
)))
2867 (symbol (widget-value widget
))
2868 (set (or (get symbol
'custom-set
) 'set-default
))
2869 (comment-widget (widget-get widget
:comment-widget
))
2870 (comment (widget-value comment-widget
))
2872 (cond ((eq state
'hidden
)
2873 (error "Cannot set hidden variable"))
2874 ((setq val
(widget-apply child
:validate
))
2875 (goto-char (widget-get val
:from
))
2876 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2877 ((memq form
'(lisp mismatch
))
2878 (when (equal comment
"")
2880 ;; Make the comment invisible by hand if it's empty
2881 (custom-comment-hide comment-widget
))
2882 (put symbol
'saved-value
(list (widget-value child
)))
2883 (custom-push-theme 'theme-value symbol
'user
2884 'set
(custom-quote (widget-value child
)))
2885 (funcall set symbol
(eval (widget-value child
)))
2886 (put symbol
'variable-comment comment
)
2887 (put symbol
'saved-variable-comment comment
))
2889 (when (equal comment
"")
2891 ;; Make the comment invisible by hand if it's empty
2892 (custom-comment-hide comment-widget
))
2893 (put symbol
'saved-value
2894 (list (custom-quote (widget-value child
))))
2895 (custom-push-theme 'theme-value symbol
'user
2896 'set
(custom-quote (widget-value child
)))
2897 (funcall set symbol
(widget-value child
))
2898 (put symbol
'variable-comment comment
)
2899 (put symbol
'saved-variable-comment comment
)))
2900 (put symbol
'customized-value nil
)
2901 (put symbol
'customized-variable-comment nil
)))
2903 (defsubst custom-variable-state-set-and-redraw
(widget)
2904 "Set state of variable widget WIDGET and redraw with current settings."
2905 (custom-variable-state-set widget
)
2906 (custom-redraw-magic widget
))
2908 (defun custom-variable-save (widget)
2909 "Save value of variable edited by widget WIDGET."
2910 (custom-variable-mark-to-save widget
)
2912 (custom-variable-state-set-and-redraw widget
))
2914 (defun custom-variable-reset-saved (widget)
2915 "Restore the saved value for the variable being edited by WIDGET.
2916 This also updates the buffer to show that value.
2917 The value that was current before this operation
2918 becomes the backup value, so you can get it again."
2919 (let* ((symbol (widget-value widget
))
2920 (set (or (get symbol
'custom-set
) 'set-default
))
2921 (value (get symbol
'saved-value
))
2922 (comment (get symbol
'saved-variable-comment
)))
2923 (cond ((or value comment
)
2924 (put symbol
'variable-comment comment
)
2925 (custom-variable-backup-value widget
)
2926 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2928 (funcall set symbol
(eval (car value
)))
2931 (error "No saved value for %s" symbol
)))
2932 (put symbol
'customized-value nil
)
2933 (put symbol
'customized-variable-comment nil
)
2934 (widget-put widget
:custom-state
'unknown
)
2935 ;; This call will possibly make the comment invisible
2936 (custom-redraw widget
)))
2938 (defun custom-variable-mark-to-reset-standard (widget)
2939 "Mark to restore standard setting for the variable edited by widget WIDGET.
2940 If `custom-reset-standard-variables-list' is nil, save, reset and
2941 redraw the widget immediately."
2942 (let* ((symbol (widget-value widget
)))
2943 (if (get symbol
'standard-value
)
2944 (custom-variable-backup-value widget
)
2945 (error "No standard setting known for %S" symbol
))
2946 (put symbol
'variable-comment nil
)
2947 (put symbol
'customized-value nil
)
2948 (put symbol
'customized-variable-comment nil
)
2949 (custom-push-theme 'theme-value symbol
'user
'reset
)
2950 (custom-theme-recalc-variable symbol
)
2951 (if (and custom-reset-standard-variables-list
2952 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2954 (put symbol
'saved-value nil
)
2955 (put symbol
'saved-variable-comment nil
)
2956 ;; Append this to `custom-reset-standard-variables-list' to
2957 ;; have `custom-reset-standard-save-and-update' save setting
2958 ;; to the file, update the widget's state, and redraw it.
2959 (setq custom-reset-standard-variables-list
2960 (cons widget custom-reset-standard-variables-list
)))
2961 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2962 (put symbol
'saved-value nil
)
2963 (put symbol
'saved-variable-comment nil
)
2965 (widget-put widget
:custom-state
'unknown
)
2966 ;; This call will possibly make the comment invisible
2967 (custom-redraw widget
))))
2969 (defun custom-variable-reset-standard (widget)
2970 "Restore standard setting for the variable edited by WIDGET.
2971 This operation eliminates any saved setting for the variable,
2972 restoring it to the state of a variable that has never been customized.
2973 The value that was current before this operation
2974 becomes the backup value, so you can get it again."
2975 (let (custom-reset-standard-variables-list)
2976 (custom-variable-mark-to-reset-standard widget
)))
2978 (defun custom-variable-backup-value (widget)
2979 "Back up the current value for WIDGET's variable.
2980 The backup value is kept in the car of the `backup-value' property."
2981 (let* ((symbol (widget-value widget
))
2982 (get (or (get symbol
'custom-get
) 'default-value
))
2983 (type (custom-variable-type symbol
))
2984 (conv (widget-convert type
))
2985 (value (if (default-boundp symbol
)
2986 (funcall get symbol
)
2987 (widget-get conv
:value
))))
2988 (put symbol
'backup-value
(list value
))))
2990 (defun custom-variable-reset-backup (widget)
2991 "Restore the backup value for the variable being edited by WIDGET.
2992 The value that was current before this operation
2993 becomes the backup value, so you can use this operation repeatedly
2994 to switch between two values."
2995 (let* ((symbol (widget-value widget
))
2996 (set (or (get symbol
'custom-set
) 'set-default
))
2997 (value (get symbol
'backup-value
))
2998 (comment-widget (widget-get widget
:comment-widget
))
2999 (comment (widget-value comment-widget
)))
3002 (custom-variable-backup-value widget
)
3003 (custom-push-theme 'theme-value symbol
'user
'set value
)
3005 (funcall set symbol
(car value
))
3007 (error "No backup value for %s" symbol
))
3008 (put symbol
'customized-value
(list (car value
)))
3009 (put symbol
'variable-comment comment
)
3010 (put symbol
'customized-variable-comment comment
)
3011 (custom-variable-state-set widget
)
3012 ;; This call will possibly make the comment invisible
3013 (custom-redraw widget
)))
3015 ;;; The `custom-visibility' Widget
3017 (define-widget 'custom-visibility
'visibility
3018 "Show or hide a documentation string."
3019 :button-face
'custom-visibility
3020 :pressed-face
'custom-visibility
3021 :mouse-face
'highlight
3022 :pressed-face
'highlight
)
3024 (defface custom-visibility
3025 '((t :height
0.8 :inherit link
))
3026 "Face for the `custom-visibility' widget."
3028 :group
'custom-faces
)
3030 ;;; The `custom-face-edit' Widget.
3032 (define-widget 'custom-face-edit
'checklist
3033 "Edit face attributes."
3037 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3038 :value-to-internal
'custom-face-edit-fix-value
3039 :match
(lambda (widget value
)
3040 (widget-checklist-match widget
3041 (custom-face-edit-fix-value widget value
)))
3042 :convert-widget
'custom-face-edit-convert-widget
3043 :args
(mapcar (lambda (att)
3046 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3047 (list 'const
:format
"" :value
(nth 0 att
))
3049 custom-face-attributes
))
3051 (defun custom-face-edit-fix-value (widget value
)
3052 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3053 Also change :reverse-video to :inverse-video."
3057 (let ((key (car value
))
3058 (val (car (cdr value
))))
3059 (cond ((eq key
:italic
)
3060 (push :slant result
)
3061 (push (if val
'italic
'normal
) result
))
3063 (push :weight result
)
3064 (push (if val
'bold
'normal
) result
))
3065 ((eq key
:reverse-video
)
3066 (push :inverse-video result
)
3070 (push val result
))))
3071 (setq value
(cdr (cdr value
))))
3072 (setq result
(nreverse result
))
3076 (defun custom-face-edit-convert-widget (widget)
3077 "Convert :args as widget types in WIDGET."
3080 :args
(mapcar (lambda (arg)
3082 :deactivate
'custom-face-edit-deactivate
3083 :activate
'custom-face-edit-activate
3084 :delete
'custom-face-edit-delete
))
3085 (widget-get widget
:args
)))
3088 (defun custom-face-edit-deactivate (widget)
3089 "Make face widget WIDGET inactive for user modifications."
3090 (unless (widget-get widget
:inactive
)
3091 (let ((tag (custom-face-edit-attribute-tag widget
))
3092 (from (copy-marker (widget-get widget
:from
)))
3093 (value (widget-value widget
))
3094 (inhibit-read-only t
)
3095 (inhibit-modification-hooks t
))
3098 (widget-default-delete widget
)
3099 (insert tag
": *\n")
3100 (widget-put widget
:inactive
3101 (cons value
(cons from
(- (point) from
))))))))
3103 (defun custom-face-edit-activate (widget)
3104 "Make face widget WIDGET active for user modifications."
3105 (let ((inactive (widget-get widget
:inactive
))
3106 (inhibit-read-only t
)
3107 (inhibit-modification-hooks t
))
3108 (when (consp inactive
)
3110 (goto-char (car (cdr inactive
)))
3111 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3112 (widget-put widget
:inactive nil
)
3113 (widget-apply widget
:create
)
3114 (widget-value-set widget
(car inactive
))
3117 (defun custom-face-edit-delete (widget)
3118 "Remove WIDGET from the buffer."
3119 (let ((inactive (widget-get widget
:inactive
))
3120 (inhibit-read-only t
)
3121 (inhibit-modification-hooks t
))
3123 ;; Widget is alive, we don't have to do anything special
3124 (widget-default-delete widget
)
3125 ;; WIDGET is already deleted because we did so to inactivate it;
3126 ;; now just get rid of the label we put in its place.
3127 (delete-region (car (cdr inactive
))
3128 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3129 (widget-put widget
:inactive nil
))))
3132 (defun custom-face-edit-attribute-tag (widget)
3133 "Returns the first :tag property in WIDGET or one of its children."
3134 (let ((tag (widget-get widget
:tag
)))
3135 (or (and (not (equal tag
"")) tag
)
3136 (let ((children (widget-get widget
:children
)))
3137 (while (and (null tag
) children
)
3138 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3141 ;;; The `custom-display' Widget.
3143 (define-widget 'custom-display
'menu-choice
3144 "Select a display type."
3147 :help-echo
"Specify frames where the face attributes should be used."
3148 :args
'((const :tag
"all" t
)
3149 (const :tag
"defaults" default
)
3153 :args
((group :sibling-args
(:help-echo
"\
3154 Only match the specified window systems.")
3155 (const :format
"Type: "
3157 (checklist :inline t
3160 :sibling-args
(:help-echo
"\
3161 The X11 Window System.")
3163 (const :format
"PM "
3164 :sibling-args
(:help-echo
"\
3165 OS/2 Presentation Manager.")
3167 (const :format
"W32 "
3168 :sibling-args
(:help-echo
"\
3171 (const :format
"MAC "
3172 :sibling-args
(:help-echo
"\
3175 (const :format
"DOS "
3176 :sibling-args
(:help-echo
"\
3179 (const :format
"TTY%n"
3180 :sibling-args
(:help-echo
"\
3181 Plain text terminals.")
3183 (group :sibling-args
(:help-echo
"\
3184 Only match the frames with the specified color support.")
3185 (const :format
"Class: "
3187 (checklist :inline t
3189 (const :format
"Color "
3190 :sibling-args
(:help-echo
"\
3191 Match color frames.")
3193 (const :format
"Grayscale "
3194 :sibling-args
(:help-echo
"\
3195 Match grayscale frames.")
3197 (const :format
"Monochrome%n"
3198 :sibling-args
(:help-echo
"\
3199 Match frames with no color support.")
3201 (group :sibling-args
(:help-echo
"\
3202 The minimum number of colors the frame should support.")
3203 (const :format
"" min-colors
)
3204 (integer :tag
"Minimum number of colors" ))
3205 (group :sibling-args
(:help-echo
"\
3206 Only match frames with the specified intensity.")
3208 Background brightness: "
3210 (checklist :inline t
3212 (const :format
"Light "
3213 :sibling-args
(:help-echo
"\
3214 Match frames with light backgrounds.")
3216 (const :format
"Dark\n"
3217 :sibling-args
(:help-echo
"\
3218 Match frames with dark backgrounds.")
3220 (group :sibling-args
(:help-echo
"\
3221 Only match frames that support the specified face attributes.")
3222 (const :format
"Supports attributes:" supports
)
3223 (custom-face-edit :inline t
:format
"%n%v"))))))
3225 ;;; The `custom-face' Widget.
3227 (defface custom-face-tag
3228 `((t (:weight bold
:height
1.2 :inherit variable-pitch
)))
3229 "Face used for face tags."
3230 :group
'custom-faces
)
3231 ;; backward-compatibility alias
3232 (put 'custom-face-tag-face
'face-alias
'custom-face-tag
)
3234 (defcustom custom-face-default-form
'selected
3235 "Default form of displaying face definition."
3236 :type
'(choice (const all
)
3239 :group
'custom-buffer
3242 (define-widget 'custom-face
'custom
3244 :sample-face
'custom-face-tag-face
3245 :help-echo
"Set or reset this face."
3246 :documentation-property
#'face-doc-string
3247 :value-create
'custom-face-value-create
3248 :action
'custom-face-action
3249 :custom-category
'face
3250 :custom-form nil
; defaults to value of `custom-face-default-form'
3251 :custom-set
'custom-face-set
3252 :custom-mark-to-save
'custom-face-mark-to-save
3253 :custom-reset-current
'custom-redraw
3254 :custom-reset-saved
'custom-face-reset-saved
3255 :custom-reset-standard
'custom-face-reset-standard
3256 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3257 :custom-standard-value
'custom-face-standard-value
3258 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3259 :custom-menu
'custom-face-menu-create
)
3261 (define-widget 'custom-face-all
'editable-list
3262 "An editable list of display specifications and attributes."
3263 :entry-format
"%i %d %v"
3264 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3265 :append-button-args
'(:help-echo
"Append new display specification here.")
3266 :delete-button-args
'(:help-echo
"Delete this display specification.")
3267 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3269 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3270 "Converted version of the `custom-face-all' widget.")
3272 (define-widget 'custom-display-unselected
'item
3273 "A display specification that doesn't match the selected display."
3274 :match
'custom-display-unselected-match
)
3276 (defun custom-display-unselected-match (widget value
)
3277 "Non-nil if VALUE is an unselected display specification."
3278 (not (face-spec-set-match-display value
(selected-frame))))
3280 (define-widget 'custom-face-selected
'group
3281 "Edit the attributes of the selected display in a face specification."
3282 :args
'((choice :inline t
3283 (group :tag
"With Defaults" :inline t
3284 (group (const :tag
"" default
)
3285 (custom-face-edit :tag
" Default\n Attributes"))
3288 (group custom-display-unselected sexp
))
3289 (group (sexp :format
"")
3290 (custom-face-edit :tag
" Overriding\n Attributes"))
3294 (group :tag
"No Defaults" :inline t
3297 (group custom-display-unselected sexp
))
3298 (group (sexp :format
"")
3299 (custom-face-edit :tag
"\n Attributes"))
3306 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3307 "Converted version of the `custom-face-selected' widget.")
3309 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3310 "Return a canonicalized version of SPEC using.
3311 FILTER-INDEX is the index in the entry for each attribute in
3312 `custom-face-attributes' at which the appropriate filter function can be
3313 found, and DEFAULT-FILTER is the filter to apply for attributes that
3315 (mapcar (lambda (entry)
3316 ;; Filter a single face-spec entry
3317 (let ((tests (car entry
))
3319 ;; Handle both old- and new-style attribute syntax
3320 (if (listp (car (cdr entry
)))
3323 (filtered-attrs nil
))
3324 ;; Filter each face attribute
3325 (while unfiltered-attrs
3326 (let* ((attr (pop unfiltered-attrs
))
3327 (pre-filtered-value (pop unfiltered-attrs
))
3329 (or (nth filter-index
(assq attr custom-face-attributes
))
3333 (funcall filter pre-filtered-value
)
3334 pre-filtered-value
)))
3335 (push filtered-value filtered-attrs
)
3336 (push attr filtered-attrs
)))
3338 (list tests filtered-attrs
)))
3341 (defun custom-pre-filter-face-spec (spec)
3342 "Return SPEC changed as necessary for editing by the face customization widget.
3343 SPEC must be a full face spec."
3344 (custom-filter-face-spec spec
2))
3346 (defun custom-post-filter-face-spec (spec)
3347 "Return the customized SPEC in a form suitable for setting the face."
3348 (custom-filter-face-spec spec
3))
3350 (defun custom-face-value-create (widget)
3351 "Create a list of the display specifications for WIDGET."
3352 (let ((buttons (widget-get widget
:buttons
))
3354 (symbol (widget-get widget
:value
))
3355 (tag (widget-get widget
:tag
))
3356 (state (widget-get widget
:custom-state
))
3358 (is-last (widget-get widget
:custom-last
))
3359 (prefix (widget-get widget
:custom-prefix
)))
3361 (setq tag
(prin1-to-string symbol
)))
3362 (cond ((eq custom-buffer-style
'tree
)
3363 (insert prefix
(if is-last
" `--- " " |--- "))
3364 (push (widget-create-child-and-convert
3365 widget
'custom-browse-face-tag
)
3367 (insert " " tag
"\n")
3368 (widget-put widget
:buttons buttons
))
3372 (widget-specify-sample widget begin
(point))
3373 (if (eq custom-buffer-style
'face
)
3375 (if (string-match "face\\'" tag
)
3377 (insert " face: ")))
3379 (push (widget-create-child-and-convert widget
'item
3386 (push (widget-create-child-and-convert
3388 :help-echo
"Hide or show this face."
3391 :action
'custom-toggle-parent
3392 (not (eq state
'hidden
)))
3396 (let ((magic (widget-create-child-and-convert
3397 widget
'custom-magic nil
)))
3398 (widget-put widget
:custom-magic magic
)
3399 (push magic buttons
))
3401 (widget-put widget
:buttons buttons
)
3402 ;; Insert documentation.
3403 (widget-put widget
:documentation-indent
3)
3404 (widget-add-documentation-string-button
3405 widget
:visibility-widget
'custom-visibility
)
3407 ;; The comment field
3408 (unless (eq state
'hidden
)
3409 (let* ((comment (get symbol
'face-comment
))
3411 (widget-create-child-and-convert
3412 widget
'custom-comment
3414 :value
(or comment
""))))
3415 (widget-put widget
:comment-widget comment-widget
)
3416 (push comment-widget children
)))
3418 (unless (eq state
'hidden
)
3419 (when (eq (widget-get widget
:custom-level
) 1)
3420 (custom-add-parent-links widget
))
3421 (custom-add-see-also widget
))
3423 (unless (eq (preceding-char) ?
\n)
3425 (unless (eq state
'hidden
)
3426 (message "Creating face editor...")
3427 (custom-load-widget widget
)
3428 (unless (widget-get widget
:custom-form
)
3429 (widget-put widget
:custom-form custom-face-default-form
))
3430 (let* ((symbol (widget-value widget
))
3431 (spec (or (get symbol
'customized-face
)
3432 (get symbol
'saved-face
)
3433 (get symbol
'face-defface-spec
)
3434 ;; Attempt to construct it.
3435 (list (list t
(custom-face-attributes-get
3436 symbol
(selected-frame))))))
3437 (form (widget-get widget
:custom-form
))
3438 (indent (widget-get widget
:indent
))
3440 ;; If the user has changed this face in some other way,
3441 ;; edit it as the user has specified it.
3442 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3443 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3444 (setq spec
(custom-pre-filter-face-spec spec
))
3445 (setq edit
(widget-create-child-and-convert
3447 (cond ((and (eq form
'selected
)
3448 (widget-apply custom-face-selected
3450 (when indent
(insert-char ?\ indent
))
3451 'custom-face-selected
)
3452 ((and (not (eq form
'lisp
))
3453 (widget-apply custom-face-all
3457 (when indent
(insert-char ?\ indent
))
3460 (custom-face-state-set widget
)
3461 (push edit children
)
3462 (widget-put widget
:children children
))
3463 (message "Creating face editor...done"))))))
3465 (defvar custom-face-menu
3466 `(("Set for Current Session" custom-face-set
)
3467 ,@(when (or custom-file init-file-user
)
3468 '(("Save for Future Sessions" custom-face-save
)))
3469 ("Undo Edits" custom-redraw
3471 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3472 ("Reset to Saved" custom-face-reset-saved
3474 (or (get (widget-value widget
) 'saved-face
)
3475 (get (widget-value widget
) 'saved-face-comment
))))
3476 ,@(when (or custom-file init-file-user
)
3477 '(("Erase Customization" custom-face-reset-standard
3479 (get (widget-value widget
) 'face-defface-spec
)))))
3480 ("---" ignore ignore
)
3481 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3482 ("---" ignore ignore
)
3483 ("For Current Display" custom-face-edit-selected
3485 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3486 ("For All Kinds of Displays" custom-face-edit-all
3488 (not (eq (widget-get widget
:custom-form
) 'all
))))
3489 ("Show Lisp Expression" custom-face-edit-lisp
3491 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3492 "Alist of actions for the `custom-face' widget.
3493 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3494 the menu entry, ACTION is the function to call on the widget when the
3495 menu is selected, and FILTER is a predicate which takes a `custom-face'
3496 widget as an argument, and returns non-nil if ACTION is valid on that
3497 widget. If FILTER is nil, ACTION is always valid.")
3499 (defun custom-face-edit-selected (widget)
3500 "Edit selected attributes of the value of WIDGET."
3501 (widget-put widget
:custom-state
'unknown
)
3502 (widget-put widget
:custom-form
'selected
)
3503 (custom-redraw widget
))
3505 (defun custom-face-edit-all (widget)
3506 "Edit all attributes of the value of WIDGET."
3507 (widget-put widget
:custom-state
'unknown
)
3508 (widget-put widget
:custom-form
'all
)
3509 (custom-redraw widget
))
3511 (defun custom-face-edit-lisp (widget)
3512 "Edit the Lisp representation of the value of WIDGET."
3513 (widget-put widget
:custom-state
'unknown
)
3514 (widget-put widget
:custom-form
'lisp
)
3515 (custom-redraw widget
))
3517 (defun custom-face-state-set (widget)
3518 "Set the state of WIDGET."
3519 (let* ((symbol (widget-value widget
))
3520 (comment (get symbol
'face-comment
))
3524 (setq tmp
(get symbol
'customized-face
))
3525 (setq temp
(get symbol
'customized-face-comment
))
3527 (if (equal temp comment
)
3531 (setq tmp
(get symbol
'saved-face
))
3532 (setq temp
(get symbol
'saved-face-comment
))
3534 (if (equal temp comment
)
3536 ((eq 'user
(caar (get symbol
'theme-face
)))
3538 ((eq 'changed
(caar (get symbol
'theme-face
)))
3542 ((get symbol
'face-defface-spec
)
3543 (if (equal comment nil
)
3548 ;; If the user called set-face-attribute to change the default
3549 ;; for new frames, this face is "set outside of Customize".
3550 (if (and (not (eq state
'rogue
))
3551 (get symbol
'face-modified
))
3552 (setq state
'changed
))
3553 (widget-put widget
:custom-state state
)))
3555 (defun custom-face-action (widget &optional event
)
3556 "Show the menu for `custom-face' WIDGET.
3557 Optional EVENT is the location for the menu."
3558 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3559 (custom-toggle-hide widget
)
3560 (let* ((completion-ignore-case t
)
3561 (symbol (widget-get widget
:value
))
3562 (answer (widget-choose (concat "Operation on "
3563 (custom-unlispify-tag-name symbol
))
3564 (custom-menu-filter custom-face-menu
3568 (funcall answer widget
)))))
3570 (defun custom-face-set (widget)
3571 "Make the face attributes in WIDGET take effect."
3572 (let* ((symbol (widget-value widget
))
3573 (child (car (widget-get widget
:children
)))
3574 (value (custom-post-filter-face-spec (widget-value child
)))
3575 (comment-widget (widget-get widget
:comment-widget
))
3576 (comment (widget-value comment-widget
)))
3577 (when (equal comment
"")
3579 ;; Make the comment invisible by hand if it's empty
3580 (custom-comment-hide comment-widget
))
3581 (put symbol
'customized-face value
)
3582 (custom-push-theme 'theme-face symbol
'user
'set value
)
3583 (if (face-spec-choose value
)
3584 (face-spec-set symbol value t
)
3585 ;; face-set-spec ignores empty attribute lists, so just give it
3586 ;; something harmless instead.
3587 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3588 (put symbol
'customized-face-comment comment
)
3589 (put symbol
'face-comment comment
)
3590 (custom-face-state-set widget
)
3591 (custom-redraw-magic widget
)))
3593 (defun custom-face-mark-to-save (widget)
3594 "Mark for saving the face edited by WIDGET."
3595 (let* ((symbol (widget-value widget
))
3596 (child (car (widget-get widget
:children
)))
3597 (value (custom-post-filter-face-spec (widget-value child
)))
3598 (comment-widget (widget-get widget
:comment-widget
))
3599 (comment (widget-value comment-widget
)))
3600 (when (equal comment
"")
3602 ;; Make the comment invisible by hand if it's empty
3603 (custom-comment-hide comment-widget
))
3604 (custom-push-theme 'theme-face symbol
'user
'set value
)
3605 (if (face-spec-choose value
)
3606 (face-spec-set symbol value t
)
3607 ;; face-set-spec ignores empty attribute lists, so just give it
3608 ;; something harmless instead.
3609 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3610 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3611 (put symbol
'saved-face value
))
3612 (put symbol
'customized-face nil
)
3613 (put symbol
'face-comment comment
)
3614 (put symbol
'customized-face-comment nil
)
3615 (put symbol
'saved-face-comment comment
)))
3617 (defsubst custom-face-state-set-and-redraw
(widget)
3618 "Set state of face widget WIDGET and redraw with current settings."
3619 (custom-face-state-set widget
)
3620 (custom-redraw-magic widget
))
3622 (defun custom-face-save (widget)
3623 "Save the face edited by WIDGET."
3624 (custom-face-mark-to-save widget
)
3626 (custom-face-state-set-and-redraw widget
))
3628 ;; For backward compatibility.
3629 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3632 (defun custom-face-reset-saved (widget)
3633 "Restore WIDGET to the face's default attributes."
3634 (let* ((symbol (widget-value widget
))
3635 (child (car (widget-get widget
:children
)))
3636 (value (get symbol
'saved-face
))
3637 (comment (get symbol
'saved-face-comment
))
3638 (comment-widget (widget-get widget
:comment-widget
)))
3639 (unless (or value comment
)
3640 (error "No saved value for this face"))
3641 (put symbol
'customized-face nil
)
3642 (put symbol
'customized-face-comment nil
)
3643 (custom-push-theme 'theme-face symbol
'user
'set value
)
3644 (face-spec-set symbol value t
)
3645 (put symbol
'face-comment comment
)
3646 (widget-value-set child value
)
3647 ;; This call manages the comment visibility
3648 (widget-value-set comment-widget
(or comment
""))
3649 (custom-face-state-set widget
)
3650 (custom-redraw-magic widget
)))
3652 (defun custom-face-standard-value (widget)
3653 (get (widget-value widget
) 'face-defface-spec
))
3655 (defun custom-face-mark-to-reset-standard (widget)
3656 "Restore widget WIDGET to the face's standard attribute values.
3657 If `custom-reset-standard-faces-list' is nil, save, reset and
3658 redraw the widget immediately."
3659 (let* ((symbol (widget-value widget
))
3660 (child (car (widget-get widget
:children
)))
3661 (value (get symbol
'face-defface-spec
))
3662 (comment-widget (widget-get widget
:comment-widget
)))
3664 (error "No standard setting for this face"))
3665 (put symbol
'customized-face nil
)
3666 (put symbol
'customized-face-comment nil
)
3667 (custom-push-theme 'theme-face symbol
'user
'reset
)
3668 (face-spec-set symbol value t
)
3669 (custom-theme-recalc-face symbol
)
3670 (if (and custom-reset-standard-faces-list
3671 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3674 (put symbol
'saved-face nil
)
3675 (put symbol
'saved-face-comment nil
)
3676 ;; Append this to `custom-reset-standard-faces-list' and have
3677 ;; `custom-reset-standard-save-and-update' save setting to the
3678 ;; file, update the widget's state, and redraw it.
3679 (setq custom-reset-standard-faces-list
3680 (cons widget custom-reset-standard-faces-list
)))
3681 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3682 (put symbol
'saved-face nil
)
3683 (put symbol
'saved-face-comment nil
)
3685 (put symbol
'face-comment nil
)
3686 (widget-value-set child
3687 (custom-pre-filter-face-spec
3688 (list (list t
(custom-face-attributes-get
3690 ;; This call manages the comment visibility
3691 (widget-value-set comment-widget
"")
3692 (custom-face-state-set widget
)
3693 (custom-redraw-magic widget
))))
3695 (defun custom-face-reset-standard (widget)
3696 "Restore WIDGET to the face's standard attribute values.
3697 This operation eliminates any saved attributes for the face,
3698 restoring it to the state of a face that has never been customized."
3699 (let (custom-reset-standard-faces-list)
3700 (custom-face-mark-to-reset-standard widget
)))
3702 ;;; The `face' Widget.
3704 (defvar widget-face-prompt-value-history nil
3705 "History of input to `widget-face-prompt-value'.")
3707 (define-widget 'face
'symbol
3708 "A Lisp face name (with sample)."
3709 :format
"%{%t%}: (%{sample%}) %v"
3712 :sample-face-get
'widget-face-sample-face-get
3713 :notify
'widget-face-notify
3714 :match
(lambda (widget value
) (facep value
))
3715 :complete-function
(lambda ()
3717 (lisp-complete-symbol 'facep
))
3718 :prompt-match
'facep
3719 :prompt-history
'widget-face-prompt-value-history
3720 :validate
(lambda (widget)
3721 (unless (facep (widget-value widget
))
3723 :error
(format "Invalid face: %S"
3724 (widget-value widget
)))
3727 (defun widget-face-sample-face-get (widget)
3728 (let ((value (widget-value widget
)))
3733 (defun widget-face-notify (widget child
&optional event
)
3734 "Update the sample, and notify the parent."
3735 (overlay-put (widget-get widget
:sample-overlay
)
3736 'face
(widget-apply widget
:sample-face-get
))
3737 (widget-default-notify widget child event
))
3740 ;;; The `hook' Widget.
3742 (define-widget 'hook
'list
3743 "An Emacs Lisp hook."
3744 :value-to-internal
(lambda (widget value
)
3745 (if (and value
(symbolp value
))
3748 :match
(lambda (widget value
)
3750 (widget-group-match widget value
)))
3751 ;; Avoid adding undefined functions to the hook, especially for
3752 ;; things like `find-file-hook' or even more basic ones, to avoid
3754 :set
(lambda (symbol value
)
3757 (add-hook symbol elt
))))
3758 :convert-widget
'custom-hook-convert-widget
3761 (defun custom-hook-convert-widget (widget)
3762 ;; Handle `:options'.
3763 (let* ((options (widget-get widget
:options
))
3764 (other `(editable-list :inline t
3765 :entry-format
"%i %d%v"
3766 (function :format
" %v")))
3768 (list `(checklist :inline t
3769 ,@(mapcar (lambda (entry)
3770 `(function-item ,entry
))
3774 (widget-put widget
:args args
)
3777 ;;; The `custom-group-link' Widget.
3779 (define-widget 'custom-group-link
'link
3780 "Show parent in other window when activated."
3781 :button-face
'custom-link
3782 :mouse-face
'highlight
3783 :pressed-face
'highlight
3784 :help-echo
"Create customization buffer for this group."
3785 :keymap custom-mode-link-map
3786 :follow-link
'mouse-face
3787 :action
'custom-group-link-action
)
3789 (defun custom-group-link-action (widget &rest ignore
)
3790 (customize-group (widget-value widget
)))
3792 ;;; The `custom-group' Widget.
3794 (defcustom custom-group-tag-faces nil
3795 ;; In XEmacs, this ought to play games with font size.
3796 ;; Fixme: make it do so in Emacs.
3797 "Face used for group tags.
3798 The first member is used for level 1 groups, the second for level 2,
3799 and so forth. The remaining group tags are shown with `custom-group-tag'."
3800 :type
'(repeat face
)
3801 :group
'custom-faces
)
3803 (defface custom-group-tag-1
3806 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3807 (((min-colors 88) (class color
)
3809 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3812 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3814 "Face used for group tags."
3815 :group
'custom-faces
)
3816 ;; backward-compatibility alias
3817 (put 'custom-group-tag-face-1
'face-alias
'custom-group-tag-1
)
3819 (defface custom-group-tag
3822 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3823 (((min-colors 88) (class color
)
3825 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3828 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3830 "Face used for low level group tags."
3831 :group
'custom-faces
)
3832 ;; backward-compatibility alias
3833 (put 'custom-group-tag-face
'face-alias
'custom-group-tag
)
3835 (define-widget 'custom-group
'custom
3838 :sample-face-get
'custom-group-sample-face-get
3839 :documentation-property
'group-documentation
3840 :help-echo
"Set or reset all members of this group."
3841 :value-create
'custom-group-value-create
3842 :action
'custom-group-action
3843 :custom-category
'group
3844 :custom-set
'custom-group-set
3845 :custom-mark-to-save
'custom-group-mark-to-save
3846 :custom-reset-current
'custom-group-reset-current
3847 :custom-reset-saved
'custom-group-reset-saved
3848 :custom-reset-standard
'custom-group-reset-standard
3849 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3850 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3851 :custom-menu
'custom-group-menu-create
)
3853 (defun custom-group-sample-face-get (widget)
3854 ;; Use :sample-face.
3855 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3858 (define-widget 'custom-group-visibility
'visibility
3859 "An indicator and manipulator for hidden group contents."
3860 :create
'custom-group-visibility-create
)
3862 (defun custom-group-visibility-create (widget)
3863 (let ((visible (widget-value widget
)))
3865 (insert "--------")))
3866 (widget-default-create widget
))
3868 (defun custom-group-members (symbol groups-only
)
3869 "Return SYMBOL's custom group members.
3870 If GROUPS-ONLY non-nil, return only those members that are groups."
3871 (if (not groups-only
)
3872 (get symbol
'custom-group
)
3874 (dolist (entry (get symbol
'custom-group
))
3875 (when (eq (nth 1 entry
) 'custom-group
)
3876 (push entry members
)))
3877 (nreverse members
))))
3879 (defun custom-group-value-create (widget)
3880 "Insert a customize group for WIDGET in the current buffer."
3881 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3882 (custom-load-widget widget
))
3883 (let* ((state (widget-get widget
:custom-state
))
3884 (level (widget-get widget
:custom-level
))
3885 ;; (indent (widget-get widget :indent))
3886 (prefix (widget-get widget
:custom-prefix
))
3887 (buttons (widget-get widget
:buttons
))
3888 (tag (widget-get widget
:tag
))
3889 (symbol (widget-value widget
))
3890 (members (custom-group-members symbol
3891 (and (eq custom-buffer-style
'tree
)
3892 custom-browse-only-groups
))))
3893 (cond ((and (eq custom-buffer-style
'tree
)
3895 (or members
(custom-unloaded-widget-p widget
)))
3896 (custom-browse-insert-prefix prefix
)
3897 (push (widget-create-child-and-convert
3898 widget
'custom-browse-visibility
3899 ;; :tag-glyph "plus"
3903 ;; (widget-glyph-insert nil "-- " "horizontal")
3904 (push (widget-create-child-and-convert
3905 widget
'custom-browse-group-tag
)
3907 (insert " " tag
"\n")
3908 (widget-put widget
:buttons buttons
))
3909 ((and (eq custom-buffer-style
'tree
)
3910 (zerop (length members
)))
3911 (custom-browse-insert-prefix prefix
)
3913 ;; (widget-glyph-insert nil "[ ]" "empty")
3914 ;; (widget-glyph-insert nil "-- " "horizontal")
3915 (push (widget-create-child-and-convert
3916 widget
'custom-browse-group-tag
)
3918 (insert " " tag
"\n")
3919 (widget-put widget
:buttons buttons
))
3920 ((eq custom-buffer-style
'tree
)
3921 (custom-browse-insert-prefix prefix
)
3922 (if (zerop (length members
))
3924 (custom-browse-insert-prefix prefix
)
3926 ;; (widget-glyph-insert nil "[ ]" "empty")
3927 ;; (widget-glyph-insert nil "-- " "horizontal")
3928 (push (widget-create-child-and-convert
3929 widget
'custom-browse-group-tag
)
3931 (insert " " tag
"\n")
3932 (widget-put widget
:buttons buttons
))
3933 (push (widget-create-child-and-convert
3934 widget
'custom-browse-visibility
3935 ;; :tag-glyph "minus"
3939 ;; (widget-glyph-insert nil "-\\ " "top")
3940 (push (widget-create-child-and-convert
3941 widget
'custom-browse-group-tag
)
3943 (insert " " tag
"\n")
3944 (widget-put widget
:buttons buttons
)
3945 (message "Creating group...")
3946 (let* ((members (custom-sort-items members
3947 custom-browse-sort-alphabetically
3948 custom-browse-order-groups
))
3949 (prefixes (widget-get widget
:custom-prefixes
))
3950 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3951 (extra-prefix (if (widget-get widget
:custom-last
)
3954 (prefix (concat prefix extra-prefix
))
3957 (setq entry
(car members
)
3958 members
(cdr members
))
3959 (push (widget-create-child-and-convert
3960 widget
(nth 1 entry
)
3962 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3963 :custom-prefixes custom-prefix-list
3964 :custom-level
(1+ level
)
3965 :custom-last
(null members
)
3966 :value
(nth 0 entry
)
3967 :custom-prefix prefix
)
3969 (widget-put widget
:children
(reverse children
)))
3970 (message "Creating group...done")))
3973 ;; Create level indicator.
3975 (if (eq custom-buffer-style
'links
)
3976 (push (widget-create-child-and-convert
3977 widget
'custom-group-link
3981 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3983 (push (widget-create-child-and-convert
3984 widget
'custom-group-visibility
3985 :help-echo
"Show members of this group."
3986 :action
'custom-toggle-parent
3987 (not (eq state
'hidden
)))
3990 ;; Create magic button.
3991 (let ((magic (widget-create-child-and-convert
3992 widget
'custom-magic nil
)))
3993 (widget-put widget
:custom-magic magic
)
3994 (push magic buttons
))
3996 (widget-put widget
:buttons buttons
)
3997 ;; Insert documentation.
3998 (if (and (eq custom-buffer-style
'links
) (> level
1))
3999 (widget-put widget
:documentation-indent
0))
4000 (widget-add-documentation-string-button
4001 widget
:visibility-widget
'custom-visibility
))
4005 ;; Add parent groups references above the group.
4006 (if t
;;; This should test that the buffer
4007 ;;; was made to display a group.
4009 (if (custom-add-parent-links widget
4011 "Parent group documentation:")
4013 ;; Create level indicator.
4014 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4017 (let ((start (point)))
4018 (insert tag
" group: ")
4019 (widget-specify-sample widget start
(point)))
4020 (insert (widget-docstring widget
))
4021 ;; Create visibility indicator.
4022 (unless (eq custom-buffer-style
'links
)
4024 (push (widget-create-child-and-convert
4026 :help-echo
"Hide members of this group."
4027 :action
'custom-toggle-parent
4028 (not (eq state
'hidden
)))
4031 ;; Create more dashes.
4032 ;; Use 76 instead of 75 to compensate for the temporary "<"
4033 ;; added by `widget-insert'.
4034 (insert-char ?-
(- 76 (current-column)
4035 (* custom-buffer-indent level
)))
4037 ;; Create magic button.
4038 (let ((magic (widget-create-child-and-convert
4039 widget
'custom-magic
4042 (widget-put widget
:custom-magic magic
)
4043 (push magic buttons
))
4045 (widget-put widget
:buttons buttons
)
4046 ;; Insert documentation.
4047 (widget-add-documentation-string-button
4048 widget
:visibility-widget
'custom-visibility
)
4051 (if nil
;;; This should test that the buffer
4052 ;;; was not made to display a group.
4054 (insert-char ?\ custom-buffer-indent
)
4055 (custom-add-parent-links widget
)))
4056 (custom-add-see-also widget
4057 (make-string (* custom-buffer-indent level
)
4060 (message "Creating group...")
4061 (let* ((members (custom-sort-items members
4062 custom-buffer-sort-alphabetically
4063 custom-buffer-order-groups
))
4064 (prefixes (widget-get widget
:custom-prefixes
))
4065 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4066 (length (length members
))
4068 (children (mapcar (lambda (entry)
4069 (widget-insert "\n")
4071 Creating group members... %2d%%"
4072 (/ (* 100.0 count
) length
))
4073 (setq count
(1+ count
))
4075 (widget-create-child-and-convert
4076 widget
(nth 1 entry
)
4078 :tag
(custom-unlispify-tag-name
4080 :custom-prefixes custom-prefix-list
4081 :custom-level
(1+ level
)
4082 :value
(nth 0 entry
))
4083 (unless (eq (preceding-char) ?
\n)
4084 (widget-insert "\n"))))
4086 (message "Creating group magic...")
4087 (mapc 'custom-magic-reset children
)
4088 (message "Creating group state...")
4089 (widget-put widget
:children children
)
4090 (custom-group-state-update widget
)
4091 (message "Creating group... done"))
4094 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4095 (insert "\\- " (widget-get widget
:tag
) " group end ")
4096 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
4099 (defvar custom-group-menu
4100 `(("Set for Current Session" custom-group-set
4102 (eq (widget-get widget
:custom-state
) 'modified
)))
4103 ,@(when (or custom-file init-file-user
)
4104 '(("Save for Future Sessions" custom-group-save
4106 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4107 ("Undo Edits" custom-group-reset-current
4109 (memq (widget-get widget
:custom-state
) '(modified))))
4110 ("Reset to Saved" custom-group-reset-saved
4112 (memq (widget-get widget
:custom-state
) '(modified set
))))
4113 ,@(when (or custom-file init-file-user
)
4114 '(("Erase Customization" custom-group-reset-standard
4116 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4117 "Alist of actions for the `custom-group' widget.
4118 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4119 the menu entry, ACTION is the function to call on the widget when the
4120 menu is selected, and FILTER is a predicate which takes a `custom-group'
4121 widget as an argument, and returns non-nil if ACTION is valid on that
4122 widget. If FILTER is nil, ACTION is always valid.")
4124 (defun custom-group-action (widget &optional event
)
4125 "Show the menu for `custom-group' WIDGET.
4126 Optional EVENT is the location for the menu."
4127 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4128 (custom-toggle-hide widget
)
4129 (let* ((completion-ignore-case t
)
4130 (answer (widget-choose (concat "Operation on "
4131 (custom-unlispify-tag-name
4132 (widget-get widget
:value
)))
4133 (custom-menu-filter custom-group-menu
4137 (funcall answer widget
)))))
4139 (defun custom-group-set (widget)
4140 "Set changes in all modified group members."
4141 (dolist (child (widget-get widget
:children
))
4142 (when (eq (widget-get child
:custom-state
) 'modified
)
4143 (widget-apply child
:custom-set
))))
4145 (defun custom-group-mark-to-save (widget)
4146 "Mark all modified group members for saving."
4147 (dolist (child (widget-get widget
:children
))
4148 (when (memq (widget-get child
:custom-state
) '(modified set
))
4149 (widget-apply child
:custom-mark-to-save
))))
4151 (defsubst custom-group-state-set-and-redraw
(widget)
4152 "Set state of group widget WIDGET and redraw with current settings."
4153 (dolist (child (widget-get widget
:children
))
4154 (when (memq (widget-get child
:custom-state
) '(modified set
))
4155 (widget-apply child
:custom-state-set-and-redraw
))))
4157 (defun custom-group-save (widget)
4158 "Save all modified group members."
4159 (custom-group-mark-to-save widget
)
4161 (custom-group-state-set-and-redraw widget
))
4163 (defun custom-group-reset-current (widget)
4164 "Reset all modified group members."
4165 (dolist (child (widget-get widget
:children
))
4166 (when (eq (widget-get child
:custom-state
) 'modified
)
4167 (widget-apply child
:custom-reset-current
))))
4169 (defun custom-group-reset-saved (widget)
4170 "Reset all modified or set group members."
4171 (dolist (child (widget-get widget
:children
))
4172 (when (memq (widget-get child
:custom-state
) '(modified set
))
4173 (widget-apply child
:custom-reset-saved
))))
4175 (defun custom-group-reset-standard (widget)
4176 "Reset all modified, set, or saved group members."
4177 (let ((custom-reset-standard-variables-list '(t))
4178 (custom-reset-standard-faces-list '(t)))
4179 (custom-group-mark-to-reset-standard widget
)
4180 (custom-reset-standard-save-and-update)))
4182 (defun custom-group-mark-to-reset-standard (widget)
4183 "Mark to reset all modified, set, or saved group members."
4184 (dolist (child (widget-get widget
:children
))
4185 (when (memq (widget-get child
:custom-state
)
4186 '(modified set saved
))
4187 (widget-apply child
:custom-mark-to-reset-standard
))))
4189 (defun custom-group-state-update (widget)
4191 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4192 (let* ((children (widget-get widget
:children
))
4193 (states (mapcar (lambda (child)
4194 (widget-get child
:custom-state
))
4196 (magics custom-magic-alist
)
4199 (let ((magic (car (car magics
))))
4200 (if (and (not (eq magic
'hidden
))
4201 (memq magic states
))
4204 (setq magics
(cdr magics
)))))
4205 (widget-put widget
:custom-state found
)))
4206 (custom-magic-reset widget
))
4208 ;;; Reading and writing the custom file.
4211 (defcustom custom-file nil
4212 "File used for storing customization information.
4213 The default is nil, which means to use your init file
4214 as specified by `user-init-file'. If the value is not nil,
4215 it should be an absolute file name.
4217 You can set this option through Custom, if you carefully read the
4218 last paragraph below. However, usually it is simpler to write
4219 something like the following in your init file:
4221 \(setq custom-file \"~/.emacs-custom.el\")
4224 Note that both lines are necessary: the first line tells Custom to
4225 save all customizations in this file, but does not load it.
4227 When you change this variable outside Custom, look in the
4228 previous custom file \(usually your init file) for the
4229 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4230 and copy them (whichever ones you find) to the new custom file.
4231 This will preserve your existing customizations.
4233 If you save this option using Custom, Custom will write all
4234 currently saved customizations, including the new one for this
4235 option itself, into the file you specify, overwriting any
4236 `custom-set-variables' and `custom-set-faces' forms already
4237 present in that file. It will not delete any customizations from
4238 the old custom file. You should do that manually if that is what you
4239 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4240 in your init file, where CUSTOM-FILE is the actual name of the
4241 file. Otherwise, Emacs will not load the file when it starts up,
4242 and hence will not set `custom-file' to that file either."
4243 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4244 (file :format
"%t:%v%d"
4246 "Please read entire docstring below before setting \
4247 this through Custom.
4248 Click om \"More\" \(or position point there and press RETURN)
4249 if only the first line of the docstring is shown."))
4252 (defun custom-file ()
4253 "Return the file name for saving customizations."
4256 (let ((user-init-file user-init-file
)
4258 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4259 (when (null user-init-file
)
4260 (if (or (file-exists-p default-init-file
)
4261 (and (eq system-type
'windows-nt
)
4262 (file-exists-p "~/_emacs")))
4263 ;; Started with -q, i.e. the file containing
4264 ;; Custom settings hasn't been read. Saving
4265 ;; settings there would overwrite other settings.
4266 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4267 (setq user-init-file default-init-file
))
4270 ;; If recentf-mode is non-nil, this is defined.
4271 (declare-function recentf-expand-file-name
"recentf" (name))
4274 (defun custom-save-all ()
4275 "Save all customizations in `custom-file'."
4276 (when (and (null custom-file
) init-file-had-error
)
4277 (error "Cannot save customizations; init file was not fully loaded"))
4278 (let* ((filename (custom-file))
4283 (recentf-expand-file-name (custom-file)))
4286 (old-buffer (find-buffer-visiting filename
)))
4287 (with-current-buffer (let ((find-file-visit-truename t
))
4288 (or old-buffer
(find-file-noselect filename
)))
4289 (unless (eq major-mode
'emacs-lisp-mode
)
4291 (let ((inhibit-read-only t
))
4292 (custom-save-variables)
4293 (custom-save-faces))
4294 (let ((file-precious-flag t
))
4297 (kill-buffer (current-buffer))))))
4300 (defun customize-save-customized ()
4301 "Save all user options which have been set in this session."
4303 (mapatoms (lambda (symbol)
4304 (let ((face (get symbol
'customized-face
))
4305 (value (get symbol
'customized-value
))
4306 (face-comment (get symbol
'customized-face-comment
))
4308 (get symbol
'customized-variable-comment
)))
4310 (put symbol
'saved-face face
)
4311 (custom-push-theme 'theme-face symbol
'user
'set value
)
4312 (put symbol
'customized-face nil
))
4314 (put symbol
'saved-value value
)
4315 (custom-push-theme 'theme-value symbol
'user
'set value
)
4316 (put symbol
'customized-value nil
))
4317 (when variable-comment
4318 (put symbol
'saved-variable-comment variable-comment
)
4319 (put symbol
'customized-variable-comment nil
))
4321 (put symbol
'saved-face-comment face-comment
)
4322 (put symbol
'customized-face-comment nil
)))))
4323 ;; We really should update all custom buffers here.
4326 ;; Editing the custom file contents in a buffer.
4328 (defun custom-save-delete (symbol)
4329 "Delete all calls to SYMBOL from the contents of the current buffer.
4330 Leave point at the old location of the first such call,
4331 or (if there were none) at the end of the buffer.
4333 This function does not save the buffer."
4334 (goto-char (point-min))
4335 ;; Skip all whitespace and comments.
4336 (while (forward-comment 1))
4338 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4341 (while t
;; We exit this loop only via throw.
4342 ;; Skip all whitespace and comments.
4343 (while (forward-comment 1))
4344 (let ((start (point))
4345 (sexp (condition-case nil
4346 (read (current-buffer))
4347 (end-of-file (throw 'found nil
)))))
4348 (when (and (listp sexp
)
4349 (eq (car sexp
) symbol
))
4350 (delete-region start
(point))
4352 (setq first
(point)))))))
4355 ;; Move in front of local variables, otherwise long Custom
4356 ;; entries would make them ineffective.
4357 (let ((pos (point-max))
4358 (case-fold-search t
))
4360 (goto-char (point-max))
4361 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4363 (when (search-forward "Local Variables:" nil t
)
4364 (setq pos
(line-beginning-position))))
4367 (defun custom-save-variables ()
4368 "Save all customized variables in `custom-file'."
4370 (custom-save-delete 'custom-set-variables
)
4371 (let ((standard-output (current-buffer))
4372 (saved-list (make-list 1 0))
4374 ;; First create a sorted list of saved variables.
4377 (if (and (get symbol
'saved-value
)
4378 ;; ignore theme values
4379 (or (null (get symbol
'theme-value
))
4380 (eq 'user
(caar (get symbol
'theme-value
)))))
4381 (nconc saved-list
(list symbol
)))))
4382 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4385 (princ "(custom-set-variables
4386 ;; custom-set-variables was added by Custom.
4387 ;; If you edit it by hand, you could mess it up, so be careful.
4388 ;; Your init file should contain only one such instance.
4389 ;; If there is more than one, they won't work right.\n")
4390 (dolist (symbol saved-list
)
4391 (let ((spec (car-safe (get symbol
'theme-value
)))
4392 (value (get symbol
'saved-value
))
4393 (requests (get symbol
'custom-requests
))
4394 (now (and (not (custom-variable-p symbol
))
4396 (eq (get symbol
'force-value
)
4398 (comment (get symbol
'saved-variable-comment
)))
4399 ;; Check REQUESTS for validity.
4400 (dolist (request requests
)
4401 (when (and (symbolp request
) (not (featurep request
)))
4402 (message "Unknown requested feature: %s" request
)
4403 (setq requests
(delq request requests
))))
4404 ;; Is there anything customized about this variable?
4405 (when (or (and spec
(eq (car spec
) 'user
))
4407 (and (null spec
) (get symbol
'saved-value
)))
4408 ;; Output an element for this variable.
4409 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4410 ;; SYMBOL is the variable name.
4411 ;; VALUE-FORM is an expression to return the customized value.
4412 ;; NOW if non-nil means always set the variable immediately
4413 ;; when the customizations are reloaded. This is used
4414 ;; for rogue variables
4415 ;; REQUESTS is a list of packages to load before setting the
4416 ;; variable. Each element of it will be passed to `require'.
4417 ;; COMMENT is whatever comment the user has specified
4418 ;; with the customize facility.
4425 (when (or now requests comment
)
4428 (when (or requests comment
)
4438 (unless (looking-at "\n")
4441 (defun custom-save-faces ()
4442 "Save all customized faces in `custom-file'."
4444 (custom-save-delete 'custom-reset-faces
)
4445 (custom-save-delete 'custom-set-faces
)
4446 (let ((standard-output (current-buffer))
4447 (saved-list (make-list 1 0))
4449 ;; First create a sorted list of saved faces.
4452 (if (and (get symbol
'saved-face
)
4453 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4454 (nconc saved-list
(list symbol
)))))
4455 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4456 ;; The default face must be first, since it affects the others.
4457 (if (memq 'default saved-list
)
4458 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4461 (princ "(custom-set-faces
4462 ;; custom-set-faces was added by Custom.
4463 ;; If you edit it by hand, you could mess it up, so be careful.
4464 ;; Your init file should contain only one such instance.
4465 ;; If there is more than one, they won't work right.\n")
4466 (dolist (symbol saved-list
)
4467 (let ((spec (car-safe (get symbol
'theme-face
)))
4468 (value (get symbol
'saved-face
))
4469 (now (not (or (get symbol
'face-defface-spec
)
4470 (and (not (custom-facep symbol
))
4471 (not (get symbol
'force-face
))))))
4472 (comment (get symbol
'saved-face-comment
)))
4473 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4475 (and (null spec
) (get symbol
'saved-face
)))
4476 ;; Don't print default face here.
4483 (when (or now comment
)
4493 (unless (looking-at "\n")
4496 ;;; The Customize Menu.
4500 (defcustom custom-menu-nesting
2
4501 "Maximum nesting in custom menus."
4503 :group
'custom-menu
)
4505 (defun custom-face-menu-create (widget symbol
)
4506 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4507 (vector (custom-unlispify-menu-entry symbol
)
4508 `(customize-face ',symbol
)
4511 (defun custom-variable-menu-create (widget symbol
)
4512 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4513 (let ((type (get symbol
'custom-type
)))
4514 (unless (listp type
)
4515 (setq type
(list type
)))
4516 (if (and type
(widget-get type
:custom-menu
))
4517 (widget-apply type
:custom-menu symbol
)
4518 (vector (custom-unlispify-menu-entry symbol
)
4519 `(customize-variable ',symbol
)
4522 ;; Add checkboxes to boolean variable entries.
4523 (widget-put (get 'boolean
'widget-type
)
4524 :custom-menu
(lambda (widget symbol
)
4525 (vector (custom-unlispify-menu-entry symbol
)
4526 `(customize-variable ',symbol
)
4528 ':selected symbol
)))
4530 (defun custom-group-menu-create (widget symbol
)
4531 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4532 `( ,(custom-unlispify-menu-entry symbol t
)
4533 :filter
(lambda (&rest junk
)
4534 (let* ((menu (custom-menu-create ',symbol
)))
4535 (if (consp menu
) (cdr menu
) menu
)))))
4538 (defun custom-menu-create (symbol)
4539 "Create menu for customization group SYMBOL.
4540 The menu is in a format applicable to `easy-menu-define'."
4541 (let* ((deactivate-mark nil
)
4542 (item (vector (custom-unlispify-menu-entry symbol
)
4543 `(customize-group ',symbol
)
4545 (if (and (or (not (boundp 'custom-menu-nesting
))
4546 (>= custom-menu-nesting
0))
4548 (custom-load-symbol symbol
)
4549 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4550 (let ((custom-prefix-list (custom-prefix-add symbol
4551 custom-prefix-list
))
4552 (members (custom-sort-items (get symbol
'custom-group
)
4553 custom-menu-sort-alphabetically
4554 custom-menu-order-groups
)))
4555 `(,(custom-unlispify-menu-entry symbol t
)
4558 ,@(mapcar (lambda (entry)
4559 (widget-apply (if (listp (nth 1 entry
))
4561 (list (nth 1 entry
)))
4562 :custom-menu
(nth 0 entry
)))
4567 (defun customize-menu-create (symbol &optional name
)
4568 "Return a customize menu for customization group SYMBOL.
4569 If optional NAME is given, use that as the name of the menu.
4570 Otherwise the menu will be named `Customize'.
4571 The format is suitable for use with `easy-menu-define'."
4573 (setq name
"Customize"))
4575 :filter
(lambda (&rest junk
)
4576 (let ((menu (custom-menu-create ',symbol
)))
4577 (if (consp menu
) (cdr menu
) menu
)))))
4579 ;;; Toolbar and menubar support
4582 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4583 "Menu used in customization buffers."
4584 (nconc (list "Custom"
4585 (customize-menu-create 'customize
))
4586 (mapcar (lambda (arg)
4587 (let ((tag (nth 0 arg
))
4588 (command (nth 1 arg
))
4589 (active (nth 2 arg
))
4591 (vector tag command
:active
(eval active
) :help help
)))
4594 (defvar tool-bar-map
)
4596 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4597 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4598 ;;; we set this up lazily in `custom-mode'.
4599 (defvar custom-tool-bar-map nil
4600 "Keymap for toolbar in Custom mode.")
4602 ;;; The Custom Mode.
4604 (defun Custom-no-edit (pos &optional event
)
4605 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4607 (error "You can't edit this part of the Custom buffer"))
4609 (defun Custom-newline (pos &optional event
)
4610 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4612 (let ((button (get-char-property pos
'button
)))
4614 (widget-apply-action button event
)
4615 (error "You can't edit this part of the Custom buffer"))))
4617 (defun Custom-goto-parent ()
4618 "Go to the parent group listed at the top of this buffer.
4619 If several parents are listed, go to the first of them."
4622 (goto-char (point-min))
4623 (if (search-forward "\nParent groups: " nil t
)
4624 (let* ((button (get-char-property (point) 'button
))
4625 (parent (downcase (widget-get button
:tag
))))
4626 (customize-group parent
)))))
4628 (defcustom custom-mode-hook nil
4629 "Hook called when entering Custom mode."
4631 :group
'custom-buffer
)
4633 (defun custom-state-buffer-message (widget)
4634 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4635 (message "To install your edits, invoke [State] and choose the Set operation")))
4637 (define-derived-mode custom-mode nil
"Custom"
4638 "Major mode for editing customization buffers.
4640 The following commands are available:
4643 Move to next button, link or editable field. \\[widget-forward]
4644 Move to previous button, link or editable field. \\[advertised-widget-backward]
4645 \\<custom-field-keymap>\
4646 Complete content of editable text field. \\[widget-complete]
4647 \\<custom-mode-map>\
4648 Invoke button under the mouse pointer. \\[widget-button-click]
4649 Invoke button under point. \\[widget-button-press]
4650 Set all options from current text. \\[Custom-set]
4651 Make values in current text permanent. \\[Custom-save]
4652 Make text match actual option values. \\[Custom-reset-current]
4653 Reset options to permanent settings. \\[Custom-reset-saved]
4654 Erase customizations; set options
4655 and buffer text to the standard values. \\[Custom-reset-standard]
4657 Entry to this mode calls the value of `custom-mode-hook'
4658 if that value is non-nil."
4659 (use-local-map custom-mode-map
)
4660 (easy-menu-add Custom-mode-menu
)
4661 (when (display-graphic-p)
4662 (set (make-local-variable 'tool-bar-map
)
4663 (or custom-tool-bar-map
4664 ;; Set up `custom-tool-bar-map'.
4665 (let ((map (make-sparse-keymap)))
4668 (tool-bar-local-item-from-menu
4669 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4671 (setq custom-tool-bar-map map
)))))
4672 (make-local-variable 'custom-options
)
4673 (make-local-variable 'custom-local-buffer
)
4674 (make-local-variable 'widget-documentation-face
)
4675 (setq widget-documentation-face
'custom-documentation
)
4676 (make-local-variable 'widget-button-face
)
4677 (setq widget-button-face custom-button
)
4678 (setq show-trailing-whitespace nil
)
4680 ;; We need this because of the "More" button on docstrings.
4681 ;; Otherwise clicking on "More" can push point offscreen, which
4682 ;; causes the window to recenter on point, which pushes the
4683 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4684 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4686 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4687 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4689 ;; When possible, use relief for buttons, not bracketing. This test
4690 ;; may not be optimal.
4691 (when custom-raised-buttons
4692 (set (make-local-variable 'widget-push-button-prefix
) "")
4693 (set (make-local-variable 'widget-push-button-suffix
) "")
4694 (set (make-local-variable 'widget-link-prefix
) "")
4695 (set (make-local-variable 'widget-link-suffix
) ""))
4696 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4698 (put 'custom-mode
'mode-class
'special
)
4701 '("^No user option defaults have been changed since Emacs "
4703 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4704 "^No customizable items matching "
4705 "^There are unset changes"
4706 "^Cannot set hidden variable"
4707 "^No \\(?:saved\\|backup\\) value for "
4708 "^No standard setting known for "
4709 "^No standard setting for this face"
4710 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4711 (add-to-list 'debug-ignored-errors regexp
))
4717 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4718 ;;; cus-edit.el ends here