1 ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; Keywords: help, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file implements the code to create and edit customize buffers.
31 ;; No commands should have names starting with `custom-' because
32 ;; that interferes with completion. Use `customize-' for commands
33 ;; that the user will run with M-x, and `Custom-' for interactive commands.
35 ;; The identity of a customize option is represented by a Lisp symbol.
36 ;; The following values are associated with an option.
38 ;; 0. The current value.
40 ;; This is the value of the option as seen by "the rest of Emacs".
42 ;; Usually extracted by 'default-value', but can be extracted with
43 ;; different means if the option symbol has the 'custom-get'
44 ;; property. Similarly, set-default (or the 'custom-set' property)
47 ;; 1. The widget value.
49 ;; This is the value shown in the widget in a customize buffer.
51 ;; 2. The customized value.
53 ;; This is the last value given to the option through customize.
55 ;; It is stored in the 'customized-value' property of the option, in a
56 ;; cons-cell whose car evaluates to the customized value.
58 ;; 3. The saved value.
60 ;; This is last value saved from customize.
62 ;; It is stored in the 'saved-value' property of the option, in a
63 ;; cons-cell whose car evaluates to the saved value.
65 ;; 4. The standard value.
67 ;; This is the value given in the 'defcustom' declaration.
69 ;; It is stored in the 'standard-value' property of the option, in a
70 ;; cons-cell whose car evaluates to the standard value.
72 ;; 5. The "think" value.
74 ;; This is what customize thinks the current value should be.
76 ;; This is the customized value, if any such value exists, otherwise
77 ;; the saved value, if that exists, and as a last resort the standard
80 ;; The reason for storing values unevaluated: This is so you can have
81 ;; values that depend on the environment. For example, you can have a
82 ;; variable that has one value when Emacs is running under a window
83 ;; system, and another value on a tty. Since the evaluation is only done
84 ;; when the variable is first initialized, this is only relevant for the
85 ;; saved (and standard) values, but affect others values for
88 ;; You can see (and modify and save) this unevaluated value by selecting
89 ;; "Show Saved Lisp Expression" from the Lisp interface. This will
90 ;; give you the unevaluated saved value, if any, otherwise the
91 ;; unevaluated standard value.
93 ;; The possible states for a customize widget are:
97 ;; The state has not been determined yet.
101 ;; The widget value is different from the current value.
105 ;; The current value is different from the "think" value.
109 ;; The "think" value is the customized value.
113 ;; The "think" value is the saved value.
117 ;; The "think" value is the standard value.
121 ;; There is no standard value. This means that the variable was
122 ;; not defined with defcustom, nor handled in cus-start.el. Most
123 ;; standard interactive Custom commands do not let you create a
124 ;; Custom buffer containing such variables. However, such Custom
125 ;; buffers can be created, for instance, by calling
126 ;; `customize-apropos' with a prefix arg or by calling
127 ;; `customize-option' non-interactively.
131 ;; There is no widget value.
135 ;; The widget value is not valid member of the :type specified for the
143 (defvar custom-versions-load-alist
) ; from cus-load
144 (defvar recentf-exclude
) ; from recentf.el
154 (put 'custom-define-hook
'custom-type
'hook
)
155 (put 'custom-define-hook
'standard-value
'(nil))
156 (custom-add-to-group 'customize
'custom-define-hook
'custom-variable
)
158 ;;; Customization Groups.
161 "Customization of the One True Editor."
162 :link
'(custom-manual "(emacs)Top"))
164 ;; Most of these groups are stolen from `finder.el',
165 (defgroup editing nil
166 "Basic text editing facilities."
170 "Abbreviation handling, typing shortcuts, macros."
174 (defgroup matching nil
175 "Various sorts of searching and matching."
178 (defgroup emulations nil
179 "Emulations of other editors."
180 :link
'(custom-manual "(emacs)Emulation")
187 (defgroup outlines nil
188 "Support for hierarchical outlining."
191 (defgroup external nil
192 "Interfacing to external utilities."
196 "Networking support."
199 (defgroup processes nil
200 "Process, subshell, compilation, and job control support."
203 (defgroup convenience nil
204 "Convenience features for faster editing."
207 (defgroup programming nil
208 "Support for programming in other languages."
211 (defgroup languages nil
212 "Specialized modes for editing programming languages."
216 "Lisp support, including Emacs Lisp."
217 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
222 "Support for the C language and related languages."
223 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
224 :link
'(custom-manual "(ccmode)")
231 (defgroup applications nil
232 "Applications written in Emacs."
235 (defgroup calendar nil
236 "Calendar and time management support."
237 :group
'applications
)
240 "Modes for electronic-mail handling."
241 :group
'applications
)
244 "Support for netnews reading and posting."
245 :link
'(custom-manual "(gnus)")
246 :group
'applications
)
249 "Games, jokes and amusements."
250 :group
'applications
)
252 (defgroup development nil
253 "Support for further development of Emacs."
257 "Support for Emacs documentation."
260 (defgroup extensions nil
261 "Emacs Lisp language extensions."
264 (defgroup internal nil
265 "Code for Emacs internals, build process, defaults."
269 "Maintenance aids for the Emacs development group."
273 (defgroup environment nil
274 "Fitting Emacs with its environment."
278 "Communications, networking, remote access to files."
282 (defgroup hardware nil
283 "Support for interfacing with miscellaneous hardware."
286 (defgroup terminals nil
287 "Support for terminal types."
291 "Front-ends/assistants for, or emulators of, UNIX features."
295 "Internationalization and alternate character-set support."
296 :link
'(custom-manual "(emacs)International")
301 "The X Window system."
305 "Support for Emacs frames and window systems."
309 "Support for editing files of data."
313 "Support for editing files."
321 "Code related to the TeX formatter."
322 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
326 "Support for multiple fonts."
330 "Support for on-line help systems."
333 (defgroup multimedia nil
334 "Non-textual support, specifically images and sound."
338 "Code local to your site."
341 (defgroup customize
'((widgets custom-group
))
342 "Customization of the Customization support."
346 (defgroup custom-faces nil
347 "Faces used by customize."
351 (defgroup custom-browse nil
352 "Control customize browser."
356 (defgroup custom-buffer nil
357 "Control customize buffers."
361 (defgroup custom-menu nil
362 "Control customize menus."
367 "Storage allocation and gc for GNU Emacs Lisp interpreter."
368 :tag
"Storage Allocation"
372 "Undoing changes in buffers."
373 :link
'(custom-manual "(emacs)Undo")
376 (defgroup mode-line nil
377 "Content of the modeline."
380 (defgroup editing-basics nil
381 "Most basic editing facilities."
384 (defgroup display nil
385 "How characters are displayed in buffers."
388 (defgroup execute nil
389 "Executing external commands."
392 (defgroup installation nil
393 "The Emacs installation."
401 "Internal Emacs limits."
405 "Debugging Emacs itself."
408 (defgroup keyboard nil
409 "Input from the keyboard."
413 "Input from the mouse."
417 "Input from the menus."
421 "Handling data from drag and drop."
424 (defgroup auto-save nil
425 "Preventing accidental loss of data."
428 (defgroup processes-basics nil
429 "Basic stuff dealing with processes."
433 "MULE Emacs internationalization."
436 (defgroup windows nil
437 "Windows within a frame."
438 :link
'(custom-manual "(emacs)Windows")
441 ;;; Custom mode keymaps
443 (defvar custom-mode-map
444 ;; This keymap should be dense, but a dense keymap would prevent inheriting
445 ;; "\r" bindings from the parent map.
446 ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26.
447 (let ((map (make-keymap)))
448 (set-keymap-parent map widget-keymap
)
449 (define-key map
[remap self-insert-command
] 'Custom-no-edit
)
450 (define-key map
"\^m" 'Custom-newline
)
451 (define-key map
" " 'scroll-up
)
452 (define-key map
"\177" 'scroll-down
)
453 (define-key map
"\C-c\C-c" 'Custom-set
)
454 (define-key map
"\C-x\C-s" 'Custom-save
)
455 (define-key map
"q" 'Custom-buffer-done
)
456 (define-key map
"u" 'Custom-goto-parent
)
457 (define-key map
"n" 'widget-forward
)
458 (define-key map
"p" 'widget-backward
)
460 "Keymap for `Custom-mode'.")
462 (defvar custom-mode-link-map
463 (let ((map (make-keymap)))
464 (set-keymap-parent map custom-mode-map
)
465 (define-key map
[down-mouse-2
] nil
)
466 (define-key map
[down-mouse-1
] 'mouse-drag-region
)
467 (define-key map
[mouse-2
] 'widget-move-and-invoke
)
469 "Local keymap for links in `Custom-mode'.")
471 (defvar custom-field-keymap
472 (let ((map (copy-keymap widget-field-keymap
)))
473 (define-key map
"\C-c\C-c" 'Custom-set
)
474 (define-key map
"\C-x\C-s" 'Custom-save
)
476 "Keymap used inside editable fields in customization buffers.")
478 (widget-put (get 'editable-field
'widget-type
) :keymap custom-field-keymap
)
482 (defun custom-split-regexp-maybe (regexp)
483 "If REGEXP is a string, split it to a list at `\\|'.
484 You can get the original back from the result with:
485 (mapconcat 'identity result \"\\|\")
487 IF REGEXP is not a string, return it unchanged."
489 (split-string regexp
"\\\\|")
492 (defun custom-variable-prompt ()
493 "Prompt for a custom variable, defaulting to the variable at point.
494 Return a list suitable for use in `interactive'."
495 (let* ((v (variable-at-point))
496 (default (and (symbolp v
) (custom-variable-p v
) (symbol-name v
)))
497 (enable-recursive-minibuffers t
)
499 (setq val
(completing-read
500 (if default
(format "Customize variable (default %s): " default
)
501 "Customize variable: ")
502 obarray
'custom-variable-p t nil nil default
))
503 (list (if (equal val
"")
504 (if (symbolp v
) v nil
)
507 (defun custom-menu-filter (menu widget
)
508 "Convert MENU to the form used by `widget-choose'.
509 MENU should be in the same format as `custom-variable-menu'.
510 WIDGET is the widget to apply the filter entries of MENU on."
512 current name action filter
)
514 (setq current
(car menu
)
516 action
(nth 1 current
)
517 filter
(nth 2 current
)
519 (if (or (null filter
) (funcall filter widget
))
520 (push (cons name action
) result
)
526 (defvar custom-prefix-list nil
527 "List of prefixes that should be ignored by `custom-unlispify'.")
529 (defcustom custom-unlispify-menu-entries t
530 "Display menu entries as words instead of symbols if non-nil."
534 (defcustom custom-unlispify-remove-prefixes nil
535 "Non-nil means remove group prefixes from option names in buffer."
537 :group
'custom-buffer
540 (defun custom-unlispify-menu-entry (symbol &optional no-suffix
)
541 "Convert SYMBOL into a menu entry."
542 (cond ((not custom-unlispify-menu-entries
)
543 (symbol-name symbol
))
544 ((get symbol
'custom-tag
)
546 (get symbol
'custom-tag
)
547 (concat (get symbol
'custom-tag
) "...")))
549 (with-current-buffer (get-buffer-create " *Custom-Work*")
551 (princ symbol
(current-buffer))
552 (goto-char (point-min))
553 ;; FIXME: Boolean variables are not predicates, so they shouldn't
554 ;; end with `-p'. -stef
555 ;; (when (and (eq (get symbol 'custom-type) 'boolean)
556 ;; (re-search-forward "-p\\'" nil t))
557 ;; (replace-match "" t t)
558 ;; (goto-char (point-min)))
559 (if custom-unlispify-remove-prefixes
560 (let ((prefixes custom-prefix-list
)
563 (setq prefix
(car prefixes
))
564 (if (search-forward prefix
(+ (point) (length prefix
)) t
)
567 (delete-region (point-min) (point)))
568 (setq prefixes
(cdr prefixes
))))))
569 (subst-char-in-region (point-min) (point-max) ?- ?\ t
)
570 (capitalize-region (point-min) (point-max))
572 (goto-char (point-max))
576 (defcustom custom-unlispify-tag-names t
577 "Display tag names as words instead of symbols if non-nil."
578 :group
'custom-buffer
581 (defun custom-unlispify-tag-name (symbol)
582 "Convert SYMBOL into a menu entry."
583 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names
))
584 (custom-unlispify-menu-entry symbol t
)))
586 (defun custom-prefix-add (symbol prefixes
)
587 "Add SYMBOL to list of ignored PREFIXES."
588 (cons (or (get symbol
'custom-prefix
)
589 (concat (symbol-name symbol
) "-"))
594 (defcustom custom-guess-name-alist
600 ("-function\\'" function
)
601 ("-functions\\'" (repeat function
))
602 ("-list\\'" (repeat sexp
))
603 ("-alist\\'" (repeat (cons sexp sexp
))))
604 "Alist of (MATCH TYPE).
606 MATCH should be a regexp matching the name of a symbol, and TYPE should
607 be a widget suitable for editing the value of that symbol. The TYPE
608 of the first entry where MATCH matches the name of the symbol will be
611 This is used for guessing the type of variables not declared with
613 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
614 :group
'custom-buffer
)
616 (defcustom custom-guess-doc-alist
617 '(("\\`\\*?Non-nil " boolean
))
618 "Alist of (MATCH TYPE).
620 MATCH should be a regexp matching a documentation string, and TYPE
621 should be a widget suitable for editing the value of a variable with
622 that documentation string. The TYPE of the first entry where MATCH
623 matches the name of the symbol will be used.
625 This is used for guessing the type of variables not declared with
627 :type
'(repeat (group (regexp :tag
"Match") (sexp :tag
"Type")))
628 :group
'custom-buffer
)
630 (defun custom-guess-type (symbol)
631 "Guess a widget suitable for editing the value of SYMBOL.
632 This is done by matching SYMBOL with `custom-guess-name-alist' and
633 if that fails, the doc string with `custom-guess-doc-alist'."
634 (let ((name (symbol-name symbol
))
635 (names custom-guess-name-alist
)
638 (setq current
(car names
)
640 (when (string-match (nth 0 current
) name
)
641 (setq found
(nth 1 current
)
644 (let ((doc (documentation-property symbol
'variable-documentation
))
645 (docs custom-guess-doc-alist
))
648 (setq current
(car docs
)
650 (when (string-match (nth 0 current
) doc
)
651 (setq found
(nth 1 current
)
658 (defcustom custom-browse-sort-alphabetically nil
659 "If non-nil, sort customization group alphabetically in `custom-browse'."
661 :group
'custom-browse
)
663 (defcustom custom-browse-order-groups nil
664 "If non-nil, order group members within each customization group.
665 If `first', order groups before non-groups.
666 If `last', order groups after non-groups."
667 :type
'(choice (const first
)
669 (const :tag
"none" nil
))
670 :group
'custom-browse
)
672 (defcustom custom-browse-only-groups nil
673 "If non-nil, show group members only within each customization group."
675 :group
'custom-browse
)
678 (defcustom custom-buffer-sort-alphabetically nil
679 "If non-nil, sort each customization group alphabetically in Custom buffer."
681 :group
'custom-buffer
)
683 (defcustom custom-buffer-order-groups
'last
684 "If non-nil, order group members within each customization group.
685 If `first', order groups before non-groups.
686 If `last', order groups after non-groups."
687 :type
'(choice (const first
)
689 (const :tag
"none" nil
))
690 :group
'custom-buffer
)
693 (defcustom custom-menu-sort-alphabetically nil
694 "If non-nil, sort each customization group alphabetically in menus."
698 (defcustom custom-menu-order-groups
'first
699 "If non-nil, order group members within each customization group.
700 If `first', order groups before non-groups.
701 If `last', order groups after non-groups."
702 :type
'(choice (const first
)
704 (const :tag
"none" nil
))
707 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\`\\*Customiz.*\\*\\'"))
709 (defun custom-sort-items (items sort-alphabetically order-groups
)
710 "Return a sorted copy of ITEMS.
711 ITEMS should be a `custom-group' property.
712 If SORT-ALPHABETICALLY non-nil, sort alphabetically.
713 If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
714 groups after non-groups, if nil do not order groups at all."
715 (sort (copy-sequence items
)
717 (let ((typea (nth 1 a
)) (typeb (nth 1 b
))
718 (namea (nth 0 a
)) (nameb (nth 0 b
)))
719 (cond ((not order-groups
)
720 ;; Since we don't care about A and B order, maybe sort.
721 (when sort-alphabetically
722 (string-lessp namea nameb
)))
723 ((eq typea
'custom-group
)
724 ;; If B is also a group, maybe sort. Otherwise, order A and B.
725 (if (eq typeb
'custom-group
)
726 (when sort-alphabetically
727 (string-lessp namea nameb
))
728 (eq order-groups
'first
)))
729 ((eq typeb
'custom-group
)
730 ;; Since A cannot be a group, order A and B.
731 (eq order-groups
'last
))
733 ;; Since A and B cannot be groups, sort.
734 (string-lessp namea nameb
)))))))
736 ;;; Custom Mode Commands.
738 ;; This variable is used by `custom-tool-bar-map', or directly by
739 ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
741 (defvar custom-commands
742 '(("Set for current session" Custom-set t
743 "Apply all settings in this buffer to the current session"
745 ("Save for future sessions" Custom-save
746 (or custom-file user-init-file
)
747 "Apply all settings in this buffer and save them for future Emacs sessions."
749 ("Undo edits" Custom-reset-current t
750 "Restore all settings in this buffer to reflect their current values."
752 ("Reset to saved" Custom-reset-saved t
753 "Restore all settings in this buffer to their saved values (if any)."
755 ("Erase customizations" Custom-reset-standard
756 (or custom-file user-init-file
)
757 "Un-customize all settings in this buffer and save them with standard values."
759 ("Help for Customize" Custom-help t
760 "Get help for using Customize."
762 ("Exit" Custom-buffer-done t
"Exit Customize." "exit")))
764 (defun Custom-help ()
765 "Read the node on Easy Customization in the Emacs manual."
767 (info "(emacs)Easy Customization"))
769 (defvar custom-reset-menu
770 '(("Undo Edits" . Custom-reset-current
)
771 ("Reset to Saved" . Custom-reset-saved
)
772 ("Erase Customizations (use standard values)" . Custom-reset-standard
))
773 "Alist of actions for the `Reset' button.
774 The key is a string containing the name of the action, the value is a
775 Lisp function taking the widget as an element which will be called
776 when the action is chosen.")
778 (defvar custom-options nil
779 "Customization widgets in the current buffer.")
781 (defun custom-command-apply (fun query
&optional strong-query
)
782 "Call function FUN on all widgets in `custom-options'.
783 If there is more than one widget, ask user for confirmation using
784 the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
785 and `yes-or-no-p' otherwise."
786 (if (or (and (= 1 (length custom-options
))
787 (memq (widget-type (car custom-options
))
788 '(custom-variable custom-face
)))
789 (funcall (if strong-query
'yes-or-no-p
'y-or-n-p
) query
))
790 (progn (mapc fun custom-options
) t
)
794 (defun Custom-set (&rest ignore
)
795 "Set the current value of all edited settings in the buffer."
797 (custom-command-apply
799 (when (eq (widget-get child
:custom-state
) 'modified
)
800 (widget-apply child
:custom-set
)))
801 "Set all values according to this buffer? "))
803 (defun Custom-save (&rest ignore
)
804 "Set all edited settings, then save all settings that have been set.
805 If a setting was edited and set before, this saves it. If a
806 setting was merely edited before, this sets it then saves it."
808 (when (custom-command-apply
810 (when (memq (widget-get child
:custom-state
)
811 '(modified set changed rogue
))
812 (widget-apply child
:custom-mark-to-save
)))
813 "Save all settings in this buffer? " t
)
814 ;; Save changes to buffer and redraw.
816 (dolist (child custom-options
)
817 (widget-apply child
:custom-state-set-and-redraw
))))
819 (defun custom-reset (widget &optional event
)
820 "Select item from reset menu."
821 (let* ((completion-ignore-case t
)
822 (answer (widget-choose "Reset settings"
828 (defun Custom-reset-current (&rest ignore
)
829 "Reset all edited settings in the buffer to show their current values."
831 (custom-command-apply
833 (if (memq (widget-get widget
:custom-state
) '(modified changed
))
834 (widget-apply widget
:custom-reset-current
)))
835 "Reset all settings' buffer text to show current values? "))
837 (defun Custom-reset-saved (&rest ignore
)
838 "Reset all edited or set settings in the buffer to their saved value.
839 This also shows the saved values in the buffer."
841 (custom-command-apply
843 (if (memq (widget-get widget
:custom-state
) '(modified set changed rogue
))
844 (widget-apply widget
:custom-reset-saved
)))
845 "Reset all settings (current values and buffer text) to saved values? "))
847 ;; The next two variables are bound to '(t) by `Custom-reset-standard'
848 ;; and `custom-group-reset-standard'. If these variables are nil, both
849 ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
850 ;; save, reset and redraw the handled widget immediately. Otherwise,
851 ;; they add the widget to the corresponding list and leave it to
852 ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
853 (defvar custom-reset-standard-variables-list nil
)
854 (defvar custom-reset-standard-faces-list nil
)
856 ;; The next function was excerpted from `custom-variable-reset-standard'
857 ;; and `custom-face-reset-standard' and is used to avoid calling
858 ;; `custom-save-all' repeatedly (and thus saving settings to file one by
859 ;; one) when erasing all customizations.
860 (defun custom-reset-standard-save-and-update ()
861 "Save settings and redraw after erasing customizations."
862 (when (or (and custom-reset-standard-variables-list
863 (not (eq custom-reset-standard-variables-list
'(t))))
864 (and custom-reset-standard-faces-list
865 (not (eq custom-reset-standard-faces-list
'(t)))))
866 ;; Save settings to file.
868 ;; Set state of and redraw variables.
869 (dolist (widget custom-reset-standard-variables-list
)
870 (unless (eq widget t
)
871 (widget-put widget
:custom-state
'unknown
)
872 (custom-redraw widget
)))
873 ;; Set state of and redraw faces.
874 (dolist (widget custom-reset-standard-faces-list
)
875 (unless (eq widget t
)
876 (let* ((symbol (widget-value widget
))
877 (child (car (widget-get widget
:children
)))
878 (value (get symbol
'face-defface-spec
))
879 (comment-widget (widget-get widget
:comment-widget
)))
880 (put symbol
'face-comment nil
)
881 (widget-value-set child
882 (custom-pre-filter-face-spec
883 (list (list t
(custom-face-attributes-get
885 ;; This call manages the comment visibility
886 (widget-value-set comment-widget
"")
887 (custom-face-state-set widget
)
888 (custom-redraw-magic widget
))))))
890 (defun Custom-reset-standard (&rest ignore
)
891 "Erase all customizations (either current or saved) in current buffer.
892 The immediate result is to restore them to their standard values.
893 This operation eliminates any saved values for the group members,
894 making them as if they had never been customized at all."
896 ;; Bind these temporarily.
897 (let ((custom-reset-standard-variables-list '(t))
898 (custom-reset-standard-faces-list '(t)))
899 (custom-command-apply
901 (and (or (null (widget-get widget
:custom-standard-value
))
902 (widget-apply widget
:custom-standard-value
))
903 (memq (widget-get widget
:custom-state
)
904 '(modified set changed saved rogue
))
905 (widget-apply widget
:custom-mark-to-reset-standard
)))
906 "Erase all customizations for settings in this buffer? " t
)
907 (custom-reset-standard-save-and-update)))
909 ;;; The Customize Commands
911 (defun custom-prompt-variable (prompt-var prompt-val
&optional comment
)
912 "Prompt for a variable and a value and return them as a list.
913 PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
914 prompt for the value. The %s escape in PROMPT-VAL is replaced with
915 the name of the variable.
917 If the variable has a `variable-interactive' property, that is used as if
918 it were the arg to `interactive' (which see) to interactively read the value.
920 If the variable has a `custom-type' property, it must be a widget and the
921 `:prompt-value' property of that widget will be used for reading the value.
923 If optional COMMENT argument is non-nil, also prompt for a comment and return
924 it as the third element in the list."
925 (let* ((var (read-variable prompt-var
))
926 (minibuffer-help-form '(describe-variable var
))
928 (let ((prop (get var
'variable-interactive
))
929 (type (get var
'custom-type
))
930 (prompt (format prompt-val var
)))
932 (setq type
(list type
)))
934 ;; Use VAR's `variable-interactive' property
935 ;; as an interactive spec for prompting.
936 (call-interactively `(lambda (arg)
940 (widget-prompt-value type
946 (eval-minibuffer prompt
))))))
949 (read-string "Comment: " (get var
'variable-comment
)))
953 (defun customize-set-value (variable value
&optional comment
)
954 "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
956 If VARIABLE has a `variable-interactive' property, that is used as if
957 it were the arg to `interactive' (which see) to interactively read the value.
959 If VARIABLE has a `custom-type' property, it must be a widget and the
960 `:prompt-value' property of that widget will be used for reading the value.
962 If given a prefix (or a COMMENT argument), also prompt for a comment."
963 (interactive (custom-prompt-variable "Set variable: "
967 (cond ((string= comment
"")
968 (put variable
'variable-comment nil
))
970 (put variable
'variable-comment comment
)))
971 (set variable value
))
974 (defun customize-set-variable (variable value
&optional comment
)
975 "Set the default for VARIABLE to VALUE, and return VALUE.
976 VALUE is a Lisp object.
978 If VARIABLE has a `custom-set' property, that is used for setting
979 VARIABLE, otherwise `set-default' is used.
981 If VARIABLE has a `variable-interactive' property, that is used as if
982 it were the arg to `interactive' (which see) to interactively read the value.
984 If VARIABLE has a `custom-type' property, it must be a widget and the
985 `:prompt-value' property of that widget will be used for reading the value.
987 If given a prefix (or a COMMENT argument), also prompt for a comment."
988 (interactive (custom-prompt-variable "Set variable: "
989 "Set customized value for %s to: "
991 (custom-load-symbol variable
)
992 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
993 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
994 (put variable
'customized-value
(list (custom-quote value
)))
995 (cond ((string= comment
"")
996 (put variable
'variable-comment nil
)
997 (put variable
'customized-variable-comment nil
))
999 (put variable
'variable-comment comment
)
1000 (put variable
'customized-variable-comment comment
)))
1004 (defun customize-save-variable (variable value
&optional comment
)
1005 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1008 If VARIABLE has a `custom-set' property, that is used for setting
1009 VARIABLE, otherwise `set-default' is used.
1011 If VARIABLE has a `variable-interactive' property, that is used as if
1012 it were the arg to `interactive' (which see) to interactively read the value.
1014 If VARIABLE has a `custom-type' property, it must be a widget and the
1015 `:prompt-value' property of that widget will be used for reading the value.
1017 If given a prefix (or a COMMENT argument), also prompt for a comment."
1018 (interactive (custom-prompt-variable "Set and save variable: "
1019 "Set and save value for %s as: "
1020 current-prefix-arg
))
1021 (funcall (or (get variable
'custom-set
) 'set-default
) variable value
)
1022 (put variable
'saved-value
(list (custom-quote value
)))
1023 (custom-push-theme 'theme-value variable
'user
'set
(custom-quote value
))
1024 (cond ((string= comment
"")
1025 (put variable
'variable-comment nil
)
1026 (put variable
'saved-variable-comment nil
))
1028 (put variable
'variable-comment comment
)
1029 (put variable
'saved-variable-comment comment
)))
1030 (put variable
'customized-value nil
)
1031 (put variable
'customized-variable-comment nil
)
1037 "Select a customization buffer which you can use to set user options.
1038 User options are structured into \"groups\".
1039 Initially the top-level group `Emacs' and its immediate subgroups
1040 are shown; the contents of those subgroups are initially hidden."
1042 (customize-group 'emacs
))
1045 (defun customize-mode (mode)
1046 "Customize options related to the current major mode.
1047 If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
1048 then prompt for the MODE to customize."
1051 (let ((completion-regexp-list '("-mode\\'"))
1052 (group (custom-group-of-mode major-mode
)))
1053 (if (and group
(not current-prefix-arg
))
1056 (completing-read (if group
1057 (format "Major mode (default %s): " major-mode
)
1060 'custom-group-of-mode
1061 t nil nil
(if group
(symbol-name major-mode
))))))))
1062 (customize-group (custom-group-of-mode mode
)))
1064 (defun customize-read-group ()
1065 (let ((completion-ignore-case t
))
1066 (completing-read "Customize group (default emacs): "
1069 (or (and (get symbol
'custom-loads
)
1070 (not (get symbol
'custom-autoload
)))
1071 (get symbol
'custom-group
)))
1075 (defun customize-group (&optional group
)
1076 "Customize GROUP, which must be a customization group."
1077 (interactive (list (customize-read-group)))
1078 (when (stringp group
)
1079 (if (string-equal "" group
)
1081 (setq group
(intern group
))))
1082 (let ((name (format "*Customize Group: %s*"
1083 (custom-unlispify-tag-name group
))))
1084 (if (get-buffer name
)
1085 (pop-to-buffer name
)
1086 (custom-buffer-create
1087 (list (list group
'custom-group
))
1089 (concat " for group "
1090 (custom-unlispify-tag-name group
))))))
1093 (defun customize-group-other-window (&optional group
)
1094 "Customize GROUP, which must be a customization group, in another window."
1095 (interactive (list (customize-read-group)))
1096 (let ((pop-up-windows t
)
1097 (same-window-buffer-names nil
)
1098 (same-window-regexps nil
))
1099 (customize-group group
)))
1102 (defalias 'customize-variable
'customize-option
)
1105 (defun customize-option (symbol)
1106 "Customize SYMBOL, which must be a user option variable."
1107 (interactive (custom-variable-prompt))
1109 (error "No variable specified"))
1110 (let ((basevar (indirect-variable symbol
)))
1111 (custom-buffer-create (list (list basevar
'custom-variable
))
1112 (format "*Customize Option: %s*"
1113 (custom-unlispify-tag-name basevar
)))
1114 (unless (eq symbol basevar
)
1115 (message "`%s' is an alias for `%s'" symbol basevar
))))
1118 (defalias 'customize-variable-other-window
'customize-option-other-window
)
1121 (defun customize-option-other-window (symbol)
1122 "Customize SYMBOL, which must be a user option variable.
1123 Show the buffer in another window, but don't select it."
1124 (interactive (custom-variable-prompt))
1126 (error "No variable specified"))
1127 (let ((basevar (indirect-variable symbol
)))
1128 (custom-buffer-create-other-window
1129 (list (list basevar
'custom-variable
))
1130 (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar
)))
1131 (unless (eq symbol basevar
)
1132 (message "`%s' is an alias for `%s'" symbol basevar
))))
1134 (defvar customize-changed-options-previous-release
"23.1"
1135 "Version for `customize-changed-options' to refer back to by default.")
1137 ;; Packages will update this variable, so make it available.
1139 (defvar customize-package-emacs-version-alist nil
1140 "Alist mapping versions of a package to Emacs versions.
1141 We use this for packages that have their own names, but are released
1142 as part of Emacs itself.
1144 Each elements looks like this:
1146 (PACKAGE (PVERSION . EVERSION)...)
1148 Here PACKAGE is the name of a package, as a symbol. After
1149 PACKAGE come one or more elements, each associating a
1150 package version PVERSION with the first Emacs version
1151 EVERSION in which it (or a subsequent version of PACKAGE)
1152 was first released. Both PVERSION and EVERSION are strings.
1153 PVERSION should be a string that this package used in
1154 the :package-version keyword for `defcustom', `defgroup',
1157 For example, the MH-E package updates this alist as follows:
1159 (add-to-list 'customize-package-emacs-version-alist
1160 '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
1161 (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
1162 (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
1163 (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
1165 The value of PACKAGE needs to be unique and it needs to match the
1166 PACKAGE value appearing in the :package-version keyword. Since
1167 the user might see the value in a error message, a good choice is
1168 the official name of the package, such as MH-E or Gnus.")
1171 (defalias 'customize-changed
'customize-changed-options
)
1174 (defun customize-changed-options (&optional since-version
)
1175 "Customize all settings whose meanings have changed in Emacs itself.
1176 This includes new user option variables and faces, and new
1177 customization groups, as well as older options and faces whose meanings
1178 or default values have changed since the previous major Emacs release.
1180 With argument SINCE-VERSION (a string), customize all settings
1181 that were added or redefined since that version."
1185 (read-from-minibuffer
1186 (format "Customize options changed, since version (default %s): "
1187 customize-changed-options-previous-release
))))
1188 (if (equal since-version
"")
1189 (setq since-version nil
)
1190 (unless (condition-case nil
1191 (numberp (read since-version
))
1193 (signal 'wrong-type-argument
(list 'numberp since-version
))))
1194 (unless since-version
1195 (setq since-version customize-changed-options-previous-release
))
1197 ;; Load the information for versions since since-version. We use
1198 ;; custom-load-symbol for this.
1199 (put 'custom-versions-load-alist
'custom-loads nil
)
1200 (dolist (elt custom-versions-load-alist
)
1201 (if (customize-version-lessp since-version
(car elt
))
1202 (dolist (load (cdr elt
))
1203 (custom-add-load 'custom-versions-load-alist load
))))
1204 (custom-load-symbol 'custom-versions-load-alist
)
1205 (put 'custom-versions-load-alist
'custom-loads nil
)
1210 (let* ((package-version (get symbol
'custom-package-version
))
1212 (or (and package-version
1213 (customize-package-emacs-version symbol
1215 (get symbol
'custom-version
))))
1217 (when (customize-version-lessp since-version version
)
1218 (if (or (get symbol
'custom-group
)
1219 (get symbol
'group-documentation
))
1220 (push (list symbol
'custom-group
) found
))
1221 (if (custom-variable-p symbol
)
1222 (push (list symbol
'custom-variable
) found
))
1223 (if (custom-facep symbol
)
1224 (push (list symbol
'custom-face
) found
)))))))
1226 (custom-buffer-create (custom-sort-items found t
'first
)
1227 "*Customize Changed Options*")
1228 (error "No user option defaults have been changed since Emacs %s"
1231 (defun customize-package-emacs-version (symbol package-version
)
1232 "Return the Emacs version in which SYMBOL's meaning last changed.
1233 PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
1234 `customize-package-emacs-version-alist' to find the version of
1235 Emacs that is associated with version VERSION of PACKAGE."
1236 (let (package-versions emacs-version
)
1237 ;; Use message instead of error since we want user to be able to
1238 ;; see the rest of the symbols even if a package author has
1239 ;; botched things up.
1240 (cond ((not (listp package-version
))
1241 (message "Invalid package-version value for %s" symbol
))
1242 ((setq package-versions
(assq (car package-version
)
1243 customize-package-emacs-version-alist
))
1245 (cdr (assoc (cdr package-version
) package-versions
)))
1246 (unless emacs-version
1247 (message "%s version %s not found in %s" symbol
1248 (cdr package-version
)
1249 "customize-package-emacs-version-alist")))
1251 (message "Package %s version %s lists no corresponding Emacs version"
1252 (car package-version
)
1253 (cdr package-version
))))
1256 (defun customize-version-lessp (version1 version2
)
1257 ;; Why are the versions strings, and given that they are, why aren't
1258 ;; they converted to numbers and compared as such here? -- fx
1260 ;; In case someone made a mistake and left out the quotes
1261 ;; in the :version value.
1262 (if (numberp version2
)
1263 (setq version2
(prin1-to-string version2
)))
1264 (let (major1 major2 minor1 minor2
)
1265 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1
)
1266 (setq major1
(read (or (match-string 1 version1
)
1268 (setq minor1
(read (or (match-string 3 version1
)
1270 (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2
)
1271 (setq major2
(read (or (match-string 1 version2
)
1273 (setq minor2
(read (or (match-string 3 version2
)
1275 (or (< major1 major2
)
1276 (and (= major1 major2
)
1277 (< minor1 minor2
)))))
1280 (defun customize-face (&optional face
)
1281 "Customize FACE, which should be a face name or nil.
1282 If FACE is nil, customize all faces. If FACE is actually a
1283 face-alias, customize the face it is aliased to.
1285 Interactively, when point is on text which has a face specified,
1286 suggest to customize that face, if it's customizable."
1287 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1288 (if (member face
'(nil ""))
1289 (setq face
(face-list)))
1290 (if (and (listp face
) (null (cdr face
)))
1291 (setq face
(car face
)))
1293 (custom-buffer-create
1295 (mapcar (lambda (s) (list s
'custom-face
)) face
)
1297 "*Customize Faces*")
1298 ;; If FACE is actually an alias, customize the face it is aliased to.
1299 (if (get face
'face-alias
)
1300 (setq face
(get face
'face-alias
)))
1301 (unless (facep face
)
1302 (error "Invalid face %S" face
))
1303 (custom-buffer-create
1304 (list (list face
'custom-face
))
1305 (format "*Customize Face: %s*"
1306 (custom-unlispify-tag-name face
)))))
1309 (defun customize-face-other-window (&optional face
)
1310 "Show customization buffer for face FACE in other window.
1311 If FACE is actually a face-alias, customize the face it is aliased to.
1313 Interactively, when point is on text which has a face specified,
1314 suggest to customize that face, if it's customizable."
1315 (interactive (list (read-face-name "Customize face" "all faces" t
)))
1316 (let ((pop-up-windows t
)
1317 (same-window-buffer-names nil
)
1318 (same-window-regexps nil
))
1319 (customize-face face
)))
1321 (defalias 'customize-customized
'customize-unsaved
)
1324 (defun customize-unsaved ()
1325 "Customize all user options set in this session but not saved."
1328 (mapatoms (lambda (symbol)
1329 (and (or (get symbol
'customized-face
)
1330 (get symbol
'customized-face-comment
))
1331 (custom-facep symbol
)
1332 (push (list symbol
'custom-face
) found
))
1333 (and (or (get symbol
'customized-value
)
1334 (get symbol
'customized-variable-comment
))
1336 (push (list symbol
'custom-variable
) found
))))
1338 (error "No user options are set but unsaved")
1339 (custom-buffer-create (custom-sort-items found t nil
)
1340 "*Customize Unsaved*"))))
1343 (defun customize-rogue ()
1344 "Customize all user variables modified outside customize."
1347 (mapatoms (lambda (symbol)
1348 (let ((cval (or (get symbol
'customized-value
)
1349 (get symbol
'saved-value
)
1350 (get symbol
'standard-value
))))
1351 (when (and cval
;Declared with defcustom.
1352 (default-boundp symbol
) ;Has a value.
1353 (not (equal (eval (car cval
))
1354 ;; Which does not match customize.
1355 (default-value symbol
))))
1356 (push (list symbol
'custom-variable
) found
)))))
1358 (error "No rogue user options")
1359 (custom-buffer-create (custom-sort-items found t nil
)
1360 "*Customize Rogue*"))))
1362 (defun customize-saved ()
1363 "Customize all already saved user options."
1366 (mapatoms (lambda (symbol)
1367 (and (or (get symbol
'saved-face
)
1368 (get symbol
'saved-face-comment
))
1369 (custom-facep symbol
)
1370 (push (list symbol
'custom-face
) found
))
1371 (and (or (get symbol
'saved-value
)
1372 (get symbol
'saved-variable-comment
))
1374 (push (list symbol
'custom-variable
) found
))))
1376 (error "No saved user options")
1377 (custom-buffer-create (custom-sort-items found t nil
)
1378 "*Customize Saved*"))))
1381 (defun customize-apropos (regexp &optional all
)
1382 "Customize all loaded options, faces and groups matching REGEXP.
1383 If ALL is `options', include only options.
1384 If ALL is `faces', include only faces.
1385 If ALL is `groups', include only groups.
1386 If ALL is t (interactively, with prefix arg), include variables
1387 that are not customizable options, as well as faces and groups
1388 \(but we recommend using `apropos-variable' instead)."
1389 (interactive "sCustomize (regexp): \nP")
1391 (mapatoms (lambda (symbol)
1392 (when (string-match regexp
(symbol-name symbol
))
1393 (when (and (not (memq all
'(faces options
)))
1394 (get symbol
'custom-group
))
1395 (push (list symbol
'custom-group
) found
))
1396 (when (and (not (memq all
'(options groups
)))
1397 (custom-facep symbol
))
1398 (push (list symbol
'custom-face
) found
))
1399 (when (and (not (memq all
'(groups faces
)))
1401 (eq (indirect-variable symbol
) symbol
)
1402 (or (get symbol
'saved-value
)
1403 (custom-variable-p symbol
)
1404 (and (not (memq all
'(nil options
)))
1405 (get symbol
'variable-documentation
))))
1406 (push (list symbol
'custom-variable
) found
)))))
1408 (error "No %s matching %s"
1411 (format "customizable %s"
1412 (if (memq all
'(options faces groups
))
1416 (custom-buffer-create
1417 (custom-sort-items found t custom-buffer-order-groups
)
1418 "*Customize Apropos*"))))
1421 (defun customize-apropos-options (regexp &optional arg
)
1422 "Customize all loaded customizable options matching REGEXP.
1423 With prefix ARG, include variables that are not customizable options
1424 \(but it is better to use `apropos-variable' if you want to find those)."
1425 (interactive "sCustomize options (regexp): \nP")
1426 (customize-apropos regexp
(or arg
'options
)))
1429 (defun customize-apropos-faces (regexp)
1430 "Customize all loaded faces matching REGEXP."
1431 (interactive "sCustomize faces (regexp): \n")
1432 (customize-apropos regexp
'faces
))
1435 (defun customize-apropos-groups (regexp)
1436 "Customize all loaded groups matching REGEXP."
1437 (interactive "sCustomize groups (regexp): \n")
1438 (customize-apropos regexp
'groups
))
1442 (defcustom custom-buffer-style
'links
1443 "Control the presentation style for customization buffers.
1444 The value should be a symbol, one of:
1446 brackets: groups nest within each other with big horizontal brackets.
1447 links: groups have links to subgroups."
1448 :type
'(radio (const brackets
)
1450 :group
'custom-buffer
)
1452 (defcustom custom-buffer-done-kill nil
1453 "Non-nil means exiting a Custom buffer should kill it."
1456 :group
'custom-buffer
)
1458 (defcustom custom-buffer-indent
3
1459 "Number of spaces to indent nested groups."
1461 :group
'custom-buffer
)
1463 (defun custom-get-fresh-buffer (name)
1464 "Get a fresh new buffer with name NAME.
1465 If the buffer already exist, clean it up to be like new.
1466 Beware: it's not quite like new. Good enough for custom, but maybe
1468 ;; To be more complete, we should also kill all permanent-local variables,
1469 ;; but it's not needed for custom.
1470 (let ((buf (get-buffer name
)))
1471 (when (and buf
(buffer-local-value 'buffer-file-name buf
))
1472 ;; This will check if the file is not saved.
1476 (get-buffer-create name
)
1477 (with-current-buffer buf
1478 (kill-all-local-variables)
1479 (run-hooks 'kill-buffer-hook
)
1480 ;; Delete overlays before erasing the buffer so the overlay hooks
1481 ;; don't get run spuriously when we erase the buffer.
1482 (let ((ols (overlay-lists)))
1483 (dolist (ol (nconc (car ols
) (cdr ols
)))
1484 (delete-overlay ol
)))
1489 (defun custom-buffer-create (options &optional name description
)
1490 "Create a buffer containing OPTIONS.
1491 Optional NAME is the name of the buffer.
1492 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1493 SYMBOL is a customization option, and WIDGET is a widget for editing
1495 (pop-to-buffer (custom-get-fresh-buffer (or name
"*Customization*")))
1496 (custom-buffer-create-internal options description
))
1499 (defun custom-buffer-create-other-window (options &optional name description
)
1500 "Create a buffer containing OPTIONS, and display it in another window.
1501 The result includes selecting that window.
1502 Optional NAME is the name of the buffer.
1503 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
1504 SYMBOL is a customization option, and WIDGET is a widget for editing
1506 (unless name
(setq name
"*Customization*"))
1507 (let ((pop-up-windows t
)
1508 (same-window-buffer-names nil
)
1509 (same-window-regexps nil
))
1510 (pop-to-buffer (custom-get-fresh-buffer name
))
1511 (custom-buffer-create-internal options description
)))
1513 (defcustom custom-reset-button-menu nil
1514 "If non-nil, only show a single reset button in customize buffers.
1515 This button will have a menu with all three reset operations."
1517 :group
'custom-buffer
)
1519 (defcustom custom-buffer-verbose-help t
1520 "If non-nil, include explanatory text in the customization buffer."
1522 :group
'custom-buffer
)
1524 (defun Custom-buffer-done (&rest ignore
)
1525 "Exit current Custom buffer according to `custom-buffer-done-kill'."
1527 (quit-window custom-buffer-done-kill
))
1529 (defvar custom-button nil
1530 "Face used for buttons in customization buffers.")
1532 (defvar custom-button-mouse nil
1533 "Mouse face used for buttons in customization buffers.")
1535 (defvar custom-button-pressed nil
1536 "Face used for pressed buttons in customization buffers.")
1538 (defcustom custom-raised-buttons
(not (equal (face-valid-attribute-values :box
)
1539 '(("unspecified" . unspecified
))))
1540 "If non-nil, indicate active buttons in a `raised-button' style.
1541 Otherwise use brackets."
1544 :group
'custom-buffer
1545 :set
(lambda (variable value
)
1546 (custom-set-default variable value
)
1548 (if value
'custom-button
'custom-button-unraised
))
1549 (setq custom-button-mouse
1550 (if value
'custom-button-mouse
'highlight
))
1551 (setq custom-button-pressed
1553 'custom-button-pressed
1554 'custom-button-pressed-unraised
))))
1556 (defun custom-buffer-create-internal (options &optional description
)
1558 (let ((init-file (or custom-file user-init-file
)))
1559 ;; Insert verbose help at the top of the custom buffer.
1560 (when custom-buffer-verbose-help
1561 (widget-insert "Editing a setting changes only the text in this buffer."
1564 To apply your changes, use the Save or Set buttons.
1565 Saving a change normally works by editing your init file."
1567 Currently, these settings cannot be saved for future Emacs sessions,
1568 possibly because you started Emacs with `-q'.")
1569 "\nFor details, see ")
1570 (widget-create 'custom-manual
1571 :tag
"Saving Customizations"
1572 "(emacs)Saving Customizations")
1573 (widget-insert " in the ")
1574 (widget-create 'custom-manual
1576 :help-echo
"Read the Emacs manual."
1578 (widget-insert "."))
1579 (widget-insert "\n")
1580 ;; The custom command buttons are also in the toolbar, so for a
1581 ;; time they were not inserted in the buffer if the toolbar was in use.
1582 ;; But it can be a little confusing for the buffer layout to
1583 ;; change according to whether or nor the toolbar is on, not to
1584 ;; mention that a custom buffer can in theory be created in a
1585 ;; frame with a toolbar, then later viewed in one without.
1586 ;; So now the buttons are always inserted in the buffer. (Bug#1326)
1587 ;;; (when (not (and (bound-and-true-p tool-bar-mode) (display-graphic-p)))
1588 (if custom-buffer-verbose-help
1590 Operate on all settings in this buffer that are not marked HIDDEN:\n"))
1591 (let ((button (lambda (tag action active help icon
)
1594 (widget-create 'push-button
:tag tag
1595 :help-echo help
:action action
))))
1596 (commands custom-commands
))
1597 (apply button
(pop commands
)) ; Set for current session
1598 (apply button
(pop commands
)) ; Save for future sessions
1599 (if custom-reset-button-menu
1602 (widget-create 'push-button
1604 :help-echo
"Show a menu with reset operations."
1605 :mouse-down-action
'ignore
1606 :action
'custom-reset
))
1607 (widget-insert "\n")
1608 (apply button
(pop commands
)) ; Undo edits
1609 (apply button
(pop commands
)) ; Reset to saved
1610 (apply button
(pop commands
)) ; Erase customization
1612 (pop commands
) ; Help (omitted)
1613 (apply button
(pop commands
)))) ; Exit
1614 (widget-insert "\n\n"))
1616 ;; Now populate the custom buffer.
1617 (message "Creating customization items...")
1618 (buffer-disable-undo)
1619 (setq custom-options
1620 (if (= (length options
) 1)
1621 (mapcar (lambda (entry)
1622 (widget-create (nth 1 entry
)
1623 :documentation-shown t
1624 :custom-state
'unknown
1625 :tag
(custom-unlispify-tag-name
1627 :value
(nth 0 entry
)))
1630 (length (length options
)))
1631 (mapcar (lambda (entry)
1633 (message "Creating customization items ...%2d%%"
1634 (/ (* 100.0 count
) length
))
1635 (widget-create (nth 1 entry
)
1636 :tag
(custom-unlispify-tag-name
1638 :value
(nth 0 entry
))
1639 (setq count
(1+ count
))
1640 (unless (eq (preceding-char) ?
\n)
1641 (widget-insert "\n"))
1642 (widget-insert "\n")))
1644 (unless (eq (preceding-char) ?
\n)
1645 (widget-insert "\n"))
1646 (message "Creating customization items ...done")
1647 (message "Resetting customization items...")
1648 (unless (eq custom-buffer-style
'tree
)
1649 (mapc 'custom-magic-reset custom-options
))
1650 (message "Resetting customization items...done")
1651 (message "Creating customization setup...")
1653 (buffer-enable-undo)
1654 (goto-char (point-min))
1655 (message "Creating customization setup...done"))
1657 ;;; The Tree Browser.
1660 (defun customize-browse (&optional group
)
1661 "Create a tree browser for the customize hierarchy."
1664 (setq group
'emacs
))
1665 (let ((name "*Customize Browser*"))
1666 (pop-to-buffer (custom-get-fresh-buffer name
)))
1668 (widget-insert (format "\
1669 %s buttons; type RET or click mouse-1
1670 on a button to invoke its action.
1671 Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
1672 (if custom-raised-buttons
1673 "`Raised' text indicates"
1674 "Square brackets indicate")))
1677 (if custom-browse-only-groups
1679 Invoke the [Group] button below to edit that item in another window.\n\n")
1680 (widget-insert "Invoke the ")
1681 (widget-create 'item
1684 :tag-glyph
"folder")
1685 (widget-insert ", ")
1686 (widget-create 'item
1690 (widget-insert ", and ")
1691 (widget-create 'item
1694 :tag-glyph
"option")
1695 (widget-insert " buttons below to edit that
1696 item in another window.\n\n"))
1697 (let ((custom-buffer-style 'tree
))
1698 (widget-create 'custom-group
1700 :custom-state
'unknown
1701 :tag
(custom-unlispify-tag-name group
)
1704 (goto-char (point-min)))
1706 (define-widget 'custom-browse-visibility
'item
1707 "Control visibility of items in the customize tree browser."
1709 :action
'custom-browse-visibility-action
)
1711 (defun custom-browse-visibility-action (widget &rest ignore
)
1712 (let ((custom-buffer-style 'tree
))
1713 (custom-toggle-parent widget
)))
1715 (define-widget 'custom-browse-group-tag
'custom-group-link
1716 "Show parent in other window when activated."
1719 :action
'custom-browse-group-tag-action
)
1721 (defun custom-browse-group-tag-action (widget &rest ignore
)
1722 (let ((parent (widget-get widget
:parent
)))
1723 (customize-group-other-window (widget-value parent
))))
1725 (define-widget 'custom-browse-variable-tag
'custom-group-link
1726 "Show parent in other window when activated."
1729 :action
'custom-browse-variable-tag-action
)
1731 (defun custom-browse-variable-tag-action (widget &rest ignore
)
1732 (let ((parent (widget-get widget
:parent
)))
1733 (customize-variable-other-window (widget-value parent
))))
1735 (define-widget 'custom-browse-face-tag
'custom-group-link
1736 "Show parent in other window when activated."
1739 :action
'custom-browse-face-tag-action
)
1741 (defun custom-browse-face-tag-action (widget &rest ignore
)
1742 (let ((parent (widget-get widget
:parent
)))
1743 (customize-face-other-window (widget-value parent
))))
1745 (defconst custom-browse-alist
'((" " "space")
1751 (defun custom-browse-insert-prefix (prefix)
1752 "Insert PREFIX. On XEmacs convert it to line graphics."
1753 ;; Fixme: do graphics.
1754 (if nil
; (featurep 'xemacs)
1757 (while (not (string-equal prefix
""))
1758 (let ((entry (substring prefix
0 3)))
1759 (setq prefix
(substring prefix
3))
1760 (let ((overlay (make-overlay (1- (point)) (point) nil t nil
))
1761 (name (nth 1 (assoc entry custom-browse-alist
))))
1762 (overlay-put overlay
'end-glyph
(widget-glyph-find name entry
))
1763 (overlay-put overlay
'start-open t
)
1764 (overlay-put overlay
'end-open t
)))))
1767 ;;; Modification of Basic Widgets.
1769 ;; We add extra properties to the basic widgets needed here. This is
1770 ;; fine, as long as we are careful to stay within our own namespace.
1772 ;; We want simple widgets to be displayed by default, but complex
1773 ;; widgets to be hidden.
1775 (widget-put (get 'item
'widget-type
) :custom-show t
)
1776 (widget-put (get 'editable-field
'widget-type
)
1777 :custom-show
(lambda (widget value
)
1778 (let ((pp (pp-to-string value
)))
1779 (cond ((string-match "\n" pp
)
1784 (widget-put (get 'menu-choice
'widget-type
) :custom-show t
)
1786 ;;; The `custom-manual' Widget.
1788 (define-widget 'custom-manual
'info-link
1789 "Link to the manual entry for this customization option."
1790 :help-echo
"Read the manual entry for this option."
1791 :keymap custom-mode-link-map
1792 :follow-link
'mouse-face
1793 :button-face
'custom-link
1794 :mouse-face
'highlight
1795 :pressed-face
'highlight
1798 ;;; The `custom-magic' Widget.
1800 (defgroup custom-magic-faces nil
1801 "Faces used by the magic button."
1802 :group
'custom-faces
1803 :group
'custom-buffer
)
1805 (defface custom-invalid
'((((class color
))
1806 (:foreground
"yellow1" :background
"red1"))
1808 (:weight bold
:slant italic
:underline t
)))
1809 "Face used when the customize item is invalid."
1810 :group
'custom-magic-faces
)
1811 (define-obsolete-face-alias 'custom-invalid-face
'custom-invalid
"22.1")
1813 (defface custom-rogue
'((((class color
))
1814 (:foreground
"pink" :background
"black"))
1817 "Face used when the customize item is not defined for customization."
1818 :group
'custom-magic-faces
)
1819 (define-obsolete-face-alias 'custom-rogue-face
'custom-rogue
"22.1")
1821 (defface custom-modified
'((((min-colors 88) (class color
))
1822 (:foreground
"white" :background
"blue1"))
1824 (:foreground
"white" :background
"blue"))
1826 (:slant italic
:bold
)))
1827 "Face used when the customize item has been modified."
1828 :group
'custom-magic-faces
)
1829 (define-obsolete-face-alias 'custom-modified-face
'custom-modified
"22.1")
1831 (defface custom-set
'((((min-colors 88) (class color
))
1832 (:foreground
"blue1" :background
"white"))
1834 (:foreground
"blue" :background
"white"))
1837 "Face used when the customize item has been set."
1838 :group
'custom-magic-faces
)
1839 (define-obsolete-face-alias 'custom-set-face
'custom-set
"22.1")
1841 (defface custom-changed
'((((min-colors 88) (class color
))
1842 (:foreground
"white" :background
"blue1"))
1844 (:foreground
"white" :background
"blue"))
1847 "Face used when the customize item has been changed."
1848 :group
'custom-magic-faces
)
1849 (define-obsolete-face-alias 'custom-changed-face
'custom-changed
"22.1")
1851 (defface custom-themed
'((((min-colors 88) (class color
))
1852 (:foreground
"white" :background
"blue1"))
1854 (:foreground
"white" :background
"blue"))
1857 "Face used when the customize item has been set by a theme."
1858 :group
'custom-magic-faces
)
1860 (defface custom-saved
'((t (:underline t
)))
1861 "Face used when the customize item has been saved."
1862 :group
'custom-magic-faces
)
1863 (define-obsolete-face-alias 'custom-saved-face
'custom-saved
"22.1")
1865 (defconst custom-magic-alist
1866 '((nil "#" underline
"\
1867 UNINITIALIZED, you should not see this.")
1868 (unknown "?" italic
"\
1869 UNKNOWN, you should not see this.")
1870 (hidden "-" default
"\
1871 HIDDEN, invoke \"Show\" in the previous line to show." "\
1872 group now hidden, invoke \"Show\", above, to show contents.")
1873 (invalid "x" custom-invalid
"\
1874 INVALID, the displayed value cannot be set.")
1875 (modified "*" custom-modified
"\
1876 EDITED, shown value does not take effect until you set or save it." "\
1877 something in this group has been edited but not set.")
1878 (set "+" custom-set
"\
1879 SET for current session only." "\
1880 something in this group has been set but not saved.")
1881 (changed ":" custom-changed
"\
1882 CHANGED outside Customize; operating on it here may be unreliable." "\
1883 something in this group has been changed outside customize.")
1884 (saved "!" custom-saved
"\
1886 something in this group has been set and saved.")
1887 (themed "o" custom-themed
"\
1889 visible group members are all at standard values.")
1890 (rogue "@" custom-rogue
"\
1891 NO CUSTOMIZATION DATA; not intended to be customized." "\
1892 something in this group is not prepared for customization.")
1893 (standard " " nil
"\
1895 visible group members are all at standard values."))
1896 "Alist of customize option states.
1897 Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
1899 STATE is one of the following symbols:
1902 For internal use, should never occur.
1904 For internal use, should never occur.
1906 This item is not being displayed.
1908 This item is modified, but has an invalid form.
1910 This item is modified, and has a valid form.
1912 This item has been set but not saved.
1914 The current value of this item has been changed outside Customize.
1916 This item is marked for saving.
1918 This item has no customization information.
1920 This item is unchanged from the standard setting.
1922 MAGIC is a string used to present that state.
1924 FACE is a face used to present the state.
1926 ITEM-DESC is a string describing the state for options.
1928 GROUP-DESC is a string describing the state for groups. If this is
1929 left out, ITEM-DESC will be used.
1931 The string %c in either description will be replaced with the
1932 category of the item. These are `group'. `option', and `face'.
1934 The list should be sorted most significant first.")
1936 (defcustom custom-magic-show
'long
1937 "If non-nil, show textual description of the state.
1938 If `long', show a full-line description, not just one word."
1939 :type
'(choice (const :tag
"no" nil
)
1941 (other :tag
"short" short
))
1942 :group
'custom-buffer
)
1944 (defcustom custom-magic-show-hidden
'(option face
)
1945 "Control whether the State button is shown for hidden items.
1946 The value should be a list with the custom categories where the State
1947 button should be visible. Possible categories are `group', `option',
1949 :type
'(set (const group
) (const option
) (const face
))
1950 :group
'custom-buffer
)
1952 (defcustom custom-magic-show-button nil
1953 "Show a \"magic\" button indicating the state of each customization option."
1955 :group
'custom-buffer
)
1957 (define-widget 'custom-magic
'default
1958 "Show and manipulate state for a customization option."
1960 :action
'widget-parent-action
1963 :value-create
'custom-magic-value-create
1964 :value-delete
'widget-children-value-delete
)
1966 (defun widget-magic-mouse-down-action (widget &optional event
)
1967 ;; Non-nil unless hidden.
1968 (not (eq (widget-get (widget-get (widget-get widget
:parent
) :parent
)
1972 (defun custom-magic-value-create (widget)
1973 "Create compact status report for WIDGET."
1974 (let* ((parent (widget-get widget
:parent
))
1975 (state (widget-get parent
:custom-state
))
1976 (hidden (eq state
'hidden
))
1977 (entry (assq state custom-magic-alist
))
1978 (magic (nth 1 entry
))
1979 (face (nth 2 entry
))
1980 (category (widget-get parent
:custom-category
))
1981 (text (or (and (eq category
'group
)
1984 (form (widget-get parent
:custom-form
))
1986 (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text
)
1987 (setq text
(concat (match-string 1 text
)
1988 (symbol-name category
)
1989 (match-string 2 text
))))
1990 (when (and custom-magic-show
1992 (memq category custom-magic-show-hidden
)))
1994 (when (and (eq category
'group
)
1995 (not (and (eq custom-buffer-style
'links
)
1996 (> (widget-get parent
:custom-level
) 1))))
1997 (insert-char ?\
(* custom-buffer-indent
1998 (widget-get parent
:custom-level
))))
1999 (push (widget-create-child-and-convert
2001 :help-echo
"Change the state of this item."
2002 :format
(if hidden
"%t" "%[%t%]")
2003 :button-prefix
'widget-push-button-prefix
2004 :button-suffix
'widget-push-button-suffix
2005 :mouse-down-action
'widget-magic-mouse-down-action
2009 (let ((start (point)))
2010 (if (eq custom-magic-show
'long
)
2012 (insert (symbol-name state
)))
2013 (cond ((eq form
'lisp
)
2015 ((eq form
'mismatch
)
2016 (insert " (mismatch)")))
2017 (put-text-property start
(point) 'face
'custom-state
))
2019 (when (and (eq category
'group
)
2020 (not (and (eq custom-buffer-style
'links
)
2021 (> (widget-get parent
:custom-level
) 1))))
2022 (insert-char ?\
(* custom-buffer-indent
2023 (widget-get parent
:custom-level
))))
2024 (when custom-magic-show-button
2025 (when custom-magic-show
2026 (let ((indent (widget-get parent
:indent
)))
2028 (insert-char ? indent
))))
2029 (push (widget-create-child-and-convert
2031 :mouse-down-action
'widget-magic-mouse-down-action
2035 :help-echo
"Change the state."
2036 :format
(if hidden
"%t" "%[%t%]")
2037 :tag
(if (memq form
'(lisp mismatch
))
2038 (concat "(" magic
")")
2039 (concat "[" magic
"]")))
2042 (widget-put widget
:children children
)))
2044 (defun custom-magic-reset (widget)
2045 "Redraw the :custom-magic property of WIDGET."
2046 (let ((magic (widget-get widget
:custom-magic
)))
2047 (widget-value-set magic
(widget-value magic
))))
2049 ;;; The `custom' Widget.
2051 (defface custom-button
2052 '((((type x w32 ns
) (class color
)) ; Like default modeline
2053 (:box
(:line-width
2 :style released-button
)
2054 :background
"lightgrey" :foreground
"black"))
2057 "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2059 :group
'custom-faces
)
2060 (define-obsolete-face-alias 'custom-button-face
'custom-button
"22.1")
2062 (defface custom-button-mouse
2063 '((((type x w32 ns
) (class color
))
2064 (:box
(:line-width
2 :style released-button
)
2065 :background
"grey90" :foreground
"black"))
2067 ;; This is for text terminals that support mouse, like GPM mouse
2068 ;; or the MS-DOS terminal: inverse-video makes the button stand
2069 ;; out on mouse-over.
2070 (:inverse-video t
)))
2071 "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
2073 :group
'custom-faces
)
2075 (defface custom-button-unraised
2076 '((t :inherit underline
))
2077 "Face for custom buffer buttons if `custom-raised-buttons' is nil."
2079 :group
'custom-faces
)
2082 (if custom-raised-buttons
'custom-button
'custom-button-unraised
))
2084 (setq custom-button-mouse
2085 (if custom-raised-buttons
'custom-button-mouse
'highlight
))
2087 (defface custom-button-pressed
2088 '((((type x w32 ns
) (class color
))
2089 (:box
(:line-width
2 :style pressed-button
)
2090 :background
"lightgrey" :foreground
"black"))
2092 (:inverse-video t
)))
2093 "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
2095 :group
'custom-faces
)
2096 (define-obsolete-face-alias 'custom-button-pressed-face
2097 'custom-button-pressed
"22.1")
2099 (defface custom-button-pressed-unraised
2100 '((default :inherit custom-button-unraised
)
2101 (((class color
) (background light
)) :foreground
"magenta4")
2102 (((class color
) (background dark
)) :foreground
"violet"))
2103 "Face for pressed custom buttons if `custom-raised-buttons' is nil."
2105 :group
'custom-faces
)
2107 (setq custom-button-pressed
2108 (if custom-raised-buttons
2109 'custom-button-pressed
2110 'custom-button-pressed-unraised
))
2112 (defface custom-documentation
'((t nil
))
2113 "Face used for documentation strings in customization buffers."
2114 :group
'custom-faces
)
2115 (define-obsolete-face-alias 'custom-documentation-face
2116 'custom-documentation
"22.1")
2118 (defface custom-state
'((((class color
)
2120 (:foreground
"lime green"))
2123 (:foreground
"dark green"))
2125 "Face used for State descriptions in the customize buffer."
2126 :group
'custom-faces
)
2127 (define-obsolete-face-alias 'custom-state-face
'custom-state
"22.1")
2129 (defface custom-link
2130 '((t :inherit link
))
2131 "Face for links in customization buffers."
2133 :group
'custom-faces
)
2135 (define-widget 'custom
'default
2136 "Customize a user option."
2138 :convert-widget
'custom-convert-widget
2139 :notify
'custom-notify
2142 :custom-state
'hidden
2143 :documentation-property
'widget-subclass-responsibility
2144 :value-create
'widget-subclass-responsibility
2145 :value-delete
'widget-children-value-delete
2146 :value-get
'widget-value-value-get
2147 :validate
'widget-children-validate
2148 :match
(lambda (widget value
) (symbolp value
)))
2150 (defun custom-convert-widget (widget)
2151 "Initialize :value and :tag from :args in WIDGET."
2152 (let ((args (widget-get widget
:args
)))
2154 (widget-put widget
:value
(widget-apply widget
2155 :value-to-internal
(car args
)))
2156 (widget-put widget
:tag
(custom-unlispify-tag-name (car args
)))
2157 (widget-put widget
:args nil
)))
2160 (defun custom-notify (widget &rest args
)
2161 "Keep track of changes."
2162 (let ((state (widget-get widget
:custom-state
)))
2163 (unless (eq state
'modified
)
2164 (unless (memq state
'(nil unknown hidden
))
2165 (widget-put widget
:custom-state
'modified
))
2166 (custom-magic-reset widget
)
2167 (apply 'widget-default-notify widget args
))))
2169 (defun custom-redraw (widget)
2170 "Redraw WIDGET with current settings."
2171 (let ((line (count-lines (point-min) (point)))
2172 (column (current-column))
2174 (from (marker-position (widget-get widget
:from
)))
2175 (to (marker-position (widget-get widget
:to
))))
2177 (widget-value-set widget
(widget-value widget
))
2178 (custom-redraw-magic widget
))
2179 (when (and (>= pos from
) (<= pos to
))
2182 (goto-char (point-min))
2183 (forward-line (if (> column
0)
2186 (move-to-column column
))
2189 (defun custom-redraw-magic (widget)
2190 "Redraw WIDGET state with current settings."
2192 (let ((magic (widget-get widget
:custom-magic
)))
2194 (widget-value-set magic
(widget-value magic
))
2195 (when (setq widget
(widget-get widget
:group
))
2196 (custom-group-state-update widget
)))
2198 (setq widget nil
)))))
2201 (defun custom-show (widget value
)
2202 "Non-nil if WIDGET should be shown with VALUE by default."
2203 (let ((show (widget-get widget
:custom-show
)))
2209 (funcall show widget value
)))))
2211 (defun custom-load-widget (widget)
2212 "Load all dependencies for WIDGET."
2213 (custom-load-symbol (widget-value widget
)))
2215 (defun custom-unloaded-symbol-p (symbol)
2216 "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
2218 (loads (get symbol
'custom-loads
))
2221 (setq load
(car loads
)
2223 (cond ((symbolp load
)
2224 (unless (featurep load
)
2226 ((assoc load load-history
))
2227 ((assoc (locate-library load
) load-history
)
2233 (defun custom-unloaded-widget-p (widget)
2234 "Return non-nil if the dependencies of WIDGET have not yet been loaded."
2235 (custom-unloaded-symbol-p (widget-value widget
)))
2237 (defun custom-toggle-hide (widget)
2238 "Toggle visibility of WIDGET."
2239 (custom-load-widget widget
)
2240 (let ((state (widget-get widget
:custom-state
)))
2241 (cond ((memq state
'(invalid modified set
))
2242 (error "There are unsaved changes"))
2244 (widget-put widget
:custom-state
'unknown
))
2246 (widget-put widget
:documentation-shown nil
)
2247 (widget-put widget
:custom-state
'hidden
)))
2248 (custom-redraw widget
)
2251 (defun custom-toggle-parent (widget &rest ignore
)
2252 "Toggle visibility of parent of WIDGET."
2253 (custom-toggle-hide (widget-get widget
:parent
)))
2255 (defun custom-add-see-also (widget &optional prefix
)
2256 "Add `See also ...' to WIDGET if there are any links.
2257 Insert PREFIX first if non-nil."
2258 (let* ((symbol (widget-get widget
:value
))
2259 (links (get symbol
'custom-links
))
2260 (many (> (length links
) 2))
2261 (buttons (widget-get widget
:buttons
))
2262 (indent (widget-get widget
:indent
)))
2265 (insert-char ?\ indent
))
2268 (insert "See also ")
2270 (push (widget-create-child-and-convert
2272 :button-face
'custom-link
2273 :mouse-face
'highlight
2274 :pressed-face
'highlight
)
2276 (setq links
(cdr links
))
2285 (widget-put widget
:buttons buttons
))))
2287 (defun custom-add-parent-links (widget &optional initial-string
2289 "Add \"Parent groups: ...\" to WIDGET if the group has parents.
2290 The value is non-nil if any parents were found.
2291 If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
2292 (let ((name (widget-value widget
))
2293 (type (widget-type widget
))
2294 (buttons (widget-get widget
:buttons
))
2297 (insert (or initial-string
"Groups:"))
2298 (mapatoms (lambda (symbol)
2299 (when (member (list name type
) (get symbol
'custom-group
))
2301 (push (widget-create-child-and-convert
2302 widget
'custom-group-link
2303 :tag
(custom-unlispify-tag-name symbol
)
2306 (setq parents
(cons symbol parents
)))))
2307 (and (null (get name
'custom-links
)) ;No links of its own.
2308 (= (length parents
) 1) ;A single parent.
2309 (let* ((links (delq nil
(mapcar (lambda (w)
2310 (unless (eq (widget-type w
)
2313 (get (car parents
) 'custom-links
))))
2314 (many (> (length links
) 2)))
2317 (left-margin (+ left-margin
2)))
2318 (insert "\n" (or doc-initial-string
"Group documentation:") " ")
2320 (push (widget-create-child-and-convert
2322 :button-face
'custom-link
2323 :mouse-face
'highlight
2324 :pressed-face
'highlight
)
2326 (setq links
(cdr links
))
2335 (fill-region-as-paragraph pt
(point))
2336 (delete-to-left-margin (1+ pt
) (+ pt
2))))))
2339 (delete-region start
(point)))
2340 (widget-put widget
:buttons buttons
)
2343 ;;; The `custom-comment' Widget.
2345 ;; like the editable field
2346 (defface custom-comment
'((((type tty
))
2347 :background
"yellow3"
2348 :foreground
"black")
2349 (((class grayscale color
)
2351 :background
"gray85")
2352 (((class grayscale color
)
2354 :background
"dim gray")
2357 "Face used for comments on variables or faces."
2359 :group
'custom-faces
)
2360 (define-obsolete-face-alias 'custom-comment-face
'custom-comment
"22.1")
2362 ;; like font-lock-comment-face
2363 (defface custom-comment-tag
2364 '((((class color
) (background dark
)) (:foreground
"gray80"))
2365 (((class color
) (background light
)) (:foreground
"blue4"))
2366 (((class grayscale
) (background light
))
2367 (:foreground
"DimGray" :weight bold
:slant italic
))
2368 (((class grayscale
) (background dark
))
2369 (:foreground
"LightGray" :weight bold
:slant italic
))
2371 "Face used for the comment tag on variables or faces."
2372 :group
'custom-faces
)
2373 (define-obsolete-face-alias 'custom-comment-tag-face
'custom-comment-tag
"22.1")
2375 (define-widget 'custom-comment
'string
2378 :help-echo
"Edit a comment here."
2379 :sample-face
'custom-comment-tag
2380 :value-face
'custom-comment
2382 :create
'custom-comment-create
)
2384 (defun custom-comment-create (widget)
2385 (let* ((null-comment (equal "" (widget-value widget
))))
2386 (if (or (widget-get (widget-get widget
:parent
) :comment-shown
)
2388 (widget-default-create widget
)
2389 ;; `widget-default-delete' expects markers in these slots --
2390 ;; maybe it shouldn't.
2391 (widget-put widget
:from
(point-marker))
2392 (widget-put widget
:to
(point-marker)))))
2394 (defun custom-comment-hide (widget)
2395 (widget-put (widget-get widget
:parent
) :comment-shown nil
))
2397 ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
2398 ;; the global custom one
2399 (defun custom-comment-show (widget)
2400 (widget-put widget
:comment-shown t
)
2401 (custom-redraw widget
)
2404 (defun custom-comment-invisible-p (widget)
2405 (let ((val (widget-value (widget-get widget
:comment-widget
))))
2407 (not (widget-get widget
:comment-shown
)))))
2409 ;;; The `custom-variable' Widget.
2411 ;; When this was underlined blue, users confused it with a
2412 ;; Mosaic-style hyperlink...
2413 (defface custom-variable-tag
2416 (:foreground
"light blue" :weight bold
))
2417 (((min-colors 88) (class color
)
2419 (:foreground
"blue1" :weight bold
))
2422 (:foreground
"blue" :weight bold
))
2424 "Face used for unpushable variable tags."
2425 :group
'custom-faces
)
2426 (define-obsolete-face-alias 'custom-variable-tag-face
2427 'custom-variable-tag
"22.1")
2429 (defface custom-variable-button
'((t (:underline t
:weight bold
)))
2430 "Face used for pushable variable tags."
2431 :group
'custom-faces
)
2432 (define-obsolete-face-alias 'custom-variable-button-face
2433 'custom-variable-button
"22.1")
2435 (defcustom custom-variable-default-form
'edit
2436 "Default form of displaying variable values."
2437 :type
'(choice (const edit
)
2439 :group
'custom-buffer
2442 (defun custom-variable-documentation (variable)
2443 "Return documentation of VARIABLE for use in Custom buffer.
2444 Normally just return the docstring. But if VARIABLE automatically
2445 becomes buffer local when set, append a message to that effect."
2446 (if (and (local-variable-if-set-p variable
)
2447 (or (not (local-variable-p variable
))
2449 (local-variable-if-set-p variable
))))
2450 (concat (documentation-property variable
'variable-documentation
)
2452 This variable automatically becomes buffer-local when set outside Custom.
2453 However, setting it through Custom sets the default value.")
2454 (documentation-property variable
'variable-documentation
)))
2456 (define-widget 'custom-variable
'custom
2457 "Customize variable."
2459 :help-echo
"Set or reset this variable."
2460 :documentation-property
#'custom-variable-documentation
2461 :custom-category
'option
2463 :custom-menu
'custom-variable-menu-create
2464 :custom-form nil
; defaults to value of `custom-variable-default-form'
2465 :value-create
'custom-variable-value-create
2466 :action
'custom-variable-action
2467 :custom-set
'custom-variable-set
2468 :custom-mark-to-save
'custom-variable-mark-to-save
2469 :custom-reset-current
'custom-redraw
2470 :custom-reset-saved
'custom-variable-reset-saved
2471 :custom-reset-standard
'custom-variable-reset-standard
2472 :custom-mark-to-reset-standard
'custom-variable-mark-to-reset-standard
2473 :custom-standard-value
'custom-variable-standard-value
2474 :custom-state-set-and-redraw
'custom-variable-state-set-and-redraw
)
2476 (defun custom-variable-type (symbol)
2477 "Return a widget suitable for editing the value of SYMBOL.
2478 If SYMBOL has a `custom-type' property, use that.
2479 Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
2480 try matching its doc string against `custom-guess-doc-alist'."
2481 (let* ((type (or (get symbol
'custom-type
)
2482 (and (not (get symbol
'standard-value
))
2483 (custom-guess-type symbol
))
2485 (options (get symbol
'custom-options
))
2486 (tmp (if (listp type
)
2487 (copy-sequence type
)
2490 (widget-put tmp
:options options
))
2493 (defun custom-variable-value-create (widget)
2494 "Here is where you edit the variable's value."
2495 (custom-load-widget widget
)
2496 (unless (widget-get widget
:custom-form
)
2497 (widget-put widget
:custom-form custom-variable-default-form
))
2498 (let* ((buttons (widget-get widget
:buttons
))
2499 (children (widget-get widget
:children
))
2500 (form (widget-get widget
:custom-form
))
2501 (state (widget-get widget
:custom-state
))
2502 (symbol (widget-get widget
:value
))
2503 (tag (widget-get widget
:tag
))
2504 (type (custom-variable-type symbol
))
2505 (conv (widget-convert type
))
2506 (get (or (get symbol
'custom-get
) 'default-value
))
2507 (prefix (widget-get widget
:custom-prefix
))
2508 (last (widget-get widget
:custom-last
))
2509 (value (if (default-boundp symbol
)
2510 (funcall get symbol
)
2511 (widget-get conv
:value
))))
2512 ;; If the widget is new, the child determines whether it is hidden.
2514 ((custom-show type value
)
2515 (setq state
'unknown
))
2517 (setq state
'hidden
)))
2518 ;; If we don't know the state, see if we need to edit it in lisp form.
2519 (when (eq state
'unknown
)
2520 (unless (widget-apply conv
:match value
)
2521 ;; (widget-apply (widget-convert type) :match value)
2522 (setq form
'mismatch
)))
2523 ;; Now we can create the child widget.
2524 (cond ((eq custom-buffer-style
'tree
)
2525 (insert prefix
(if last
" `--- " " |--- "))
2526 (push (widget-create-child-and-convert
2527 widget
'custom-browse-variable-tag
)
2529 (insert " " tag
"\n")
2530 (widget-put widget
:buttons buttons
))
2532 ;; Indicate hidden value.
2533 (push (widget-create-child-and-convert
2536 :sample-face
'custom-variable-tag
2540 (push (widget-create-child-and-convert
2542 :help-echo
"Show the value of this option."
2544 :action
'custom-toggle-parent
2547 ((memq form
'(lisp mismatch
))
2548 ;; In lisp mode edit the saved value when possible.
2549 (let* ((value (cond ((get symbol
'saved-value
)
2550 (car (get symbol
'saved-value
)))
2551 ((get symbol
'standard-value
)
2552 (car (get symbol
'standard-value
)))
2553 ((default-boundp symbol
)
2554 (custom-quote (funcall get symbol
)))
2556 (custom-quote (widget-get conv
:value
))))))
2557 (insert (symbol-name symbol
) ": ")
2558 (push (widget-create-child-and-convert
2560 :help-echo
"Hide the value of this option."
2563 :action
'custom-toggle-parent
2567 (push (widget-create-child-and-convert
2569 :button-face
'custom-variable-button-face
2571 :tag
(symbol-name symbol
)
2577 (let* ((format (widget-get type
:format
))
2578 tag-format value-format
)
2579 (unless (string-match ":" format
)
2580 (error "Bad format"))
2581 (setq tag-format
(substring format
0 (match-end 0)))
2582 (setq value-format
(substring format
(match-end 0)))
2583 (push (widget-create-child-and-convert
2586 :action
'custom-tag-action
2587 :help-echo
"Change value of this option."
2588 :mouse-down-action
'custom-tag-mouse-down-action
2589 :button-face
'custom-variable-button
2590 :sample-face
'custom-variable-tag
2594 (push (widget-create-child-and-convert
2596 :help-echo
"Hide the value of this option."
2599 :action
'custom-toggle-parent
2602 (push (widget-create-child-and-convert
2604 :format value-format
2607 (unless (eq custom-buffer-style
'tree
)
2608 (unless (eq (preceding-char) ?
\n)
2609 (widget-insert "\n"))
2610 ;; Create the magic button.
2611 (let ((magic (widget-create-child-and-convert
2612 widget
'custom-magic nil
)))
2613 (widget-put widget
:custom-magic magic
)
2614 (push magic buttons
))
2615 (widget-put widget
:buttons buttons
)
2616 ;; Insert documentation.
2617 (widget-put widget
:documentation-indent
3)
2618 (widget-add-documentation-string-button
2619 widget
:visibility-widget
'custom-visibility
)
2621 ;; The comment field
2622 (unless (eq state
'hidden
)
2623 (let* ((comment (get symbol
'variable-comment
))
2625 (widget-create-child-and-convert
2626 widget
'custom-comment
2628 :value
(or comment
""))))
2629 (widget-put widget
:comment-widget comment-widget
)
2630 ;; Don't push it !!! Custom assumes that the first child is the
2632 (setq children
(append children
(list comment-widget
)))))
2633 ;; Update the rest of the properties properties.
2634 (widget-put widget
:custom-form form
)
2635 (widget-put widget
:children children
)
2636 ;; Now update the state.
2637 (if (eq state
'hidden
)
2638 (widget-put widget
:custom-state state
)
2639 (custom-variable-state-set widget
))
2641 (unless (eq state
'hidden
)
2642 (when (eq (widget-get widget
:custom-level
) 1)
2643 (custom-add-parent-links widget
))
2644 (custom-add-see-also widget
)))))
2646 (defun custom-tag-action (widget &rest args
)
2647 "Pass :action to first child of WIDGET's parent."
2648 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2651 (defun custom-tag-mouse-down-action (widget &rest args
)
2652 "Pass :mouse-down-action to first child of WIDGET's parent."
2653 (apply 'widget-apply
(car (widget-get (widget-get widget
:parent
) :children
))
2654 :mouse-down-action args
))
2656 (defun custom-variable-state-set (widget)
2657 "Set the state of WIDGET."
2658 (let* ((symbol (widget-value widget
))
2659 (get (or (get symbol
'custom-get
) 'default-value
))
2660 (value (if (default-boundp symbol
)
2661 (funcall get symbol
)
2662 (widget-get widget
:value
)))
2663 (comment (get symbol
'variable-comment
))
2666 (state (cond ((progn (setq tmp
(get symbol
'customized-value
))
2668 (get symbol
'customized-variable-comment
))
2670 (if (condition-case nil
2671 (and (equal value
(eval (car tmp
)))
2672 (equal comment temp
))
2676 ((progn (setq tmp
(get symbol
'theme-value
))
2677 (setq temp
(get symbol
'saved-variable-comment
))
2679 (if (condition-case nil
2680 (and (equal comment temp
)
2683 (car (custom-variable-theme-value
2687 ((eq (caar tmp
) 'user
) 'saved
)
2688 ((eq (caar tmp
) 'changed
)
2689 (if (condition-case nil
2693 (car (get symbol
'standard-value
)))))
2695 ;; The value was originally set outside
2696 ;; custom, but it was set to the standard
2697 ;; value (probably an autoloaded defcustom).
2702 ((setq tmp
(get symbol
'standard-value
))
2703 (if (condition-case nil
2704 (and (equal value
(eval (car tmp
)))
2705 (equal comment nil
))
2710 (widget-put widget
:custom-state state
)))
2712 (defun custom-variable-standard-value (widget)
2713 (get (widget-value widget
) 'standard-value
))
2715 (defvar custom-variable-menu
2716 `(("Set for Current Session" custom-variable-set
2718 (eq (widget-get widget
:custom-state
) 'modified
)))
2719 ;; Note that in all the backquoted code in this file, we test
2720 ;; init-file-user rather than user-init-file. This is in case
2721 ;; cus-edit is loaded by something in site-start.el, because
2722 ;; user-init-file is not set at that stage.
2723 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
2724 ,@(when (or custom-file init-file-user
)
2725 '(("Save for Future Sessions" custom-variable-save
2727 (memq (widget-get widget
:custom-state
)
2728 '(modified set changed rogue
))))))
2729 ("Undo Edits" custom-redraw
2731 (and (default-boundp (widget-value widget
))
2732 (memq (widget-get widget
:custom-state
) '(modified changed
)))))
2733 ("Reset to Saved" custom-variable-reset-saved
2735 (and (or (get (widget-value widget
) 'saved-value
)
2736 (get (widget-value widget
) 'saved-variable-comment
))
2737 (memq (widget-get widget
:custom-state
)
2738 '(modified set changed rogue
)))))
2739 ,@(when (or custom-file init-file-user
)
2740 '(("Erase Customization" custom-variable-reset-standard
2742 (and (get (widget-value widget
) 'standard-value
)
2743 (memq (widget-get widget
:custom-state
)
2744 '(modified set changed saved rogue
)))))))
2745 ("Set to Backup Value" custom-variable-reset-backup
2747 (get (widget-value widget
) 'backup-value
)))
2748 ("---" ignore ignore
)
2749 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
2750 ("---" ignore ignore
)
2751 ("Show Current Value" custom-variable-edit
2753 (eq (widget-get widget
:custom-form
) 'lisp
)))
2754 ("Show Saved Lisp Expression" custom-variable-edit-lisp
2756 (eq (widget-get widget
:custom-form
) 'edit
))))
2757 "Alist of actions for the `custom-variable' widget.
2758 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
2759 the menu entry, ACTION is the function to call on the widget when the
2760 menu is selected, and FILTER is a predicate which takes a `custom-variable'
2761 widget as an argument, and returns non-nil if ACTION is valid on that
2762 widget. If FILTER is nil, ACTION is always valid.")
2764 (defun custom-variable-action (widget &optional event
)
2765 "Show the menu for `custom-variable' WIDGET.
2766 Optional EVENT is the location for the menu."
2767 (if (eq (widget-get widget
:custom-state
) 'hidden
)
2768 (custom-toggle-hide widget
)
2769 (unless (eq (widget-get widget
:custom-state
) 'modified
)
2770 (custom-variable-state-set widget
))
2771 (custom-redraw-magic widget
)
2772 (let* ((completion-ignore-case t
)
2773 (answer (widget-choose (concat "Operation on "
2774 (custom-unlispify-tag-name
2775 (widget-get widget
:value
)))
2776 (custom-menu-filter custom-variable-menu
2780 (funcall answer widget
)))))
2782 (defun custom-variable-edit (widget)
2783 "Edit value of WIDGET."
2784 (widget-put widget
:custom-state
'unknown
)
2785 (widget-put widget
:custom-form
'edit
)
2786 (custom-redraw widget
))
2788 (defun custom-variable-edit-lisp (widget)
2789 "Edit the Lisp representation of the value of WIDGET."
2790 (widget-put widget
:custom-state
'unknown
)
2791 (widget-put widget
:custom-form
'lisp
)
2792 (custom-redraw widget
))
2794 (defun custom-variable-set (widget)
2795 "Set the current value for the variable being edited by WIDGET."
2796 (let* ((form (widget-get widget
:custom-form
))
2797 (state (widget-get widget
:custom-state
))
2798 (child (car (widget-get widget
:children
)))
2799 (symbol (widget-value widget
))
2800 (set (or (get symbol
'custom-set
) 'set-default
))
2801 (comment-widget (widget-get widget
:comment-widget
))
2802 (comment (widget-value comment-widget
))
2804 (cond ((eq state
'hidden
)
2805 (error "Cannot set hidden variable"))
2806 ((setq val
(widget-apply child
:validate
))
2807 (goto-char (widget-get val
:from
))
2808 (error "%s" (widget-get val
:error
)))
2809 ((memq form
'(lisp mismatch
))
2810 (when (equal comment
"")
2812 ;; Make the comment invisible by hand if it's empty
2813 (custom-comment-hide comment-widget
))
2814 (custom-variable-backup-value widget
)
2815 (custom-push-theme 'theme-value symbol
'user
2816 'set
(custom-quote (widget-value child
)))
2817 (funcall set symbol
(eval (setq val
(widget-value child
))))
2818 (put symbol
'customized-value
(list val
))
2819 (put symbol
'variable-comment comment
)
2820 (put symbol
'customized-variable-comment comment
))
2822 (when (equal comment
"")
2824 ;; Make the comment invisible by hand if it's empty
2825 (custom-comment-hide comment-widget
))
2826 (custom-variable-backup-value widget
)
2827 (custom-push-theme 'theme-value symbol
'user
2828 'set
(custom-quote (widget-value child
)))
2829 (funcall set symbol
(setq val
(widget-value child
)))
2830 (put symbol
'customized-value
(list (custom-quote val
)))
2831 (put symbol
'variable-comment comment
)
2832 (put symbol
'customized-variable-comment comment
)))
2833 (custom-variable-state-set widget
)
2834 (custom-redraw-magic widget
)))
2836 (defun custom-variable-mark-to-save (widget)
2837 "Set value and mark for saving the variable edited by WIDGET."
2838 (let* ((form (widget-get widget
:custom-form
))
2839 (state (widget-get widget
:custom-state
))
2840 (child (car (widget-get widget
:children
)))
2841 (symbol (widget-value widget
))
2842 (set (or (get symbol
'custom-set
) 'set-default
))
2843 (comment-widget (widget-get widget
:comment-widget
))
2844 (comment (widget-value comment-widget
))
2846 (cond ((eq state
'hidden
)
2847 (error "Cannot set hidden variable"))
2848 ((setq val
(widget-apply child
:validate
))
2849 (goto-char (widget-get val
:from
))
2850 (error "Saving %s: %s" symbol
(widget-get val
:error
)))
2851 ((memq form
'(lisp mismatch
))
2852 (when (equal comment
"")
2854 ;; Make the comment invisible by hand if it's empty
2855 (custom-comment-hide comment-widget
))
2856 (put symbol
'saved-value
(list (widget-value child
)))
2857 (custom-push-theme 'theme-value symbol
'user
2858 'set
(custom-quote (widget-value child
)))
2859 (funcall set symbol
(eval (widget-value child
)))
2860 (put symbol
'variable-comment comment
)
2861 (put symbol
'saved-variable-comment comment
))
2863 (when (equal comment
"")
2865 ;; Make the comment invisible by hand if it's empty
2866 (custom-comment-hide comment-widget
))
2867 (put symbol
'saved-value
2868 (list (custom-quote (widget-value child
))))
2869 (custom-push-theme 'theme-value symbol
'user
2870 'set
(custom-quote (widget-value child
)))
2871 (funcall set symbol
(widget-value child
))
2872 (put symbol
'variable-comment comment
)
2873 (put symbol
'saved-variable-comment comment
)))
2874 (put symbol
'customized-value nil
)
2875 (put symbol
'customized-variable-comment nil
)))
2877 (defsubst custom-variable-state-set-and-redraw
(widget)
2878 "Set state of variable widget WIDGET and redraw with current settings."
2879 (custom-variable-state-set widget
)
2880 (custom-redraw-magic widget
))
2882 (defun custom-variable-save (widget)
2883 "Save value of variable edited by widget WIDGET."
2884 (custom-variable-mark-to-save widget
)
2886 (custom-variable-state-set-and-redraw widget
))
2888 (defun custom-variable-reset-saved (widget)
2889 "Restore the saved value for the variable being edited by WIDGET.
2890 This also updates the buffer to show that value.
2891 The value that was current before this operation
2892 becomes the backup value, so you can get it again."
2893 (let* ((symbol (widget-value widget
))
2894 (set (or (get symbol
'custom-set
) 'set-default
))
2895 (value (get symbol
'saved-value
))
2896 (comment (get symbol
'saved-variable-comment
)))
2897 (cond ((or value comment
)
2898 (put symbol
'variable-comment comment
)
2899 (custom-variable-backup-value widget
)
2900 (custom-push-theme 'theme-value symbol
'user
'set
(car-safe value
))
2902 (funcall set symbol
(eval (car value
)))
2905 (error "No saved value for %s" symbol
)))
2906 (put symbol
'customized-value nil
)
2907 (put symbol
'customized-variable-comment nil
)
2908 (widget-put widget
:custom-state
'unknown
)
2909 ;; This call will possibly make the comment invisible
2910 (custom-redraw widget
)))
2912 (defun custom-variable-mark-to-reset-standard (widget)
2913 "Mark to restore standard setting for the variable edited by widget WIDGET.
2914 If `custom-reset-standard-variables-list' is nil, save, reset and
2915 redraw the widget immediately."
2916 (let* ((symbol (widget-value widget
)))
2917 (if (get symbol
'standard-value
)
2918 (custom-variable-backup-value widget
)
2919 (error "No standard setting known for %S" symbol
))
2920 (put symbol
'variable-comment nil
)
2921 (put symbol
'customized-value nil
)
2922 (put symbol
'customized-variable-comment nil
)
2923 (custom-push-theme 'theme-value symbol
'user
'reset
)
2924 (custom-theme-recalc-variable symbol
)
2925 (if (and custom-reset-standard-variables-list
2926 (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
)))
2928 (put symbol
'saved-value nil
)
2929 (put symbol
'saved-variable-comment nil
)
2930 ;; Append this to `custom-reset-standard-variables-list' to
2931 ;; have `custom-reset-standard-save-and-update' save setting
2932 ;; to the file, update the widget's state, and redraw it.
2933 (setq custom-reset-standard-variables-list
2934 (cons widget custom-reset-standard-variables-list
)))
2935 (when (or (get symbol
'saved-value
) (get symbol
'saved-variable-comment
))
2936 (put symbol
'saved-value nil
)
2937 (put symbol
'saved-variable-comment nil
)
2939 (widget-put widget
:custom-state
'unknown
)
2940 ;; This call will possibly make the comment invisible
2941 (custom-redraw widget
))))
2943 (defun custom-variable-reset-standard (widget)
2944 "Restore standard setting for the variable edited by WIDGET.
2945 This operation eliminates any saved setting for the variable,
2946 restoring it to the state of a variable that has never been customized.
2947 The value that was current before this operation
2948 becomes the backup value, so you can get it again."
2949 (let (custom-reset-standard-variables-list)
2950 (custom-variable-mark-to-reset-standard widget
)))
2952 (defun custom-variable-backup-value (widget)
2953 "Back up the current value for WIDGET's variable.
2954 The backup value is kept in the car of the `backup-value' property."
2955 (let* ((symbol (widget-value widget
))
2956 (get (or (get symbol
'custom-get
) 'default-value
))
2957 (type (custom-variable-type symbol
))
2958 (conv (widget-convert type
))
2959 (value (if (default-boundp symbol
)
2960 (funcall get symbol
)
2961 (widget-get conv
:value
))))
2962 (put symbol
'backup-value
(list value
))))
2964 (defun custom-variable-reset-backup (widget)
2965 "Restore the backup value for the variable being edited by WIDGET.
2966 The value that was current before this operation
2967 becomes the backup value, so you can use this operation repeatedly
2968 to switch between two values."
2969 (let* ((symbol (widget-value widget
))
2970 (set (or (get symbol
'custom-set
) 'set-default
))
2971 (value (get symbol
'backup-value
))
2972 (comment-widget (widget-get widget
:comment-widget
))
2973 (comment (widget-value comment-widget
)))
2976 (custom-variable-backup-value widget
)
2977 (custom-push-theme 'theme-value symbol
'user
'set value
)
2979 (funcall set symbol
(car value
))
2981 (error "No backup value for %s" symbol
))
2982 (put symbol
'customized-value
(list (car value
)))
2983 (put symbol
'variable-comment comment
)
2984 (put symbol
'customized-variable-comment comment
)
2985 (custom-variable-state-set widget
)
2986 ;; This call will possibly make the comment invisible
2987 (custom-redraw widget
)))
2989 ;;; The `custom-visibility' Widget
2991 (define-widget 'custom-visibility
'visibility
2992 "Show or hide a documentation string."
2993 :button-face
'custom-visibility
2994 :pressed-face
'custom-visibility
2995 :mouse-face
'highlight
2996 :pressed-face
'highlight
)
2998 (defface custom-visibility
2999 '((t :height
0.8 :inherit link
))
3000 "Face for the `custom-visibility' widget."
3002 :group
'custom-faces
)
3004 ;;; The `custom-face-edit' Widget.
3006 (define-widget 'custom-face-edit
'checklist
3007 "Edit face attributes."
3011 :button-args
'(:help-echo
"Control whether this attribute has any effect.")
3012 :value-to-internal
'custom-face-edit-fix-value
3013 :match
(lambda (widget value
)
3014 (widget-checklist-match widget
3015 (custom-face-edit-fix-value widget value
)))
3016 :convert-widget
'custom-face-edit-convert-widget
3017 :args
(mapcar (lambda (att)
3020 :sibling-args
(widget-get (nth 1 att
) :sibling-args
)
3021 (list 'const
:format
"" :value
(nth 0 att
))
3023 custom-face-attributes
))
3025 (defun custom-face-edit-fix-value (widget value
)
3026 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3027 Also change :reverse-video to :inverse-video."
3031 (let ((key (car value
))
3032 (val (car (cdr value
))))
3033 (cond ((eq key
:italic
)
3034 (push :slant result
)
3035 (push (if val
'italic
'normal
) result
))
3037 (push :weight result
)
3038 (push (if val
'bold
'normal
) result
))
3039 ((eq key
:reverse-video
)
3040 (push :inverse-video result
)
3044 (push val result
))))
3045 (setq value
(cdr (cdr value
))))
3046 (setq result
(nreverse result
))
3050 (defun custom-face-edit-convert-widget (widget)
3051 "Convert :args as widget types in WIDGET."
3054 :args
(mapcar (lambda (arg)
3056 :deactivate
'custom-face-edit-deactivate
3057 :activate
'custom-face-edit-activate
3058 :delete
'custom-face-edit-delete
))
3059 (widget-get widget
:args
)))
3062 (defun custom-face-edit-deactivate (widget)
3063 "Make face widget WIDGET inactive for user modifications."
3064 (unless (widget-get widget
:inactive
)
3065 (let ((tag (custom-face-edit-attribute-tag widget
))
3066 (from (copy-marker (widget-get widget
:from
)))
3067 (value (widget-value widget
))
3068 (inhibit-read-only t
)
3069 (inhibit-modification-hooks t
))
3072 (widget-default-delete widget
)
3073 (insert tag
": *\n")
3074 (widget-put widget
:inactive
3075 (cons value
(cons from
(- (point) from
))))))))
3077 (defun custom-face-edit-activate (widget)
3078 "Make face widget WIDGET active for user modifications."
3079 (let ((inactive (widget-get widget
:inactive
))
3080 (inhibit-read-only t
)
3081 (inhibit-modification-hooks t
))
3082 (when (consp inactive
)
3084 (goto-char (car (cdr inactive
)))
3085 (delete-region (point) (+ (point) (cdr (cdr inactive
))))
3086 (widget-put widget
:inactive nil
)
3087 (widget-apply widget
:create
)
3088 (widget-value-set widget
(car inactive
))
3091 (defun custom-face-edit-delete (widget)
3092 "Remove WIDGET from the buffer."
3093 (let ((inactive (widget-get widget
:inactive
))
3094 (inhibit-read-only t
)
3095 (inhibit-modification-hooks t
))
3097 ;; Widget is alive, we don't have to do anything special
3098 (widget-default-delete widget
)
3099 ;; WIDGET is already deleted because we did so to inactivate it;
3100 ;; now just get rid of the label we put in its place.
3101 (delete-region (car (cdr inactive
))
3102 (+ (car (cdr inactive
)) (cdr (cdr inactive
))))
3103 (widget-put widget
:inactive nil
))))
3106 (defun custom-face-edit-attribute-tag (widget)
3107 "Return the first :tag property in WIDGET or one of its children."
3108 (let ((tag (widget-get widget
:tag
)))
3109 (or (and (not (equal tag
"")) tag
)
3110 (let ((children (widget-get widget
:children
)))
3111 (while (and (null tag
) children
)
3112 (setq tag
(custom-face-edit-attribute-tag (pop children
))))
3115 ;;; The `custom-display' Widget.
3117 (define-widget 'custom-display
'menu-choice
3118 "Select a display type."
3121 :help-echo
"Specify frames where the face attributes should be used."
3122 :args
'((const :tag
"all" t
)
3123 (const :tag
"defaults" default
)
3127 :args
((group :sibling-args
(:help-echo
"\
3128 Only match the specified window systems.")
3129 (const :format
"Type: "
3131 (checklist :inline t
3134 :sibling-args
(:help-echo
"\
3135 The X11 Window System.")
3137 (const :format
"PM "
3138 :sibling-args
(:help-echo
"\
3139 OS/2 Presentation Manager.")
3141 (const :format
"W32 "
3142 :sibling-args
(:help-echo
"\
3145 (const :format
"NS "
3146 :sibling-args
(:help-echo
"\
3147 GNUstep or Macintosh OS Cocoa interface.")
3149 (const :format
"DOS "
3150 :sibling-args
(:help-echo
"\
3153 (const :format
"TTY%n"
3154 :sibling-args
(:help-echo
"\
3155 Plain text terminals.")
3157 (group :sibling-args
(:help-echo
"\
3158 Only match the frames with the specified color support.")
3159 (const :format
"Class: "
3161 (checklist :inline t
3163 (const :format
"Color "
3164 :sibling-args
(:help-echo
"\
3165 Match color frames.")
3167 (const :format
"Grayscale "
3168 :sibling-args
(:help-echo
"\
3169 Match grayscale frames.")
3171 (const :format
"Monochrome%n"
3172 :sibling-args
(:help-echo
"\
3173 Match frames with no color support.")
3175 (group :sibling-args
(:help-echo
"\
3176 The minimum number of colors the frame should support.")
3177 (const :format
"" min-colors
)
3178 (integer :tag
"Minimum number of colors" ))
3179 (group :sibling-args
(:help-echo
"\
3180 Only match frames with the specified intensity.")
3182 Background brightness: "
3184 (checklist :inline t
3186 (const :format
"Light "
3187 :sibling-args
(:help-echo
"\
3188 Match frames with light backgrounds.")
3190 (const :format
"Dark\n"
3191 :sibling-args
(:help-echo
"\
3192 Match frames with dark backgrounds.")
3194 (group :sibling-args
(:help-echo
"\
3195 Only match frames that support the specified face attributes.")
3196 (const :format
"Supports attributes:" supports
)
3197 (custom-face-edit :inline t
:format
"%n%v"))))))
3199 ;;; The `custom-face' Widget.
3201 (defface custom-face-tag
3202 `((t :inherit custom-variable-tag
))
3203 "Face used for face tags."
3204 :group
'custom-faces
)
3205 (define-obsolete-face-alias 'custom-face-tag-face
'custom-face-tag
"22.1")
3207 (defcustom custom-face-default-form
'selected
3208 "Default form of displaying face definition."
3209 :type
'(choice (const all
)
3212 :group
'custom-buffer
3215 (define-widget 'custom-face
'custom
3217 :sample-face
'custom-face-tag
3218 :help-echo
"Set or reset this face."
3219 :documentation-property
#'face-doc-string
3220 :value-create
'custom-face-value-create
3221 :action
'custom-face-action
3222 :custom-category
'face
3223 :custom-form nil
; defaults to value of `custom-face-default-form'
3224 :custom-set
'custom-face-set
3225 :custom-mark-to-save
'custom-face-mark-to-save
3226 :custom-reset-current
'custom-redraw
3227 :custom-reset-saved
'custom-face-reset-saved
3228 :custom-reset-standard
'custom-face-reset-standard
3229 :custom-mark-to-reset-standard
'custom-face-mark-to-reset-standard
3230 :custom-standard-value
'custom-face-standard-value
3231 :custom-state-set-and-redraw
'custom-face-state-set-and-redraw
3232 :custom-menu
'custom-face-menu-create
)
3234 (define-widget 'custom-face-all
'editable-list
3235 "An editable list of display specifications and attributes."
3236 :entry-format
"%i %d %v"
3237 :insert-button-args
'(:help-echo
"Insert new display specification here.")
3238 :append-button-args
'(:help-echo
"Append new display specification here.")
3239 :delete-button-args
'(:help-echo
"Delete this display specification.")
3240 :args
'((group :format
"%v" custom-display custom-face-edit
)))
3242 (defconst custom-face-all
(widget-convert 'custom-face-all
)
3243 "Converted version of the `custom-face-all' widget.")
3245 (define-widget 'custom-display-unselected
'item
3246 "A display specification that doesn't match the selected display."
3247 :match
'custom-display-unselected-match
)
3249 (defun custom-display-unselected-match (widget value
)
3250 "Non-nil if VALUE is an unselected display specification."
3251 (not (face-spec-set-match-display value
(selected-frame))))
3253 (define-widget 'custom-face-selected
'group
3254 "Edit the attributes of the selected display in a face specification."
3255 :args
'((choice :inline t
3256 (group :tag
"With Defaults" :inline t
3257 (group (const :tag
"" default
)
3258 (custom-face-edit :tag
" Default\n Attributes"))
3261 (group custom-display-unselected sexp
))
3262 (group (sexp :format
"")
3263 (custom-face-edit :tag
" Overriding\n Attributes"))
3267 (group :tag
"No Defaults" :inline t
3270 (group custom-display-unselected sexp
))
3271 (group (sexp :format
"")
3272 (custom-face-edit :tag
"\n Attributes"))
3279 (defconst custom-face-selected
(widget-convert 'custom-face-selected
)
3280 "Converted version of the `custom-face-selected' widget.")
3282 (defun custom-filter-face-spec (spec filter-index
&optional default-filter
)
3283 "Return a canonicalized version of SPEC using.
3284 FILTER-INDEX is the index in the entry for each attribute in
3285 `custom-face-attributes' at which the appropriate filter function can be
3286 found, and DEFAULT-FILTER is the filter to apply for attributes that
3288 (mapcar (lambda (entry)
3289 ;; Filter a single face-spec entry
3290 (let ((tests (car entry
))
3292 ;; Handle both old- and new-style attribute syntax
3293 (if (listp (car (cdr entry
)))
3296 (filtered-attrs nil
))
3297 ;; Filter each face attribute
3298 (while unfiltered-attrs
3299 (let* ((attr (pop unfiltered-attrs
))
3300 (pre-filtered-value (pop unfiltered-attrs
))
3302 (or (nth filter-index
(assq attr custom-face-attributes
))
3306 (funcall filter pre-filtered-value
)
3307 pre-filtered-value
)))
3308 (push filtered-value filtered-attrs
)
3309 (push attr filtered-attrs
)))
3311 (list tests filtered-attrs
)))
3314 (defun custom-pre-filter-face-spec (spec)
3315 "Return SPEC changed as necessary for editing by the face customization widget.
3316 SPEC must be a full face spec."
3317 (custom-filter-face-spec spec
2))
3319 (defun custom-post-filter-face-spec (spec)
3320 "Return the customized SPEC in a form suitable for setting the face."
3321 (custom-filter-face-spec spec
3))
3323 (defun custom-face-value-create (widget)
3324 "Create a list of the display specifications for WIDGET."
3325 (let ((buttons (widget-get widget
:buttons
))
3327 (symbol (widget-get widget
:value
))
3328 (tag (widget-get widget
:tag
))
3329 (state (widget-get widget
:custom-state
))
3331 (is-last (widget-get widget
:custom-last
))
3332 (prefix (widget-get widget
:custom-prefix
)))
3334 (setq tag
(prin1-to-string symbol
)))
3335 (cond ((eq custom-buffer-style
'tree
)
3336 (insert prefix
(if is-last
" `--- " " |--- "))
3337 (push (widget-create-child-and-convert
3338 widget
'custom-browse-face-tag
)
3340 (insert " " tag
"\n")
3341 (widget-put widget
:buttons buttons
))
3345 (widget-specify-sample widget begin
(point))
3346 (if (eq custom-buffer-style
'face
)
3348 (if (string-match "face\\'" tag
)
3350 (insert " face: ")))
3352 (push (widget-create-child-and-convert widget
'item
3359 (push (widget-create-child-and-convert
3361 :help-echo
"Hide or show this face."
3364 :action
'custom-toggle-parent
3365 (not (eq state
'hidden
)))
3369 (let ((magic (widget-create-child-and-convert
3370 widget
'custom-magic nil
)))
3371 (widget-put widget
:custom-magic magic
)
3372 (push magic buttons
))
3374 (widget-put widget
:buttons buttons
)
3375 ;; Insert documentation.
3376 (widget-put widget
:documentation-indent
3)
3377 (widget-add-documentation-string-button
3378 widget
:visibility-widget
'custom-visibility
)
3380 ;; The comment field
3381 (unless (eq state
'hidden
)
3382 (let* ((comment (get symbol
'face-comment
))
3384 (widget-create-child-and-convert
3385 widget
'custom-comment
3387 :value
(or comment
""))))
3388 (widget-put widget
:comment-widget comment-widget
)
3389 (push comment-widget children
)))
3391 (unless (eq state
'hidden
)
3392 (when (eq (widget-get widget
:custom-level
) 1)
3393 (custom-add-parent-links widget
))
3394 (custom-add-see-also widget
))
3396 (unless (eq (preceding-char) ?
\n)
3398 (unless (eq state
'hidden
)
3399 (message "Creating face editor...")
3400 (custom-load-widget widget
)
3401 (unless (widget-get widget
:custom-form
)
3402 (widget-put widget
:custom-form custom-face-default-form
))
3403 (let* ((symbol (widget-value widget
))
3404 (spec (or (get symbol
'customized-face
)
3405 (get symbol
'saved-face
)
3406 (get symbol
'face-defface-spec
)
3407 ;; Attempt to construct it.
3408 (list (list t
(custom-face-attributes-get
3409 symbol
(selected-frame))))))
3410 (form (widget-get widget
:custom-form
))
3411 (indent (widget-get widget
:indent
))
3413 ;; If the user has changed this face in some other way,
3414 ;; edit it as the user has specified it.
3415 (if (not (face-spec-match-p symbol spec
(selected-frame)))
3416 (setq spec
(list (list t
(face-attr-construct symbol
(selected-frame))))))
3417 (setq spec
(custom-pre-filter-face-spec spec
))
3418 (setq edit
(widget-create-child-and-convert
3420 (cond ((and (eq form
'selected
)
3421 (widget-apply custom-face-selected
3423 (when indent
(insert-char ?\ indent
))
3424 'custom-face-selected
)
3425 ((and (not (eq form
'lisp
))
3426 (widget-apply custom-face-all
3430 (when indent
(insert-char ?\ indent
))
3433 (custom-face-state-set widget
)
3434 (push edit children
)
3435 (widget-put widget
:children children
))
3436 (message "Creating face editor...done"))))))
3438 (defvar custom-face-menu
3439 `(("Set for Current Session" custom-face-set
)
3440 ,@(when (or custom-file init-file-user
)
3441 '(("Save for Future Sessions" custom-face-save
)))
3442 ("Undo Edits" custom-redraw
3444 (memq (widget-get widget
:custom-state
) '(modified changed
))))
3445 ("Reset to Saved" custom-face-reset-saved
3447 (or (get (widget-value widget
) 'saved-face
)
3448 (get (widget-value widget
) 'saved-face-comment
))))
3449 ,@(when (or custom-file init-file-user
)
3450 '(("Erase Customization" custom-face-reset-standard
3452 (get (widget-value widget
) 'face-defface-spec
)))))
3453 ("---" ignore ignore
)
3454 ("Add Comment" custom-comment-show custom-comment-invisible-p
)
3455 ("---" ignore ignore
)
3456 ("For Current Display" custom-face-edit-selected
3458 (not (eq (widget-get widget
:custom-form
) 'selected
))))
3459 ("For All Kinds of Displays" custom-face-edit-all
3461 (not (eq (widget-get widget
:custom-form
) 'all
))))
3462 ("Show Lisp Expression" custom-face-edit-lisp
3464 (not (eq (widget-get widget
:custom-form
) 'lisp
)))))
3465 "Alist of actions for the `custom-face' widget.
3466 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
3467 the menu entry, ACTION is the function to call on the widget when the
3468 menu is selected, and FILTER is a predicate which takes a `custom-face'
3469 widget as an argument, and returns non-nil if ACTION is valid on that
3470 widget. If FILTER is nil, ACTION is always valid.")
3472 (defun custom-face-edit-selected (widget)
3473 "Edit selected attributes of the value of WIDGET."
3474 (widget-put widget
:custom-state
'unknown
)
3475 (widget-put widget
:custom-form
'selected
)
3476 (custom-redraw widget
))
3478 (defun custom-face-edit-all (widget)
3479 "Edit all attributes of the value of WIDGET."
3480 (widget-put widget
:custom-state
'unknown
)
3481 (widget-put widget
:custom-form
'all
)
3482 (custom-redraw widget
))
3484 (defun custom-face-edit-lisp (widget)
3485 "Edit the Lisp representation of the value of WIDGET."
3486 (widget-put widget
:custom-state
'unknown
)
3487 (widget-put widget
:custom-form
'lisp
)
3488 (custom-redraw widget
))
3490 (defun custom-face-state-set (widget)
3491 "Set the state of WIDGET."
3492 (let* ((symbol (widget-value widget
))
3493 (comment (get symbol
'face-comment
))
3497 (setq tmp
(get symbol
'customized-face
))
3498 (setq temp
(get symbol
'customized-face-comment
))
3500 (if (equal temp comment
)
3504 (setq tmp
(get symbol
'saved-face
))
3505 (setq temp
(get symbol
'saved-face-comment
))
3507 (if (equal temp comment
)
3509 ((eq 'user
(caar (get symbol
'theme-face
)))
3511 ((eq 'changed
(caar (get symbol
'theme-face
)))
3515 ((get symbol
'face-defface-spec
)
3516 (if (equal comment nil
)
3521 ;; If the user called set-face-attribute to change the default
3522 ;; for new frames, this face is "set outside of Customize".
3523 (if (and (not (eq state
'rogue
))
3524 (get symbol
'face-modified
))
3525 (setq state
'changed
))
3526 (widget-put widget
:custom-state state
)))
3528 (defun custom-face-action (widget &optional event
)
3529 "Show the menu for `custom-face' WIDGET.
3530 Optional EVENT is the location for the menu."
3531 (if (eq (widget-get widget
:custom-state
) 'hidden
)
3532 (custom-toggle-hide widget
)
3533 (let* ((completion-ignore-case t
)
3534 (symbol (widget-get widget
:value
))
3535 (answer (widget-choose (concat "Operation on "
3536 (custom-unlispify-tag-name symbol
))
3537 (custom-menu-filter custom-face-menu
3541 (funcall answer widget
)))))
3543 (defun custom-face-set (widget)
3544 "Make the face attributes in WIDGET take effect."
3545 (let* ((symbol (widget-value widget
))
3546 (child (car (widget-get widget
:children
)))
3547 (value (custom-post-filter-face-spec (widget-value child
)))
3548 (comment-widget (widget-get widget
:comment-widget
))
3549 (comment (widget-value comment-widget
)))
3550 (when (equal comment
"")
3552 ;; Make the comment invisible by hand if it's empty
3553 (custom-comment-hide comment-widget
))
3554 (put symbol
'customized-face value
)
3555 (custom-push-theme 'theme-face symbol
'user
'set value
)
3556 (if (face-spec-choose value
)
3557 (face-spec-set symbol value t
)
3558 ;; face-set-spec ignores empty attribute lists, so just give it
3559 ;; something harmless instead.
3560 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3561 (put symbol
'customized-face-comment comment
)
3562 (put symbol
'face-comment comment
)
3563 (custom-face-state-set widget
)
3564 (custom-redraw-magic widget
)))
3566 (defun custom-face-mark-to-save (widget)
3567 "Mark for saving the face edited by WIDGET."
3568 (let* ((symbol (widget-value widget
))
3569 (child (car (widget-get widget
:children
)))
3570 (value (custom-post-filter-face-spec (widget-value child
)))
3571 (comment-widget (widget-get widget
:comment-widget
))
3572 (comment (widget-value comment-widget
)))
3573 (when (equal comment
"")
3575 ;; Make the comment invisible by hand if it's empty
3576 (custom-comment-hide comment-widget
))
3577 (custom-push-theme 'theme-face symbol
'user
'set value
)
3578 (if (face-spec-choose value
)
3579 (face-spec-set symbol value t
)
3580 ;; face-set-spec ignores empty attribute lists, so just give it
3581 ;; something harmless instead.
3582 (face-spec-set symbol
'((t :foreground unspecified
)) t
))
3583 (unless (eq (widget-get widget
:custom-state
) 'standard
)
3584 (put symbol
'saved-face value
))
3585 (put symbol
'customized-face nil
)
3586 (put symbol
'face-comment comment
)
3587 (put symbol
'customized-face-comment nil
)
3588 (put symbol
'saved-face-comment comment
)))
3590 (defsubst custom-face-state-set-and-redraw
(widget)
3591 "Set state of face widget WIDGET and redraw with current settings."
3592 (custom-face-state-set widget
)
3593 (custom-redraw-magic widget
))
3595 (defun custom-face-save (widget)
3596 "Save the face edited by WIDGET."
3597 (custom-face-mark-to-save widget
)
3599 (custom-face-state-set-and-redraw widget
))
3601 ;; For backward compatibility.
3602 (define-obsolete-function-alias 'custom-face-save-command
'custom-face-save
3605 (defun custom-face-reset-saved (widget)
3606 "Restore WIDGET to the face's default attributes."
3607 (let* ((symbol (widget-value widget
))
3608 (child (car (widget-get widget
:children
)))
3609 (value (get symbol
'saved-face
))
3610 (comment (get symbol
'saved-face-comment
))
3611 (comment-widget (widget-get widget
:comment-widget
)))
3612 (unless (or value comment
)
3613 (error "No saved value for this face"))
3614 (put symbol
'customized-face nil
)
3615 (put symbol
'customized-face-comment nil
)
3616 (custom-push-theme 'theme-face symbol
'user
'set value
)
3617 (face-spec-set symbol value t
)
3618 (put symbol
'face-comment comment
)
3619 (widget-value-set child value
)
3620 ;; This call manages the comment visibility
3621 (widget-value-set comment-widget
(or comment
""))
3622 (custom-face-state-set widget
)
3623 (custom-redraw-magic widget
)))
3625 (defun custom-face-standard-value (widget)
3626 (get (widget-value widget
) 'face-defface-spec
))
3628 (defun custom-face-mark-to-reset-standard (widget)
3629 "Restore widget WIDGET to the face's standard attribute values.
3630 If `custom-reset-standard-faces-list' is nil, save, reset and
3631 redraw the widget immediately."
3632 (let* ((symbol (widget-value widget
))
3633 (child (car (widget-get widget
:children
)))
3634 (value (get symbol
'face-defface-spec
))
3635 (comment-widget (widget-get widget
:comment-widget
)))
3637 (error "No standard setting for this face"))
3638 (put symbol
'customized-face nil
)
3639 (put symbol
'customized-face-comment nil
)
3640 (custom-push-theme 'theme-face symbol
'user
'reset
)
3641 (face-spec-set symbol value t
)
3642 (custom-theme-recalc-face symbol
)
3643 (if (and custom-reset-standard-faces-list
3644 (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
)))
3647 (put symbol
'saved-face nil
)
3648 (put symbol
'saved-face-comment nil
)
3649 ;; Append this to `custom-reset-standard-faces-list' and have
3650 ;; `custom-reset-standard-save-and-update' save setting to the
3651 ;; file, update the widget's state, and redraw it.
3652 (setq custom-reset-standard-faces-list
3653 (cons widget custom-reset-standard-faces-list
)))
3654 (when (or (get symbol
'saved-face
) (get symbol
'saved-face-comment
))
3655 (put symbol
'saved-face nil
)
3656 (put symbol
'saved-face-comment nil
)
3658 (put symbol
'face-comment nil
)
3659 (widget-value-set child
3660 (custom-pre-filter-face-spec
3661 (list (list t
(custom-face-attributes-get
3663 ;; This call manages the comment visibility
3664 (widget-value-set comment-widget
"")
3665 (custom-face-state-set widget
)
3666 (custom-redraw-magic widget
))))
3668 (defun custom-face-reset-standard (widget)
3669 "Restore WIDGET to the face's standard attribute values.
3670 This operation eliminates any saved attributes for the face,
3671 restoring it to the state of a face that has never been customized."
3672 (let (custom-reset-standard-faces-list)
3673 (custom-face-mark-to-reset-standard widget
)))
3675 ;;; The `face' Widget.
3677 (defvar widget-face-prompt-value-history nil
3678 "History of input to `widget-face-prompt-value'.")
3680 (define-widget 'face
'symbol
3681 "A Lisp face name (with sample)."
3682 :format
"%{%t%}: (%{sample%}) %v"
3685 :sample-face-get
'widget-face-sample-face-get
3686 :notify
'widget-face-notify
3687 :match
(lambda (widget value
) (facep value
))
3688 :complete-function
(lambda ()
3690 (lisp-complete-symbol 'facep
))
3691 :prompt-match
'facep
3692 :prompt-history
'widget-face-prompt-value-history
3693 :validate
(lambda (widget)
3694 (unless (facep (widget-value widget
))
3696 :error
(format "Invalid face: %S"
3697 (widget-value widget
)))
3700 (defun widget-face-sample-face-get (widget)
3701 (let ((value (widget-value widget
)))
3706 (defun widget-face-notify (widget child
&optional event
)
3707 "Update the sample, and notify the parent."
3708 (overlay-put (widget-get widget
:sample-overlay
)
3709 'face
(widget-apply widget
:sample-face-get
))
3710 (widget-default-notify widget child event
))
3713 ;;; The `hook' Widget.
3715 (define-widget 'hook
'list
3716 "An Emacs Lisp hook."
3717 :value-to-internal
(lambda (widget value
)
3718 (if (and value
(symbolp value
))
3721 :match
(lambda (widget value
)
3723 (widget-group-match widget value
)))
3724 ;; Avoid adding undefined functions to the hook, especially for
3725 ;; things like `find-file-hook' or even more basic ones, to avoid
3727 :set
(lambda (symbol value
)
3730 (add-hook symbol elt
))))
3731 :convert-widget
'custom-hook-convert-widget
3734 (defun custom-hook-convert-widget (widget)
3735 ;; Handle `:options'.
3736 (let* ((options (widget-get widget
:options
))
3737 (other `(editable-list :inline t
3738 :entry-format
"%i %d%v"
3739 (function :format
" %v")))
3741 (list `(checklist :inline t
3742 ,@(mapcar (lambda (entry)
3743 `(function-item ,entry
))
3747 (widget-put widget
:args args
)
3750 ;;; The `custom-group-link' Widget.
3752 (define-widget 'custom-group-link
'link
3753 "Show parent in other window when activated."
3754 :button-face
'custom-link
3755 :mouse-face
'highlight
3756 :pressed-face
'highlight
3757 :help-echo
"Create customization buffer for this group."
3758 :keymap custom-mode-link-map
3759 :follow-link
'mouse-face
3760 :action
'custom-group-link-action
)
3762 (defun custom-group-link-action (widget &rest ignore
)
3763 (customize-group (widget-value widget
)))
3765 ;;; The `custom-group' Widget.
3767 (defcustom custom-group-tag-faces nil
3768 ;; In XEmacs, this ought to play games with font size.
3769 ;; Fixme: make it do so in Emacs.
3770 "Face used for group tags.
3771 The first member is used for level 1 groups, the second for level 2,
3772 and so forth. The remaining group tags are shown with `custom-group-tag'."
3773 :type
'(repeat face
)
3774 :group
'custom-faces
)
3776 (defface custom-group-tag-1
3779 (:foreground
"pink" :weight bold
:height
1.2 :inherit variable-pitch
))
3780 (((min-colors 88) (class color
)
3782 (:foreground
"red1" :weight bold
:height
1.2 :inherit variable-pitch
))
3785 (:foreground
"red" :weight bold
:height
1.2 :inherit variable-pitch
))
3787 "Face used for group tags."
3788 :group
'custom-faces
)
3789 (define-obsolete-face-alias 'custom-group-tag-face-1
'custom-group-tag-1
"22.1")
3791 (defface custom-group-tag
3794 (:foreground
"light blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3795 (((min-colors 88) (class color
)
3797 (:foreground
"blue1" :weight bold
:height
1.2 :inherit variable-pitch
))
3800 (:foreground
"blue" :weight bold
:height
1.2 :inherit variable-pitch
))
3802 "Face used for low level group tags."
3803 :group
'custom-faces
)
3804 (define-obsolete-face-alias 'custom-group-tag-face
'custom-group-tag
"22.1")
3806 (define-widget 'custom-group
'custom
3809 :sample-face-get
'custom-group-sample-face-get
3810 :documentation-property
'group-documentation
3811 :help-echo
"Set or reset all members of this group."
3812 :value-create
'custom-group-value-create
3813 :action
'custom-group-action
3814 :custom-category
'group
3815 :custom-set
'custom-group-set
3816 :custom-mark-to-save
'custom-group-mark-to-save
3817 :custom-reset-current
'custom-group-reset-current
3818 :custom-reset-saved
'custom-group-reset-saved
3819 :custom-reset-standard
'custom-group-reset-standard
3820 :custom-mark-to-reset-standard
'custom-group-mark-to-reset-standard
3821 :custom-state-set-and-redraw
'custom-group-state-set-and-redraw
3822 :custom-menu
'custom-group-menu-create
)
3824 (defun custom-group-sample-face-get (widget)
3825 ;; Use :sample-face.
3826 (or (nth (1- (widget-get widget
:custom-level
)) custom-group-tag-faces
)
3829 (define-widget 'custom-group-visibility
'visibility
3830 "An indicator and manipulator for hidden group contents."
3831 :create
'custom-group-visibility-create
)
3833 (defun custom-group-visibility-create (widget)
3834 (let ((visible (widget-value widget
)))
3836 (insert "--------")))
3837 (widget-default-create widget
))
3839 (defun custom-group-members (symbol groups-only
)
3840 "Return SYMBOL's custom group members.
3841 If GROUPS-ONLY non-nil, return only those members that are groups."
3842 (if (not groups-only
)
3843 (get symbol
'custom-group
)
3845 (dolist (entry (get symbol
'custom-group
))
3846 (when (eq (nth 1 entry
) 'custom-group
)
3847 (push entry members
)))
3848 (nreverse members
))))
3850 (defun custom-group-value-create (widget)
3851 "Insert a customize group for WIDGET in the current buffer."
3852 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
3853 (custom-load-widget widget
))
3854 (let* ((state (widget-get widget
:custom-state
))
3855 (level (widget-get widget
:custom-level
))
3856 ;; (indent (widget-get widget :indent))
3857 (prefix (widget-get widget
:custom-prefix
))
3858 (buttons (widget-get widget
:buttons
))
3859 (tag (widget-get widget
:tag
))
3860 (symbol (widget-value widget
))
3861 (members (custom-group-members symbol
3862 (and (eq custom-buffer-style
'tree
)
3863 custom-browse-only-groups
)))
3864 (doc (widget-docstring widget
)))
3865 (cond ((and (eq custom-buffer-style
'tree
)
3867 (or members
(custom-unloaded-widget-p widget
)))
3868 (custom-browse-insert-prefix prefix
)
3869 (push (widget-create-child-and-convert
3870 widget
'custom-browse-visibility
3871 ;; :tag-glyph "plus"
3875 ;; (widget-glyph-insert nil "-- " "horizontal")
3876 (push (widget-create-child-and-convert
3877 widget
'custom-browse-group-tag
)
3879 (insert " " tag
"\n")
3880 (widget-put widget
:buttons buttons
))
3881 ((and (eq custom-buffer-style
'tree
)
3882 (zerop (length members
)))
3883 (custom-browse-insert-prefix prefix
)
3885 ;; (widget-glyph-insert nil "[ ]" "empty")
3886 ;; (widget-glyph-insert nil "-- " "horizontal")
3887 (push (widget-create-child-and-convert
3888 widget
'custom-browse-group-tag
)
3890 (insert " " tag
"\n")
3891 (widget-put widget
:buttons buttons
))
3892 ((eq custom-buffer-style
'tree
)
3893 (custom-browse-insert-prefix prefix
)
3894 (if (zerop (length members
))
3896 (custom-browse-insert-prefix prefix
)
3898 ;; (widget-glyph-insert nil "[ ]" "empty")
3899 ;; (widget-glyph-insert nil "-- " "horizontal")
3900 (push (widget-create-child-and-convert
3901 widget
'custom-browse-group-tag
)
3903 (insert " " tag
"\n")
3904 (widget-put widget
:buttons buttons
))
3905 (push (widget-create-child-and-convert
3906 widget
'custom-browse-visibility
3907 ;; :tag-glyph "minus"
3911 ;; (widget-glyph-insert nil "-\\ " "top")
3912 (push (widget-create-child-and-convert
3913 widget
'custom-browse-group-tag
)
3915 (insert " " tag
"\n")
3916 (widget-put widget
:buttons buttons
)
3917 (message "Creating group...")
3918 (let* ((members (custom-sort-items members
3919 custom-browse-sort-alphabetically
3920 custom-browse-order-groups
))
3921 (prefixes (widget-get widget
:custom-prefixes
))
3922 (custom-prefix-list (custom-prefix-add symbol prefixes
))
3923 (extra-prefix (if (widget-get widget
:custom-last
)
3926 (prefix (concat prefix extra-prefix
))
3929 (setq entry
(car members
)
3930 members
(cdr members
))
3931 (push (widget-create-child-and-convert
3932 widget
(nth 1 entry
)
3934 :tag
(custom-unlispify-tag-name (nth 0 entry
))
3935 :custom-prefixes custom-prefix-list
3936 :custom-level
(1+ level
)
3937 :custom-last
(null members
)
3938 :value
(nth 0 entry
)
3939 :custom-prefix prefix
)
3941 (widget-put widget
:children
(reverse children
)))
3942 (message "Creating group...done")))
3945 ;; Create level indicator.
3947 (if (eq custom-buffer-style
'links
)
3948 (push (widget-create-child-and-convert
3949 widget
'custom-group-link
3953 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3955 (push (widget-create-child-and-convert
3956 widget
'custom-group-visibility
3957 :help-echo
"Show members of this group."
3958 :action
'custom-toggle-parent
3959 (not (eq state
'hidden
)))
3962 ;; Create magic button.
3963 (let ((magic (widget-create-child-and-convert
3964 widget
'custom-magic nil
)))
3965 (widget-put widget
:custom-magic magic
)
3966 (push magic buttons
))
3968 (widget-put widget
:buttons buttons
)
3969 ;; Insert documentation.
3970 (if (and (eq custom-buffer-style
'links
) (> level
1))
3971 (widget-put widget
:documentation-indent
0))
3972 (widget-add-documentation-string-button
3973 widget
:visibility-widget
'custom-visibility
))
3977 ;; Add parent groups references above the group.
3978 (if t
;;; This should test that the buffer
3979 ;;; was made to display a group.
3981 (if (custom-add-parent-links widget
3983 "Parent group documentation:")
3985 ;; Create level indicator.
3986 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
3989 (let ((start (point)))
3990 (insert tag
" group: ")
3991 (widget-specify-sample widget start
(point)))
3994 (insert " Group definition missing. "))
3995 ((< (length doc
) 50)
3997 ;; Create visibility indicator.
3998 (unless (eq custom-buffer-style
'links
)
4000 (push (widget-create-child-and-convert
4002 :help-echo
"Hide members of this group."
4003 :action
'custom-toggle-parent
4004 (not (eq state
'hidden
)))
4007 ;; Create more dashes.
4008 ;; Use 76 instead of 75 to compensate for the temporary "<"
4009 ;; added by `widget-insert'.
4010 (insert-char ?-
(- 76 (current-column)
4011 (* custom-buffer-indent level
)))
4013 ;; Create magic button.
4014 (let ((magic (widget-create-child-and-convert
4015 widget
'custom-magic
4018 (widget-put widget
:custom-magic magic
)
4019 (push magic buttons
))
4021 (widget-put widget
:buttons buttons
)
4022 ;; Insert documentation.
4023 (when (and doc
(>= (length doc
) 50))
4024 (widget-add-documentation-string-button
4025 widget
:visibility-widget
'custom-visibility
))
4028 (if nil
;;; This should test that the buffer
4029 ;;; was not made to display a group.
4031 (insert-char ?\ custom-buffer-indent
)
4032 (custom-add-parent-links widget
)))
4033 (custom-add-see-also widget
4034 (make-string (* custom-buffer-indent level
)
4037 (message "Creating group...")
4038 (let* ((members (custom-sort-items members
4039 custom-buffer-sort-alphabetically
4040 custom-buffer-order-groups
))
4041 (prefixes (widget-get widget
:custom-prefixes
))
4042 (custom-prefix-list (custom-prefix-add symbol prefixes
))
4043 (length (length members
))
4045 (children (mapcar (lambda (entry)
4046 (widget-insert "\n")
4048 Creating group members... %2d%%"
4049 (/ (* 100.0 count
) length
))
4050 (setq count
(1+ count
))
4052 (widget-create-child-and-convert
4053 widget
(nth 1 entry
)
4055 :tag
(custom-unlispify-tag-name
4057 :custom-prefixes custom-prefix-list
4058 :custom-level
(1+ level
)
4059 :value
(nth 0 entry
))
4060 (unless (eq (preceding-char) ?
\n)
4061 (widget-insert "\n"))))
4063 (message "Creating group magic...")
4064 (mapc 'custom-magic-reset children
)
4065 (message "Creating group state...")
4066 (widget-put widget
:children children
)
4067 (custom-group-state-update widget
)
4068 (message "Creating group... done"))
4071 (insert-char ?\
(* custom-buffer-indent
(1- level
)))
4072 (insert "\\- " (widget-get widget
:tag
) " group end ")
4073 (insert-char ?-
(- 75 (current-column) (* custom-buffer-indent level
)))
4076 (defvar custom-group-menu
4077 `(("Set for Current Session" custom-group-set
4079 (eq (widget-get widget
:custom-state
) 'modified
)))
4080 ,@(when (or custom-file init-file-user
)
4081 '(("Save for Future Sessions" custom-group-save
4083 (memq (widget-get widget
:custom-state
) '(modified set
))))))
4084 ("Undo Edits" custom-group-reset-current
4086 (memq (widget-get widget
:custom-state
) '(modified))))
4087 ("Reset to Saved" custom-group-reset-saved
4089 (memq (widget-get widget
:custom-state
) '(modified set
))))
4090 ,@(when (or custom-file init-file-user
)
4091 '(("Erase Customization" custom-group-reset-standard
4093 (memq (widget-get widget
:custom-state
) '(modified set saved
)))))))
4094 "Alist of actions for the `custom-group' widget.
4095 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
4096 the menu entry, ACTION is the function to call on the widget when the
4097 menu is selected, and FILTER is a predicate which takes a `custom-group'
4098 widget as an argument, and returns non-nil if ACTION is valid on that
4099 widget. If FILTER is nil, ACTION is always valid.")
4101 (defun custom-group-action (widget &optional event
)
4102 "Show the menu for `custom-group' WIDGET.
4103 Optional EVENT is the location for the menu."
4104 (if (eq (widget-get widget
:custom-state
) 'hidden
)
4105 (custom-toggle-hide widget
)
4106 (let* ((completion-ignore-case t
)
4107 (answer (widget-choose (concat "Operation on "
4108 (custom-unlispify-tag-name
4109 (widget-get widget
:value
)))
4110 (custom-menu-filter custom-group-menu
4114 (funcall answer widget
)))))
4116 (defun custom-group-set (widget)
4117 "Set changes in all modified group members."
4118 (dolist (child (widget-get widget
:children
))
4119 (when (eq (widget-get child
:custom-state
) 'modified
)
4120 (widget-apply child
:custom-set
))))
4122 (defun custom-group-mark-to-save (widget)
4123 "Mark all modified group members for saving."
4124 (dolist (child (widget-get widget
:children
))
4125 (when (memq (widget-get child
:custom-state
) '(modified set
))
4126 (widget-apply child
:custom-mark-to-save
))))
4128 (defsubst custom-group-state-set-and-redraw
(widget)
4129 "Set state of group widget WIDGET and redraw with current settings."
4130 (dolist (child (widget-get widget
:children
))
4131 (when (memq (widget-get child
:custom-state
) '(modified set
))
4132 (widget-apply child
:custom-state-set-and-redraw
))))
4134 (defun custom-group-save (widget)
4135 "Save all modified group members."
4136 (custom-group-mark-to-save widget
)
4138 (custom-group-state-set-and-redraw widget
))
4140 (defun custom-group-reset-current (widget)
4141 "Reset all modified group members."
4142 (dolist (child (widget-get widget
:children
))
4143 (when (eq (widget-get child
:custom-state
) 'modified
)
4144 (widget-apply child
:custom-reset-current
))))
4146 (defun custom-group-reset-saved (widget)
4147 "Reset all modified or set group members."
4148 (dolist (child (widget-get widget
:children
))
4149 (when (memq (widget-get child
:custom-state
) '(modified set
))
4150 (widget-apply child
:custom-reset-saved
))))
4152 (defun custom-group-reset-standard (widget)
4153 "Reset all modified, set, or saved group members."
4154 (let ((custom-reset-standard-variables-list '(t))
4155 (custom-reset-standard-faces-list '(t)))
4156 (custom-group-mark-to-reset-standard widget
)
4157 (custom-reset-standard-save-and-update)))
4159 (defun custom-group-mark-to-reset-standard (widget)
4160 "Mark to reset all modified, set, or saved group members."
4161 (dolist (child (widget-get widget
:children
))
4162 (when (memq (widget-get child
:custom-state
)
4163 '(modified set saved
))
4164 (widget-apply child
:custom-mark-to-reset-standard
))))
4166 (defun custom-group-state-update (widget)
4168 (unless (eq (widget-get widget
:custom-state
) 'hidden
)
4169 (let* ((children (widget-get widget
:children
))
4170 (states (mapcar (lambda (child)
4171 (widget-get child
:custom-state
))
4173 (magics custom-magic-alist
)
4176 (let ((magic (car (car magics
))))
4177 (if (and (not (eq magic
'hidden
))
4178 (memq magic states
))
4181 (setq magics
(cdr magics
)))))
4182 (widget-put widget
:custom-state found
)))
4183 (custom-magic-reset widget
))
4185 ;;; Reading and writing the custom file.
4188 (defcustom custom-file nil
4189 "File used for storing customization information.
4190 The default is nil, which means to use your init file
4191 as specified by `user-init-file'. If the value is not nil,
4192 it should be an absolute file name.
4194 You can set this option through Custom, if you carefully read the
4195 last paragraph below. However, usually it is simpler to write
4196 something like the following in your init file:
4198 \(setq custom-file \"~/.emacs-custom.el\")
4201 Note that both lines are necessary: the first line tells Custom to
4202 save all customizations in this file, but does not load it.
4204 When you change this variable outside Custom, look in the
4205 previous custom file \(usually your init file) for the
4206 forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
4207 and copy them (whichever ones you find) to the new custom file.
4208 This will preserve your existing customizations.
4210 If you save this option using Custom, Custom will write all
4211 currently saved customizations, including the new one for this
4212 option itself, into the file you specify, overwriting any
4213 `custom-set-variables' and `custom-set-faces' forms already
4214 present in that file. It will not delete any customizations from
4215 the old custom file. You should do that manually if that is what you
4216 want. You also have to put something like `\(load \"CUSTOM-FILE\")
4217 in your init file, where CUSTOM-FILE is the actual name of the
4218 file. Otherwise, Emacs will not load the file when it starts up,
4219 and hence will not set `custom-file' to that file either."
4220 :type
'(choice (const :tag
"Your Emacs init file" nil
)
4221 (file :format
"%t:%v%d"
4223 "Please read entire docstring below before setting \
4224 this through Custom.
4225 Click on \"More\" \(or position point there and press RETURN)
4226 if only the first line of the docstring is shown."))
4229 (defun custom-file ()
4230 "Return the file name for saving customizations."
4233 (let ((user-init-file user-init-file
)
4235 (if (eq system-type
'ms-dos
) "~/_emacs" "~/.emacs")))
4236 (when (null user-init-file
)
4237 (if (or (file-exists-p default-init-file
)
4238 (and (eq system-type
'windows-nt
)
4239 (file-exists-p "~/_emacs")))
4240 ;; Started with -q, i.e. the file containing
4241 ;; Custom settings hasn't been read. Saving
4242 ;; settings there would overwrite other settings.
4243 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
4244 (setq user-init-file default-init-file
))
4247 ;; If recentf-mode is non-nil, this is defined.
4248 (declare-function recentf-expand-file-name
"recentf" (name))
4251 (defun custom-save-all ()
4252 "Save all customizations in `custom-file'."
4253 (when (and (null custom-file
) init-file-had-error
)
4254 (error "Cannot save customizations; init file was not fully loaded"))
4255 (let* ((filename (custom-file))
4260 (recentf-expand-file-name (custom-file)))
4263 (old-buffer (find-buffer-visiting filename
))
4266 (with-current-buffer (let ((find-file-visit-truename t
))
4267 (or old-buffer
(find-file-noselect filename
)))
4268 ;; We'll save using file-precious-flag, so avoid destroying
4269 ;; symlinks. (If we're not already visiting the buffer, this is
4270 ;; handled by find-file-visit-truename, above.)
4272 (setq old-buffer-name
(buffer-file-name))
4273 (set-visited-file-name (file-chase-links filename
)))
4275 (unless (eq major-mode
'emacs-lisp-mode
)
4277 (let ((inhibit-read-only t
))
4278 (custom-save-variables)
4279 (custom-save-faces))
4280 (let ((file-precious-flag t
))
4284 (set-visited-file-name old-buffer-name
)
4285 (set-buffer-modified-p nil
))
4286 (kill-buffer (current-buffer))))))
4289 (defun customize-save-customized ()
4290 "Save all user options which have been set in this session."
4292 (mapatoms (lambda (symbol)
4293 (let ((face (get symbol
'customized-face
))
4294 (value (get symbol
'customized-value
))
4295 (face-comment (get symbol
'customized-face-comment
))
4297 (get symbol
'customized-variable-comment
)))
4299 (put symbol
'saved-face face
)
4300 (custom-push-theme 'theme-face symbol
'user
'set value
)
4301 (put symbol
'customized-face nil
))
4303 (put symbol
'saved-value value
)
4304 (custom-push-theme 'theme-value symbol
'user
'set value
)
4305 (put symbol
'customized-value nil
))
4306 (when variable-comment
4307 (put symbol
'saved-variable-comment variable-comment
)
4308 (put symbol
'customized-variable-comment nil
))
4310 (put symbol
'saved-face-comment face-comment
)
4311 (put symbol
'customized-face-comment nil
)))))
4312 ;; We really should update all custom buffers here.
4315 ;; Editing the custom file contents in a buffer.
4317 (defun custom-save-delete (symbol)
4318 "Delete all calls to SYMBOL from the contents of the current buffer.
4319 Leave point at the old location of the first such call,
4320 or (if there were none) at the end of the buffer.
4322 This function does not save the buffer."
4323 (goto-char (point-min))
4324 ;; Skip all whitespace and comments.
4325 (while (forward-comment 1))
4327 (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
4330 (while t
;; We exit this loop only via throw.
4331 ;; Skip all whitespace and comments.
4332 (while (forward-comment 1))
4333 (let ((start (point))
4334 (sexp (condition-case nil
4335 (read (current-buffer))
4336 (end-of-file (throw 'found nil
)))))
4337 (when (and (listp sexp
)
4338 (eq (car sexp
) symbol
))
4339 (delete-region start
(point))
4341 (setq first
(point)))))))
4344 ;; Move in front of local variables, otherwise long Custom
4345 ;; entries would make them ineffective.
4346 (let ((pos (point-max))
4347 (case-fold-search t
))
4349 (goto-char (point-max))
4350 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
4352 (when (search-forward "Local Variables:" nil t
)
4353 (setq pos
(line-beginning-position))))
4356 (defun custom-save-variables ()
4357 "Save all customized variables in `custom-file'."
4359 (custom-save-delete 'custom-set-variables
)
4360 (let ((standard-output (current-buffer))
4361 (saved-list (make-list 1 0))
4363 ;; First create a sorted list of saved variables.
4366 (if (and (get symbol
'saved-value
)
4367 ;; ignore theme values
4368 (or (null (get symbol
'theme-value
))
4369 (eq 'user
(caar (get symbol
'theme-value
)))))
4370 (nconc saved-list
(list symbol
)))))
4371 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4374 (princ "(custom-set-variables
4375 ;; custom-set-variables was added by Custom.
4376 ;; If you edit it by hand, you could mess it up, so be careful.
4377 ;; Your init file should contain only one such instance.
4378 ;; If there is more than one, they won't work right.\n")
4379 (dolist (symbol saved-list
)
4380 (let ((spec (car-safe (get symbol
'theme-value
)))
4381 (value (get symbol
'saved-value
))
4382 (requests (get symbol
'custom-requests
))
4383 (now (and (not (custom-variable-p symbol
))
4385 (eq (get symbol
'force-value
)
4387 (comment (get symbol
'saved-variable-comment
)))
4388 ;; Check REQUESTS for validity.
4389 (dolist (request requests
)
4390 (when (and (symbolp request
) (not (featurep request
)))
4391 (message "Unknown requested feature: %s" request
)
4392 (setq requests
(delq request requests
))))
4393 ;; Is there anything customized about this variable?
4394 (when (or (and spec
(eq (car spec
) 'user
))
4396 (and (null spec
) (get symbol
'saved-value
)))
4397 ;; Output an element for this variable.
4398 ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
4399 ;; SYMBOL is the variable name.
4400 ;; VALUE-FORM is an expression to return the customized value.
4401 ;; NOW if non-nil means always set the variable immediately
4402 ;; when the customizations are reloaded. This is used
4403 ;; for rogue variables
4404 ;; REQUESTS is a list of packages to load before setting the
4405 ;; variable. Each element of it will be passed to `require'.
4406 ;; COMMENT is whatever comment the user has specified
4407 ;; with the customize facility.
4414 (when (or now requests comment
)
4417 (when (or requests comment
)
4427 (unless (looking-at "\n")
4430 (defun custom-save-faces ()
4431 "Save all customized faces in `custom-file'."
4433 (custom-save-delete 'custom-reset-faces
)
4434 (custom-save-delete 'custom-set-faces
)
4435 (let ((standard-output (current-buffer))
4436 (saved-list (make-list 1 0))
4438 ;; First create a sorted list of saved faces.
4441 (if (and (get symbol
'saved-face
)
4442 (eq 'user
(car (car-safe (get symbol
'theme-face
)))))
4443 (nconc saved-list
(list symbol
)))))
4444 (setq saved-list
(sort (cdr saved-list
) 'string
<))
4445 ;; The default face must be first, since it affects the others.
4446 (if (memq 'default saved-list
)
4447 (setq saved-list
(cons 'default
(delq 'default saved-list
))))
4450 (princ "(custom-set-faces
4451 ;; custom-set-faces was added by Custom.
4452 ;; If you edit it by hand, you could mess it up, so be careful.
4453 ;; Your init file should contain only one such instance.
4454 ;; If there is more than one, they won't work right.\n")
4455 (dolist (symbol saved-list
)
4456 (let ((spec (car-safe (get symbol
'theme-face
)))
4457 (value (get symbol
'saved-face
))
4458 (now (not (or (get symbol
'face-defface-spec
)
4459 (and (not (custom-facep symbol
))
4460 (not (get symbol
'force-face
))))))
4461 (comment (get symbol
'saved-face-comment
)))
4462 (when (or (and spec
(eq (nth 0 spec
) 'user
))
4464 (and (null spec
) (get symbol
'saved-face
)))
4465 ;; Don't print default face here.
4472 (when (or now comment
)
4482 (unless (looking-at "\n")
4485 ;;; The Customize Menu.
4489 (defcustom custom-menu-nesting
2
4490 "Maximum nesting in custom menus."
4492 :group
'custom-menu
)
4494 (defun custom-face-menu-create (widget symbol
)
4495 "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
4496 (vector (custom-unlispify-menu-entry symbol
)
4497 `(customize-face ',symbol
)
4500 (defun custom-variable-menu-create (widget symbol
)
4501 "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
4502 (let ((type (get symbol
'custom-type
)))
4503 (unless (listp type
)
4504 (setq type
(list type
)))
4505 (if (and type
(widget-get type
:custom-menu
))
4506 (widget-apply type
:custom-menu symbol
)
4507 (vector (custom-unlispify-menu-entry symbol
)
4508 `(customize-variable ',symbol
)
4511 ;; Add checkboxes to boolean variable entries.
4512 (widget-put (get 'boolean
'widget-type
)
4513 :custom-menu
(lambda (widget symbol
)
4514 (vector (custom-unlispify-menu-entry symbol
)
4515 `(customize-variable ',symbol
)
4517 ':selected symbol
)))
4519 (defun custom-group-menu-create (widget symbol
)
4520 "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
4521 `( ,(custom-unlispify-menu-entry symbol t
)
4522 :filter
(lambda (&rest junk
)
4523 (let* ((menu (custom-menu-create ',symbol
)))
4524 (if (consp menu
) (cdr menu
) menu
)))))
4527 (defun custom-menu-create (symbol)
4528 "Create menu for customization group SYMBOL.
4529 The menu is in a format applicable to `easy-menu-define'."
4530 (let* ((deactivate-mark nil
)
4531 (item (vector (custom-unlispify-menu-entry symbol
)
4532 `(customize-group ',symbol
)
4534 (if (and (or (not (boundp 'custom-menu-nesting
))
4535 (>= custom-menu-nesting
0))
4537 (custom-load-symbol symbol
)
4538 (< (length (get symbol
'custom-group
)) widget-menu-max-size
)))
4539 (let ((custom-prefix-list (custom-prefix-add symbol
4540 custom-prefix-list
))
4541 (members (custom-sort-items (get symbol
'custom-group
)
4542 custom-menu-sort-alphabetically
4543 custom-menu-order-groups
)))
4544 `(,(custom-unlispify-menu-entry symbol t
)
4547 ,@(mapcar (lambda (entry)
4548 (widget-apply (if (listp (nth 1 entry
))
4550 (list (nth 1 entry
)))
4551 :custom-menu
(nth 0 entry
)))
4556 (defun customize-menu-create (symbol &optional name
)
4557 "Return a customize menu for customization group SYMBOL.
4558 If optional NAME is given, use that as the name of the menu.
4559 Otherwise the menu will be named `Customize'.
4560 The format is suitable for use with `easy-menu-define'."
4562 (setq name
"Customize"))
4564 :filter
(lambda (&rest junk
)
4565 (let ((menu (custom-menu-create ',symbol
)))
4566 (if (consp menu
) (cdr menu
) menu
)))))
4568 ;;; Toolbar and menubar support
4571 Custom-mode-menu
(list custom-mode-map custom-field-keymap
)
4572 "Menu used in customization buffers."
4573 (nconc (list "Custom"
4574 (customize-menu-create 'customize
))
4575 (mapcar (lambda (arg)
4576 (let ((tag (nth 0 arg
))
4577 (command (nth 1 arg
))
4578 (active (nth 2 arg
))
4580 (vector tag command
:active
(eval active
) :help help
)))
4583 (defvar tool-bar-map
)
4585 ;;; `custom-tool-bar-map' used to be set up here. This will fail to
4586 ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
4587 ;;; we set this up lazily in `Custom-mode'.
4588 (defvar custom-tool-bar-map nil
4589 "Keymap for toolbar in Custom mode.")
4591 ;;; The Custom Mode.
4593 (defun Custom-no-edit (pos &optional event
)
4594 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4596 (error "You can't edit this part of the Custom buffer"))
4598 (defun Custom-newline (pos &optional event
)
4599 "Invoke button at POS, or refuse to allow editing of Custom buffer."
4601 (let ((button (get-char-property pos
'button
)))
4603 (widget-apply-action button event
)
4604 (error "You can't edit this part of the Custom buffer"))))
4606 (defun Custom-goto-parent ()
4607 "Go to the parent group listed at the top of this buffer.
4608 If several parents are listed, go to the first of them."
4611 (goto-char (point-min))
4612 (if (search-forward "\nParent groups: " nil t
)
4613 (let* ((button (get-char-property (point) 'button
))
4614 (parent (downcase (widget-get button
:tag
))))
4615 (customize-group parent
)))))
4617 (defcustom Custom-mode-hook nil
4618 "Hook called when entering Custom mode."
4620 :group
'custom-buffer
)
4622 (defun custom-state-buffer-message (widget)
4623 (if (eq (widget-get (widget-get widget
:parent
) :custom-state
) 'modified
)
4624 (message "To install your edits, invoke [State] and choose the Set operation")))
4626 (define-derived-mode Custom-mode nil
"Custom"
4627 "Major mode for editing customization buffers.
4629 The following commands are available:
4632 Move to next button, link or editable field. \\[widget-forward]
4633 Move to previous button, link or editable field. \\[widget-backward]
4634 \\<custom-field-keymap>\
4635 Complete content of editable text field. \\[widget-complete]
4636 \\<custom-mode-map>\
4637 Invoke button under the mouse pointer. \\[widget-button-click]
4638 Invoke button under point. \\[widget-button-press]
4639 Set all options from current text. \\[Custom-set]
4640 Make values in current text permanent. \\[Custom-save]
4641 Make text match actual option values. \\[Custom-reset-current]
4642 Reset options to permanent settings. \\[Custom-reset-saved]
4643 Erase customizations; set options
4644 and buffer text to the standard values. \\[Custom-reset-standard]
4646 Entry to this mode calls the value of `Custom-mode-hook'
4647 if that value is non-nil."
4648 (use-local-map custom-mode-map
)
4649 (easy-menu-add Custom-mode-menu
)
4650 (set (make-local-variable 'tool-bar-map
)
4651 (or custom-tool-bar-map
4652 ;; Set up `custom-tool-bar-map'.
4653 (let ((map (make-sparse-keymap)))
4656 (tool-bar-local-item-from-menu
4657 (nth 1 arg
) (nth 4 arg
) map custom-mode-map
))
4659 (setq custom-tool-bar-map map
))))
4660 (make-local-variable 'custom-options
)
4661 (make-local-variable 'custom-local-buffer
)
4662 (make-local-variable 'widget-documentation-face
)
4663 (setq widget-documentation-face
'custom-documentation
)
4664 (make-local-variable 'widget-button-face
)
4665 (setq widget-button-face custom-button
)
4666 (setq show-trailing-whitespace nil
)
4668 ;; We need this because of the "More" button on docstrings.
4669 ;; Otherwise clicking on "More" can push point offscreen, which
4670 ;; causes the window to recenter on point, which pushes the
4671 ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
4672 (set (make-local-variable 'widget-button-click-moves-point
) t
)
4674 (set (make-local-variable 'widget-button-pressed-face
) custom-button-pressed
)
4675 (set (make-local-variable 'widget-mouse-face
) custom-button-mouse
)
4677 ;; When possible, use relief for buttons, not bracketing. This test
4678 ;; may not be optimal.
4679 (when custom-raised-buttons
4680 (set (make-local-variable 'widget-push-button-prefix
) "")
4681 (set (make-local-variable 'widget-push-button-suffix
) "")
4682 (set (make-local-variable 'widget-link-prefix
) "")
4683 (set (make-local-variable 'widget-link-suffix
) ""))
4684 (add-hook 'widget-edit-functions
'custom-state-buffer-message nil t
))
4686 (put 'Custom-mode
'mode-class
'special
)
4688 ;; backward-compatibility
4689 (defun custom-mode ()
4690 "Non-interactive variant of `Custom-mode'."
4692 (make-obsolete 'custom-mode
'Custom-mode
"23.1")
4693 (put 'custom-mode
'mode-class
'special
)
4694 (define-obsolete-variable-alias 'custom-mode-hook
'Custom-mode-hook
"23.1")
4697 '("^No user option defaults have been changed since Emacs "
4699 "^No \\(?:customized\\|rogue\\|saved\\) user options"
4700 "^No customizable items matching "
4701 "^There are unset changes"
4702 "^Cannot set hidden variable"
4703 "^No \\(?:saved\\|backup\\) value for "
4704 "^No standard setting known for "
4705 "^No standard setting for this face"
4706 "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
4707 (add-to-list 'debug-ignored-errors regexp
))
4713 ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f
4714 ;;; cus-edit.el ends here